DEV Community

Discussion on: Get Your (Fizz)Buzz On

Collapse
 
yechielk profile image
Yechiel Kalmenson

Oh wow! I was NOT expecting a COBOL solution ;)

Guess that last part is left as an exercise for the reader (from my understanding, COBOL programmers don't have silly riddles in their interviews these days... :)

Collapse
 
danieljsummers profile image
Daniel J. Summers • Edited

I'm less than 4 years from the end of my current employment, and need to decide what to do next. Helping prop up aging COBOL is on my list to consider. :)

To bring it into this century, here's an F# version...

let words =
  function
  | _ when 0 = nbr % 3 && 0 = nbr % 5 -> "FizzBuzz"
  | _ when 0 = nbr % 3 -> "Fizz"
  | _ when 0 = nbr % 5 -> "Buzz"
  | x -> string x
let fizzBuzz i =
  [1 .. i]
  |> List.map words
  |> String.concat ", "
fizzBuzz 100
|> System.Console.WriteLine

...although, technically, this separates them by commas rather than listing one per line.