September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,16 +1,16 @@
func cocktailsort(a) {
var swapped = false;
var swapped = false
func cmpsw(i) {
if (a[i] > a[i+1]) {
a[i, i+1] = a[i+1, i];
swapped = true;
a[i, i+1] = a[i+1, i]
swapped = true
}
}
var max = a.end;
var max = a.end
do {
{ |i| cmpsw(i-1) } * max;
swapped.not! && break;
{ |i| cmpsw(max-i) } * max;
} while (swapped);
return a;
{|i| cmpsw(i) } << ^max
swapped.not! && break
{|i| cmpsw(max-i) } << 1..max
} while (swapped)
return a
}

View file

@ -1,5 +1,5 @@
var numbers = [7,6,5,9,8,4,3,1,2,0];
say cocktailsort(numbers).dump;
var numbers = [7,6,5,9,8,4,3,1,2,0]
say cocktailsort(numbers)
var strs = ["John", "Kate", "Zerg", "Alice", "Joe", "Jane"];
say cocktailsort(strs).dump;
var strs = ["John", "Kate", "Zerg", "Alice", "Joe", "Jane"]
say cocktailsort(strs)