Anagrams

For the Compleat Fan
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Anagrams

Post by newdep »

strangly the anagrams example kills itself under linux.. Probably a high loader
Or did i just forget to chnage the list/mem size defaults ???

below the output...

(define (permutations lst)
(if (= (length lst) 1)
lst
(apply append (map (fn (rot) (map (fn (perm) (cons (first rot) perm))
(permutations (rest rot))))
(rotations lst)))))

(define (rotations lst)
(map (fn (x) (rotate lst)) (sequence 1 (length lst))))


(define (anagrams str)
(map (fn (perm) (select str perm)) (permutations (sequence 0 (- (length str) 1)))))

(anagrams "abcdefghijklmnopqrstuvwxyz" )






File anagram.lsp saved.
xxxx@C066698:~/prog/nl$ newlisp ./anagram.lsp
Killed
xxxx@C066698:~/prog/nl$
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

That string "abcdefghijklmnopqrstuvwxyz" permuted will use a lot of memory and/or stack. You are trying to generate:

(apply mul (sequence 1 26)) => 4.032914611e+026 anagrams

But what you could do, to get to the ground of this is using (sys-info) to report stack usage: the 4th and 5th parameter.

The whole thing may be more a stress to memory than to the stack. You can limit cell memory usage using the -m commandline switch. Do 'top' in another window and see what is going on.

Filter all of the anagrams, which contain the word 'newlisp' and publish them on the discussion board :-)

Lutz

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Ah yes its a lot ;-) But then again it was just a try-out and Newlisp nicly killes
itself so thats oke... Indeed its too mutch to handle...:-)
-- (define? (Cornflakes))

Locked