day14 package

Subpackages

Submodules

day14.day14 module

day14 solution.

class day14.day14.World(data: Any, left_is: Direction = Direction.West, score: int | None = None)[source]

Bases: object

2d array of boulders (square/round) and empty space.

as_orientiented_north() str[source]

Well defined string if our world has up as North.

correct_side() World[source]

Return world oriented with North at the top.

data: Any
get_score() int[source]

Get score of the world.

left_is: Direction = 1
rotate_world_ccw() World[source]

Rotate world anti-clockwise.

rotate_world_cw() World[source]

Rotate world clockwise.

score: int | None = None
to_string() str[source]

Well defined string of our world.

day14.day14.get_input(path: str) World[source]

Grabs input, rotated so that left is north.

day14.day14.main() None[source]

Get input and run question1/question2.

day14.day14.naive_score(world_rows: list[str]) int[source]

Returns score assuming west is pointing left.

For each row, a round boulder O’s score is num_rows minus its index (higher weight to the left.)

day14.day14.question1(world: World) int[source]

Returns world’s score after rotating the world once.

day14.day14.question2(world: World) int[source]

Finds a loop in world rotation.

Once the loop is found we can estimate the world’s state after any amount of rotations

Parameters:

world (World) – world to spin

Returns:

“weight” to the north after 1000000000 cycles.

Return type:

int

day14.day14.simulate_row(row: list[str]) tuple[list[str], int][source]

Simulates a row; returns its value and the new row.

Assumes that we are moving boulders to the left

day14.day14.simulate_world(world_rows: list[list[str]]) list[list[str]][source]

Simulates world by rolling to the left.

Module contents

Day14 Solution.