extends Control func _ready(): pass func read_map(lines, i): var map = [] while true: var line = lines[i] if line == '': break i += 1 var map_entry_string = line.split(' ') var entry = MapEntry.new() entry.dst_start = int(map_entry_string[0]) entry.src_start = int(map_entry_string[1]) entry.range = int(map_entry_string[2]) map.append(entry) return [map, i] func parse_input(input): var lines = input.split('\n') var i = 0 var maps = Maps.new() # Parse seeds var seeds_str = lines[i].split(' ').slice(1) var seeds = [] for s in seeds_str: seeds.append(int(s)) # Skip to seed-to-soil map i += 3 var map_i = read_map(lines, i) maps.seed2soil = map_i[0] i = map_i[1] # Skip to soil-to-fertilizer map i += 2 map_i = read_map(lines, i) maps.soil2fertilizer = map_i[0] i = map_i[1] # Skip to fertilizer-to-water map i += 2 map_i = read_map(lines, i) maps.fertilizer2water = map_i[0] i = map_i[1] # Skip to water-to-light map i += 2 map_i = read_map(lines, i) maps.water2light = map_i[0] i = map_i[1] # Skip to light-to-temperature map i += 2 map_i = read_map(lines, i) maps.light2temperature = map_i[0] i = map_i[1] # Skip to temperature-to-humidity map i += 2 map_i = read_map(lines, i) maps.temperature2humidity = map_i[0] i = map_i[1] # Skip to humidity-to-location map i += 2 map_i = read_map(lines, i) maps.humidity2location = map_i[0] i = map_i[1] return [seeds, maps] func _on_part1(): var input = $TextEdit.text + '\n' # Safety newline :) var seeds_maps = parse_input(input) var seeds = seeds_maps[0] var maps = seeds_maps[1] print(seeds) print(maps) var overall_closest = INF for seed in seeds: var closest = maps.find_closest(seed) overall_closest = min(overall_closest, closest) print("Closest location: " + str(overall_closest)) func _on_part2(): var input = $TextEdit.text