Skip to content

Instantly share code, notes, and snippets.

@smies
Created April 23, 2013 09:22
Show Gist options
  • Save smies/5442110 to your computer and use it in GitHub Desktop.
Save smies/5442110 to your computer and use it in GitHub Desktop.
// 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