Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def process2(s): # Avoiding functools.lru_cache().
- lines = s.strip('\n').split('\n')
- pos = [int(lines[0][27:]), int(lines[1][27:])]
- die_sum_distribution = collections.Counter(
- sum(die) for die in itertools.product([1, 2, 3], repeat=3))
- # Count of wins for [score0, score1, pos0, pos1, player]
- wins = np.zeros((21, 21, 10, 10, 2), dtype=np.int64)
- for total_score in range(40, -1, -1):
- for score0 in range(min(20, total_score), max(total_score - 21, -1), -1):
- score1 = total_score - score0
- for total, count in die_sum_distribution.items():
- for pos0 in range(10):
- new_pos0 = (pos0 + total) % 10
- new_score0 = score0 + (new_pos0 + 1)
- if new_score0 >= 21:
- wins[score0, score1, pos0, :, 0] += count
- else:
- wins[score0, score1, pos0, :, :] += count * (
- wins[score1, new_score0, :, new_pos0, ::-1])
- return wins[0, 0, pos[0] - 1, pos[1] - 1].max()
Add Comment
Please, Sign In to add comment