day 25 optimize and improve heuristics
[aoc_eblake.git] / 2021 / day02.m4
blob2bd77e0416c425aa8b9dda1463f886bb14e2af8f
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
6 ')m4exit(1)')
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))
23 divert`'part1
24 part2