new structure for 2018, added license information

This commit is contained in:
Akumatic
2019-12-03 00:24:58 +01:00
parent e79d6aa6a6
commit 200d471145
60 changed files with 1257 additions and 73 deletions

49
2018/02/README.md Normal file
View File

@ -0,0 +1,49 @@
# 2018 Day 2: Inventory Management System
Copyright (c) Eric Wastl
#### [Direct Link](https://adventofcode.com/2018/day/2)
## Part 1
You stop falling through time, catch your breath, and check the screen on the device. "Destination reached. Current Year: 1518. Current Location: North Pole Utility Closet 83N10." You made it! Now, to find those anomalies.
Outside the utility closet, you hear footsteps and a voice. "...I'm not sure either. But now that so many people have chimneys, maybe he could sneak in that way?" Another voice responds, "Actually, we've been working on a new kind of **suit** that would let him fit through tight spaces like that. But, I heard that a few days ago, they lost the prototype fabric, the design plans, everything! Nobody on the team can even seem to remember important details of the project!"
"Wouldn't they have had enough fabric to fill several boxes in the warehouse? They'd be stored together, so the box IDs should be similar. Too bad it would take forever to search the warehouse for **two similar box IDs**..." They walk too far away to hear any more.
Late at night, you sneak to the warehouse - who knows what kinds of paradoxes you could cause if you were discovered - and use your fancy wrist device to quickly scan every box and produce a list of the likely candidates (your puzzle input).
To make sure you didn't miss any, you scan the likely candidate boxes again, counting the number that have an ID containing **exactly two of any letter** and then separately counting those with **exactly three of any letter**. You can multiply those two counts together to get a rudimentary [checksum](https://en.wikipedia.org/wiki/Checksum) and compare it to what your device predicts.
For example, if you see the following box IDs:
- `abcdef` contains no letters that appear exactly two or three times.
- `bababc` contains two `a` and three `b`, so it counts for both.
- `abbcde` contains two `b`, but no letter appears exactly three times.
- `abcccd` contains three `c`, but no letter appears exactly two times.
- `aabcdd` contains two `a` and two `d`, but it only counts once.
- `abcdee` contains two `e`.
- `ababab` contains three `a` and three `b`, but it only counts once.
Of these box IDs, four of them contain a letter which appears exactly twice, and three of them contain a letter which appears exactly three times. Multiplying these together produces a checksum of `4 * 3 = 12`.
**What is the checksum** for your list of box IDs?
## Part 2
Confident that your list of box IDs is complete, you're ready to find the boxes full of prototype fabric.
The boxes will have IDs which differ by exactly one character at the same position in both strings. For example, given the following box IDs:
```
abcde
fghij
klmno
pqrst
fguij
axcye
wvxyz
```
The IDs `abcde` and `axcye` are close, but they differ by two characters (the second and fourth). However, the IDs `fghij` and `fguij` differ by exactly one character, the third (`h` and `u`). Those must be the correct boxes.
**What letters are common between the two correct box IDs?** (In the example above, this is found by removing the differing character from either ID, producing `fgij`.)

54
2018/02/code.py Normal file
View File

@ -0,0 +1,54 @@
""" https://adventofcode.com/2018/day/2 """
def readFile():
l = []
with open(f"{__file__.rstrip('code.py')}input.txt", "r") as f:
line = f.readline()
while line:
l.append(line)
line = f.readline()
return l
def count(data : dict, n : int):
sum = 0
for val in data:
for char in val:
if data[val][char] == n:
sum += 1
break
return sum
def part1(vals : list):
data = {}
# Count for each letter per word
for val in vals:
data[val] = {}
for char in val:
if char in data[val]:
data[val][char] = data[val][char] + 1
else:
data[val][char] = 1
return count(data, 2) * count(data, 3)
def getCommonLetters(a : str, b : str):
lenMin = min(len(a), len(b))
commons = [a[i] for i in range(lenMin) if a[i] == b[i]]
return "".join(commons)
def part2(vals : list):
maxLen = 0
maxStr = ""
for i in range(len(vals)):
for j in range(i + 1, len(vals)):
cur = getCommonLetters(vals[i], vals[j])
if len(cur) > maxLen:
maxLen = len(cur)
maxStr = cur
return maxStr
if __name__ == "__main__":
vals = readFile()
print(f"Part 1: {part1(vals)}")
print(f"Part 2: {part2(vals)}")

250
2018/02/input.txt Normal file
View File

@ -0,0 +1,250 @@
asgwdcmbrkerohqoutfylvzpnx
asgwjcmbrkejihqoutfylvipne
asgwjcmbrkedihqoutvylizpnz
azgsjcmbrkedihqouifylvzpnx
asgwucmbrktddhqoutfylvzpnx
asgwocmbrkedihqoutfylvzivx
aqgwjcmbrkevihqvutfylvzpnx
tsgljcmbrkedihqourfylvzpnx
asgpjcmbrkedihqoutfnlvzsnx
astwjcmbrktdihqrutfylvzpnx
asgwjcmbrpedhhqoutfylvzynx
xsgwjcmbrkedieqowtfylvzpnx
asgwjcmbvkedihfoutnylvzpnx
asgwjcmtrkedihqouafylvzcnx
asgwjcmbrkedihqoutfylvxpvm
usgwjcmbrkedihqortfyuvzpnx
asgwjcmbrwedihqoutfylizpix
asgrjcvbrkedixqoutfylvzpnx
asgwjcmbrogdihqoutfelvzpnx
aggwjcmbrkesihqoutoylvzpnx
asgtjccbrkedihqoutfrlvzpnx
asgcucmbrbedihqoutfylvzpnx
esgwjcmbrkedihqsutfylvzcnx
asgwjcmbrkedrhqoutfyobzpnx
mngwjcbbrkedihqoutfylvzpnx
asgwjcrbrkeoihqyutfylvzpnx
apgwjcmbrkednhqogtfylvzpnx
asgwjcwbrkedihqoutfylplpnx
asgwjcmbrkfdihqoutfxlvzpyx
aegwjcmbrkedihqoutfylbxpnx
asgljcmbrkedixqoutaylvzpnx
aigwjcmbrkedihqouhfylvzpex
asgwjbmbrkedihqoutfylfzpnp
asgwjcmzroedihqoutcylvzinx
asgwjcwbrieuihqoutfylvzpnx
aagwjcmbrkedjhqdutfylvzpnx
ahgwjcmbrkedihqsutfylvzpfx
asgwjcmbrkedihzosttylvzpnx
aegwjcmbrkedioqnutfylvzpnx
asgwjcmbykidihqoutfysvzpnx
asgwkcxbrkeddhqoutfylvzpnx
ashwjcmbrkeeihqoutfylvzknx
acgwjcmbrqedihqoqtfylvzpnx
asgwjcmtrkedihooutfylszpnx
asgwjcmbrkmdihqfutrylvzpnx
asgwjcmbrkedihqoutjylvapnn
asgwjcmbwkedihqoutkylkzpnx
asgwjrmbrkedihqoutfycnzpnx
asgwtcmbrkedihqoqtfylozpnx
asgajcmbrkedihqoutuylvzpny
asgwjcmbykedihqoutfylfzpwx
asgwjcsbrkedihpoutfylvvpnx
hsdwjcmbrvedihqoutfylvzpnx
asgwjcmbrkedihqoutfdmszpnx
adgwjcmbrtidihqoutfylvzpnx
augwjcmbriedihqoutgylvzpnx
asgwjvmbreedihqoutfllvzpnx
asgwjcnbfkedihqoltfylvzpnx
asgwjcmbykddihqoutqylvzpnx
ajgwjcmbrkedihqoutfylvpvnx
asgwjcmbrkydihqoutfylszpnl
xsgwjcmbrkqdihqoutfylvkpnx
asgwjcmbrkedimqoutfklvzknx
csgwjbmbrkedihqoftfylvzpnx
asgwjcmbjkedihjoutfylvzpnn
asgwjcmprkedihqoulfalvzpnx
asgwjcmbrvediqqoutfyuvzpnx
asgwjambrkedhhqoutkylvzpnx
asgejcmbrkidihqoutfylvzpnk
hsiwjcmbrkedihqoutfylvzpnq
asswjczbrkedihqoutfylczpnx
asgwjnmbrkedyhzoutfylvzpnx
asgwscmbrkedihqoutfklvlpnx
asgwlcmbrktdihqoutfylvzpax
asfwjcmerkedihqoutfylvipnx
asgwjcmbrkeditqoeafylvzpnx
asgwgcmbrkesihqoutfylyzpnx
fsgwjcmbrkedihqouvfyavzpnx
asgwjcmbrpedwhqoutfylmzpnx
asgwjcmbrkzdzhqoucfylvzpnx
asgwjcmnrketmhqoutfylvzpnx
asgwjcmbrkedihxoutsylvzpnh
asgwjcobrkedihqoutfrlvzpox
asgwjcmbrkedihqootfylxzpox
asgjjcmcrkedihqoutfylmzpnx
lsgwjcmbrkedihqoutfyqvzunx
asgwjcmbrwedihqoutoylvzpnu
aszwjcmbtkedihqoutfylczpnx
asgwjcmbykedihqoutfylvgpex
asgijcmbrkedilqoutkylvzpnx
astwxcmzrkedihqoutfylvzpnx
akgwjcmbnkedihqfutfylvzpnx
asgwjcmbrqndivqoutfylvzpnx
asgwjrmbrleqihqoutfylvzpnx
asgwjcmbrkevihqoutfxlvzpvx
asbwjcmbrkedihqoutfelvwpnx
asewjcbbrkmdihqoutfylvzpnx
asgwjcmbrkeaihxoutfylpzpnx
asgwjzmbrkedihqrotfylvzpnx
asgwjcmbrkedihqoutgdxvzpnx
asgwjcwbrkmdihqoutfylvzlnx
asgwjcmbrkegihqoutfylrzpax
ajgwjcmbrkegihqhutfylvzpnx
asgwjcmbrzedihqhutfylvkpnx
asgwjcmwrkedihqouhfylkzpnx
aygwjcmbrkedihqoutfdlvzpnr
asgwjcmbrkednhqoutiylvypnx
aqgwjcmbrkezihqoutfylvzonx
bsgwjcmbrkedihqouhfylvzsnx
asgwjcmcrkedihqokyfylvzpnx
asgsjcmbrkewiyqoutfylvzpnx
asgwpcmbrkejihqoutfylzzpnx
asgwjumbrkedbeqoutfylvzpnx
asgwjcmbrkedihpoutqylqzpnx
awgwjcmbrredihqoutfylvzpna
asgwjsmbraedihqoutfylvzpvx
asgwncmbrkedihqoutfyljzrnx
asgwncmbrkedihqohtfylvzonx
asgwjcmbrkedihqlutfylvypux
asgwjcmbbkedihooutfylkzpnx
asghjcmsryedihqoutfylvzpnx
asgwjcmbrkevihqoulfzlvzpnx
asggjcmbrkedizqoutfylvzknx
asbwjcmbriedihqoutfylvmpnx
asgwjcmbrkedqbqoutfylvzenx
asgwjcmprkedihqoutfylvzknp
asgwjcmbrkerihqoutfwlvzpno
asgwjcmvrkesihqoutrylvzpnx
asgzjcmbrkedihqoutfnlvbpnx
asfwjcmbrkhdihqoutfylpzpnx
asgwjcmbskedihqdutfyyvzpnx
asgwjcmzrkedihqoutcylvzinx
asgwjcmbrkedibqoutfylvjonx
asgwjcmbrbedihqoutfylmzbnx
asgwjcmbrkedhhqoutmylczpnx
asgwjcmbrkbgihqoutzylvzpnx
asgwjcfbrkedihqoupfyxvzpnx
asiwjcmbzkedihqoutfyluzpnx
asvwjcmbrkedihqoitfylvzpns
asgwjcmxikedihqoutfyevzpnx
asgwjcmbrkedioqoutfylvzwox
asgwjcmbrkedivqoutjyuvzpnx
asgwjcmbkkydihqrutfylvzpnx
asgwjcmbrkxdiuqoutfylvopnx
asgwjcmbrkedihqouthylvzpra
asgwjcmbrzedimloutfylvzpnx
asgwjcmbrkedmhqoulfytvzpnx
asgwjcmbrkzdihqrutfysvzpnx
ssgwjcmxrkedihqoutftlvzpnx
asgwjcmbrkedihqoutfajvzynx
asgwjcmbrkqdihqxuufylvzpnx
asmwjcabrkedihqouxfylvzpnx
asgwjcmbrkeeihqoatfycvzpnx
asgwjcjbrgedjhqoutfylvzpnx
asgljcmtrkedihqoutoylvzpnx
asgwjcmbrkedigqouzfylvzpvx
ajgvjcmbkkedihqoutfylvzpnx
asgwjcmbrkedihqtugfygvzpnx
asgbjcmbrkedihboftfylvzpnx
asgwjwmbrkedihqontfylhzpnx
asgwjfmhrkedihqoutfylvqpnx
asgwjxmbrkedihqoutzylvzpnj
asgwjcrlrkedihqoutfylvzpsx
aygwjcmbrkedihqoutsylvzdnx
zsgwjcmbrkedihjogtfylvzpnx
asgwjxmbrkegihqoutfylvopnx
asgwjcmbrkedihqhutfylvzcnr
asgwicmbrkewihvoutfylvzpnx
asqwjcmbvkedihqoutfylvzknx
asgwjcmbrkedihqoktfyevzpnu
asgwjcmbrkudihqoutfylqzznx
asgwjdmbrkedihqoutfylvvdnx
asgwjcmbrkwmihqautfylvzpnx
asgwjcmbrxedihqoctfyldzpnx
asgwjdmbrkedjhqoutfyfvzpnx
asgwjcmtrzedihqoutfylvzpnm
bpgwjcmbrmedihqoutfylvzpnx
asgwjctbrkedihqoqtfynvzpnx
askhjcmbrkedihqoutfylvzrnx
asgkjcmblkehihqoutfylvzpnx
asgwjjmbrkedvhqoutfhlvzpnx
asgwjcmbrkedihqoupzylvzknx
asgwjcmbukedchqoutfylizpnx
askwjcmdrkedihqoutwylvzpnx
asgwjcmbtkcdihloutfylvzpnx
asgwjcmbrkedwgqoutvylvzpnx
asmwjcmbrkedihqoutfylozpnc
asgwjcmbriedibqouofylvzpnx
asgnjcmcrkedihqoupfylvzpnx
asgzjcmbrksdihqoutiylvzpnx
asgwjcrbkkedihqouafylvzpnx
asgwjcmbkkvdihqqutfylvzpnx
astwjcqbrkedihqoutfylvzpvx
asgwjcmhrkehihqoutfylvzvnx
asgwjcmbraeduhqoutmylvzpnx
asgwjcmbrkedihquutnylvzptx
asgwjcmbrkedilqoftfylvzpnz
akgwjmmbrkedihqoutfylxzpnx
asgwjcmbrkhxikqoutfylvzpnx
asgcjcmetkedihqoutfylvzpnx
fsgwjcmsrkedihooutfylvzpnx
gsgwjcmbrkedihdoutfylvzdnx
asgwtccbrkedihqoutfylvwpnx
asuwjcmbrkedihqcutfylvzpox
asgwacmbrkodihqlutfylvzpnx
asgwjcmbrkediuqoutfylqhpnx
asgwjcmbrkwdrhqoutfylvzpno
angwjcsblkedihqoutfylvzpnx
aigwjcmbyoedihqoutfylvzpnx
adgwjcmbrkedihqtutfylyzpnx
asgwjzmbrkeeihqputfylvzpnx
asgwjcmbrkwdihqoutfylvzpwc
asgpjcmbrkgdihqbutfylvzpnx
osgwjmmbrkedijqoutfylvzpnx
asgjjcmbrkkdihqoutfylvzynx
asgwjcnerwedihqoutfylvzpnx
azgwhcmbrkedicqoutfylvzpnx
asnwjcmbrsedihqoutfylvzpnm
hsgwjcmgrkedihqoutfilvzpnx
asgwscmbrkjdihqoutfylvzpnm
asgbjbmbrkedhhqoutfylvzpnx
aswwjcmtrkedihqjutfylvzpnx
asgwicmbrbedihqoutfylvzpnm
asgwjcubrkedihqoutfylvbnnx
asvwjcmbrkehihqoutfylhzpnx
gsgwjcmbrkedihqoutsklvzpnx
asgwjcubikedihqoitfylvzpnx
asgwjpmbskedilqoutfylvzpnx
aigwjcmbrxedihqoutyylvzpnx
asgwjcpbrkedihxoutfynvzpnx
asgwjcmbrkegihqoutfklvzcnx
asgwjvubrkedjhqoutfylvzpnx
asgwjcabrkedihqoutfyivzplx
asgwjcxbrkedihqgutfylvepnx
asgwlcmbrkedihqoutqylvwpnx
asgwjhmbrkydihqhutfylvzpnx
asgwjcmbrkedihqoutfylwzone
asgwycmbrkadihqoutuylvzpnx
asgwjcybrkedihqoftfylvzpne
asgwjcmnrkedihrodtfylvzpnx
asgwicmwrkedihqoutfyovzpnx
aqgwjlmbrkedilqoutfylvzpnx
asgwjcmzskwdihqoutfylvzpnx
asgwjcmdrkebihqoutfylvjpnx
asgwjcmbrkpdihqoutfylxzphx
asgwjcmbrkedixqoutlylfzpnx
asgwjcmbrkadihqoutfylvlpdx
asgejcmqrkedyhqoutfylvzpnx
asgwjcmvroedihpoutfylvzpnx
asgwjcmxrkedihqoutfyivzpmx

2
2018/02/solution.txt Normal file
View File

@ -0,0 +1,2 @@
Part 1: 6175
Part 2: asgwjcmzredihqoutcylvzinx