1 divert(-1)dnl -*- m4 -*-
2 # Usage: m4 [-Dfile=day2.input] day2.m4
4 include(`common.m4')ifelse(common(2), `ok', `',
5 `errprint(`Missing common initialization
8 define(`x', 0)define(`y1', 0)define(`y2', 0)
9 translit(include(defn(`file')), ` 'nl, `()'
10 define(`forward', `define(`x', eval(x+$1))define(`y2', eval(y2+$1*y1))')
11 define(`up', `define(`y1', eval(y1-$1))')
12 define(`down', `define(`y1', eval(y1+$1))'))
13 define(`part1', eval(x*y1))
14 define(`part2', eval(x*y2))
16 ifelse(`dnl golfing variants of parts 1, 2:
17 define(d,defn(define))d(x)d(y)translit(include(f),` '
18 forwdp,()d(a,`d(`x',x+$1)')d(u,`d(`y',y-$1)')d(n,`d(`y',y+$1)'))eval((x)*(y))
19 define(d,defn(define))d(x)d(y)d(z,0)translit(include(f),` '
20 forwdp,()d(a,`d(`x',x+$1)d(`y',y+$1*(z))')d(u,`d(`z',z-$1)')d(n,`d(`z',z+$1)'))eval((x)*(y))