day 25 solved in C
[aoc_eblake.git] / 2017 / day9.m4
blobafcac4269a6d1b056f3fd23a8deee9b9451bd942
1 divert(-1)dnl -*- m4 -*-
2 # Usage: m4 [-Dfile=day9.input] day9.m4
4 include(`common.m4')ifelse(common(9), `ok', `',
5 `errprint(`Missing common initialization
6 ')m4exit(1)')
8 define(`input', translit((include(defn(`file'))), `,`'()'nl, `;[]'))
9 define(`depth', 0)define(`part1', 0)define(`part2', 0)
10 define(`visitc', `popdef(`$0')')
11 define(`visitg', `ifelse(`$1', `>', `popdef(`$0')', `$1', `!', `pushdef(`$0',
12   defn(`visitc'))', `define(`part2', incr(part2))')')
13 define(`visit', `ifelse(`$1', `{', `define(`depth', incr(depth))define(`part1',
14   eval(part1 + depth))', `$1', `}', `define(`depth', decr(depth))', `$1', `<',
15   `pushdef(`$0', defn(`visitg'))')')
16 ifdef(`__gnu__', `
17   patsubst(defn(`input'), `.', `visit(`\&')')
18 ',`
19   define(`split', `ifelse($1, 1, `visit(`$2')', `$0(eval($1/2),
20     substr(`$2', 0, eval($1/2)), `$3')$0(eval($1 - $1/2), substr(`$2',
21     eval($1/2)), `$3')')')
22   split(len(defn(`input')), defn(`input'))
25 divert`'part1
26 part2