adventofcode/2022/07/part2.js

21 lines
399 B
JavaScript
Raw Normal View History

2022-12-07 23:43:09 +00:00
import * as R from "remeda";
2022-12-07 23:43:32 +00:00
import { cumulative, parseInput } from "./part1.js";
2022-12-07 23:43:09 +00:00
export default (lines) => {
2022-12-07 23:43:32 +00:00
let cumu = R.pipe(lines, parseInput, cumulative);
2022-12-07 23:43:09 +00:00
2022-12-07 23:43:32 +00:00
console.log(cumu);
2022-12-07 23:43:09 +00:00
2022-12-07 23:43:32 +00:00
const spaceNeeded = 30000000 - 70000000 + cumu["/"];
2022-12-07 23:43:09 +00:00
2022-12-07 23:43:32 +00:00
cumu = R.pickBy(cumu, (v) => v >= spaceNeeded);
2022-12-07 23:43:09 +00:00
2022-12-07 23:43:32 +00:00
return R.pipe(
R.keys(cumu),
R.sortBy((k) => cumu[k]),
R.first,
(k) => cumu[k]
);
};