readability
This commit is contained in:
parent
4857f8d12e
commit
33f36a6798
|
@ -11,9 +11,13 @@ provide more information in the form of e.g. graphics.
|
|||
Run a solution by passing the puzzle input to the program:
|
||||
|
||||
```
|
||||
./two.bash < input2
|
||||
./two.awk < input2
|
||||
```
|
||||
or
|
||||
```
|
||||
./five.py -v < test5
|
||||
```
|
||||
or
|
||||
```
|
||||
kotlinc -include-runtime -d seven.jar seven.kt && java -jar seven.jar < input7
|
||||
```
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/awk -f
|
||||
|
||||
function score() {
|
||||
if(a["red"] <= 12 && a["green"] <= 13 && a["blue"] <= 14) sum1 += round
|
||||
sum2 += a["red"] * a["green"] * a["blue"]
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
RS="[:,;\n]"
|
||||
}
|
||||
|
||||
$1=="Game" {
|
||||
score()
|
||||
round=$2
|
||||
delete a
|
||||
next
|
||||
}
|
||||
|
||||
{
|
||||
a[$2] = $1 > a[$2] ? $1 : a[$2]
|
||||
}
|
||||
|
||||
END {
|
||||
score()
|
||||
print sum1
|
||||
print sum2
|
||||
}
|
5
two.bash
5
two.bash
|
@ -1,5 +0,0 @@
|
|||
if ! f=$(mktemp); then exit 1; fi
|
||||
cat > "$f"
|
||||
(cat "$f"; echo Game) | awk -v RS='[:,;\n]' '$1=="Game" {if(a["red"] <= 12 && a["green"] <= 13 && a["blue"] <= 14) sum+=round; round=$2; delete a; next} 1 {a[$2] = $1 > a[$2] ? $1 : a[$2]} END {print sum}'
|
||||
(cat "$f"; echo Game) | awk -v RS='[:,;\n]' '$1=="Game" {sum+= a["red"] * a["green"] * a["blue"]; delete a; next} 1 {a[$2] = $1 > a[$2] ? $1 : a[$2]} END {print sum}'
|
||||
rm "$f"
|
Loading…
Reference in New Issue