Date: Mon, 15 Dec 2003 13:57:29 -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
Content-Type: text/plain
Alert readers Harry Droogendyk and Robert wrote to let me know that Robert's
solution merely restricts the results of the SQL query to the permutations
of the string. I had jumped to the conclusion that
sum(index(combo,'D'),index(combo,'G'),index(combo,'J'),index(combo,'L'),inde
x(combo,'O'),index(combo,'U'))=21
would find the 'GodJul' solution. It would if written:
sum(index(combo,'D')=3,index(combo,'G')=1,index(combo,'J')=4,index(combo,'L'
)=6,inde
x(combo,'O')=2,index(combo,'U')=5)=6
That would provide the solution, but only if you know in advance how to
assign the character positions!
Sig
-----Original Message-----
From: Sigurd Hermansen
Sent: Monday, December 15, 2003 12:45 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Permutation problem
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
|