Skip to content

Instantly share code, notes, and snippets.

@davidwengier
Created February 28, 2018 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidwengier/bc95d4b0b52042ed5d54326d7810b30b to your computer and use it in GitHub Desktop.
Save davidwengier/bc95d4b0b52042ed5d54326d7810b30b to your computer and use it in GitHub Desktop.
let is divisor outputString n result =
if n % divisor = 0 then
Some ( (result |> Option.defaultValue("")) + outputString)
else if result.IsSome then
result
else
None
let fizz x s = is 3 "fizz" x s
let buzz x s = is 5 "buzz" x s
let bang x s = is 7 "bang" x s
let fizzBuzzChecks n =
None
|> fizz n
|> buzz n
|> bang n
|> Option.defaultValue (string n)
let fizzBuzz =
[1..100] |> List.map fizzBuzzChecks
[<EntryPoint>]
let main argv =
fizzBuzz |> List.iter System.Console.WriteLine
System.Console.ReadLine() |> ignore
0
@ChrisCarrAu
Copy link

ChrisCarrAu commented Feb 28, 2018

You can also leave off the x s as follows:

let fizz = is 3 "fizz" 
let buzz = is 5 "buzz" 
let bang = is 7 "bang" 

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