Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created October 5, 2015 22:50
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/2f7db032e62aa5301e51 to your computer and use it in GitHub Desktop.
Save vznvzn/2f7db032e62aa5301e51 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 = 8001
l = []
1000.times { l << n; n += 2 }
l2 = l.dup
seen = {}
i = 0
begin
j = (0...l2.size).max_by { |x| l2[x] }
z = l[j]
if (seen.member?(z)) then
l.delete_at(j)
l2.delete_at(j)
next
end
seen[z] = nil
l[j] = f(z)
l2[j] += z
t = 0.0
l.each { |x| t += x }
puts([t, l.size].join("\t"))
end while (!l.empty?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment