Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
プロローグには、要素がリストのメンバーであるかどうかを確認し、リスト内の位置を書き込む必要がある小さなルールがありますが、探している要素が 1 か所にある場合にのみ機能します。助けが必要です!
write_element(X,[X|_],1). write_element(X,[_|Tail],N):- N1 is N-1, write_element(X,Tail,N1).
最初の位置でのみ機能していると報告しているため、他の場合に機能するようにコードを簡単に修正できます。
write_element(X,[X|_],1). write_element(X,[_|Tail],N):- write_element(X,Tail,N1), N is N1 + 1.
しかし、ダニエル (+1) からの答えは、あなたが研究すべきものです。