[考題] 程式語言考古題

看板Examination作者 (PS)時間10年前 (2015/06/24 17:14), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串3/4 (看更多)
◎高考三級/資訊處理/102年 第五題 考慮下述Prolog程式: ancestor(x,x). ancestor(x,y) :- ancestor(z,y), parent(x,z). parent(Allen, John). 用一個subgoal的搜尋樹(search tree),描述此Prolog程式在執行查詢: ancestor(Allen,X)時的執行步驟。 Ans: (高上的解答是) ancestor(Allen,X) → ancestor(Allen, Allen) {X = Allen} failure → ancestor(Allen, John) {X = John} →ancestor(Z, John), parent(Allen, Z) {Z = John} →ancestor(John, John) {Z = John} success →ancestor(Allen, John) {Z = John} success (實際用prolog得到的結果是) 1 ?- ancestor(Allen,X). Allen = X, X = x ============================================ 請問版上高手,哪個才是對的。 又如果prolog的結果是對的,那執行步驟為何? 感謝回答。 ============================================ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.163.171.166 ※ 文章網址: https://www.ptt.cc/bbs/Examination/M.1435137241.A.D94.html

06/25 00:57, , 1F
補習班錯了
06/25 00:57, 1F

06/25 01:25, , 2F
還有公X王網路上那的答案也是錯的
06/25 01:25, 2F

06/25 19:28, , 3F
補習班的答案錯
06/25 19:28, 3F
文章代碼(AID): #1LYdJPsK (Examination)
文章代碼(AID): #1LYdJPsK (Examination)