aboutsummaryrefslogtreecommitdiff
path: root/2015
diff options
context:
space:
mode:
Diffstat (limited to '2015')
-rw-r--r--2015/01/Makefile8
-rw-r--r--2015/02/Makefile1
-rwxr-xr-x2015/02/puzzle-1.awk6
-rwxr-xr-x2015/02/puzzle-2.awk6
-rw-r--r--2015/02/puzzles.awk27
-rwxr-xr-x2015/03/puzzles.sh2
-rw-r--r--2015/04/Makefile9
-rw-r--r--2015/05/puzzle-1.sed6
-rw-r--r--2015/05/puzzle-2.sed4
-rwxr-xr-x2015/05/puzzles.sh6
-rwxr-xr-x2015/06/puzzle-1.awk16
-rwxr-xr-x2015/06/puzzle-2.awk17
-rw-r--r--2015/07/Makefile9
-rw-r--r--2015/07/puzzles.py2
-rwxr-xr-x2015/08/puzzle-1.sh4
-rwxr-xr-x2015/08/puzzle-2.sh4
-rw-r--r--2015/09/Makefile9
-rw-r--r--2015/09/puzzles.py2
-rw-r--r--2015/10/README5
-rwxr-xr-x2015/10/puzzles.sh3
-rw-r--r--2015/11/puzzle-111
-rw-r--r--2015/11/puzzle-213
-rwxr-xr-x2015/12/puzzle-1.sh2
-rwxr-xr-x2015/12/puzzle-2.sh10
-rw-r--r--2015/13/Makefile9
-rw-r--r--2015/14/puzzle-1.bc10
-rw-r--r--2015/14/puzzle-2.bc6
-rwxr-xr-x2015/14/puzzles.sh12
-rw-r--r--2015/15/Makefile9
-rw-r--r--2015/15/puzzles.py6
-rwxr-xr-x2015/16/puzzle-1.sh38
-rwxr-xr-x2015/16/puzzle-2.sh40
-rw-r--r--2015/18/Makefile9
-rw-r--r--2015/18/puzzles.py10
-rwxr-xr-x2015/19/puzzle-1.py2
-rwxr-xr-x2015/19/puzzle-2.sh9
-rw-r--r--2015/20/Makefile13
-rw-r--r--2015/21/Makefile9
-rw-r--r--2015/21/puzzles.py2
-rw-r--r--2015/23/Makefile10
-rw-r--r--2015/23/puzzles.l23
41 files changed, 187 insertions, 212 deletions
diff --git a/2015/01/Makefile b/2015/01/Makefile
index c32dafa..de3f940 100644
--- a/2015/01/Makefile
+++ b/2015/01/Makefile
@@ -1,7 +1 @@
-all:
- ${CC} ${CFLAGS} -o puzzle-1 puzzles.c
- ${CC} ${CFLAGS} -DPART2 -o puzzle-2 puzzles.c
-
-.PHONY: clean
-clean:
- rm -f puzzle-[12]
+include ../../Makefiles/c.mk
diff --git a/2015/02/Makefile b/2015/02/Makefile
new file mode 100644
index 0000000..3e0defd
--- /dev/null
+++ b/2015/02/Makefile
@@ -0,0 +1 @@
+include ../../Makefiles/awk.mk
diff --git a/2015/02/puzzle-1.awk b/2015/02/puzzle-1.awk
index e316ba2..5c05d31 100755
--- a/2015/02/puzzle-1.awk
+++ b/2015/02/puzzle-1.awk
@@ -1,7 +1,6 @@
-#!/usr/bin/env -S awk -f
+#!/usr/bin/awk -f
-function min(a, b, c)
-{
+function min(a, b, c) {
if (a <= b && a <= c)
return a
if (b <= a && b <= c)
@@ -11,6 +10,7 @@ function min(a, b, c)
BEGIN { FS = "x" }
{
+ # START PART 1
x = $1 * $2
y = $2 * $3
z = $1 * $3
diff --git a/2015/02/puzzle-2.awk b/2015/02/puzzle-2.awk
index e031b94..450aed9 100755
--- a/2015/02/puzzle-2.awk
+++ b/2015/02/puzzle-2.awk
@@ -1,7 +1,6 @@
-#!/usr/bin/env -S awk -f
+#!/usr/bin/awk -f
-function min(a, b, c)
-{
+function min(a, b, c) {
if (a <= b && a <= c)
return a
if (b <= a && b <= c)
@@ -16,5 +15,6 @@ BEGIN { FS = "x" }
z = $1 + $1 + $3 + $3
sum += $1 * $2 * $3 + min(x, y, z)
+ # END PART 2
}
END { print sum }
diff --git a/2015/02/puzzles.awk b/2015/02/puzzles.awk
new file mode 100644
index 0000000..b7b35e1
--- /dev/null
+++ b/2015/02/puzzles.awk
@@ -0,0 +1,27 @@
+#!/usr/bin/awk -f
+
+function min(a, b, c) {
+ if (a <= b && a <= c)
+ return a
+ if (b <= a && b <= c)
+ return b
+ return c
+}
+
+BEGIN { FS = "x" }
+{
+ # START PART 1
+ x = $1 * $2
+ y = $2 * $3
+ z = $1 * $3
+
+ sum += (2 * x) + (2 * y) + (2 * z) + min(x, y, z)
+ # END PART 1 START PART 2
+ x = $1 + $1 + $2 + $2
+ y = $2 + $2 + $3 + $3
+ z = $1 + $1 + $3 + $3
+
+ sum += $1 * $2 * $3 + min(x, y, z)
+ # END PART 2
+}
+END { print sum }
diff --git a/2015/03/puzzles.sh b/2015/03/puzzles.sh
index 6007df1..4a21b8a 100755
--- a/2015/03/puzzles.sh
+++ b/2015/03/puzzles.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env sh
+#!/bin/sh
fold -w1 input | awk -f puzzle-1.awk
fold -w1 input | awk -f puzzle-2.awk
diff --git a/2015/04/Makefile b/2015/04/Makefile
index 10ec8f9..039d3f7 100644
--- a/2015/04/Makefile
+++ b/2015/04/Makefile
@@ -1,7 +1,4 @@
-all:
- ${CC} ${CFLAGS} -lmd -DINPUT=\"$$(cat input)\" -o puzzle-1 puzzles.c
- ${CC} ${CFLAGS} -lmd -DINPUT=\"$$(cat input)\" -DPART2 -o puzzle-2 puzzles.c
+CPPFLAGS = -DINPUT=\"$$(cat input)\"
+LDLIBS = -lmd
-.PHONY: clean
-clean:
- rm -f puzzle-[12]
+include ../../Makefiles/c.mk
diff --git a/2015/05/puzzle-1.sed b/2015/05/puzzle-1.sed
index 9cba7ad..7dd514b 100644
--- a/2015/05/puzzle-1.sed
+++ b/2015/05/puzzle-1.sed
@@ -1,3 +1,3 @@
-/ab\|cd\|pq\|xy/d
-/\(.\)\1/!d
-/\(.*[aeiou].*\)\{3\}/p
+/ab|cd|pq|xy/d
+/(.)\1/!d
+/(.*[aeiou].*){3}/p
diff --git a/2015/05/puzzle-2.sed b/2015/05/puzzle-2.sed
index 908afdf..182d85c 100644
--- a/2015/05/puzzle-2.sed
+++ b/2015/05/puzzle-2.sed
@@ -1,2 +1,2 @@
-/\(.\).\1/!d
-/\(..\).*\1/p
+/(.).\1/!d
+/(..).*\1/p
diff --git a/2015/05/puzzles.sh b/2015/05/puzzles.sh
index 57ddb11..4959366 100755
--- a/2015/05/puzzles.sh
+++ b/2015/05/puzzles.sh
@@ -1,6 +1,6 @@
-#!/usr/bin/env sh
+#!/bin/sh
# Could do this with just grep(1) and skip using wc(1), but I am lazy
-sed -nf puzzle-1.sed input | wc -l
-sed -nf puzzle-2.sed input | wc -l
+sed -Enf puzzle-1.sed input | wc -l
+sed -Enf puzzle-2.sed input | wc -l
diff --git a/2015/06/puzzle-1.awk b/2015/06/puzzle-1.awk
index 97165cf..95034d4 100755
--- a/2015/06/puzzle-1.awk
+++ b/2015/06/puzzle-1.awk
@@ -1,7 +1,6 @@
-#!/usr/bin/env -S awk -f
+#!/usr/bin/awk -f
-function setlights(val, toggle)
-{
+function setlights(val, toggle) {
for (i = from[1]; i <= to[1]; i++) {
for (j = from[2]; j <= to[2]; j++)
lights[i][j] = toggle ? (lights[i][j] ? 0 : 1) : val
@@ -9,7 +8,14 @@ function setlights(val, toggle)
}
$1 == "toggle" { split($2, from, ","); split($4, to, ","); setlights(0, 1) }
-$2 ~ /on|off/ { split($3, from, ","); split($5, to, ",") }
+$2 ~ /on|off/ { split($3, from, ","); split($5, to, ",") }
$2 == "on" { setlights(1, 0) }
$2 == "off" { setlights(0, 0) }
-END { for (i = 0; i <= 999; i++) for (j = 0; j <= 999; j++) count += lights[i][j]; print count }
+
+END {
+ for (i = 0; i <= 999; i++) {
+ for (j = 0; j <= 999; j++)
+ count += lights[i][j]
+ }
+ print count
+}
diff --git a/2015/06/puzzle-2.awk b/2015/06/puzzle-2.awk
index 97ae1f8..9774521 100755
--- a/2015/06/puzzle-2.awk
+++ b/2015/06/puzzle-2.awk
@@ -1,7 +1,6 @@
-#!/usr/bin/env -S awk -f
+#!/usr/bin/awk -f
-function setlights(val)
-{
+function setlights(val) {
for (i = from[1]; i <= to[1]; i++) {
for (j = from[2]; j <= to[2]; j++) {
if (!(val == -1 && lights[i][j] == 0))
@@ -11,7 +10,13 @@ function setlights(val)
}
$1 == "toggle" { split($2, from, ","); split($4, to, ","); setlights(2) }
-$2 ~ /on|off/ { split($3, from, ","); split($5, to, ",") }
-$2 == "on" { setlights(1) }
+$2 ~ /on|off/ { split($3, from, ","); split($5, to, ",") }
+$2 == "on" { setlights(+1) }
$2 == "off" { setlights(-1) }
-END { for (i = 0; i <= 999; i++) for (j = 0; j <= 999; j++) count += lights[i][j]; print count }
+END {
+ for (i = 0; i <= 999; i++) {
+ for (j = 0; j <= 999; j++)
+ count += lights[i][j]
+ }
+ print count
+}
diff --git a/2015/07/Makefile b/2015/07/Makefile
index 247194a..0a4e980 100644
--- a/2015/07/Makefile
+++ b/2015/07/Makefile
@@ -1,8 +1 @@
-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
- chmod +x puzzle-[12].py
-
-.PHONY: clean
-clean:
- rm -f puzzle-[12].py
+include ../../Makefiles/py.mk
diff --git a/2015/07/puzzles.py b/2015/07/puzzles.py
index 683e537..fc182fe 100644
--- a/2015/07/puzzles.py
+++ b/2015/07/puzzles.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/python3
# START PART 2
from copy import deepcopy
diff --git a/2015/08/puzzle-1.sh b/2015/08/puzzle-1.sh
index ee35d69..c10a244 100755
--- a/2015/08/puzzle-1.sh
+++ b/2015/08/puzzle-1.sh
@@ -1,7 +1,7 @@
-#!/usr/bin/env sh
+#!/bin/sh
X=$(tr -d '\n' <input | wc -c)
Y=$(sed 's/\(^"\|"$\)//g; s/\\x[a-f0-9]\{2\}/./g; s/\\[\\"]/./g' input \
- | tr -d '\n' \
+ | tr -d '\n' \
| wc -c)
expr $X - $Y
diff --git a/2015/08/puzzle-2.sh b/2015/08/puzzle-2.sh
index a00f13f..2157ae3 100755
--- a/2015/08/puzzle-2.sh
+++ b/2015/08/puzzle-2.sh
@@ -1,7 +1,7 @@
-#!/usr/bin/env sh
+#!/bin/sh
X=$(sed 's/\("\|\\\)/\\&/g; s/^/../' input \
- | tr -d '\n' \
+ | tr -d '\n' \
| wc -c)
Y=$(tr -d '\n' <input | wc -c)
expr $X - $Y
diff --git a/2015/09/Makefile b/2015/09/Makefile
index 247194a..0a4e980 100644
--- a/2015/09/Makefile
+++ b/2015/09/Makefile
@@ -1,8 +1 @@
-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
- chmod +x puzzle-[12].py
-
-.PHONY: clean
-clean:
- rm -f puzzle-[12].py
+include ../../Makefiles/py.mk
diff --git a/2015/09/puzzles.py b/2015/09/puzzles.py
index e0d33b7..cb10a63 100644
--- a/2015/09/puzzles.py
+++ b/2015/09/puzzles.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/python3
import itertools
import re
diff --git a/2015/10/README b/2015/10/README
index 1102d82..caf3dad 100644
--- a/2015/10/README
+++ b/2015/10/README
@@ -2,8 +2,9 @@
NOTE
======
-I did not come up with the shell script solution myself, that is why I also included the very slow
-Go solution. The shell script solution comes from this Reddit post:
+I did not come up with the shell script solution myself, that is why I also
+included the very slow Go solution. The shell script solution comes from this
+Reddit post:
https://www.reddit.com/r/adventofcode/comments/3w6h3m/comment/cxtsigs/
diff --git a/2015/10/puzzles.sh b/2015/10/puzzles.sh
index 291ac96..d510052 100755
--- a/2015/10/puzzles.sh
+++ b/2015/10/puzzles.sh
@@ -1,7 +1,6 @@
#!/usr/bin/env sh
-output()
-{
+output() {
echo $in | tr -d '\n' | wc -c
}
diff --git a/2015/11/puzzle-1 b/2015/11/puzzle-1
index b0e5756..913a194 100644
--- a/2015/11/puzzle-1
+++ b/2015/11/puzzle-1
@@ -1,7 +1,8 @@
-The starting string is "hepxcrrq"
+The starting string is “hepxcrrq”
-The string must contain two sets of non-overlapping duplicates, this is best done as having the last
-5 characters be "xxyzz". The first 3 characters aren't illegal, so we don't need to change them.
-This gives an end result of "hepxxyzz".
+The string must contain two sets of non-overlapping duplicates, this is best
+done as having the last 5 characters be “xxyzz”. The first 3 characters aren’t
+illegal, so we don't need to change them. This gives an end result of
+“hepxxyzz”.
-QED. (I hope)
+QED. (I hope)
diff --git a/2015/11/puzzle-2 b/2015/11/puzzle-2
index 444ce35..089865d 100644
--- a/2015/11/puzzle-2
+++ b/2015/11/puzzle-2
@@ -1,9 +1,10 @@
-This continues from the last puzzle, so our starting string is "hepxxyzz"
+This continues from the last puzzle, so our starting string is “hepxxyzz”
-Following the theme of the previous puzzle, we want to create an "xxyzz" pattern in the lowest
-amount of increments possible. Since the string currently ends in "xxyzz", we know that the next
-possible value we could have that satisfies this property is "aabcc". In order to go from "xxyzz" to
-"aabcc" however, you need to overflow which would increment the "p" to a "q". This gives an end
-result of "heqaabcc".
+Following the theme of the previous puzzle, we want to create an “xxyzz” pattern
+in the lowest amount of increments possible. Since the string currently ends in
+“xxyzz”, we know that the next possible value we could have that satisfies this
+property is “aabcc”. In order to go from “xxyzz” to “aabcc” however, you need to
+overflow which would increment the “p” to a “q”. This gives an end result of
+“heqaabcc”.
QED.
diff --git a/2015/12/puzzle-1.sh b/2015/12/puzzle-1.sh
index e1e1f0e..8173222 100755
--- a/2015/12/puzzle-1.sh
+++ b/2015/12/puzzle-1.sh
@@ -1,3 +1,3 @@
-#!/usr/bin/env sh
+#!/bin/sh
tr -c '\-0-9' '\n' <input | grep . | paste -sd+ | bc
diff --git a/2015/12/puzzle-2.sh b/2015/12/puzzle-2.sh
index b1e649c..b941678 100755
--- a/2015/12/puzzle-2.sh
+++ b/2015/12/puzzle-2.sh
@@ -1,7 +1,7 @@
-#!/usr/bin/env sh
+#!/bin/sh
-jq 'walk(if type == "object" then del(select(.[] == "red")) end)' input \
- | tr -c '\-0-9' '\n' \
- | grep . \
- | paste -sd+ \
+jq 'walk(if type == "object" then del(select(.[] == "red")) else . end)' input \
+ | tr -c '\-0-9' '\n' \
+ | grep . \
+ | paste -sd+ \
| bc
diff --git a/2015/13/Makefile b/2015/13/Makefile
index 247194a..0a4e980 100644
--- a/2015/13/Makefile
+++ b/2015/13/Makefile
@@ -1,8 +1 @@
-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
- chmod +x puzzle-[12].py
-
-.PHONY: clean
-clean:
- rm -f puzzle-[12].py
+include ../../Makefiles/py.mk
diff --git a/2015/14/puzzle-1.bc b/2015/14/puzzle-1.bc
index d36cafd..1ccab06 100644
--- a/2015/14/puzzle-1.bc
+++ b/2015/14/puzzle-1.bc
@@ -1,6 +1,5 @@
/* Return the largest element from array `a` of length `l` */
-define max(a[], l)
-{
+define max(a[], l) {
auto m, i
for (i = 0; i < l; i++) {
if (a[i] > m)
@@ -9,11 +8,10 @@ define max(a[], l)
return m
}
-/* Return the kilometers traveled by a raindeer that flys with speed `s` km/s for `t` seconds before
- * needing to rest for `r` seconds.
+/* Return the kilometers traveled by a raindeer that flys with speed `s` km/s
+ * for `t` seconds before needing to rest for `r` seconds.
*/
-define calc(s, t, r)
-{
+define calc(s, t, r) {
auto a, d
while (d + t <= 2503) {
a += s * t
diff --git a/2015/14/puzzle-2.bc b/2015/14/puzzle-2.bc
index 4a41277..b471510 100644
--- a/2015/14/puzzle-2.bc
+++ b/2015/14/puzzle-2.bc
@@ -1,8 +1,7 @@
scale = 0
/* Return the largest element from array `a` of length `l` */
-define max(a[], l)
-{
+define max(a[], l) {
auto m, i
for (i = 0; i < l; i++) {
if (a[i] > m)
@@ -11,8 +10,7 @@ define max(a[], l)
return m
}
-define calc(speed[], time[], rest[], n)
-{
+define calc(speed[], time[], rest[], n) {
auto i, j, k, p[], d[]
for (i = 0; i < 2503; i++) {
diff --git a/2015/14/puzzles.sh b/2015/14/puzzles.sh
index b55642d..93bda78 100755
--- a/2015/14/puzzles.sh
+++ b/2015/14/puzzles.sh
@@ -1,11 +1,11 @@
#!/usr/bin/env sh
-# I use bc-gh(1), but it's just Gavin Howards implementation of bc(1)
-
-sed -e 's|[^0-9]*\([0-9]*\)[^0-9]*\([0-9]*\)[^0-9]*\([0-9]*\).*|x[y++] = calc(\1, \2, \3)|' \
+sed -E \
+ -e 's|[^0-9]*([0-9]*)[^0-9]*([0-9]*)[^0-9]*([0-9]*).*|x[y++] = calc(\1, \2, \3)|' \
-e '$amax(x[], y)' input \
- | bc-gh -q puzzle-1.bc
+ | bc -q puzzle-1.bc
-sed -e 's|[^0-9]*\([0-9]*\)[^0-9]*\([0-9]*\)[^0-9]*\([0-9]*\).*|speed[n] = \1; time[n] = \2; rest[n++] = \3|' \
+sed -E \
+ -e 's|[^0-9]*([0-9]*)[^0-9]*([0-9]*)[^0-9]*([0-9]*).*|speed[n] = \1; time[n] = \2; rest[n++] = \3|' \
-e '$acalc(speed[], time[], rest[], n)' input \
- | bc-gh -q puzzle-2.bc
+ | bc -q puzzle-2.bc
diff --git a/2015/15/Makefile b/2015/15/Makefile
index b01f411..0a4e980 100644
--- a/2015/15/Makefile
+++ b/2015/15/Makefile
@@ -1,8 +1 @@
-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
- chmod +x puzzle-[12].py
-
-.PHONY: clean
-clean:
- rm -f puzzle-[12].py
+include ../../Makefiles/py.mk
diff --git a/2015/15/puzzles.py b/2015/15/puzzles.py
index 5c3be94..1f5fb32 100644
--- a/2015/15/puzzles.py
+++ b/2015/15/puzzles.py
@@ -6,6 +6,12 @@ from math import prod
def main() -> None:
+ # START PART 1
+ GROUPS = 5
+ # END PART 1 START PART 2
+ GROUPS = 6
+ # END PART 2
+
data: list[list[int]] = []
with open("input", "r", encoding="utf-8") as f:
for line in f.readlines():
diff --git a/2015/16/puzzle-1.sh b/2015/16/puzzle-1.sh
index 3550231..6552cf3 100755
--- a/2015/16/puzzle-1.sh
+++ b/2015/16/puzzle-1.sh
@@ -1,25 +1,25 @@
-#!/usr/bin/env sh
+#!/bin/sh
# Definitely there is a better way to do this, but this is fine
# Original solution was just me using regex in vim lol
-sed '/children/!s/$/, children: 3/' input \
- | sed '/cats/!s/$/, cats: 7/' \
- | sed '/samoyeds/!s/$/, samoyeds: 2/' \
+sed '/children/!s/$/, children: 3/' input \
+ | sed '/cats/!s/$/, cats: 7/' \
+ | sed '/samoyeds/!s/$/, samoyeds: 2/' \
| sed '/pomeranians/!s/$/, pomeranians: 3/' \
- | sed '/akitas/!s/$/, akitas: 0/' \
- | sed '/vizslas/!s/$/, vizslas: 0/' \
- | sed '/goldfish/!s/$/, goldfish: 5/' \
- | sed '/trees/!s/$/, trees: 3/' \
- | sed '/cars/!s/$/, cars: 2/' \
- | sed '/perfumes/!s/$/, perfumes: 1/' \
- | grep 'children: 3' \
- | grep 'cats: 7' \
- | grep 'samoyeds: 2' \
- | grep 'pomeranians: 3' \
- | grep 'akitas: 0' \
- | grep 'vizslas: 0' \
- | grep 'goldfish: 5' \
- | grep 'trees: 3' \
- | grep 'cars: 2' \
+ | sed '/akitas/!s/$/, akitas: 0/' \
+ | sed '/vizslas/!s/$/, vizslas: 0/' \
+ | sed '/goldfish/!s/$/, goldfish: 5/' \
+ | sed '/trees/!s/$/, trees: 3/' \
+ | sed '/cars/!s/$/, cars: 2/' \
+ | sed '/perfumes/!s/$/, perfumes: 1/' \
+ | grep 'children: 3' \
+ | grep 'cats: 7' \
+ | grep 'samoyeds: 2' \
+ | grep 'pomeranians: 3' \
+ | grep 'akitas: 0' \
+ | grep 'vizslas: 0' \
+ | grep 'goldfish: 5' \
+ | grep 'trees: 3' \
+ | grep 'cars: 2' \
| sed -n '/perfumes: 1/s/Sue \([0-9]*\).*/\1/p'
diff --git a/2015/16/puzzle-2.sh b/2015/16/puzzle-2.sh
index e854c7c..92e6f9d 100755
--- a/2015/16/puzzle-2.sh
+++ b/2015/16/puzzle-2.sh
@@ -1,26 +1,26 @@
-#!/usr/bin/env sh
+#!/bin/sh
# Definitely there is a better way to do this, but this is fine
# Original solution was just me using regex in vim lol
-sed '/children/!s/$/, children: 3/' input \
- | sed '/cats/!s/$/, cats: 8/' \
- | sed '/samoyeds/!s/$/, samoyeds: 2/' \
+sed '/children/!s/$/, children: 3/' input \
+ | sed '/cats/!s/$/, cats: 8/' \
+ | sed '/samoyeds/!s/$/, samoyeds: 2/' \
| sed '/pomeranians/!s/$/, pomeranians: 2/' \
- | sed '/akitas/!s/$/, akitas: 0/' \
- | sed '/vizslas/!s/$/, vizslas: 0/' \
- | sed '/goldfish/!s/$/, goldfish: 4/' \
- | sed '/trees/!s/$/, trees: 4/' \
- | sed '/cars/!s/$/, cars: 2/' \
- | sed '/perfumes/!s/$/, perfumes: 1/' \
- | sed 's/$/ /' \
- | grep 'children: 3' \
- | grep 'samoyeds: 2' \
- | grep 'akitas: 0' \
- | grep 'vizslas: 0' \
- | grep 'cars: 2' \
- | grep 'perfumes: 1' \
- | grep 'goldfish: [0-4][ ,]' \
- | grep 'pomeranians: [0-2][ ,]' \
- | grep 'cats: \([8-9]\|[1-9][0-9]\)' \
+ | sed '/akitas/!s/$/, akitas: 0/' \
+ | sed '/vizslas/!s/$/, vizslas: 0/' \
+ | sed '/goldfish/!s/$/, goldfish: 4/' \
+ | sed '/trees/!s/$/, trees: 4/' \
+ | sed '/cars/!s/$/, cars: 2/' \
+ | sed '/perfumes/!s/$/, perfumes: 1/' \
+ | sed 's/$/ /' \
+ | grep 'children: 3' \
+ | grep 'samoyeds: 2' \
+ | grep 'akitas: 0' \
+ | grep 'vizslas: 0' \
+ | grep 'cars: 2' \
+ | grep 'perfumes: 1' \
+ | grep 'goldfish: [0-4][ ,]' \
+ | grep 'pomeranians: [0-2][ ,]' \
+ | grep 'cats: \([8-9]\|[1-9][0-9]\)' \
| sed -n '/trees: \([4-9]\|[1-9][0-9]\)/s/Sue \([0-9]*\).*/\1/p'
diff --git a/2015/18/Makefile b/2015/18/Makefile
index 247194a..0a4e980 100644
--- a/2015/18/Makefile
+++ b/2015/18/Makefile
@@ -1,8 +1 @@
-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
- chmod +x puzzle-[12].py
-
-.PHONY: clean
-clean:
- rm -f puzzle-[12].py
+include ../../Makefiles/py.mk
diff --git a/2015/18/puzzles.py b/2015/18/puzzles.py
index 4082ab5..2aa03b9 100644
--- a/2015/18/puzzles.py
+++ b/2015/18/puzzles.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/python3
def neighbours(data: list[list[str]], x: int, y: int) -> int:
@@ -6,12 +6,12 @@ def neighbours(data: list[list[str]], x: int, y: int) -> int:
for x1, y1 in [
(x - 1, y - 1),
- (x - 1, y),
+ (x - 1, y ),
(x - 1, y + 1),
- (x, y - 1),
- (x, y + 1),
+ (x, y - 1),
+ (x, y + 1),
(x + 1, y - 1),
- (x + 1, y),
+ (x + 1, y ),
(x + 1, y + 1),
]:
try:
diff --git a/2015/19/puzzle-1.py b/2015/19/puzzle-1.py
index b694c8b..9b6760a 100755
--- a/2015/19/puzzle-1.py
+++ b/2015/19/puzzle-1.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/python3
import re
diff --git a/2015/19/puzzle-2.sh b/2015/19/puzzle-2.sh
index 78c3ce5..cc28f1c 100755
--- a/2015/19/puzzle-2.sh
+++ b/2015/19/puzzle-2.sh
@@ -1,10 +1,11 @@
-#!/usr/bin/env sh
+#!/bin/sh
-# I could not figure this out on my own, but god bless this guy for doing the math:
+# I could not figure this out on my own, but god bless this guy for doing the
+# math:
# https://www.reddit.com/r/adventofcode/comments/3xflz8/day_19_solutions/cy4etju/
-# Some people has inputs that could be solved by just going in reverse trivially, my input did not
-# work
+# Some people have inputs that could be solved by just going in reverse
+# trivially, my input did not work
sed -n '
$ {
diff --git a/2015/20/Makefile b/2015/20/Makefile
index 8d1d1fa..9a04f0b 100644
--- a/2015/20/Makefile
+++ b/2015/20/Makefile
@@ -1,12 +1 @@
-all:
- sed '/START PART 2/,/END PART 2/d' puzzles.go >tmp1.go
- sed '/START PART 1/,/END PART 1/d' puzzles.go >tmp2.go
- go build tmp1.go
- go build tmp2.go
- mv tmp1 puzzle-1
- mv tmp2 puzzle-2
- rm -f tmp[12].go
-
-.PHONY: clean
-clean:
- rm -f puzzle-[12]
+include ../../Makefiles/go.mk
diff --git a/2015/21/Makefile b/2015/21/Makefile
index 247194a..0a4e980 100644
--- a/2015/21/Makefile
+++ b/2015/21/Makefile
@@ -1,8 +1 @@
-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
- chmod +x puzzle-[12].py
-
-.PHONY: clean
-clean:
- rm -f puzzle-[12].py
+include ../../Makefiles/py.mk
diff --git a/2015/21/puzzles.py b/2015/21/puzzles.py
index 103a2eb..6b17751 100644
--- a/2015/21/puzzles.py
+++ b/2015/21/puzzles.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/python3
import itertools
diff --git a/2015/23/Makefile b/2015/23/Makefile
index 8779ec0..b65503c 100644
--- a/2015/23/Makefile
+++ b/2015/23/Makefile
@@ -1,9 +1,3 @@
-all:
- flex -f -DYY_NO_INPUT --nounput puzzles.l
- ${CC} ${CFLAGS} -lfl -DPROGLEN=`wc -l <input` -o puzzle-1 lex.yy.c
- ${CC} ${CFLAGS} -lfl -DPROGLEN=`wc -l <input` -DPART2 -o puzzle-2 lex.yy.c
- rm lex.yy.c
+CPPFLAGS = -DPROGLEN=`wc -l <input`
-.PHONY: clean
-clean:
- rm -f puzzle-[12]
+include ../../Makefiles/lex.mk
diff --git a/2015/23/puzzles.l b/2015/23/puzzles.l
index 7d654e1..6793126 100644
--- a/2015/23/puzzles.l
+++ b/2015/23/puzzles.l
@@ -1,5 +1,4 @@
%{
-#define _POSIX_C_SOURCE
#include <err.h>
#include <stdbool.h>
#include <stdio.h>
@@ -38,17 +37,17 @@ unsigned long long registers[2];
%%
-hlf { program[i].type = HLF; BEGIN(ARGS); }
-inc { program[i].type = INC; BEGIN(ARGS); }
-jie { program[i].type = JIE; BEGIN(ARGS); }
-jio { program[i].type = JIO; BEGIN(ARGS); }
-jmp { program[i].type = JMP; BEGIN(ARGS); }
-tpl { program[i].type = TPL; BEGIN(ARGS); }
-
-<ARGS>[ab] { program[i].reg = *yytext - 'a'; }
-<ARGS>[+\-][0-9]+ { program[i].imm = atoi(yytext); }
-<ARGS>[ ,]+ { ; }
-<ARGS>\n { i++; BEGIN(INITIAL); }
+hlf { program[i].type = HLF; BEGIN(ARGS); }
+inc { program[i].type = INC; BEGIN(ARGS); }
+jie { program[i].type = JIE; BEGIN(ARGS); }
+jio { program[i].type = JIO; BEGIN(ARGS); }
+jmp { program[i].type = JMP; BEGIN(ARGS); }
+tpl { program[i].type = TPL; BEGIN(ARGS); }
+
+<ARGS>[ab] { program[i].reg = *yytext - 'a'; }
+<ARGS>[+\-][0-9]+ { program[i].imm = atoi(yytext); }
+<ARGS>[ ,]+ { ; }
+<ARGS>\n { i++; BEGIN(INITIAL); }
%%