day 11 part 1
[aoc_eblake.git] / 2017 / day17.m4
blob704f4f4274270cee3dbbf3c5fecfe1bf551f7260
1 divert(-1)dnl -*- m4 -*-
2 # Usage: m4 [-Dstep=N] [-Dhashsize=H] [-Dfile=day17.input] day17.m4
4 include(`common.m4')ifelse(common(17, 65537), `ok', `',
5 `errprint(`Missing common initialization
6 ')m4exit(1)')
8 ifdef(`step', `', `define(`step', translit(include(defn(`file')), nl))')
9 define(`set', `ifelse($1, 2018, `', `define(`p$1', eval(($2+step)%$1+1))$0(
10   incr($1), p$1)')')
11 define(`p0', 0)
12 set(1, 0)
13 define(`find', `ifelse(p$1, $2, `$1', `$0(decr($1), ifelse(eval(p$1 < $2), 1,
14   `decr($2)', $2))')')
15 define(`part1', find(2016, p2017))
16 define(`do', `ifelse(eval(`$1 < 50000000'), 1, `ifelse($2, 1, `define(`part2',
17   $1)')_$0($1, $2, $3, eval(`($1 - $2)/$3'))')')
18 define(`_do', `do(eval(`$1+$4+1'), eval(`($2+($4+1)*($3+1)-1)%($1+$4+1)+1'),
19   $3)')
20 do(2017, p2017, step)
22 divert`'part1
23 part2