fork download
  1. ; your code goes here
  2.  
  3. (defun all-indexes-1 (len numbers pattern)
  4. (if (null numbers)
  5. (list pattern)
  6. (mapcan (lambda (n)
  7. (all-indexes-1 len
  8. (remove n numbers)
  9. (cons n pattern)))
  10. numbers)))
  11.  
  12. (defun all-indexes (len)
  13. (all-indexes-1 len
  14. (loop for n below len collect n)
  15. nil))
  16.  
  17. (defun all-patterns (seq)
  18. (mapcar (lambda (indexes)
  19. (coerce (mapcar (lambda (i) (aref seq i))
  20. indexes)
  21. (type-of seq)))
  22. (all-indexes (length seq))))
  23.  
  24. (mapc #'print (all-patterns "abcd"))
  25.  
Success #stdin #stdout 0.04s 10624KB
stdin
Standard input is empty
stdout
"dcba" 
"cdba" 
"dbca" 
"bdca" 
"cbda" 
"bcda" 
"dcab" 
"cdab" 
"dacb" 
"adcb" 
"cadb" 
"acdb" 
"dbac" 
"bdac" 
"dabc" 
"adbc" 
"badc" 
"abdc" 
"cbad" 
"bcad" 
"cabd" 
"acbd" 
"bacd" 
"abcd"