-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_05.rb
70 lines (63 loc) · 1.74 KB
/
day_05.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def step1(example = false)
data_list = [
:seed_to_soil,
:soil_to_fertilizer,
:fertilizer_to_water,
:water_to_light,
:light_to_temperature,
:temperature_to_humidity,
:humidity_to_location
]
dict = {}
seeds = input(example)[0].split(" ").map(&:to_i).select{|x| x > 0}
p seeds
category = data_list[0]
input(example).each_with_index do |line, index|
next if index == 0 || index == 1
if line[0].match?(/\d/)
split_line = line.strip.split(" ").map(&:to_i)
dest_start = split_line[0]
source_start = split_line[1]
range = split_line[2]
new_value = {dest_start: dest_start, source_start: source_start, range: range}
new_dict = dict[category] ? [dict[category], new_value].flatten : [new_value]
dict[category] = new_dict
elsif line[0].match?(/\w/)
category = line.split(" ")[0].gsub("-", "_").to_sym
else
next
end
end
p dict
dict.each do |cat, value|
seeds.map!.with_index do |number, index|
value.each do |v|
if number >= v[:source_start] && number < (v[:source_start] + v[:range])
if index == 1 && number == 49
p number
p cat
p v
p (number - v[:source_start])
p v[:dest_start] + (number - v[:source_start])
end
if index == 1 && number == 53
p number
p cat
p v
p (number - v[:source_start])
p v[:dest_start] + (number - v[:source_start])
end
number = v[:dest_start] + (number - v[:source_start])
end
end
number
end
p seeds
end
p seeds.min
end
def step2(example = false)
end
def input(example)
example == 'example' ? @input_example : @input
end