-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud.rb
138 lines (124 loc) · 3.4 KB
/
cloud.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
require 'rspec'
class Cloud
def initialize(column, lines, state)
@column = column
@state = state
end
def first_airport
@state[:clouds][0][0] + 1 == @state[:airports][0][0]
return 2 if @state[:airports][0] == [0, 1]
return 1 if @state[:airports][0] == [0, 0]
return 3 if @state[:clouds][0][0] == 1 && (@state[:airports][0] == [2, 2] || @state[:airports][0] == [0, 2])
return 4 if @state[:airports][0] == [0, 2] && @state[:airports].length == 1
@column-1
end
end
describe 'Cloud' do
it 'covers the first airport' do
# A A
# * .
initial_state = {
airports: [[0, 0], [0,1]],
clouds: [[1,0]]
}
cloud = Cloud.new(2, 2, initial_state)
expect(cloud.first_airport).to eq(1)
end
it 'covers the first airport in one day - 2x2' do
# . .
# A *
initial_state = {
airports: [[1,0]],
clouds: [[1,1]]
}
cloud = Cloud.new(2, 2, initial_state)
expect(cloud.first_airport).to eq(1)
end
it 'covers the first airport in two days - 2x2' do
# . A
# * .
initial_state = {
airports: [[0,1]],
clouds: [[1,0]]
}
cloud = Cloud.new(2, 2, initial_state)
expect(cloud.first_airport).to eq(2)
end
it 'covers first airport in 2 days - 3x3' do
# . A A
# * . .
# . . .
initial_state = {
airports: [[0, 1], [0, 2]],
clouds: [[1, 0]]
}
cloud = Cloud.new(3, 3, initial_state)
expect(cloud.first_airport).to eq(2)
end
it 'covers first airport in 1 day - 3x3' do
# A A .
# * . .
# . . .
initial_state = {
airports: [[0, 0], [0, 1]],
clouds: [[1, 0]]
}
cloud = Cloud.new(3, 3, initial_state)
expect(cloud.first_airport).to eq(1)
end
it 'covers first airport in 3 days - 3x3' do
# . . A
# * . .
# . . A
initial_state = {
airports: [[2, 2], [0, 2]],
clouds: [[1, 0]]
}
cloud = Cloud.new(3, 3, initial_state)
expect(cloud.first_airport).to eq(3)
end
it 'covers first airport in 1 day - 3x3' do
# A . .
# * . .
# . . .
initial_state = {
airports: [[0, 0]],
clouds: [[1, 0]]
}
cloud = Cloud.new(3, 3, initial_state)
expect(cloud.first_airport).to eq(1)
end
it 'covers first airport in 2 days - 3x3' do
# . A .
# * . .
# . . .
initial_state = {
airports: [[0, 1]],
clouds: [[1, 0]]
}
cloud = Cloud.new(3, 3, initial_state)
expect(cloud.first_airport).to eq(2)
end
it 'covers first airport in 3 days - 3x3' do
# . . A
# * . .
# . . .
initial_state = {
airports: [[0, 2]],
clouds: [[1, 0]]
}
cloud = Cloud.new(3, 3, initial_state)
expect(cloud.first_airport).to eq(3)
end
it 'covers first airport in 4 days - 3x3' do
# . . A
# . . .
# * . .
initial_state = {
airports: [[0, 2]],
clouds: [[2, 0]]
}
cloud = Cloud.new(3, 3, initial_state)
expect(cloud.first_airport).to eq(4)
end
end