2011年2月13日日曜日

Prologの技芸 12.3節の練習問題

(1)

% nim(N,S) :- % 和がNで自分に回ってきたとき,Sと言えば勝てる. nim(N,S) :- between(1,3,S), N1 is N+S, lose(N1), !. :- dynamic win/1. :- dynamic lose/1. win(N) :- N =< 20, between(1,3,A), N1 is N+A, lemma(lose(N1)), !. lose(20). lose(N) :- N =< 20, N1 is N+1, N2 is N+2, N3 is N+3, lemma(win(N1)), lemma(win(N2)), lemma(win(N3)).

0 件のコメント: