Day 17: Conway Cubes¶
Classes:
|
Represent a cube in 3D. |
|
Represent the current active cubes in the energy source |
Functions:
|
Check whether the |
|
List all neighbouring cubes w.r.t. |
|
Perform a single cycle of the initialization starting from |
|
Parse |
|
Represent the activity as a string for easier testing/debugging. |
|
Count number of active cells in the |
- class Point(x: int, y: int, z: int)[source]¶
Represent a cube in 3D.
Methods:
__new__
(cls, x, y, z)Create the point as tuple with the given coordinates.
__getitem__
(index)Get the item at the given integer index.
- class Activity(active_cubes: Set[Point])[source]¶
Represent the current active cubes in the energy source
Methods:
__new__
(cls, active_cubes)Create an activity as a set of active cubes.
__iter__
()Iterate over the lines.
__contains__
(item)Return True if the cube is activated.
__len__
()Return the number of active cubes.
- are_neighbours(point: Point, another: Point) bool [source]¶
Check whether the
point
andanother
are adjacent cubes.
- list_neighbourhood(point: Point) List[Point] [source]¶
List all neighbouring cubes w.r.t. the
point
cube.- Ensures
all( are_neighbours(point=point, another=neighbour) for neighbour in result )
point not in result
len(result) == 26
- apply(activity: Activity) Activity [source]¶
Perform a single cycle of the initialization starting from
activity
.- Returns
the new state of the energy source
- parse_initial(lines: Lines) Activity [source]¶
Parse
lines
into the state of the energy source.- Requires
all(re.match(r'^[.#]+Z', line) for line in lines)
len(lines) >= 1 and all( len(line) == len(lines[0]) for line in lines )
- Ensures
sum(line.count('#') for line in lines) == len(result)