Thank you, duly chastened. I did know the formulae for P and C, but didn't know how to add the repetitions. My original code was :- |c| c := SortedCollection new. c add: '0, 0'; add:'1, 1'; add: '2, 2'; add:'3, 3'; add: '4, 4'. (0 to: 4) combinations: 2 atATimeDo:[:each | c add: each asCommaString. c add:( each reverse) asCommaString]. ^c Really glad that I asked the question. Thank you again. On Tue, Jan 5, 2010 at 20:36, Randal L. Schwartz <merlyn@stonehenge.com>wrote:
"John" == John Toohey <jt@parspro.com> writes:
John> What I needed to do was from a sequence of say, 0 to: 4, produce #(0 0)#(1 John> 1)#(2 2)#(3 3)#(4 4)#(1 0)#(2 1)#(3 2)#(4 3)#(0 4)#(2 0)#(3 1)#(4 2)#(0 John> 3)#(1 4)#(3 0)#(4 1)#(0 2)#(1 3)#(2 4)#(4 0)#(0 1)#(1 2)#(2 3)#(3 John> 4). Basically, I wanted to generate all possible scores for a soccer match, John> hence the 1-1, 0-0, etc.
That's what I did.
You want X, Y for all possible values of X from 0 to 4 and Y from 0 to 4, right?
That's *not* permutations.
That's *not* combinations.
That's "combinations with replacement/repetition".
... http://en.wikipedia.org/wiki/Combination
I hate it when people use the words permutation or combination without realizing they have specific math meanings. But that's not your fault, but I hope you never do it again. :)
-- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <merlyn@stonehenge.com> <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 Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- -JT