June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
27
Task/Permutations/Smalltalk/permutations-2.st
Normal file
27
Task/Permutations/Smalltalk/permutations-2.st
Normal 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)]]]
|
||||
2
Task/Permutations/Smalltalk/permutations-3.st
Normal file
2
Task/Permutations/Smalltalk/permutations-3.st
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
st> 'Abc' permutations contents
|
||||
('bcA' 'cbA' 'cAb' 'Acb' 'bAc' 'Abc' )
|
||||
Loading…
Add table
Add a link
Reference in a new issue