Created
November 10, 2018 05:39
-
-
Save vznvzn/3a34fa70fbb0327c1a10953e343ba9b3 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.map { |x| {'11' => '0', '12' => '1'}[x] }.join | |
return ns2 | |
end | |
l = readlines().map { |x| x.split } | |
raise if (l[-1].size != 1) | |
l = l[0..-2].map { |x| x[-1] } | |
ns = sym2bin(l.join) | |
puts(ns) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment