Data update

This commit is contained in:
Ingy döt Net 2024-03-06 22:25:12 -08:00
parent ed705008a8
commit 0df55f9f24
2196 changed files with 32999 additions and 3075 deletions

View file

@ -13,7 +13,7 @@ proc countsort min max . d[] .
.
.
for i = 1 to 100
d[] &= random 1000
d[] &= randint 1000
.
countsort 1 1000 d[]
print d[]

View file

@ -11,11 +11,11 @@ extension op
int[] count := new int[](max - min + 1);
int z := 0;
count.populate:(int i => 0);
count.populate::(int i => 0);
for(int i := 0, i < self.Length, i += 1) { count[self[i] - min] := count[self[i] - min] + 1 };
for(int i := 0; i < self.Length; i += 1) { count[self[i] - min] := count[self[i] - min] + 1 };
for(int i := min, i <= max, i += 1)
for(int i := min; i <= max; i += 1)
{
while (count[i - min] > 0)
{
@ -30,7 +30,7 @@ extension op
public program()
{
var list := new Range(0, 10).selectBy:(i => randomGenerator.nextInt(10)).toArray();
var list := new Range(0, 10).selectBy::(i => randomGenerator.nextInt(10)).toArray();
console.printLine("before:", list.asEnumerable());
console.printLine("after :", list.countingSort().asEnumerable())

View file

@ -1,8 +1,8 @@
val .countingSort = f(.array) {
val .min, .max = minmax(.array)
var .count = arr .max-.min+1, 0
for .i in .array { .count[.i-.min+1] += 1 }
for .i of .count { _for ~= arr .count[.i], .i+.min-1 }
val .countingSort = f(.list) {
val .min, .max = minmax(.list)
var .count = [0] x (.max-.min+1)
for .i in .list { .count[.i-.min+1] += 1 }
for .i of .count { _for ~= .count[.i] x [.i+.min-1] }
}
val .data = [7, 234, -234, 9, 43, 123, 14]