Date: Mon, 15 Dec 2003 12:45:03 -0500 Sigurd Hermansen "SAS(r) Discussion" Sigurd Hermansen Re: Permutation problem To: Robert Stratton text/plain

Robert: I like the clever use of the sum of index values, but wouldn't you have to know the answer to the puzzle before you could use this solution? Sig

-----Original Message----- From: Robert Stratton [mailto:rstratton@PHD.CO.UK] Sent: Monday, December 15, 2003 10:28 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Permutation problem

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'),inde x(combo,'O'),index(combo,'U'))=21 order by combo; ;

"LWn" <villerwalle.nononospam@yahoo.com> wrote in message news:<u34Db.42048\$dP1.163479@newsc.telia.net>... > 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