From b790dc93f2b97e66eec7e9a8748325da405685cf Mon Sep 17 00:00:00 2001 From: Dazbo Date: Sun, 22 Dec 2024 16:27:09 +0000 Subject: [PATCH] Pt 2 works, but it's too slow --- .../Dazbo's_Advent_of_Code_2024.ipynb | 376 ++++-------------- 1 file changed, 78 insertions(+), 298 deletions(-) diff --git a/src/AoC_2024/Dazbo's_Advent_of_Code_2024.ipynb b/src/AoC_2024/Dazbo's_Advent_of_Code_2024.ipynb index dcae406..8817e2a 100644 --- a/src/AoC_2024/Dazbo's_Advent_of_Code_2024.ipynb +++ b/src/AoC_2024/Dazbo's_Advent_of_Code_2024.ipynb @@ -48,131 +48,12 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "id": "9Dgeww1rMrkQ", "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: jupyterlab-lsp in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (5.1.0)\n", - "Requirement already satisfied: ipykernel in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (6.29.5)\n", - "Requirement already satisfied: ipywidgets in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (8.1.5)\n", - "Requirement already satisfied: matplotlib in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (3.10.0)\n", - "Requirement already satisfied: pandas in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (2.2.3)\n", - "Requirement already satisfied: networkx in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (3.4.2)\n", - "Requirement already satisfied: sympy in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (1.13.3)\n", - "Requirement already satisfied: dazbo-commons in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (0.1.5)\n", - "Requirement already satisfied: colorama in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (0.4.6)\n", - "Requirement already satisfied: python-dotenv in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (1.0.1)\n", - "Requirement already satisfied: tqdm in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (4.67.1)\n", - "Requirement already satisfied: jupyter-lsp>=2.0.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyterlab-lsp) (2.2.5)\n", - "Requirement already satisfied: jupyterlab<5.0.0a0,>=4.1.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyterlab-lsp) (4.3.0)\n", - "Requirement already satisfied: comm>=0.1.1 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipykernel) (0.2.2)\n", - "Requirement already satisfied: debugpy>=1.6.5 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipykernel) (1.8.8)\n", - "Requirement already satisfied: ipython>=7.23.1 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipykernel) (8.29.0)\n", - "Requirement already satisfied: jupyter-client>=6.1.12 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipykernel) (8.6.3)\n", - "Requirement already satisfied: jupyter-core!=5.0.*,>=4.12 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipykernel) (5.7.2)\n", - "Requirement already satisfied: matplotlib-inline>=0.1 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipykernel) (0.1.7)\n", - "Requirement already satisfied: nest-asyncio in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipykernel) (1.6.0)\n", - "Requirement already satisfied: packaging in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipykernel) (24.1)\n", - "Requirement already satisfied: psutil in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipykernel) (6.1.0)\n", - "Requirement already satisfied: pyzmq>=24 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipykernel) (26.2.0)\n", - "Requirement already satisfied: tornado>=6.1 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipykernel) (6.4.1)\n", - "Requirement already satisfied: traitlets>=5.4.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipykernel) (5.14.3)\n", - "Requirement already satisfied: widgetsnbextension~=4.0.12 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipywidgets) (4.0.13)\n", - "Requirement already satisfied: jupyterlab-widgets~=3.0.12 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipywidgets) (3.0.13)\n", - "Requirement already satisfied: contourpy>=1.0.1 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from matplotlib) (1.3.1)\n", - "Requirement already satisfied: cycler>=0.10 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from matplotlib) (0.12.1)\n", - "Requirement already satisfied: fonttools>=4.22.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from matplotlib) (4.54.1)\n", - "Requirement already satisfied: kiwisolver>=1.3.1 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from matplotlib) (1.4.7)\n", - "Requirement already satisfied: numpy>=1.23 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from matplotlib) (2.1.3)\n", - "Requirement already satisfied: pillow>=8 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from matplotlib) (11.0.0)\n", - "Requirement already satisfied: pyparsing>=2.3.1 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from matplotlib) (3.2.0)\n", - "Requirement already satisfied: python-dateutil>=2.7 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from matplotlib) (2.9.0)\n", - "Requirement already satisfied: pytz>=2020.1 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from pandas) (2024.2)\n", - "Requirement already satisfied: tzdata>=2022.7 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from pandas) (2024.2)\n", - "Requirement already satisfied: mpmath<1.4,>=1.1.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from sympy) (1.3.0)\n", - "Requirement already satisfied: decorator in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipython>=7.23.1->ipykernel) (5.1.1)\n", - "Requirement already satisfied: jedi>=0.16 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipython>=7.23.1->ipykernel) (0.19.2)\n", - "Requirement already satisfied: prompt-toolkit<3.1.0,>=3.0.41 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipython>=7.23.1->ipykernel) (3.0.48)\n", - "Requirement already satisfied: pygments>=2.4.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipython>=7.23.1->ipykernel) (2.18.0)\n", - "Requirement already satisfied: stack-data in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipython>=7.23.1->ipykernel) (0.6.2)\n", - "Requirement already satisfied: pexpect>4.3 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from ipython>=7.23.1->ipykernel) (4.9.0)\n", - "Requirement already satisfied: platformdirs>=2.5 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyter-core!=5.0.*,>=4.12->ipykernel) (4.3.6)\n", - "Requirement already satisfied: jupyter-server>=1.1.2 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyter-lsp>=2.0.0->jupyterlab-lsp) (2.14.2)\n", - "Requirement already satisfied: async-lru>=1.0.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (2.0.4)\n", - "Requirement already satisfied: httpx>=0.25.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (0.27.2)\n", - "Requirement already satisfied: jinja2>=3.0.3 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (3.1.4)\n", - "Requirement already satisfied: jupyterlab-server<3,>=2.27.1 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (2.27.3)\n", - "Requirement already satisfied: notebook-shim>=0.2 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (0.2.4)\n", - "Requirement already satisfied: setuptools>=40.1.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (75.1.0)\n", - "Requirement already satisfied: six>=1.5 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from python-dateutil>=2.7->matplotlib) (1.16.0)\n", - "Requirement already satisfied: anyio in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from httpx>=0.25.0->jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (4.6.2.post1)\n", - "Requirement already satisfied: certifi in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from httpx>=0.25.0->jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (2024.8.30)\n", - "Requirement already satisfied: httpcore==1.* in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from httpx>=0.25.0->jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (1.0.6)\n", - "Requirement already satisfied: idna in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from httpx>=0.25.0->jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (3.10)\n", - "Requirement already satisfied: sniffio in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from httpx>=0.25.0->jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (1.3.1)\n", - "Requirement already satisfied: h11<0.15,>=0.13 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from httpcore==1.*->httpx>=0.25.0->jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (0.14.0)\n", - "Requirement already satisfied: parso<0.9.0,>=0.8.4 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jedi>=0.16->ipython>=7.23.1->ipykernel) (0.8.4)\n", - "Requirement already satisfied: MarkupSafe>=2.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jinja2>=3.0.3->jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (3.0.2)\n", - "Requirement already satisfied: argon2-cffi>=21.1 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (23.1.0)\n", - "Requirement already satisfied: jupyter-events>=0.9.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (0.10.0)\n", - "Requirement already satisfied: jupyter-server-terminals>=0.4.4 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (0.5.3)\n", - "Requirement already satisfied: nbconvert>=6.4.4 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (7.16.4)\n", - "Requirement already satisfied: nbformat>=5.3.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (5.10.4)\n", - "Requirement already satisfied: overrides>=5.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (7.7.0)\n", - "Requirement already satisfied: prometheus-client>=0.9 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (0.21.0)\n", - "Requirement already satisfied: send2trash>=1.8.2 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (1.8.3)\n", - "Requirement already satisfied: terminado>=0.8.3 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (0.18.1)\n", - "Requirement already satisfied: websocket-client>=1.7 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (1.8.0)\n", - "Requirement already satisfied: babel>=2.10 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyterlab-server<3,>=2.27.1->jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (2.16.0)\n", - "Requirement already satisfied: json5>=0.9.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyterlab-server<3,>=2.27.1->jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (0.9.28)\n", - "Requirement already satisfied: jsonschema>=4.18.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyterlab-server<3,>=2.27.1->jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (4.23.0)\n", - "Requirement already satisfied: requests>=2.31 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyterlab-server<3,>=2.27.1->jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (2.32.3)\n", - "Requirement already satisfied: ptyprocess>=0.5 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from pexpect>4.3->ipython>=7.23.1->ipykernel) (0.7.0)\n", - "Requirement already satisfied: wcwidth in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from prompt-toolkit<3.1.0,>=3.0.41->ipython>=7.23.1->ipykernel) (0.2.13)\n", - "Requirement already satisfied: executing>=1.2.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from stack-data->ipython>=7.23.1->ipykernel) (2.1.0)\n", - "Requirement already satisfied: asttokens>=2.1.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from stack-data->ipython>=7.23.1->ipykernel) (2.4.1)\n", - "Requirement already satisfied: pure-eval in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from stack-data->ipython>=7.23.1->ipykernel) (0.2.3)\n", - "Requirement already satisfied: argon2-cffi-bindings in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from argon2-cffi>=21.1->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (21.2.0)\n", - "Requirement already satisfied: attrs>=22.2.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (24.2.0)\n", - "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (2024.10.1)\n", - "Requirement already satisfied: referencing>=0.28.4 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (0.35.1)\n", - "Requirement already satisfied: rpds-py>=0.7.1 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (0.21.0)\n", - "Requirement already satisfied: python-json-logger>=2.0.4 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyter-events>=0.9.0->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (2.0.7)\n", - "Requirement already satisfied: pyyaml>=5.3 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyter-events>=0.9.0->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (6.0.2)\n", - "Requirement already satisfied: rfc3339-validator in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyter-events>=0.9.0->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (0.1.4)\n", - "Requirement already satisfied: rfc3986-validator>=0.1.1 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jupyter-events>=0.9.0->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (0.1.1)\n", - "Requirement already satisfied: beautifulsoup4 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from nbconvert>=6.4.4->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (4.12.3)\n", - "Requirement already satisfied: bleach!=5.0.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from nbconvert>=6.4.4->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (6.2.0)\n", - "Requirement already satisfied: defusedxml in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from nbconvert>=6.4.4->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (0.7.1)\n", - "Requirement already satisfied: jupyterlab-pygments in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from nbconvert>=6.4.4->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (0.3.0)\n", - "Requirement already satisfied: mistune<4,>=2.0.3 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from nbconvert>=6.4.4->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (3.0.2)\n", - "Requirement already satisfied: nbclient>=0.5.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from nbconvert>=6.4.4->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (0.10.0)\n", - "Requirement already satisfied: pandocfilters>=1.4.1 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from nbconvert>=6.4.4->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (1.5.1)\n", - "Requirement already satisfied: tinycss2 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from nbconvert>=6.4.4->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (1.4.0)\n", - "Requirement already satisfied: fastjsonschema>=2.15 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from nbformat>=5.3.0->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (2.20.0)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from requests>=2.31->jupyterlab-server<3,>=2.27.1->jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (3.4.0)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from requests>=2.31->jupyterlab-server<3,>=2.27.1->jupyterlab<5.0.0a0,>=4.1.0->jupyterlab-lsp) (2.2.3)\n", - "Requirement already satisfied: webencodings in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from bleach!=5.0.0->nbconvert>=6.4.4->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (0.5.1)\n", - "Requirement already satisfied: fqdn in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.0->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (1.5.1)\n", - "Requirement already satisfied: isoduration in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.0->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (20.11.0)\n", - "Requirement already satisfied: jsonpointer>1.13 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.0->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (3.0.0)\n", - "Requirement already satisfied: uri-template in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.0->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (1.3.0)\n", - "Requirement already satisfied: webcolors>=24.6.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.0->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (24.11.1)\n", - "Requirement already satisfied: cffi>=1.0.1 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from argon2-cffi-bindings->argon2-cffi>=21.1->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (1.17.1)\n", - "Requirement already satisfied: soupsieve>1.2 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from beautifulsoup4->nbconvert>=6.4.4->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (2.6)\n", - "Requirement already satisfied: pycparser in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from cffi>=1.0.1->argon2-cffi-bindings->argon2-cffi>=21.1->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (2.22)\n", - "Requirement already satisfied: arrow>=0.15.0 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from isoduration->jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.0->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (1.3.0)\n", - "Requirement already satisfied: types-python-dateutil>=2.8.10 in /home/darren/miniconda3/envs/.aoc-conda-env/lib/python3.13/site-packages (from arrow>=0.15.0->isoduration->jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.0->jupyter-server>=1.1.2->jupyter-lsp>=2.0.0->jupyterlab-lsp) (2.9.0.20241003)\n", - "Note: you may need to restart the kernel to use updated packages.\n" - ] - } - ], + "outputs": [], "source": [ "%pip install --upgrade --no-cache-dir \\\n", " jupyterlab-lsp ipykernel ipywidgets \\\n", @@ -183,7 +64,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 110, "metadata": { "id": "p5Ki_HvOJUWk", "tags": [] @@ -209,7 +90,7 @@ "from getpass import getpass\n", "from numbers import Number\n", "from pathlib import Path\n", - "from typing import NamedTuple, ClassVar, Iterator\n", + "from typing import NamedTuple, ClassVar, Iterator, Iterable\n", "\n", "# Third-party imports\n", "import dazbo_commons as dc # my own utility library, which includes things like coloured logging\n", @@ -243,21 +124,12 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": { "id": "SwzjfUFCKhXe", "tags": [] }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[32m08:32:35.419:aoc2024 - INF: Logger initialised.\u001b[39m\n", - "\u001b[34m08:32:35.420:aoc2024 - DBG: Debugging enabled\u001b[39m\n" - ] - } - ], + "outputs": [], "source": [ "# Setup logger\n", "YEAR = 2024\n", @@ -280,32 +152,9 @@ }, { "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[34m08:32:35.430:aoc2024 - DBG: Checking if ffmpeg is installed\u001b[39m\n", - "\u001b[34m08:32:35.478:aoc2024 - DBG: ffmpeg version: ffmpeg version 6.1.1-3ubuntu5 Copyright (c) 2000-2023 the FFmpeg developers\n", - "built with gcc 13 (Ubuntu 13.2.0-23ubuntu3)\n", - "configuration: --prefix=/usr --extra-version=3ubuntu5 --toolchain=hardened --libdir=/usr/lib/aarch64-linux-gnu --incdir=/usr/include/aarch64-linux-gnu --arch=arm64 --enable-gpl --disable-stripping --disable-omx --enable-gnutls --enable-libaom --enable-libass --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libglslang --enable-libgme --enable-libgsm --enable-libharfbuzz --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-openal --enable-opencl --enable-opengl --disable-sndio --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-ladspa --enable-libbluray --enable-libjack --enable-libpulse --enable-librabbitmq --enable-librist --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libx264 --enable-libzmq --enable-libzvbi --enable-lv2 --enable-sdl2 --enable-libplacebo --enable-librav1e --enable-pocketsphinx --enable-librsvg --enable-libjxl --enable-shared\n", - "libavutil 58. 29.100 / 58. 29.100\n", - "libavcodec 60. 31.102 / 60. 31.102\n", - "libavformat 60. 16.100 / 60. 16.100\n", - "libavdevice 60. 3.100 / 60. 3.100\n", - "libavfilter 9. 12.100 / 9. 12.100\n", - "libswscale 7. 5.100 / 7. 5.100\n", - "libswresample 4. 12.100 / 4. 12.100\n", - "libpostproc 57. 3.100 / 57. 3.100\u001b[39m\n", - "\u001b[34m08:32:35.479:aoc2024 - DBG: ffmpeg is already installed.\u001b[39m\n", - "\u001b[34m08:32:35.479:aoc2024 - DBG: Checking if dot is installed\u001b[39m\n", - "\u001b[34m08:32:35.485:aoc2024 - DBG: dot is not installed or absent from path.\u001b[39m\n", - "\u001b[32m08:32:35.485:aoc2024 - INF: Installing graphviz on Linux...\u001b[39m\n" - ] - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "import subprocess\n", "\n", @@ -782,22 +631,9 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "KeyError", - "evalue": "'AOC_SESSION_COOKIE'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[63], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mdel\u001b[39;00m \u001b[43mos\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43menviron\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mAOC_SESSION_COOKIE\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\n", - "File \u001b[0;32m:732\u001b[0m, in \u001b[0;36m__delitem__\u001b[0;34m(self, key)\u001b[0m\n", - "\u001b[0;31mKeyError\u001b[0m: 'AOC_SESSION_COOKIE'" - ] - } - ], + "outputs": [], "source": [ "del os.environ['AOC_SESSION_COOKIE']" ] @@ -8296,22 +8132,9 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "#### See [Day 22](https://adventofcode.com/2024/day/22)." - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "DAY = \"22\" # replace with actual number (without leading digit)\n", "show_day_link(DAY)" @@ -8319,29 +8142,9 @@ }, { "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[34m08:42:49.625:aoc2024 - DBG: input.txt already exists\u001b[39m\n", - "\u001b[32m08:42:49.632:aoc2024 - INF: Input data:\n", - " 1: 4688826\n", - " 2: 16200140\n", - " 3: 16105529\n", - " 4: 14489781\n", - " 5: 6567477\n", - "...\n", - "2004: 11798329\n", - "2005: 16268496\n", - "2006: 599307\n", - "2007: 1916773\n", - "2008: 666746\u001b[39m\n" - ] - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "d_name = \"d\" + str(DAY).zfill(2) # e.g. d01\n", "script_name = \"aoc\" + str(YEAR) + d_name # e.g. aoc2024d01\n", @@ -8440,32 +8243,9 @@ }, { "cell_type": "code", - "execution_count": 71, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[34m10:12:49.786:aoc2024 - DBG: initial_secrets=[1, 10, 100, 2024]\u001b[39m\n", - "\u001b[34m10:12:49.787:aoc2024 - DBG: secret=1\u001b[39m\n", - "\u001b[34m10:12:49.788:aoc2024 - DBG: secret=10\u001b[39m\n", - "\u001b[34m10:12:49.789:aoc2024 - DBG: secret=100\u001b[39m\n", - "\u001b[34m10:12:49.790:aoc2024 - DBG: secret=2024\u001b[39m\n", - "\u001b[32m10:12:49.792:aoc2024 - INF: Test passed\u001b[39m\n", - "\u001b[32m10:12:49.792:aoc2024 - INF: All tests passed!\u001b[39m\n", - "\u001b[32m10:12:51.487:aoc2024 - INF: Part 1 soln=16953639210\u001b[39m\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "CPU times: user 1.6 s, sys: 204 ms, total: 1.8 s\n", - "Wall time: 1.7 s\n" - ] - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "%%time\n", "sample_inputs = []\n", @@ -8530,78 +8310,78 @@ }, { "cell_type": "code", - "execution_count": 90, + "execution_count": 156, "metadata": {}, "outputs": [], "source": [ + "CHANGES_SEQ_LEN = 4\n", + "SECRETS = 2000\n", + "\n", "def solve_part2(data):\n", - " CHANGES_SEQ_LEN = 4\n", - " \n", " initial_secrets = list(map(int, data))\n", " logger.debug(f\"{initial_secrets=}\")\n", " \n", - " prices_for_buyer = defaultdict(list)\n", - " diffs_for_buyer = {}\n", - " change_sequences = []\n", - " bananas = 0\n", + " prices_for_buyer: dict[int, list[int]] = defaultdict(list)\n", + " diffs_for_buyer: dict[int, list[int]] = {}\n", + " all_change_sequences: set[tuple[int]] = set()\n", " \n", " secret = 123\n", - " for buyer, secret in enumerate([123]): # Test buyer\n", - " # for buyer, secret in enumerate(initial_secrets):\n", + " # for buyer, secret in enumerate([123]): # Test buyer\n", + " for buyer, secret in enumerate(initial_secrets):\n", " logger.debug(f\"{buyer=},{secret=}\")\n", - " for price in range(10+1):\n", + " \n", + " # list the first n prices for this buyer\n", + " for price in range(SECRETS+1):\n", " prices_for_buyer[buyer].append(secret % 10) # Get units column\n", " secret = generate_next_secret(secret)\n", + " \n", + " # logger.debug(f\"For {buyer=}, prices_for_buyer: {prices_for_buyer[buyer]}\")\n", + " \n", + " # determine the diffs between each price for this buyer\n", + " diffs_for_buyer[buyer] = tuple(j-i for i, j in zip(prices_for_buyer[buyer], prices_for_buyer[buyer][1:]))\n", + " assert len(diffs_for_buyer[buyer]) == SECRETS, f\"Should be {SECRETS} diffs\"\n", + " \n", + " # logger.debug(f\"For {buyer=}, diffs_for_buyer: {diffs_for_buyer[buyer]}\")\n", + " # for price, diff in zip(prices_for_buyer[buyer], diffs_for_buyer[buyer]):\n", + " # logger.debug(f\"{price=}, {diff=}\")\n", + " \n", + " # Add sequences into set\n", + " all_change_sequences.update(diffs_for_buyer[buyer][i:i+CHANGES_SEQ_LEN] \n", + " for i in range(len(diffs_for_buyer[buyer])-CHANGES_SEQ_LEN+1))\n", + " \n", + " # logger.debug(all_change_sequences)\n", + " \n", + " bananas_for_seq = defaultdict(int)\n", + " # Check if / where this seq appears in changes for each buyer\n", + " for seq in tqdm(all_change_sequences):\n", + " for buyer, diffs in diffs_for_buyer.items():\n", + " if chg_idx := index_seq_complete(seq, diffs):\n", + " bananas_for_seq[seq] += prices_for_buyer[buyer][chg_idx+1]\n", + " \n", + " # logger.debug(f\"{bananas_for_seq=}\")\n", + " most_bananas = max(bananas_for_seq.items(), key=lambda x: x[1])\n", + " logger.debug(f\"{most_bananas=}\")\n", + " \n", + " return most_bananas[1]\n", " \n", - " diffs_for_buyer[buyer] = [j-i for i, j in zip(prices_for_buyer[buyer], prices_for_buyer[buyer][1:])]\n", - " \n", - " for price, diff in zip(prices_for_buyer[buyer], diffs_for_buyer[buyer]):\n", - " logger.debug(f\"{price=}, {diff=}\")\n", - " \n", - " # Add sequences into flattened list\n", - " change_sequences += [diffs_for_buyer[buyer][i:i+CHANGES_SEQ_LEN] \n", - " for i in range(len(diffs_for_buyer[buyer])-CHANGES_SEQ_LEN+1)]\n", - " \n", - " logger.debug(change_sequences) # return totals\n" - ] - }, - { - "cell_type": "code", - "execution_count": 91, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[34m10:36:18.608:aoc2024 - DBG: initial_secrets=[1, 2, 3, 2024]\u001b[39m\n", - "\u001b[34m10:36:18.609:aoc2024 - DBG: buyer=0,secret=123\u001b[39m\n", - "\u001b[34m10:36:18.610:aoc2024 - DBG: price=3, diff=-3\u001b[39m\n", - "\u001b[34m10:36:18.611:aoc2024 - DBG: price=0, diff=6\u001b[39m\n", - "\u001b[34m10:36:18.611:aoc2024 - DBG: price=6, diff=-1\u001b[39m\n", - "\u001b[34m10:36:18.611:aoc2024 - DBG: price=5, diff=-1\u001b[39m\n", - "\u001b[34m10:36:18.612:aoc2024 - DBG: price=4, diff=0\u001b[39m\n", - "\u001b[34m10:36:18.612:aoc2024 - DBG: price=4, diff=2\u001b[39m\n", - "\u001b[34m10:36:18.612:aoc2024 - DBG: price=6, diff=-2\u001b[39m\n", - "\u001b[34m10:36:18.613:aoc2024 - DBG: price=4, diff=0\u001b[39m\n", - "\u001b[34m10:36:18.613:aoc2024 - DBG: price=4, diff=-2\u001b[39m\n", - "\u001b[34m10:36:18.613:aoc2024 - DBG: price=2, diff=2\u001b[39m\n", - "\u001b[34m10:36:18.614:aoc2024 - DBG: [[-3, 6, -1, -1], [6, -1, -1, 0], [-1, -1, 0, 2], [-1, 0, 2, -2], [0, 2, -2, 0], [2, -2, 0, -2], [-2, 0, -2, 2]]\u001b[39m\n" - ] - }, - { - "ename": "AssertionError", - "evalue": "None != 23", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", - "File \u001b[0;32m:11\u001b[0m\n", - "Cell \u001b[0;32mIn[6], line 8\u001b[0m, in \u001b[0;36mvalidate\u001b[0;34m(test, answer)\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;124;03mArgs:\u001b[39;00m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;124;03m test: the answer given by our solution\u001b[39;00m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;124;03m answer: the expected answer, e.g. from instructions\u001b[39;00m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m test \u001b[38;5;241m!=\u001b[39m answer:\n\u001b[0;32m----> 8\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mAssertionError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mtest\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m != \u001b[39m\u001b[38;5;132;01m{\u001b[39;00manswer\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n", - "\u001b[0;31mAssertionError\u001b[0m: None != 23" - ] - } - ], + "def index_seq_complete(change_seq: Iterable[int], diffs_for_this_buyer):\n", + " \"\"\" Determines if this sequence is found in the diffs list.\n", + " If so, it returns the index where the index COMPLETES. (Which must be > 0.)\n", + " \n", + " Return 0 if the sequence is not found.\n", + " \"\"\"\n", + " for i in range(SECRETS - CHANGES_SEQ_LEN + 1):\n", + " if diffs_for_this_buyer[i:i+CHANGES_SEQ_LEN] == change_seq:\n", + " return i+CHANGES_SEQ_LEN-1 # the index where this seq completed\n", + " \n", + " return 0\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "%%time\n", "sample_inputs = []\n",