-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclouds.rb
More file actions
56 lines (40 loc) · 1000 Bytes
/
clouds.rb
File metadata and controls
56 lines (40 loc) · 1000 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
49
50
51
52
53
54
55
56
#!/bin/ruby
require 'json'
require 'stringio'
#
# Complete the 'jumpingOnClouds' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER_ARRAY c as parameter.
#
def jumpingOnClouds(c)
# Write your code here
minSteps = 0
i = 0
while i < c.length
if c[i + 1] == 0 || c[i + 2] == 0
if (c[i + 1] == 1 && c[i + 2] == 0) || (c[i + 1] == 0 && c[i + 2] == 0)
i = i + 2
else
i = i + 1
end
minSteps = minSteps + 1
else
puts 'what'
break
end
end
return minSteps
end
# fptr = File.open(ENV['OUTPUT_PATH'], 'w')
n = gets.strip.to_i
c = gets.rstrip.split.map(&:to_i)
if (c[0] == 0 && c[c.length - 1] == 0 && 2 <= n && n <= 100)
result = jumpingOnClouds c
else
result = 0
end
puts result
# fptr.write result
# fptr.write "\n"
# fptr.close()