Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##############################################
- # CSC 246 - Fall 2019
- # Missouri Western State University
- # Homework #4 - Logic Programming
- # Starter Template
- # Student(s):
- from kanren import *
- allgoals = [] # goals used to solve the logic puzzle
- def anon_employee():
- return (var(), var(), var())
- def set_fname(employee, name):
- return (name, employee[1], employee[2])
- def set_lname(employee, name):
- return (employee[0], name, employee[2])
- def set_job(employee, job):
- return (employee[0], employee[1], job)
- # TODO: you can make the starting variables more specific
- # this will make your program run more efficiently
- # but be careful! don't solve the problem in your code...
- # ... have your code solve the problem!
- # ex. Curtis ended up with a wall office.
- curtis = set_fname(anon_employee(), "curtis")
- wallseats = (curtis, var(), var()) # employees with seats by the wall
- windowseats = (var(), var(), var()) # employees with seats by the window
- employees = wallseats + windowseats # all employees (same vars)
- # TODO: create more goal generating functions for use below
- def has_wall_seat(employee):
- """produces a goal expecting the employee to have a wall seat"""
- return (membero, employee, wallseats)
- def is_employee(employee):
- """produces a goal asserting that 'employee' is one of the six employees in question"""
- return (membero, employee, employees)
- def is_male(employee):
- """produces a goal asserting that the employee has one of the male first names"""
- return (lany,
- is_employee(set_fname(employee, "steve")),
- is_employee(set_fname(employee, "curtis")),
- is_employee(set_fname(employee, "dick")))
- # TODO: add more goals below to force a solution to the puzzle
- # you should end up with one unique solution if you do everything correctly
- # however, your program will run much faster when you are further from the correct answer!
- #The marketing analyst had a last name of Radcliffe.
- mx_radcliffe = set_lname(anon_employee(), "radcliffe")
- mx_radcliffe = set_job(mx_radcliffe, "marketing analyst")
- allgoals.append(is_employee(mx_radcliffe))
- #One product manager was male
- pm1 = set_job(anon_employee(), "product manager")
- allgoals.append(is_male(pm1))
- # TODO: nothing to change here, but consider setting the number of solutions to find to 1
- # if you want your program to run quickly for testing! A setting of 0 will determine if you're
- # 100% correct or not, but it may take a long time (or literally forever if you're wrong).
- print("**********************************")
- results = run(0, (wallseats, windowseats), (lall,) + tuple(allgoals))
- results = set(map(lambda x: (frozenset(x[0]), frozenset(x[1])), results)) # eliminate duplicates
- for (walls, windows) in results:
- print("wall seats: ")
- for employee in walls:
- print(employee)
- print("window seats: ")
- for employee in windows:
- print(employee)
- print("-----------")
- print("number of results: " + str(len(results)))
Add Comment
Please, Sign In to add comment