Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created April 6, 2016 01:52
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/62546e1d7f499697976140d8d86dc0d1 to your computer and use it in GitHub Desktop.
Save vznvzn/62546e1d7f499697976140d8d86dc0d1 to your computer and use it in GitHub Desktop.
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