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
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(
13 define(`find', `ifelse(p$1, $2, `$1', `$0(decr($1), ifelse(eval(p$1 < $2), 1,
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'),