wip d2p2
This commit is contained in:
@@ -4,7 +4,7 @@ import {readFile} from "../../utils";
|
||||
|
||||
let input = readFile(path.resolve(__dirname, 'input.txt'));
|
||||
|
||||
const ans = Math.max(
|
||||
const day1 = Math.max(
|
||||
...input
|
||||
.split("\n\n")
|
||||
.map(a => a.split("\n"))
|
||||
@@ -13,5 +13,16 @@ const ans = Math.max(
|
||||
.reduce((a, b) => a + b), 0)
|
||||
)
|
||||
|
||||
console.log(ans);
|
||||
console.log("Day1:", day1);
|
||||
|
||||
const day2 =
|
||||
input
|
||||
.split("\n\n")
|
||||
.map(a => a.split("\n"))
|
||||
.map(buck => buck.map(Number).reduce((a, b) => a + b), 0)
|
||||
.sort((n1,n2) => n2 - n1)
|
||||
.splice(0,3)
|
||||
.reduce((n1, n2) => n1 + n2)
|
||||
|
||||
|
||||
console.log("Day2:", day2);
|
||||
3
src/2022/day2/example.txt
Normal file
3
src/2022/day2/example.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
A Y
|
||||
B X
|
||||
C Z
|
||||
56
src/2022/day2/index.ts
Normal file
56
src/2022/day2/index.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import * as fs from 'fs';
|
||||
import path from 'path';
|
||||
import {readFile, sum} from "../../utils";
|
||||
|
||||
let input = readFile(path.resolve(__dirname, 'input.txt'));
|
||||
|
||||
const roll = (line) => {
|
||||
|
||||
const [opp, me] = line.split(" ");
|
||||
|
||||
if(opp === "A"){
|
||||
if(me === "X") return 3 + 1;
|
||||
if(me === "Y") return 6 + 2;
|
||||
if(me === "Z") return 0 + 3;
|
||||
}
|
||||
if(opp === "B"){
|
||||
if(me === "X") return 0 + 1;
|
||||
if(me === "Y") return 3 + 2;
|
||||
if(me === "Z") return 6 + 3;
|
||||
}
|
||||
if(opp === "C"){
|
||||
if(me === "X") return 6 + 1;
|
||||
if(me === "Y") return 0 + 2;
|
||||
if(me === "Z") return 3 + 3;
|
||||
}
|
||||
}
|
||||
|
||||
const day1 = input.split("\n").map(roll).reduce(sum);
|
||||
|
||||
console.log("Day1:", day1);
|
||||
|
||||
const roll2 = (line) => {
|
||||
|
||||
const [opp, me] = line.split(" ");
|
||||
|
||||
if(opp === "A"){
|
||||
if(me === "X") return 3 + 1;
|
||||
if(me === "Y") return 6 + 2;
|
||||
if(me === "Z") return 0 + 3;
|
||||
}
|
||||
if(opp === "B"){
|
||||
if(me === "X") return 0 + 1;
|
||||
if(me === "Y") return 3 + 2;
|
||||
if(me === "Z") return 6 + 3;
|
||||
}
|
||||
if(opp === "C"){
|
||||
if(me === "X") return 6 + 1;
|
||||
if(me === "Y") return 0 + 2;
|
||||
if(me === "Z") return 3 + 3;
|
||||
}
|
||||
}
|
||||
|
||||
const day2 = input.split("\n").map(roll2).reduce(sum);
|
||||
|
||||
console.log("Day2:", day2);
|
||||
|
||||
2500
src/2022/day2/input.txt
Normal file
2500
src/2022/day2/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user