-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
old work on 2023, and added new solution for d02 of 2020 because why …
…be consistent.
- Loading branch information
Showing
4 changed files
with
192 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import re | ||
|
||
|
||
class FarmMaps: | ||
def __init__(self): | ||
self.s2s = [] | ||
self.s2f = [] | ||
self.f2w = [] | ||
self.w2l = [] | ||
self.l2t = [] | ||
self.t2h = [] | ||
self.h2l = [] | ||
|
||
|
||
class Seeds: | ||
def __init__(self): | ||
self.seeds = [] | ||
|
||
|
||
def parse_input(input_list): | ||
seeds = Seeds() | ||
my_farm = FarmMaps() | ||
|
||
map_type = None | ||
|
||
for line in input_list: | ||
s2s_map = line.strip().split(' ') | ||
if re.match(r'seeds: ', line): | ||
seeds.seeds = [int(seed) for seed in line.strip().split() if seed.isnumeric()] | ||
# elif line and re.match(r'\d+ \d+ \d+', line): | ||
# s2s_map = list(map(int, s2s_map)) | ||
|
||
if re.match(r'seed-to-soil map:', line): | ||
map_type = 'seed-to-soil map:' | ||
if re.match(r'soil-to-fertilizer map:', line): | ||
map_type = 'soil-to-fertilizer map:' | ||
if re.match(r'fertilizer-to-water map:', line): | ||
map_type = 'fertilizer-to-water map:' | ||
if re.match(r'water-to-light map:', line): | ||
map_type = 'water-to-light map:' | ||
if re.match(r'light-to-temperature map:', line): | ||
map_type = 'light-to-temperature map:' | ||
if re.match(r'temperature-to-humidity map:', line): | ||
map_type = 'temperature-to-humidity map:' | ||
if re.match(r'humidity-to-location map:', line): | ||
map_type = 'humidity-to-location map:' | ||
|
||
if line and re.match(r'\d+ \d+ \d+', line): | ||
s2s_map = list(map(int, s2s_map)) | ||
map_range = (s2s_map[1], s2s_map[0], s2s_map[1] + s2s_map[2], s2s_map[0] + s2s_map[2]) | ||
|
||
if map_type == 'seed-to-soil map:': | ||
my_farm.s2s.append(map_range) | ||
if map_type == 'soil-to-fertilizer map:': | ||
my_farm.s2f.append(map_range) | ||
if map_type == 'fertilizer-to-water map:': | ||
my_farm.f2w.append(map_range) | ||
if map_type == 'water-to-light map:': | ||
my_farm.w2l.append(map_range) | ||
if map_type == 'light-to-temperature map:': | ||
my_farm.l2t.append(map_range) | ||
if map_type == 'temperature-to-humidity map:': | ||
my_farm.t2h.append(map_range) | ||
if map_type == 'humidity-to-location map:': | ||
my_farm.h2l.append(map_range) | ||
|
||
return seeds, my_farm | ||
|
||
|
||
def part01(input_lines): | ||
(seeds, farm_map) = parse_input(input_lines) | ||
lowest_location = -1 | ||
for seed in seeds.seeds: | ||
for s2s in farm_map.s2s: | ||
if s2s[0] <= seed <= s2s[2]: | ||
soil = s2s[1] + (seed - s2s[0]) | ||
break | ||
soil = seed | ||
for s2f in farm_map.s2f: | ||
if s2f[0] <= soil <= s2f[2]: | ||
fertilizer = s2f[1] + (soil - s2f[0]) | ||
break | ||
fertilizer = soil | ||
for f2w in farm_map.f2w: | ||
if f2w[0] <= fertilizer <= f2w[2]: | ||
water = f2w[1] + (fertilizer - s2f[0]) | ||
break | ||
water = fertilizer | ||
for w2l in farm_map.w2l: | ||
if w2l[0] <= water <= w2l[2]: | ||
light = w2l[1] + (water - w2l[0]) | ||
break | ||
light = water | ||
for l2t in farm_map.l2t: | ||
if l2t[0] <= light <= l2t[2]: | ||
temperature = l2t[1] + (light - l2t[0]) | ||
break | ||
temperature = light | ||
for t2h in farm_map.t2h: | ||
if t2h[0] <= temperature <= t2h[2]: | ||
humidity = t2h[1] + (temperature - t2h[0]) | ||
break | ||
humidity = temperature | ||
for h2l in farm_map.h2l: | ||
if h2l[0] <= humidity <= h2l[2]: | ||
location = h2l[1] + (humidity - h2l[0]) | ||
break | ||
location = humidity | ||
|
||
if lowest_location == -1: | ||
lowest_location = location | ||
elif location < lowest_location: | ||
lowest_location = location | ||
|
||
print(lowest_location) | ||
|
||
|
||
def part02(input_lines): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import re | ||
|
||
|
||
def part01(speed_input): | ||
times = re.split(r'\s+', speed_input[0])[1:] | ||
distances = re.split(r'\s+', speed_input[1])[1:] | ||
|
||
for race in len(times): | ||
for poweruptime in (range(1, times[race])): | ||
time to travel = times[race] - poweruptime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
class Y2020D02: | ||
pwd_input = [] | ||
|
||
def __init__(self, input_list): | ||
for i in input_list: | ||
(rules, pwd) = i.split(":") | ||
(minmax, ltr) = rules.split(" ") | ||
(min_ltr, max_ltr) = minmax.split("-") | ||
|
||
self.pwd_input.append((int(min_ltr), int(max_ltr), ltr.strip(), pwd.strip(), i)) | ||
|
||
def day01(self): | ||
correct_passwords = 0 | ||
for potential_word in self.pwd_input: | ||
filtered_word_count = potential_word[3].count(potential_word[2]) | ||
if potential_word[0] <= filtered_word_count <= potential_word[1]: | ||
correct_passwords += 1 | ||
|
||
print(correct_passwords) | ||
|
||
def day02(self): | ||
correct_passwords = 0 | ||
pos1 = False | ||
pos2 = False | ||
for pword in self.pwd_input: | ||
if pword[3][pword[0]-1] == pword[2]: | ||
pos1 = True | ||
if pword[3][pword[1]-1] == pword[2]: | ||
pos2 = True | ||
if pos1 ^ pos2: | ||
correct_passwords += 1 | ||
print(pword[0], pword[1], "s:", pword[3][pword[0]-1], "e:", pword[3][pword[1]-1], "ltr:", pword[2], pword[3]) | ||
pos1 = False | ||
pos2 = False | ||
|
||
print(correct_passwords) |