I’m trying to implement a function that returns a list of LIST (each list in LIST is the result of two elements swapped in list). It’s supposed to do a search based on the list formed from each swap. It is part of my program to solve the 8 puzzle problem. Here’s what i have so far
(setq *LIST* nil)
(defun swapped_list(lst)
(loop for j in (positions_to_swap) do
(setq *LIST* (rotatef (nth pos lst) (nth j lst))
*LIST*)
(swapped_list '(11 12 13 14 15 16 17 18 19))
If positions_to_swap is (0 2 5) and pos is 4, this should return
((15 12 13 14 11 16 17 18 19) (11 12 15 14 13 16 17 18 19) (11 12 13 14 16 15 17 18 19))
I’ve been spending countless hours trying to debug with no progress. I’ve tried many variants but none of them work.
Does the trick: