Skip to content

Instantly share code, notes, and snippets.

@caindy
Created June 2, 2014 08:57
Show Gist options
  • Save caindy/f47f698edab3dc6a08d6 to your computer and use it in GitHub Desktop.
Save caindy/f47f698edab3dc6a08d6 to your computer and use it in GitHub Desktop.
F# FizzBuzz
let (|Fizz|_|) i =
if i % 3 = 0 then Some i
else None
let (|Buzz|_|) i =
if i % 5 = 0 then Some i
else None
let (|``Fizz Buzz``|_|) i =
match i with
| Fizz _ & Buzz _ -> Some "Fizz Buzz"
| Fizz i -> Some "Fizz"
| Buzz i -> Some "Buzz"
| _ -> None
for i in [1..100] do
match i with
|``Fizz Buzz`` fb -> System.Console.WriteLine fb
| _ -> System.Console.WriteLine "nothing"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment