Path: utzoo!attcan!uunet!willett!ForthNet From: ForthNet@willett.UUCP (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: PUZZLES AND PROBLEMS Message-ID: <1279.UUL1.3#5129@willett.UUCP> Date: 5 Jul 90 02:23:46 GMT Organization: String, Scotch tape, and Paperclips. (in Pgh, PA) Lines: 44 Category 3, Topic 35 Message 123 Tue Jul 03, 1990 W.BADEN1 [Wil] at 22:28 PDT I've changed my mind. Here's Trotter's algorithm in Forth. 10 CONSTANT Maxperm CREATE P Maxperm ALLOT 1 P C! CREATE D Maxperm ALLOT : perm ( n -- i) P C@ IF 0 DO ( ) 0 P I + C! 1 D I + C! LOOP 0 EXIT THEN 0 ( n k) 1 ROT 1- DO ( k) D I + C@ P I + C+! P I + C@ ( k q) DUP IF DUP I > 0= IF + UNLOOP EXIT THEN DROP ( k) -1 D I + C! ELSE ( k q) DROP ( k) 1 D I + C! 1+ THEN -1 +LOOP 1 P C! 1+ ; If you lack : C+! ( n a -- ) DUP C@ +under C! ; This was easy to code from the C. And I find the Forth easy to read. But discovering the algorithm in Forth without benefit of a higher level language would have been difficult. Procedamus in pace. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu