Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % erlang solution to codeabbey challenge 71
- -module(main).
- -import(string, [tokens/2]).
- -import(lists,[nth/2]).
- -export([while/4,getidxfib/1,forloop/3,main/1]).
- while(F1, F2, M, Idx) ->
- F3 = (F1 + F2) rem M,
- C = F3 rem M,
- if
- C == 0 ->
- erlang:display(Idx);
- C /= 0 ->
- while(F2, F3, M, Idx+1);
- true ->
- erlang:display("")
- end.
- getidxfib(Mod) ->
- while(0, 1, Mod, 2).
- forloop(Arr, Lim, N) ->
- if
- N =< Lim ->
- getidxfib(nth(N, Arr)),
- forloop(Arr, Lim, N + 1);
- true ->
- erlang:display("")
- end.
- main([_]) ->
- Ncases = 19,
- Cases = [449825, 940999, 891051, 674588, 241652, 1049193, 1024240, 857743, 408165, 641261, 349920, 1015891, 982578, 291607, 657942, 374884, 508055, 458138, 732856],
- forloop(Cases, Ncases, 1).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement