1 divert(-1)dnl -*- m4 -*-
2 # Usage: m4 [-Dfile=day25.input] day25.m4
4 include(`common.m4')ifelse(common(25), `ok', `',
5 `errprint(`Missing common initialization
8 define(`To', `<')define(`row', `>')
9 define(`parse', `define(`r', $2)define(`c', $5)')
10 parse(translit((include(defn(`file'))), `<> .()', `(),,'))
11 define(`code', eval(c*(c+1)/ 2 + (c-1)*(r-1) + (r-1)*r/2))
13 define(`bits', `_$0(eval($1, 2))')
14 define(`_bits', ifdef(`__gnu__', ``shift(patsubst($1, ., `, \&'))'',
15 ``ifelse(len($1), 1, `$1', `substr($1, 0, 1),$0(substr($1, 1))')''))
16 define(`modmul', `define(`d', 0)define(`b', $2)pushdef(`m', $3)foreach(`_$0',
17 bits($1))popdef(`m')d`'')
18 define(`_modmul', `define(`d', eval((d * 2 + $1 * b) % m))')
19 define(`modpow', `define(`r', 1)define(`a', $1)pushdef(`m', $3)foreach(`_$0',
20 bits($2))popdef(`m')r`'')
21 define(`_modpow', `define(`r', ifelse($1, 1, `modmul(modmul(r, r, m), a, m)',
23 define(`part1', modmul(20151125, modpow(252533, decr(code), 33554393),