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,27 @@
ArrayedCollection extend [
permuteAndDo: aBlock
["Permute receiver in-place, and call aBlock.
Requires integer keys."
self permuteUpto: self size andDo: aBlock]
permuteUpto: n andDo: aBlock
[n = 0 ifTrue: [^aBlock value].
1 to: n do:
[:i |
self swap: i with: n.
self permuteUpto: n-1 andDo: aBlock.
self swap: i with: n]]
]
SequenceableCollection extend [
permutations
["Answer a ReadStream of permuted shallow copies of receiver."
| c |
c := MappedCollection
collection: self
map: self keys asArray.
^Generator on:
[:g |
c map permuteAndDo: [g yield: (c copyFrom: 1 to: c size)]]]

View file

@ -0,0 +1,2 @@
st> 'Abc' permutations contents
('bcA' 'cbA' 'cAb' 'Acb' 'bAc' 'Abc' )