Compare commits

..

2 Commits

Author SHA1 Message Date
Aelita4 56c9032aab
02_2 2022-12-02 10:05:17 +01:00
Aelita4 53c3925d7c
02_1 2022-12-02 10:00:43 +01:00
2 changed files with 2591 additions and 0 deletions

91
day02/index.js Normal file
View File

@ -0,0 +1,91 @@
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;
score += 0;
break;
case "Y":
//score += 2;
score += 3;
break;
case "Z":
//score += 3;
score += 6;
break;
}
switch(opponent) {
case "A":
switch(player) {
case "X":
//score += 3;
score += 3;
break;
case "Y":
//score += 6;
score += 1;
break;
case "Z":
//score += 0;
score += 2;
break;
}
break;
case "B":
switch(player) {
case "X":
score += 1;
break;
case "Y":
score += 2;
break;
case "Z":
score += 3;
break;
}
break;
case "C":
switch(player) {
case "X":
//score += 6;
score += 2;
break;
case "Y":
//score += 0;
score += 3;
break;
case "Z":
//score += 3;
score += 1;
break;
}
break;
}
return score;
}

2500
day02/rps.txt Normal file

File diff suppressed because it is too large Load Diff