-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnail.rb
More file actions
49 lines (47 loc) · 754 Bytes
/
Snail.rb
File metadata and controls
49 lines (47 loc) · 754 Bytes
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
arr = [[1,2,3],
[8,9,4],
[7,6,5]]
h = 0
v = 0
answer = []
min = 0
count = 0
if count == 0
max = arr.length() -1
count += 1
end
if (h < max)
while (h < max)
answer << arr[v][h]
h += 1
end
end
if (v < max)
while (v < max)
answer << arr[v][h]
v += 1
end
end
max -= 1
if (h > min)
while (h > min)
answer << arr [v][h]
h -= 1
end
end
if (v > min)
while (v > min)
answer << arr [v][h]
v -= 1
end
end
# What to do here when you start over, because the numbers overlapp. Consider reducing them between each turn
v += 1
h += 1
if (h <= max)
while (h <= max)
answer << arr[v][h]
h += 1
end
end
p answer