Created
April 6, 2016 01:52
-
-
Save vznvzn/62546e1d7f499697976140d8d86dc0d1 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
def f1(n) | |
n = (n * 3 + 1) / 2 while (n.odd?) | |
n /= 2 while (n.even?) | |
return n | |
end | |
def adv(n) | |
c = 0 | |
n1 = n | |
while (n != 1) | |
n = f1(n) | |
break if (n < n1) | |
c += 1 | |
end | |
return c | |
end | |
def width(n) | |
t = 2**n | |
(t...2**(n+1)).each_with_index \ | |
{ | |
|i, j| | |
s = i.to_s(2).reverse | |
puts([j.to_f / (t - 1), adv(s.to_i(2)) + n * 20, n].join("\t")) | |
} | |
puts | |
end | |
14.times { |x| width(x) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment