Averages/Mode: Difference between revisions

no edit summary
m (→‎{{header|Perl 6}}: Combine files to make runnable code)
No edit summary
Line 2,474:
Vector: [1,3,6,6,6,6,7,7,12,12,17], Mode(s): [6]
Vector: [1,1,2,4,4], Mode(s): [1,4]</pre>
 
=={{header|Ring}}==
<lang ring>
# 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
</lang>
Output:
<pre>
mode(s) of a() =
6
mode(s) of b() =
1 4
</pre>
 
=={{header|Ruby}}==
2,468

edits