day 14 semi-golf, with missing fifth glyph
[aoc_eblake.git] / 2015 / day8.m4
blob6f22d68e07a77dc77cde4023152e03349f95a410
1 divert(-1)dnl -*- m4 -*-
2 # Usage: m4 [-Dfile=day8.input] day8.m4
4 include(`common.m4')ifelse(common(8), `ok', `',
5 `errprint(`Missing common initialization
6 ')m4exit(1)')
8 # Gag: some input files happen to contain macro names
9 pushdef(`nl', `ifelse(`$#', 0, ``$0'', `''nl`)')
10 define(`list', translit(include(defn(`file')), nl(), `;'))
11 define(`part1', len(defn(`list')))
12 define(`part2', eval(2 * part1 - len(translit(defn(`list'), `;')) -
13   len(translit(defn(`list'), `\";'))))
14 define(`_visit', `popdef(`$0')ifelse(`$1', `x', `pushdef(`$0',
15   `popdef(`$0')')pushdef(`$0', `popdef(`$0')')')define(`part1', decr(part1))')
16 define(`visit', `ifelse(`$1', `\', `pushdef(`$0', defn(`_$0'))', `$1', `"',
17   `', `define(`part1', decr(part1))')')
18 ifdef(`__gnu__', `
19   patsubst(defn(`list'), `\(.\)', `visit(`\1')')
20 ',`
21   define(`split', `ifelse($1, 1, `visit(`$2')', `$0(eval($1/2),
22     substr(`$2', 0, eval($1/2)))$0(eval(len(defn(`tail')) + $1 - $1/2),
23     defn(`tail')substr(`$2', eval($1/2)))')')
24   split(len(defn(`list')), defn(`list'))
27 divert`'part1
28 part2