Puzzle Nekst 1 2021-2022
Last year Microsoft organised a hackathon. The attendees made puzzles to test AI’s programming proficiency. Each puzzle takes the form of a Python function that takes an answer as an argument. The answer is an input which makes the function return True. This is called satisfying the puzzle, and that is why the puzzles are all named sat. Can you figure out a required input for the functions?
Example excersise
def sat(x: str):
return 'Hello ' + x[::-1] == 'Hello world'
Solution
def reverse(s):
return s[::-1]
sat(reverse("world"))
Puzzle 1
def sat(x):
try:
x(123)
return False
except RandomException:
return True
except:
return False
Puzzle 2
def sat(one, two, three):
return one(two) == three
and one(two(three)) == two
and two != three
Puzzle 3
def sat(x):
return x > x and x + 1 == x
Solution
Puzzle 1
class RandomException(Exception):
pass
def foo(string):
raise RandomException
sat(foo)
Puzzle 2
def how(x):
return 1 if x is dee else dee
def dee(x):
return x
sat(how, dee, 1)
Puzzle 3
class Var:
def __gt__(self, other):
return True
def __add__(self, other):
return 1
def __eq__(self, other):
return True
bob = Var()
sat(bob)