1 divert(-1)dnl -*- m4 -*-
2 # Usage: m4 [-Dfile=day02.input] day02.m4
4 include(`common.m4')ifelse(common(02), `ok', `',
5 `errprint(`Missing common initialization
8 define(`part1', 0)define(`part2', 0)
9 define(`try', `ifelse(`$2', `red', `$1 > 12 || $0(shift(shift($@)))',
10 `$2', `green', `$1 > 13 || $0(shift(shift($@)))',
11 `$2', `blue', `$1 > 14 || $0(shift(shift($@)))', 0)')
12 define(`_game1', `ifelse(eval(try(translit(`$2', ` ', `,'))), `0',
13 `game1(`$1', shift(shift($@)))')')
14 define(`game1', `ifelse(`$2', `', `define(`part1', eval(part1+$1))',
16 define(`max', `ifelse(eval(`$1>$2'), 1, `$1', `$2')')
17 define(`_red', `max($1, $4)`,$2,$3'')
18 define(`_green', ``$1,'max($2, $4)`,$3'')
19 define(`_blue', ``$1,$2,'max($3, $4)')
20 define(`splat', ``$1*$2*$3'')
21 define(`game2', `ifelse(`$2', `', `define(`part2', eval(part2+splat($1)))',
22 `$0(_$3($1, $2), shift(shift(shift($@))))')')
23 define(`game', `game1($@)game2(`0,0,0', translit((shift($@)), ` ()', `,'))')
24 translit((include(defn(`file'))), define(`Game', `game(')nl`:;,', `),,')
27 dnl Here is my entry for Allez Cuisine: Cooking with C-food!
28 changequote(π,π )define(C,πifelse(index($1,^),0,πshift($@)π ,$1,><>,πC(
29 ^C(^C(^C(^C(^C(^$@))))))π ,$1,~,πeval(($2>$3)*$2+($2<=$3)*$3)π ,$4$5,,π) C(
30 ~,0,$1*$2*$3π ,$4,,πC($1,$2,$3,C(><>,,$@))π ,$5,ray,π*($4<13)C(C(~,$1,$4),
31 $2,$3,C(><>,$@))π ,$5,craab,π*($4<14)C($1,C(~,$2,$4),$3,C(><>,$@))π ,$5,
32 orca,π*($4<15)C($1,$2,C(~,$3,$4),C(><>,$@))π ,$4,tuna,π+$5C(0,0,0,C(><>,
33 $@))+$1*$2*$3π )π )translit(_EeL(s(0,0,0,include(I))), (medusa_EGg
34 nlbiL ):;, (naycCuevtc,broil,))