Advertisement
31ph4n70m

Fibonacci_Divisibility_Advanced.lua

Nov 25th, 2019
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.64 KB | None | 0 0
  1. -- lua solution to codabbey challenge 71
  2. function getidxfib(mod)
  3.     fib1 = 0
  4.     fib2 = 1
  5.     fib3 = 0
  6.     idx = 2
  7.     while (true)
  8.     do
  9.         fib3 = (fib1 + fib2) % mod
  10.         if (fib3 % mod == 0)
  11.         then
  12.           return tostring(idx)
  13.         end
  14.         fib1 = fib2
  15.         fib2 = fib3
  16.         idx = idx + 1
  17.     end
  18. end
  19.  
  20. N_CASES = 19
  21. CASES = {449825, 940999, 891051, 674588, 241652, 1049193, 1024240, 857743, 408165, 641261, 349920, 1015891, 982578, 291607, 657942, 374884, 508055, 458138, 732856}
  22. RSP = {}
  23. for i=1,N_CASES do
  24.     val = getidxfib(CASES[i])
  25.     table.insert(RSP, val)
  26. end
  27. print(table.concat(RSP, " "))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement