Last active
February 27, 2018 10:07
-
-
Save daniel-chambers/18d6ea4fa141eb901c2eec38d68b3b01 to your computer and use it in GitHub Desktop.
FizzBuzz 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
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