From 0a947a559e31777eb20e845ce2fcd9f6d0fa03b7 Mon Sep 17 00:00:00 2001 From: Domenico Testa Date: Tue, 1 Dec 2020 22:15:23 +0100 Subject: [PATCH] Day 1: Solving first challenge --- .gitignore | 2 + README.md | 4 + day_1/__init__.py | 0 day_1/report_repair.py | 213 +++++++++++++++++++++++++++++++++++++++++ poetry.lock | 81 ++++++++++++++++ pyproject.toml | 15 +++ 6 files changed, 315 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 day_1/__init__.py create mode 100644 day_1/report_repair.py create mode 100644 poetry.lock create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9574a29 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode +*.pyc diff --git a/README.md b/README.md new file mode 100644 index 0000000..9c21c9b --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Advent of code 2020 + +This repository contains code written to solve aoc challenges. +More information at: https://adventofcode.com/2020 diff --git a/day_1/__init__.py b/day_1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/day_1/report_repair.py b/day_1/report_repair.py new file mode 100644 index 0000000..6c07d39 --- /dev/null +++ b/day_1/report_repair.py @@ -0,0 +1,213 @@ +data = """\ +1822 +1917 +1642 +1617 +1941 +1740 +1529 +1896 +1880 +568 +1897 +1521 +1832 +1936 +611 +1475 +1950 +1895 +1532 +1721 +1498 +1905 +1770 +1845 +2003 +1854 +1705 +1916 +1913 +1956 +1798 +1823 +1955 +1713 +1942 +1710 +1696 +1590 +1966 +1476 +1800 +1672 +1533 +1524 +1957 +1923 +1545 +534 +1707 +1760 +1104 +1471 +1947 +1802 +1525 +1931 +1653 +1608 +1937 +1977 +1598 +1470 +1794 +1488 +1786 +1652 +1482 +1603 +1667 +1245 +1478 +667 +1948 +1885 +547 +1971 +1795 +1910 +1571 +1711 +1727 +1987 +1597 +1586 +1661 +1893 +1873 +1827 +1561 +2006 +1782 +1813 +2000 +1592 +1714 +1849 +1501 +1809 +1751 +1935 +1692 +1697 +1878 +1502 +1738 +1731 +1682 +1690 +1499 +1641 +1925 +1996 +1972 +1886 +1836 +1747 +1841 +1668 +715 +1698 +1859 +1637 +1477 +1785 +1695 +1702 +1944 +1631 +1771 +1623 +1892 +1466 +1834 +1899 +201 +1801 +1978 +1830 +1591 +1673 +1949 +1846 +1677 +1657 +1576 +1817 +1851 +1894 +1754 +1604 +1568 +1730 +1985 +1614 +1980 +1554 +1997 +1960 +1983 +1848 +1883 +1968 +1729 +1716 +628 +1472 +1676 +1943 +1821 +1681 +1619 +1644 +842 +1492 +1633 +1921 +775 +1861 +1584 +1974 +585 +1898 +1560 +1708 +1927 +1563 +1872 +1876 +1865 +1535 +1994 +1756 +1662 +1621 +1993 +1825 +1679 +1959 +1691 +1875\ +""" +input = [int(n) for n in data.split("\n")] + +from itertools import combinations + +solution = [(a,b) for a, b in combinations(input, r=2) if a+b == 2020] +for a,b in solution: + print(f"{a} * {b} = {a * b}") + +solution = [(a,b,c) for a, b, c in combinations(input, r=3) if a+b+c == 2020] +for a,b,c in solution: + print(f"{a} * {b} * {c} = {a * b * c}") diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..d001698 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,81 @@ +[[package]] +name = "certifi" +version = "2020.11.8" +description = "Python package for providing Mozilla's CA Bundle." +category = "main" +optional = false +python-versions = "*" + +[[package]] +name = "chardet" +version = "3.0.4" +description = "Universal encoding detector for Python 2 and 3" +category = "main" +optional = false +python-versions = "*" + +[[package]] +name = "idna" +version = "2.10" +description = "Internationalized Domain Names in Applications (IDNA)" +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" + +[[package]] +name = "requests" +version = "2.25.0" +description = "Python HTTP for Humans." +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[package.dependencies] +certifi = ">=2017.4.17" +chardet = ">=3.0.2,<4" +idna = ">=2.5,<3" +urllib3 = ">=1.21.1,<1.27" + +[package.extras] +security = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)"] +socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7)", "win-inet-pton"] + +[[package]] +name = "urllib3" +version = "1.26.2" +description = "HTTP library with thread-safe connection pooling, file post, and more." +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4" + +[package.extras] +brotli = ["brotlipy (>=0.6.0)"] +secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"] +socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7,<2.0)"] + +[metadata] +lock-version = "1.1" +python-versions = "~3.8" +content-hash = "dd038e74b7f412b5a36ceb304626f13577bf3eedea259a0b6194da7b32a41b04" + +[metadata.files] +certifi = [ + {file = "certifi-2020.11.8-py2.py3-none-any.whl", hash = "sha256:1f422849db327d534e3d0c5f02a263458c3955ec0aae4ff09b95f195c59f4edd"}, + {file = "certifi-2020.11.8.tar.gz", hash = "sha256:f05def092c44fbf25834a51509ef6e631dc19765ab8a57b4e7ab85531f0a9cf4"}, +] +chardet = [ + {file = "chardet-3.0.4-py2.py3-none-any.whl", hash = "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"}, + {file = "chardet-3.0.4.tar.gz", hash = "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae"}, +] +idna = [ + {file = "idna-2.10-py2.py3-none-any.whl", hash = "sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0"}, + {file = "idna-2.10.tar.gz", hash = "sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6"}, +] +requests = [ + {file = "requests-2.25.0-py2.py3-none-any.whl", hash = "sha256:e786fa28d8c9154e6a4de5d46a1d921b8749f8b74e28bde23768e5e16eece998"}, + {file = "requests-2.25.0.tar.gz", hash = "sha256:7f1a0b932f4a60a1a65caa4263921bb7d9ee911957e0ae4a23a6dd08185ad5f8"}, +] +urllib3 = [ + {file = "urllib3-1.26.2-py2.py3-none-any.whl", hash = "sha256:d8ff90d979214d7b4f8ce956e80f4028fc6860e4431f731ea4a8c08f23f99473"}, + {file = "urllib3-1.26.2.tar.gz", hash = "sha256:19188f96923873c92ccb987120ec4acaa12f0461fa9ce5d3d0772bc965a39e08"}, +] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..a6d3f51 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,15 @@ +[tool.poetry] +name = "aoc_2020" +version = "0.1.0" +description = "Advent of code 2020" +authors = ["Domenico Testa"] + +[tool.poetry.dependencies] +python = "~3.8" +requests = "^2.25.0" + +[tool.poetry.dev-dependencies] + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api"