67 lines
1.3 KiB
Plaintext
67 lines
1.3 KiB
Plaintext
sub floor(x)
|
|
return int(x + .05)
|
|
end sub
|
|
|
|
SUB ASort$(matriz$())
|
|
local last, gap, first, tempi$, tempj$, i, j
|
|
|
|
last = arraysize(matriz$(), 1)
|
|
|
|
gap = floor(last / 10) + 1
|
|
while(TRUE)
|
|
first = gap + 1
|
|
for i = first to last
|
|
tempi$ = matriz$(i)
|
|
j = i - gap
|
|
while(TRUE)
|
|
tempj$ = matriz$(j)
|
|
if (tempi$ >= tempj$) then
|
|
j = j + gap
|
|
break
|
|
end if
|
|
matriz$(j+gap) = tempj$
|
|
if j <= gap then
|
|
break
|
|
end if
|
|
j = j - gap
|
|
wend
|
|
matriz$(j) = tempi$
|
|
next i
|
|
if gap = 1 then
|
|
return
|
|
else
|
|
gap = floor(gap / 3.5) + 1
|
|
end if
|
|
wend
|
|
END SUB
|
|
|
|
|
|
sub getMode$(list$) // returns mode and count
|
|
local m$(1), n, i, mode$, count, maxM$, maxC
|
|
|
|
n = token(list$, m$(), ", ")
|
|
ASort$(m$())
|
|
|
|
for i = 1 to n
|
|
if m$(i) <> mode$ then
|
|
if count > maxC then
|
|
maxM$ = mode$
|
|
maxC = count
|
|
end if
|
|
count = 1
|
|
mode$ = m$(i)
|
|
else
|
|
count = count + 1
|
|
end if
|
|
next i
|
|
|
|
return maxM$ + "," + str$(maxC)
|
|
end sub
|
|
|
|
result$ = getMode$("1,3,6,6,6,6,7,7,12,12,17")
|
|
n = instr(result$, ",")
|
|
print "mode ", left$(result$, n - 1), " occur(s) ", right$(result$, len(result$) - n), " times."
|
|
|
|
result$ = getMode$("a, a, b, d, d")
|
|
print "mode ", left$(result$, n - 1), " occur(s) ", right$(result$, len(result$) - n), " times."
|