Created
October 16, 2018 00:58
-
-
Save vznvzn/1f1c904f29bc35150b3446a4e5d2ada3 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 re(n, t) | |
s = (n % 2).to_s | |
n1 = n | |
t.times \ | |
{ | |
n = f2(n) | |
s << (n % 2).to_s | |
} | |
return s | |
end | |
p = (1..20).map { rand(2) }.join | |
p2 = p[0, 1] | |
(1...p.length).each \ | |
{ | |
|x| | |
n = p2.reverse.to_i(2) | |
s = re(n, x) | |
b = s[-1, 1] | |
p2 += (b == p[x, 1]) ? '0' : '1' | |
p([s, n, n.to_s(2).reverse]) | |
} | |
n = p2.reverse.to_i(2) | |
s = re(n, p.length - 1) | |
p([s, n, n.to_s(2).reverse, p == s]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment