Advertisement
31ph4n70m

Fibonacci_Divisibility_Advanced.erl

Nov 25th, 2019
1,895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.88 KB | None | 0 0
  1. % erlang solution to codeabbey challenge 71
  2. -module(main).
  3. -import(string, [tokens/2]).
  4. -import(lists,[nth/2]).
  5. -export([while/4,getidxfib/1,forloop/3,main/1]).
  6.  
  7. while(F1, F2, M, Idx) ->
  8.     F3 = (F1 + F2) rem M,
  9.     C = F3 rem M,
  10.     if
  11.         C == 0 ->
  12.             erlang:display(Idx);
  13.         C /= 0 ->
  14.             while(F2, F3, M, Idx+1);
  15.         true ->
  16.             erlang:display("")
  17.     end.
  18.  
  19.  
  20. getidxfib(Mod) ->
  21.     while(0, 1, Mod, 2).
  22.  
  23.  
  24. forloop(Arr, Lim, N) ->
  25.     if
  26.         N =< Lim ->
  27.             getidxfib(nth(N, Arr)),
  28.             forloop(Arr, Lim, N + 1);
  29.         true ->
  30.             erlang:display("")
  31.     end.
  32.  
  33. main([_]) ->
  34.     Ncases = 19,
  35.     Cases = [449825, 940999, 891051, 674588, 241652, 1049193, 1024240, 857743, 408165, 641261, 349920, 1015891, 982578, 291607, 657942, 374884, 508055, 458138, 732856],
  36.     forloop(Cases, Ncases, 1).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement