Created
June 25, 2013 07:04
-
-
Save dadhi/5856539 to your computer and use it in GitHub Desktop.
FizzBuzz on F# as generic solution.
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
let rules = [(3, "Fizz"); (5, "Buzz")] | |
let translate x = | |
None |> List.foldBack (fun (i, word) say -> | |
if x % i = 0 then Some <| Option.fold (+) word say | |
else say) rules | |
for n in 1..100 do | |
printfn "%s" <| match translate n with | Some s -> s | _ -> string n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment