Solve day 01

This commit is contained in:
Vicky Steeves 2020-12-01 14:17:07 -05:00
commit 517e93c440
2 changed files with 727 additions and 0 deletions

200
day01-1-input.txt Normal file
View File

@ -0,0 +1,200 @@
1918
1869
1821
1852
1981
1987
1989
1597
1634
1537
1991
1603
1543
1949
1879
1800
1761
2010
1810
1458
1755
1938
1500
2005
818
1493
1618
1923
1283
1952
1373
1605
1230
1321
1873
1853
1886
1372
1913
1871
159
733
1400
1880
1462
2007
1801
1982
1728
1640
1442
1525
1953
1791
1906
1946
1641
2009
1627
1935
1936
1908
1826
1291
1978
1884
1799
1464
1538
1365
1678
1872
1964
1863
1388
1912
1928
1471
1632
1336
1396
1948
1974
1331
1290
1992
1096
1889
1874
1341
757
1351
1876
1674
2002
1504
1865
1469
1792
1920
1925
1898
1899
1435
405
1488
1319
1322
1749
1867
1957
1944
1727
1293
1739
1285
1917
1897
1844
1966
1921
1905
1830
1484
1364
1782
1415
1412
1413
833
1857
1370
1890
1393
1262
1311
2008
1545
1896
1362
1862
1617
1864
608
1868
1689
1784
1806
1976
1870
1973
1993
1986
1998
1414
1858
1990
1841
1895
1779
1850
2001
1590
1902
1487
943
1808
782
1546
2004
1656
154
1661
1688
1731
1466
1927
1438
1387
1576
1793
1797
1979
1903
1638
1940
1911
1301
1669
1409
1578
1887
1860
1619
1939
1625
1941
1374
1766
1407

527
day01.ipynb Normal file
View File

