-
Notifications
You must be signed in to change notification settings - Fork 0
/
puzzle-2.rb
49 lines (42 loc) · 982 Bytes
/
puzzle-2.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
class PuzzleTwo
def self.method_one(input)
return unless input.is_a?(Array)
horizontal = 0
depth = 0
input.each do |value|
value_split = value.split(' ')
case value_split[0]
when 'forward'
horizontal += value_split[1].to_i
when 'up'
depth -= value_split[1].to_i
when 'down'
depth += value_split[1].to_i
else
puts 'no matching command'
end
end
horizontal * depth
end
def self.method_two(input)
return unless input.is_a?(Array)
horizontal = 0
depth = 0
aim = 0
input.each do |value|
value_split = value.split(' ')
case value_split[0]
when 'forward'
horizontal += value_split[1].to_i
depth += aim * value_split[1].to_i
when 'up'
aim -= value_split[1].to_i
when 'down'
aim += value_split[1].to_i
else
puts 'no matching command'
end
end
horizontal * depth
end
end