Advertisement
31ph4n70m

Neumann's_Random_Generator.R

Dec 19th, 2019
866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.50 KB | None | 0 0
  1. # R solution to codeabbey challenge 24
  2. seed = c(3488, 373, 5368, 751, 8342, 3416, 843, 6173, 7019, 381, 1054, 6303)
  3. counter = 1
  4. rsp = list()
  5. vals = list()
  6. for (i in seed) {
  7.     aux = i
  8.     repeat {
  9.         aux2 = trunc((aux * aux / 100) %% 10000)
  10.         if (aux2 %in% vals) {
  11.             rsp[length(rsp)+1] = counter
  12.             break
  13.         }
  14.         vals [length(vals)+1] = aux
  15.         counter = counter + 1
  16.         aux = aux2
  17.     }
  18.     counter = 1
  19.     vals = list()
  20. }
  21. cat(unlist(rsp))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement