Created
April 23, 2013 09:22
-
-
Save smies/5442110 to your computer and use it in GitHub Desktop.
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
// setup the active patterns | |
let (|MultOf3|_|) i = if i % 3 = 0 then Some MultOf3 else None | |
let (|MultOf5|_|) i = if i % 5 = 0 then Some MultOf5 else None | |
// the main function | |
let fizzBuzz i = | |
match i with | |
| MultOf3 & MultOf5 -> printf "FizzBuzz, " | |
| MultOf3 -> printf "Fizz, " | |
| MultOf5 -> printf "Buzz, " | |
| _ -> printf "%i, " i | |
// test | |
[1..20] |> List.iter fizzBuzz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment