-
-
Save dminuoso/1e76c685d5168d8fe8881de0230a5208 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
spreadBits :: Int -> Int -> [Int] | |
spreadBits n m = go [] 0.5 0 | |
where | |
go :: [Int] -> Float -> Int -> [Int] | |
go result leapTotal i | i <= n | |
= go (whole + leap : result) leapTotal'' (i + 1) | |
| otherwise | |
= reverse result | |
where | |
leapTotal' = leapTotal + fraction | |
(leap :: Int, leapTotal'') = properFraction leapTotal' | |
zeroGroupSize :: Float | |
zeroGroupSize = ((/) `on` fromIntegral) (m - n) (n + 1) | |
(whole :: Int, fraction :: Float) = properFraction zeroGroupSize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment