fork download
  1. ; your code goes here
  2.  
  3. (defun all-indexes-1 (len numbers pattern)
  4. (if (null numbers)
  5. (list pattern)
  6. (let (patterns)
  7. (dolist (n numbers)
  8. (setf patterns
  9. (nconc patterns
  10. (all-indexes-1 len
  11. (remove n numbers)
  12. (cons n pattern)))))
  13. patterns)))
  14.  
  15. (defun all-indexes (len)
  16. (all-indexes-1
  17. len
  18. (loop for n below len collect n)
  19. nil))
  20.  
  21. (defun all-patterns (seq)
  22. (let ((len (length seq))
  23. (acc))
  24. (dolist (indexes (all-indexes len))
  25. (let ((new (make-sequence (type-of seq) len)))
  26. (loop for i from 0 by 1
  27. for j in indexes
  28. do
  29. (setf (aref new i)
  30. (aref seq j)))
  31. (push new acc)))
  32. acc))
  33.  
  34. (mapc #'print (all-patterns "abcd"))
  35.  
Success #stdin #stdout 0.02s 10616KB
stdin
Standard input is empty
stdout
"abcd" 
"bacd" 
"acbd" 
"cabd" 
"bcad" 
"cbad" 
"abdc" 
"badc" 
"adbc" 
"dabc" 
"bdac" 
"dbac" 
"acdb" 
"cadb" 
"adcb" 
"dacb" 
"cdab" 
"dcab" 
"bcda" 
"cbda" 
"bdca" 
"dbca" 
"cdba" 
"dcba"