<blush>oops, just noticed Randal already provided this.</blush>
On Tue, Jan 5, 2010 at 5:47 PM, Eliot Miranda <[email protected]>wrote: > > > 2010/1/5 John Toohey <[email protected]> > > What I needed to do was from a sequence of say, 0 to: 4, produce #(0 0)#(1 >> 1)#(2 2)#(3 3)#(4 4)#(1 0)#(2 1)#(3 2)#(4 3)#(0 4)#(2 0)#(3 1)#(4 2)#(0 >> 3)#(1 4)#(3 0)#(4 1)#(0 2)#(1 3)#(2 4)#(4 0)#(0 1)#(1 2)#(2 3)#(3 >> 4). Basically, I wanted to generate all possible scores for a soccer match, >> hence the 1-1, 0-0, etc. > > > allPairsDo: aBinaryBlock > self do: [:first| self do: [:second| aBinaryBlock value: first value: > second]] > > right? > > >> >> >> On Tue, Jan 5, 2010 at 19:58, Randal L. Schwartz >> <[email protected]>wrote: >> >>> >>>>> "Levente" == Levente Uzonyi <[email protected]> writes: >>> >>> Levente> On Tue, 5 Jan 2010, John Toohey wrote: >>> >> But this doesn't get 1-1, 2-2 or 3-3. I had tried something like that >>> use >>> >> #reverse on each combination, but #combinations does not generate >>> >> -duplicates- from the number sequences. >>> >>> Levente> I guess you are looking for this: >>> Levente> allPairsFromCollectionDo := [ :collection :block | >>> Levente> | o | >>> Levente> o := OrderedCollection newFrom: collection. >>> Levente> o size timesRepeat: [ >>> Levente> o with: collection do: block. >>> Levente> o add: o removeFirst ] ]. >>> >>> Or more simply: >>> >>> aCollection do: [:x | aCollection do: [:y | "use x and y"]]. >>> >>> Unless I'm misunderstanding the problem. >>> >>> Which is neither combinations nor permutations, but so far is the only >>> thing >>> that fits all the bizarre conditions. >>> >>> -- >>> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 >>> 0095 >>> <[email protected]> <URL:http://www.stonehenge.com/merlyn/> >>> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. >>> See http://methodsandmessages.vox.com/ for Smalltalk and Seaside >>> discussion >>> >>> _______________________________________________ >>> Pharo-project mailing list >>> [email protected] >>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project >>> >> >> >> >> -- >> -JT >> >> >> >> _______________________________________________ >> Pharo-project mailing list >> [email protected] >> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project >> > >
_______________________________________________ Pharo-project mailing list [email protected] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
