re: Fizz Buzz in Every Language VIEW POST

TOP OF THREAD FULL DISCUSSION
re: There's several ways to do it in C++ :) The Classic #include <cstdio> int main () { for (auto i = 1; i < 101; ++i) { i...
 

I raise you the compile time calculated fizzbuzz in Nim ;)

proc fizzbuzz(): seq[string] =
  result = @[]
  for i in 1..100:
    result.add(
      if i mod 15 == 0: "FizzBuzz"
      elif i mod 5 == 0: "Buzz"
      elif i mod 3 == 0: "Fizz"
      else: $i
    )

const compileTimeValue = fizzbuzz()

echo compileTimeValue
 

C++20 isn't available yet, but we're a bit closer to this approach. :)

 
code of conduct - report abuse