Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
fast solution in Speedy category for Unfair Dice by Sim0000
from itertools import combinations
def judge(p, e):
return sum((xp > xe) - (xp < xe) for xp in p for xe in e)
def winning_die(e):
n = len(e)
for i in range(n):
for j, k in combinations(range(n), 2):
p = e[:]
p[i] -= 2
p[j] += 1
p[k] += 1
if p[i] > 0 and judge(p, e) > 0: return p
return []
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: