Skip to content

Instantly share code, notes, and snippets.

@dvdsgl
Created December 18, 2012 05:28
Show Gist options
  • Save dvdsgl/4325309 to your computer and use it in GitHub Desktop.
Save dvdsgl/4325309 to your computer and use it in GitHub Desktop.
type FizzBuzz =
FizzBuzz | Fizz | Buzz | Nat of int
let (|DivisibleBy|_|) by n =
if n % by = 0 then Some () else None
let fizzbuzz n = match n with
| DivisibleBy 3 & DivisibleBy 5 -> FizzBuzz
| DivisibleBy 3 -> Fizz
| DivisibleBy 5 -> Buzz
| _ -> Nat n
let fizzbuzzes = Seq.initInfinite fizzbuzz
@WooCode
Copy link

WooCode commented Feb 14, 2013

Instead of | DivisibleBy 3 & DivisibleBy 5 -> FizzBuzz
You could do | DivisibleBy 15 -> FizzBuzz

Cause if it's divisible by 3 & 5 it should be divisible by 15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment