Created
September 27, 2011 04:54
-
-
Save mythz/1244370 to your computer and use it in GitHub Desktop.
Simon Cousins Israel Tax Solution in F#
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
(* http://www.simontylercousins.netsolution to http://ayende.com/blog/108545/the-tax-calculation-challenge *) | |
let taxes salary = | |
let rates = [ | |
40230.0m,0.45m; | |
21240.0m,0.33m; | |
14070.0m,0.3m; | |
8660.0m,0.23m; | |
5070.0m,0.14m; | |
0.0m,0.1m] | |
let taxAtRate (tax,remainder) (threshold,rate) = | |
let taxable = remainder - threshold | |
if taxable > 0.0m | |
then tax + rate * taxable, remainder - taxable | |
else tax,remainder | |
List.fold taxAtRate (0.0m, salary) rates |> fst |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment