blob: e3e827da1d0449dc602542c16c9b86b79bdbfb9e (
plain)
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
|
' Challenge 202
'
' Task 1: Consecutive Odds
' Submitted by: Mohammad S Anwar
'
' You are given an array of integers.
'
' Write a script to print 1 if there are THREE consecutive odds in the given array
' otherwise print 0.
'
' Example 1
'
' Input: @array = (1,5,3,6)
' Output: 1
'
' Example 2
'
' Input: @array = (2,6,3,5)
' Output: 0
'
' Example 3
'
' Input: @array = (1,2,3,4)
' Output: 0
'
' Example 4
'
' Input: @array = (2,3,5,7)
' Output: 1
sub collect_args(nums() as integer)
dim i as integer
i=0
do while command(i+1)<>""
redim preserve nums(i) as integer
nums(i)=val(command(i+1))
i=i+1
loop
end sub
function is_odd(n as integer) as boolean
if n mod 2=0 then
is_odd=false
else
is_odd=true
end if
end function
function three_consecutive_odds(nums() as integer) as integer
dim i as integer
for i=0 to ubound(nums)-2
if is_odd(nums(i)) and is_odd(nums(i+1)) and is_odd(nums(i+2)) then
three_consecutive_odds=1
exit function
end if
next
three_consecutive_odds=0
end function
dim nums() as integer
collect_args nums()
print three_consecutive_odds(nums())
|