diff --git a/day-02/01-checksum.py b/day-02/01-checksum.py new file mode 100644 index 0000000..49c51a1 --- /dev/null +++ b/day-02/01-checksum.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +with open('input.txt', 'r') as f: + package_ids = [x.strip() for x in f.readlines()] + +# print(package_ids) + +count_doubles = 0 +count_tripples = 0 + +for el in package_ids: + is_double = False + is_tripple = False + + for my_char in set(el): + count = el.count(my_char) + if count == 2: + is_double = True + if count == 3: + is_tripple = True + + if is_double: + count_doubles += 1 + if is_tripple: + count_tripples += 1 + +print('Entries:', len(package_ids)) +print('Doubles:', count_doubles) +print('Tripples:', count_tripples) +print('-' * 40) +print('Checksum:', count_doubles * count_tripples) diff --git a/day-02/02-close-ids.py b/day-02/02-close-ids.py new file mode 100644 index 0000000..e7ca9aa --- /dev/null +++ b/day-02/02-close-ids.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +with open('input.txt', 'r') as f: + package_ids = [x.strip() for x in f.readlines()] + +# print(package_ids) + +def find_close(package_ids): + for i, el_1 in enumerate(package_ids[:len(package_ids)]): + for el_2 in package_ids[i + 1:]: + diffs = 0 + for j, char_1 in enumerate(el_1): + char_2 = el_2[j] + if char_1 != char_2: + diffs += 1 + if diffs == 1: + return el_1, el_2 + +def remove_differing(id_1, id_2): + for i, char_1 in enumerate(id_1): + char_2 = id_2[i] + if char_1 != char_2: + return id_1[:i] + id_1[i + 1:] + +close_1, close_2 = find_close(package_ids) +common = remove_differing(close_1, close_2) + +print('Close IDs:', close_1, close_2) +print('Common letters:', common) + + diff --git a/day-02/README.md b/day-02/README.md new file mode 100644 index 0000000..06c2437 --- /dev/null +++ b/day-02/README.md @@ -0,0 +1,51 @@ +--- Day 2: Inventory Management System --- +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 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? + +Your puzzle answer was 5880. + +--- Part Two --- +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.) + +Your puzzle answer was tiwcdpbseqhxryfmgkvjujvza. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. + +You can also [Share] this puzzle. diff --git a/day-02/input.txt b/day-02/input.txt new file mode 100644 index 0000000..79e9fce --- /dev/null +++ b/day-02/input.txt @@ -0,0 +1,250 @@ +oiwcdpbseqgxryfmlpktnupvza +oiwddpbsuqhxryfmlgkznujvza +ziwcdpbsechxrvfmlgktnujvza +oiwcgpbseqhxryfmmgktnhjvza +owwcdpbseqhxryfmlgktnqjvze +oiscdkbseqhxrffmlgktnujvza +oiwcdibseqoxrnfmlgktnujvza +oiwcdpbsejhxryfmlektnujiza +oewcdpbsephxryfmlgkwnujvza +riwcdpbseqhxryfmlgktnujzaa +omwcdpbseqwxryfmlgktnujvqa +oiwcdqqneqhxryfmlgktnujvza +oawcdvaseqhxryfmlgktnujvza +oiwcdabseqhxcyfmlkktnujvza +oiwcdpbseqhxryfmlrktrufvza +oiwcdpbseqhxdyfmlgqtnujkza +oiwcdpbseqhxrmfolgktnujvzy +oiwcdpeseqhxnyfmlgktnejvza +oiwcdpbseqhxrynmlaktlujvza +oiwcdpbseqixryfmlektncjvza +liwtdpbseqhxryfylgktnujvza +ouwcdpbszqhxryfmlgktnajvza +oiwzdpbseqhxryfmngktnujvga +wiwcfpbseqhxryfmlgktnuhvza +oiwcdpbselhfryfmlrktnujvza +oywcdpbveqhxryfmlgktnujdza +oiwcdpbsiqhxryfmqiktnujvza +obwcdhbseqhxryfmlgktnujvqa +oitcdpbseqhfryfmlyktnujvza +oiwcdpbseqhxryfmlnutnujqza +oiwcdpbseqhxnyfmlhktnujtza +oiwcdpbseqhbryfmlgkunuwvza +oiwcopbseqhiryfmlgktnkjvza +oiwcdpsseqhxryfklrktnujvza +oiwcdpsrsqhxryfmlgktnujvza +oiwcdpbsyqrxryfmlgktnujvzc +ojwcepbseqhxryfmlgktnujvfa +oiwcdpbseqhxrlfmlgvtnujvzr +oiycdpbsethsryfmlgktnujvza +eiwcdpbseqwxryfmlgktnujcza +oiocdpbseqhxryfxlgktaujvza +qiwydpbseqhpryfmlgktnujvza +ziwcdpbseqhxryfmlgktsuuvza +oiwcdpbseqheryfmygxtnujvza +oiwidpbseqhxryfulgktnujvzm +oiscdpdseqhxryfmlgktnujvya +oiwmypbseqhxryfmlgktnuxvza +oizcwbbseqhxryfmlgktnujvza +oiwcdpbseqpxryfmlgxfnujvza +oiwpdpbscqhxryxmlgktnujvza +oiwcdpbseqhxrifrlgkxnujvza +oiwcdpbsrqhxrifmlgktnzjvza +tiwcdpbseqhxryfmegkvjujvza +oiwcddbseqhxryfingktnujvza +oiwcdpbsiqhiryfmlgktnucvza +oiwcipbseqhxrkfmlgktnuvvza +kiwcdpbseqhxryfmlbkonujvza +qiwcdhbsedhxryfmlgktnujvza +siwcdpbseqhxryfmsgktnujvua +oqwcdpbseqhxryfmlyktndjvza +oiwcqnbseehxryfmlgktnujvza +oiwcdybseqhxryfmlgbtnujvia +oiwcdpbsejhxryfdlgktngjvza +oawcdpbseqhxrbfmlkktnujvza +oilcdpbseqhhrjfmlgktnujvza +oibcdpbseqhxryfmngktnucvza +niwcdpbseqhxryfmlgkuaujvza +oiwcdpbseqhxryfmqgmtnujvha +oiwcdpbseqhcryfxlgktnzjvza +oiwcdpaseqhxryfmqgktnujvzl +oiwcdpbseqhxjyfmlgkonujvzx +oiwmdzbseqlxryfmlgktnujvza +oiwhdpbsexhxryfmlgktnujvzw +oiwctpbseqhxryfmlgktnummza +oiwcdpbseqoxrydmlgktnujvoa +oiwkdpvseqhxeyfmlgktnujvza +oixcdpbsemhxryfmlgctnujvza +oimcdpbseqhxryfmlgktnujvlr +oiwcdpbseehxrywmlgktnejvza +oiwcdpbseqoxhyfmlgktnujyza +oiwcdpbsethxryfmlgktnrjvxa +oiwcdpbxeqhxryfmlgktnrjvzb +ogeadpbseqhxryfmlgktnujvza +eiwcdpbseqhxryfmlgktnvuvza +oiwcdpbseqhxryfmlgktnujaxv +siwcdpbsuqhxryfmlgktnuavza +oixcdpbseqhxryfmlgatnujvzy +oiwcdpbzeghmryfmlgktnujvza +oiwcdpbieqhxryfmlgktyujvzr +oiwcdpbseqhxeyfhlgktngjvza +oiwcdpbseqhjoyrmlgktnujvza +iiwcdpbseqhxryfmwhktnujvza +oixcdpbsiqhxryfmagktnujvza +oiwcdpfljqhxryfmlgktnujvza +oivcdpbseqhxrqfmlgktnujvca +ovwcdpbseqhxzyfmlgkenujvza +oiwxdpgseqhxryfmlgktnhjvza +oibcdpbbeohxryfmlgktnujvza +oiwcrpbseqhxrygmlgwtnujvza +jiwcdpbseqkxryfmlgntnujvza +oiwcdbbseqhxrywmlgktnujvra +oiwcdpbteqyxoyfmlgktnujvza +oiwcdjbsvqvxryfmlgktnujvza +obwcdukseqhxryfmlgktnujvza +oifcdpdseqhxryfmlgktnujsza +oiwcdpbseqhxryfalgktnujyda +oiwcwpbseqhxrnfmkgktnujvza +oswcdpbsethcryfmlgktnujvza +oiwcdpbieqhxryfmlgktnuoiza +oiwcdibsehhxryfmzgktnujvza +oisjdpbseqhxryfmfgktnujvza +oiwcjpbseqkxqyfmlgktnujvza +obwcdpbshqhgryfmlgktnujvza +oiwcspbseqhxryxmlgktnujvzl +oiwcdvbswqhxryfmlgklnujvza +oiwcdhuseqhxryfmlgdtnujvza +oiwcdpbkeqdxryfmlgktnujvzv +oiwcdpzseqhxcyfmlgksnujvza +oiwcdpbseqhxryfmbkkvnujvza +qiwcdpbseqhxrnfmlgktnujvha +okwcdpbseqhxryfmdgktgujvza +oiwcdpbkeqhxryfmldktnujvzu +oiwctpxseqhxgyfmlgktnujvza +oiwcdpbseqhxrykmlgktnujita +oiwcdpbseqhxryfmldktyujnza +oiwcdpbszqhxrjfmlgktnuqvza +oiwcdpbeeqhxrykmlgktnujrza +oiwcvpbseqhxryhmlgwtnujvza +oiwcdpbpeehxryfmlgktnujvzz +oiwcdbbsxqhxyyfmlgktnujvza +oiwkdpbseqhxryfplgktnujeza +opwcdpbseqhxdyfmlgctnujvza +oowcdpbseqhnryfmlgktnujvga +oawzdibseqhxryfmlgktnujvza +oiwcdpbfeqzxrjfmlgktnujvza +oiwcdpbseqaxryfmlgkonulvza +oiacdpbseqvxryfmlgktvujvza +oiwudpbseqhxryfwlgktnujvka +oiwcdpbjeqhxryfymgktnujvza +oiwcdpbweqhxrynmlgktnujaza +oiwcdpbseqdxryfclgvtnujvza +oiwcdppseqhxryfmlgmtzujvza +oiwcdpbseqhxrhfelektnujvza +kiwcdpbsnqhxryfmegktnujvza +oiwcdpbseqpxryfmlgzwnujvza +eiwcdpbseqnxryfplgktnujvza +oiwcdbbseqhxryfmlmktnujvha +oiwcdpbseqhxryfmlgktjhjvka +oiwcdpbseqhxnyfylgktnujvzs +oiwcdpbbxqhxryfmzgktnujvza +opwcdpbseqhfryfmlgktnujzza +oiwcdpbsjqpxryfmtgktnujvza +oiwcdpbseqhyqbfmlgktnujvza +oxwcdpbseqhxrffmlgktiujvza +oiwcdpbseqhxgyfmlgytnujvzq +oiwidpbseqhxryfmlgxtnujvzd +oiwcdpbshqhxryzmlpktnujvza +oifcdpbseqbxryfmlgktdujvza +biwcdzbseqhxtyfmlgktnujvza +oiwcdpbswqhxryfmlgutnujvca +xiwcdpbseqhxryxmlnktnujvza +oiwcdpzseqhxryfrlgktdujvza +oiwudpbseqhxryfmlgkqnurvza +oiwqdpbseihiryfmlgktnujvza +iiwjdpbseqhxryamlgktnujvza +oiwcdplseqhqryfmmgktnujvza +oiwcdppseqhxrmfmlgklnujvza +oiwcdobseqhxryfmmgkttujvza +odwcdpbseqhxryfmlgktnujvyk +oiwcdpkseqhxrhfmlgktntjvza +oiocdpbseqhxryfmlgjknujvza +oiicdpbieqhxryfmlgksnujvza +oiwcdpbseqhxryemlgktnujdla +oiwcdpbseqdxryfmlgktsujvzt +oiwcdcksnqhxryfmlgktnujvza +oowcdpbseqhxryfmlgsfnujvza +oawcdpbseqhxryfmljktnuevza +oiwcdpbsaqhxrffmzgktnujvza +oiwcipbseqhcryfmlgktnujvga +oiwcdpbsewhxrbfmlgktnuuvza +oiwcdpbsewhxryfmlgkunujvzc +oiwcdpbseqhxryfmlgktiujkga +jiwcdpbseqhxrlfmlgktnurvza +tiwcdpbseqoxryfmliktnujvza +oiwcdpbsenhxryfmlgkskujvza +oiwcdpbseqhxvyfmlhktoujvza +oiwcdpbseqhxeyfmlgmtnunvza +oiwcdpbseqhxdyfmloktnujvzu +oiwcdpbseqgxryfmlgkynejvza +oudcdpbseqhxryfmlgktmujvza +oiwcdpbseqhxryfmvgktnucvzc +oiwcdpbseqhxrysalgwtnujvza +odwodpbseqhgryfmlgktnujvza +oiwcdpbseqheryzmlgktnujgza +oiwcdpbseqhxryfalgwtnujvba +oiwcdpbseqhxryfmlgtdnuhvza +oiocdpbseqhxrefulgktnujvza +kiwcdpbseqhxrywolgktnujvza +niwcdpbseksxryfmlgktnujvza +oiwcdybseqexryfalgktnujvza +oiwcdpbbeqhxryamlgktnujpza +oiecdqbseqhxryfmlgktnujcza +oiwcdpbsqqhxlyfmlpktnujvza +oiwcdpbsaqheryfmlgktnujlza +oiecdpbseqhxryfmlgkknujvzz +oiwcapbsdqhxryfmlgktvujvza +ojwcdxbseqhxryfmlgktrujvza +oiwhdpbseqvxrzfmlgktnujvza +oiwcdppseqhtryfmlgktnujvzs +oikcdpbsfqhxryfmdgktnujvza +owwczpbseqhxryfilgktnujvza +oifwdpbseqhxryfmlgktnujfza +oowcdpbseqhxrprmlgktnujvza +oiwcapbseqhxryfmjgktnujvze +oiwcdpaseqhdrybmlgktnujvza +tiwcdpbseqhxryfmlgkvjujvza +xiwcdpbseqhoryfmlgktnujvqa +eiwrdpbsyqhxryfmlgktnujvza +oiwcdpbseqhxranmlgktnujvzt +oiwcdpbseqhxryfqlgktnudaza +oiwcdpbsvqhxrywmlgktnsjvza +oewcdpbseqhxryfmlgkunujvma +oiwcdpbseqhjrywmlgktnujvzb +omwcdpbseqhxryfmlgktwujsza +oiwcdpbyxqhxryfmlgrtnujvza +oiwidpbseqhxryfhlgktnunvza +oqwcdpbweqhxrybmlgktnujvza +oiwcdqbseqhxryfrlgktnujfza +oiacdpbseqhdryfmlgktaujvza +oiwcdpbstqhxmyfmlgktyujvza +oiwcdpbseqhxeyfclgktjujvza +wiwcdpeseqhxryfmlgktnujvzx +viwcdpbseqhxryfmlgvtvujvza +oircdpbseqhxcyfmlgktnujvma +miwcdpbseqtwryfmlgktnujvza +oiwcppbseqhxcyfmlgxtnujvza +giwcrpbseqhxryfmlgktnudvza +onwcvpbseqhxryfmlgktnujqza +oiwcipbseqhxryfmlgitnuqvza +oiwcdpbseqhxryjmlgkonufvza +oiwnwpbseqhxtyfmlgktnujvza +oiwcypbseqhxryfmlgetnujvzv +oiwcdpbseqhxryqmljktnkjvza +olwcdpbseqhxryfmlgkenujvba +biwcdpbseqwxrywmlgktnujvza +oiwcdpbsevhmryjmlgktnujvza +oiwcdpbseqhxryfmlzktnkjvzv +oiwudpbseqhxrefmlgktnujvia +oiicdpbseqhxryfdloktnujvza +oihcjpbsxqhxryfmlgktnujvza \ No newline at end of file diff --git a/day-02/solutions.txt b/day-02/solutions.txt new file mode 100644 index 0000000..57fcbee --- /dev/null +++ b/day-02/solutions.txt @@ -0,0 +1,2 @@ +01: 5880 +02: tiwcdpbseqhxryfmgkvjujvza \ No newline at end of file