Luninariel

Python Office Logic Template

Nov 6th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.03 KB | None | 0 0
  1. ##############################################
  2. # CSC 246 - Fall 2019
  3. # Missouri Western State University
  4. # Homework #4 - Logic Programming
  5. # Starter Template
  6. # Student(s):
  7.  
  8. from kanren import *
  9.  
  10. allgoals = []   # goals used to solve the logic puzzle
  11.  
  12.  
  13. def anon_employee():
  14.   return (var(), var(), var())
  15.  
  16. def set_fname(employee, name):
  17.   return (name, employee[1], employee[2])
  18.  
  19. def set_lname(employee, name):
  20.   return (employee[0], name, employee[2])
  21.  
  22. def set_job(employee, job):
  23.   return (employee[0], employee[1], job)
  24.  
  25.  
  26. # TODO: you can make the starting variables more specific
  27. #       this will make your program run more efficiently
  28. #       but be careful! don't solve the problem in your code...
  29. #       ... have your code solve the problem!
  30.  
  31.  
  32. # ex. Curtis ended up with a wall office.
  33. curtis = set_fname(anon_employee(), "curtis")
  34.  
  35. wallseats = (curtis, var(), var())  # employees with seats by the wall
  36. windowseats = (var(), var(), var()) # employees with seats by the window
  37. employees = wallseats + windowseats # all employees (same vars)
  38.  
  39.  
  40.  
  41.  
  42. # TODO: create more goal generating functions for use below
  43.  
  44. def has_wall_seat(employee):
  45.   """produces a goal expecting the employee to have a wall seat"""
  46.   return (membero, employee, wallseats)
  47.  
  48. def is_employee(employee):
  49.   """produces a goal asserting that 'employee' is one of the six employees in question"""
  50.   return (membero, employee, employees)
  51.  
  52. def is_male(employee):
  53.   """produces a goal asserting that the employee has one of the male first names"""
  54.   return (lany,
  55.             is_employee(set_fname(employee, "steve")),
  56.             is_employee(set_fname(employee, "curtis")),
  57.             is_employee(set_fname(employee, "dick")))
  58.  
  59.  
  60.  
  61. # TODO: add more goals below to force a solution to the puzzle
  62. #       you should end up with one unique solution if you do everything correctly
  63. #       however, your program will run much faster when you are further from the correct answer!
  64.  
  65. #The marketing analyst had a last name of Radcliffe.
  66. mx_radcliffe = set_lname(anon_employee(), "radcliffe")
  67. mx_radcliffe = set_job(mx_radcliffe, "marketing analyst")
  68. allgoals.append(is_employee(mx_radcliffe))
  69.  
  70.  
  71. #One product manager was male
  72. pm1 = set_job(anon_employee(), "product manager")
  73. allgoals.append(is_male(pm1))
  74.  
  75.  
  76. # TODO: nothing to change here, but consider setting the number of solutions to find to 1
  77. # if you want your program to run quickly for testing! A setting of 0 will determine if you're
  78. # 100% correct or not, but it may take a long time (or literally forever if you're wrong).
  79. print("**********************************")
  80. results = run(0, (wallseats, windowseats), (lall,) + tuple(allgoals))
  81. results = set(map(lambda x: (frozenset(x[0]), frozenset(x[1])), results))  # eliminate duplicates
  82. for (walls, windows) in results:
  83.   print("wall seats: ")
  84.   for employee in walls:
  85.     print(employee)
  86.   print("window seats: ")
  87.   for employee in windows:
  88.     print(employee)
  89.   print("-----------")
  90.  
  91.  
  92. print("number of results: " + str(len(results)))
Add Comment
Please, Sign In to add comment