Define function to compute triangle numbers