Task

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



But:

   for multiples of three,   print   Fizz     (instead of the number)
   for multiples of five,   print   Buzz     (instead of the number)
   for multiples of both three and five,   print   FizzBuzz     (instead of the number) 


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



Also see

   (a blog)   dont-overthink-fizzbuzz
   (a blog)   fizzbuzz-the-programmers-stairway-to-heaven


 
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).
 