aboutsummaryrefslogtreecommitdiff
path: root/2024/03/puzzle-2.sh
blob: cc8e677036403c6618dafc0f69ad293e26a238f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
#!/bin/sh

grep -Eo "(mul\\([0-9]+,[0-9]+\\)|do(n't)?\(\))" input \
| awk 'BEGIN        { FPAT = "[0-9]+"; go = 1 }
       /do\(/       { go = 1 }
       /don/        { go = 0 }
       /mul/ && go  { x += $1 * $2 }
       END          { print x }
'