Created
June 8, 2021 02:03
-
-
Save moniquelive/1ed51154fba6e408365ef4184e7b180b 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
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