1. Homepage
  2. Homework
  3. CS3342 Organization of Programming Languages - Assignment 4: Prolog
This question has been solved

CS3342 Organization of Programming Languages - Assignment 4: Prolog

Engage in a Conversation
UWOCS3342Organization of Programming LanguagesPrologKnights and Knaves puzzles

CS3342 – Assignment 4 CourseNana.COM


1. (50pt) Consider the following Prolog facts and rules:
CourseNana.COM

  member(H, [H|_]).
  member(H, [_|T]) :- member(H, T).
  unique(H, [H|T]) :- not(member(H, T)).
  unique(H, [_|T]).

Draw the Prolog tree corresponding to each of the following queries, explaining the effect of each cut: CourseNana.COM

  1. (a)  (15pt) CourseNana.COM

           ?- member(a, [a,b,a]).
           true ;
           true ;
           false.
    
  2. (b)  (17pt) CourseNana.COM

           ?- unique(a, [b,a,c]).
           true ;
           false.
    
  3. (c)  (18pt) CourseNana.COM

           ?- unique(a, [a,b,a]).
           false.
    

2. (50pt) Knights and Knaves puzzles: You are on an island where every inhabitant is either a knight or a knave. Knights always tell the truth, and knaves always lie. Implement the following puzzles in a Prolog program, kk.pl, which finds the correct answer(s); the program behaves as indicated below: CourseNana.COM

  1. (a)  Puzzle 1: You are approached by two people. The first one says: “We are both knaves”. What are they actually? CourseNana.COM

            puzzle_1 :- ....
    
            ?- puzzle_1.
           [a=Knave,b=Knight]
           false.
    
  2. (b)  Puzzle 2: You are approached by two people. The first one says: ”At least one of us is a knave”. What are they actually? CourseNana.COM

            puzzle_2 :- ....
           ?- puzzle_2.
           [a=Knight,b=Knave]
           false.
    

CourseNana.COM

(c) Puzzle 3: You are approached by two people. The first one says: ”Either I am a knave or B is a knight.”. What are they actually? CourseNana.COM

     puzzle_3 :- ....
    ?- puzzle_3.
    [a=Knight,b=Knight]
    false.

(d) Puzzle 4: You are approached by two people. The first one says: ”We are the same”. Is the other person a knight or a knave? CourseNana.COM

     puzzle_4 :- ....
    ?- puzzle_4.
    [a=Knave,b=Knight]
    [a=Knight,b=Knight]
    false.

!!! Submit two files: one pdf file with responses to Assignment 4 Q1 and one source code file, kk.pl, with code as required above to Assignment 4 Q2 (code); anything else receives 0pt. Solutions should be typed but high-quality hand-written solutions are acceptable. CourseNana.COM

Tools: You are allowed to use web resources, such as JFLAP, LLMs (e.g., ChatGPT), online Lambda calculators, etc., to help you solve the assignments. You still need to explain clearly your solution. Also, make sure you understand the answers as these tools will not be available during exams! CourseNana.COM

LATEX: For those interested, the best program for scientific writing is LATEX. It is far superior to all the other programs, it is free, and you can start using it in minutes; here is an introduction: https://tobi.oetiker.ch/lshort/lshort.pdf. It is also available online at https://www.overleaf.com/. CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
UWO代写,CS3342代写,Organization of Programming Languages代写,Prolog代写,Knights and Knaves puzzles代写,UWO代编,CS3342代编,Organization of Programming Languages代编,Prolog代编,Knights and Knaves puzzles代编,UWO代考,CS3342代考,Organization of Programming Languages代考,Prolog代考,Knights and Knaves puzzles代考,UWOhelp,CS3342help,Organization of Programming Languageshelp,Prologhelp,Knights and Knaves puzzleshelp,UWO作业代写,CS3342作业代写,Organization of Programming Languages作业代写,Prolog作业代写,Knights and Knaves puzzles作业代写,UWO编程代写,CS3342编程代写,Organization of Programming Languages编程代写,Prolog编程代写,Knights and Knaves puzzles编程代写,UWOprogramming help,CS3342programming help,Organization of Programming Languagesprogramming help,Prologprogramming help,Knights and Knaves puzzlesprogramming help,UWOassignment help,CS3342assignment help,Organization of Programming Languagesassignment help,Prologassignment help,Knights and Knaves puzzlesassignment help,UWOsolution,CS3342solution,Organization of Programming Languagessolution,Prologsolution,Knights and Knaves puzzlessolution,