;; #!/bin/sbcl --script (with-open-file (file "aoc8input.txt") (let( (key "AAA") (steps 0) (goal-to-be-reached nil) (direction-line "") (route-hash (make-hash-table :test #'equalp :size 800)) ) ;;Prep work (setf direction-line (read-line file nil)) ;;(setf direction-line (subseq temp-first-line (+ 2 (position #\: temp-first-line :test #'equalp)) (length temp-first-line) )) ;;(setf yet-to-translate (seed-list manipulated-line)) ;;(print yet-to-translate) ;;(print translated) (print "----") (read-line file nil) (loop for line = (read-line file nil) with key = "" with left-value = "" with right-value = "" with cell = nil while line do (setf key (subseq line 0 (- (position #\= line :test #'equalp) 1) )) (setf left-value (subseq line (+ 1 (position #\( line :test #'equalp)) (position #\, line :test #'equalp) )) (setf right-value (subseq line (+ 2 (position #\, line :test #'equalp)) (position #\) line :test #'equalp) )) (setf (gethash key route-hash) (cons left-value right-value)) ) (loop for key being the hash-keys of route-hash using (hash-value value) do (format t "~%The value associated with the key ~a is ~A" key value)) (loop while (not goal-to-be-reached) do (loop for c across direction-line while (not goal-to-be-reached) do (print key) (incf steps) (if(char= c #\L) (setf key (car(gethash key route-hash))) (setf key (cdr(gethash key route-hash)))) (if (string= key "ZZZ") (setf goal-to-be-reached t)) )) (print steps)))