05-2 fertig
This commit is contained in:
113
05/05-2_only-example.py
Normal file
113
05/05-2_only-example.py
Normal file
@@ -0,0 +1,113 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
seeds = [] # 0
|
||||
seed_to_soil = [] # 1
|
||||
soil_to_fertilizer = [] # 2
|
||||
fertilizer_to_water = [] # 3
|
||||
water_to_light = [] # 4
|
||||
light_to_temperature = [] # 5
|
||||
temperature_to_humidity = [] # 6
|
||||
humidity_to_location = [] # 7
|
||||
|
||||
list_number = 0
|
||||
|
||||
|
||||
def find_dest(num, map_list):
|
||||
for m in map_list:
|
||||
if m[1] <= num < m[1] + m[2]:
|
||||
return num-m[1]+m[0]
|
||||
return num
|
||||
|
||||
|
||||
# parse input
|
||||
input_file = open("input-ex", "r")
|
||||
for line in input_file:
|
||||
line = line.strip()
|
||||
if line == "":
|
||||
continue
|
||||
if line.startswith('seeds: '):
|
||||
seed_list = [int(x) for x in line.replace('seeds: ', '').split()]
|
||||
for i in range(0, len(seed_list), 2):
|
||||
for j in range(seed_list[i], seed_list[i] + seed_list[i + 1]):
|
||||
seeds.append(j)
|
||||
if line == "seed-to-soil map:":
|
||||
list_number = 1
|
||||
continue
|
||||
if line == "soil-to-fertilizer map:":
|
||||
list_number = 2
|
||||
continue
|
||||
if line == "fertilizer-to-water map:":
|
||||
list_number = 3
|
||||
continue
|
||||
if line == "water-to-light map:":
|
||||
list_number = 4
|
||||
continue
|
||||
if line == "light-to-temperature map:":
|
||||
list_number = 5
|
||||
continue
|
||||
if line == "temperature-to-humidity map:":
|
||||
list_number = 6
|
||||
continue
|
||||
if line == "humidity-to-location map:":
|
||||
list_number = 7
|
||||
continue
|
||||
if list_number == 1:
|
||||
seed_to_soil.append([int(x) for x in line.split()])
|
||||
elif list_number == 2:
|
||||
soil_to_fertilizer.append([int(x) for x in line.split()])
|
||||
elif list_number == 3:
|
||||
fertilizer_to_water.append([int(x) for x in line.split()])
|
||||
elif list_number == 4:
|
||||
water_to_light.append([int(x) for x in line.split()])
|
||||
elif list_number == 5:
|
||||
light_to_temperature.append([int(x) for x in line.split()])
|
||||
elif list_number == 6:
|
||||
temperature_to_humidity.append([int(x) for x in line.split()])
|
||||
elif list_number == 7:
|
||||
humidity_to_location.append([int(x) for x in line.split()])
|
||||
input_file.close()
|
||||
|
||||
seeds_fin = {}
|
||||
for seed in seeds:
|
||||
soil = find_dest(seed, seed_to_soil)
|
||||
fertilizer = find_dest(soil, soil_to_fertilizer)
|
||||
water = find_dest(fertilizer, fertilizer_to_water)
|
||||
light = find_dest(water, water_to_light)
|
||||
temperature = find_dest(light, light_to_temperature)
|
||||
humidity = find_dest(temperature, temperature_to_humidity)
|
||||
location = find_dest(humidity, humidity_to_location)
|
||||
seeds_fin[seed] = {"soil": soil, "fertilizer": fertilizer, "water": water, "light": light,
|
||||
"temperature": temperature, "humidity": humidity, "location": location}
|
||||
# Ausgaben
|
||||
for i in seeds:
|
||||
print(i)
|
||||
print()
|
||||
for i in seed_to_soil:
|
||||
print(i)
|
||||
print()
|
||||
for i in soil_to_fertilizer:
|
||||
print(i)
|
||||
print()
|
||||
for i in fertilizer_to_water:
|
||||
print(i)
|
||||
print()
|
||||
for i in water_to_light:
|
||||
print(i)
|
||||
print()
|
||||
for i in light_to_temperature:
|
||||
print(i)
|
||||
print()
|
||||
for i in temperature_to_humidity:
|
||||
print(i)
|
||||
print()
|
||||
for i in humidity_to_location:
|
||||
print(i)
|
||||
print()
|
||||
for key in seeds_fin.keys():
|
||||
print(key, seeds_fin[key])
|
||||
|
||||
# #### Final
|
||||
all_locations = []
|
||||
for key in seeds_fin.keys():
|
||||
all_locations.append(seeds_fin[key]["location"])
|
||||
print(f"Kleinste Location: {min(all_locations)}")
|
||||
Reference in New Issue
Block a user