challenges/e2/e2.pl

6 lines
375 B
Perl
Raw Normal View History

2011-04-01 23:37:14 +00:00
fib_count(Last, Current, Max, Sum, Sum) :- Current >= Max.
fib_count(Last, Current, Max, Acc, Sum) :- 0 is Current rem 2, Next is Last + Current, NewAcc is Acc + Current, fib_count(Current, Next, Max, NewAcc, Sum).
fib_count(Last, Current, Max, Acc, Sum) :- Next is Last + Current, fib_count(Current, Next, Max, Acc, Sum).
e2(Result) :- fib_count(0, 1, 4000000, 0, Result).