Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created November 9, 2018 02:36
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/dfc935449496e4153aeb164147b1ac98 to your computer and use it in GitHub Desktop.
Save vznvzn/dfc935449496e4153aeb164147b1ac98 to your computer and use it in GitHub Desktop.
def sym2bin(ns)
ns1 = (0..(ns.length / 2)).map { |x| ns[(x * 2)..(x * 2 + 1)] }
ns1b = ns1.dup
raise if (ns1b.pop != '2')
ns2 = ns1b.reverse.map { |x| {'11' => '0', '12' => '1'}[x] }.join
return ns2
end
def breakup(ns)
l1 = ns.split(/0+/).map { |x| x.length }
l0 = ns.split(/1+/)[1..-1].map { |x| x.length }
p([l1.size, l0.size, l1.select { |x| x == 10}, l0.select { |x| x == 10}, l1, l0])
end
x = readlines()[0..-2].map { |x| x.split[-1] }.join
ns = sym2bin(x)
p(ns)
breakup(ns)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment