Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
66
Task/Averages-Mode/Yabasic/averages-mode.basic
Normal file
66
Task/Averages-Mode/Yabasic/averages-mode.basic
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
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."
|
||||
Loading…
Add table
Add a link
Reference in a new issue