How to resolve the algorithm FizzBuzz step by step in the Nim programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm FizzBuzz step by step in the Nim programming language

Table of Contents

Problem Statement

Write a program that prints the integers from   1   to   100   (inclusive).

But:

The   FizzBuzz   problem was presented as the lowest level of comprehension required to illustrate adequacy.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm FizzBuzz step by step in the Nim programming language

Source code in the nim programming language

for i in 1..100:
  if i mod 15 == 0:
    echo("FizzBuzz")
  elif i mod 3 == 0:
    echo("Fizz")
  elif i mod 5 == 0:
    echo("Buzz")
  else:
    echo(i)

var messages = @["", "Fizz", "Buzz", "FizzBuzz"]
var acc = 810092048
for i in 1..100:
  var c = acc and 3
  echo(if c == 0: $i else: messages[c])
  acc = acc shr 2 or c shl 28

import macros
macro FizzBuzz(N): untyped =
  var source = ""
  for i in 1..N.intVal:
    source &= "echo \""
    if i mod 15 == 0:
      source &= "FizzBuzz"
    elif i mod 3 == 0:
      source &= "Fizz"
    elif i mod 5 == 0:
      source &= "Buzz"
    else:
      source &= $i
    source &= "\"\n"
  result = parseStmt(source)

FizzBuzz(100)

  

You may also check:How to resolve the algorithm Copy a string step by step in the Fortran programming language
You may also check:How to resolve the algorithm Generate random chess position step by step in the Java programming language
You may also check:How to resolve the algorithm Reduced row echelon form step by step in the Fortran programming language
You may also check:How to resolve the algorithm Spiral matrix step by step in the Stata programming language
You may also check:How to resolve the algorithm Square form factorization step by step in the C++ programming language