Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Exhaustive solution in Uncategorized category for Unfair Dice by Sim0000
def winning_die(enemy_die):
def judge(p, e):
return sum((xp > xe) - (xp < xe) for xp in p for xe in e)
def seek(n, player, remain, last):
if n == 1:
player.append(remain)
return player if judge(player, enemy_die) > 0 else []
for i in range(last, remain // n + 1):
rc = seek(n - 1, player + [i], remain - i, i)
if rc: break
return rc
return seek(len(enemy_die), [], sum(enemy_die), 1)
if __name__ == '__main__':
#These are only used for self-checking and not necessary for auto-testing
def check_solution(func, enemy):
player = func(enemy)
total = 0
for p in player:
for e in enemy:
if p > e:
total += 1
elif p < e:
total -= 1
return total > 0
assert check_solution(winning_die, [3, 3, 3, 3, 6, 6]), "Threes and Sixes"
assert check_solution(winning_die, [4, 4, 4, 4, 4, 4]), "All Fours"
assert check_solution(winning_die, [1, 1, 1, 4]), "Unities and Four"
assert winning_die([1, 2, 3, 4, 5, 6]) == [], "All in row -- No die"
June 4, 2014
Comments: