#!/usr/bin/env python32
# from __future__ import division
from functools import lru_cache
def lose_condition(x):
return x<1
def action_A(x):
return x-1
def action_B(x):
return x/2
ACTIONS = (action_A, action_B)
@lru_cache(maxsize=100)
def detect_winner(n, cond=lose_condition, actions=ACTIONS):
if cond(n):
return True
return not all(detect_winner(action(n)) for action in actions)
if __name__ == '__main__':
assert not detect_winner(1)
assert not detect_winner(1.5)
assert detect_winner(2)
assert detect_winner(2.5)
assert detect_winner(3)
assert not detect_winner(4)
assert detect_winner(5)
assert not detect_winner(6)
print("OK")
IyEvdXNyL2Jpbi9lbnYgcHl0aG9uMzIKCiMgZnJvbSBfX2Z1dHVyZV9fIGltcG9ydCBkaXZpc2lvbgpmcm9tIGZ1bmN0b29scyBpbXBvcnQgbHJ1X2NhY2hlCgpkZWYgbG9zZV9jb25kaXRpb24oeCk6CiAgcmV0dXJuIHg8MQoKZGVmIGFjdGlvbl9BKHgpOgogIHJldHVybiB4LTEKCmRlZiBhY3Rpb25fQih4KToKICByZXR1cm4geC8yCgpBQ1RJT05TID0gKGFjdGlvbl9BLCBhY3Rpb25fQikKCkBscnVfY2FjaGUobWF4c2l6ZT0xMDApCmRlZiBkZXRlY3Rfd2lubmVyKG4sIGNvbmQ9bG9zZV9jb25kaXRpb24sIGFjdGlvbnM9QUNUSU9OUyk6CiAgaWYgY29uZChuKToKICAgIHJldHVybiBUcnVlCiAgcmV0dXJuIG5vdCBhbGwoZGV0ZWN0X3dpbm5lcihhY3Rpb24obikpIGZvciBhY3Rpb24gaW4gYWN0aW9ucykKCmlmIF9fbmFtZV9fID09ICdfX21haW5fXyc6CgogIGFzc2VydCBub3QgZGV0ZWN0X3dpbm5lcigxKQogIGFzc2VydCBub3QgZGV0ZWN0X3dpbm5lcigxLjUpCiAgYXNzZXJ0IGRldGVjdF93aW5uZXIoMikKICBhc3NlcnQgZGV0ZWN0X3dpbm5lcigyLjUpCiAgYXNzZXJ0IGRldGVjdF93aW5uZXIoMykKICBhc3NlcnQgbm90IGRldGVjdF93aW5uZXIoNCkKICBhc3NlcnQgZGV0ZWN0X3dpbm5lcig1KQogIGFzc2VydCBub3QgZGV0ZWN0X3dpbm5lcig2KQogIHByaW50KCJPSyIpCg==