Created
October 8, 2015 04:15
-
-
Save vznvzn/9495ebcd7fb50f64c9d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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