Skip to content

Instantly share code, notes, and snippets.

@marcelmeyer
Created January 30, 2012 15:34
Show Gist options
  • Save marcelmeyer/1705006 to your computer and use it in GitHub Desktop.
Save marcelmeyer/1705006 to your computer and use it in GitHub Desktop.
Rail Cars!
-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