1
0
mirror of https://github.com/chylex/Advent-of-Code.git synced 2025-05-31 18:34:07 +02:00

Add 2022 - Day 1 - Part 1

This commit is contained in:
chylex 2022-12-03 13:27:46 +01:00
parent 0fd3573077
commit fb795c2a38
Signed by: chylex
GPG Key ID: 4DE42C8F19A80548
5 changed files with 2305 additions and 0 deletions
2022
.idea/runConfigurations
01
utils
README.md

View File

@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Day 01" type="PythonConfigurationType" factoryName="Python">
<module name="2022" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/01" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/01/main.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>

2262
2022/01/input.txt Normal file

File diff suppressed because it is too large Load Diff

12
2022/01/main.py Normal file
View File

@ -0,0 +1,12 @@
from itertools import groupby
from utils.input import read_input
lines = read_input()
groups = [list(group) for is_group, group in groupby(lines, lambda x: x != '') if is_group]
carrying_calories = ((int(item) for item in group) for group in groups)
carrying_total_calories = (sum(group) for group in carrying_calories)
most_calories_carried = max(carrying_total_calories)
print(f"Most calories carried: {most_calories_carried}")

3
2022/utils/input.py Normal file
View File

@ -0,0 +1,3 @@
def read_input() -> list[str]:
with open("input.txt") as f:
return [line.strip() for line in f.readlines()]

View File

@ -55,3 +55,7 @@ The versions should not matter, but I used Visual Studio 2019 with `MSVC v142 (1
| | | | / | 2020 | 06 | Rust | / | 2021 | 06 | Kotlin |
| | | | / | 2020 | 07 | Rust | / | 2021 | 07 | Kotlin |
| | | | / | 2020 | 08 | Rust | / | 2021 | 08 | Kotlin |
| Year | Day | Language |
|-----:|----:|----------|
| 2022 | 01 | Python |