Skip to content

Instantly share code, notes, and snippets.

@dadhi
Created June 25, 2013 07:04
Show Gist options
  • Save dadhi/5856539 to your computer and use it in GitHub Desktop.
Save dadhi/5856539 to your computer and use it in GitHub Desktop.
FizzBuzz on F# as generic solution.
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