Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
37
Task/FizzBuzz/KL1/fizzbuzz.kl1
Normal file
37
Task/FizzBuzz/KL1/fizzbuzz.kl1
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
:- 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([]).
|
||||
Loading…
Add table
Add a link
Reference in a new issue