-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dde7a5b
Showing
72 changed files
with
16,409 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
1254 | ||
1313 | ||
1456 | ||
1782 | ||
1742 | ||
1391 | ||
1273 | ||
1286 | ||
1373 | ||
1891 | ||
1188 | ||
1994 | ||
1887 | ||
1816 | ||
1984 | ||
961 | ||
1428 | ||
1105 | ||
1123 | ||
1699 | ||
1154 | ||
1953 | ||
1977 | ||
1450 | ||
1696 | ||
1068 | ||
1241 | ||
1926 | ||
1228 | ||
1591 | ||
1789 | ||
1966 | ||
1508 | ||
1193 | ||
1190 | ||
1654 | ||
444 | ||
1282 | ||
1169 | ||
1165 | ||
1778 | ||
1669 | ||
1570 | ||
1671 | ||
1845 | ||
1208 | ||
1728 | ||
1798 | ||
847 | ||
1300 | ||
1817 | ||
1200 | ||
1297 | ||
1658 | ||
1296 | ||
1571 | ||
1991 | ||
1305 | ||
1314 | ||
1903 | ||
1472 | ||
1359 | ||
1506 | ||
1999 | ||
1877 | ||
1168 | ||
1137 | ||
1288 | ||
1083 | ||
1656 | ||
413 | ||
1430 | ||
1408 | ||
1397 | ||
1846 | ||
1218 | ||
684 | ||
1234 | ||
2007 | ||
900 | ||
1604 | ||
1460 | ||
1848 | ||
1693 | ||
1324 | ||
1401 | ||
1968 | ||
1918 | ||
1975 | ||
1665 | ||
1413 | ||
1874 | ||
1852 | ||
1521 | ||
1753 | ||
1229 | ||
1940 | ||
1650 | ||
1976 | ||
1235 | ||
1130 | ||
1927 | ||
1365 | ||
1908 | ||
1441 | ||
1302 | ||
1986 | ||
1449 | ||
1692 | ||
1944 | ||
1277 | ||
1312 | ||
1826 | ||
1231 | ||
1289 | ||
1814 | ||
1170 | ||
1606 | ||
1608 | ||
1773 | ||
1883 | ||
1936 | ||
1626 | ||
1497 | ||
1860 | ||
1673 | ||
1295 | ||
2005 | ||
1481 | ||
1995 | ||
1734 | ||
1646 | ||
1557 | ||
1298 | ||
1174 | ||
1894 | ||
1309 | ||
1240 | ||
1982 | ||
1414 | ||
1799 | ||
1620 | ||
1863 | ||
1220 | ||
1642 | ||
508 | ||
1146 | ||
1187 | ||
1253 | ||
1284 | ||
1952 | ||
1527 | ||
1610 | ||
1333 | ||
1221 | ||
1362 | ||
1457 | ||
1721 | ||
1493 | ||
1330 | ||
156 | ||
1647 | ||
1841 | ||
1724 | ||
2000 | ||
1398 | ||
1745 | ||
1985 | ||
1269 | ||
1722 | ||
2001 | ||
1923 | ||
1395 | ||
1094 | ||
1140 | ||
1958 | ||
1239 | ||
1336 | ||
1588 | ||
1338 | ||
1750 | ||
1757 | ||
1444 | ||
1822 | ||
1335 | ||
1941 | ||
1865 | ||
1767 | ||
1881 | ||
1499 | ||
1157 | ||
1990 | ||
1210 | ||
1779 | ||
1201 | ||
1784 | ||
1961 | ||
1476 | ||
1861 | ||
1468 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import filecmp | ||
|
||
if __name__ == "__main__": | ||
inputFile = open("input", "r") | ||
fileLines = inputFile.readlines() | ||
numbers = [int(line) for line in fileLines] | ||
|
||
found = False | ||
for i in range(len(numbers)): | ||
for j in range(i, len(numbers)): | ||
numbersI = numbers[i] | ||
numbersJ = numbers[j] | ||
if numbersI + numbersJ == 2020: | ||
found = True | ||
print("Part 1 Found: " + str(numbersI * numbersJ)) | ||
break | ||
if found: | ||
break | ||
|
||
found = False | ||
for i in range(len(numbers)): | ||
for j in range(i, len(numbers)): | ||
for k in range(j, len(numbers)): | ||
numbersI = numbers[i] | ||
numbersJ = numbers[j] | ||
numbersK = numbers[k] | ||
if numbersI + numbersJ + numbersK == 2020: | ||
found = True | ||
print("Part 2 Found: " + str(numbersI * numbersJ * numbersK)) | ||
break | ||
if found: | ||
break | ||
if found: | ||
break | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
38 | ||
23 | ||
31 | ||
16 | ||
141 | ||
2 | ||
124 | ||
25 | ||
37 | ||
147 | ||
86 | ||
150 | ||
99 | ||
75 | ||
81 | ||
121 | ||
93 | ||
120 | ||
96 | ||
55 | ||
48 | ||
58 | ||
108 | ||
22 | ||
132 | ||
62 | ||
107 | ||
54 | ||
69 | ||
51 | ||
7 | ||
134 | ||
143 | ||
122 | ||
28 | ||
60 | ||
123 | ||
82 | ||
95 | ||
14 | ||
6 | ||
106 | ||
41 | ||
131 | ||
109 | ||
90 | ||
112 | ||
1 | ||
103 | ||
44 | ||
127 | ||
9 | ||
83 | ||
59 | ||
117 | ||
8 | ||
140 | ||
151 | ||
89 | ||
35 | ||
148 | ||
76 | ||
100 | ||
114 | ||
130 | ||
19 | ||
72 | ||
36 | ||
133 | ||
12 | ||
34 | ||
46 | ||
15 | ||
45 | ||
87 | ||
144 | ||
80 | ||
13 | ||
142 | ||
149 | ||
88 | ||
94 | ||
61 | ||
154 | ||
24 | ||
66 | ||
113 | ||
5 | ||
73 | ||
79 | ||
74 | ||
65 | ||
137 | ||
47 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import os | ||
|
||
def part1(adapters): | ||
sortedAdapters = sorted(adapters) | ||
|
||
differences = { | ||
1: 0, | ||
2: 0, | ||
3: 1, # Initialize as 1 because device joltage is always 3 more than the largest adapter | ||
} | ||
for idx in range(len(sortedAdapters)): | ||
prevAdapter = sortedAdapters[idx - 1] if idx > 0 else 0 | ||
currAdapter = sortedAdapters[idx] | ||
differences[currAdapter - prevAdapter] += 1 | ||
|
||
print(f"Part 1 - Solution: {differences[1] * differences[3]}") | ||
|
||
waysMem = {} # For memoization | ||
def countWays(sortedAdapters): | ||
ways = 0 | ||
currAdapter = sortedAdapters[0] | ||
for nextIdx in range(1, len(sortedAdapters)): | ||
nextAdapter = sortedAdapters[nextIdx] | ||
|
||
if nextAdapter - currAdapter <= 3: | ||
nextWays = None | ||
if nextAdapter in waysMem: | ||
nextWays = waysMem[nextAdapter] | ||
else: | ||
nextWays = countWays(sortedAdapters[nextIdx:]) | ||
waysMem[nextAdapter] = nextWays | ||
|
||
ways += 1 * (nextWays if nextWays > 0 else 1) | ||
else: | ||
break | ||
|
||
# print(f"Ways: {ways} for adapter {sortedAdapters[0]}") | ||
return ways | ||
|
||
def part2(adapters): | ||
sortedAdapters = sorted(adapters) | ||
|
||
# Add socket and device to make the full chain | ||
fullChain = sortedAdapters[:] | ||
fullChain.insert(0, 0) | ||
fullChain.insert(len(sortedAdapters), sortedAdapters[-1] + 3) | ||
# print(fullChain) | ||
|
||
ways = countWays(fullChain) | ||
print(f"Part 2 - Solution: {ways}") | ||
|
||
if __name__ == "__main__": | ||
dirname = os.path.dirname(__file__) | ||
filename = os.path.join(dirname, "input.txt") | ||
|
||
with open(filename, "r") as fileInput: | ||
fileLines = fileInput.readlines() | ||
lines = [line.strip() for line in fileLines] | ||
|
||
adapters = [int(adapter) for adapter in lines] | ||
|
||
part1(adapters) | ||
part2(adapters) |
Oops, something went wrong.