June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
45
Task/Averages-Mode/Ring/averages-mode.ring
Normal file
45
Task/Averages-Mode/Ring/averages-mode.ring
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
# Project : Averages/Mode
|
||||
# Date : 2018/04/11
|
||||
# Author : Gal Zsolt (~ CalmoSoft ~)
|
||||
# Email : <calmosoft@gmail.com>
|
||||
|
||||
a = [1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17]
|
||||
b = [1, 2, 4, 4, 1]
|
||||
amodes = list(12)
|
||||
see "mode(s) of a() = " + nl
|
||||
for i1 = 1 to modes(a,amodes)
|
||||
see "" + amodes[i1] + " "
|
||||
next
|
||||
see nl
|
||||
see "mode(s) of b() = " + nl
|
||||
for i1 = 1 to modes(b,amodes)
|
||||
see "" + amodes [i1] + " "
|
||||
next
|
||||
see nl
|
||||
|
||||
func modes(a,amodes)
|
||||
max = 0
|
||||
n = len(a)
|
||||
if n = 0
|
||||
amodes[1] = a[1]
|
||||
return 1
|
||||
ok
|
||||
c = list(n)
|
||||
for i = 1 to n
|
||||
for j = i+1 to n
|
||||
if a[i] = a[j]
|
||||
c[i] = c[i] + 1
|
||||
ok
|
||||
next
|
||||
if c[i] > max
|
||||
max = c[i]
|
||||
ok
|
||||
next
|
||||
j = 0
|
||||
for i = 1 to n
|
||||
if c[i] = max
|
||||
j = j + 1
|
||||
amodes[j] = a[i]
|
||||
ok
|
||||
next
|
||||
return j
|
||||
Loading…
Add table
Add a link
Reference in a new issue