Skip to content

Instantly share code, notes, and snippets.

@amalloy
Last active September 17, 2016 07:05
Show Gist options
  • Save amalloy/ee99e4ea6279cca8e8a10431a517648d to your computer and use it in GitHub Desktop.
Save amalloy/ee99e4ea6279cca8e8a10431a517648d to your computer and use it in GitHub Desktop.
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