練習問題/解答例/FizzBuzz/Prolog
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
%swi-prolog
fizzbuzz(N) :- fizzbuzz(N, 0).
fizzbuzz(N, M) :-
M < N, M1 is M+1,
M1 mod 15 =:= 0,
write('FizzBuzz '),
fizzbuzz(N, M1).
fizzbuzz(N, M) :-
M < N, M1 is M+1,
M1 mod 5 =:= 0,
write('Buzz '),
fizzbuzz(N, M1).
fizzbuzz(N, M) :-
M < N, M1 is M+1,
M1 mod 3 =:= 0,
write('Fizz '),
fizzbuzz(N, M1).
fizzbuzz(N, M) :-
M < N, M1 is M+1,
write(M1), write(' '),
fizzbuzz(N, M1).
fizzbuzz(N, N).
終了行:
%swi-prolog
fizzbuzz(N) :- fizzbuzz(N, 0).
fizzbuzz(N, M) :-
M < N, M1 is M+1,
M1 mod 15 =:= 0,
write('FizzBuzz '),
fizzbuzz(N, M1).
fizzbuzz(N, M) :-
M < N, M1 is M+1,
M1 mod 5 =:= 0,
write('Buzz '),
fizzbuzz(N, M1).
fizzbuzz(N, M) :-
M < N, M1 is M+1,
M1 mod 3 =:= 0,
write('Fizz '),
fizzbuzz(N, M1).
fizzbuzz(N, M) :-
M < N, M1 is M+1,
write(M1), write(' '),
fizzbuzz(N, M1).
fizzbuzz(N, N).
ページ名: