Anagrams
Posted: Fri Oct 01, 2004 11:26 pm
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$
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$