mirror of
https://github.com/thib8956/advent-of-code.git
synced 2024-12-26 13:56:29 +00:00
29 lines
666 B
Python
29 lines
666 B
Python
#!/usr/bin/env python3
|
|
|
|
|
|
class Grid:
|
|
def __init__(self, inp):
|
|
lines = inp.read().splitlines()
|
|
self.cells = list("".join(lines))
|
|
self.height = len(lines)
|
|
self.width = len(lines[0])
|
|
|
|
def __getitem__(self, key):
|
|
x, y = key
|
|
return cells[y * self.width + x]
|
|
|
|
def __setitem__(self, key, value):
|
|
x, y = key
|
|
cells[y * self.width + x] = value
|
|
|
|
def __iter__(self):
|
|
return self.cells.__iter__()
|
|
|
|
def __str__(self):
|
|
"\n".join(
|
|
"".join(
|
|
grid[pos : pos + grid_width]
|
|
for pos in range(0, self.width, self.height)
|
|
)
|
|
)
|