Skip to content

Instantly share code, notes, and snippets.

@moniquelive
Created June 8, 2021 02:03
Show Gist options
  • Save moniquelive/1ed51154fba6e408365ef4184e7b180b to your computer and use it in GitHub Desktop.
Save moniquelive/1ed51154fba6e408365ef4184e7b180b to your computer and use it in GitHub Desktop.
main = interact $ show . sum . bin2dec . reverse . dec2bin . read
where
dec2bin 0 = []
dec2bin n = dec2bin (n `div` 2) ++ [n `rem` 2]
bin2dec bs = let l = length bs
l1 = l - 1
l2 = l - 2
in zipWith (\a b -> a * 2 ^ b) bs [l1,l2..0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment