This commit is contained in:
Aelita4 2022-12-02 10:00:43 +01:00
parent 0a755fe324
commit 53c3925d7c
Signed by: Aelita4
GPG Key ID: E44490C2025906C1
2 changed files with 2582 additions and 0 deletions

82
day02/index.js Normal file
View File

@ -0,0 +1,82 @@
import { readFileSync } from "fs";
const input = readFileSync("rps.txt", "utf-8");
let totalScore = 0;
// A X rock 1
// B Y paper 2
// C Z scissors 3
// lose 0
// draw 3
// win 6
input.split("\n").forEach(line => {
const arr = line.split(" ");
totalScore += getScore(arr[0], arr[1]);
});
console.log(totalScore);
function getScore(opponent, player) {
let score = 0;
switch(player) {
case "X":
score += 1;
break;
case "Y":
score += 2;
break;
case "Z":
score += 3;
break;
}
switch(opponent) {
case "A":
switch(player) {
case "X":
score += 3;
break;
case "Y":
score += 6;
break;
case "Z":
score += 0;
break;
}
break;
case "B":
switch(player) {
case "X":
score += 0;
break;
case "Y":
score += 3;
break;
case "Z":
score += 6;
break;
}
break;
case "C":
switch(player) {
case "X":
score += 6;
break;
case "Y":
score += 0;
break;
case "Z":
score += 3;
break;
}
break;
}
return score;
}

2500
day02/rps.txt Normal file

File diff suppressed because it is too large Load Diff