Created
April 6, 2016 09:11
-
-
Save mjul/8f5f632b5dd12d1c3bf6c43cfa357c5a to your computer and use it in GitHub Desktop.
FizzBuzz F#
This file contains hidden or 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
// F# FizzBuzz using Active Patterns | |
let (|DivisibleBy|_|) by n = | |
match n%by with | |
| 0 -> Some DivisibleBy | |
| _ -> None | |
let fizzbuzz = function | |
| DivisibleBy 3 & DivisibleBy 5 -> "FizzBuzz" | |
| DivisibleBy 3 -> "Fizz" | |
| DivisibleBy 5 -> "Buzz" | |
| i -> string i | |
// Generate and print the sequence | |
Seq.map fizzbuzz [1..20] | |
|> Seq.iter (fun x -> printfn "%s" x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment