38 lines
880 B
Plaintext
38 lines
880 B
Plaintext
:- module main.
|
|
|
|
main :-
|
|
nats(100, Nats),
|
|
fizzbuzz(Nats, Output),
|
|
display(Output).
|
|
|
|
nats(Max, Out) :-
|
|
nats(Max, 1, Out).
|
|
nats(Max, Count, Out) :- Count =< Max |
|
|
Out = [Count|NewOut],
|
|
NewCount := Count + 1,
|
|
nats(Max, NewCount, NewOut).
|
|
nats(Max, Count, Out) :- Count > Max |
|
|
Out = [].
|
|
|
|
fizzbuzz([N|Rest], Out) :- N mod 3 =:= 0, N mod 5 =:= 0 |
|
|
Out = ['FizzBuzz' | NewOut],
|
|
fizzbuzz(Rest, NewOut).
|
|
fizzbuzz([], Out) :-
|
|
Out = [].
|
|
alternatively.
|
|
fizzbuzz([N|Rest], Out) :- N mod 3 =:= 0 |
|
|
Out = ['Fizz' | NewOut],
|
|
fizzbuzz(Rest, NewOut).
|
|
fizzbuzz([N|Rest], Out) :- N mod 5 =:= 0 |
|
|
Out = ['Buzz' | NewOut],
|
|
fizzbuzz(Rest, NewOut).
|
|
alternatively.
|
|
fizzbuzz([N|Rest], Out) :-
|
|
Out = [N | NewOut],
|
|
fizzbuzz(Rest, NewOut).
|
|
|
|
display([Message|Rest]) :-
|
|
io:outstream([print(Message), nl]),
|
|
display(Rest).
|
|
display([]).
|