Created
December 22, 2019 21:01
-
-
Save vznvzn/fe3bc6d3cfb89944184bc7d2aad715e3 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 f2(n) | |
return n.odd? ? (n * 3 + 1) / 2 : n / 2 | |
end | |
def seq(n) | |
n1 = n | |
l = [n1] | |
while (n != 1) | |
n = f2(n) | |
l << n | |
end | |
return l | |
end | |
(1..2000).each \ | |
{ | |
|x| | |
ns = '1' * x | |
l1 = seq(ns.to_i(2)) | |
cg = l1.index { |x| x < l1[0] } | |
cg = l1.size if (cg.nil?) | |
cm = (0...cg).max_by { |x| l1[x] } | |
puts([x, cm, cm - x].join("\t")) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment