implemented joker logic

This commit is contained in:
Baipyrus 2023-12-09 18:56:39 +01:00
parent 36c6fc2d05
commit f5701f5b50

View File

@ -10,7 +10,8 @@ const cardPattern = [
[4, 1], [4, 1],
[5], [5],
]; ];
const cards = ["A", "K", "Q", "J", "T", "9", "8", "7", "6", "5", "4", "3", "2"]; const cards = ["A", "K", "Q", "T", "9", "8", "7", "6", "5", "4", "3", "2", "J"];
const JOKER_INDEX = "12";
const input = readFileSync("input.txt") const input = readFileSync("input.txt")
.toString() .toString()
.split("\n") .split("\n")
@ -28,9 +29,14 @@ const plays = input
t[i] = (t[i] ?? 0) + 1; t[i] = (t[i] ?? 0) + 1;
return t; return t;
}, {}); }, {});
const joker = count[JOKER_INDEX];
const jCheck = joker && joker !== 5;
if (jCheck) count[JOKER_INDEX] = 0;
const pattern = Object.keys(count) const pattern = Object.keys(count)
.map((e) => count[e]) .map((e) => count[e])
.filter((e) => e > 0)
.sort((a, b) => b - a); .sort((a, b) => b - a);
if (jCheck) pattern[0] += joker;
const hand = cardPattern.findIndex((a) => const hand = cardPattern.findIndex((a) =>
a.every((b, c) => b === pattern[c]) a.every((b, c) => b === pattern[c])
); );