Skip to content

Instantly share code, notes, and snippets.

@daniel-chambers
Last active February 27, 2018 10:07
Show Gist options
  • Save daniel-chambers/18d6ea4fa141eb901c2eec38d68b3b01 to your computer and use it in GitHub Desktop.
Save daniel-chambers/18d6ea4fa141eb901c2eec38d68b3b01 to your computer and use it in GitHub Desktop.
FizzBuzz in F#
let fizzDiv ys str x =
if ys |> List.forall (fun y -> x % y = 0)
then Some str
else None
let fizzBuzzChecks x =
(fizzDiv [3;5] "FizzBuzz" x)
|> Option.orElse (fizzDiv [5] "Buzz" x)
|> Option.orElse (fizzDiv [3] "Fizz" x)
|> Option.defaultValue (string x)
let fizzBuzz =
[1..100] |> List.map fizzBuzzChecks
[<EntryPoint>]
let main argv =
fizzBuzz |> List.iter System.Console.WriteLine
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment