Project Euler

Problem #104

The Fibonacci sequence is defined by the recurrence relation:

F_(n) = F_(n−1) + F_(n−2), where F_(1) = 1 and F_(2) = 1.

It turns out that F_(541), which contains 113 digits, is the first Fibonacci number for which the last nine digits are 1-9 pandigital (contain all the digits 1 to 9, but not necessarily in order). And F_(2749), which contains 575 digits, is the first Fibonacci number for which the first nine digits are 1-9 pandigital.

Given that F_(k) is the first Fibonacci number for which the first nine digits AND the last nine digits are 1-9 pandigital, find k.

Erlang: Running time = 67.756s
+%digit_split

+%pow

p104()->
	put(jillion,pow(10,9)),
	put(digs,lists:seq(1,9)),
	p104(2,1,1,1,1).
p104(I,ALong,BLong,AShort,BShort)->
	case lists:sort(digit_split(BShort))==get(digs) of
		true->
			FirstNine=lists:sublist(digit_split(BLong),9),
			case lists:sort(FirstNine) == get(digs) of
				true->
					io:format("~w~n",[I]);
				false->p104(I+1,BLong,ALong+BLong,BShort,(AShort+BShort) rem get(jillion))
			end;
		false->p104(I+1,BLong,ALong+BLong,BShort,(AShort+BShort) rem get(jillion))
	end.