Skip to content

Commit b969cba

Browse files
committed
2022/01
1 parent 96fac28 commit b969cba

File tree

10 files changed

+2444
-4
lines changed

10 files changed

+2444
-4
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"preLaunchTask": "build",
1313
// If you have changed target frameworks, make sure to update the program path.
1414
"program": "${workspaceFolder}/bin/Debug/net7.0/adventofcode.dll",
15-
"args": ["2021/24"],
15+
"args": ["today"],
1616
"cwd": "${workspaceFolder}",
1717
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
1818
"console": "internalConsole",

2022/Day01/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
original source: [https://adventofcode.com/2022/day/1](https://adventofcode.com/2022/day/1)
2+
## --- Day 1: Calorie Counting ---
3+
Santa's reindeer typically eat regular reindeer food, but they need a lot of [magical energy](/2018/day/25) to deliver presents on Christmas. For that, their favorite snack is a special type of <em>star</em> fruit that only grows deep in the jungle. The Elves have brought you on their annual expedition to the grove where the fruit grows.
4+
5+
To supply enough magical energy, the expedition needs to retrieve a minimum of <em>fifty stars</em> by December 25th. Although the Elves assure you that the grove has plenty of fruit, you decide to grab any fruit you see along the way, just in case.
6+
7+
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants <em>one star</em>. Good luck!
8+
9+
The jungle must be too overgrown and difficult to navigate in vehicles or access from the air; the Elves' expedition traditionally goes on foot. As your boats approach land, the Elves begin taking inventory of their supplies. One important consideration is food - in particular, the number of <em>Calories</em> each Elf is carrying (your puzzle input).
10+
11+
The Elves take turns writing down the number of Calories contained by the various meals, snacks, rations, etc. that they've brought with them, one item per line. Each Elf separates their own inventory from the previous Elf's inventory (if any) by a blank line.
12+
13+
For example, suppose the Elves finish writing their items' Calories and end up with the following list:
14+
15+
<pre>
16+
<code>1000
17+
2000
18+
3000
19+
20+
4000
21+
22+
5000
23+
6000
24+
25+
7000
26+
8000
27+
9000
28+
29+
10000
30+
</code>
31+
</pre>
32+
33+
This list represents the Calories of the food carried by five Elves:
34+
35+
36+
- The first Elf is carrying food with <code>1000</code>, <code>2000</code>, and <code>3000</code> Calories, a total of <code><em>6000</em></code> Calories.
37+
- The second Elf is carrying one food item with <code><em>4000</em></code> Calories.
38+
- The third Elf is carrying food with <code>5000</code> and <code>6000</code> Calories, a total of <code><em>11000</em></code> Calories.
39+
- The fourth Elf is carrying food with <code>7000</code>, <code>8000</code>, and <code>9000</code> Calories, a total of <code><em>24000</em></code> Calories.
40+
- The fifth Elf is carrying one food item with <code><em>10000</em></code> Calories.
41+
42+
In case the Elves get hungry and need extra snacks, they need to know which Elf to ask: they'd like to know how many Calories are being carried by the Elf carrying the <em>most</em> Calories. In the example above, this is <em><code>24000</code></em> (carried by the fourth Elf).
43+
44+
Find the Elf carrying the most Calories. <em>How many total Calories is that Elf carrying?</em>
45+
46+
47+
## --- Part Two ---
48+
By the time you calculate the answer to the Elves' question, they've already realized that the Elf carrying the most Calories of food might eventually <em>run out of snacks</em>.
49+
50+
To avoid this unacceptable situation, the Elves would instead like to know the total Calories carried by the <em>top three</em> Elves carrying the most Calories. That way, even if one of those Elves runs out of snacks, they still have two backups.
51+
52+
In the example above, the top three Elves are the fourth Elf (with <code>24000</code> Calories), then the third Elf (with <code>11000</code> Calories), then the fifth Elf (with <code>10000</code> Calories). The sum of the Calories carried by these three elves is <code><em>45000</em></code>.
53+
54+
Find the top three Elves carrying the most Calories. <em>How many Calories are those Elves carrying in total?</em>
55+
56+

2022/Day01/Solution.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
4+
namespace AdventOfCode.Y2022.Day01;
5+
6+
[ProblemName("Calorie Counting")]
7+
class Solution : Solver {
8+
9+
public object PartOne(string input) =>
10+
GetCaloriesPerElf(input).First();
11+
12+
public object PartTwo(string input) =>
13+
GetCaloriesPerElf(input).Take(3).Sum();
14+
15+
private IEnumerable<int> GetCaloriesPerElf(string input) =>
16+
from elf in input.Split("\n\n")
17+
let calories = elf.Split('\n').Select(int.Parse).Sum()
18+
orderby calories descending
19+
select calories;
20+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy