This commit is contained in:
Sven Weidauer 2021-12-03 22:18:59 +01:00
parent 609cf69d40
commit 8798f1b1e4

View file

@ -1023,13 +1023,11 @@ count pos (zero, one) num = case num !! pos of
'0' -> (zero + 1, one) '0' -> (zero + 1, one)
'1' -> (zero, one + 1) '1' -> (zero, one + 1)
_ -> (zero, one) _ -> (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 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 toNumber :: Foldable t => t Bool -> Int