Skip to content

Instantly share code, notes, and snippets.

@alucky0707
Created October 11, 2013 10:57
Show Gist options
  • Save alucky0707/6932932 to your computer and use it in GitHub Desktop.
Save alucky0707/6932932 to your computer and use it in GitHub Desktop.
PrologでFizzBuzz書きましたー。なんかPrologっぽくない
fizzbuzz(N, "FizzBuzz") :- 0 is N mod 15, !.
fizzbuzz(N, "Fizz") :- 0 is N mod 3, !.
fizzbuzz(N, "Buzz") :- 0 is N mod 5, !.
fizzbuzz(N, X) :- swritef(Y, "%d", [N]), string_to_list(Y, X).
print_fizzbuzz(N) :- fizzbuzz(N, X), writef("%s", [X]), nl.
do_fizzbuzz :- foreach(between(1, 100, N), print_fizzbuzz(N)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment