aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <thomasvoss@live.com> 2021-12-02 10:05:22 +0100
committerThomas Voss <thomasvoss@live.com> 2021-12-02 10:05:22 +0100
commit8e6440d8fd69caedc11192dca02a6ae28f5248cf (patch)
tree3a99cb992870acbea9d887523f42378d9b1b28a2
parent00b67942fed9961bd8d46d6f4fdae97dd074bb4e (diff)
Improve the makeshift macros
-rw-r--r--2015/15/Makefile4
-rw-r--r--2015/15/puzzles.py3
-rw-r--r--2015/18/Makefile4
-rw-r--r--2015/18/puzzles.py5
-rw-r--r--2015/21/Makefile4
-rw-r--r--2015/21/puzzles.py9
6 files changed, 12 insertions, 17 deletions
diff --git a/2015/15/Makefile b/2015/15/Makefile
index 8ada60c..b01f411 100644
--- a/2015/15/Makefile
+++ b/2015/15/Makefile
@@ -1,6 +1,6 @@
all:
- m4 -D GROUPS=5 puzzles.py | sed '/# START PART 2/,/# END PART 2/d' >puzzle-1.py
- m4 -D GROUPS=6 puzzles.py | sed '/# START PART 1/,/# END PART 1/d' >puzzle-2.py
+ m4 -D GROUPS=5 puzzles.py | sed '/START PART 2/,/END PART 2/d' >puzzle-1.py
+ m4 -D GROUPS=6 puzzles.py | sed '/START PART 1/,/END PART 1/d' >puzzle-2.py
chmod +x puzzle-[12].py
.PHONY: clean
diff --git a/2015/15/puzzles.py b/2015/15/puzzles.py
index 506e11f..5c3be94 100644
--- a/2015/15/puzzles.py
+++ b/2015/15/puzzles.py
@@ -12,8 +12,7 @@ def main() -> None:
m = re.match(
# START PART 1
r"[^\-0-9]+([\-0-9]+)[^\-0-9]+([\-0-9]+)[^\-0-9]+([\-0-9]+)[^\-0-9]+([\-0-9]+)",
- # END PART 1
- # START PART 2
+ # END PART 1 START PART 2
r"[^\-0-9]+([\-0-9]+)[^\-0-9]+([\-0-9]+)[^\-0-9]+([\-0-9]+)[^\-0-9]+([\-0-9]+)[^\-0-9]+([0-9]+)",
# END PART 2
line,
diff --git a/2015/18/Makefile b/2015/18/Makefile
index 9f0c9fb..247194a 100644
--- a/2015/18/Makefile
+++ b/2015/18/Makefile
@@ -1,6 +1,6 @@
all:
- sed '/# START PART 2/,/# END PART 2/d' puzzles.py >puzzle-1.py
- sed '/# START PART 1/,/# END PART 1/d' puzzles.py >puzzle-2.py
+ sed '/START PART 2/,/END PART 2/d' puzzles.py >puzzle-1.py
+ sed '/START PART 1/,/END PART 1/d' puzzles.py >puzzle-2.py
chmod +x puzzle-[12].py
.PHONY: clean
diff --git a/2015/18/puzzles.py b/2015/18/puzzles.py
index 5fbe572..4082ab5 100644
--- a/2015/18/puzzles.py
+++ b/2015/18/puzzles.py
@@ -28,10 +28,9 @@ def simulate(data: list[list[str]]) -> list[list[str]]:
cond = lambda x, y: (data[x][y] == "#" and neighbours(data, x, y) in [2, 3]) or (
data[x][y] == "." and neighbours(data, x, y) == 3
)
- # END PART 1
- # START PART 2
+ # END PART 1 START PART 2
cond = lambda x, y: (
- ((i, j) in [(0, 0), (0, 99), (99, 0), (99, 99)])
+ ((x, y) in [(0, 0), (0, 99), (99, 0), (99, 99)])
or (data[x][y] == "#" and neighbours(data, x, y) in [2, 3])
or (data[x][y] == "." and neighbours(data, x, y) == 3)
)
diff --git a/2015/21/Makefile b/2015/21/Makefile
index 9f0c9fb..247194a 100644
--- a/2015/21/Makefile
+++ b/2015/21/Makefile
@@ -1,6 +1,6 @@
all:
- sed '/# START PART 2/,/# END PART 2/d' puzzles.py >puzzle-1.py
- sed '/# START PART 1/,/# END PART 1/d' puzzles.py >puzzle-2.py
+ sed '/START PART 2/,/END PART 2/d' puzzles.py >puzzle-1.py
+ sed '/START PART 1/,/END PART 1/d' puzzles.py >puzzle-2.py
chmod +x puzzle-[12].py
.PHONY: clean
diff --git a/2015/21/puzzles.py b/2015/21/puzzles.py
index d355c77..e43829b 100644
--- a/2015/21/puzzles.py
+++ b/2015/21/puzzles.py
@@ -57,8 +57,7 @@ def main() -> None:
# START PART 1
min_cost = 999999999999999999999999999999999999999999999999999999999
- # END PART 1
- # START PART 2
+ # END PART 1 START PART 2
max_cost = 0
# END PART 2
@@ -72,16 +71,14 @@ def main() -> None:
# START PART 1
if (delta > 0) or ((delta == 0) and wins(damage - b_armor, b_health)):
min_cost = min(cost, min_cost)
- # END PART 1
- # START PART 2
+ # END PART 1 START PART 2
if (delta < 0) or ((delta == 0) and not wins(damage - b_armor, b_health)):
max_cost = max(cost, max_cost)
# END PART 2
# START PART 1
print(min_cost)
- # END PART 1
- # START PART 2
+ # END PART 1 START PART 2
print(max_cost)
# END PART 2