Skip to content

Instantly share code, notes, and snippets.

@melston
Last active November 15, 2017 19:25
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 melston/8dcfb2e26de693f5c1eaee42ca682e48 to your computer and use it in GitHub Desktop.
Save melston/8dcfb2e26de693f5c1eaee42ca682e48 to your computer and use it in GitHub Desktop.
Another alternative FizzBuzz in F#
let cycle x = Seq.initInfinite (fun _ -> x) |> Seq.concat
let zipWith f xs ys = Seq.zip xs ys |> Seq.map (fun (x,y) -> f x y)
let fizz = seq ["";"";"fizz"] |> cycle
let buzz = seq ["";"";"";"";"buzz"] |> cycle
let bang = seq ["";"";"";"";"";"";"bang"] |> cycle
let boom = seq ["";"";"";"";"";"";"";"";"";"";"boom"] |> cycle
let numbers = seq [1 .. 115] |> Seq.map string
let fizzBuzz3 = zipWith (+) bang boom
|> zipWith (+) buzz
|> zipWith (+) fizz
|> zipWith max numbers
fizzBuzz3 |> Seq.take 115 |> Seq.toList |> List.iter (printfn "%s")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment