Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,2 @@
(1 to: 4) permutationsDo: [ :x |
Transcript show: x printString; cr ].

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' )