How to resolve the algorithm FizzBuzz step by step in the Visual Prolog programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm FizzBuzz step by step in the Visual Prolog 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 Visual Prolog programming language

Source code in the visual programming language

implement main
   open core, console

class predicates
   fizzbuzz : (integer) -> string procedure (i).

clauses
    fizzbuzz(X) = S :- X mod 15 = 0, S = "FizzBuzz", !.
    fizzbuzz(X) = S :- X mod 5 = 0, S = "Buzz", !.
    fizzbuzz(X) = S :- X mod 3 = 0, S = "Fizz", !.
    fizzbuzz(X) = S :- S = toString(X).

    run() :-
        foreach X = std::fromTo(1,100) do
            write(fizzbuzz(X)), write("\n")
        end foreach,
        succeed.

end implement main

goal
    console::runUtf8(main::run).

  

You may also check:How to resolve the algorithm Guess the number/With feedback (player) step by step in the Haskell programming language
You may also check:How to resolve the algorithm Truncate a file step by step in the Lasso programming language
You may also check:How to resolve the algorithm Bitmap/Read a PPM file step by step in the J programming language
You may also check:How to resolve the algorithm Hello world/Standard error step by step in the Lua programming language
You may also check:How to resolve the algorithm Multiplication tables step by step in the Bracmat programming language