Numbers in array

mrossen

Active Member
Licensed User
Longtime User
Hi,

Anyone know a smart way to find the first available number in at array like this : [1, 2, 3, 5, 6, 7].
I would like to get the result 4 or [1,2,3,4] the result will be 5 or [2,3,4,5] the result will be 1

Mogens
 

mc73

Well-Known Member
Licensed User
Longtime User
B4X:
dim ar() as int
ar(0)=1:ar(1)=2:ar(2)=3:ar(3)=5:ar(4)=6:ar(5)=7
n=ar.size
dim s1,s2 as int
s1=(n+1)*(n+2)/2
s2=0
for k=0 to n-1
s2=s2+ar(k)
next
msgbox(s1-s2,"you mean this?")
 
Upvote 0
Top