Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created October 6, 2015 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vznvzn/cf9c68608ecea255100e to your computer and use it in GitHub Desktop.
Save vznvzn/cf9c68608ecea255100e to your computer and use it in GitHub Desktop.
def f(n)
n = (n * 3 + 1) if (n.odd?)
n /= 2 while (n.even?)
return n
end
n = 7001
l = []
50.times { l << n; n += 2 }
l2 = l.dup
x = 0
begin
i = 0
while (i < l.size)
y1 = l[i]
y = Math.log(l2[i])
l[i] = f(l[i])
l2[i] += l[i]
c = l[i] > y1 ? 1 : 2
puts([x, y, c].join("\t"))
puts([x + 1, Math.log(l2[i]), c].join("\t"))
puts
if (l[i] == 1) then
l.delete_at(i)
next
end
i += 1
end
x += 1
end while (!l.empty?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment