Skip to content

Commit

Permalink
Add solution that works only on test input
Browse files Browse the repository at this point in the history
  • Loading branch information
mjalkio committed Dec 25, 2023
1 parent e582060 commit bd3135a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 11 additions & 2 deletions year_2023/day05/if_you_give_a_seed_a_fertilizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
Map = namedtuple("Map", ["dest_start", "source_start", "range_length"])


def get_lowest_location_number(puzzle_input):
def get_lowest_location_number(puzzle_input, use_ranges=False):
lines = puzzle_input.split("\n")
seeds = [int(seed) for seed in lines.pop(0).split(": ")[1].split(" ")]
if use_ranges:
new_seeds = []
while len(seeds) > 0:
start = seeds.pop(0)
num_values = seeds.pop(0)
for i in range(num_values):
new_seeds.append(start + i)
seeds = new_seeds

while len(lines) > 0:
lines = lines[2:]
maps = []
Expand All @@ -27,4 +36,4 @@ def get_lowest_location_number(puzzle_input):
puzzle_input = read_puzzle_input()

print(f"Part 1: {get_lowest_location_number(puzzle_input)}")
print(f"Part 2: {get_lowest_location_number(puzzle_input)}")
print(f"Part 2: {get_lowest_location_number(puzzle_input, use_ranges=True)}")
7 changes: 7 additions & 0 deletions year_2023/day05/test_if_you_give_a_seed_a_fertilizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@

def test_get_lowest_location_number():
assert get_lowest_location_number(read_puzzle_input("test_input.txt")) == 35


def test_get_lowest_location_number_part_2():
assert (
get_lowest_location_number(read_puzzle_input("test_input.txt"), use_ranges=True)
== 46
)

0 comments on commit bd3135a

Please sign in to comment.