commit ca4c02a1e7bf6ea4283ff564c6df6dcaa14c08ca Author: Moritz Böhme Date: Thu Dec 1 17:45:37 2022 +0100 add day 1 diff --git a/2022/.gitignore b/2022/.gitignore new file mode 100644 index 0000000..f88dde9 --- /dev/null +++ b/2022/.gitignore @@ -0,0 +1,175 @@ +# Created by https://www.toptal.com/developers/gitignore/api/direnv,python +# Edit at https://www.toptal.com/developers/gitignore?templates=direnv,python + +### direnv ### +.direnv +.envrc + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +### Python Patch ### +# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration +poetry.toml + + +# End of https://www.toptal.com/developers/gitignore/api/direnv,python diff --git a/2022/.idea/.gitignore b/2022/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/2022/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/2022/.idea/2022.iml b/2022/.idea/2022.iml new file mode 100644 index 0000000..4a9091f --- /dev/null +++ b/2022/.idea/2022.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/2022/.idea/inspectionProfiles/Project_Default.xml b/2022/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..03d9549 --- /dev/null +++ b/2022/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/2022/.idea/inspectionProfiles/profiles_settings.xml b/2022/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/2022/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/2022/.idea/misc.xml b/2022/.idea/misc.xml new file mode 100644 index 0000000..1e17fd7 --- /dev/null +++ b/2022/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/2022/.idea/modules.xml b/2022/.idea/modules.xml new file mode 100644 index 0000000..997c71a --- /dev/null +++ b/2022/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/2022/.idea/vcs.xml b/2022/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/2022/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2022/poetry.lock b/2022/poetry.lock new file mode 100644 index 0000000..6ca9f43 --- /dev/null +++ b/2022/poetry.lock @@ -0,0 +1,214 @@ +[[package]] +name = "attrs" +version = "22.1.0" +description = "Classes Without Boilerplate" +category = "dev" +optional = false +python-versions = ">=3.5" + +[package.extras] +dev = ["cloudpickle", "coverage[toml] (>=5.0.2)", "furo", "hypothesis", "mypy (>=0.900,!=0.940)", "pre-commit", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "sphinx", "sphinx-notfound-page", "zope.interface"] +docs = ["furo", "sphinx", "sphinx-notfound-page", "zope.interface"] +tests = ["cloudpickle", "coverage[toml] (>=5.0.2)", "hypothesis", "mypy (>=0.900,!=0.940)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "zope.interface"] +tests-no-zope = ["cloudpickle", "coverage[toml] (>=5.0.2)", "hypothesis", "mypy (>=0.900,!=0.940)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins"] + +[[package]] +name = "black" +version = "22.10.0" +description = "The uncompromising code formatter." +category = "main" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +click = ">=8.0.0" +mypy-extensions = ">=0.4.3" +pathspec = ">=0.9.0" +platformdirs = ">=2" + +[package.extras] +colorama = ["colorama (>=0.4.3)"] +d = ["aiohttp (>=3.7.4)"] +jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] +uvloop = ["uvloop (>=0.15.2)"] + +[[package]] +name = "click" +version = "8.1.3" +description = "Composable command line interface toolkit" +category = "main" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +category = "main" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" + +[[package]] +name = "iniconfig" +version = "1.1.1" +description = "iniconfig: brain-dead simple config-ini parsing" +category = "dev" +optional = false +python-versions = "*" + +[[package]] +name = "mypy-extensions" +version = "0.4.3" +description = "Experimental type system extensions for programs checked with the mypy typechecker." +category = "main" +optional = false +python-versions = "*" + +[[package]] +name = "packaging" +version = "21.3" +description = "Core utilities for Python packages" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +pyparsing = ">=2.0.2,<3.0.5 || >3.0.5" + +[[package]] +name = "pathspec" +version = "0.10.2" +description = "Utility library for gitignore style pattern matching of file paths." +category = "main" +optional = false +python-versions = ">=3.7" + +[[package]] +name = "platformdirs" +version = "2.5.4" +description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." +category = "main" +optional = false +python-versions = ">=3.7" + +[package.extras] +docs = ["furo (>=2022.9.29)", "proselint (>=0.13)", "sphinx (>=5.3)", "sphinx-autodoc-typehints (>=1.19.4)"] +test = ["appdirs (==1.4.4)", "pytest (>=7.2)", "pytest-cov (>=4)", "pytest-mock (>=3.10)"] + +[[package]] +name = "pluggy" +version = "1.0.0" +description = "plugin and hook calling mechanisms for python" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + +[[package]] +name = "pyparsing" +version = "3.0.9" +description = "pyparsing module - Classes and methods to define and execute parsing grammars" +category = "dev" +optional = false +python-versions = ">=3.6.8" + +[package.extras] +diagrams = ["jinja2", "railroad-diagrams"] + +[[package]] +name = "pytest" +version = "7.2.0" +description = "pytest: simple powerful testing with Python" +category = "dev" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +attrs = ">=19.2.0" +colorama = {version = "*", markers = "sys_platform == \"win32\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=0.12,<2.0" + +[package.extras] +testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "xmlschema"] + +[metadata] +lock-version = "1.1" +python-versions = "^3.11" +content-hash = "adba8c1dd6be494968ab1869bbb1735cfffa6e28fbe981d0d0299faba66d48f9" + +[metadata.files] +attrs = [ + {file = "attrs-22.1.0-py2.py3-none-any.whl", hash = "sha256:86efa402f67bf2df34f51a335487cf46b1ec130d02b8d39fd248abfd30da551c"}, + {file = "attrs-22.1.0.tar.gz", hash = "sha256:29adc2665447e5191d0e7c568fde78b21f9672d344281d0c6e1ab085429b22b6"}, +] +black = [ + {file = "black-22.10.0-1fixedarch-cp310-cp310-macosx_11_0_x86_64.whl", hash = "sha256:5cc42ca67989e9c3cf859e84c2bf014f6633db63d1cbdf8fdb666dcd9e77e3fa"}, + {file = "black-22.10.0-1fixedarch-cp311-cp311-macosx_11_0_x86_64.whl", hash = "sha256:5d8f74030e67087b219b032aa33a919fae8806d49c867846bfacde57f43972ef"}, + {file = "black-22.10.0-1fixedarch-cp37-cp37m-macosx_10_16_x86_64.whl", hash = "sha256:197df8509263b0b8614e1df1756b1dd41be6738eed2ba9e9769f3880c2b9d7b6"}, + {file = "black-22.10.0-1fixedarch-cp38-cp38-macosx_10_16_x86_64.whl", hash = "sha256:2644b5d63633702bc2c5f3754b1b475378fbbfb481f62319388235d0cd104c2d"}, + {file = "black-22.10.0-1fixedarch-cp39-cp39-macosx_11_0_x86_64.whl", hash = "sha256:e41a86c6c650bcecc6633ee3180d80a025db041a8e2398dcc059b3afa8382cd4"}, + {file = "black-22.10.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:2039230db3c6c639bd84efe3292ec7b06e9214a2992cd9beb293d639c6402edb"}, + {file = "black-22.10.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:14ff67aec0a47c424bc99b71005202045dc09270da44a27848d534600ac64fc7"}, + {file = "black-22.10.0-cp310-cp310-win_amd64.whl", hash = "sha256:819dc789f4498ecc91438a7de64427c73b45035e2e3680c92e18795a839ebb66"}, + {file = "black-22.10.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:5b9b29da4f564ba8787c119f37d174f2b69cdfdf9015b7d8c5c16121ddc054ae"}, + {file = "black-22.10.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b8b49776299fece66bffaafe357d929ca9451450f5466e997a7285ab0fe28e3b"}, + {file = "black-22.10.0-cp311-cp311-win_amd64.whl", hash = "sha256:21199526696b8f09c3997e2b4db8d0b108d801a348414264d2eb8eb2532e540d"}, + {file = "black-22.10.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1e464456d24e23d11fced2bc8c47ef66d471f845c7b7a42f3bd77bf3d1789650"}, + {file = "black-22.10.0-cp37-cp37m-win_amd64.whl", hash = "sha256:9311e99228ae10023300ecac05be5a296f60d2fd10fff31cf5c1fa4ca4b1988d"}, + {file = "black-22.10.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:fba8a281e570adafb79f7755ac8721b6cf1bbf691186a287e990c7929c7692ff"}, + {file = "black-22.10.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:915ace4ff03fdfff953962fa672d44be269deb2eaf88499a0f8805221bc68c87"}, + {file = "black-22.10.0-cp38-cp38-win_amd64.whl", hash = "sha256:444ebfb4e441254e87bad00c661fe32df9969b2bf224373a448d8aca2132b395"}, + {file = "black-22.10.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:974308c58d057a651d182208a484ce80a26dac0caef2895836a92dd6ebd725e0"}, + {file = "black-22.10.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:72ef3925f30e12a184889aac03d77d031056860ccae8a1e519f6cbb742736383"}, + {file = "black-22.10.0-cp39-cp39-win_amd64.whl", hash = "sha256:432247333090c8c5366e69627ccb363bc58514ae3e63f7fc75c54b1ea80fa7de"}, + {file = "black-22.10.0-py3-none-any.whl", hash = "sha256:c957b2b4ea88587b46cf49d1dc17681c1e672864fd7af32fc1e9664d572b3458"}, + {file = "black-22.10.0.tar.gz", hash = "sha256:f513588da599943e0cde4e32cc9879e825d58720d6557062d1098c5ad80080e1"}, +] +click = [ + {file = "click-8.1.3-py3-none-any.whl", hash = "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48"}, + {file = "click-8.1.3.tar.gz", hash = "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"}, +] +colorama = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] +iniconfig = [ + {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, + {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, +] +mypy-extensions = [ + {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, + {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, +] +packaging = [ + {file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"}, + {file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"}, +] +pathspec = [ + {file = "pathspec-0.10.2-py3-none-any.whl", hash = "sha256:88c2606f2c1e818b978540f73ecc908e13999c6c3a383daf3705652ae79807a5"}, + {file = "pathspec-0.10.2.tar.gz", hash = "sha256:8f6bf73e5758fd365ef5d58ce09ac7c27d2833a8d7da51712eac6e27e35141b0"}, +] +platformdirs = [ + {file = "platformdirs-2.5.4-py3-none-any.whl", hash = "sha256:af0276409f9a02373d540bf8480021a048711d572745aef4b7842dad245eba10"}, + {file = "platformdirs-2.5.4.tar.gz", hash = "sha256:1006647646d80f16130f052404c6b901e80ee4ed6bef6792e1f238a8969106f7"}, +] +pluggy = [ + {file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"}, + {file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"}, +] +pyparsing = [ + {file = "pyparsing-3.0.9-py3-none-any.whl", hash = "sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc"}, + {file = "pyparsing-3.0.9.tar.gz", hash = "sha256:2b020ecf7d21b687f219b71ecad3631f644a47f01403fa1d1036b0c6416d70fb"}, +] +pytest = [ + {file = "pytest-7.2.0-py3-none-any.whl", hash = "sha256:892f933d339f068883b6fd5a459f03d85bfcb355e4981e146d2c7616c21fef71"}, + {file = "pytest-7.2.0.tar.gz", hash = "sha256:c4014eb40e10f11f355ad4e3c2fb2c6c6d1919c73f3b5a433de4708202cade59"}, +] diff --git a/2022/pyproject.toml b/2022/pyproject.toml new file mode 100644 index 0000000..77ec5df --- /dev/null +++ b/2022/pyproject.toml @@ -0,0 +1,19 @@ +[tool.poetry] +name = "aoc" +version = "0.0.0" +description = "" +authors = ["Your Name "] +packages = [ + { include = "src" } +] + +[tool.poetry.dependencies] +python = "^3.11" +black = "^22.10.0" + +[tool.poetry.group.dev.dependencies] +pytest = "^7.2.0" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/2022/src/__init__.py b/2022/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/2022/src/day1/first.py b/2022/src/day1/first.py new file mode 100644 index 0000000..5bd9e8c --- /dev/null +++ b/2022/src/day1/first.py @@ -0,0 +1,28 @@ +def process_input(lines: list[str]) -> list[list[int]]: + output = [] + block = [] + for line in lines: + stripped = line.strip() + if stripped.isnumeric(): + block.append(int(stripped)) + elif block: + output.append(block) + block = [] + return output + + +def sum_blocks(blocks: list[list[int]]) -> list[int]: + return [sum(block) for block in blocks] + + +def main(lines: list[str]) -> int: + blocks = process_input(lines) + block_sums = sum_blocks(blocks) + return max(block_sums) + + +if __name__ == "__main__": + with open("input.txt") as file: + contents = file.readlines() + solution = main(contents) + print(f"Highest block sum: {solution}") diff --git a/2022/src/day1/input.txt b/2022/src/day1/input.txt new file mode 100644 index 0000000..335bff5 --- /dev/null +++ b/2022/src/day1/input.txt @@ -0,0 +1,2237 @@ +8462 +6981 +3714 +4409 +8186 +3614 +2218 +7558 +6702 + +2947 +4727 +6396 +5718 +2361 +1970 +1583 +2816 +2995 +6914 +4313 +1401 + +1643 +7815 +2162 +8841 +7671 + +5740 +5471 +4838 +2281 +2784 +4587 +1497 +2074 +1161 +4388 +2233 +4795 +2011 +5438 + +14064 +9646 +2537 + +2064 +2833 +1164 +14379 + +6008 +4327 +4709 +5412 +2745 +5680 +5322 +4375 +4064 +4822 +6523 +6824 +6822 + +12100 +24791 +18239 + +9704 +8218 +9949 +3078 +9407 +3732 +4281 +6727 + +9833 +2549 +5042 +7053 +6116 +9624 +5393 +8359 + +4195 +7869 +15434 +6997 +5776 + +2487 +7843 +2739 +5227 +4088 +6281 +7078 +4291 +5461 +4838 +7936 + +5449 +5754 +4685 +7642 +7244 +4912 + +4020 +18761 +17710 +8736 + +6204 +1295 +3812 +5078 +4627 +3818 +4351 +5202 +2542 +2728 +3036 +5026 +5146 +5771 + +8809 +5364 +22076 + +3846 +2867 +10260 +3321 +7715 +7670 +1326 +5480 + +2613 +1442 +3771 +1692 +6131 +3945 +4591 +5165 +1648 +6084 +4952 +4295 +4390 +3935 + +4403 +6299 +4307 +5329 +4235 +4779 +4498 +6871 +5739 +4102 +6815 +1975 +4056 + +3875 +2650 +5888 +1605 +3972 +4781 +5694 +4150 +5765 +3919 +4260 +6339 +5614 +4597 + +1829 +4292 +4756 +4348 +3051 +2662 +4018 +1498 +3391 +1776 +1919 +3141 +3938 + +17338 +10081 +22228 + +10554 +2454 +2879 +3605 +3717 +5477 +4826 +3133 + +2221 +1431 +3235 +3371 +1364 +2137 +1774 +2015 +5115 +3331 +3588 +3264 +2401 + +5770 +3408 +1153 +6106 +3261 +2801 +3380 +1377 +2126 +5516 +4087 +2353 +1039 +1909 +5374 + +15655 +12356 +7421 +12094 +1776 + +16080 +7634 +4329 + +9409 +10153 +10744 +2145 +5796 +1586 +3622 +3635 + +1314 +5713 +5566 +6397 +2033 +1083 +7096 +6595 +6652 +4872 +4444 + +9731 +12016 +10148 +7358 +10025 +7471 +1346 + +1189 +2777 +4153 +1415 +9311 +6324 +4108 +7104 +8467 + +9326 +3339 +5048 +8225 +1647 +3640 +2922 + +3110 +15978 +17916 + +4502 +4106 +5683 +8061 +6507 +3591 +4560 +4620 +7036 +5762 +1470 + +7613 +12487 +1257 +10687 +4374 + +14169 +1170 + +2310 +10184 +6759 +12955 +3895 +6388 + +19637 +11418 +4728 +10935 + +8856 +9067 +7661 +3795 +3895 +7974 +2340 +3395 +1442 + +4258 +3584 +1935 +2919 +3870 +1078 +4163 +5192 +3363 +2386 +5897 +2922 +1619 +4872 +1903 + +8638 +8492 +1883 +10979 +2715 +3274 +7286 + +10670 +13042 +13137 + +3729 +1312 +1981 +2754 +4417 +1466 +7675 +2290 +5074 +5666 + +13836 +1263 +24451 + +6390 +8913 +12614 +6468 +2541 +13763 + +4673 +7245 +9128 +4712 +3838 +4596 +6620 +5459 +6350 + +4454 +5111 +3862 +1374 +2091 +2522 +6196 +2052 +1399 +6151 +1987 +3678 + +7427 +6633 +1447 +1854 +6601 +3459 +4633 +1339 +2955 +3929 +1057 +1910 + +1896 +2326 +2173 +1062 +5249 +3730 +4479 +6377 +2833 +4106 +4126 +4492 +2132 +4484 + +3465 +5345 +2295 +5946 +2465 +5684 +5573 +4449 +5983 +4863 +3678 +6007 +1249 +1563 +5270 + +3334 +1612 +3210 +1215 +4474 +2893 +4987 +2355 +3912 +5019 +4544 +1446 +3076 +4833 +4889 + +8299 +3042 +5715 +8442 +10294 +3697 +2071 +1482 + +2461 +6281 +3382 +1175 +7048 +2050 +1470 +5249 +7622 +6950 +4962 + +8573 +6266 +12922 +11159 +1493 + +6320 +4365 +7883 + +17708 +18169 +11780 + +8023 +7870 +4647 +6059 +1094 +1888 +8696 +2077 +5882 +3320 + +3180 +5779 +2360 +6811 +7802 +1662 +3157 +7373 +4282 +5282 + +3162 +5081 +1917 +1149 +2325 +6862 +4536 +2776 +6418 +4161 +6919 +1766 +2387 + +11508 +6617 +1521 +6854 +4799 +1463 +11379 + +12419 +4634 +8522 +3323 + +43380 + +1529 +2302 +6234 +5285 +6071 +3741 +6783 +3271 +1451 +3379 +1032 +1218 + +53976 + +3746 +2269 +4878 +5085 +1873 +3582 +2155 +6638 +2804 +3910 +5384 +4865 + +4905 +2648 +2320 +1775 +3803 +1137 +2405 +1974 +1667 +5677 +3687 +2476 +5332 + +2511 +2805 +3088 +5437 +4000 +5283 +6220 +3387 +1962 +2868 +2084 +5740 +4899 +5846 + +20975 +15672 + +11633 +12928 +17372 + +10964 +6326 +3115 +18901 + +2151 +6218 +2619 +8294 +12292 +12179 + +5390 +4373 +3685 +2236 +7107 +11917 +3701 + +5696 +1751 +6613 +6606 +1288 +5362 +6157 +6236 +3649 +4023 + +5290 +7999 +10040 +3338 +7547 +7575 +6369 + +3358 +6414 +2066 +2012 +3849 +1421 +2962 +4607 +3548 +6637 +5759 +4800 +5974 + +3209 +11201 +10317 +7340 +1073 +11610 + +5148 +2081 +5577 +5340 +7634 +4998 +7107 +6923 +1673 + +4809 +6274 +4140 +2993 +3003 +2973 +9914 +1878 + +3190 +5792 +3561 +2917 +4408 +1443 +4373 +1241 +3288 +5703 +4155 +5764 +4857 +5828 +4089 + +7390 +5924 +7987 +2919 +4474 +7700 +5457 +7926 +7539 + +5344 +5739 +4883 +1156 +5896 +5991 +7625 +2118 +3292 +7562 +1820 + +6485 +7804 +6886 +7436 +6163 +2618 +3119 +7144 +6274 +2792 +7602 + +4912 +6024 +5984 +2408 +1685 +1702 +5851 +2756 +1341 +4558 +1073 +4394 +6014 +1395 + +6662 +6573 +6043 +7402 +5790 +6942 +4171 +4043 +3077 +5672 +4984 + +1292 +6545 +2265 +6121 +2385 +2229 +6870 +6579 +1549 +6030 +3423 +1830 +6027 + +6361 +5979 +6532 +7110 +1881 +4659 + +9825 +4176 +4534 +1732 +4816 +6604 +8182 +2391 + +2309 +5266 +5879 +2463 +3636 +4958 +6308 +2091 +2588 +1841 +6899 +5666 + +9351 + +3824 +5754 +2710 +3782 +2784 +4535 +6157 +1055 +3569 +6498 +2679 +2949 +3285 +2519 + +5661 + +4565 +8056 +1975 +6947 +7508 +5570 +3727 +3287 +1794 +4933 +6458 + +6171 +9991 +10533 +6503 +1450 + +18391 +9046 +17384 +18940 + +5583 +5102 +2869 +5328 +2041 +4327 +1656 +2874 +2811 +5765 +4568 +5280 +2770 +1147 +6082 + +1512 +5928 +8631 +3263 +5569 +3693 +5060 +1810 +8327 +2900 + +21146 +13775 +13189 + +2853 +1782 +1461 +2560 +2046 +2773 +2453 +1218 +3545 +6013 +5893 +1853 +1926 +1847 +5914 + +15312 +22899 + +2752 +1253 +1448 +2627 +1161 +3661 +3457 +2992 +4606 +3206 +3145 +3639 +2833 +3687 +2148 + +6668 +3671 +3484 +2000 +2149 +3748 +1256 +3168 +6889 +5046 +6594 + +7437 +5596 +6744 +6863 +7397 +5922 +1897 +4042 +3993 +2569 +2509 +6048 + +10456 +7724 +2668 +4749 + +11329 +5011 +4007 +10189 +6972 + +4514 +1702 +2925 +1828 +8000 +5724 +3567 +1190 + +2949 +7487 +6652 +1472 +5965 +3071 +6990 +3356 +5283 +6487 +1990 + +31016 + +3585 +6168 +6826 +6184 +4985 +6209 +7290 +5732 +4058 +7919 +2152 + +18469 + +5945 +4318 +3986 +3386 +7037 +7149 +5313 +6521 +8266 +6665 + +39430 + +2779 +2507 +4473 +1635 +6487 +6823 +5443 +7274 +4722 +6267 +6421 + +8443 +3747 +3863 +6109 +1369 +8602 +4231 +7029 +4102 +2876 + +1013 +2319 +1800 +5256 +9521 +12068 +2116 + +11032 +1733 +6220 +7666 +3891 +3761 +6096 + +3434 +4984 +3662 +3070 +3560 +4494 +1485 +3460 +3851 +1007 +2615 +5349 +4254 +5248 +2140 + +3469 +2318 +4553 +1058 +1122 +4413 +3672 +6019 +1616 +3557 +3211 +2938 +4390 +2685 +3250 + +1446 +5593 +4857 +2389 +6242 +2724 +1425 +7948 +7140 +7839 +6895 + +5659 +4475 +5467 +1742 +1243 +8125 +2044 +3449 +5796 + +3012 +12758 +2478 +11102 +2615 +7856 + +5170 +5356 +1141 +1513 +1650 +4280 +2441 +4572 +6556 +6821 +3519 +3330 + +4799 +6959 +1737 +1502 +3510 +2089 +6946 +1303 +3574 +6382 + +6579 +2997 +1700 +6006 +1855 +2135 +10659 +2237 + +55371 + +1551 +2828 +3490 +2030 +5126 +4109 +2305 +4994 +4733 +1693 +3338 +3996 +4181 +3896 +1092 + +1846 +4756 +9555 +7994 +8733 +1489 +4585 +5954 +6058 + +48724 + +3025 +6315 +1398 +2563 +2661 +6414 +1230 +1290 +1898 +1493 +1347 +3971 +4248 + +8315 +17843 +17103 + +4287 +2732 +2284 +3036 +6831 +2890 +7588 +7268 +1464 +2247 +1306 + +4480 +1267 +5209 +3558 +5311 +2958 +3054 +4265 +3836 +3300 +1867 +1892 +5756 +3293 + +7569 +9154 +4238 +1586 +7972 +9683 +5373 +3431 +4990 + +9579 +6370 +1128 +3575 +5785 +5055 +8228 +1914 +6012 + +5171 +3810 +3053 +1775 +2437 +1751 +5214 +6904 +3496 +5429 +2340 +5683 +3428 + +27584 +19252 + +23558 +8432 + +8727 +6023 +1708 +1839 +6467 +2494 +6788 +6905 +2160 +2380 + +1023 +2142 +10754 +7460 +5136 + +4181 +1605 +2243 +9554 +4041 +4423 + +38394 + +5137 +2560 +1230 +7342 +5300 +3089 +1281 +7567 +1529 +3628 + +4026 +8121 +4227 +14794 +7567 + +4344 +12998 +5424 +2987 +10128 +8362 + +9373 +5522 +2017 +10260 +5263 +3402 +7981 + +6772 +2092 +6024 +4548 +1229 +2486 +4733 +3112 +4908 +3598 +5839 +2922 +4936 + +7723 +2389 +2100 +4448 +7255 +3430 +2808 +4832 +5848 +7024 + +4664 +4953 +4403 +3171 +6125 +4154 +2921 +3502 +7290 +6371 +2314 +1391 + +4967 +5243 +6186 +3218 +2082 +4625 +5827 +2257 +2186 +5716 +1032 +1796 +2609 +5704 + +66296 + +6973 +4755 +6328 +6720 +8118 +2696 +4449 +3474 +5110 +5852 + +8320 +10410 +7618 +6504 +1892 +9355 +2792 +6286 + +47376 + +1448 +1176 +6150 +3289 +1759 +5919 +2579 +5630 +3798 +6203 +4909 +5294 +1471 +4537 + +7656 +12471 +14457 +11694 +8007 + +3990 +8373 +1412 +1462 +5601 +8555 +8500 +2545 +8920 + +1312 +6198 +2638 +1095 +5201 +4953 +3056 +2526 +3699 +5639 +4583 +4737 +2245 + +7833 +5242 +6384 +7309 +3805 +6525 +6070 +6074 +5899 +2583 + +65699 + +6154 +3691 +1858 +5141 +6915 +2134 +2131 +5295 +4071 +4552 +1753 +6950 +3909 + +2587 +1337 +3790 +3137 +6150 +1698 +3950 +4046 +2308 +3871 +1824 +1533 +1930 +3360 + +10305 +13340 +6892 + +4945 +6137 +10521 +2418 +9791 +7035 +4151 +5497 + +25807 +25417 + +5771 +6122 +4596 +4022 +9682 +4696 +8749 + +1028 +6870 +3606 +4626 +4557 +6908 +5503 +1803 +2561 +2487 +3368 +5319 + +2027 +4102 +5920 +3335 +5804 +3829 +5977 +1592 +2113 +3771 +3938 +3417 +2550 +1980 + +3321 +4002 +1229 +3591 +3851 +1384 +2618 +4049 +3336 +2035 +1231 +2126 +1901 +2834 +5604 + +45987 + +3667 +3442 +2721 +5515 +9294 +4897 +7333 +2518 +4009 + +5686 +2042 +1130 +5463 +2814 +2780 +1037 +5490 +3188 +2882 +3742 +4048 +3203 +1785 + +20148 +14705 + +6293 +1673 +6865 +2414 +6552 +3886 +5944 +6538 +2569 +3770 +7698 + +1588 +2025 +2071 +4336 +4768 +1826 +2939 +3016 +1529 +3092 +1326 +5698 +5864 +4837 +4188 + +9974 +3626 +6637 +6988 +7509 +9460 +7542 +7164 + +5343 +1913 +12824 +13105 +13538 +1114 + +4699 +4692 +4170 +6325 +1634 +4627 +2721 +5309 +3772 +2132 +1894 +5094 +6416 +2492 + +22223 +15163 +3520 + +9437 +25803 + +2519 +7012 +2571 +6251 +1380 +5344 +6362 +2465 +4457 +1071 +5560 +1992 + +5522 +3334 +2597 +2382 +4118 +1624 +6175 +4656 +6525 +6593 +4459 +1349 +1403 + +1443 +7693 +10526 +9927 +9729 +3172 +7632 + +3154 +6472 +3815 +3055 +1009 +8458 +3250 +1864 +6734 +8458 + +3155 +2476 +6384 +2045 +2773 +7447 +7646 +1186 +5360 +4499 +2502 + +9675 +8902 +12054 +9405 +8558 +8901 + +3605 +2465 +9906 +5145 +13502 +9839 + +9207 +7212 +4778 +9929 +6582 +9680 +3349 +1813 + +4483 +15153 +22152 + +24781 +33010 + +19696 + +6451 +5583 +3639 +3565 +7956 +4005 +5236 +3053 +2192 +5485 +3143 + +3990 +1296 +4262 +4493 +4072 +5136 +4507 +4191 +6636 +5514 +5759 +6471 +3567 + +2296 +5998 +6269 +3935 +1929 +3188 +5768 +2547 +1318 +3689 +1161 +3894 +1206 +1304 + +2942 +2195 +5594 +8418 +3600 +6710 +4414 +7753 +1672 +1878 + +6682 +9976 +18511 +17026 + +7606 +3587 +2427 +9258 +8752 +7387 +4096 +3911 +6200 + +4364 +8277 +5476 +1718 +3530 +6895 +4822 +3970 +3368 + +12691 +3502 +4641 +8562 +8062 +5216 + +7316 +7688 +5102 +7950 +4291 +9711 +3202 +7487 + +57056 + +4268 +1730 +3617 +5257 +5760 +3222 +3497 +4891 +1584 +2587 +5954 +3391 +1203 +2673 + +15671 +11805 +1242 + +5560 +1774 +2332 +2068 +6859 +3012 +6677 +6255 +1178 +3695 +5131 +2075 +1398 + +8310 +2657 +1795 +14376 + +4270 +1931 +6894 +5011 +3766 +1028 +1405 +3768 +5249 +3972 +5799 +4704 + +4331 +3682 +1748 +6674 +4191 +4711 +4971 +3329 +5968 +1971 +1533 +5559 + +4569 +5005 +4292 +3541 +4578 +5532 +4163 +2555 +1936 +5767 +1299 +5620 +4897 +5824 + +2350 +3735 +7113 +6094 +7952 +5611 +3634 +8849 +5171 + +7046 +11580 +1720 +1574 +12103 +5747 +5966 + +10027 +6090 +9627 +4738 +9248 +5177 +3622 +5265 + +4617 +8158 +2629 +4317 +8707 +1442 +1944 +3006 +7283 +4939 + +2744 +3616 +1211 +4479 +5857 +6062 +5475 +1369 +7243 +4930 +5514 +3919 + +5938 +2249 +18108 +6713 + +6017 +1815 +2551 +2246 +5082 +3795 +3673 +1083 +5008 +6903 +6492 +1272 +1494 + +5350 +4727 +5366 +1227 +6846 +1355 +5226 +7069 +3365 +4011 +2857 +1696 + +2732 +3684 +5801 +3059 +1099 +5909 +4528 +2645 +2363 +1622 +3335 +2903 +4690 +1443 + +2445 +4940 +4878 +5229 +6686 +5416 +8016 +5249 + +1875 +2976 +3545 +2571 +2691 +5763 +4373 +5126 +5078 +2895 +3976 +1934 +4212 + +1649 +2120 +2801 +1222 +4478 +7415 +7956 +2507 +3464 +1512 +3680 + +3087 +5058 +5726 +4050 +5667 +1709 +4970 +1805 +4369 +3211 +2953 +1847 +5848 +3365 +5717 + +18473 + +2897 +15970 +13899 + +2396 +2432 +4315 +1646 +2933 +3701 +3034 +6228 +4978 +1254 +5964 +4797 +3712 +4613 + +3583 +4652 +2589 +3126 +1356 +3268 +4372 +5851 +3159 +2936 +2568 +1631 +4557 +4254 +5537 + +1796 +1304 +1129 +3237 +7542 +4587 +3158 +3055 +5129 +5981 +3396 + +2326 +2916 +7617 +1438 +1205 +4903 +7842 +6171 +6042 +6076 +8009 + +60341 + +10527 +30521 + +1882 +7475 +4092 +10469 +11258 +2361 +6750 + +7307 +10450 +2273 +3998 +4324 +4453 +5606 + +14605 +8618 +19203 +6177 + +40070 + +13758 +9814 +16312 +14985 +8629 + +20716 + +2344 +9535 +6583 +10900 +12041 +3724 + +3075 +11273 +9002 +9802 +1148 +9197 +10064 + +25216 +11228 +15709 + +21181 +10820 +8812 + +3073 +5764 +8201 +4269 +3302 +1795 +5387 +2618 +7288 +8388 + +24566 + +7608 +1738 +3212 +7028 +6321 +1087 +3361 +1698 +5582 +4314 + +9189 +9689 +7007 +2845 +1086 +9086 +1795 +6550 +7610 + +1139 +4157 +4135 +9875 +7720 +8262 +2666 +7147 diff --git a/2022/src/day1/second.py b/2022/src/day1/second.py new file mode 100644 index 0000000..fd3096f --- /dev/null +++ b/2022/src/day1/second.py @@ -0,0 +1,27 @@ +from first import process_input, sum_blocks + + +def maximum(input_list: list[int], top=3) -> list[int]: + if top <= 0: + raise RuntimeError(f"Argument top has to be >= 1! Got {top}.") + top_elements = input_list[:top] + for i in input_list[top:]: + if any(i > element for element in top_elements): + top_elements.append(i) + if len(top_elements) > top: + top_elements.sort(reverse=True) + top_elements.pop() + return top_elements + + +def main(lines: list[str]) -> int: + blocks = process_input(lines) + block_sums = sum_blocks(blocks) + return sum(maximum(block_sums)) + + +if __name__ == "__main__": + with open("input.txt") as file: + contents = file.readlines() + solution = main(contents) + print(f"Highest block sum: {solution}") diff --git a/2022/src/day1/test_first.py b/2022/src/day1/test_first.py new file mode 100644 index 0000000..10a0329 --- /dev/null +++ b/2022/src/day1/test_first.py @@ -0,0 +1,35 @@ +import pytest +from first import main, process_input + + +@pytest.fixture() +def example(): + return """ + 1000 + 2000 + 3000 + + 4000 + + 5000 + 6000 + + 7000 + 8000 + 9000 + + 10000 + """.splitlines() + + +@pytest.fixture() +def blocks(): + return [[1000, 2000, 3000], [4000], [5000, 6000], [7000, 8000, 9000], [10000]] + + +def test_process_input(example, blocks): + assert process_input(example) == blocks + + +def test_main(example): + assert main(example) == 24000 diff --git a/2022/src/day1/test_second.py b/2022/src/day1/test_second.py new file mode 100644 index 0000000..fc58321 --- /dev/null +++ b/2022/src/day1/test_second.py @@ -0,0 +1,11 @@ +from second import main, maximum +from test_first import blocks, example +from first import sum_blocks + + +def test_maximum(blocks): + assert sorted(maximum(sum_blocks(blocks)), reverse=True) == [24000, 11000, 10000] + + +def test_main(example): + assert main(example) == 45000