-
Notifications
You must be signed in to change notification settings - Fork 0
/
11.rb
42 lines (39 loc) · 768 Bytes
/
11.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
input = File.open('11-input.txt').read
steps = input.split(',').map(&:chomp)
east_score = 0
north_score = 0
steps.each do |step|
if step.length == 1
north_score += 1 if step == 'n'
north_score += -1 if step == 's'
end
if step.length == 2
north_score += 0.5 if step[0] == 'n'
north_score += -0.5 if step[0] == 's'
east_score += 0.5 if step[1] == 'e'
east_score += -0.5 if step[1] == 'w'
end
end
count = 0
while east_score != 0 do
if east_score > 0
east_score -= 0.5
else
east_score += 0.5
end
if north_score > 0
north_score -= 0.5
else
north_score += 0.5
end
count += 1
end
while north_score != 0 do
if north_score > 0
north_score -= 1
else
north_score += 1
end
count += 1
end
puts count