Skip to content

Instantly share code, notes, and snippets.

@mjul
Created April 6, 2016 09:11
Show Gist options
  • Save mjul/8f5f632b5dd12d1c3bf6c43cfa357c5a to your computer and use it in GitHub Desktop.
Save mjul/8f5f632b5dd12d1c3bf6c43cfa357c5a to your computer and use it in GitHub Desktop.
FizzBuzz F#
// 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