add aoc2023
This commit is contained in:
parent
59966ade16
commit
3d57434c04
aoc_2022
README.md
day-00
day-01
day-02
day-03
day-04
day-05
day-06
day-07
day-08
day-09
day-10
day-11
day-12
day-13
day-14
day-15
day-16
day-17
day-18
day-19
day-20
day-21
day-22
day-23
day-24
aoc_2023/day0
1000
aoc_2023/day0/input.txt
Normal file
1000
aoc_2023/day0/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
18
aoc_2023/day0/main_1.js
Normal file
18
aoc_2023/day0/main_1.js
Normal file
@ -0,0 +1,18 @@
|
||||
const fs = require("node:fs");
|
||||
|
||||
const data = fs.readFileSync("input.txt", "utf8");
|
||||
|
||||
const res = data
|
||||
.split("\n")
|
||||
.filter((line) => line && line != "")
|
||||
.map((line) => line.replaceAll(/[^0-9]*/g, ""))
|
||||
.reduce((acc, line) => {
|
||||
const nums = line.split("");
|
||||
|
||||
const first = parseInt(nums.at(0));
|
||||
const last = parseInt(nums.at(-1));
|
||||
|
||||
return acc + (first * 10 + last);
|
||||
}, 0);
|
||||
|
||||
console.log(res);
|
43
aoc_2023/day0/main_2.js
Normal file
43
aoc_2023/day0/main_2.js
Normal file
@ -0,0 +1,43 @@
|
||||
const fs = require("node:fs");
|
||||
|
||||
const digits = {
|
||||
one: 1,
|
||||
two: 2,
|
||||
three: 3,
|
||||
four: 4,
|
||||
five: 5,
|
||||
six: 6,
|
||||
seven: 7,
|
||||
eight: 8,
|
||||
nine: 9,
|
||||
};
|
||||
|
||||
const data = fs.readFileSync("input.txt", "utf8");
|
||||
|
||||
const res = data
|
||||
.split("\n")
|
||||
.filter((line) => line && line != "")
|
||||
.map((line) => {
|
||||
let newLine = "";
|
||||
for (let i = 0; i < line.length; i++) {
|
||||
for (let j = i + 1; j < line.length + 1; j++) {
|
||||
const word = line.substring(i, j);
|
||||
if (word.match(/^[0-9]$/)) {
|
||||
newLine += word;
|
||||
}
|
||||
if (word in digits) {
|
||||
newLine += digits[word].toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return newLine;
|
||||
})
|
||||
.reduce((acc, line) => {
|
||||
const nums = line.split("");
|
||||
const first = parseInt(nums.at(0));
|
||||
const last = parseInt(nums.at(-1));
|
||||
|
||||
return acc + (first * 10 + last);
|
||||
}, 0);
|
||||
|
||||
console.log(res);
|
Loading…
Reference in New Issue
Block a user