BFH72ISNORLFYPNB5SKVOG36JUXY2NAYHQZ6SMQIUUG4PB4EKVLAC calculate (Positive income) = Budget (Positive needs) (Positive wants) (Positive savings)
calculate x = Budget needs wants savingswhereincome = fromIntegral . unP $ x(needs:wants:savings:_) = map (unsafePos "") . distribute [0.5, 0.3, 0.2] $ incomedistribute :: [Double] -> Int -> [Int]distribute xs target = flip evalState 0 . mapM (\x -> distributeState x weight target) $ xs
needs = income `quot` 2wants = income - needs - savingssavings = income `quot` 5
weight = sum xsdistributeState :: Double -> Double -> Int -> State Double IntdistributeState basis weight target = doold <- getlet r = (basis / weight * fromIntegral target) + oldput rpure $ round r - round old
packages: .source-repository-packagetype: gitlocation: https://github.com/gbwey/pos.gittag: 659d493eb3fa7d04a9fcf5e3038e350e7808d06a