BFH72ISNORLFYPNB5SKVOG36JUXY2NAYHQZ6SMQIUUG4PB4EKVLAC
calculate (Positive income) = Budget (Positive needs) (Positive wants) (Positive savings)
calculate x = Budget needs wants savings
where
income = fromIntegral . unP $ x
(needs:wants:savings:_) = map (unsafePos "") . distribute [0.5, 0.3, 0.2] $ income
distribute :: [Double] -> Int -> [Int]
distribute xs target = flip evalState 0 . mapM (\x -> distributeState x weight target) $ xs
needs = income `quot` 2
wants = income - needs - savings
savings = income `quot` 5
weight = sum xs
distributeState :: Double -> Double -> Int -> State Double Int
distributeState basis weight target = do
old <- get
let r = (basis / weight * fromIntegral target) + old
put r
pure $ round r - round old
packages: .
source-repository-package
type: git
location: https://github.com/gbwey/pos.git
tag: 659d493eb3fa7d04a9fcf5e3038e350e7808d06a