Last active
September 17, 2016 07:05
-
-
Save amalloy/ee99e4ea6279cca8e8a10431a517648d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
data Rule = Rule {bytes :: Int, | |
cost :: Double} | |
charges :: [Rule] -> Int -> Double | |
charges = foldr applyCharge (const 0) | |
where applyCharge _ _ 0 = 0 | |
applyCharge (Rule n mult) cont used = (mult * (fromIntegral $ min n used)) | |
+ cont (max 0 (used - n)) | |
value = charges (zipWith Rule [1024, 51200, 512000, 512000, 5120000, 1024000] | |
[0.0671, 0.0659, 0.0648, 0.0637, 0.0626, 0.0626]) | |
100000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment