Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
parent 81fd053722
commit 52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions

View file

@ -1,12 +1,13 @@
BEGIN # find the mode (most frequent value) of a set of items #
PR read "rows.incl.a68" PR # include row (array) utilities #
PR read "sort.incl.a68" PR # include row sorting utilities #
# returns the mode(s) of a - similar operators could be defined for #
# types other than INT #
OP MODEOF = ( []INT a )[]INT:
IF LWB a > UPB a THEN []INT() # no data #
ELSE # have data #
[ LWB a : UPB a ]INT sorted data := a;
QUICKSORT sorted data FROMELEMENT LWB sorted data TOELEMENT UPB sorted data;
QUICKSORT sorted data;
INT distinct count = BEGIN # count the number of distinct values #
INT count := 1;
INT value := sorted data[ LWB sorted data ];
@ -58,6 +59,5 @@ BEGIN # find the mode (most frequent value) of a set of items #
SHOW MODEOF []INT( 7, 13, 5, 13, 7, 2, 7, 10, 13 ) ;print( ( newline ) );
SHOW MODEOF []INT( 5 ) ;print( ( newline ) );
# additional test case #
SHOW MODEOF []INT( 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 ) ;print( ( newline )
SHOW MODEOF []INT( 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 ) ;print( ( newline ) )
END

View file

@ -0,0 +1 @@
[6 7 9 5 9 8 7] | math mode | grid

View file

@ -0,0 +1,15 @@
##
function modes<T>(s: sequence of T): sequence of T;
begin
var count := s.EachCount;
var best := count.Values.Max;
result := new List<T>;
foreach var k in count do
if k.value = best then result := result + k.key;
end;
modes(|1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17|).Println;
modes(|1, 1, 2, 4, 4|).Println;
modes('sdsvdvddffffs').Println;
var a := new object[] (1, 'blue', 2, 7.5, 5, 'green', 'red', 5, 2, 'blue', 'white');
modes(a).Println;