Anagrams

Started by newdep, October 01, 2004, 04:26:20 PM

Previous topic - Next topic

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

#1
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

#2
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))