Created
January 30, 2012 15:34
-
-
Save marcelmeyer/1705006 to your computer and use it in GitHub Desktop.
Rail Cars!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module (game). | |
-compile([export_all]). | |
go() -> | |
test(lists:seq(250,999)). | |
test([N|T]) -> | |
case match(parse(N), parse(4*N)) of | |
true -> io:format("~p~n", [N]); | |
false -> no | |
end, | |
test(T); | |
test([]) -> | |
done. | |
parse(N) -> | |
parse(integer_to_list(N), []). | |
parse([H|T], Acc) -> | |
{Digit, _} = string:to_integer([H]), | |
parse(T, [Digit | Acc]); | |
parse([],Acc) -> | |
lists:reverse(Acc). | |
match([_,A,R],[R,A,_,_]) -> | |
true; | |
match(_,_) -> | |
false. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment