Skip to content

Commit 014ce5e

Browse files
author
Chris Poch
committed
Days 1 and 2 complete
1 parent cfcbdc3 commit 014ce5e

File tree

5 files changed

+1264
-0
lines changed

5 files changed

+1264
-0
lines changed

1.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
3+
with open("1.txt") as file:
4+
nums = file.readlines()
5+
for num1 in nums:
6+
for num2 in nums:
7+
if int(num1) + int(num2) == 2020:
8+
print(num1, num2, str(int(num1)*int(num2)),sep=" ")
9+
print("Part 2")
10+
for num1 in nums:
11+
for num2 in nums:
12+
for num3 in nums:
13+
if int(num1) + int(num2) + int(num3) == 2020:
14+
print(num1, num2, num3, str(int(num1)*int(num2)*int(num3)),sep=" ")

1.txt

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
1446
2+
1893
3+
1827
4+
1565
5+
1728
6+
497
7+
1406
8+
1960
9+
1986
10+
1945
11+
1731
12+
1925
13+
1550
14+
1841
15+
1789
16+
1952
17+
1610
18+
1601
19+
1776
20+
1808
21+
1812
22+
1834
23+
1454
24+
1729
25+
513
26+
1894
27+
1703
28+
1587
29+
1788
30+
1690
31+
1655
32+
1473
33+
1822
34+
1437
35+
1626
36+
1447
37+
1400
38+
1396
39+
1715
40+
1720
41+
1469
42+
1388
43+
1874
44+
1641
45+
518
46+
1664
47+
1552
48+
1800
49+
512
50+
1506
51+
1806
52+
1857
53+
1802
54+
1843
55+
1956
56+
1678
57+
1560
58+
1971
59+
1940
60+
1847
61+
1902
62+
1500
63+
1383
64+
1386
65+
1398
66+
1535
67+
1713
68+
1931
69+
1619
70+
1519
71+
1897
72+
1767
73+
1548
74+
1976
75+
1984
76+
1426
77+
914
78+
2000
79+
1585
80+
1634
81+
1832
82+
1849
83+
1665
84+
1609
85+
1670
86+
1520
87+
1490
88+
1746
89+
1608
90+
1829
91+
1431
92+
1762
93+
1384
94+
1504
95+
1434
96+
1356
97+
1654
98+
1719
99+
1599
100+
1686
101+
1489
102+
1377
103+
1531
104+
1912
105+
144
106+
1875
107+
1532
108+
1439
109+
1482
110+
1420
111+
1529
112+
1554
113+
1826
114+
1546
115+
1589
116+
1993
117+
1518
118+
1708
119+
1733
120+
1876
121+
1953
122+
1741
123+
1689
124+
773
125+
1455
126+
1613
127+
2004
128+
1819
129+
1725
130+
1617
131+
1498
132+
1651
133+
2007
134+
1402
135+
728
136+
1475
137+
1928
138+
1904
139+
1969
140+
1851
141+
1296
142+
1558
143+
1817
144+
1663
145+
1750
146+
1780
147+
1501
148+
1443
149+
1734
150+
1977
151+
1901
152+
1547
153+
1631
154+
1644
155+
1815
156+
1949
157+
1586
158+
1697
159+
1435
160+
1783
161+
1772
162+
1987
163+
1483
164+
1372
165+
1999
166+
1848
167+
1512
168+
1541
169+
1861
170+
2008
171+
1607
172+
1622
173+
1629
174+
1763
175+
1656
176+
1661
177+
1581
178+
1968
179+
1985
180+
1974
181+
1882
182+
995
183+
1704
184+
1896
185+
1611
186+
1888
187+
1773
188+
1810
189+
1650
190+
1712
191+
1410
192+
1796
193+
1691
194+
1671
195+
1947
196+
1775
197+
1593
198+
656
199+
1530
200+
1743

2.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import os
2+
3+
4+
#initial
5+
with open("2.txt") as file:
6+
lines = file.readlines()
7+
total = 0
8+
valid = 0
9+
invalid = 0
10+
11+
for line in lines:
12+
total = total + 1
13+
14+
sep = line.find("-")
15+
space = line.find(" ")
16+
min = int(line[0:sep])
17+
max = int(line[sep + 1:space])
18+
letter = line[space + 1]
19+
password = line[space + 4:]
20+
21+
found = password.count(letter)
22+
if found >= min and found <= max:
23+
valid = valid + 1
24+
else:
25+
invalid = invalid + 1
26+
print(total, valid, invalid)
27+
28+
#part2
29+
total = 0
30+
valid = 0
31+
invalid = 0
32+
33+
for line in lines:
34+
total = total + 1
35+
36+
sep = line.find("-")
37+
space = line.find(" ")
38+
pos1 = int(line[0:sep]) - 1
39+
pos2 = int(line[sep + 1:space]) - 1
40+
letter = line[space + 1]
41+
password = line[space + 4:]
42+
#print (line, str(pos1), str(sep), str(pos2), str(space), letter, password)
43+
44+
if (password[pos1] == letter or password[pos2] == letter) and (password[pos1] != password[pos2]):
45+
valid = valid + 1
46+
else:
47+
invalid = invalid + 1
48+
print(total, valid, invalid)

0 commit comments

Comments
 (0)