52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
|
|
"""
|
||
|
|
name: Nicholas Tamassia
|
||
|
|
|
||
|
|
Honor Code and Acknowledgments:
|
||
|
|
|
||
|
|
This work complies with the JMU Honor Code.
|
||
|
|
|
||
|
|
Comments here on your code and submission.
|
||
|
|
"""
|
||
|
|
|
||
|
|
from itertools import product
|
||
|
|
from typing import Callable
|
||
|
|
|
||
|
|
type Three_SAT = Callable[[bool, bool, bool], bool]
|
||
|
|
|
||
|
|
|
||
|
|
def three_sat_missing(x1: bool, x2: bool, x3: bool) -> bool:
|
||
|
|
combos = product([x1, not x1], [x2, not x2], [x3, not x3])
|
||
|
|
# Remove the last clause
|
||
|
|
missing_combo = list(combos)[:-1]
|
||
|
|
return all(a or b or c for a, b, c in missing_combo)
|
||
|
|
|
||
|
|
|
||
|
|
def three_sat(x1: bool, x2: bool, x3: bool) -> bool:
|
||
|
|
return all(
|
||
|
|
a or b or c for a, b, c in product([x1, not x1], [x2, not x2], [x3, not x3])
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
# All modules for CS 412 must include a main method that allows it
|
||
|
|
# to imported and invoked from other python scripts
|
||
|
|
def main():
|
||
|
|
settings = product([False, True], repeat=3)
|
||
|
|
|
||
|
|
sentences_satisfied: dict[Three_SAT, bool] = {}
|
||
|
|
sentences_satisfied[three_sat] = False
|
||
|
|
sentences_satisfied[three_sat_missing] = False
|
||
|
|
|
||
|
|
for setting in settings:
|
||
|
|
for sentence in sentences_satisfied:
|
||
|
|
if sentence(*setting):
|
||
|
|
print(f"{setting} satisfied {sentence.__name__}")
|
||
|
|
sentences_satisfied[sentence] = True
|
||
|
|
|
||
|
|
for sentence, satisfied in sentences_satisfied.items():
|
||
|
|
if not satisfied:
|
||
|
|
print(f"{sentence.__name__} is not satisfiable")
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|