LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2003, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Sun, 14 Dec 2003 21:26:34 -0500
Reply-To:   Sigurd Hermansen <HERMANS1@WESTAT.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Sigurd Hermansen <HERMANS1@WESTAT.COM>
Subject:   Re: Permutation problem
Comments:   To: LWn <villerwalle@YAHOO.COM>
Content-Type:   text/plain; charset="iso-8859-1"

Lars: Merry %permute(%str(D),%str(G),%str(J),%str(L),%str(O),%str(U),__n=194) Sig %macro permute(__x1,__x2,__x3,__x4,__x5,__x6,__n=); /* Create data*/ data d; do x="&__x1","&__x2","&__x3","&__x4","&__x5","&__x6"; output; end; run;

proc sql; create table permute as select d1.x||d2.x||d3.x||d4.x||d5.x||d6.x as permute from d as d1,d as d2,d as d3,d as d4,d as d5,d as d6 where index(calculated permute,"&__x1") and index(calculated permute,"&__x2") and index(calculated permute,"&__x3") and index(calculated permute,"&__x4") and index(calculated permute,"&__x5") and index(calculated permute,"&__x6") order by permute ; select monotonic() as n,* from permute where calculated n=&__n ; quit; %mend permute; %permute(%str(D),%str(G),%str(J),%str(L),%str(O),%str(U),__n=194)

-----Original Message----- From: LWn To: SAS-L@LISTSERV.UGA.EDU Sent: 12/14/2003 3:51 PM Subject: Permutation problem

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