-
Notifications
You must be signed in to change notification settings - Fork 0
/
day09.py
40 lines (30 loc) · 1.19 KB
/
day09.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from typing import Set
from src.common.utils import SolverFunctions, Position_zero, Point, arrow_direction
title = '--- Day 3: Gear Ratios ---'
parser_method = 'make_instructions'
handle_data = 'paragraph' # by default
class SolveTheDay(SolverFunctions):
@staticmethod
def helper(data):
return data
@classmethod
def level_1(cls, data):
def move_rope(motions, start=Position_zero) -> Set[Point]:
head = tail = start
visited = {start}
for direction, step in motions[0]:
for num in range(step):
head = cls.add_together(head, arrow_direction[direction])
tail = move_tail(tail, head)
visited.add(tail)
return visited
def move_tail(tail: Point, head: Point) -> Point:
direction_x, direction_y = cls.sub(head, tail)
if max(abs(direction_x), abs(direction_y)) > 1:
tail = cls.add_together(tail, (cls.indication(direction_x), cls.indication(direction_y)))
return tail
return len(move_rope(data))
@classmethod
def level_2(cls, data):
result = cls.helper(data)
return