From b5f130aea1e26606784ecfa0a20f8fcfb19abc99 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 19 Dec 2023 18:22:40 -0600 Subject: [PATCH] day 17 part 2 wrong 1392 too high --- 2023/day17.m4 | 93 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 27 deletions(-) diff --git a/2023/day17.m4 b/2023/day17.m4 index d630988..efb4296 100644 --- a/2023/day17.m4 +++ b/2023/day17.m4 @@ -1,10 +1,9 @@ divert(-1)dnl -*- m4 -*- # Usage: m4 [-Dfile=day17.input] day17.m4 # Optionally use -Dverbose=1 to see some progress -# Optionally use -Dalgo=bfs|astar to choose search algorithm # Optionally use -Dpriority=1|2|3|4|5 to choose priority queue algorithm -include(`common.m4')ifelse(common(17), `ok', `', +include(`common.m4')ifelse(common(17, 1000003), `ok', `', `errprint(`Missing common initialization ')m4exit(1)') @@ -12,8 +11,8 @@ include(`priority.m4') ifdef(`algo', `', `define(`algo', `astar')') define(`input', translit(include(defn(`file')), nl, `0')) -define(`x', 1)define(`y', 1) -define(`do', `ifelse(`$3', 0, `define(`maxx', $1)define(`x', 1)define(`y', +define(`x', 4)define(`y', 4) +define(`do', `ifelse(`$3', 0, `define(`maxx', $1)define(`x', 4)define(`y', incr($2))', `define(`x', incr($1))define(`g$1_$2', $3)')') ifdef(`__gnu__', ` @@ -25,33 +24,70 @@ ifdef(`__gnu__', ` ') define(`p', `ifdef(`g$1_$2', `addwork($1, $2, `$3', $4+g$1_$2, `$5')')') -define(`ve1', `p($1, decr($2), `n1', $3, `$4n')p(incr($1), $2, `e2', $3, `$4e')p( - $1, incr($2), `s1', $3, `$4s')') -define(`ve2', `p($1, decr($2), `n1', $3, `$4n')p(incr($1), $2, `e3', $3, `$4e')p( - $1, incr($2), `s1', $3, `$4s')') -define(`ve3', `p($1, decr($2), `n1', $3, `$4n')p($1, incr($2), `s1', $3, `$4s')') -define(`vs1', `p(incr($1), $2, `e1', $3, `$4e')p($1, incr($2), `s2', $3, `$4s')p( - decr($1), $2, `w1', $3, `$4w')') -define(`vs2', `p(incr($1), $2, `e1', $3, `$4e')p($1, incr($2), `s3', $3, `$4s')p( - decr($1), $2, `w1', $3, `$4w')') -define(`vs3', `p(incr($1), $2, `e1', $3, `$4e')p(decr($1), $2, `w1', $3, `$4w')') -define(`vw1', `p($1, decr($2), `n1', $3, `$4n')p(decr($1), $2, `w2', $3, `$4w')p( - $1, incr($2), `s1', $3, `$4s')') -define(`vw2', `p($1, decr($2), `n1', $3, `$4n')p(decr($1), $2, `w3', $3, `$4w')p( - $1, incr($2), `s1', $3, `$4s')') -define(`vw3', `p($1, decr($2), `n1', $3, `$4n')p($1, incr($2), `s1', $3, `$4s')') -define(`vn1', `p(incr($1), $2, `e1', $3, `$4e')p($1, decr($2), `n2', $3, `$4n')p( - decr($1), $2, `w1', $3, `$4w')') -define(`vn2', `p(incr($1), $2, `e1', $3, `$4e')p($1, decr($2), `n3', $3, `$4n')p( - decr($1), $2, `w1', $3, `$41')') -define(`vn3', `p(incr($1), $2, `e1', $3, `$4e')p(decr($1), $2, `w1', $3, `$4w')') -define(`visit', `v$3($1, $2, $4, `$5')') +define(`e', `p(incr($1), $2, `$0$5', $3, `$4$0')')define(`E', defn(`e')) +define(`s', `p($1, incr($2), `$0$5', $3, `$4$0')')define(`S', defn(`s')) +define(`w', `p(decr($1), $2, `$0$5', $3, `$4$0')')define(`W', defn(`w')) +define(`n', `p($1, decr($2), `$0$5', $3, `$4$0')')define(`N', defn(`n')) + +define(`ve1', `n($@, 1)e($@, 2)s($@, 1)') +define(`ve2', `n($@, 1)e($@, 3)s($@, 1)') +define(`ve3', `n($@, 1)s($@, 1)') +define(`vs1', `e($@, 1)s($@, 2)w($@, 1)') +define(`vs2', `e($@, 1)s($@, 3)w($@, 1)') +define(`vs3', `e($@, 1)w($@, 1)') +define(`vw1', `s($@, 1)w($@, 2)n($@, 1)') +define(`vw2', `s($@, 1)w($@, 3)n($@, 1)') +define(`vw3', `s($@, 1)n($@, 1)') +define(`vn1', `w($@, 1)n($@, 2)e($@, 1)') +define(`vn2', `w($@, 1)n($@, 3)e($@, 1)') +define(`vn3', `w($@, 1)e($@, 1)') + +define(`vE1', `ifdef(`g'eval($1+4)`_$2', `addwork(eval($1+4), $2, `E4', + $3+defn(`g'eval($1+1)`_$2')+defn(`g'eval($1+2)`_$2')+defn(`g'eval($1+3)`_$2') + +defn(`g'eval($1+4)`_$2'), `$4EEEE')')') +define(`vE4', `vN1($@)E($@, 5)vS1($@)') +define(`vE5', `vN1($@)E($@, 6)vS1($@)') +define(`vE6', `vN1($@)E($@, 7)vS1($@)') +define(`vE7', `vN1($@)E($@, 8)vS1($@)') +define(`vE8', `vN1($@)E($@, 9)vS1($@)') +define(`vE9', `vN1($@)E($@, 10)vS1($@)') +define(`vE10', `vN1($@)vS1($@)') +define(`vS1', `ifdef(`g$1_'eval($2+4), `addwork($1, eval($2+4), `S4', + $3+defn(`g$1_'eval($2+1))+defn(`g$1_'eval($2+2))+defn(`g$1_'eval($2+3)) + +defn(`g$1_'eval($2+4)), `$4SSSS')')') +define(`vS4', `vE1($@)S($@, 5)vW1($@)') +define(`vS5', `vE1($@)S($@, 6)vW1($@)') +define(`vS6', `vE1($@)S($@, 7)vW1($@)') +define(`vS7', `vE1($@)S($@, 8)vW1($@)') +define(`vS8', `vE1($@)S($@, 9)vW1($@)') +define(`vS9', `vE1($@)S($@, 10)vW1($@)') +define(`vS10', `vE1($@)vW1($@)') +define(`vW1', `ifdef(`g'eval($1-4)`_$2', `addwork(eval($1-4), $2, `W4', + $3+defn(`g'eval($1-1)`_$2')+defn(`g'eval($1-2)`_$2')+defn(`g'eval($1-3)`_$2') + +defn(`g'eval($1-4)`_$2'), `$4WWWW')')') +define(`vW4', `vS1($@)W($@, 5)vN1($@)') +define(`vW5', `vS1($@)W($@, 6)vN1($@)') +define(`vW6', `vS1($@)W($@, 7)vN1($@)') +define(`vW7', `vS1($@)W($@, 8)vN1($@)') +define(`vW8', `vS1($@)W($@, 9)vN1($@)') +define(`vW9', `vS1($@)W($@, 10)vN1($@)') +define(`vW10', `vS1($@)vN1($@)') +define(`vN1', `ifdef(`g$1_'eval($2+4), `addwork($1, eval($2+4), `N4', + $3+defn(`g$1_'eval($2+1))+defn(`g$1_'eval($2+2))+defn(`g$1_'eval($2+3)) + +defn(`g$1_'eval($2+4)), `$4NNNN')')') +define(`vN4', `vW1($@)N($@, 5)vE1($@)') +define(`vN5', `vW1($@)N($@, 6)vE1($@)') +define(`vN6', `vW1($@)N($@, 7)vE1($@)') +define(`vN7', `vW1($@)N($@, 8)vE1($@)') +define(`vN8', `vW1($@)N($@, 9)vE1($@)') +define(`vN9', `vW1($@)N($@, 10)vE1($@)') +define(`vN10', `vW1($@)vE1($@)') define(`dist', `eval('maxx`-$1+'y`-$2-2+$3)') define(`addwork', `ifdef(`p$1_$2$3', `', `define(`p$1_$2$3')insert(dist($1, $2, $4), $@)')') define(`_round', `ifelse(`$2.$3', 'decr(maxx).decr(y)`, `eval($5)clearall()', - `visit($2, $3, `$4', $5, `$6')round()')') + `v$4($2, $3, `$5', `$6')round()')') define(`round', `_$0(pop())') define(`progress', 0) @@ -60,8 +96,11 @@ define(`show0', `output(1, `...$1')rename(`show$1', `show'eval($1+10000))') define(`show', `ifdef(`$0$1', `$0$1($1)')define(`progress', incr($1))') ifelse(eval(verbose >1), 1, `define(`round', `show(progress)'defn(`round'))') -p(2, 1, `e1', 0, `e')p(1, 2, `s1', 0, `s') +e(4, 4, 0, `', 1)s(4, 4, 0, `', 1) define(`part1', round()) +vE1(4, 4, 0)vS1(4, 4, 0) +define(`part2', round()) + divert`'part1 part2 -- 2.11.4.GIT