1 divert(-1)dnl -*- m4 -*-
2 # Usage: m4 [-Dfile=day09.input] day09.m4
4 include(`common.m4')ifelse(common(09), `ok', `',
5 `errprint(`Missing common initialization
8 define(`prep', `define(`p$1x', 500)define(`p$1y', 500)')
9 forloop_arg(0, 9, `prep')
10 define(`v1_500_500')define(`v2_500_500')define(`part1', 1)define(`part2', 1)
11 define(`bump', `ifdef(`v$1_$2_$3', `', `define(`v$1_$2_$3')define(`part$1',
13 define(`visit', `define(`p$1x', eval(p$1x+$2))define(`p$1y',
14 eval(p$1y+$3))ifelse($1, 1, `bump(1, p1x, p1y)', $1, 9, `bump(2, p9x,
15 p9y)')ifelse($1, 9, `', `check($1, incr($1))')')
16 define(`check', `first(`off'eval(p$2x-p$1x+2)eval(p$2y-p$1y+2))($2)')
17 define(`off00', `visit($1, 1, 1)')
18 define(`off10', `visit($1, 1, 1)')
19 define(`off20', `visit($1, 0, 1)')
20 define(`off30', `visit($1, -1, 1)')
21 define(`off40', `visit($1, -1, 1)')
22 define(`off01', `visit($1, 1, 1)')
26 define(`off41', `visit($1, -1, 1)')
27 define(`off02', `visit($1, 1, 0)')
31 define(`off42', `visit($1, -1, 0)')
32 define(`off03', `visit($1, 1, -1)')
36 define(`off43', `visit($1, -1, -1)')
37 define(`off04', `visit($1, 1, -1)')
38 define(`off14', `visit($1, 1, -1)')
39 define(`off24', `visit($1, 0, -1)')
40 define(`off34', `visit($1, -1, -1)')
41 define(`off44', `visit($1, -1, -1)')
42 define(`move', `ifelse($1, 0, `', `visit(0, $2, $3)$0(decr($1), $2, $3)')')
44 translit(include(defn(`file')), ` 'nl, `()'define(`U', `move('$`1, 0,
45 -1)')define(`D', `move('$`1, 0, 1)')define(`L', `move('$`1, -1,
46 0)')define(`R', `move('$`1, 1, 0)'))