From 8b094b573189d9b43336997127d616bf55627bfc Mon Sep 17 00:00:00 2001 From: setop Date: Fri, 2 Dec 2022 10:26:15 +0100 Subject: [PATCH] day 2 --- d02/part1.awk | 18 ++++++++++++++++++ d02/part1b.awk | 13 +++++++++++++ d02/part2.awk | 21 +++++++++++++++++++++ d02/part2b.awk | 13 +++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 d02/part1.awk create mode 100644 d02/part1b.awk create mode 100644 d02/part2.awk create mode 100644 d02/part2b.awk diff --git a/d02/part1.awk b/d02/part1.awk new file mode 100644 index 0000000..936a84a --- /dev/null +++ b/d02/part1.awk @@ -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 } \ No newline at end of file diff --git a/d02/part1b.awk b/d02/part1b.awk new file mode 100644 index 0000000..d80be8c --- /dev/null +++ b/d02/part1b.awk @@ -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} \ No newline at end of file diff --git a/d02/part2.awk b/d02/part2.awk new file mode 100644 index 0000000..19e4318 --- /dev/null +++ b/d02/part2.awk @@ -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 } diff --git a/d02/part2b.awk b/d02/part2b.awk new file mode 100644 index 0000000..4e8b062 --- /dev/null +++ b/d02/part2b.awk @@ -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}