Created
June 2, 2014 08:57
-
-
Save caindy/f47f698edab3dc6a08d6 to your computer and use it in GitHub Desktop.
F# FizzBuzz
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 (|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