day 1 golfed M4 500 significant bytes
[aoc_eblake.git] / 2017 / day25.m4
blob81d03bdf4f910ebe6dfc9144c6e4aa83acd8c59e
1 divert(-1)dnl -*- m4 -*-
2 # Usage: m4 [-Dhashsize=H] [-Dfile=day25.input] day25.m4
4 include(`common.m4')ifelse(common(25, 65537), `ok', `',
5 `errprint(`Missing common initialization
6 ')m4exit(1)')
8 define(`begin_', `define(`init', `$4')')
9 define(`perform_', `define(`do$6', `$'2)')
10 define(`in_', `define(`st', `$3')')
11 define(`if_', `define(`rd', `$6')')
12 define(`write_', `define(st`'rd, defn(`rd')`,`$4'')')
13 define(`move_', `define(st`'rd, defn(st`'rd)`,'dquote(substr(`$6', 0, 1)))')
14 define(`cont_', `define(st`'rd, defn(st`'rd)`,`$4'')')
15 translit(include(defn(`file')), `.: ', define(`Begin', `begin_(')define(
16   `Perform', `perform_(')define(`In', `in_(')define(`If', `if_(')define(
17   `Write', `write_(')define(`Move', `move_(')define(`Continue', `cont_(')`)),')
19 define(`rename', `ifdef(`$2', `', `define(`$2', defn(`$1'))popdef(`$1')')')
20 define(`do'100000, `output(1, `...'decr(`$1'))rename(`$0', `do'eval(
21   `$1+99999'))_do($@)')
22 define(`do', `ifdef(`$0$1',`$0$1',`_do')(incr(`$1'),`$2',`$3',ifdef(`t$3',
23   `$4'1, `$4'0))')
24 define(`_do', `do(`$1',w$4$5(`$2',`$3'),m$6(`$3'),`$7')')
25 define(`w00', `$1')
26 define(`w01', `define(`t$2')incr(`$1')')
27 define(`w10', `popdef(`t$2')decr(`$1')')
28 define(`w11', `$1')
29 define(`ml', defn(`decr'))define(`mr', defn(`incr'))
30 define(`part1', do(0, 0, 12000, init))
32 divert`'part1
33 no part2