Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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])
Add Comment
Please, Sign In to add comment