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 @@
Smalltalk at: #gnomesort put: nil.
"Utility"
OrderedCollection extend [
swap: a with: b [ |t|
t := self at: a.
self at: a put: b.
self at: b put: t
]
].
"Gnome sort as block closure"
gnomesort := [ :c |
|i j|
i := 2. j := 3.
[ i <= (c size) ]
whileTrue: [
(c at: (i-1)) <= (c at: i)
ifTrue: [
i := j copy.
j := j + 1.
]
ifFalse: [
c swap: (i-1) with: i.
i := i - 1.
i == 1
ifTrue: [
i := j copy.
j := j + 1
]
]
]
].

View file

@ -0,0 +1,9 @@
|r o|
r := Random new.
o := OrderedCollection new.
1 to: 10 do: [ :i | o add: (r between: 0 and: 50) ].
gnomesort value: o.
1 to: 10 do: [ :i | (o at: i) displayNl ].