From f3e3e3e354b87f4ce27bd74bf14cec05d06974b6 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Wed, 30 Nov 2022 12:23:17 +0100 Subject: Lots of cleanup and stuff --- 2015/01/Makefile | 8 +------- 2015/02/Makefile | 1 + 2015/02/puzzle-1.awk | 6 +++--- 2015/02/puzzle-2.awk | 6 +++--- 2015/02/puzzles.awk | 27 +++++++++++++++++++++++++++ 2015/03/puzzles.sh | 2 +- 2015/04/Makefile | 9 +++------ 2015/05/puzzle-1.sed | 6 +++--- 2015/05/puzzle-2.sed | 4 ++-- 2015/05/puzzles.sh | 6 +++--- 2015/06/puzzle-1.awk | 16 +++++++++++----- 2015/06/puzzle-2.awk | 17 +++++++++++------ 2015/07/Makefile | 9 +-------- 2015/07/puzzles.py | 2 +- 2015/08/puzzle-1.sh | 4 ++-- 2015/08/puzzle-2.sh | 4 ++-- 2015/09/Makefile | 9 +-------- 2015/09/puzzles.py | 2 +- 2015/10/README | 5 +++-- 2015/10/puzzles.sh | 3 +-- 2015/11/puzzle-1 | 11 ++++++----- 2015/11/puzzle-2 | 13 +++++++------ 2015/12/puzzle-1.sh | 2 +- 2015/12/puzzle-2.sh | 10 +++++----- 2015/13/Makefile | 9 +-------- 2015/14/puzzle-1.bc | 10 ++++------ 2015/14/puzzle-2.bc | 6 ++---- 2015/14/puzzles.sh | 12 ++++++------ 2015/15/Makefile | 9 +-------- 2015/15/puzzles.py | 6 ++++++ 2015/16/puzzle-1.sh | 38 +++++++++++++++++++------------------- 2015/16/puzzle-2.sh | 40 ++++++++++++++++++++-------------------- 2015/18/Makefile | 9 +-------- 2015/18/puzzles.py | 10 +++++----- 2015/19/puzzle-1.py | 2 +- 2015/19/puzzle-2.sh | 9 +++++---- 2015/20/Makefile | 13 +------------ 2015/21/Makefile | 9 +-------- 2015/21/puzzles.py | 2 +- 2015/23/Makefile | 10 ++-------- 2015/23/puzzles.l | 23 +++++++++++------------ 41 files changed, 187 insertions(+), 212 deletions(-) create mode 100644 2015/02/Makefile create mode 100644 2015/02/puzzles.awk 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' 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' 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 #include #include @@ -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); } - -[ab] { program[i].reg = *yytext - 'a'; } -[+\-][0-9]+ { program[i].imm = atoi(yytext); } -[ ,]+ { ; } -\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); } + +[ab] { program[i].reg = *yytext - 'a'; } +[+\-][0-9]+ { program[i].imm = atoi(yytext); } +[ ,]+ { ; } +\n { i++; BEGIN(INITIAL); } %% -- cgit v1.2.3