Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def process2(s, part2=False):
- lines = s.strip('\n').split('\n')
- pos0, pos1 = int(lines[0][27:]) - 1, int(lines[1][27:]) - 1
- die_sum_distribution = collections.Counter(
- sum(die) for die in itertools.product([1, 2, 3], repeat=3))
- @functools.lru_cache(maxsize=None)
- def compute(pos0, pos1, score0, score1):
- wins0 = wins1 = 0
- for total, count in die_sum_distribution.items():
- new_pos0 = (pos0 + total) % 10
- new_score0 = score0 + (new_pos0 + 1)
- if new_score0 >= 21:
- wins0 += count
- else:
- d_wins1, d_wins0 = compute(pos1, new_pos0, score1, new_score0)
- wins0 += d_wins0 * count
- wins1 += d_wins1 * count
- return wins0, wins1
- return max(*compute(pos0, pos1, 0, 0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement