Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created December 4, 2015 19:32
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/3925e7a4816627198665 to your computer and use it in GitHub Desktop.
Save vznvzn/3925e7a4816627198665 to your computer and use it in GitHub Desktop.
def adv(n)
l = []
s = ''
while (n != 1)
l << n
while (n.odd?)
n = (n * 3 + 1) / 2
s << '1'
end
while (n.even?)
n /= 2
s << '0'
end
end
return [0, l]
end
n = 10001
l = []
a = 100
a.times { l << adv(n); n += 2 }
loop \
{
c = t = 0
l.each \
{
|l2|
x = l2[0]
if (x == l2[1].size) then
c += 1
next
end
t += l2[1][x].to_s(2).length
l2[0] += 1
}
puts([t, c].join("\t"))
break if (c == a)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment