mirror of
https://github.com/Baipyrus/AoC-23.git
synced 2024-11-14 01:33:50 +00:00
reading plays; detecting hand types
This commit is contained in:
parent
167b259c9f
commit
2fcefde8f7
@ -2,16 +2,33 @@ import { readFileSync } from "fs";
|
|||||||
const t0 = performance.now();
|
const t0 = performance.now();
|
||||||
|
|
||||||
const patterns = [
|
const patterns = [
|
||||||
"abcde",
|
"01234",
|
||||||
"aabcd",
|
"00123",
|
||||||
"aabbc",
|
"00112",
|
||||||
"aaabc",
|
"00012",
|
||||||
"aaabb",
|
"00011",
|
||||||
"aaaab",
|
"00001",
|
||||||
"aaaaa",
|
"00000",
|
||||||
];
|
];
|
||||||
const input = readFileSync("input.txt").toString();
|
const cards = ["A", "K", "Q", "J", "T", "9", "8", "7", "6", "5", "4", "3", "2"];
|
||||||
console.log(input);
|
const input = readFileSync("input.txt")
|
||||||
|
.toString()
|
||||||
|
.split("\r\n")
|
||||||
|
.filter((e) => e.length > 0);
|
||||||
|
const plays = input.map((e) => {
|
||||||
|
const [draw, bidding] = e.split(" ");
|
||||||
|
|
||||||
|
let count = 0;
|
||||||
|
const hand = draw
|
||||||
|
.split("")
|
||||||
|
.map((e) => cards.indexOf(e))
|
||||||
|
.sort((a, b) => b - a)
|
||||||
|
.map((e, i, a) => (i !== 0 && e !== (a[i - 1] ?? 0) ? ++count : count))
|
||||||
|
.reduce((a, i) => a + i.toString());
|
||||||
|
|
||||||
|
return { hand, draw, bidding };
|
||||||
|
});
|
||||||
|
console.log(plays);
|
||||||
|
|
||||||
const t1 = performance.now();
|
const t1 = performance.now();
|
||||||
console.log(`Runtime: ${t1 - t0}ms`);
|
console.log(`Runtime: ${t1 - t0}ms`);
|
||||||
|
Loading…
Reference in New Issue
Block a user