mirror of
https://github.com/thib8956/advent-of-code.git
synced 2025-08-24 00:11:57 +00:00
chore: create new project structure and aoc.py runner script
This commit is contained in:
28
adventofcode/2020/day11/grid.py
Normal file
28
adventofcode/2020/day11/grid.py
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/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)
|
||||
)
|
||||
)
|
Reference in New Issue
Block a user