From 97a1d98510c1b2c935e3d19f0d2dd73d7f3d3d36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Rasmussen?= Date: Tue, 1 Dec 2020 14:10:36 +0100 Subject: [PATCH] Day 1 --- 1/sum.py | 20 ++++++ 1/sum.txt | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1/sum2.py | 19 ++++++ 3 files changed, 239 insertions(+) create mode 100644 1/sum.py create mode 100644 1/sum.txt create mode 100644 1/sum2.py diff --git a/1/sum.py b/1/sum.py new file mode 100644 index 0000000..7de678b --- /dev/null +++ b/1/sum.py @@ -0,0 +1,20 @@ +from pprint import pprint + +def search(l, key): + for ix, x in enumerate(l): + for iy, y in enumerate(l): + if x == y: + continue + + if x + y == key: + return x, y + +with open("sum.txt", "r", encoding="utf-8") as f: + s = f.read() +ls = s.split() +l = [int(x) for x in ls] +x, y = search(l, 2020) +pprint((x, y)) +print(x*y) + + diff --git a/1/sum.txt b/1/sum.txt new file mode 100644 index 0000000..84654e6 --- /dev/null +++ b/1/sum.txt @@ -0,0 +1,200 @@ +1228 +1584 +1258 +1692 +1509 +1927 +1177 +1854 +1946 +1815 +1925 +1531 +1529 +1920 +1576 +1392 +1744 +1937 +1636 +1615 +1944 +1949 +1931 +1253 +1587 +1860 +1874 +1611 +2008 +1182 +1900 +1515 +1978 +1996 +116 +1588 +1322 +1680 +1174 +1712 +1513 +1778 +1443 +1569 +1453 +708 +1783 +1926 +1959 +2001 +1776 +1643 +1654 +1934 +1983 +1630 +1382 +1486 +1422 +1836 +1728 +1315 +1843 +1521 +1995 +1403 +1897 +1280 +1981 +1901 +1870 +1519 +1945 +1857 +591 +1329 +1954 +1679 +1726 +1846 +1709 +1695 +1293 +1602 +1665 +1940 +1921 +1861 +1710 +1524 +1303 +1849 +1742 +1892 +1913 +1530 +1484 +1903 +1545 +1609 +1652 +1908 +1923 +1188 +1649 +1994 +1790 +1832 +140 +867 +1664 +1598 +1371 +1018 +35 +1833 +1161 +1898 +1482 +1767 +1252 +1882 +1448 +1032 +1459 +1661 +1391 +1770 +1806 +1465 +1295 +1546 +1355 +1358 +1321 +1368 +1514 +1756 +1775 +1957 +1468 +1975 +631 +1812 +1151 +1167 +1251 +1960 +1991 +1972 +1936 +1552 +1419 +1577 +1549 +1580 +1974 +1830 +1813 +1893 +1492 +1389 +1454 +1522 +1556 +1172 +1653 +1822 +1328 +1907 +1999 +1281 +1912 +1919 +1896 +1722 +1341 +1720 +1201 +1512 +1298 +1254 +1947 +1505 +1594 +1334 +1592 +1943 +1405 +1589 +1263 +1930 +1736 +1180 +1984 +1401 +1340 +1292 +1979 +1876 diff --git a/1/sum2.py b/1/sum2.py new file mode 100644 index 0000000..999f896 --- /dev/null +++ b/1/sum2.py @@ -0,0 +1,19 @@ +from pprint import pprint + +def search(l, key): + for ix, x in enumerate(l): + for iy, y in enumerate(l): + for iz, z in enumerate(l): + + if x + y + z == key: + return x, y, z + +with open("sum.txt", "r", encoding="utf-8") as f: + s = f.read() +ls = s.split() +l = [int(x) for x in ls] +x, y, z = search(l, 2020) +pprint((x, y, z)) +print(x*y*z) + +