-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday02_part2.js
More file actions
39 lines (32 loc) · 1.02 KB
/
day02_part2.js
File metadata and controls
39 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// A / X for Rock, B / Y for Paper, and C / Z for Scissors
// A / X > C / Z
// C / Z > B / Y
// B / Y > A / X
var fs = require('fs');
var path = require('path');
var filePath = './inputDay02.txt';
const caloriesSums = new Array();
let buffer = fs.readFileSync(path.join(__dirname, filePath));
let chosePoints = { 'A': 1, 'X': 1, 'B': 2, 'Y': 2, 'C': 3, 'Z': 3 };
let choseShape = {
'AX': 'Z', 'AY': 'X', 'AZ': 'Y',
'BX': 'X', 'BY': 'Y', 'BZ': 'Z',
'CX': 'Y', 'CY': 'Z', 'CZ': 'X',
};
let matchPoints = {
'AX': 3, 'AY': 6, 'AZ': 0,
'BX': 0, 'BY': 3, 'BZ': 6,
'CX': 6, 'CY': 0, 'CZ': 3,
};
let totalPoints = 0;
buffer.toString().split('\n').forEach((element, index) => {
if (element.length > 0) {
let elements = element.split(' ');
let first = elements[0];
let second = elements[1];
let myshape = choseShape[first + second];
let currentPoints = chosePoints[myshape] + matchPoints[first + myshape];
totalPoints += currentPoints;
}
});
console.log(totalPoints);