20 lines
598 B
Bash
Executable File
20 lines
598 B
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
# part 1 values
|
|
# 3,1 6,2 0,3 0,1 3,2 6,3 6,1 0,2 3,3
|
|
set -- 4 8 3 1 5 9 7 2 6
|
|
while getopts :2 OPT; do
|
|
case $OPT in
|
|
# 0,3 3,1 6,2 0,1 3,2 6,3 0,2 3,3 6,1
|
|
2) set -- 3 4 8 1 5 9 2 6 7 ;;
|
|
*) echo "bad option" 1>&2; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
# sort 02_input | uniq -c | awk '{print $1}' | while read l; do printf "$l" | sed s/$/*$1+/; shift; done | sed s/+$/\\n/ | bc
|
|
sort 02_input | uniq -c | awk '{print $1}' | while read l; do
|
|
printf "$l" | sed s/$/*$1+/ # if you go for the less magic-numbery version you can do sed "s/$/*(${1%,*}+${1#*,})/"
|
|
shift
|
|
done | sed s/+$/\\n/ | bc
|