Created
January 18, 2020 13:27
-
-
Save andybrackley/5d0ac66401b15e9ba9d4adfd785a33a7 to your computer and use it in GitHub Desktop.
An alternative approach to the FizzBuzz problem that doesn't use modules
This file contains 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
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