From 13a817e4630170e7d0d5e68dd12dba5570b1f5f8 Mon Sep 17 00:00:00 2001 From: Peery Date: Sun, 4 Dec 2022 14:22:20 +0100 Subject: [PATCH] Switching to Rust; Removed all Python Code Wanted to practice Rust skills more, so I shall let it take over this advent of cod --- calories/__init__.py | 0 calories/__pycache__/__init__.cpython-310.pyc | Bin 161 -> 0 bytes calories/file/__init__.py | 0 .../file/__pycache__/__init__.cpython-310.pyc | Bin 166 -> 0 bytes .../__pycache__/calorie_list.cpython-310.pyc | Bin 1683 -> 0 bytes calories/file/calorie_list.py | 48 - entities/__init__.py | 0 entities/__pycache__/__init__.cpython-310.pyc | Bin 161 -> 0 bytes entities/__pycache__/elf.cpython-310.pyc | Bin 2604 -> 0 bytes entities/elf.py | 108 - entities/items/__init__.py | 0 .../__pycache__/__init__.cpython-310.pyc | Bin 167 -> 0 bytes .../items/__pycache__/food.cpython-310.pyc | Bin 591 -> 0 bytes .../items/__pycache__/item.cpython-310.pyc | Bin 455 -> 0 bytes entities/items/food.py | 8 - entities/items/item.py | 5 - input/day1/example_list.lst | 14 - input/day1/input.lst | 2255 --------------- input/day2/example_guide.lst | 3 - input/day2/input.lst | 2500 ----------------- input/day3/example_packs.lst | 6 - input/day3/input.lst | 300 -- main.py | 38 - main_day1.py | 14 - main_day2.py | 21 - rockpaperscissor/__init__.py | 0 rockpaperscissor/file/__init__.py | 0 rockpaperscissor/file/guide_list.py | 109 - rucksack/ItemPriorities.py | 3 - rucksack/__init__.py | 0 rucksack/file/__init__.py | 0 rucksack/file/rucksack_loader.py | 21 - 32 files changed, 5453 deletions(-) delete mode 100644 calories/__init__.py delete mode 100644 calories/__pycache__/__init__.cpython-310.pyc delete mode 100644 calories/file/__init__.py delete mode 100644 calories/file/__pycache__/__init__.cpython-310.pyc delete mode 100644 calories/file/__pycache__/calorie_list.cpython-310.pyc delete mode 100644 calories/file/calorie_list.py delete mode 100644 entities/__init__.py delete mode 100644 entities/__pycache__/__init__.cpython-310.pyc delete mode 100644 entities/__pycache__/elf.cpython-310.pyc delete mode 100644 entities/elf.py delete mode 100644 entities/items/__init__.py delete mode 100644 entities/items/__pycache__/__init__.cpython-310.pyc delete mode 100644 entities/items/__pycache__/food.cpython-310.pyc delete mode 100644 entities/items/__pycache__/item.cpython-310.pyc delete mode 100644 entities/items/food.py delete mode 100644 entities/items/item.py delete mode 100644 input/day1/example_list.lst delete mode 100644 input/day1/input.lst delete mode 100644 input/day2/example_guide.lst delete mode 100644 input/day2/input.lst delete mode 100644 input/day3/example_packs.lst delete mode 100644 input/day3/input.lst delete mode 100644 main.py delete mode 100644 main_day1.py delete mode 100644 main_day2.py delete mode 100644 rockpaperscissor/__init__.py delete mode 100644 rockpaperscissor/file/__init__.py delete mode 100644 rockpaperscissor/file/guide_list.py delete mode 100644 rucksack/ItemPriorities.py delete mode 100644 rucksack/__init__.py delete mode 100644 rucksack/file/__init__.py delete mode 100644 rucksack/file/rucksack_loader.py diff --git a/calories/__init__.py b/calories/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/calories/__pycache__/__init__.cpython-310.pyc b/calories/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index 9809a046fdf96319f3df6a1f19d830bd197b12c6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 161 zcmd1j<>g`kf>jGUl0o!i5P=LBfgA@QE@lA|DGb33nv8xc8Hzx{2;!HEenx(7s(wLg zYEh+raDG}zd16s&d_YltR%&udvA$zUS!!NMewuTBN~*q*fsv7Za$-(?QD$nfetdjp eUS>&ryk0@&Ee@O9{FKt1R6CIA#Y{kgg#iEu7A8yp diff --git a/calories/file/__init__.py b/calories/file/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/calories/file/__pycache__/__init__.cpython-310.pyc b/calories/file/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index 715c9a9e313fb5135b351926cc666b43be422351..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 166 zcmd1j<>g`kf};yNl0o!i5P=LBfgA@QE@lA|DGb33nv8xc8Hzx{2;!Hgenx(7s(wLg zYEh+raDG}zd16s&d_YltR%&udvA$zUS!!NMewuTBN~*q*fsv7Za$-(?QD$nfep+Tu js(yTYW?p7Ve7s&kb84BSgMHH<`j$c;O3CkJ9b5bW0o^wi`62(>Lf~d|p%R7obBZKr$up|2e8u^~J z3cks1Jt~p8yl%t12V6~Zsz}Zh%@f5mA2F3Ee!;st8*+}WoKSYw5gL*08+Bh##Wgn_E!>C^o0_m=#53s!$ZK;eSqn^yxb7 zvC}t~u(f%kR076s*9x36*lo3bhr=N`qk%L~GeytYPamBz;3N%uLcSZE@rGYA1xUVP z?K!z3?%gK2bEq&SFV{kfXT^`0d)UxR-XzEm-E;5*(oBKwO$WXqD&>Te^Mn$U zJtF?`3FzYQTiCCxA%{*wA%}ZsX;=YI-6n+`Q38nT(MwY z&mKB9I(9U^B^d8GCZLdKH&|<-dQJM6Zm+FXf&SityZ-x}*V z_P@PV&N7-V_?(^ITgKumSNnr5;@8NDE{fPIiiuS-n4Kc_i{j->)(c6uD3mRMo%rC~ z8pL+*Ai;TBBABV;K)SF!B0D3Tu6O%s%N?W+$0L6OY5*^$_M7;2`OOhL>umw^{;dRu d7E9e4E`?|#wiU@fzE1WN1jHg(pY`e8g`kf|W}U6OdqG000ZsCSm{p diff --git a/entities/__pycache__/elf.cpython-310.pyc b/entities/__pycache__/elf.cpython-310.pyc deleted file mode 100644 index 1de1ff013d6883ec6491a910fd7ee25511f8dfa9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2604 zcmb7GOK;mo5Z)yz>S6gA$8FLFSR^Q-Ad!Mx3Is-))Nz~yt!h**3M^0%G`dY0A8&?2*M~Q%;J>U91RslSxLCOB+A?sm9E3fymIUuQC8(uUOOhN z2IF&Gi_h`;vBTIOPhQ>p_OZY5{g3UPyzT=+-%kh0 zu2A_xSD3Kx3m8g+MC7%TS!^$k+fn*Lq(-XYTZp;_&9_9&gVFb2xB4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ger", - "Joy", "Merry", "Pepper", "Sparkle", "Tinsel", "Winter", "Trinket", "Buddy", "Noel", "Snowball", - "Tiny", "Elfin", "Candy", "Carol", "Angel", "Nick", "Plum", "Holly", "Snow", "Pine", "Garland", - "Joseph", "Gabriel", "Hope", "Cedar"] - return name_list[i % len(name_list)] - - def __str__(self): - return f"#{self.__number} {self.__name}" - - def get_inventory(self) -> list: - return self.__inventory - - def add_to_inventory(self, item: Item): - self.__inventory.append(item) - - def remove_from_inventory(self, slot: int): - """ - Removes item of the given slot number from the inventory using pop(). - That means there are no empty spaces. - - Starts with 0. - :param slot: - :return: - """ - self.__inventory.pop(slot) - - def get_inventory_calories(self) -> int: - return sum([x.calorie_value for x in list(filter(lambda x: isinstance(x, Food), self.get_inventory()))]) - - def evaluate_RPS_round(self, other: str, own: str) -> Tuple[bool, int]: - """ - Evaluates a rock paper scissor round according to day 2 puzzle 1. - :param other: What the opponent played - :param own: what you played - :return: - """ - round_score = None - was_win = None - if other == own: - round_score = RPS.DRAW_SCORE - else: - if (other == RPS.PAPER and own == RPS.ROCK) or \ - (other == RPS.SCISSOR and own == RPS.PAPER) or \ - (other == RPS.ROCK and own == RPS.SCISSOR): - round_score = RPS.LOSS_SCORE - was_win = False - elif (other == RPS.PAPER and own == RPS.SCISSOR) or \ - (other == RPS.SCISSOR and own == RPS.ROCK) or \ - (other == RPS.ROCK and own == RPS.PAPER): - round_score = RPS.WIN_SCORE - was_win = True - else: - raise Exception(f"Something went terribly wrong! Other: {other} Own: {own}") - - return was_win, round_score + RPS.RPS_SHAPE_TO_SCORE[own] - - @staticmethod - def check_rucksacks_for_duplicates(rucksack1: Tuple[List[str], List[str]], rucksack2: Tuple[List[str], List[str]]) -> List[str]: - """ - Check if rucksack1 and rucksack2 have an item in common. This will merge the compartments in each rucksack. - - :param rucksack1: - :param rucksack2: - :return: list of the duplicate item (as a character) or None if there is no duplicate - """ - r1 = list(set(rucksack1[0] + rucksack1[1])) - r2 = list(set(rucksack2[0] + rucksack2[1])) - - dups = [] - for a in r1: - if a in r2: - dups.append(a) - - return dups - - @staticmethod - def check_compartments_for_duplicates(compartment_1: List[str], compartment_2: List[str]) -> str: - """ - Check two given compartment for the duplicate item according to day 3 puzzle 1 - :return: the duplicate item (as a character) or None if there is no duplicate - """ - for a in compartment_1: - if a in compartment_2: - return a - - return False diff --git a/entities/items/__init__.py b/entities/items/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/entities/items/__pycache__/__init__.cpython-310.pyc b/entities/items/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index 118f914d322b90da83f88e2ca3ab6587099d909b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 167 zcmd1j<>g`kg1<{Ul0o!i5P=LBfgA@QE@lA|DGb33nv8xc8Hzx{2;!HQenx(7s(wLg zYEh+raDG}zd16s&d_YltR%&udvA$zUS!!NMewuTBN~*q*fsv6ukegYOnOdx$S(2Jt jtREkrnU`4-AFo$Xd5gm)H$SB`C)EyQM==wSU||3NN0ccI diff --git a/entities/items/__pycache__/food.cpython-310.pyc b/entities/items/__pycache__/food.cpython-310.pyc deleted file mode 100644 index 148cfd416359aa1b19c564f47005bc47a8d5229d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 591 zcmYk3v1;5v5Qb;9I{R{*(j-Ml71F6Wg{wnI2sorM0e5N!p&b#K)$L_ha&U0xfZgOd zj9+QnRCxtgnc2I88<<}+((X6^u3S+pfMa^NZy)&iSDNFG^tx%XC}XZa`ul`L8)T?b)=z{<~Rf<5#F*8)XD&FRHVD?4my>9%R0Y<9O@b4 z@|d4FXX0twSm%3cv$TCDQtN$&S6qy63zy0;<`4V3Q8$2@0mkU_m^^Kofl3``VcL?9 zbHskrkBD`#$KzFFCn~d;2eO?Pw~s15Lu_pm0^%b)omJo6K-HGWUso5d8-F&Q@SAs+ z)Q+M0WUgp4y6&?xRIT5w*A=(@*i)!_zK~FLe4N$x+RvGN!Wm@9bG1;v3OVWO;Hf+j ze_|LhE)WN2CM)$4@yFEI{TJPD#>9%n-epVHBKjp`cOt*n7b0?5GA_-W!|N=)IWKkn f;^1( zalYR6Q?2W+4qDSzPv>I(l91f_FSEoCU>k|ox{tMPt=Tk`A8Y-%DViT9^1-= 3: - groups.append(curr_group) - curr_group = [] - - group_badges = [] - for i in range(len(groups)): - group = groups[i] - dup1 = Elf.check_rucksacks_for_duplicates(group[0][1], group[1][1]) - dup2 = Elf.check_rucksacks_for_duplicates(group[0][1], group[2][1]) - - r = Elf.check_compartments_for_duplicates(dup1, dup2) - if r: - final_dup = r - print(f"Group #{i} has the badge item {final_dup} ({item_priority[final_dup]})") - else: - final_dup = None - raise ValueError(f"Found no badge item for Group #{i}") - - group_badges.append(final_dup) - - print("") - print(f"The priority sum is: {sum([item_priority[c] for c in group_badges])}") - - diff --git a/main_day1.py b/main_day1.py deleted file mode 100644 index 2f31b48..0000000 --- a/main_day1.py +++ /dev/null @@ -1,14 +0,0 @@ -from calories.file.calorie_list import CalorieList - - -if __name__ == "__main__": - elves = CalorieList("./input/day1/input.lst").parse_file() - for elf in elves: - print(f"Elf {elf} has calories: {elf.get_inventory_calories()}") - elves.sort(key=lambda x: x.get_inventory_calories(), reverse=True) - print(f"Most calories has: {elves[0]} with {elves[0].get_inventory_calories()} calories in their inventory!") - - print(f"The top 3 calorie elves are: {elves[0]} ({elves[0].get_inventory_calories()}), " - f"{elves[1]} ({elves[1].get_inventory_calories()}) and " - f"{elves[2]} ({elves[2].get_inventory_calories()})") - print(f"Their total is: {sum([x.get_inventory_calories() for x in elves[:3]])}") diff --git a/main_day2.py b/main_day2.py deleted file mode 100644 index 30614f6..0000000 --- a/main_day2.py +++ /dev/null @@ -1,21 +0,0 @@ -from entities.elf import Elf -from rockpaperscissor.file.guide_list import RockPaperScissorGuide - -if __name__ == "__main__": - my_elf = Elf() - other_elf = Elf() - rounds = RockPaperScissorGuide("./input/day2/input.lst").parse_file() - scores = [] - for other, own in rounds: - result, score = my_elf.evaluate_RPS_round(other, own) - scores.append(score) - if result: - r = "won" - else: - r = "lost" - print(f"Elf {my_elf} played {own} against {other} and {r} with {score} points!") - - print() - print(f"I've got a total of {sum(scores)} points!") - - diff --git a/rockpaperscissor/__init__.py b/rockpaperscissor/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/rockpaperscissor/file/__init__.py b/rockpaperscissor/file/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/rockpaperscissor/file/guide_list.py b/rockpaperscissor/file/guide_list.py deleted file mode 100644 index 1a87cd7..0000000 --- a/rockpaperscissor/file/guide_list.py +++ /dev/null @@ -1,109 +0,0 @@ -import os -from typing import List, Tuple - - -class RPS: - WIN_SYM = "Z" - DRAW_SYM = "Y" - LOSS_SYM = "X" - - ROCK = "R" - PAPER = "P" - SCISSOR = "S" - - ROCK_SCORE = 1 - PAPER_SCORE = 2 - SCISSOR_SCORE = 3 - - WIN_SCORE = 6 - DRAW_SCORE = 3 - LOSS_SCORE = 0 - - RPS_SYM_TO_SHAPE = { - "A": ROCK, - "X": ROCK, - - "B": PAPER, - "Y": PAPER, - - "C": SCISSOR, - "Z": SCISSOR - } - - RPS_SHAPE_TO_SCORE = { - ROCK: ROCK_SCORE, - PAPER: PAPER_SCORE, - SCISSOR: SCISSOR_SCORE - } - - -class RockPaperScissorGuide: - """ - Day 2 - Rock Paper Scissors - - The Elves begin to set up camp on the beach. To decide whose tent gets to be closest to the snack storage, - a giant Rock Paper Scissors tournament is already in progress. - - One Elf gives you an encrypted strategy guide (your puzzle input) that they say will be sure to help you win. - The first column is what your opponent is going to play: A for Rock, B for Paper, and C for Scissors. - The second column, you reason, must be what you should play in response: X for Rock, Y for Paper, - and Z for Scissors. Winning every time would be suspicious, so the responses must have been carefully chosen. - - The score for a single round is the score for the shape you selected (1 for Rock, 2 for Paper, and 3 for Scissors) - plus the score for the outcome of the round (0 if you lost, 3 if the round was a draw, and 6 if you won). - - (Part 2 only) - The second column says how the round needs to end: X means you need to lose, - Y means you need to end the round in a draw, and Z means you need to win. - """ - - def __init__(self, path: str): - if not os.path.isfile(path): - raise FileNotFoundError(f"File was not found or isn't a file: {path}") - - self.file_path = path - - def parse_file_v1(self) -> List[Tuple[str, str]]: - strategy_guide = [] - with open(self.file_path, "r") as file: - for line in file: - line = line.replace("\n", "") - a, b = line.split(" ") - strategy_guide.append((RPS.RPS_SYM_TO_SHAPE[a], RPS.RPS_SYM_TO_SHAPE[b])) - - return strategy_guide - - def parse_file(self) -> List[Tuple[str, str]]: - strategy_guide = [] - with open(self.file_path, "r") as file: - for line in file: - line = line.replace("\n", "") - a, b = line.split(" ") - - a = RPS.RPS_SYM_TO_SHAPE[a] - - answer = None - - if b == RPS.WIN_SYM: - if a == RPS.ROCK: - answer = RPS.PAPER - elif a == RPS.PAPER: - answer = RPS.SCISSOR - elif a == RPS.SCISSOR: - answer = RPS.ROCK - elif b == RPS.DRAW_SYM: - answer = a - elif b == RPS.LOSS_SYM: - if a == RPS.ROCK: - answer = RPS.SCISSOR - elif a == RPS.PAPER: - answer = RPS.ROCK - elif a == RPS.SCISSOR: - answer = RPS.PAPER - - if answer is None: - raise ValueError("Something went wrong with answer determination!") - - strategy_guide.append((a, answer)) - - return strategy_guide diff --git a/rucksack/ItemPriorities.py b/rucksack/ItemPriorities.py deleted file mode 100644 index fde731e..0000000 --- a/rucksack/ItemPriorities.py +++ /dev/null @@ -1,3 +0,0 @@ -alphabet = "abcdefghijklmnopqrstuvwxyz" - -item_priority = dict(zip(alphabet+alphabet.upper(), range(1, len(alphabet)+27+1))) diff --git a/rucksack/__init__.py b/rucksack/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/rucksack/file/__init__.py b/rucksack/file/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/rucksack/file/rucksack_loader.py b/rucksack/file/rucksack_loader.py deleted file mode 100644 index f025fe6..0000000 --- a/rucksack/file/rucksack_loader.py +++ /dev/null @@ -1,21 +0,0 @@ -from typing import List, Tuple - - -class RucksackLoader: - - def __init__(self, path: str): - self.path = path - - def parse_file(self) -> List[Tuple[List[str], List[str]]]: - rucksacks = [] - with open(self.path, "r") as file: - for line in file: - line = line.strip() - if len(line) == 0: - continue - comp_1 = list(line[:len(line)//2]) - comp_2 = list(line[len(line)//2:]) - rucksacks.append((comp_1, comp_2)) - - return rucksacks -