Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
20
Task/FizzBuzz/Prolog/fizzbuzz-3.pro
Normal file
20
Task/FizzBuzz/Prolog/fizzbuzz-3.pro
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
% N /3? /5? V
|
||||
fizzbuzz(_, yes, yes, 'FizzBuzz').
|
||||
fizzbuzz(_, yes, no, 'Fizz').
|
||||
fizzbuzz(_, no, yes, 'Buzz').
|
||||
fizzbuzz(N, no, no, N).
|
||||
|
||||
% Unifies V with 'yes' if D divides evenly into N, 'no' otherwise.
|
||||
divisible_by(N, D, V) :-
|
||||
( 0 is N mod D -> V = yes
|
||||
; V = no).
|
||||
|
||||
% Print 'Fizz', 'Buzz', 'FizzBuzz' or N as appropriate.
|
||||
fizz_buzz_or_n(N) :-
|
||||
divisible_by(N, 3, Fizz),
|
||||
divisible_by(N, 5, Buzz),
|
||||
fizzbuzz(N, Fizz, Buzz, FB),
|
||||
format("~p -> ~p~n", [N, FB]).
|
||||
|
||||
main :-
|
||||
foreach(between(1,100, N), fizz_buzz_or_n(N)).
|
||||
Loading…
Add table
Add a link
Reference in a new issue