Skip to content

Instantly share code, notes, and snippets.

@pocarist
Created September 26, 2023 16:04
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 pocarist/b7b4c80aa0bc465ab1ed0c4e4088978a to your computer and use it in GitHub Desktop.
Save pocarist/b7b4c80aa0bc465ab1ed0c4e4088978a to your computer and use it in GitHub Desktop.
FizzBuzz written using F# sequence
let fizz =
Seq.initInfinite (fun i -> if (i+1) % 3 = 0 then "Fizz" else "")
let buzz =
Seq.initInfinite (fun i -> if (i+1) % 5 = 0 then "Buzz" else "")
let fizzbuzz =
Seq.mapi2 (fun i f b -> match f + b with "" -> string (i + 1) | x -> x) fizz buzz
fizzbuzz
|> Seq.take 100
|> Seq.iter (printfn "%s")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment