Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!quiche!einstein From: einstein@cs.mcgill.ca (Michael CHOWET) Newsgroups: comp.lang.pascal Subject: Re: Anagram Summary: See code below Message-ID: <1991Jan10.023817.14980@cs.mcgill.ca> Date: 10 Jan 91 02:38:17 GMT References: <25369@adm.brl.mil> Sender: Michael Chowet (einstein@cs.mcgill.ca) Followup-To: Request for anagram generating algorithm for N-strings Organization: SOCS, McGill University, Montreal, Canada Lines: 83 Shawn Barnhart posted a little while ago for an anagram generator that is not limited by size. Well, after thinking it over for a day or so, I came up with the following.... (Note, this program was written in Turbo Pascal ('natch :-), so caveat emptor. This makes use of the string type, and the length function for it. As well, this is only good for starting words where the letters are all unique. If any letter appears twice, the exit condition at the UNTIL would need to be substituted for a flag containing false if the ENTIRE link array is void of True's. (Ie, For Ct := 1 to Length(S)-1 do Flag := Flag Or L[Ct] ; ) Enjoy...) -------->CUT HERE-------->CUT HERE-------->CUT HERE-------->CUT HERE--------> program Give_Anagrams ; {Written: Jan 8th 1990 } {By : Michael Chowet } {Note : This code is freely distributable by anyone. I hereby relenquish } { it into the public domain... } var s : string ; procedure swap ( var ch1,ch2 : char ) ; var temp : char ; begin temp := ch1 ; ch1 := ch2 ; ch2 := temp; end ; procedure anagram ( s,s2 : string ) ; var i, ct : integer ; l : array [ 1..3 ] of boolean ; begin for i := 1 to length(s)-1 do l[i] := false ; { fill the link array with NOT-YET-SWITCHED flag } repeat i := 1 ; { start looking at the first letter pair } while (i',s ) ; until s=s2; { this condition will need to be } { changed for non-unique characters } end; begin s := 'MIKE' ; { place your word for anagram-ing here } anagram ( s,s ) ; end. ============================================================================== Today's message was brought to you by the letter 'S', the number 6, and =====> Einstein@cs.mcgill.ca <==== =====> Mike CHOWET | McGill CSUS VP External <===== Post back soon, now y'hear... ==============================================================================