def cd_solve(self, message): """[target] [numbers]* -> attempts to reach the target using only the available numbers once each. a solver for the countdown numbers game""" target, *numbers = [int(x) for x in message.text.split()] if len(numbers) > 6: raise Exception("too many numbers") expr, value = solve(target, numbers) if value == target: return message.reply("Solution: " + expr + " = " + str(target)) else: return message.reply("closest: " + expr + " = " + str(value))
def giveup(self, message): """gives up the current game in the channel, and attempts to solve it""" if self.games[message.params]: target = self.games[message.params].target numbers = self.games[message.params].numbers expr, value = solve(target, numbers) del self.games[message.params] if value == target: return message.reply("Solution: " + expr + " = " + str(target)) else: return message.reply("closest: " + expr + " = " + str(value)) else: return message.reply("no game running")