SE701:Untangling a string
Found this assignement online. Seems more interesting than Traveling salesperson. So I'll do this first. For a complete description of the problem see https://www.se.auckland.ac.nz/wiki/images/4/4c/P45-meredith.pdf
Code so far:
(defun validate-tripcode (tripcode)
(let ((found (make-array 0 :fill-pointer 0 :adjustable t)) (count 0) (match-found NIL) (all-matches-found T))
(dolist (x tripcode)
(if (eql (position (first x) found :test #'string=) NIL)
(dotimes (i (- (length tripcode) (+ count 1)))
(setf match-found NIL)
(let* ((current-count (+ count i 1)) (current-point (nth current-count tripcode)))
(cond ((crossing-point-opposite current-point x) (vector-push-extend (first x) found) (setf match-found T)(return))))))
(setf all-matches-found (and all-matches-found match-found)))
all-matches-found))
(defun crossing-point-opposite (pair1 pair2)
(if (and (string= (first pair1) (first pair2)) (or (and (string= (second pair1) "o") (string= (second pair2) "u"))
(and (string= (second pair1) "u") (string= (second pair2) "o"))))
T))
(defun similar-crossing-points (pair1 pair2)
(if (or (and (string= (second pair1) "o") (string= (second pair2) "o"))
(and (string= (second pair1) "u") (string= (second pair2) "u")))
T))
(defun type1-move (tripcode)
(loop
with type1-list NIL
for i from 0 to (- (length tripcode) 2)
for x in tripcode
do (when (crossing-point-opposite x (nth (+ 1 i) tripcode))
(setf type1-list (list i (+ 1 i)))
(return type1-list))))