Created
November 9, 2018 02:36
-
-
Save vznvzn/dfc935449496e4153aeb164147b1ac98 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 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