Browse Source

Initial commit

master
Ben Ashton 1 year ago
commit
ef4a9f7182
  1. 2238
      1/input
  2. 28
      1/solution.mjs
  3. 2500
      2/input
  4. 34
      2/solution.mjs

2238
1/input

File diff suppressed because it is too large Load Diff

28
1/solution.mjs

@ -0,0 +1,28 @@
import { readFileSync } from 'node:fs';
const input = readFileSync('input', 'utf-8');
const elfCalories = input
.split(/\n{2,}/)
.filter(calories => calories)
.map(calories =>
calories
.split('\n')
.map(count => parseInt(count))
);
const totalElfCalories = elfCalories
.map(calories =>
calories.reduce((total, count) => total + count, 0)
);
totalElfCalories.sort((a, b) => a - b);
const mostCalories = totalElfCalories[totalElfCalories.length - 1];
console.log(`Elf with most calories has: ${mostCalories}`);
const topThreeCalories = totalElfCalories
.slice(-3)
.reduce((total, count) => total + count, 0);
console.log(`Top three calory count: ${topThreeCalories}`);

2500
2/input

File diff suppressed because it is too large Load Diff

34
2/solution.mjs

@ -0,0 +1,34 @@
import { readFileSync } from 'node:fs';
const input = readFileSync('input', 'utf-8');
const data = input
.split('\n')
.filter(line => line)
.map(line => {
const play = line.split(' ');
return [
['A', 'B', 'C'].indexOf(play[0]),
['X', 'Y', 'Z'].indexOf(play[1])
]
});
const scoreGame = plays =>
plays.map(([o, p]) =>
(p + 1) + // shape score
3 * (o == p) + // draw
6 * ((o + 1) % 3 == p) // win
);
const wrongScores = scoreGame(data);
const totalScore = wrongScores.reduce((t, s) => t + s, 0)
console.log(`Total Score: ${totalScore}`);
const actualPlays = data.map(([o, a]) => [
o,
(o + [2, 0, 1][a]) % 3
]);
const correctScores = scoreGame(actualPlays);
const correctTotalScore = correctScores.reduce((t, s) => t + s, 0)
console.log(`Correct Total Score: ${correctTotalScore}`);
Loading…
Cancel
Save