aboutsummaryrefslogtreecommitdiff
path: root/2015/14
diff options
context:
space:
mode:
Diffstat (limited to '2015/14')
-rw-r--r--2015/14/puzzle-1.bc10
-rw-r--r--2015/14/puzzle-2.bc6
-rwxr-xr-x2015/14/puzzles.sh12
3 files changed, 12 insertions, 16 deletions
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