Switching to Rust; Removed all Python Code

Wanted to practice Rust skills more, so I shall let it take over this advent of cod
main
Peery 2 years ago
parent 47c6e0c941
commit 13a817e463

@ -1,48 +0,0 @@
import os
from entities.items.food import Food
from entities.elf import Elf
class CalorieList:
"""
Day 1 - Calorie List
The Elves take turns writing down the number of Calories contained by the various meals, snacks, rations, etc. that they've brought with them, one item per line.
Each Elf separates their own inventory from the previous Elf's inventory (if any) by a blank line.
"""
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(self):
"""
read the file and parse its contents
:return:
"""
elf_invs = []
with open(self.file_path, "r") as file:
curr_elf_inventory = []
for line in file:
line = line.replace("\n", "")
if line.isnumeric():
curr_elf_inventory.append(int(line))
elif len(line) == 0: # line is empty, next inventory
elf_invs.append(curr_elf_inventory)
curr_elf_inventory = list()
else:
raise ValueError(f"Unexpected line encountered in calorie list file: {line}")
elf_invs.append(curr_elf_inventory)
elves = []
for inv in elf_invs:
elf = Elf()
for calories in inv:
elf.add_to_inventory(Food(calories))
elves.append(elf)
return elves

@ -1,108 +0,0 @@
from typing import Tuple, List
from entities.items.item import Item
from entities.items.food import Food
from rockpaperscissor.file.guide_list import RPS
class Elf:
"""
The absolute overkill, because I can.
"""
ELF_COUNT = 0
def __init__(self):
self.__number = Elf.ELF_COUNT
Elf.ELF_COUNT += 1
self.__name = Elf.fetch_elf_name(self.__number)
self.__inventory = []
@staticmethod
def fetch_elf_name(i: int) -> str:
name_list = ["Dash", "Evergreen", "Sugarplum", "Pixie", "Pudding", "Perky", "Candycane", "Glitter-toes",
"Happy", "Angel-Eyes", "Sugar-Socks", "McJingles", "Frost", "Tinsel", "Twinkle", "Jingle", "Ginger",
"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

@ -1,8 +0,0 @@
from entities.items.item import Item
class Food(Item):
def __init__(self, calorie: int):
super().__init__(name="")
self.calorie_value = calorie

@ -1,5 +0,0 @@
class Item:
def __init__(self, name: str):
self.name = name

@ -1,14 +0,0 @@
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,6 +0,0 @@
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw

@ -1,300 +0,0 @@
DMwrszrfMzSSCpLpfCCn
RMvhZhQqlvhMvRtbvbcPclPlncddppLTdppd
tVMQhFtjjWmsFJsmsW
trRtvNhfJhSzzSTFVhQQZQhHGphP
CnLMBWLwDMgMcwwdngdHGPVTQGpTHZdGPGpd
LLDqcDgwqCMnLWqtvzrzbbtJqPjJ
wQQwHNQLmbWQbQRHwHNFBbwqPfjqlzRMGRqzpSfvPlzplM
nCtGCZZtsGsrtDMZpfMpSlMlvlZq
cJctJCgVJsCJnDTsCthGhGLwBWBbbQmLbgQLQQdWbbbQ
ZWnNlTNTnhhQQlDNdmmpwrrrqBwjwjZd
GzvlVRSfvMVMvGlSpdCCdjmfpmBCdsqB
bzlFlLzJWLHHttLL
SmzFhVDzrmSrszVDVhSVbhZcCZdfZNcnMfMbZnNN
PTTRGqwqTqWRwLgTLTZGnCbZbNddZCCtMcNs
sgPqPqgJgWWqjjwgwLLVFBFSVmvmBBrmJJDSvp
CBccfSBhcSBddfgtlJmmmwmPRwmh
FpTzzGWHWprgDtJlDZDPFR
HbbTzWnTrnWtCbQBbQqQbSjf
fPHspCjgwZggSvZQ
RrNhzFZFcNzFLNLNwQlSlLnv
TRFrcDVrrRmrhFRZzVrczqhRpjqjsssCpfHjsCdpsP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GlmlmrdcLLsTBBfcfnBppc
mbCGFFmGmcdTrCTQdh
MJHfJNLllJffPLRTdBqTRQNcqQGB
fPJHfSSSWfSLDMLWGHDMLDFmznmsjmvZwzvjZjbvbZ
pPvpJSfZTTvCzNZczzQZchcj
svbHWsqsvbsMFtVHgVtcRQcDlQRRRQLjlqjczj
tBsgvHVMFggbgFrgWnwSndfBmmBJfPSfpn
jwbwfjSbwjVSjvZPzWSvhvhQlCsBFgLRLLgBLRClLLFQQw
GdNJHpmHTDnTNJqnFCgBLFLFzFtsQRCd
NpMJHpnMrDpJGTHqTTmJHTPjfcvbWfrffVzvZfVWSbjz
wFwpqWwwpqwtqqrbCFtptDmCcfNhNRzRBZRRJRChVNBZBJ
svlvjHsQlvdlvMLdlvPSSLtzzczcNhJthfNtRcNMJNMc
HvvPLSHjgltjsvqwbbnmWmDpgwTT
zhCmPVwwChdCBtsWnNWswBWr
GJJSfSgFpjJjGgpfpgrcNNstvnBHNnHLtFHr
jgDTfjpMgZMGMGJTMMJRhzZPCzbhVlPqdNCbhd
bDbQQmVDRpDNbRQlfQQZnfwTlllfsT
FChzzBWhVzrgMwffJwlnngnTlJ
MCvqvhFzcHCChjtpNNVLppGmbq
bZZzJnccqdzcLhrcQDLrDs
FfCfWVfjWTFClClfwjWCfGGwhZSDhSLsSSRpZprLph
mFmTMmFjMMWFfZtttflWjmWTngNHJHggJJHtzgnJvBtBgHdv

@ -1,38 +0,0 @@
from rucksack.file.rucksack_loader import RucksackLoader
from rucksack.ItemPriorities import item_priority
from entities.elf import Elf
if __name__ == "__main__":
rs = RucksackLoader("./input/day3/input.lst").parse_file()
i = item_priority
groups = []
curr_group = []
for rucksack in rs: # creating groups of 3
elf = Elf()
curr_group.append((elf, rucksack))
if len(curr_group) >= 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])}")

@ -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]])}")

@ -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!")

@ -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

@ -1,3 +0,0 @@
alphabet = "abcdefghijklmnopqrstuvwxyz"
item_priority = dict(zip(alphabet+alphabet.upper(), range(1, len(alphabet)+27+1)))

@ -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
Loading…
Cancel
Save