Skip to content

Instantly share code, notes, and snippets.

@andybrackley
Created January 18, 2020 13:27
Show Gist options
  • Save andybrackley/5d0ac66401b15e9ba9d4adfd785a33a7 to your computer and use it in GitHub Desktop.
Save andybrackley/5d0ac66401b15e9ba9d4adfd785a33a7 to your computer and use it in GitHub Desktop.
An alternative approach to the FizzBuzz problem that doesn't use modules
module Program =
type Fizz = Fizz
type Buzz = Buzz
let fizzBuzzLines =
let fizzPattern = Seq.initInfinite (fun _ -> [ None; None; Some Fizz ] ) |> Seq.concat
let buzzPattern = Seq.initInfinite (fun _ -> [ None; None; None; None; Some Buzz ] ) |> Seq.concat
let fizzBuzzPattern =
buzzPattern
|> Seq.zip fizzPattern
fizzBuzzPattern
|> Seq.mapi(fun i (fizz, buzz) ->
match (fizz, buzz) with
| Some(_), Some(_) -> "FizzBuzz"
| Some(_), _ -> "Fizz"
| _, Some(_) -> "Buzz"
| None, None -> string (i + 1))
let [<EntryPoint>] main _ =
fizzBuzzLines
|> Seq.take 50
|> Seq.iter (printfn "%s")
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment