Data update

This commit is contained in:
Ingy döt Net 2025-06-11 20:16:52 -04:00
parent 72eb4943cb
commit 4d5544505c
2347 changed files with 62432 additions and 16731 deletions

View file

@ -0,0 +1,27 @@
import ballerina/io;
function mode(int[] arr) returns int[]|error {
map<int> m = {};
foreach int e in arr {
string k = e.toString();
if !m.hasKey(k) { m[k] = 0; }
m[k] = m.get(k) + 1;
}
int max = int:MIN_VALUE;
int[] modes = [];
foreach string k in m.keys() {
int v = m.get(k);
if v > max {
max = v;
modes.removeAll();
}
if v >= max {
modes.push(check int:fromString(k));
}
}
return modes;
}
public function main() {
io:println(mode([1, 2, 3, 4, 5, 5, 51, 2, 3]));
}

View file

@ -0,0 +1,6 @@
def mode (seq)
seq.tally.group_by {|n, count| count }.max[1].map {|n, count| n }
end
p mode([1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17])
p mode([1, 1, 2, 4, 4])

View file

@ -1,4 +1,4 @@
proc modes . in[] r[] .
proc modes &in[] &r[] .
r[] = [ ]
for v in in[]
for i to len vals[]
@ -12,9 +12,7 @@ proc modes . in[] r[] .
cnt[] &= 0
.
for i to len cnt[]
if cnt[i] = max
r[] &= vals[i]
.
if cnt[i] = max : r[] &= vals[i]
.
.
in[] = [ 1 3 6 6 6 6 7 7 12 12 17 ]