1 divert(-1)dnl -*- m4 -*-
2 # Usage: m4 [-Dfile=day02.input] day02.m4
4 include(`common.m4')ifelse(common(02), `ok', `',
5 `errprint(`Missing common initialization
8 define(`part1', 0)define(`part2', 0)
9 define(`do', `define(`part1', eval(part1`+($2+$1)%3*3+$1'))define(`part2',
10 eval(part2`+$1*3-($3-$1)%3'))')
11 define(`setup', `define(`$1', `do('$`1, $2, $3)')')
12 translit(include(defn(`file')), `XYZ 'nl, `123()'setup(`A', 0, 4)setup(`B',
13 2, 3)setup(`C', 1, 5))
15 ifelse(`dnl golfing variants, the newline after Y is essential
17 eval(translit(include(f),X Y
18 Z,1(2)3define(d,`define($1,+($2+$`1')%3*3+$`1')')d(A,0)d(B,2)d(C,1)))
20 eval(translit(include(f),X Y
21 Z,1(2)3define(d,`define($1,+$`1'*3-($2-$`1')%3)')d(A,4)d(B,3)d(C,5)))