Changes
This commit is contained in:
parent
609cf69d40
commit
8798f1b1e4
1 changed files with 2 additions and 4 deletions
6
day3.hs
6
day3.hs
|
@ -1023,13 +1023,11 @@ count pos (zero, one) num = case num !! pos of
|
|||
'0' -> (zero + 1, one)
|
||||
'1' -> (zero, one + 1)
|
||||
_ -> (zero, one)
|
||||
gammaBit (zero, one)
|
||||
| zero > one = False
|
||||
| otherwise = True
|
||||
|
||||
|
||||
bitsAt :: Foldable t => t [Char] -> Int -> (Bool, Bool)
|
||||
bitsAt input pos = bits $ foldl (count pos) (0, 0) input
|
||||
where bits a = (gammaBit a, not $ gammaBit a)
|
||||
where bits (zero, one) = (zero <= one, zero > one)
|
||||
|
||||
|
||||
toNumber :: Foldable t => t Bool -> Int
|
||||
|
|
Loading…
Add table
Reference in a new issue