Content-Length: 368582 | pFad | http://github.com/Piratmac/adventofcode-python/commit/a386be1c1e120b3f896148924b0c5f434642b3ad

2F Grid can now have integer values · Piratmac/adventofcode-python@a386be1 · GitHub
Skip to content

Commit a386be1

Browse files
committed
Grid can now have integer values
1 parent f7e470a commit a386be1

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

2021/dot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,17 @@ def __ge__(self, other):
129129

130130
def __repr__(self):
131131
if self.grid.is_isotropic:
132-
return self.terrain + "@" + complex(self.position).__str__()
132+
return str(self.terrain) + "@" + complex(self.position).__str__()
133133
else:
134134
return (
135-
self.terrain
135+
str(self.terrain)
136136
+ "@"
137137
+ complex(self.position).__str__()
138138
+ direction_to_text[self.source_direction]
139139
)
140140

141141
def __str__(self):
142-
return self.terrain
142+
return str(self.terrain)
143143

144144
def __add__(self, direction):
145145
if not direction in self.allowed_directions:

2021/grid.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def reset_pathfinding(self):
7878
for dot in self.dots.values():
7979
dot.neighbors_obsolete = True
8080

81-
def text_to_dots(self, text, ignore_terrain=""):
81+
def text_to_dots(self, text, ignore_terrain="", convert_to_int=False):
8282
"""
8383
Converts a text to a set of dots
8484
@@ -94,14 +94,18 @@ def text_to_dots(self, text, ignore_terrain=""):
9494
for line in text.splitlines():
9595
for x in range(len(line)):
9696
if line[x] not in ignore_terrain:
97+
if convert_to_int:
98+
value = int(line[x])
99+
else:
100+
value = line[x]
97101
if self.is_isotropic:
98-
self.dots[x - y * 1j] = Dot(self, x - y * 1j, line[x])
102+
self.dots[x - y * 1j] = Dot(self, x - y * 1j, value)
99103
else:
100104
for dir in self.possible_source_directions.get(
101-
line[x], self.direction_default
105+
value, self.direction_default
102106
):
103107
self.dots[(x - y * 1j, dir)] = Dot(
104-
self, x - y * 1j, line[x], dir
108+
self, x - y * 1j, value, dir
105109
)
106110
y += 1
107111

@@ -150,7 +154,7 @@ def dots_to_text(self, mark_coords={}, void=" "):
150154
for y in range(max_y, min_y - 1, -1):
151155
for x in range(min_x, max_x + 1):
152156
try:
153-
text += mark_coords[x + y * 1j]
157+
text += str(mark_coords[x + y * 1j])
154158
except (KeyError, TypeError):
155159
if x + y * 1j in mark_coords:
156160
text += "X"

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/Piratmac/adventofcode-python/commit/a386be1c1e120b3f896148924b0c5f434642b3ad

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy