This commit is contained in:
setop 2022-12-02 10:26:15 +01:00
parent 74439923dd
commit 8b094b5731
4 changed files with 65 additions and 0 deletions

18
d02/part1.awk Normal file
View File

@ -0,0 +1,18 @@
# A for Rock, B for Paper, and C for Scissors
# X for Rock, Y for Paper, and Z for Scissors
# 1 for Rock, 2 for Paper, and 3 for Scissors
# 0 if you lost, 3 if the round was a draw, and 6 if you won
$2 == "X" { S+= 1}
$2 == "Y" { S+= 2}
$2 == "Z" { S+= 3}
($1 == "A" && $2 == "X") ||
($1 == "B" && $2 == "Y") ||
($1 == "C" && $2 == "Z") { S+=3 } # draw
($1 == "A" && $2 == "Y") ||
($1 == "B" && $2 == "Z") ||
($1 == "C" && $2 == "X") { S+=6 } # win
END { print S }

13
d02/part1b.awk Normal file
View File

@ -0,0 +1,13 @@
#loose
$1=="A"&&$2=="Z"{S+=3;P+=6+1;next}
$1=="B"&&$2=="X"{S+=1;P+=6+2;next}
$1=="C"&&$2=="Y"{S+=2;P+=6+3;next}
#draw
$1=="A"&&$2=="X"{S+=3+1;P+=3+1;next}
$1=="B"&&$2=="Y"{S+=3+2;P+=3+2;next}
$1=="C"&&$2=="Z"{S+=3+3;P+=3+3;next}
#win
$1=="A"&&$2=="Y"{S+=6+2;P+=1;next}
$1=="B"&&$2=="Z"{S+=6+3;P+=2;next}
$1=="C"&&$2=="X"{S+=6+1;P+=3;next}
END{print S,P}

21
d02/part2.awk Normal file
View File

@ -0,0 +1,21 @@
# A for Rock, B for Paper, and C for Scissors
# X need to lose, Y need a draw, and Z need to win.
# 1 for Rock, 2 for Paper, and 3 for Scissors
# 0 if you lost, 3 if the round was a draw, and 6 if you won
# to loose
($2 == "X") && ($1 == "A") { S+= 0 + 3; } # A for Rock, need scisors, worth 3
($2 == "X") && ($1 == "B") { S+= 0 + 1; } # B for Paper, need rock, worth 1
($2 == "X") && ($1 == "C") { S+= 0 + 2; } # C for Scissors, need papaer, worth 2
# to draw
($2 == "Y") && ($1 == "A") { S+= 3 + 1; } # A for Rock, need rock, worth 1
($2 == "Y") && ($1 == "B") { S+= 3 + 2; } # B for Paper, need paper, worth 2
($2 == "Y") && ($1 == "C") { S+= 3 + 3; } # C for Scissors, need scissors, worth 3
# to win
($2 == "Z") && ($1 == "A") { S+= 6 + 2; } # A for Rock, need paper, worth 2
($2 == "Z") && ($1 == "B") { S+= 6 + 3; } # B for Paper, need scissors, worth 3
($2 == "Z") && ($1 == "C") { S+= 6 + 1; } # C for Scissors, nee rock, worth 1
END { print S }

13
d02/part2b.awk Normal file
View File

@ -0,0 +1,13 @@
#loose
$2=="X"&&$1=="A"{S+=3;P+=6+1;next}
$2=="X"&&$1=="B"{S+=1;P+=6+2;next}
$2=="X"&&$1=="C"{S+=2;P+=6+3;next}
#draw
$2=="Y"&&$1=="A"{S+=3+1;P+=3+1;next}
$2=="Y"&&$1=="B"{S+=3+2;P+=3+2;next}
$2=="Y"&&$1=="C"{S+=3+3;P+=3+3;next}
#win
$2=="Z"&&$1=="A"{S+=6+2;P+=1;next}
$2=="Z"&&$1=="B"{S+=6+3;P+=2;next}
$2=="Z"&&$1=="C"{S+=6+1;P+=3;next}
END{print S,P}