31ph4n70m

Fibonacci_Divisibility_Advanced.erl

Nov 25th, 2019
616
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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).
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×