Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
58
Task/Averages-Mode/Liberty-BASIC/averages-mode.basic
Normal file
58
Task/Averages-Mode/Liberty-BASIC/averages-mode.basic
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
a$ = "1 3 6 6 6 6 7 7 12 12 17"
|
||||
b$ = "1 2 4 4 1"
|
||||
|
||||
print "Modes for ";a$
|
||||
print modes$(a$)
|
||||
print "Modes for ";b$
|
||||
print modes$(b$)
|
||||
|
||||
function modes$(a$)
|
||||
'get array size
|
||||
n=0
|
||||
t$ = "*"
|
||||
while t$<>""
|
||||
n=n+1
|
||||
t$=word$(a$, n)
|
||||
'print n, t$
|
||||
wend
|
||||
n=n-1
|
||||
'print "n=", n
|
||||
'dim array
|
||||
'read in array
|
||||
redim a(n)
|
||||
for i = 1 to n
|
||||
a(i)=val(word$(a$, i))
|
||||
'print i, a(i)
|
||||
next
|
||||
'sort
|
||||
sort a(), 1, n
|
||||
'get the modes
|
||||
occurence = 1
|
||||
maxOccurence = 0
|
||||
oldVal = a(1)
|
||||
modes$ = ""
|
||||
for i = 2 to n
|
||||
'print i, a(i)
|
||||
if a(i) = oldVal then
|
||||
occurence = occurence + 1
|
||||
else
|
||||
select case
|
||||
case occurence > maxOccurence
|
||||
maxOccurence = occurence
|
||||
modes$ = oldVal; " "
|
||||
case occurence = maxOccurence
|
||||
modes$ = modes$; oldVal; " "
|
||||
end select
|
||||
occurence = 1
|
||||
end if
|
||||
oldVal = a(i)
|
||||
next
|
||||
'check after loop
|
||||
select case
|
||||
case occurence > maxOccurence
|
||||
maxOccurence = occurence
|
||||
modes$ = oldVal; " "
|
||||
case occurence = maxOccurence
|
||||
modes$ = modes$; oldVal; " "
|
||||
end select
|
||||
end function
|
||||
Loading…
Add table
Add a link
Reference in a new issue