Skip to content

Instantly share code, notes, and snippets.

@vznvzn
Created November 10, 2018 05:39
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/3a34fa70fbb0327c1a10953e343ba9b3 to your computer and use it in GitHub Desktop.
Save vznvzn/3a34fa70fbb0327c1a10953e343ba9b3 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.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