Solve 2026-01
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { groupBy, multBy } from '../../utils/array.ts';
|
||||
|
||||
export function solveFirst(input: string): number {
|
||||
const numbers = groupBy(input.split('\n').map(Number), (n) => n).toSorted(
|
||||
(a, b) => b.elements.length - a.elements.length
|
||||
);
|
||||
|
||||
const top3 = numbers.slice(0, 3);
|
||||
|
||||
return multBy(top3, (e) => e.key);
|
||||
}
|
||||
|
||||
export function solveSecond(input: string): number {
|
||||
const numbers = groupBy(input.split('\n').map(Number), (n) => n).toSorted(
|
||||
(a, b) => a.elements.length - b.elements.length
|
||||
);
|
||||
|
||||
const top3 = numbers.slice(0, 3);
|
||||
|
||||
return multBy(top3, (e) => e.key);
|
||||
}
|
||||
Reference in New Issue
Block a user