day 12 part 2
[aoc_eblake.git] / 2022 / day04.m4
blob0d898dc79145c49ad8d1d0c38d47374ccba341a7
1 divert(-1)dnl -*- m4 -*-
2 # Usage: m4 [-Dfile=day04.input] day04.m4
4 include(`common.m4')ifelse(common(04), `ok', `',
5 `errprint(`Missing common initialization
6 ')m4exit(1)')
8 define(`part1', 0)define(`part2', 0)
9 define(`bump', `define(`$1', eval($1`+($2)'))')
10 define(`_do', `bump(`part1', `$1>=$3&$2<=$4|$3>=$1&$4<=$2')bump(`part2',
11 `$3<=$2&$4>=$1')')
12 define(`do', `_$0(translit(`$1', `-', `,'))')
14 define(`input', translit((include(defn(`file'))), nl`,()', `;-'))
15 ifdef(`__gnu__', `
16   patsubst(defn(`input'), `\([^;]*\);', `do(`\1')')
17 ', `
18   define(`_chew', `do(substr(`$1', 0, index(`$1', `;')))define(
19     `tail', substr(`$1', incr(index(`$1', `;'))))ifelse(index(defn(`tail'),
20     `;'), -1, `', `$0(defn(`tail'))')')
21   define(`chew', `ifelse(eval($1 < 25), 1, `_$0(`$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   chew(len(defn(`input')), defn(`input'))
27 divert`'part1
28 part2