|
|
@ -7,10 +7,28 @@ Run with: |
|
|
|
|
|
|
|
import pathlib |
|
|
|
import sys |
|
|
|
from statistics import median |
|
|
|
from typing import List, Tuple |
|
|
|
|
|
|
|
|
|
|
|
class AlignCrabSubs: |
|
|
|
positions: List[int] |
|
|
|
|
|
|
|
def __init__(self, positions: List[int]) -> None: |
|
|
|
self.positions = positions |
|
|
|
|
|
|
|
def calc_least_fuel(self) -> int: |
|
|
|
target = median(self.positions) |
|
|
|
fuel = 0 |
|
|
|
for num in self.positions: |
|
|
|
fuel += num - target if num > target else target - num |
|
|
|
|
|
|
|
return int(fuel) |
|
|
|
|
|
|
|
|
|
|
|
def part1(inputs: List[int]) -> int: |
|
|
|
return False |
|
|
|
subs = AlignCrabSubs(inputs) |
|
|
|
return subs.calc_least_fuel() |
|
|
|
|
|
|
|
|
|
|
|
def part2(inputs: List[int]) -> int: |
|
|
@ -19,7 +37,7 @@ def part2(inputs: List[int]) -> int: |
|
|
|
|
|
|
|
def parse(inputs: str) -> List[int]: |
|
|
|
"""Parse the input string""" |
|
|
|
return [int(line) for line in inputs.split()] |
|
|
|
return [int(value) for value in inputs.split(",")] |
|
|
|
|
|
|
|
|
|
|
|
def solve(path: str) -> Tuple[int, int]: |
|
|
|