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}`);