Problem 2

completed November 28, 2011

Code

set bound to 4000000
set the_list to {{1, 1}, {2, 2}} -- {item, value}
set the_sum to 0


repeat with i from 3 to 4000000
	
	if ((item 2 of item (i - 2) of the_list) + (item 2 of item (i - 1) of the_list)) <= 4000000 then
		set the_list to the_list & {{i, (item 2 of item (i - 2) of the_list) + (item 2 of item (i - 1) of the_list)}}
	else
		exit repeat
	end if
	
end repeat

repeat with j from 1 to (count the_list)
	
	if ((j * 3) - 1) > (count the_list) then exit repeat
	set the_sum to the_sum + (item 2 of item ((j * 3) - 1) of the_list)
	
end repeat

return the_sum