mirror of
https://github.com/chylex/Advent-of-Code.git
synced 2024-11-25 14:42:48 +01:00
Compare commits
3 Commits
c2b2da271b
...
94bfc58598
Author | SHA1 | Date | |
---|---|---|---|
94bfc58598 | |||
ca7b829db3 | |||
4304efd023 |
24
2022/.idea/runConfigurations/Day_04.xml
Normal file
24
2022/.idea/runConfigurations/Day_04.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Day 04" 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$/04" />
|
||||
<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$/04/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>
|
24
2022/.idea/runConfigurations/Day_05.xml
Normal file
24
2022/.idea/runConfigurations/Day_05.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Day 05" 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$/05" />
|
||||
<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$/05/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>
|
1000
2022/04/input.txt
Normal file
1000
2022/04/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
51
2022/04/main.py
Normal file
51
2022/04/main.py
Normal file
@ -0,0 +1,51 @@
|
||||
from utils.input import read_input_lines
|
||||
|
||||
|
||||
class Assignment:
|
||||
def __init__(self, first_section: int, last_section: int):
|
||||
self.first_section = first_section
|
||||
self.last_section = last_section
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{self.first_section}-{self.last_section}"
|
||||
|
||||
def contains(self, other: "Assignment") -> bool:
|
||||
return self.first_section <= other.first_section and self.last_section >= other.last_section
|
||||
|
||||
def overlaps(self, other: "Assignment") -> bool:
|
||||
return self.first_section in range(other.first_section, other.last_section + 1) or self.last_section in range(other.first_section, other.last_section + 1)
|
||||
|
||||
@staticmethod
|
||||
def from_str(line: str) -> "Assignment":
|
||||
(first_section, last_section) = line.split("-", maxsplit = 1)
|
||||
return Assignment(int(first_section), int(last_section))
|
||||
|
||||
|
||||
class Pair:
|
||||
def __init__(self, first: Assignment, second: Assignment):
|
||||
self.first = first
|
||||
self.second = second
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{self.first}, {self.second}"
|
||||
|
||||
def has_full_overlap(self) -> bool:
|
||||
return self.first.contains(self.second) or self.second.contains(self.first)
|
||||
|
||||
def has_any_overlap(self) -> bool:
|
||||
return self.first.overlaps(self.second) or self.second.overlaps(self.first)
|
||||
|
||||
@staticmethod
|
||||
def from_line(line: str) -> "Pair":
|
||||
(first, second) = line.split(",", maxsplit = 1)
|
||||
return Pair(Assignment.from_str(first), Assignment.from_str(second))
|
||||
|
||||
|
||||
lines = read_input_lines()
|
||||
pairs = list(map(lambda line: Pair.from_line(line), lines))
|
||||
|
||||
assignments_with_full_overlap = sum(1 for pair in pairs if pair.has_full_overlap())
|
||||
print(f"Amount of assignments with full overlap: {assignments_with_full_overlap}")
|
||||
|
||||
assignments_with_any_overlap = sum(1 for pair in pairs if pair.has_any_overlap())
|
||||
print(f"Amount of assignments with any overlap: {assignments_with_any_overlap}")
|
512
2022/05/input.txt
Normal file
512
2022/05/input.txt
Normal file
@ -0,0 +1,512 @@
|
||||
[H] [D] [P]
|
||||
[W] [B] [C] [Z] [D]
|
||||
[T] [J] [T] [J] [D] [J]
|
||||
[H] [Z] [H] [H] [W] [S] [M]
|
||||
[P] [F] [R] [P] [Z] [F] [W] [F]
|
||||
[J] [V] [T] [N] [F] [G] [Z] [S] [S]
|
||||
[C] [R] [P] [S] [V] [M] [V] [D] [Z]
|
||||
[F] [G] [H] [Z] [N] [P] [M] [N] [D]
|
||||
1 2 3 4 5 6 7 8 9
|
||||
|
||||
move 2 from 8 to 2
|
||||
move 3 from 9 to 2
|
||||
move 1 from 3 to 8
|
||||
move 5 from 1 to 7
|
||||
move 2 from 9 to 2
|
||||
move 8 from 2 to 4
|
||||
move 6 from 7 to 2
|
||||
move 2 from 1 to 7
|
||||
move 4 from 5 to 9
|
||||
move 4 from 5 to 6
|
||||
move 1 from 8 to 3
|
||||
move 1 from 8 to 5
|
||||
move 2 from 9 to 8
|
||||
move 8 from 6 to 4
|
||||
move 4 from 3 to 6
|
||||
move 10 from 2 to 3
|
||||
move 1 from 5 to 1
|
||||
move 1 from 7 to 4
|
||||
move 2 from 9 to 8
|
||||
move 18 from 4 to 8
|
||||
move 1 from 1 to 6
|
||||
move 4 from 7 to 3
|
||||
move 12 from 8 to 4
|
||||
move 4 from 7 to 9
|
||||
move 5 from 6 to 9
|
||||
move 2 from 2 to 7
|
||||
move 3 from 9 to 5
|
||||
move 3 from 5 to 9
|
||||
move 1 from 2 to 8
|
||||
move 10 from 3 to 1
|
||||
move 2 from 7 to 8
|
||||
move 10 from 1 to 9
|
||||
move 1 from 3 to 5
|
||||
move 16 from 9 to 8
|
||||
move 1 from 3 to 2
|
||||
move 3 from 8 to 3
|
||||
move 1 from 5 to 9
|
||||
move 3 from 6 to 7
|
||||
move 2 from 7 to 2
|
||||
move 1 from 3 to 8
|
||||
move 5 from 4 to 1
|
||||
move 4 from 9 to 5
|
||||
move 2 from 2 to 5
|
||||
move 2 from 1 to 9
|
||||
move 23 from 8 to 4
|
||||
move 6 from 5 to 2
|
||||
move 5 from 2 to 6
|
||||
move 1 from 9 to 6
|
||||
move 2 from 2 to 4
|
||||
move 35 from 4 to 9
|
||||
move 1 from 6 to 1
|
||||
move 2 from 8 to 7
|
||||
move 1 from 6 to 8
|
||||
move 3 from 1 to 7
|
||||
move 1 from 7 to 1
|
||||
move 3 from 6 to 2
|
||||
move 4 from 3 to 7
|
||||
move 6 from 7 to 9
|
||||
move 1 from 6 to 9
|
||||
move 1 from 8 to 1
|
||||
move 2 from 2 to 9
|
||||
move 2 from 8 to 2
|
||||
move 3 from 7 to 3
|
||||
move 2 from 1 to 9
|
||||
move 5 from 9 to 3
|
||||
move 1 from 4 to 2
|
||||
move 1 from 1 to 4
|
||||
move 7 from 3 to 9
|
||||
move 1 from 3 to 4
|
||||
move 2 from 4 to 7
|
||||
move 24 from 9 to 4
|
||||
move 12 from 9 to 3
|
||||
move 1 from 3 to 1
|
||||
move 1 from 1 to 2
|
||||
move 2 from 2 to 6
|
||||
move 1 from 6 to 5
|
||||
move 1 from 6 to 8
|
||||
move 3 from 2 to 4
|
||||
move 1 from 7 to 4
|
||||
move 1 from 5 to 3
|
||||
move 1 from 9 to 8
|
||||
move 23 from 4 to 8
|
||||
move 17 from 8 to 5
|
||||
move 12 from 9 to 8
|
||||
move 10 from 8 to 7
|
||||
move 1 from 8 to 6
|
||||
move 5 from 4 to 3
|
||||
move 3 from 5 to 1
|
||||
move 3 from 1 to 6
|
||||
move 6 from 5 to 4
|
||||
move 10 from 3 to 1
|
||||
move 9 from 1 to 7
|
||||
move 2 from 4 to 9
|
||||
move 1 from 1 to 6
|
||||
move 4 from 8 to 1
|
||||
move 4 from 3 to 7
|
||||
move 4 from 6 to 5
|
||||
move 1 from 9 to 6
|
||||
move 1 from 9 to 2
|
||||
move 1 from 1 to 7
|
||||
move 1 from 2 to 7
|
||||
move 3 from 1 to 7
|
||||
move 9 from 5 to 9
|
||||
move 7 from 9 to 7
|
||||
move 2 from 9 to 1
|
||||
move 3 from 5 to 9
|
||||
move 3 from 4 to 8
|
||||
move 1 from 1 to 2
|
||||
move 1 from 2 to 6
|
||||
move 1 from 1 to 6
|
||||
move 5 from 8 to 7
|
||||
move 1 from 8 to 1
|
||||
move 1 from 3 to 9
|
||||
move 1 from 1 to 6
|
||||
move 2 from 9 to 5
|
||||
move 2 from 3 to 9
|
||||
move 4 from 6 to 3
|
||||
move 1 from 9 to 4
|
||||
move 2 from 4 to 8
|
||||
move 1 from 4 to 8
|
||||
move 1 from 9 to 5
|
||||
move 1 from 6 to 8
|
||||
move 23 from 7 to 8
|
||||
move 27 from 8 to 2
|
||||
move 2 from 8 to 1
|
||||
move 23 from 2 to 6
|
||||
move 3 from 5 to 3
|
||||
move 4 from 2 to 5
|
||||
move 2 from 3 to 1
|
||||
move 2 from 9 to 3
|
||||
move 4 from 1 to 4
|
||||
move 13 from 7 to 9
|
||||
move 1 from 5 to 6
|
||||
move 2 from 5 to 9
|
||||
move 1 from 5 to 3
|
||||
move 3 from 9 to 3
|
||||
move 5 from 9 to 5
|
||||
move 2 from 4 to 2
|
||||
move 1 from 4 to 9
|
||||
move 11 from 6 to 9
|
||||
move 9 from 6 to 1
|
||||
move 17 from 9 to 5
|
||||
move 3 from 7 to 4
|
||||
move 3 from 6 to 3
|
||||
move 14 from 5 to 2
|
||||
move 5 from 3 to 1
|
||||
move 2 from 9 to 4
|
||||
move 2 from 3 to 8
|
||||
move 5 from 5 to 9
|
||||
move 2 from 5 to 4
|
||||
move 7 from 1 to 8
|
||||
move 2 from 9 to 5
|
||||
move 3 from 9 to 8
|
||||
move 8 from 4 to 2
|
||||
move 2 from 7 to 8
|
||||
move 10 from 2 to 9
|
||||
move 10 from 2 to 6
|
||||
move 8 from 9 to 7
|
||||
move 2 from 3 to 9
|
||||
move 3 from 9 to 8
|
||||
move 5 from 3 to 9
|
||||
move 7 from 7 to 9
|
||||
move 3 from 2 to 9
|
||||
move 10 from 8 to 5
|
||||
move 1 from 7 to 6
|
||||
move 1 from 2 to 3
|
||||
move 4 from 1 to 6
|
||||
move 2 from 8 to 4
|
||||
move 1 from 4 to 6
|
||||
move 2 from 6 to 3
|
||||
move 2 from 3 to 1
|
||||
move 1 from 4 to 9
|
||||
move 4 from 1 to 5
|
||||
move 2 from 5 to 2
|
||||
move 2 from 8 to 4
|
||||
move 1 from 3 to 5
|
||||
move 3 from 5 to 7
|
||||
move 2 from 2 to 9
|
||||
move 3 from 7 to 6
|
||||
move 3 from 8 to 5
|
||||
move 10 from 5 to 7
|
||||
move 3 from 6 to 4
|
||||
move 11 from 6 to 1
|
||||
move 3 from 6 to 2
|
||||
move 12 from 1 to 3
|
||||
move 1 from 7 to 5
|
||||
move 9 from 7 to 3
|
||||
move 5 from 5 to 1
|
||||
move 4 from 4 to 6
|
||||
move 2 from 1 to 7
|
||||
move 1 from 2 to 6
|
||||
move 2 from 7 to 8
|
||||
move 1 from 2 to 4
|
||||
move 1 from 9 to 5
|
||||
move 3 from 6 to 7
|
||||
move 1 from 5 to 2
|
||||
move 9 from 9 to 5
|
||||
move 1 from 2 to 8
|
||||
move 1 from 4 to 8
|
||||
move 1 from 1 to 8
|
||||
move 1 from 4 to 2
|
||||
move 1 from 7 to 2
|
||||
move 1 from 6 to 2
|
||||
move 1 from 6 to 8
|
||||
move 6 from 9 to 6
|
||||
move 1 from 3 to 4
|
||||
move 9 from 3 to 5
|
||||
move 1 from 1 to 3
|
||||
move 2 from 2 to 6
|
||||
move 1 from 3 to 5
|
||||
move 14 from 5 to 1
|
||||
move 1 from 2 to 6
|
||||
move 5 from 6 to 4
|
||||
move 3 from 8 to 2
|
||||
move 5 from 6 to 1
|
||||
move 5 from 4 to 6
|
||||
move 1 from 7 to 1
|
||||
move 3 from 9 to 3
|
||||
move 7 from 5 to 7
|
||||
move 1 from 4 to 6
|
||||
move 2 from 7 to 5
|
||||
move 3 from 6 to 1
|
||||
move 3 from 8 to 1
|
||||
move 14 from 3 to 4
|
||||
move 8 from 4 to 2
|
||||
move 1 from 6 to 1
|
||||
move 15 from 1 to 6
|
||||
move 7 from 1 to 6
|
||||
move 6 from 1 to 3
|
||||
move 3 from 3 to 1
|
||||
move 2 from 4 to 5
|
||||
move 1 from 4 to 2
|
||||
move 19 from 6 to 8
|
||||
move 2 from 1 to 8
|
||||
move 4 from 5 to 4
|
||||
move 7 from 8 to 2
|
||||
move 2 from 3 to 1
|
||||
move 13 from 8 to 6
|
||||
move 4 from 4 to 9
|
||||
move 2 from 4 to 8
|
||||
move 2 from 1 to 6
|
||||
move 1 from 3 to 5
|
||||
move 19 from 2 to 3
|
||||
move 13 from 3 to 1
|
||||
move 1 from 4 to 9
|
||||
move 1 from 2 to 8
|
||||
move 3 from 7 to 1
|
||||
move 14 from 6 to 9
|
||||
move 2 from 6 to 4
|
||||
move 18 from 9 to 4
|
||||
move 3 from 7 to 2
|
||||
move 15 from 1 to 4
|
||||
move 2 from 1 to 8
|
||||
move 5 from 3 to 1
|
||||
move 1 from 3 to 6
|
||||
move 5 from 8 to 9
|
||||
move 3 from 9 to 5
|
||||
move 1 from 9 to 5
|
||||
move 1 from 8 to 9
|
||||
move 1 from 6 to 2
|
||||
move 3 from 9 to 4
|
||||
move 2 from 6 to 7
|
||||
move 30 from 4 to 6
|
||||
move 22 from 6 to 9
|
||||
move 6 from 9 to 4
|
||||
move 4 from 6 to 7
|
||||
move 1 from 1 to 6
|
||||
move 1 from 9 to 8
|
||||
move 1 from 7 to 6
|
||||
move 3 from 5 to 3
|
||||
move 5 from 6 to 5
|
||||
move 2 from 7 to 9
|
||||
move 4 from 1 to 5
|
||||
move 1 from 6 to 4
|
||||
move 1 from 8 to 7
|
||||
move 2 from 6 to 4
|
||||
move 17 from 9 to 8
|
||||
move 2 from 2 to 7
|
||||
move 2 from 3 to 1
|
||||
move 8 from 4 to 8
|
||||
move 1 from 3 to 8
|
||||
move 8 from 4 to 2
|
||||
move 2 from 1 to 2
|
||||
move 1 from 4 to 6
|
||||
move 4 from 7 to 1
|
||||
move 1 from 6 to 8
|
||||
move 19 from 8 to 3
|
||||
move 5 from 5 to 1
|
||||
move 5 from 5 to 9
|
||||
move 2 from 9 to 3
|
||||
move 6 from 1 to 9
|
||||
move 1 from 7 to 5
|
||||
move 1 from 7 to 4
|
||||
move 2 from 5 to 7
|
||||
move 2 from 2 to 4
|
||||
move 4 from 9 to 8
|
||||
move 12 from 8 to 7
|
||||
move 2 from 1 to 9
|
||||
move 1 from 7 to 4
|
||||
move 4 from 4 to 5
|
||||
move 3 from 9 to 3
|
||||
move 9 from 2 to 6
|
||||
move 2 from 7 to 5
|
||||
move 1 from 1 to 9
|
||||
move 5 from 9 to 7
|
||||
move 9 from 6 to 2
|
||||
move 6 from 2 to 8
|
||||
move 21 from 3 to 2
|
||||
move 12 from 2 to 9
|
||||
move 3 from 5 to 9
|
||||
move 3 from 3 to 8
|
||||
move 5 from 9 to 6
|
||||
move 13 from 2 to 3
|
||||
move 3 from 6 to 2
|
||||
move 10 from 9 to 8
|
||||
move 6 from 3 to 1
|
||||
move 3 from 2 to 9
|
||||
move 2 from 6 to 7
|
||||
move 5 from 3 to 9
|
||||
move 4 from 1 to 9
|
||||
move 3 from 8 to 5
|
||||
move 1 from 1 to 7
|
||||
move 6 from 5 to 7
|
||||
move 12 from 9 to 7
|
||||
move 1 from 1 to 8
|
||||
move 11 from 8 to 5
|
||||
move 9 from 5 to 7
|
||||
move 1 from 3 to 1
|
||||
move 4 from 8 to 7
|
||||
move 1 from 1 to 7
|
||||
move 2 from 8 to 3
|
||||
move 42 from 7 to 4
|
||||
move 3 from 7 to 9
|
||||
move 4 from 7 to 5
|
||||
move 1 from 7 to 8
|
||||
move 1 from 8 to 5
|
||||
move 1 from 7 to 5
|
||||
move 1 from 3 to 4
|
||||
move 1 from 3 to 9
|
||||
move 1 from 9 to 6
|
||||
move 1 from 6 to 4
|
||||
move 1 from 3 to 5
|
||||
move 3 from 9 to 2
|
||||
move 16 from 4 to 8
|
||||
move 3 from 2 to 4
|
||||
move 1 from 5 to 4
|
||||
move 30 from 4 to 6
|
||||
move 15 from 8 to 3
|
||||
move 2 from 4 to 5
|
||||
move 1 from 8 to 7
|
||||
move 13 from 3 to 6
|
||||
move 1 from 7 to 8
|
||||
move 1 from 3 to 8
|
||||
move 1 from 3 to 8
|
||||
move 4 from 5 to 2
|
||||
move 6 from 5 to 2
|
||||
move 2 from 8 to 6
|
||||
move 43 from 6 to 2
|
||||
move 1 from 6 to 1
|
||||
move 18 from 2 to 4
|
||||
move 24 from 2 to 6
|
||||
move 19 from 6 to 3
|
||||
move 4 from 6 to 3
|
||||
move 2 from 6 to 3
|
||||
move 3 from 3 to 2
|
||||
move 1 from 1 to 3
|
||||
move 23 from 3 to 6
|
||||
move 12 from 4 to 3
|
||||
move 7 from 3 to 9
|
||||
move 13 from 2 to 9
|
||||
move 1 from 8 to 4
|
||||
move 4 from 3 to 8
|
||||
move 6 from 4 to 2
|
||||
move 10 from 9 to 3
|
||||
move 6 from 2 to 9
|
||||
move 8 from 3 to 5
|
||||
move 3 from 5 to 3
|
||||
move 13 from 6 to 5
|
||||
move 4 from 3 to 9
|
||||
move 1 from 4 to 2
|
||||
move 4 from 8 to 3
|
||||
move 1 from 2 to 5
|
||||
move 14 from 9 to 5
|
||||
move 2 from 5 to 4
|
||||
move 2 from 4 to 3
|
||||
move 1 from 9 to 5
|
||||
move 4 from 6 to 1
|
||||
move 1 from 6 to 2
|
||||
move 6 from 3 to 2
|
||||
move 5 from 6 to 8
|
||||
move 2 from 3 to 7
|
||||
move 1 from 8 to 1
|
||||
move 25 from 5 to 7
|
||||
move 3 from 7 to 9
|
||||
move 5 from 2 to 9
|
||||
move 12 from 9 to 8
|
||||
move 3 from 1 to 6
|
||||
move 16 from 8 to 2
|
||||
move 1 from 9 to 2
|
||||
move 1 from 6 to 2
|
||||
move 1 from 1 to 3
|
||||
move 21 from 7 to 3
|
||||
move 2 from 7 to 1
|
||||
move 1 from 7 to 8
|
||||
move 2 from 2 to 1
|
||||
move 2 from 6 to 3
|
||||
move 18 from 2 to 9
|
||||
move 2 from 5 to 1
|
||||
move 1 from 2 to 1
|
||||
move 3 from 5 to 2
|
||||
move 13 from 9 to 1
|
||||
move 3 from 9 to 2
|
||||
move 1 from 8 to 7
|
||||
move 3 from 2 to 6
|
||||
move 2 from 5 to 1
|
||||
move 17 from 3 to 8
|
||||
move 3 from 3 to 8
|
||||
move 2 from 9 to 1
|
||||
move 1 from 7 to 5
|
||||
move 1 from 5 to 3
|
||||
move 2 from 6 to 4
|
||||
move 1 from 6 to 1
|
||||
move 15 from 8 to 2
|
||||
move 2 from 3 to 6
|
||||
move 1 from 8 to 5
|
||||
move 2 from 6 to 8
|
||||
move 13 from 2 to 9
|
||||
move 4 from 9 to 8
|
||||
move 9 from 8 to 9
|
||||
move 3 from 3 to 4
|
||||
move 4 from 9 to 7
|
||||
move 1 from 8 to 6
|
||||
move 1 from 7 to 5
|
||||
move 2 from 5 to 1
|
||||
move 1 from 6 to 3
|
||||
move 4 from 4 to 5
|
||||
move 1 from 4 to 6
|
||||
move 1 from 3 to 7
|
||||
move 1 from 5 to 6
|
||||
move 2 from 7 to 2
|
||||
move 4 from 2 to 3
|
||||
move 3 from 2 to 7
|
||||
move 1 from 3 to 6
|
||||
move 1 from 9 to 6
|
||||
move 2 from 5 to 2
|
||||
move 3 from 9 to 5
|
||||
move 1 from 6 to 1
|
||||
move 3 from 5 to 4
|
||||
move 12 from 1 to 2
|
||||
move 2 from 2 to 4
|
||||
move 2 from 7 to 8
|
||||
move 2 from 3 to 9
|
||||
move 1 from 4 to 7
|
||||
move 1 from 5 to 2
|
||||
move 1 from 8 to 3
|
||||
move 2 from 3 to 6
|
||||
move 7 from 2 to 8
|
||||
move 3 from 4 to 1
|
||||
move 7 from 8 to 5
|
||||
move 7 from 9 to 2
|
||||
move 1 from 4 to 5
|
||||
move 3 from 7 to 6
|
||||
move 5 from 6 to 9
|
||||
move 6 from 9 to 5
|
||||
move 4 from 9 to 6
|
||||
move 1 from 8 to 5
|
||||
move 1 from 7 to 4
|
||||
move 1 from 4 to 2
|
||||
move 2 from 2 to 9
|
||||
move 2 from 9 to 2
|
||||
move 11 from 5 to 3
|
||||
move 2 from 5 to 2
|
||||
move 1 from 2 to 9
|
||||
move 4 from 6 to 9
|
||||
move 1 from 2 to 9
|
||||
move 4 from 3 to 7
|
||||
move 3 from 6 to 4
|
||||
move 1 from 5 to 7
|
||||
move 18 from 1 to 3
|
||||
move 11 from 3 to 2
|
||||
move 1 from 7 to 9
|
||||
move 1 from 5 to 9
|
||||
move 14 from 3 to 6
|
||||
move 15 from 2 to 4
|
||||
move 5 from 2 to 5
|
||||
move 1 from 2 to 5
|
||||
move 1 from 1 to 9
|
||||
move 8 from 4 to 1
|
||||
move 5 from 5 to 9
|
||||
move 9 from 4 to 9
|
||||
move 4 from 7 to 4
|
||||
move 5 from 4 to 8
|
||||
move 2 from 9 to 6
|
||||
move 8 from 1 to 8
|
||||
move 1 from 5 to 3
|
||||
move 1 from 3 to 4
|
||||
move 1 from 1 to 8
|
||||
move 13 from 6 to 3
|
||||
move 9 from 9 to 5
|
||||
move 1 from 2 to 8
|
||||
move 8 from 5 to 1
|
||||
move 1 from 2 to 7
|
37
2022/05/main.py
Normal file
37
2022/05/main.py
Normal file
@ -0,0 +1,37 @@
|
||||
import itertools
|
||||
import re
|
||||
|
||||
from utils.input import read_input_lines
|
||||
|
||||
lines = iter(read_input_lines())
|
||||
initial_stack_configuration_lines = list(itertools.takewhile(lambda line: len(line) > 0, lines))[:-1]
|
||||
|
||||
stacks = list()
|
||||
|
||||
for line in reversed(initial_stack_configuration_lines):
|
||||
for stack_index, character_index in enumerate(range(1, len(line), 4)):
|
||||
crate = line[character_index]
|
||||
|
||||
if crate == " ":
|
||||
continue
|
||||
|
||||
for i in range(len(stacks), stack_index + 1):
|
||||
stacks.append(list())
|
||||
|
||||
stacks[stack_index].append(crate)
|
||||
|
||||
for instruction in lines:
|
||||
parsed = re.search(r"move (\d+) from (\d+) to (\d+)", instruction)
|
||||
|
||||
moved_count = int(parsed.group(1))
|
||||
from_column = int(parsed.group(2)) - 1
|
||||
to_column = int(parsed.group(3)) - 1
|
||||
|
||||
for i in range(moved_count):
|
||||
moved_crate = stacks[from_column].pop()
|
||||
stacks[to_column].append(moved_crate)
|
||||
|
||||
print("Top of each stack: ", end = "")
|
||||
|
||||
for stack in stacks:
|
||||
print(stack[-1], end = "")
|
@ -1,3 +1,3 @@
|
||||
def read_input_lines() -> list[str]:
|
||||
with open("input.txt") as f:
|
||||
return [line.strip() for line in f.readlines()]
|
||||
return [line.rstrip() for line in f.readlines()]
|
||||
|
@ -83,8 +83,8 @@ The versions should not matter, but I used Visual Studio 2019 with `MSVC v142 (1
|
||||
| 2021 | 01 | Kotlin | / | 2022 | 01 | Python |
|
||||
| 2021 | 02 | Kotlin | / | 2022 | 02 | Python |
|
||||
| 2021 | 03 | Kotlin | / | 2022 | 03 | Python |
|
||||
| 2021 | 04 | Kotlin | / | | | |
|
||||
| 2021 | 05 | Kotlin | / | | | |
|
||||
| 2021 | 04 | Kotlin | / | 2022 | 04 | Python |
|
||||
| 2021 | 05 | Kotlin | / | 2022 | 05 | Python |
|
||||
| 2021 | 06 | Kotlin | / | | | |
|
||||
| 2021 | 07 | Kotlin | / | | | |
|
||||
| 2021 | 08 | Kotlin | / | | | |
|
||||
|
Loading…
Reference in New Issue
Block a user