Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created October 8, 2015 04:15
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/9495ebcd7fb50f64c9d6 to your computer and use it in GitHub Desktop.
Save vznvzn/9495ebcd7fb50f64c9d6 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby1.8
def f(n)
l = []
while (n != 1)
n = (n * 3 + 1) / 2 while (n % 2 == 1)
n /= 2 while (n % 2 == 0)
l << [n, n.to_s(2).length]
end
return l
end
n = 10001
l = []
5000.times { l << f(n); n += 2 }
m = l.map { |x| x.size }.max
(m + 1).times \
{
|i|
t1 = t2 = 0
l.size.times \
{
|j|
x1, x2 = l[j][(i.to_f / m * (l[j].size - 1)).to_i]
t1 += x1
t2 += x2
}
puts([Math.log(t1), t2].join("\t"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment