mirror of
https://github.com/Baipyrus/AoC-23.git
synced 2024-12-27 04:21:45 +00:00
finalized d7p1
This commit is contained in:
parent
ceacaf6948
commit
e3eeec7fd9
@ -15,7 +15,8 @@ const input = readFileSync("input.txt")
|
||||
.toString()
|
||||
.split("\r\n")
|
||||
.filter((e) => e.length > 0);
|
||||
const plays = input.map((p) => {
|
||||
const plays = input
|
||||
.map((p) => {
|
||||
const [draw, bidding] = p.split(" ");
|
||||
|
||||
const count = draw
|
||||
@ -35,7 +36,22 @@ const plays = input.map((p) => {
|
||||
);
|
||||
|
||||
return { hand, draw, bidding: parseInt(bidding) };
|
||||
});
|
||||
})
|
||||
.sort((a, b) => {
|
||||
const type = a.hand - b.hand;
|
||||
if (type !== 0) return type;
|
||||
|
||||
for (const [i, c] of a.draw.split("").entries()) {
|
||||
const p1 = cards.indexOf(c);
|
||||
const p2 = cards.indexOf(b.draw[i]);
|
||||
|
||||
if (p1 === p2) continue;
|
||||
return p1 > p2 ? -1 : 1;
|
||||
}
|
||||
return 0;
|
||||
})
|
||||
.map((e, i) => e.bidding * (i + 1))
|
||||
.reduce((a, i) => a + i);
|
||||
console.log(plays);
|
||||
|
||||
const t1 = performance.now();
|
||||
|
Loading…
Reference in New Issue
Block a user