diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2021-12-20 14:53:14 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2021-12-20 14:53:14 +0200 |
| commit | 8cf112cad7c0a52676a834ec3ac77f3006031c87 (patch) | |
| tree | 2c8aba70caa310f7c00ebe1a5eef739bbc3fe980 /utils.hs | |
| parent | 47a2c42249aab79dd2aec4554d3387d2b47ced21 (diff) | |
Day 20
Diffstat (limited to 'utils.hs')
| -rw-r--r-- | utils.hs | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -1,6 +1,7 @@ module Utils where import Control.Applicative (ZipList (ZipList, getZipList)) +import Data.Char (digitToInt) (.>) = flip (.) @@ -46,4 +47,11 @@ takeUntil _ [] = [] takeUntil p (x : xs) = x : if p x then takeUntil p xs else [] fromSymEither (Left x) = x -fromSymEither (Right x) = x
\ No newline at end of file +fromSymEither (Right x) = x + +-- | Convert binary (list of zeros and ones) to decimal +binaryToInt :: String -> Int +binaryToInt = reverse .> binaryToIntRev + +binaryToIntRev [] = 0 +binaryToIntRev (x : xs) = digitToInt x + 2 * binaryToIntRev xs |
