```Date: Mon, 15 Dec 2003 07:28:08 -0800 Reply-To: Robert Stratton Sender: "SAS(r) Discussion" From: Robert Stratton Organization: http://groups.google.com Subject: Re: Permutation problem Content-Type: text/plain; charset=ISO-8859-1 data y; input x \$1.; cards; D G J L O U ; proc sql; create table x as select combo from (select a.x||b.x||c.x||d.x||e.x||f.x as combo from y as a , y as b, y as c, y as d, y as e, y as f) where sum(index(combo,'D'),index(combo,'G'),index(combo,'J'),index(combo,'L'),index(combo,'O'),index(combo,'U'))=21 order by combo; ; "LWn" wrote in message news:... > This week every year I use to present a small permutation problem in > two steps to my students. > i) How many possible sixletter "words" can be made using > the letters DGJLOU? No problem, the answer usually comes > within ten seconds. > ii) OK, now I want you to arrange all those 720 "words" > alphabetically. What "word" is number 194? > > 1: DGJLOU > 2: DGJLUO > . > 194: ?????? > . > 720: UOLJGD > > If the students are familiar with SAS or some other programming > tool I ask them to try using their computers. Here is my SAS solution. > Does anybody have a more elegant solution with SAS or SPSS? > > data dgjlou (keep=word) ; > length i j k l m n \$ 1. ; > do i='D', 'G', 'J', 'L', 'O', 'U' ; > do j='D', 'G', 'J', 'L', 'O', 'U' ; > do k='D', 'G', 'J', 'L', 'O', 'U' ; > do l='D', 'G', 'J', 'L', 'O', 'U' ; > do m='D', 'G', 'J', 'L', 'O', 'U' ; > do n='D', 'G', 'J', 'L', 'O', 'U' ; > word = i||j||k||l||m||n ; > xx = (i=j)+(i=k)+(i=l)+(i=m)+(i=n) > +(j=k)+(j=l)+(j=m)+(j=n)+(k=l) > +(k=m)+(k=n)+(l=m)+(l=n)+(m=n) ; > xx = 0 then output ; > end ; > end ; > end ; > end ; > end ; > end ; > run ; > ------------------------------ > No 194 is GOD JUL which is Swedish for Merry Xmas! > > /Lars Wahlgren > Lund university, Sweden ```

Back to: Top of message | Previous page | Main SAS-L page