This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Optional | |
def model(dark: int, milk: int, last: Optional[str] = None) -> float: | |
""" | |
Solves the Riddler Classic using dynamic programming. We start with a given number | |
of chocolates in the bag, and we draw one at a time. We track the last chocolate we | |
drew, and if we draw the same one, we eat it. Otherwise, we put it back in the bag | |
and reset the "last" value to None. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Solves the Riddler Classic from October 2, 2020. | |
https://fivethirtyeight.com/features/can-you-eat-all-the-chocolates/ | |
""" | |
from __future__ import annotations | |
from functools import lru_cache | |
from typing import List, NamedTuple, Optional, Tuple | |
class ChocolateBag(NamedTuple): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from itertools import groupby, product | |
def model(): | |
""" | |
Solves the Riddler Classic from October 26, 2018. | |
First, generate all valid hands. We only care about suits, | |
so we represent them using numbers 0, 1, 2, 3. There are | |
4096 unique hands we could generate, such as [0,0,0,0,0,0], |