black formatter
This commit is contained in:
@@ -1,44 +1,47 @@
|
|||||||
from aocd.models import Puzzle
|
from aocd.models import Puzzle
|
||||||
from aocd import submit
|
from aocd import submit
|
||||||
|
|
||||||
|
|
||||||
class Elf:
|
class Elf:
|
||||||
'''
|
"""
|
||||||
object which holds a a list of calories
|
object which holds a a list of calories
|
||||||
carried by this particular elf
|
carried by this particular elf
|
||||||
'''
|
"""
|
||||||
|
|
||||||
calories = list()
|
calories = list()
|
||||||
|
|
||||||
def __init__(self, numbers: list) -> None:
|
def __init__(self, numbers: list) -> None:
|
||||||
'''
|
"""
|
||||||
constructor
|
constructor
|
||||||
'''
|
"""
|
||||||
self.calories = numbers.copy()
|
self.calories = numbers.copy()
|
||||||
|
|
||||||
def __lt__(self, other) -> bool:
|
def __lt__(self, other) -> bool:
|
||||||
'''
|
"""
|
||||||
compare if sum of calorie is less than other
|
compare if sum of calorie is less than other
|
||||||
'''
|
"""
|
||||||
return (self.sum_calories() < other.sum_calories())
|
return self.sum_calories() < other.sum_calories()
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
'''
|
"""
|
||||||
print string representation of object
|
print string representation of object
|
||||||
'''
|
"""
|
||||||
return f'{str(self.calories)}'
|
return f"{str(self.calories)}"
|
||||||
|
|
||||||
def sum_calories(self) -> int:
|
def sum_calories(self) -> int:
|
||||||
'''
|
"""
|
||||||
calculate the total calories carried by this elf
|
calculate the total calories carried by this elf
|
||||||
'''
|
"""
|
||||||
return sum(self.calories)
|
return sum(self.calories)
|
||||||
|
|
||||||
|
|
||||||
def parse_input(data: list) -> list:
|
def parse_input(data: list) -> list:
|
||||||
'''
|
"""
|
||||||
parses the input data and generates a list of elfs
|
parses the input data and generates a list of elfs
|
||||||
from the input data string
|
from the input data string
|
||||||
'''
|
"""
|
||||||
# split input string into list
|
# split input string into list
|
||||||
splits = data.split('\n')
|
splits = data.split("\n")
|
||||||
# split list into sublists
|
# split list into sublists
|
||||||
numbers = list()
|
numbers = list()
|
||||||
tmp = list()
|
tmp = list()
|
||||||
@@ -49,7 +52,8 @@ def parse_input(data: list) -> list:
|
|||||||
else:
|
else:
|
||||||
tmp.append(int(number))
|
tmp.append(int(number))
|
||||||
# elf object for each sublist
|
# elf object for each sublist
|
||||||
return [ Elf(data) for data in numbers ]
|
return [Elf(data) for data in numbers]
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# get puzzle and parse data
|
# get puzzle and parse data
|
||||||
@@ -61,10 +65,10 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# part a: submit biggest number of calories
|
# part a: submit biggest number of calories
|
||||||
answer = elfs[0].sum_calories()
|
answer = elfs[0].sum_calories()
|
||||||
print(f'answer part a: {answer}')
|
print(f"answer part a: {answer}")
|
||||||
submit(answer, part='a', day=1, year=2022)
|
submit(answer, part="a", day=1, year=2022)
|
||||||
|
|
||||||
# part b: submit the calorie sum of the top 3 elfs
|
# part b: submit the calorie sum of the top 3 elfs
|
||||||
answer = sum([ elf.sum_calories() for elf in elfs[:3]])
|
answer = sum([elf.sum_calories() for elf in elfs[:3]])
|
||||||
print(f'answer part b: {answer}')
|
print(f"answer part b: {answer}")
|
||||||
submit(answer, part='b', day=1, year=2022)
|
submit(answer, part="b", day=1, year=2022)
|
||||||
|
|||||||
Reference in New Issue
Block a user