June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,66 @@
import extensions.
extension $op
{
pancakeSort
[
var list := self clone.
int i := list length.
if (i < 2) [ ^ self ].
while (i > 1)
[
int max_num_pos := 0.
int a := 0.
while (a < i)
[
if (list[a] > list[max_num_pos])
[
max_num_pos := a
].
a += 1
].
if (max_num_pos == i - 1)
[
];
[
if (max_num_pos > 0)
[
list flip(list length, max_num_pos + 1)
].
list flip(list length, i)
].
i -= 1
].
^ list
]
flip(IntNumber length, IntNumber num)
[
int i := 0.
int count := num - 1.
while (i < count)
[
var swap := self[i].
self[i] := self[count].
self[count] := swap.
i += 1.
count -= 1
]
]
}
program =
[
var list := (6, 7, 8, 9, 2, 5, 3, 4, 1).
console printLine("before:", list).
console printLine("after :", list pancakeSort).
].