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";
|
import { group, sum } from "../_utils";
|
||||||
|
|
||||||
const groupSnacksByElf = (lines: string[]) =>
|
const groupSnacksByElf = (lines: string[]): string[][] =>
|
||||||
group(lines, (_, line) => line === "", false);
|
group(lines, (_, line) => line === "", false);
|
||||||
|
|
||||||
const parseCaloriesToInts = (snacks: string[]) =>
|
const parseCaloriesToInts = (snacks: string[]): number[] =>
|
||||||
snacks.map((calorie) => parseInt(calorie));
|
snacks.map((calorie) => parseInt(calorie));
|
||||||
|
|
||||||
const sumCalories = (snacks: number[]): number => snacks.reduce(sum, 0);
|
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?
|
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;
|
const [first, second, third] = leaders;
|
||||||
|
|
||||||
if (calorieSum > first) {
|
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?
|
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 {
|
export function part1_solver(lines: string[]): number {
|
||||||
const score_map = {
|
const score_map = {
|
||||||
|
@ -63,12 +63,12 @@ export function part1_solver(lines: string[]): number {
|
||||||
return score;
|
return score;
|
||||||
};
|
};
|
||||||
|
|
||||||
return lines.filter(emptyLines).reduce((totalScore, match) => {
|
const toRoundScore = (line: string): number => {
|
||||||
const [opponent, player] = match.split(" ");
|
const [opponent, player] = line.split(" ");
|
||||||
const roundScore = scoreRound(opponent, player);
|
return scoreRound(opponent, player);
|
||||||
|
};
|
||||||
|
|
||||||
return (totalScore += roundScore);
|
return lines.filter(emptyLines).map(toRoundScore).reduce(sum, 0);
|
||||||
}, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -118,10 +118,10 @@ export function part2_solver(lines: string[]): number {
|
||||||
return score;
|
return score;
|
||||||
};
|
};
|
||||||
|
|
||||||
return lines.filter(emptyLines).reduce((totalScore, match) => {
|
const toRoundScore = (line: string): number => {
|
||||||
const [opponent, outcome] = match.split(" ");
|
const [opponent, outcome] = line.split(" ");
|
||||||
const roundScore = scoreRound(opponent, outcome);
|
return scoreRound(opponent, outcome);
|
||||||
|
};
|
||||||
|
|
||||||
return (totalScore += roundScore);
|
return lines.filter(emptyLines).map(toRoundScore).reduce(sum, 0);
|
||||||
}, 0);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue