-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathday16.rb
60 lines (49 loc) · 977 Bytes
/
day16.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
require_relative 'helpers'
require 'rspec'
require 'pry'
sues = []
read_input_lines(16).each do |line|
props = line.match(/Sue \d+\:(.+)/).captures.first.split(',')
sue = {}
props.each do |prop|
key, value = prop.strip.split(': ')
sue[key.to_sym] = value.to_i
end
sues << sue
end
target_sue = {
children: 3,
cats: 7,
samoyeds: 2,
pomeranians: 3,
akitas: 0,
vizslas: 0,
goldfish: 5,
trees: 3,
cars: 2,
perfumes: 1
}
possibly_sues = []
sues.each_with_index do |sue, i|
match = true
sue.each do |key, value|
if [:cats, :trees].include?(key)
if target_sue[key] >= value
match = false
break
end
elsif [:pomeranians, :goldfish].include?(key)
if target_sue[key] <= value
match = false
break
end
else
if target_sue[key] != value
match = false
break
end
end
end
possibly_sues << [i+1, sue] if match
end
puts possibly_sues.inspect