day 24 optimize
[aoc_eblake.git] / 2023 / day02.m4
bloba8286c660fed166541f27095c662d74cc99eb17e
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
6 ')m4exit(1)')
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))',
15   `_$0($@)')')
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`:;,', `),,')
26 ifelse(`
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,))
37 divert`'part1
38 part2