-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex2.rb
More file actions
36 lines (31 loc) · 686 Bytes
/
ex2.rb
File metadata and controls
36 lines (31 loc) · 686 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
inp = ARGV
if inp == '--help'
puts 'Enter a list of random elements to check if they are part of an ascending sequence of characters starting with 1'
end
def check_num(inp)
non_numeric = false
inp.each do |element|
non_numeric = true if element.to_i == 0
end
non_numeric
end
def get_result(inp)
if check_num(inp)
result = 1
else
sorted = inp.sort
for i in 0..sorted.length() - 2
current_int = sorted[i].to_i
next_int = sorted[i + 1].to_i
if (current_int + 1 != next_int)
result = current_int + 1
break
else
result = 0
end
end
end
return result
end
result = get_result(inp)
puts result