Skip to content

Instantly share code, notes, and snippets.

@muupan
Last active Dec 20, 2015
Embed
What would you like to do?
FizzBuzz in Prolog It would be better to use between/3.
fizzbuzz(_n) :-
fizzbuzz_sequence(1, _n).
fizzbuzz_sequence(_max, _max) :-
fizzbuzz_number(_max), !.
fizzbuzz_sequence(_min, _max) :-
fizzbuzz_number(_min),
_next is _min + 1,
fizzbuzz_sequence(_next, _max).
fizzbuzz_number(_n) :-
_n mod 3 =:= 0,
_n mod 5 =:= 0,
write('FizzBuzz'), nl, !.
fizzbuzz_number(_n) :-
_n mod 3 =:= 0,
write('Fizz'), nl, !.
fizzbuzz_number(_n) :-
_n mod 5 =:= 0,
write('Buzz'), nl, !.
fizzbuzz_number(_n) :-
write(_n), nl.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment