1 divert(-1)dnl -*- m4 -*-
2 # Usage: m4 [-Dfile=day1.input] day1.m4
4 include(`common.m4')ifelse(common(1), `ok', `',
5 `errprint(`Missing common initialization
8 # The input file contains bare unbalanced ( and ), which is a pain in
9 # m4. Tackle it by reading twice and exploiting that the data starts
10 # with ( but eventually balances out to go to a negative floor. On
11 # the first read, our define() will terminate early and the remaining
12 # input is discarded because we are diverting to -1. On the second
13 # read, we redefine comments to begin with the start of input and end
14 # with a newline (the file lacks one, so just one that we supply), so
15 # that the input is a single comment that we can then post-process
16 # into saner contents.
17 define(`input', include(defn(`file')))
18 define(`part2', incr(len(defn(`input'))))
19 changecom(defn(`input'), `
21 define(`input', include(defn(`file'))
24 define(`input', translit(dquote(defn(`input')), `()
27 define(`part1', eval(len(translit(input, >)) - len(translit(input, <))))