Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
|
|
@ -1,27 +1,28 @@
|
|||
#define system.
|
||||
#define system'routines.
|
||||
#define system'collections.
|
||||
#define extensions'io.
|
||||
#define extensions.
|
||||
|
||||
// Averages/Mode
|
||||
|
||||
#symbol mode = &&:anArray
|
||||
#symbol mode = (:anArray)
|
||||
[
|
||||
#var aCountMap := Dictionary new &default:0.
|
||||
control foreach:anArray &do: &&:anItem
|
||||
control foreach:anArray &do: anItem
|
||||
[
|
||||
aCountMap @ anItem << ((aCountMap @ anItem) + 1).
|
||||
aCountMap set &key:anItem &value:(aCountMap getAt &key:anItem + 1).
|
||||
].
|
||||
|
||||
listControl sort:aCountMap &with: &&:p:n
|
||||
[ p Value > n Value ].
|
||||
listControl sort:aCountMap &with: (:p:n)
|
||||
[ p value > n value ].
|
||||
|
||||
#var aResult := List new.
|
||||
|
||||
#var aMax := aCountMap First Value.
|
||||
control foreach:aCountMap &do: &&:anItem
|
||||
#var aMax := aCountMap First value.
|
||||
control foreach:aCountMap &do: anItem
|
||||
[
|
||||
aMax == anItem Value
|
||||
? [ aResult += anItem Key. ].
|
||||
aMax == anItem value
|
||||
? [ aResult += anItem key. ].
|
||||
].
|
||||
|
||||
^ listControl toArray:aResult.
|
||||
|
|
@ -35,6 +36,6 @@
|
|||
#var aMode1 := mode:anArray1.
|
||||
#var aMode2 := mode:anArray2.
|
||||
|
||||
consoleEx write:"mode of (" write::anArray1 write:") is (" write::aMode1 writeLine:")".
|
||||
consoleEx write:"mode of (" write::anArray2 write:") is (" write::aMode2 writeLine:")".
|
||||
consoleEx writeLine:"mode of (":anArray1:") is (":aMode1:")".
|
||||
consoleEx writeLine:"mode of (":anArray2:") is (":aMode2:")".
|
||||
].
|
||||
|
|
|
|||
58
Task/Averages-Mode/Liberty-BASIC/averages-mode.liberty
Normal file
58
Task/Averages-Mode/Liberty-BASIC/averages-mode.liberty
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
|
||||
20
Task/Averages-Mode/PL-I/averages-mode.pli
Normal file
20
Task/Averages-Mode/PL-I/averages-mode.pli
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
av: procedure options (main); /* 28 October 2013 */
|
||||
declare x(10) fixed binary static initial (1, 4, 2, 6, 2, 5, 6, 2, 4, 2);
|
||||
declare f(32767) fixed binary;
|
||||
declare (j, n, max, value) fixed binary;
|
||||
declare i fixed;
|
||||
|
||||
n = hbound(x,1);
|
||||
|
||||
do i = 1 to n;
|
||||
j = x(i);
|
||||
f(j) = f(j) + 1;
|
||||
end;
|
||||
max = 0;
|
||||
do i = 1 to hbound(f,1);
|
||||
if max < f(i) then do; max = f(i); value = i; end;
|
||||
end;
|
||||
put list ('The mode value is ' || value || ' occurred ' ||
|
||||
max || ' times.');
|
||||
|
||||
end av;
|
||||
Loading…
Add table
Add a link
Reference in a new issue