@ -0,0 +1,527 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"input_1 = open('day01-1-input.txt')"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['1918\\n',\n",
" '1869\\n',\n",
" '1821\\n',\n",
" '1852\\n',\n",
" '1981\\n',\n",
" '1987\\n',\n",
" '1989\\n',\n",
" '1597\\n',\n",
" '1634\\n',\n",
" '1537\\n',\n",
" '1991\\n',\n",
" '1603\\n',\n",
" '1543\\n',\n",
" '1949\\n',\n",
" '1879\\n',\n",
" '1800\\n',\n",
" '1761\\n',\n",
" '2010\\n',\n",
" '1810\\n',\n",
" '1458\\n',\n",
" '1755\\n',\n",
" '1938\\n',\n",
" '1500\\n',\n",
" '2005\\n',\n",
" '818\\n',\n",
" '1493\\n',\n",
" '1618\\n',\n",
" '1923\\n',\n",
" '1283\\n',\n",
" '1952\\n',\n",
" '1373\\n',\n",
" '1605\\n',\n",
" '1230\\n',\n",
" '1321\\n',\n",
" '1873\\n',\n",
" '1853\\n',\n",
" '1886\\n',\n",
" '1372\\n',\n",
" '1913\\n',\n",
" '1871\\n',\n",
" '159\\n',\n",
" '733\\n',\n",
" '1400\\n',\n",
" '1880\\n',\n",
" '1462\\n',\n",
" '2007\\n',\n",
" '1801\\n',\n",
" '1982\\n',\n",
" '1728\\n',\n",
" '1640\\n',\n",
" '1442\\n',\n",
" '1525\\n',\n",
" '1953\\n',\n",
" '1791\\n',\n",
" '1906\\n',\n",
" '1946\\n',\n",
" '1641\\n',\n",
" '2009\\n',\n",
" '1627\\n',\n",
" '1935\\n',\n",
" '1936\\n',\n",
" '1908\\n',\n",
" '1826\\n',\n",
" '1291\\n',\n",
" '1978\\n',\n",
" '1884\\n',\n",
" '1799\\n',\n",
" '1464\\n',\n",
" '1538\\n',\n",
" '1365\\n',\n",
" '1678\\n',\n",
" '1872\\n',\n",
" '1964\\n',\n",
" '1863\\n',\n",
" '1388\\n',\n",
" '1912\\n',\n",
" '1928\\n',\n",
" '1471\\n',\n",
" '1632\\n',\n",
" '1336\\n',\n",
" '1396\\n',\n",
" '1948\\n',\n",
" '1974\\n',\n",
" '1331\\n',\n",
" '1290\\n',\n",
" '1992\\n',\n",
" '1096\\n',\n",
" '1889\\n',\n",
" '1874\\n',\n",
" '1341\\n',\n",
" '757\\n',\n",
" '1351\\n',\n",
" '1876\\n',\n",
" '1674\\n',\n",
" '2002\\n',\n",
" '1504\\n',\n",
" '1865\\n',\n",
" '1469\\n',\n",
" '1792\\n',\n",
" '1920\\n',\n",
" '1925\\n',\n",
" '1898\\n',\n",
" '1899\\n',\n",
" '1435\\n',\n",
" '405\\n',\n",
" '1488\\n',\n",
" '1319\\n',\n",
" '1322\\n',\n",
" '1749\\n',\n",
" '1867\\n',\n",
" '1957\\n',\n",
" '1944\\n',\n",
" '1727\\n',\n",
" '1293\\n',\n",
" '1739\\n',\n",
" '1285\\n',\n",
" '1917\\n',\n",
" '1897\\n',\n",
" '1844\\n',\n",
" '1966\\n',\n",
" '1921\\n',\n",
" '1905\\n',\n",
" '1830\\n',\n",
" '1484\\n',\n",
" '1364\\n',\n",
" '1782\\n',\n",
" '1415\\n',\n",
" '1412\\n',\n",
" '1413\\n',\n",
" '833\\n',\n",
" '1857\\n',\n",
" '1370\\n',\n",
" '1890\\n',\n",
" '1393\\n',\n",
" '1262\\n',\n",
" '1311\\n',\n",
" '2008\\n',\n",
" '1545\\n',\n",
" '1896\\n',\n",
" '1362\\n',\n",
" '1862\\n',\n",
" '1617\\n',\n",
" '1864\\n',\n",
" '608\\n',\n",
" '1868\\n',\n",
" '1689\\n',\n",
" '1784\\n',\n",
" '1806\\n',\n",
" '1976\\n',\n",
" '1870\\n',\n",
" '1973\\n',\n",
" '1993\\n',\n",
" '1986\\n',\n",
" '1998\\n',\n",
" '1414\\n',\n",
" '1858\\n',\n",
" '1990\\n',\n",
" '1841\\n',\n",
" '1895\\n',\n",
" '1779\\n',\n",
" '1850\\n',\n",
" '2001\\n',\n",
" '1590\\n',\n",
" '1902\\n',\n",
" '1487\\n',\n",
" '943\\n',\n",
" '1808\\n',\n",
" '782\\n',\n",
" '1546\\n',\n",
" '2004\\n',\n",
" '1656\\n',\n",
" '154\\n',\n",
" '1661\\n',\n",
" '1688\\n',\n",
" '1731\\n',\n",
" '1466\\n',\n",
" '1927\\n',\n",
" '1438\\n',\n",
" '1387\\n',\n",
" '1576\\n',\n",
" '1793\\n',\n",
" '1797\\n',\n",
" '1979\\n',\n",
" '1903\\n',\n",
" '1638\\n',\n",
" '1940\\n',\n",
" '1911\\n',\n",
" '1301\\n',\n",
" '1669\\n',\n",
" '1409\\n',\n",
" '1578\\n',\n",
" '1887\\n',\n",
" '1860\\n',\n",
" '1619\\n',\n",
" '1939\\n',\n",
" '1625\\n',\n",
" '1941\\n',\n",
" '1374\\n',\n",
" '1766\\n',\n",
" '1407\\n']"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"input_1 = list(input_1)\n",
"input_1"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1918,\n",
" 1869,\n",
" 1821,\n",
" 1852,\n",
" 1981,\n",
" 1987,\n",
" 1989,\n",
" 1597,\n",
" 1634,\n",
" 1537,\n",
" 1991,\n",
" 1603,\n",
" 1543,\n",
" 1949,\n",
" 1879,\n",
" 1800,\n",
" 1761,\n",
" 2010,\n",
" 1810,\n",
" 1458,\n",
" 1755,\n",
" 1938,\n",
" 1500,\n",
" 2005,\n",
" 818,\n",
" 1493,\n",
" 1618,\n",
" 1923,\n",
" 1283,\n",
" 1952,\n",
" 1373,\n",
" 1605,\n",
" 1230,\n",
" 1321,\n",
" 1873,\n",
" 1853,\n",
" 1886,\n",
" 1372,\n",
" 1913,\n",
" 1871,\n",
" 159,\n",
" 733,\n",
" 1400,\n",
" 1880,\n",
" 1462,\n",
" 2007,\n",
" 1801,\n",
" 1982,\n",
" 1728,\n",
" 1640,\n",
" 1442,\n",
" 1525,\n",
" 1953,\n",
" 1791,\n",
" 1906,\n",
" 1946,\n",
" 1641,\n",
" 2009,\n",
" 1627,\n",
" 1935,\n",
" 1936,\n",
" 1908,\n",
" 1826,\n",
" 1291,\n",
" 1978,\n",
" 1884,\n",
" 1799,\n",
" 1464,\n",
" 1538,\n",
" 1365,\n",
" 1678,\n",
" 1872,\n",
" 1964,\n",
" 1863,\n",
" 1388,\n",
" 1912,\n",
" 1928,\n",
" 1471,\n",
" 1632,\n",
" 1336,\n",
" 1396,\n",
" 1948,\n",
" 1974,\n",
" 1331,\n",
" 1290,\n",
" 1992,\n",
" 1096,\n",
" 1889,\n",
" 1874,\n",
" 1341,\n",
" 757,\n",
" 1351,\n",
" 1876,\n",
" 1674,\n",
" 2002,\n",
" 1504,\n",
" 1865,\n",
" 1469,\n",
" 1792,\n",
" 1920,\n",
" 1925,\n",
" 1898,\n",
" 1899,\n",
" 1435,\n",
" 405,\n",
" 1488,\n",
" 1319,\n",
" 1322,\n",
" 1749,\n",
" 1867,\n",
" 1957,\n",
" 1944,\n",
" 1727,\n",
" 1293,\n",
" 1739,\n",
" 1285,\n",
" 1917,\n",
" 1897,\n",
" 1844,\n",
" 1966,\n",
" 1921,\n",
" 1905,\n",
" 1830,\n",
" 1484,\n",
" 1364,\n",
" 1782,\n",
" 1415,\n",
" 1412,\n",
" 1413,\n",
" 833,\n",
" 1857,\n",
" 1370,\n",
" 1890,\n",
" 1393,\n",
" 1262,\n",
" 1311,\n",
" 2008,\n",
" 1545,\n",
" 1896,\n",
" 1362,\n",
" 1862,\n",
" 1617,\n",
" 1864,\n",
" 608,\n",
" 1868,\n",
" 1689,\n",
" 1784,\n",
" 1806,\n",
" 1976,\n",
" 1870,\n",
" 1973,\n",
" 1993,\n",
" 1986,\n",
" 1998,\n",
" 1414,\n",
" 1858,\n",
" 1990,\n",
" 1841,\n",
" 1895,\n",
" 1779,\n",
" 1850,\n",
" 2001,\n",
" 1590,\n",
" 1902,\n",
" 1487,\n",
" 943,\n",
" 1808,\n",
" 782,\n",
" 1546,\n",
" 2004,\n",
" 1656,\n",
" 154,\n",
" 1661,\n",
" 1688,\n",
" 1731,\n",
" 1466,\n",
" 1927,\n",
" 1438,\n",
" 1387,\n",
" 1576,\n",
" 1793,\n",
" 1797,\n",
" 1979,\n",
" 1903,\n",
" 1638,\n",
" 1940,\n",
" 1911,\n",
" 1301,\n",
" 1669,\n",
" 1409,\n",
" 1578,\n",
" 1887,\n",
" 1860,\n",
" 1619,\n",
" 1939,\n",
" 1625,\n",
" 1941,\n",
" 1374,\n",
" 1766,\n",
" 1407]"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"numbers = []\n",
"for item in input_1:\n",
" item = item[:-1]\n",
" numbers.append(int(item))\n",
"numbers"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"858496\n"
]
}
],
"source": [
"for i in range(0, len(numbers)):\n",
" for j in range(i + 1, len(numbers)):\n",
" if numbers[i] + numbers[j] == 2020:\n",
" print(numbers[i] * numbers[j])\n",
" break"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"263819430\n"
]
}
],
"source": [
"for i in range(0, len(numbers)):\n",
" for j in range(i + 1, len(numbers)):\n",
" for k in range(j + 1, len(numbers)):\n",
" if numbers[i] + numbers[j] + numbers[k] == 2020:\n",
" print(numbers[i] * numbers[j] * numbers[k])\n",
" break"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}