smol improvements
This commit is contained in:
parent
583f200eac
commit
109f3d47c8
|
@ -45,10 +45,10 @@ Find the Elf carrying the most Calories. How many total Calories is that Elf car
|
|||
|
||||
import { group, sum } from "../_utils";
|
||||
|
||||
const groupSnacksByElf = (lines: string[]) =>
|
||||
const groupSnacksByElf = (lines: string[]): string[][] =>
|
||||
group(lines, (_, line) => line === "", false);
|
||||
|
||||
const parseCaloriesToInts = (snacks: string[]) =>
|
||||
const parseCaloriesToInts = (snacks: string[]): number[] =>
|
||||
snacks.map((calorie) => parseInt(calorie));
|
||||
|
||||
const sumCalories = (snacks: number[]): number => snacks.reduce(sum, 0);
|
||||
|
@ -74,7 +74,7 @@ In the example above, the top three Elves are the fourth Elf (with 24000 Calorie
|
|||
Find the top three Elves carrying the most Calories. How many Calories are those Elves carrying in total?
|
||||
*/
|
||||
|
||||
const findTopThreeElves = (leaders: number[], calorieSum: number) => {
|
||||
const findTopThreeElves = (leaders: number[], calorieSum: number): number[] => {
|
||||
const [first, second, third] = leaders;
|
||||
|
||||
if (calorieSum > first) {
|
||||
|
|
|
@ -30,7 +30,7 @@ In this example, if you were to follow the strategy guide, you would get a total
|
|||
What would your total score be if everything goes exactly according to your strategy guide?
|
||||
*/
|
||||
|
||||
import { emptyLines } from "../_utils";
|
||||
import { emptyLines, sum } from "../_utils";
|
||||
|
||||
export function part1_solver(lines: string[]): number {
|
||||
const score_map = {
|
||||
|
@ -63,12 +63,12 @@ export function part1_solver(lines: string[]): number {
|
|||
return score;
|
||||
};
|
||||
|
||||
return lines.filter(emptyLines).reduce((totalScore, match) => {
|
||||
const [opponent, player] = match.split(" ");
|
||||
const roundScore = scoreRound(opponent, player);
|
||||
const toRoundScore = (line: string): number => {
|
||||
const [opponent, player] = line.split(" ");
|
||||
return scoreRound(opponent, player);
|
||||
};
|
||||
|
||||
return (totalScore += roundScore);
|
||||
}, 0);
|
||||
return lines.filter(emptyLines).map(toRoundScore).reduce(sum, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -118,10 +118,10 @@ export function part2_solver(lines: string[]): number {
|
|||
return score;
|
||||
};
|
||||
|
||||
return lines.filter(emptyLines).reduce((totalScore, match) => {
|
||||
const [opponent, outcome] = match.split(" ");
|
||||
const roundScore = scoreRound(opponent, outcome);
|
||||
const toRoundScore = (line: string): number => {
|
||||
const [opponent, outcome] = line.split(" ");
|
||||
return scoreRound(opponent, outcome);
|
||||
};
|
||||
|
||||
return (totalScore += roundScore);
|
||||
}, 0);
|
||||
return lines.filter(emptyLines).map(toRoundScore).reduce(sum, 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue