Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,33 @@
var gnomeSort = Fn.new { |a, asc|
var size = a.count
var i = 1
var j = 2
while (i < size) {
if ((asc && a[i-1] <= a[i]) || (!asc && a[i-1] >= a[i])) {
i = j
j = j + 1
} else {
var t = a[i-1]
a[i-1] = a[i]
a[i] = t
i = i - 1
if (i == 0) {
i = j
j = j + 1
}
}
}
}
var as = [ [4, 65, 2, -31, 0, 99, 2, 83, 782, 1], [7, 5, 2, 6, 1, 4, 2, 6, 3] ]
for (asc in [true, false]) {
System.print("Sorting in %(asc ? "ascending" : "descending") order:\n")
for (a in as) {
var b = (asc) ? a : a.toList
System.print("Before: %(b)")
gnomeSort.call(b, asc)
System.print("After : %(b)")
System.print()
}
}