From a6d4c09a2862aa2c97cdd5d9fd1105e61d79158e Mon Sep 17 00:00:00 2001 From: Arne Wischer Date: Wed, 4 Dec 2019 13:46:39 +0100 Subject: [PATCH] initial commit --- .gitignore | 129 +++++++++++++++++++++++++++++++++++++++++++++++ advent.py | 13 +++++ days/__init__.py | 2 + days/day1.py | 33 ++++++++++++ days/day1_input | 100 ++++++++++++++++++++++++++++++++++++ days/day2.py | 8 +++ 6 files changed, 285 insertions(+) create mode 100644 .gitignore create mode 100644 advent.py create mode 100644 days/__init__.py create mode 100644 days/day1.py create mode 100644 days/day1_input create mode 100644 days/day2.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b6e4761 --- /dev/null +++ b/.gitignore @@ -0,0 +1,129 @@ +# 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/ +pip-wheel-metadata/ +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/ + +# 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 +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.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 + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__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/ diff --git a/advent.py b/advent.py new file mode 100644 index 0000000..7241ff7 --- /dev/null +++ b/advent.py @@ -0,0 +1,13 @@ +import days +import unittest + +def suite(): + suite = unittest.TestSuite() + suite.addTest(days.Day1('test_day1a')) + suite.addTest(days.Day1('test_day1b')) + suite.addTest(days.Day2('test_day2a')) + return suite + +if __name__ == "__main__": + runner = unittest.TextTestRunner(verbosity=2) + runner.run(suite()) \ No newline at end of file diff --git a/days/__init__.py b/days/__init__.py new file mode 100644 index 0000000..62b2105 --- /dev/null +++ b/days/__init__.py @@ -0,0 +1,2 @@ +from .day1 import Day1 +from .day2 import Day2 \ No newline at end of file diff --git a/days/day1.py b/days/day1.py new file mode 100644 index 0000000..22cc110 --- /dev/null +++ b/days/day1.py @@ -0,0 +1,33 @@ +import unittest +import os + +class Day1(unittest.TestCase): + inputfile = os.path.join(os.path.dirname(__file__), "day1_input") + + def calc_fuel(self, mass): + fuel = mass // 3 - 2 + if(fuel > 0): + return fuel + self.calc_fuel(fuel) + else: + return 0 + + def test_day1a(self): + fuel = 0 + with open(self.inputfile) as fp: + value = fp.readline() + while value: + fuel += int(value) // 3 - 2 + value = fp.readline() + self.assertEqual(fuel, 3402609) + + def test_day1b(self): + with open(self.inputfile) as fp: + line = fp.readline() + sumfuel = 0 + while line: + sumfuel += self.calc_fuel(int(line)) + line = fp.readline() + self.assertEqual(sumfuel, 5101025) + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/days/day1_input b/days/day1_input new file mode 100644 index 0000000..54ed4eb --- /dev/null +++ b/days/day1_input @@ -0,0 +1,100 @@ +109364 +144584 +87498 +130293 +91960 +117563 +91730 +138879 +144269 +89058 +89982 +115609 +114728 +85422 +111803 +148524 +130035 +107558 +138936 +95622 +58042 +50697 +86848 +123301 +123631 +143125 +76434 +78004 +91115 +89062 +58465 +141127 +139993 +80958 +104184 +145131 +87438 +74385 +102113 +97392 +105986 +58600 +147156 +54377 +61409 +73552 +87138 +63168 +149602 +111776 +113191 +80137 +145985 +145177 +73192 +141631 +132979 +52565 +126574 +92005 +134655 +115894 +89175 +127328 +139873 +50072 +78814 +134750 +120848 +132950 +126523 +58206 +70885 +85482 +70889 +100029 +68447 +95111 +79896 +138650 +83079 +83112 +117762 +57223 +138122 +145193 +85251 +103331 +134501 +77023 +148189 +141341 +75994 +67024 +137767 +86260 +58705 +58771 +60684 +79655 diff --git a/days/day2.py b/days/day2.py new file mode 100644 index 0000000..4531fa6 --- /dev/null +++ b/days/day2.py @@ -0,0 +1,8 @@ +import unittest + +class Day2(unittest.TestCase): + def test_day2a(self): + self.assertTrue(1 == 1) + +if __name__ == "__main__": + unittest.main() \ No newline at end of file