Created
October 19, 2018 05:06
-
-
Save vznvzn/87b3f056fc5e3f8867279e4d11854832 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 | |
break if (n == 1) | |
} | |
return s, n | |
end | |
#srand(5) | |
p = (1..20).map { rand(2) }.join | |
p2 = ['01', '11'][p[0, 1].to_i] | |
x2 = 2 | |
nb = n2b = 1 | |
n3b = 0 | |
mb = p2 == '11' | |
x3 = (p2.reverse.to_i(2)) >> 1 | |
(1...p.length).each \ | |
{ | |
|x| | |
n = p2.reverse.to_i(2) | |
s, n2 = re(n, x) | |
b = s[x, 1] | |
m = (b == p[x, 1]) | |
p2[x, 1] = m ? '11' : '01' | |
n3 = s[0...x].split('').select { |z| z == '1' }.size | |
if (!mb) | |
ns1 = nb.to_s(2) | |
ns = ns1.dup | |
ns[0, 1] = '' | |
m1 = n2b - 3**n3b | |
n1 = f2(m1) | |
end | |
x3 = mb ? (x2 + 3**n3) : (n1 + 3**n3) | |
s2 = p[0...x] + (x3 % 2).to_s | |
t = s[0...x] == p[0...x] | |
p({'k' => x, 'w_i' => s, 'n' => n, 'n_2_r' => n.to_s(2).reverse, 'X' => n2, 't' => t}) | |
raise if (!t) | |
raise if (s != s2) | |
raise if (n2 != x3) | |
x2 = f2(n2) | |
n3b = n3 | |
n2b = n2 | |
nb = n | |
mb = m | |
} | |
n = p2.reverse.to_i(2) | |
s, n2 = re(n, p.length - 1) | |
p({'k' => p.length, 'w_i' => s, 'n' => n, 'n_2' => n.to_s(2).reverse, 't' => p == s}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment