From 1c24854526f67007c884f4e6f791a73dc4c41b7b Mon Sep 17 00:00:00 2001 From: Hane Date: Tue, 26 Dec 2023 23:29:19 +0100 Subject: [PATCH 01/10] fuck you aoc5-2 --- src/aoc5-2.lisp | 302 +++++++++++++++++++++++++++++++++------------- src/aoc5input.txt | 2 +- src/aoc5test.txt | 2 +- src/aoc6-2.lisp | 7 +- 4 files changed, 225 insertions(+), 88 deletions(-) diff --git a/src/aoc5-2.lisp b/src/aoc5-2.lisp index b8a4e78..afd2e24 100644 --- a/src/aoc5-2.lisp +++ b/src/aoc5-2.lisp @@ -1,91 +1,231 @@ ;; #!/bin/sbcl --script -(defun seed-list (seed-string) - (let ((temp-string "") (source-parsed nil) (temp-source 0) (temp-range 0) (index 0) (return-list '())) - (loop for c across seed-string - do - (if(char= c #\Space) - (cond ((not source-parsed) - (setf temp-source (parse-integer temp-string) ) - (setf temp-string "") - (setf source-parsed t)) - (t (setf temp-range (parse-integer temp-string)) - (setf temp-string "") - ;(setf index temp-range) - (loop while (< index temp-range) - do - (push (+ temp-source index) return-list) - (incf index) - ) - (setf index 0) - (setf source-parsed nil))) - (setf temp-string (format nil "~a~c" temp-string c))) - finally - (setf temp-range (parse-integer temp-string)) - (loop while (< index temp-range) - do - (push (+ temp-source index) return-list) - (incf index))) - (format T "~%~A" return-list) - return-list)) - -(defun parse-map (seed source dest range) - (format T "~%~d-~d-~d-~d" seed source dest range) - (if(and(>= seed source) (<= seed (+ source range))) - (progn - (+ dest (- seed source))) - seed)) - -(defun parse-file (file - + (defun seed-list (seed-string) + (let ((temp-string "") (return-list '()) (base 0) (base-parsed nil) (range 0)) + (loop for c across seed-string + do + (if(char= c #\Space) + (if(not base-parsed) + (progn + (setf base (parse-integer temp-string)) + (setf return-list (append return-list (list base) )) + (setf base-parsed t) + (setf temp-string "")) + (progn + (setf range (parse-integer temp-string)) + (setf return-list (append return-list (list (+ base (- range 1)) ))) + (setf base-parsed nil) + (setf temp-string ""))) + (setf temp-string (format nil "~a~c" temp-string c))) + finally + (setf range (parse-integer temp-string)) + (setf return-list (append return-list (list (+ base (- range 1)) )))) + return-list)) (with-open-file (file "aoc5input.txt") - (let( (digit-line nil) (temp-first-line "") (temp-string "") (manipulated-line "") (code '()) (numbers '()) (translated '())) + (let( (lowest -1) (digit-line nil) (dest-parsed nil) (temp-first-line "") (range "") (temp-string "") + (manipulated-line "") (dest-exploded '()) (source-exploded '()) (yet-to-translate '()) (translated '())) ;;Prep work (setf temp-first-line (read-line file nil)) (setf manipulated-line (subseq temp-first-line (+ 2 (position #\: temp-first-line :test #'equalp)) (length temp-first-line) )) - (setf numbers (seed-list manipulated-line)) - (dolist (item numbers) (push nil translated)) - (print numbers) + (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) - while line - do - (when (equalp 0 (length line)) - (let((current-index 0)) - (print "hola") - (dolist (item translated) - (setf (nth current-index translated) nil) - (incf current-index)))) - (loop for c across line - do - (if(digit-char-p c) - (progn - (setf digit-line t) - (setf temp-string (format nil "~a~c" temp-string c))) - (if digit-line - (progn - (push (parse-integer temp-string) code) - (setf temp-string "")))) - finally - (when digit-line - (push (parse-integer temp-string) code) - (print code) - (let((current-index 0) (translation 0)) - (dolist (item numbers) - (when (not (nth current-index translated)) - (setf translation (parse-map item (nth 1 code) (nth 0 (last code)) (first code))) - (when (not (equal item translation)) - (setf (nth current-index translated) t) - (setf (nth current-index numbers) translation) - (setf translation 0))) - (incf current-index))) - (setf temp-string "") + (loop for line = (read-line file nil) + while line + do + (when (equalp 0 (length line)) + (print (append yet-to-translate translated)) + (print "----") + (setf yet-to-translate (append yet-to-translate translated)) + (setf translated '())) + (loop for c across line + do + (if(digit-char-p c) + (progn + (setf digit-line t) + (setf temp-string (format nil "~a~c" temp-string c))) + (if digit-line + (progn + (if dest-parsed + (push (parse-integer temp-string) source-exploded) + (progn + (setf dest-parsed t) + (push (parse-integer temp-string) dest-exploded))) + (setf temp-string "")))) + finally + (when digit-line + ;;RANGES + ;;(format T "~%~a" temp-string) + ;;(print "newline") + (setf range (parse-integer temp-string)) + (setf source-exploded (append source-exploded (list (+ (first source-exploded) (- range 1))))) + (setf dest-exploded (append dest-exploded (list (+ (first dest-exploded) (- range 1))))) + ;;DANGER ZONE + (let( (unqualified '() ) (done '()) (source-base (nth 0 source-exploded)) (source-end (nth 1 source-exploded)) + (dest-base (nth 0 dest-exploded)) (dest-end (nth 1 dest-exploded)) (len (list-length yet-to-translate)) ) + (loop with index = 0 + with current-base = 0 + with current-end = 0 + while (< index len) + do + (setf current-base (nth index yet-to-translate)) + (setf current-end (nth (+ index 1) yet-to-translate)) + ;;(format T "~%~a ~a ~a ~a" "Current base:" current-base "Current end:" current-end) + ;;(format T "~%~a ~a ~a ~a" "Source base: " source-base "Source end: " source-end) + ;;(format T "~%~a ~a ~a ~a" "Dest base: " dest-base "Dest end: " dest-end) + (if(or(and(<= current-base source-end) (>= current-base source-base)) (and(>= current-end source-base) (<= current-end source-end)) + (and(<= source-end current-end) (>= source-base current-base)) ) + (progn + ;;(print "based") + (if (> current-end source-end) + (progn + (setf unqualified (append unqualified (list (+ source-end 1) current-end))) + (setf done (append done (list dest-end )))) + (setf done (append done (list (- dest-end (- source-end current-end))) ))) + (if (< current-base source-base) + (progn + (setf unqualified (append unqualified (list current-base (- source-base 1) ))) + (push dest-base done)) + (push (+ dest-base (- current-base source-base)) done)) + ;;(format T "~%~a ~A" "Done:" done) + (setf translated (append translated done)) + (setf done '())) + (progn + ;;(print "unbased") + (setf unqualified (append unqualified (list current-base current-end) )))) + ;;(format T "~%~a ~A ~a ~A" "Run unqualified:" unqualified "Translated:" translated) + (setf index (+ index 2))) + (setf yet-to-translate unqualified) ) + ;;CLEANUP + ;;(format T "~%~a ~A" "SE:" source-exploded) + ;;(format T "~%~a ~A" "DE:" dest-exploded) + ;;(format T "~%~a ~A ~a ~A" "Translated:" translated "Yet to translate:" yet-to-translate) (setf digit-line nil) - (setf code '())) )) - (format T "~%~a ~A" "Result: " numbers) - (let( (lowest (first numbers))) - (dolist (item numbers) - (when (< item lowest) (setf lowest item))) - (print lowest)))) + (setf dest-parsed nil) + (setf temp-string "") + (setf source-exploded '()) + (setf dest-exploded '()) ) + )) + + (format T "~%~a ~A" "final: " (append yet-to-translate translated)) + (print (list-length (append yet-to-translate translated))) + (dolist (item (append yet-to-translate translated)) + (when (or (= lowest -1) (< item lowest)) + (setf lowest item))) + (print lowest))) + + + + +;; ;; #!/bin/sbcl --script +;; (defun seed-list (seed-string file-content) +;; (let ((temp-string "") (lowest -1) (base 0) (base-parsed nil) (range 0)) +;; (loop for c across seed-string +;; do +;; (if(char= c #\Space) +;; (if(not base-parsed) +;; (progn +;; (setf base (parse-integer temp-string)) +;; (setf base-parsed t) +;; (setf temp-string "")) +;; (progn +;; (setf range (parse-integer temp-string)) +;; (loop with current-index = 0 +;; with return-value = 0 +;; while (< current-index range) +;; do +;; (format T "~%~a ~d" "FS:" (+ base current-index)) +;; (setf return-value (transform-value (+ base current-index) file-content)) +;; ;(format T "~%~a ~d-~d-~d-~d ~a ~d" "Seed-List:" base range current-index (+ base current-index) "Retval:" return-value) +;; (if (equalp -1 lowest) +;; (setf lowest return-value) +;; (when(< return-value lowest) +;; (setf lowest return-value))) +;; (incf current-index)) +;; (setf base-parsed nil) +;; (setf temp-string ""))) +;; (setf temp-string (format nil "~a~c" temp-string c))) +;; finally +;; (setf range (parse-integer temp-string)) +;; (loop with current-index = 0 +;; with return-value = 0 +;; while (< current-index range) +;; do +;; (format T "~%~a ~d ~a ~d" "FS:" (+ base current-index) "Index:" current-index) +;; (setf return-value (transform-value (+ base current-index) file-content)) +;; ;(format T "~%~a ~d-~d-~d-~d ~a ~d" "Seed-List:" base range current-index (+ base current-index) "Retval:" return-value) +;; (if (equalp lowest -1) +;; (setf lowest return-value) +;; (when(< return-value lowest) +;; (setf lowest return-value))) +;; (incf current-index)) +;; ) +;; lowest)) + +;; (defun transform-value (seed file-content) +;; (let( (digit-line nil) (stream "") (final-seed 0) (temp-string "") (code '()) (translated nil)) +;; (setf final-seed seed) +;; (setf stream (make-string-input-stream file-content)) +;; (loop for line = (read-line stream nil) +;; while line +;; do +;; ;(print line) +;; (when (equalp 0 (length line)) +;; (setf translated nil)) +;; (loop for c across line +;; do +;; (if(digit-char-p c) +;; (progn +;; (setf digit-line t) +;; (setf temp-string (format nil "~a~c" temp-string c))) +;; (if digit-line +;; (progn +;; (push (parse-integer temp-string) code) +;; (setf temp-string "")))) +;; finally +;; (when digit-line +;; (push (parse-integer temp-string) code) +;; ;(print code) + +;; (when (not translated) +;; (let( (temp-translate 0) ) +;; (setf temp-translate (parse-map final-seed (nth 1 code) (nth 0 (last code)) (first code))) +;; ;(format T "~%~a ~d" "Translated to:" final-seed) +;; (when(not(equalp temp-translate final-seed)) +;; (setf final-seed temp-translate) +;; (setf translated t)))) + +;; (setf temp-string "") +;; (setf digit-line nil) +;; (setf code '())) ) + +;; ) +;; final-seed)) + +;; (defun parse-map (seed source dest range) +;; ;(format T "~%~a ~d-~d-~d-~d" "Parse-map:" seed source dest range) +;; (if(and(>= seed source) (<= seed (+ source range))) +;; (progn +;; (+ dest (- seed source))) +;; seed)) + +;; (with-open-file (file "aoc5input.txt") +;; (let( (file-content "") (manipulated-line "") ) +;; ;;Prep work +;; (setf file-content (read-line file nil)) +;; (setf manipulated-line (subseq file-content (+ 2 (position #\: file-content :test #'equalp)) (length file-content) )) +;; (setf file-content "") +;; (read-line file nil) + +;; (loop for line = (read-line file nil) +;; while line +;; do +;; (if(not(string= file-content "")) +;; (setf file-content (format nil "~a~%" file-content))) +;; (setf file-content (format nil "~a~a" file-content line)) +;; ) +;; ;(print manipulated-line) +;; (print (seed-list manipulated-line file-content)) )) diff --git a/src/aoc5input.txt b/src/aoc5input.txt index 6cab5eb..bd43a49 100644 --- a/src/aoc5input.txt +++ b/src/aoc5input.txt @@ -274,4 +274,4 @@ humidity-to-location map: 2575348595 2130499969 195699098 593882556 705484119 648158843 3871554698 3932373353 42274873 -2998499327 1650316948 79272282 \ No newline at end of file +2998499327 1650316948 79272282 diff --git a/src/aoc5test.txt b/src/aoc5test.txt index bd902a4..f756727 100644 --- a/src/aoc5test.txt +++ b/src/aoc5test.txt @@ -30,4 +30,4 @@ temperature-to-humidity map: humidity-to-location map: 60 56 37 -56 93 4 \ No newline at end of file +56 93 4 diff --git a/src/aoc6-2.lisp b/src/aoc6-2.lisp index 2aef4af..e8a2d09 100644 --- a/src/aoc6-2.lisp +++ b/src/aoc6-2.lisp @@ -25,7 +25,6 @@ (with-open-file (file "aoc6input.txt") (let( (file-lines '()) (time-list '()) (distance-list '()) (result 1) ) - (loop for line = (read-line file nil) while line do @@ -39,7 +38,5 @@ do ;(print (num-ways-to-win (nth index time-list) (nth index distance-list))) (setf result (* result (num-ways-to-win (nth index time-list) (nth index distance-list)))) - (incf index) - ) - (print result) - )) + (incf index)) + (print result))) From d530bda461c7b4d1a3fafe53b8d6a30afedaeadb Mon Sep 17 00:00:00 2001 From: Hane Date: Sat, 30 Dec 2023 18:46:13 +0100 Subject: [PATCH 02/10] full aoc8 fuck you --- src/aoc11.lisp | 97 ++++++ src/aoc11input.txt | 140 ++++++++ src/aoc11test.txt | 10 + src/aoc8-2.lisp | 175 ++++++++++ src/aoc8.lisp | 40 +++ src/aoc8input.txt | 796 +++++++++++++++++++++++++++++++++++++++++++++ src/aoc8test.txt | 11 + 7 files changed, 1269 insertions(+) create mode 100644 src/aoc11.lisp create mode 100644 src/aoc11input.txt create mode 100644 src/aoc11test.txt create mode 100644 src/aoc8-2.lisp create mode 100644 src/aoc8.lisp create mode 100644 src/aoc8input.txt create mode 100644 src/aoc8test.txt diff --git a/src/aoc11.lisp b/src/aoc11.lisp new file mode 100644 index 0000000..33d2e98 --- /dev/null +++ b/src/aoc11.lisp @@ -0,0 +1,97 @@ + +(defun input-parsing (path) + (with-open-file (file path) + (let( (galaxy-columns '()) (data-line nil) (galaxies (make-array 0 :adjustable t)) (current-line 0) ) + ;;Prep work + ;;(defparameter keys (make-array 0 :adjustable t)) + ;;(defparameter parsed '()) + ;;(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) + ;; (let( (size (+ 1 (length keys))) ) + ;; (adjust-array keys size) (decf size) + ;; (setf (aref keys size) key) )) + + (loop for line = (read-line file nil) + with key = "" + with left-value = "" + with right-value = "" + while line + do + (when(zerop current-line) + (dotimes (i (length line)) + (push nil galaxy-columns))) + (loop for c across line + with char-position = 0 + do + (when (char= c #\#) + (let( (size (+ 1 (length galaxies))) ) + (adjust-array galaxies size) (decf size) + (setf (aref galaxies size) (cons current-line char-position)) ) + (format T "~% ~d ~A" char-position galaxy-columns) + (setf (nth char-position galaxy-columns) t) + ;;(setf (nth i parsed) nil) + (setf data-line t)) + (incf char-position) + finally + (if (not data-line) + (incf current-line)) + (incf current-line) + (setf data-line nil)) + ) + galaxies))) + +(print (input-parsing "aoc11test.txt")) + ;;(print "Hola") + ;;(print (aref keys 0)) + + ;; (incf (nth 0 steps-per-key)) + ;; (if(char= c #\L) + ;; (setf (aref keys 0) (car(gethash (aref keys 0) route-hash))) + ;; (setf (aref keys 0) (cdr(gethash (aref keys 0) route-hash)))) + ;; ;;(print (aref keys 0)) + + ;; (when(char= (char (aref keys 0) 2) #\Z) + ;; (format T "~%~a ~d" "Ayo on key 0 found at: " (nth 0 steps-per-key)) + ;; (dotimes (i (length keys)) + ;; ;;(print (+ i 1)) + ;; ;;(print (length keys)) + ;; ;;(when (< (+ i 1) (length keys)) + ;; (when (> i 0) + + ;; ;;WTF + ;; (sb-thread:make-thread (lambda () (hashmap-parse route-hash direction-line (length direction-line) (- i 1) (nth 1 steps-per-key) (nth 0 steps-per-key)) ) ) + ;; ;;(format T "~%~d" i) + ;; ) + ;; ) + ;; (loop while (not (every #'null parsed)) + ;; do + ;; ;;(print parsed) + ;; (sleep 1)) + ;; (dotimes (i (length parsed)) + ;; (if (= i 0) + ;; (setf (nth i parsed) nil) + ;; (setf (nth i parsed) t))) + + ;; (loop with i = 1 + ;; with failure = nil + ;; while (and(< i (length keys)) (not failure)) + ;; do + ;; (setf (nth i steps-per-key) (nth 0 steps-per-key)) + ;; (if(char= (char (aref keys i) 2) #\Z) + ;; (progn + ;; (incf i) ) + ;; (setf failure t)) + ;; finally + ;; (if(= i (length keys)) + ;; (setf goal-to-be-reached t)) + ;; )) + ;; ) + ;; (print (nth 0 steps-per-key)) + ;; (setf keys (make-array 0 :adjustable t)) + ;; (setf parsed '()))) + ;; ) diff --git a/src/aoc11input.txt b/src/aoc11input.txt new file mode 100644 index 0000000..794d39e --- /dev/null +++ b/src/aoc11input.txt @@ -0,0 +1,140 @@ +.....................#......#...................#...............#........................................#.................................. +...........................................................#.............................................................#.................. +.....................................................................#.........#......#...........#.............#........................... +.....................................................#.......................................#.............................................. +......#.................................#..........................................................................................#........ +....................#.........#.............................................................................#............................... +..#.........................................................#.............................................................................#. +........................................................................................#...........#..................#.................... +........#....................................#........................#.........................................................#........... +..............................................................................#................................#............................ +..................................................#............#............................................................................ +.........................#......#........#................................................#..........................................#...... +......#..............................................................................#...............#...................................... +...................................................................#........................................................................ +....................#...........................#............................................................#..............#.....#......... +..................................#....................#.........................................#......#..............................#.... +.#.......................................................................................................................................... +........#.....#........................#...........#.............#.....................#.................................................... +..........................#.................................#.....................#......................................................... +.............................................................................................................................#.............# +...................................#......................................................#....................#............................ +.....................#...................#............#..................#.............................................#...........#........ +..............................................................................................#............................................. +....#..........#...............#..........................................................................#................................. +.............................................#.............................................................................................. +...................................................................#..............#.................................#....................... +..................#........................................................#................................................................ +..#.................................#...................#..............................#.........................................#.......#.. +...............................................................#...............#.....................#..........#.........#................. +.........#......................#.............................................................#............................................. +..............#...............................#............................................................................................. +........................................#.................................#............................................................#.... +..............................................................................................................#......#......#............... +.........................#..........#.............................................#........#................................................ +....................................................................#.....................................#................................. +....#...............#........#...............................#........................#........................................#............ +........................................................#................................................................................... +............................................#...........................#......................#.....#...................................... +.........................................................................................#.............................................#.... +...........#....................#..................................#.................................................#...........#.......... +.#.......................................................................................................................................... +................#........................#..........#....................................................................................... +........................#........................................................................................#.......................... +........................................................................#.........#...................#...................#................. +........................................................#......................................................................#............ +.....#.....................................................................................#................................................ +...............#...................................#.................#..............................................................#....... +.........#..................#..................................#..................................................#......................... +......................................#.......#....................................#......................................................#. +..........................................................................................................#......................#.......... +...#..............#.......................#.....................................................#........................................... +................................#...............................................#..........#................................................ +..........................#......................#......................#................................................................... +..................................................................#................................#........................................ +......................................................#.................................#.........................#...................#..... +..............#..........................#..................................................................................#............... +......#......................#.................................................................#...........#................................ +.............................................................................#.............................................................. +.......................#..........................#......................................................................#..........#....... +.#.................................#................................................................#....................................#.. +........#......#................................................#...............................................#........................... +..........................................................................#.....#.........................#...........#.....#............... +............................#..............#..........#....................................#................................................ +............................................................................................................................................ +............#..........#.................................................................................................................... +............................................................#.......................#..............#........................................ +.....................................#...............................#...................................#.................................. +.........#.....................................................................#.....................................#...............#.....# +#.............#............................................................................................................................. +......................................................#....................................#....................................#........... +...................................................................#............................................#........................... +............................................................................................................................................ +....................#............................#................................................#......................................#.. +.............................#...................................................#.......................................................... +.........................................................................#...............#.................#................................ +.............#.........#.........#.....#......................#............................................................#................ +............................................................................................................................................ +.............................................#..........#.....................#..................................#.......................... +............................................................................................................................................ +...................................#.............#................#.....#.....................................................#............. +....#.....................#..................................#.............................................................................. +............................................................................................................................................ +#.....................................#...................................................................................#................. +...............................................#......................#.....#...................................#........................... +.........#...................#.....................................................#.................#...................................... +.......................#...............................#........................................#..............................#............ +...#.....................................#..................................................................#............................... +...................................................#......................................#...........................................#..... +.................#.......................................................................................................................... +...................................................................................................................#......#................. +.................................#..............#.....#......................#.................#.........#.................................. +#....................................................................#........................................#...........................#. +............................................................................................................................................ +.........................#.................................................................................................................. +...............................#.......................................................................................#.................... +..........#...................................#..................#.....................#....................#............................... +............................................................................#.....#......................................................... +....#............#............................................................................#.......#..........#.......................... +..................................................................................................................................#......... +...................................#...........................................#............................................................ +.............................#..........................#.................................#........#........................................ +..............#....................................................#........................................#.............#...........#..... +...............................................#.............#.......................................................#...................... +........#..............................................................#.................................................................... +.......................................................................................#........#........................................... +......................#........#.........................#..................#........................#......................#............... +.#.........#.....#..............................................#........................................................................#.. +.....................................................#...................................................................................... +.........................................#...........................#..............................................#....................... +.............................................................#................................................#................#............ +......#.......................................#.......................................#...............#..................................... +....................#.......#............................#................#...........................................................#..... +...........#.....................................................................................................#.......................... +..........................................................................................#..............#.................................. +..................................................#..........................................................................#.............. +...............#............................................#.....................................................................#......... +........................#...........................................#............................#..................#....................... +................................................................................#..............................#.......................#.... +......................................#...................................#..............#..............#................................... +..#............................................#..............#...........................................................#................. +.........#........................#...................#..................................................................................... +.............................#.............................................................................................................. +....................................................................................#....................................................... +.........................#.............#............................................................#......#......#.........#......#........ +...................#...........................................................................#...........................................# +.......#...............................................#.....#........#..........#.......................................................... +..............#....................#........................................................................................................ +........................................................................................................#.................#...........#..... +..#...............................................................#.........#.......#....................................................... +.........#......................#..........................#.....................................#............#............................. +...................#.................................#.................................................................#.................... +....................................#....................................................................................................... +...........................#......................................................................................................#......... +............................................#.................#............#...................#.......#...................#................ +............#.....................................#......................................................................................... +...........................................................................................................#......#......................... +.....................................#..............................................#......#................................................ +.........................................................................#..............................................#................... +#....................#........#...................................................................#.....................................#... +.....#........................................#.........#........................#.......................................................... \ No newline at end of file diff --git a/src/aoc11test.txt b/src/aoc11test.txt new file mode 100644 index 0000000..a0bda53 --- /dev/null +++ b/src/aoc11test.txt @@ -0,0 +1,10 @@ +...#...... +.......#.. +#......... +.......... +......#... +.#........ +.........# +.......... +.......#.. +#...#..... \ No newline at end of file diff --git a/src/aoc8-2.lisp b/src/aoc8-2.lisp new file mode 100644 index 0000000..37a11e9 --- /dev/null +++ b/src/aoc8-2.lisp @@ -0,0 +1,175 @@ +#!/bin/sbcl --script + +(defparameter keys (make-array 0 :adjustable t)) +(defparameter parsed '()) +(defparameter steps-per-key '()) +(print (sb-thread:list-all-threads)) + +(with-open-file (file "aoc8input.txt") + (let( (goal-to-be-reached nil) (direction-line "") (route-hash (make-hash-table :test #'equalp :size 800)) ) + ;;Prep work + (defparameter keys (make-array 0 :adjustable t)) + (defparameter parsed '()) + (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 = "" + 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)) + (when(char= #\A (char key 2)) + (let( (size (+ 1 (length keys))) ) + (adjust-array keys size) (decf size) + (setf (aref keys size) key) )) + ) + + ;;(print keys) + ;;(print parsed) + (dotimes (i (length keys)) + (push 0 steps-per-key) + (push t parsed)) + (setf (nth 0 parsed) nil) + ;;(print steps-per-key) + ;;(print parsed))) + + (loop while (not goal-to-be-reached) + do + (loop for c across direction-line + while (not goal-to-be-reached) + do + ;;(print "Hola") + ;;(print (aref keys 0)) + (incf (nth 0 steps-per-key)) + (if(char= c #\L) + (setf (aref keys 0) (car(gethash (aref keys 0) route-hash))) + (setf (aref keys 0) (cdr(gethash (aref keys 0) route-hash)))) + ;;(print (aref keys 0)) + + (when(char= (char (aref keys 0) 2) #\Z) + ;;(format T "~%~a ~d" "Ayo on key 0 found at: " (nth 0 steps-per-key)) + (dotimes (i (length keys)) + ;;(print (+ i 1)) + ;;(print (length keys)) + ;;(when (< (+ i 1) (length keys)) + (when (> i 0) + ;;WTF + (sb-thread:make-thread (lambda (x hashmap dir strlen steps) (hashmap-parse hashmap dir strlen x steps) ) :arguments (list i route-hash direction-line (length direction-line) (nth i steps-per-key) ) ) + ;;(format T "~%~d" i) + ) + ) + ;;(print parsed) + (loop while (not (every #'null parsed)) + do + (print parsed) + (sleep 1)) + (print steps-per-key) + (setf goal-to-be-reached t) + (print (apply #'lcm (append steps-per-key (list (length direction-line))))))))) + (print "awaa") + ;;(print (nth 0 steps-per-key)) + (setf keys (make-array 0 :adjustable t)) + (setf parsed '())) + + (defun starting-char (strlen steps) + (loop while (>= steps strlen) + do + (setf steps (- steps strlen))) + steps) + + (defun hashmap-parse (hashmap direction-string strlen key-position steps) + (let( (current-char (starting-char strlen steps) ) (z-found nil) ) + ;;(print steps) + (loop while (not z-found) + do + (incf steps) + ;;(format T "~%~c" direction-char) + ;;(print current-char) + (if(char= (char direction-string current-char) #\L) + (setf (aref keys key-position) (car(gethash (aref keys key-position) hashmap))) + (setf (aref keys key-position) (cdr(gethash (aref keys key-position) hashmap)))) + + (incf current-char) + (when(= current-char strlen) + (setf current-char 0)) + (when(char= (char (aref keys key-position) 2) #\Z) + (setf z-found t) + (setf (nth key-position parsed) nil) + (setf (nth key-position steps-per-key) steps)) + ) + )) + +;; (defvar *directions*) +;; (defvar *ndirections*) +;; (defvar *map* (make-hash-table :test #'equal)) + +;; ;;(setf *print-circle* t) +;; (defun parse-file (path) +;; (with-open-file (file path) +;; (loop +;; :with first-line = (read-line file nil) +;; :with second-line = (read-line file nil) +;; :initially +;; ;; Parse first line +;; (setf *directions* (coerce first-line 'list)) +;; ;; Turn directions into a cyclical list +;; (setf *ndirections* (length *directions*)) +;; (setf (cdr (last *directions*)) *directions*) +;; :for line = (read-line file nil) +;; :while line +;; :for key = (subseq line 0 3) +;; :for left = (subseq line 7 10) +;; :for right = (subseq line 12 15) +;; :do +;; (setf (gethash key *map*) (cons left right))))) + +;; (defun part-1 () +;; (loop :for direction = (car p) +;; :for current-node = "AAA" :then (if (char= #\L direction) (car paths) (cdr paths)) +;; :for p = *directions* :then (cdr p) +;; :for paths = (gethash current-node *map*) +;; :for n :from 0 +;; :until (string= current-node "ZZZ") +;; ;; :do (format t "Step ~S:~%~tCurrent node: ~S~%~tLast direction: ~S~% Possible paths: ~S~%" n current-node direction paths) +;; :finally +;; (print n))) + +;; (defun part-2 () +;; (loop :with initial-keys = (loop :for key :being :the :hash-keys :of *map* :if (char= (char key 2) #\A) :collect key) +;; :with distance-maps = (loop :for key :in initial-keys :collect (make-hash-table :test #'equal)) +;; :for key :in initial-keys +;; :for distance-map :in distance-maps +;; :do +;; (setf (gethash key distance-map) 0) +;; (explore-map distance-map key 1) +;; :finally +;; (return (apply #'lcm (append (mapcar #'cdar (mapcar #'distance-to-z distance-maps)) (list *ndirections*)))) +;; ;;(return distance-maps) +;; )) + +;; (defun distance-to-z (distance-map) +;; (loop :with z-keys = (loop :for key :being :the :hash-keys :of distance-map :if (char= (char key 2) #\Z) :collect key) +;; :for key :in z-keys +;; :collect (cons key (gethash key distance-map)))) + +;; (defun explore-map (distance-map node distance) +;; (let ((options (gethash node *map*))) +;; (when (> (gethash (car options) distance-map 9999) distance) +;; ;; We found a shorter path +;; (setf (gethash (car options) distance-map) distance) +;; (explore-map distance-map (car options) (1+ distance))) +;; (when (> (gethash (cdr options) distance-map 9999) distance) +;; ;; We found a shorter path +;; (setf (gethash (cdr options) distance-map) distance) +;; (explore-map distance-map (cdr options) (1+ distance))) +;; )) diff --git a/src/aoc8.lisp b/src/aoc8.lisp new file mode 100644 index 0000000..b4ecddd --- /dev/null +++ b/src/aoc8.lisp @@ -0,0 +1,40 @@ +;; #!/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))) diff --git a/src/aoc8input.txt b/src/aoc8input.txt new file mode 100644 index 0000000..ac178d0 --- /dev/null +++ b/src/aoc8input.txt @@ -0,0 +1,796 @@ +LRRLRLRRRLLRLRRRLRLLRLRLRRLRLRRLRRLRLRLLRRRLRRLLRRRLRRLRRRLRRLRLRLLRRLRLRRLLRRRLLLRRRLLLRRLRLRRLRLLRRRLRRLRRRLRRLLRRRLRRRLRRRLRLRRLRLRRRLRRRLRRLRLRRLLRRRLRRLLRRLRRLRLRLRRRLRLLRRRLRRLRRRLLRRLLLLLRRRLRRLLLRRRLRRRLRRLRLLLLLRLRRRLRRRLRLRRLLLLRLRRRLLRRRLRRRLRLRLRRLRRLRRLRLRLLLRLRRLRRLRRRLRRRLLRRRR + +RBX = (TMF, KTP) +RBP = (MKS, MKS) +CGR = (XDR, VDX) +KBX = (DGP, JKM) +BNJ = (NJC, QRL) +BXQ = (DKX, CJQ) +NDX = (PHJ, TRQ) +KFQ = (KXN, GBQ) +LRF = (CTS, MTT) +RTN = (VMK, JTK) +QKP = (FDS, SFG) +BVB = (BHS, VRQ) +NBT = (BPJ, DFF) +HQM = (QMV, XVG) +XMR = (RKH, NJQ) +PHC = (XHP, DKM) +HTX = (BXK, BQP) +TPJ = (TNQ, QDX) +RDJ = (KHB, MFG) +XTF = (PPR, FHG) +DVA = (DBM, MVD) +HFP = (CXV, VCD) +HPS = (GTD, NBL) +LBK = (FVN, LHX) +KKS = (FKM, LHN) +FJV = (LVN, PLP) +MLH = (SFR, RJK) +SVQ = (RCS, FFD) +PTB = (TMC, QCR) +RFL = (RXP, VRL) +PTH = (XTS, GFG) +QNM = (TJR, MHX) +BJT = (PJG, SHG) +JJD = (FMJ, QVV) +GMX = (CLD, QRM) +DGZ = (BSL, BRS) +BVM = (SFC, JGD) +GNQ = (PLP, LVN) +XPG = (VLH, BCM) +PND = (RXV, VGM) +RNV = (GVL, MTB) +JSG = (QVP, XCX) +QHP = (KQG, BML) +XBK = (NPP, CRN) +QRL = (RQH, BGH) +HDJ = (VRQ, BHS) +XPD = (HSB, LRC) +KJK = (XCV, MDG) +NJB = (RKL, SHQ) +MCQ = (XFT, MRQ) +QRC = (XVS, CSN) +FCT = (DFF, BPJ) +MTF = (PQT, CNQ) +RXG = (QVP, XCX) +MVZ = (QRC, GHJ) +RKL = (QQM, BFT) +VRT = (GMJ, BDK) +BNS = (HQV, HPS) +JSQ = (HTC, PGD) +BHB = (VGQ, BTM) +NLP = (RKB, XQB) +FGF = (CVK, VRT) +FPM = (GDS, LTG) +BCX = (NDX, GSL) +GVL = (VCX, PSP) +KRM = (MHK, JCX) +GLJ = (XNX, RKP) +LBV = (FDC, TPJ) +GSP = (KMC, LQR) +TFR = (HXJ, MFJ) +DLX = (FNK, GLJ) +DKX = (XSR, LHP) +SVR = (KPX, QTM) +JMT = (GXV, RTX) +XSX = (HHD, HHD) +RJF = (BRH, HGP) +BDK = (TGX, HKP) +TFF = (DSX, DSX) +TJR = (BKB, LCB) +BDQ = (CLD, QRM) +NTC = (BQL, BQL) +CVS = (RQC, FFV) +BML = (VNT, JRH) +CBK = (TGB, RTN) +HQV = (GTD, NBL) +PDT = (SRQ, MLD) +RXV = (KJK, FCD) +XTS = (SCG, KQJ) +PXG = (LKG, MTQ) +PCX = (FKJ, FCV) +HKR = (LMK, BJR) +CKK = (XSX, XSX) +TNP = (TDH, JPR) +PCH = (RBP, PQH) +KHB = (RQR, BXQ) +CJZ = (CNC, HJX) +JPN = (FRP, QTB) +RKP = (NKH, FQC) +BDP = (GCM, VKT) +HQX = (TQF, NJB) +PFV = (FPM, VNP) +NFQ = (GFX, GXH) +STX = (MCQ, DNS) +CKX = (CFS, BNS) +NRJ = (SBG, TLK) +DHS = (VBH, VMT) +TVL = (BPQ, NBM) +QTF = (MPS, RJB) +FHV = (LMK, BJR) +JCV = (JSQ, STQ) +RGX = (GVL, MTB) +CTS = (PCB, GJV) +RCS = (TNT, XTF) +PCS = (NJH, RLX) +KNG = (CHP, FNN) +FJL = (KKH, QGQ) +CPK = (KTX, CGR) +BLF = (PCQ, TKN) +FCR = (STF, SVQ) +BSL = (GFJ, CDL) +FKS = (GRG, JSB) +FCM = (LFX, RJF) +XLK = (CDP, CBD) +KNB = (VGQ, BTM) +KGC = (TJR, MHX) +JHM = (JSP, XDN) +HFN = (STF, SVQ) +GCM = (CKX, KPS) +CGV = (MHK, JCX) +TQP = (JRM, XSB) +GSM = (FJV, GNQ) +KBL = (DLX, BGD) +CBC = (MQK, RRF) +NJM = (KLQ, BVL) +THG = (CPG, PND) +DXP = (HDJ, BVB) +DTT = (XDN, JSP) +PLP = (BKF, FGP) +MSZ = (MVD, DBM) +BQC = (NPL, VXF) +CGB = (LRM, MTH) +RLX = (DBT, RJN) +RXP = (HFP, JNS) +TTH = (QNF, KNG) +LHS = (QFR, GTN) +NBL = (THT, VTQ) +DRS = (PJH, STX) +PSP = (CPK, QKF) +PPR = (LQK, VSN) +QHT = (RLG, TDG) +FVM = (MLR, HXF) +DHB = (CQC, BKK) +MVP = (GHJ, QRC) +TDG = (RVX, CDB) +LKN = (HXF, MLR) +CNR = (KCV, CDR) +SMC = (BBR, BMS) +QDP = (LXV, VPS) +LLD = (CGC, NGQ) +KXN = (PRR, PSR) +LRC = (SHB, PBK) +SQD = (LBV, CRP) +QTB = (KNS, JTS) +MTT = (GJV, PCB) +GMV = (JNH, MJF) +DTG = (SQD, KVV) +RTV = (DSB, SJB) +CDL = (FTQ, CPN) +JHR = (JRM, XSB) +BFP = (PFG, MTD) +DTB = (NDX, GSL) +SQM = (CXL, NBD) +NBP = (KBN, LQH) +BTC = (LJT, TCV) +PQT = (PXG, BSF) +QDH = (FPM, VNP) +VPT = (PRT, VHJ) +VKC = (GXK, QSB) +NXB = (QKP, TGK) +FDF = (VRT, CVK) +NTG = (FRV, BQR) +RKB = (PHC, JSD) +MHV = (XXL, THG) +PHV = (SNM, TFR) +XRK = (JNN, LKR) +XVS = (CBK, NNM) +GDQ = (BDQ, GMX) +TKR = (CKJ, LVQ) +XCX = (LSP, FNB) +JCX = (FGF, FDF) +MFJ = (DBB, HBH) +BQP = (HRT, DQD) +VNC = (BDQ, GMX) +SSC = (LQH, KBN) +TJD = (QFV, KRS) +NKL = (CKK, DDC) +NTM = (QHG, MCC) +JBQ = (HXV, JPN) +DGP = (FVM, LKN) +SJB = (LRQ, DMG) +LJT = (MMT, MDL) +RFC = (MVM, JXP) +FFV = (TPG, QMD) +PJH = (DNS, MCQ) +VCD = (FHV, HKR) +MPS = (DHH, LPT) +VHJ = (RGX, RNV) +FLT = (FRF, NHG) +DSF = (SDV, VKC) +HJQ = (CDR, KCV) +BQR = (PDX, PMX) +CRJ = (BPN, KKS) +MQN = (PNN, DHB) +KCC = (KMC, LQR) +BTH = (VLH, BCM) +KNS = (GGM, SJS) +SCG = (MBF, RDR) +VDQ = (JNN, LKR) +XFT = (VPT, FLH) +RDR = (GTF, GJR) +CXS = (RRF, MQK) +XDN = (SSF, VGC) +JPR = (VGX, TCF) +BTF = (LKM, GBG) +GCJ = (VPS, LXV) +FGJ = (XVG, QMV) +MBF = (GJR, GTF) +TPG = (TND, QSF) +BNR = (BHG, SMC) +GJV = (FLB, PCX) +LQF = (BJT, KTN) +VSB = (JVB, FVK) +NHB = (HQX, LLQ) +CKC = (PJD, TRS) +JVB = (QQV, NRS) +BKK = (LSR, LJN) +SBV = (GTN, QFR) +JMK = (MFG, KHB) +LPX = (NBP, SSC) +KLJ = (CDX, VTL) +KQJ = (RDR, MBF) +VMK = (JXJ, BMT) +TRS = (LQM, JJD) +KCM = (XBD, XMH) +JCT = (NFQ, NDJ) +FGM = (HMK, PGQ) +QKK = (RLS, LPX) +QJD = (PDT, RPQ) +LHP = (PLN, MQN) +NPL = (TFF, TFF) +XHP = (PJQ, KBL) +HMK = (JNV, XPS) +KMC = (VCG, NTG) +QDX = (TMM, HHM) +VNP = (LTG, GDS) +PDR = (CDX, VTL) +HVK = (BQC, SCN) +QMV = (BNJ, CRL) +DDR = (KRS, QFV) +RDG = (QHP, QXN) +CRL = (NJC, QRL) +SHB = (SQX, JVV) +TSP = (BPX, FVC) +RRF = (KJB, PTB) +CSG = (FRX, RTP) +RPQ = (SRQ, MLD) +VXS = (MTN, DJQ) +PJK = (NGD, NTM) +QHG = (NXT, DHS) +LSP = (MTR, GGH) +SHN = (JJS, RVC) +TNQ = (TMM, HHM) +NPK = (GCM, VKT) +MJF = (NBT, FCT) +JNN = (PTH, HFK) +NRS = (CLT, HGV) +HSX = (BPX, FVC) +MVM = (DSF, NQS) +PBK = (SQX, JVV) +HHD = (DBM, MVD) +MTD = (DVB, BTX) +PXP = (NPP, CRN) +TMF = (LPF, QPD) +BRT = (FJV, GNQ) +MFQ = (BHG, SMC) +DJQ = (MVP, MVZ) +LKR = (PTH, HFK) +STQ = (HTC, PGD) +DXF = (JBX, TRT) +RJN = (PDR, KLJ) +CGC = (KKL, RJV) +SRG = (QKK, LND) +MCC = (DHS, NXT) +JMG = (RLX, NJH) +NKH = (DGF, FJL) +JXP = (DSF, NQS) +GXX = (CKC, MFL) +MXD = (KBC, FGK) +SCH = (XPG, BTH) +XSR = (MQN, PLN) +KKD = (NBD, CXL) +CLJ = (GCN, GCN) +QVV = (THK, LQV) +VLH = (FFB, STD) +RTP = (CBC, CXS) +RVX = (BLF, PTM) +KBN = (JNF, BTC) +PFX = (JHM, DTT) +NVL = (KCM, DLK) +QRM = (CQK, RBB) +HKP = (SHN, TMV) +VXF = (TFF, JRP) +LDL = (LHM, JMT) +BQL = (DRS, VQQ) +FDC = (TNQ, QDX) +MMT = (MSL, JCT) +CXV = (HKR, FHV) +BKB = (FCM, QTC) +HRQ = (RXG, JSG) +RKH = (JFF, TKR) +VQR = (JGD, SFC) +KCV = (LNG, NCV) +XSB = (DTG, DFK) +JGD = (HLP, FNS) +VCK = (RXP, VRL) +GTN = (BCP, CKB) +QDK = (CBD, CDP) +SNF = (JNH, MJF) +FVK = (QQV, NRS) +HHM = (VXK, PJK) +JRM = (DTG, DFK) +QPL = (XLK, QDK) +SCV = (QHP, QXN) +RQC = (QMD, TPG) +LFX = (BRH, HGP) +FRX = (CXS, CBC) +BTM = (FPK, JVF) +BPN = (LHN, FKM) +LRQ = (LSQ, PMP) +TPV = (LQF, KDN) +XBN = (QDS, DXP) +RBB = (FCR, HFN) +XSM = (LNT, STB) +SBR = (PQT, CNQ) +LVM = (SBV, LHS) +KBC = (JHR, TQP) +DLJ = (FGK, KBC) +LKG = (VJX, HLQ) +NXT = (VMT, VBH) +CBD = (HGN, HBG) +BHS = (VTF, MRV) +BTP = (GBG, LKM) +DSM = (CKK, CKK) +LSR = (CMB, NLP) +NPP = (BCX, DTB) +XCV = (SMS, QJD) +PNM = (BPQ, NBM) +VPS = (JJB, XMR) +JNH = (FCT, NBT) +KTN = (SHG, PJG) +FMJ = (LQV, THK) +GFX = (NBB, NBB) +SRQ = (GNS, QGB) +FQC = (DGF, FJL) +MPA = (BRS, BSL) +BMS = (FKS, SKF) +BMT = (JMG, PCS) +QFV = (SCH, FDJ) +STF = (RCS, FFD) +JTS = (GGM, SJS) +NJQ = (TKR, JFF) +MTQ = (HLQ, VJX) +FGK = (TQP, JHR) +JNF = (TCV, LJT) +LKM = (KGC, QNM) +MXV = (BQP, BXK) +FRF = (LVM, HGK) +GGH = (BHB, KNB) +BGH = (KBX, FDN) +LQH = (JNF, BTC) +JVF = (LDS, DCD) +CLT = (QPL, LFV) +HRV = (TRD, RXH) +NBD = (PXP, XBK) +PJD = (JJD, LQM) +XMV = (BBF, LKX) +BCN = (PBH, HPL) +XMH = (JNG, GCX) +HFK = (GFG, XTS) +VTL = (RFC, VPF) +MSL = (NFQ, NDJ) +THH = (KNG, QNF) +PCB = (PCX, FLB) +GBQ = (PRR, PSR) +NMS = (BQC, SCN) +PDX = (BGP, SFH) +LDS = (TLJ, LLD) +HGV = (QPL, LFV) +LMK = (VKX, JCV) +NBM = (PKR, QCS) +NLR = (LKJ, DGZ) +QDN = (TRT, JBX) +MTH = (HMT, NJM) +CKF = (LKJ, LKJ) +FDN = (DGP, JKM) +CDR = (NCV, LNG) +SGJ = (GBQ, KXN) +TMM = (VXK, PJK) +JSL = (CTS, MTT) +QGB = (TBK, NHB) +TDA = (GHJ, QRC) +GTF = (QDP, GCJ) +TCG = (FVK, JVB) +LXJ = (FVN, LHX) +TQF = (RKL, SHQ) +ZZZ = (VQQ, DRS) +NCV = (CRJ, GBL) +BKF = (CJP, PRL) +QPD = (DQN, JBQ) +MFL = (PJD, TRS) +NHG = (HGK, LVM) +MRV = (MLH, TBV) +XHS = (PSN, HRQ) +JJB = (NJQ, RKH) +TGK = (SFG, FDS) +CGS = (TRD, RXH) +GCN = (NCN, CVS) +PNN = (BKK, CQC) +LSQ = (KCC, GSP) +LND = (RLS, LPX) +CPG = (VGM, RXV) +GSF = (HMJ, RMH) +JRH = (VQR, BVM) +FJB = (DTT, JHM) +FKM = (BFK, XCQ) +LPT = (PRD, CGB) +XVG = (CRL, BNJ) +KRS = (FDJ, SCH) +BNL = (BQL, ZZZ) +JMB = (XVD, MBH) +KKH = (RLN, PHV) +MTB = (PSP, VCX) +NCN = (FFV, RQC) +FVC = (QJC, SRG) +FTS = (THG, XXL) +SFG = (BCN, DBN) +RXH = (XQT, SDR) +MLR = (GDQ, VNC) +TRD = (XQT, SDR) +BGD = (GLJ, FNK) +XDJ = (MPS, RJB) +JMJ = (MDJ, RTV) +RVC = (PXQ, NRJ) +QQV = (CLT, HGV) +MLD = (QGB, GNS) +KPH = (HRQ, PSN) +RLN = (TFR, SNM) +JRP = (DSX, HPD) +SJS = (DSM, NKL) +PGD = (CGS, HRV) +HPL = (GKH, CVN) +MQK = (PTB, KJB) +QCR = (MHV, FTS) +VCG = (BQR, FRV) +LXV = (XMR, JJB) +PKR = (QSH, XMV) +JSB = (DLJ, MXD) +VRL = (JNS, HFP) +PHJ = (BTF, BTP) +CXL = (XBK, PXP) +FNN = (TSP, HSX) +XQT = (VHH, QHT) +LQV = (DQK, JMB) +RLS = (NBP, SSC) +TCV = (MDL, MMT) +QTC = (LFX, RJF) +LRK = (MFL, CKC) +MHK = (FGF, FDF) +RLJ = (HJX, CNC) +TLK = (RFL, VCK) +CNC = (HJQ, CNR) +LQL = (FRX, RTP) +QQM = (MFQ, BNR) +VBH = (HLB, JMJ) +GKX = (TGK, QKP) +KQG = (JRH, VNT) +XDR = (DNF, KJV) +GMJ = (HKP, TGX) +VRQ = (VTF, MRV) +HGP = (VNB, LDL) +LNG = (GBL, CRJ) +BSF = (LKG, MTQ) +BRH = (VNB, LDL) +PJQ = (BGD, DLX) +QKF = (CGR, KTX) +QMD = (TND, QSF) +PQH = (MKS, STP) +FRV = (PDX, PMX) +LPF = (JBQ, DQN) +CQM = (TDH, JPR) +HJX = (CNR, HJQ) +AAA = (DRS, VQQ) +TDH = (VGX, TCF) +TGX = (TMV, SHN) +BDH = (XFV, GSF) +GXK = (BFP, TFH) +BFT = (MFQ, BNR) +NGD = (QHG, MCC) +FPK = (DCD, LDS) +MTR = (KNB, BHB) +SNM = (MFJ, HXJ) +HLP = (RHQ, SVR) +JSP = (VGC, SSF) +NJH = (RJN, DBT) +SKF = (GRG, JSB) +PTM = (TKN, PCQ) +QGQ = (PHV, RLN) +SSF = (NVL, JPB) +PCQ = (LTC, PCH) +KJV = (GMS, XGF) +JSD = (XHP, DKM) +RRB = (LQF, KDN) +GJJ = (FLT, BNV) +FJA = (HJX, CNC) +HLQ = (XRK, VDQ) +KTP = (LPF, QPD) +PRD = (LRM, MTH) +QNF = (CHP, FNN) +DQK = (MBH, XVD) +TMS = (CLJ, XML) +QVP = (FNB, LSP) +BPX = (QJC, SRG) +QXN = (KQG, BML) +VGQ = (JVF, FPK) +BRS = (CDL, GFJ) +NQS = (VKC, SDV) +LFV = (XLK, QDK) +SMS = (RPQ, PDT) +BBF = (CGV, KRM) +VMT = (HLB, JMJ) +QSF = (JSL, LRF) +CJQ = (XSR, LHP) +RDF = (KKD, SQM) +MKS = (CKF, CKF) +STD = (MNM, TMS) +DNS = (MRQ, XFT) +MFG = (RQR, BXQ) +GBG = (QNM, KGC) +JNG = (RDG, SCV) +CVN = (GJJ, QVC) +HMT = (BVL, KLQ) +VTQ = (NTC, BNL) +TGB = (JTK, VMK) +PSR = (NPK, BDP) +MDJ = (DSB, SJB) +CKB = (VSB, TCG) +DNF = (GMS, XGF) +LQK = (XFR, RDF) +RHQ = (KPX, QTM) +VKX = (STQ, JSQ) +BRX = (DDR, TJD) +LJN = (NLP, CMB) +DJR = (HMK, PGQ) +VNB = (JMT, LHM) +DBM = (SBR, MTF) +KLQ = (XBN, MNH) +MDL = (MSL, JCT) +SQX = (TPV, RRB) +CLD = (CQK, RBB) +HPD = (RLJ, CJZ) +LHN = (BFK, XCQ) +KJB = (TMC, QCR) +RLG = (RVX, CDB) +PBH = (GKH, CVN) +DMB = (HHD, MSZ) +SDV = (GXK, QSB) +KPX = (XDJ, QTF) +NBB = (MTN, MTN) +BTX = (BRT, GSM) +HGN = (HJT, RBX) +GDS = (XSM, BGG) +KDN = (KTN, BJT) +GSL = (TRQ, PHJ) +SFR = (XHS, KPH) +JNV = (TVL, PNM) +JNS = (VCD, CXV) +LHM = (GXV, RTX) +TFH = (MTD, PFG) +GHJ = (CSN, XVS) +KNQ = (LRK, GXX) +PRT = (RNV, RGX) +JTK = (BMT, JXJ) +MRQ = (VPT, FLH) +TKN = (LTC, PCH) +VSN = (XFR, RDF) +HXJ = (DBB, HBH) +PRL = (THH, TTH) +GCX = (RDG, SCV) +MNH = (DXP, QDS) +CMB = (XQB, RKB) +CHP = (TSP, HSX) +BCP = (TCG, VSB) +LNT = (HQM, FGJ) +FNK = (XNX, RKP) +HRT = (FJB, PFX) +HTC = (CGS, HRV) +SDR = (QHT, VHH) +CQK = (FCR, HFN) +LVN = (FGP, BKF) +FDS = (DBN, BCN) +QCS = (QSH, XMV) +TRT = (KFQ, SGJ) +RQH = (FDN, KBX) +QJC = (QKK, LND) +MVD = (SBR, MTF) +SBG = (RFL, VCK) +DSX = (RLJ, RLJ) +JBX = (KFQ, SGJ) +JVV = (RRB, TPV) +BBR = (FKS, SKF) +KTX = (VDX, XDR) +CSN = (NNM, CBK) +NNM = (RTN, TGB) +VXK = (NGD, NTM) +DQD = (FJB, PFX) +CDB = (BLF, PTM) +GBL = (BPN, KKS) +BGP = (SNT, BRX) +CRP = (FDC, TPJ) +DFK = (KVV, SQD) +LVQ = (KNQ, FBX) +HSB = (PBK, SHB) +PJG = (TNP, CQM) +JPB = (KCM, DLK) +JJS = (PXQ, NRJ) +XGF = (QDH, PFV) +DKM = (KBL, PJQ) +DVB = (GSM, BRT) +TMC = (MHV, FTS) +TRQ = (BTP, BTF) +FLB = (FCV, FKJ) +BVL = (MNH, XBN) +XPA = (NCN, CVS) +XPS = (PNM, TVL) +CPN = (RDJ, JMK) +RQR = (DKX, CJQ) +SFH = (SNT, BRX) +DBT = (KLJ, PDR) +MBH = (XCS, XPD) +DLK = (XMH, XBD) +HBG = (HJT, RBX) +THK = (DQK, JMB) +DGF = (KKH, QGQ) +BPJ = (GKX, NXB) +MTN = (MVP, MVP) +TMV = (RVC, JJS) +GMS = (PFV, QDH) +FDJ = (BTH, XPG) +FFB = (MNM, MNM) +RTX = (LBK, LXJ) +BGG = (LNT, STB) +LRM = (HMT, NJM) +XVD = (XPD, XCS) +THT = (NTC, NTC) +GXH = (NBB, VXS) +LTG = (XSM, BGG) +GKH = (GJJ, QVC) +TNT = (FHG, PPR) +CDP = (HGN, HBG) +DQN = (HXV, JPN) +FNS = (SVR, RHQ) +DSB = (DMG, LRQ) +DCD = (TLJ, LLD) +FTQ = (JMK, RDJ) +VGX = (SFN, BDH) +VDX = (KJV, DNF) +PMX = (SFH, BGP) +VTF = (TBV, MLH) +LQM = (FMJ, QVV) +VNT = (VQR, BVM) +XML = (GCN, QFZ) +VPF = (MVM, JXP) +TBK = (LLQ, HQX) +PXQ = (TLK, SBG) +LKX = (CGV, KRM) +DBN = (PBH, HPL) +XXL = (CPG, PND) +BHG = (BBR, BMS) +VQQ = (STX, PJH) +VHH = (RLG, TDG) +RJK = (KPH, XHS) +BFK = (MXV, HTX) +VJX = (XRK, VDQ) +GFJ = (CPN, FTQ) +GRG = (MXD, DLJ) +CQC = (LJN, LSR) +RJB = (DHH, LPT) +FGP = (CJP, PRL) +BCM = (FFB, STD) +FBX = (GXX, LRK) +FLH = (VHJ, PRT) +GTD = (THT, THT) +GNS = (NHB, TBK) +QTM = (XDJ, QTF) +VGM = (KJK, FCD) +XBD = (JNG, GCX) +QVC = (BNV, FLT) +FCV = (LQL, CSG) +SCN = (NPL, VXF) +KKL = (HVK, NMS) +MDG = (QJD, SMS) +QSB = (BFP, TFH) +LKJ = (BRS, BSL) +XCS = (HSB, LRC) +HLB = (MDJ, RTV) +TLJ = (NGQ, CGC) +MNM = (CLJ, CLJ) +STB = (HQM, FGJ) +HJT = (TMF, KTP) +TND = (LRF, JSL) +FVN = (QDN, DXF) +SNT = (TJD, DDR) +JKM = (LKN, FVM) +LTC = (RBP, PQH) +STP = (CKF, NLR) +DMG = (LSQ, PMP) +CDX = (RFC, VPF) +CNQ = (PXG, BSF) +PMP = (KCC, GSP) +VKT = (CKX, KPS) +CKJ = (FBX, KNQ) +VGC = (JPB, NVL) +LCB = (QTC, FCM) +TCF = (BDH, SFN) +DDC = (XSX, DMB) +SFN = (XFV, GSF) +HXF = (GDQ, VNC) +BPQ = (QCS, PKR) +FFD = (TNT, XTF) +TBV = (SFR, RJK) +DBB = (FGM, DJR) +FHG = (VSN, LQK) +GGM = (DSM, NKL) +RJV = (NMS, HVK) +NGQ = (RJV, KKL) +CFS = (HQV, HPS) +PFG = (BTX, DVB) +VCX = (QKF, CPK) +XCQ = (MXV, HTX) +DHH = (PRD, CGB) +HBH = (DJR, FGM) +RMH = (GMV, SNF) +HXV = (QTB, FRP) +QFZ = (CVS, NCN) +CVK = (BDK, GMJ) +SHQ = (QQM, BFT) +PGQ = (XPS, JNV) +LQR = (NTG, VCG) +QDS = (BVB, HDJ) +CJP = (THH, TTH) +FNB = (GGH, MTR) +PSN = (RXG, JSG) +LHX = (QDN, DXF) +GFG = (SCG, KQJ) +PRR = (NPK, BDP) +QSH = (LKX, BBF) +KVV = (LBV, CRP) +DFF = (NXB, GKX) +JFF = (CKJ, LVQ) +FCD = (MDG, XCV) +SFC = (FNS, HLP) +KPS = (BNS, CFS) +PLN = (PNN, DHB) +SHG = (CQM, TNP) +GJR = (QDP, GCJ) +NDJ = (GFX, GXH) +XQB = (PHC, JSD) +FKJ = (CSG, LQL) +FRP = (KNS, JTS) +MHX = (BKB, LCB) +HGK = (LHS, SBV) +JXJ = (JMG, PCS) +NJC = (RQH, BGH) +LLQ = (TQF, NJB) +QFR = (BCP, CKB) +BXK = (DQD, HRT) +XFR = (KKD, SQM) +XFV = (HMJ, RMH) +HMJ = (GMV, SNF) +BNV = (NHG, FRF) +GXV = (LBK, LXJ) +XNX = (NKH, FQC) +BJR = (VKX, JCV) +CRN = (BCX, DTB) diff --git a/src/aoc8test.txt b/src/aoc8test.txt new file mode 100644 index 0000000..d834763 --- /dev/null +++ b/src/aoc8test.txt @@ -0,0 +1,11 @@ +LR + +11A = (11B, XXX) +12A = (11B, XXX) +11B = (XXX, 11Z) +11Z = (11B, XXX) +22A = (22B, XXX) +22B = (22C, 22C) +22C = (22Z, 22Z) +22Z = (22B, 22B) +XXX = (XXX, XXX) From d6ff1570a6a8d1f7660429dd889c7409c3ecfb8d Mon Sep 17 00:00:00 2001 From: Hane Date: Sun, 31 Dec 2023 01:12:22 +0100 Subject: [PATCH 03/10] full aoc11 --- src/aoc11-2.lisp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ src/aoc11.lisp | 69 +++++++++++++++++++++++++++-------------- src/aoc8-2.lisp | 23 +++----------- 3 files changed, 132 insertions(+), 41 deletions(-) create mode 100644 src/aoc11-2.lisp diff --git a/src/aoc11-2.lisp b/src/aoc11-2.lisp new file mode 100644 index 0000000..4310c6e --- /dev/null +++ b/src/aoc11-2.lisp @@ -0,0 +1,81 @@ +(defun input-parsing (path) + (with-open-file (file path) + (let( (galaxies (make-array 0 :adjustable t)) ) + (loop for line = (read-line file nil) + for current-line from 0 + with galaxy-columns = '() + with galaxies-copy = (make-array 0 :adjustable t) + with data-line = nil + with key = "" + with left-value = "" + with right-value = "" + while line + do + (when(zerop current-line) + (dotimes (i (length line)) + (push nil galaxy-columns))) + + (loop for c across line + with char-position = 0 + do + (when (char= c #\#) + (let( (size (+ 1 (length galaxies))) ) + (adjust-array galaxies size) (adjust-array galaxies-copy size) (decf size) + (setf (aref galaxies size) (cons current-line char-position)) + (setf (aref galaxies-copy size) (cons current-line char-position))) + ;;(format T "~% ~d ~A" char-position galaxy-columns) + (setf (nth char-position galaxy-columns) t) + ;;(setf (nth i parsed) nil) + (setf data-line t)) + (incf char-position) + finally + (if (not data-line) + (setf current-line (+ current-line *replace-value*))) + ;;(incf current-line) + (setf data-line nil)) + finally + ;;(print galaxy-columns) + ;;(setf galaxies-copy galaxies) + (loop for occupied-column in galaxy-columns + for x-index from 0 + do + (when (not occupied-column) + (loop for index from 0 + while (< index (array-total-size galaxies-copy)) + ;;for galaxy in galaxies + do + ;;(print x-index) + ;;(print index) + (when (> (cdr (aref galaxies-copy index)) x-index) + ;;(print (aref galaxies-copy index)) + (setf (cdr (aref galaxies index)) (+ (cdr (aref galaxies index)) *replace-value*))))))) + ;;(y . x) + (print galaxies) + galaxies))) + +(defun calculate-pairs (galaxies) + (loop for base from 0 + with result = 0 + while (< base (array-total-size galaxies)) + do + (loop for comparee from (+ base 1) + with x-movement = 0 + with y-movement = 0 + while (< comparee (array-total-size galaxies)) + do + ;;(print (aref galaxies base)) + ;;(print (aref galaxies comparee)) + (setf y-movement (if(<= (car(aref galaxies base)) (car(aref galaxies comparee))) + (- (car(aref galaxies comparee)) (car(aref galaxies base))) + (- (car(aref galaxies base)) (car(aref galaxies comparee))))) + (setf x-movement (if(<= (cdr(aref galaxies base)) (cdr(aref galaxies comparee))) + (- (cdr(aref galaxies comparee)) (cdr(aref galaxies base))) + (- (cdr(aref galaxies base)) (cdr(aref galaxies comparee))))) + ;;(print y-movement) + ;;(print x-movement) + (setf result (+ result (+ x-movement y-movement)))) + finally + (return result))) + +(defparameter *replace-value* 999999) +(print (calculate-pairs (input-parsing "aoc11input.txt"))) diff --git a/src/aoc11.lisp b/src/aoc11.lisp index 33d2e98..c2b6d4f 100644 --- a/src/aoc11.lisp +++ b/src/aoc11.lisp @@ -1,22 +1,10 @@ - (defun input-parsing (path) (with-open-file (file path) - (let( (galaxy-columns '()) (data-line nil) (galaxies (make-array 0 :adjustable t)) (current-line 0) ) - ;;Prep work - ;;(defparameter keys (make-array 0 :adjustable t)) - ;;(defparameter parsed '()) - ;;(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) - ;; (let( (size (+ 1 (length keys))) ) - ;; (adjust-array keys size) (decf size) - ;; (setf (aref keys size) key) )) - + (let( (galaxies (make-array 0 :adjustable t)) ) (loop for line = (read-line file nil) + for current-line from 0 + with galaxy-columns = '() + with data-line = nil with key = "" with left-value = "" with right-value = "" @@ -24,15 +12,16 @@ do (when(zerop current-line) (dotimes (i (length line)) - (push nil galaxy-columns))) + (push nil galaxy-columns))) + (loop for c across line with char-position = 0 do (when (char= c #\#) (let( (size (+ 1 (length galaxies))) ) (adjust-array galaxies size) (decf size) - (setf (aref galaxies size) (cons current-line char-position)) ) - (format T "~% ~d ~A" char-position galaxy-columns) + (setf (aref galaxies size) (cons current-line char-position )) ) + ;;(format T "~% ~d ~A" char-position galaxy-columns) (setf (nth char-position galaxy-columns) t) ;;(setf (nth i parsed) nil) (setf data-line t)) @@ -40,18 +29,52 @@ finally (if (not data-line) (incf current-line)) - (incf current-line) + ;;(incf current-line) (setf data-line nil)) - ) + finally + (loop for occupied-column in galaxy-columns + for x-index from 0 + do + (when (not occupied-column) + (loop for index from 0 + while (< index (array-total-size galaxies)) + ;;for galaxy in galaxies + do + (when (> (cdr (aref galaxies index)) x-index) + (setf (cdr (aref galaxies index)) (+ (cdr (aref galaxies index)) 1))))))) galaxies))) -(print (input-parsing "aoc11test.txt")) +(defun calculate-pairs (galaxies) + (loop for base from 0 + with result = 0 + while (< base (array-total-size galaxies)) + do + (loop for comparee from (+ base 1) + with x-movement = 0 + with y-movement = 0 + while (< comparee (array-total-size galaxies)) + do + ;;(print (aref galaxies base)) + ;;(print (aref galaxies comparee)) + (setf y-movement (if(<= (car(aref galaxies base)) (car(aref galaxies comparee))) + (- (car(aref galaxies comparee)) (car(aref galaxies base))) + (- (car(aref galaxies base)) (car(aref galaxies comparee))))) + (setf x-movement (if(<= (cdr(aref galaxies base)) (cdr(aref galaxies comparee))) + (- (cdr(aref galaxies comparee)) (cdr(aref galaxies base))) + (- (cdr(aref galaxies base)) (cdr(aref galaxies comparee))))) + ;;(print y-movement) + ;;(print x-movement) + (setf result (+ result (+ x-movement y-movement)))) + finally + result)) + +(print (calculate-pairs (input-parsing "aoc11input.txt"))) ;;(print "Hola") ;;(print (aref keys 0)) ;; (incf (nth 0 steps-per-key)) ;; (if(char= c #\L) - ;; (setf (aref keys 0) (car(gethash (aref keys 0) route-hash))) + ;; (setf (aref keys 0) (cdr(gethash (aref keys 0) route-hash))) ;; (setf (aref keys 0) (cdr(gethash (aref keys 0) route-hash)))) ;; ;;(print (aref keys 0)) diff --git a/src/aoc8-2.lisp b/src/aoc8-2.lisp index 37a11e9..c861017 100644 --- a/src/aoc8-2.lisp +++ b/src/aoc8-2.lisp @@ -6,7 +6,7 @@ (print (sb-thread:list-all-threads)) (with-open-file (file "aoc8input.txt") - (let( (goal-to-be-reached nil) (direction-line "") (route-hash (make-hash-table :test #'equalp :size 800)) ) + (let( (goal-to-be-reached nil) (direction-line "") (route-hash (make-hash-table :test #'equalp :size 800))) ;;Prep work (defparameter keys (make-array 0 :adjustable t)) (defparameter parsed '()) @@ -31,11 +31,7 @@ (when(char= #\A (char key 2)) (let( (size (+ 1 (length keys))) ) (adjust-array keys size) (decf size) - (setf (aref keys size) key) )) - ) - - ;;(print keys) - ;;(print parsed) + (setf (aref keys size) key) ))) (dotimes (i (length keys)) (push 0 steps-per-key) (push t parsed)) @@ -59,16 +55,9 @@ (when(char= (char (aref keys 0) 2) #\Z) ;;(format T "~%~a ~d" "Ayo on key 0 found at: " (nth 0 steps-per-key)) (dotimes (i (length keys)) - ;;(print (+ i 1)) - ;;(print (length keys)) - ;;(when (< (+ i 1) (length keys)) (when (> i 0) - ;;WTF - (sb-thread:make-thread (lambda (x hashmap dir strlen steps) (hashmap-parse hashmap dir strlen x steps) ) :arguments (list i route-hash direction-line (length direction-line) (nth i steps-per-key) ) ) - ;;(format T "~%~d" i) - ) - ) - ;;(print parsed) + (sb-thread:make-thread (lambda (x hashmap dir strlen steps) (hashmap-parse hashmap dir strlen x steps) ) :arguments (list i route-hash direction-line (length direction-line) (nth i steps-per-key))))) + (loop while (not (every #'null parsed)) do (print parsed) @@ -105,9 +94,7 @@ (when(char= (char (aref keys key-position) 2) #\Z) (setf z-found t) (setf (nth key-position parsed) nil) - (setf (nth key-position steps-per-key) steps)) - ) - )) + (setf (nth key-position steps-per-key) steps))))) ;; (defvar *directions*) ;; (defvar *ndirections*) From aaa99ab07302879fafcfa4eea9139a576f19aac1 Mon Sep 17 00:00:00 2001 From: Hane Date: Fri, 5 Jan 2024 17:52:53 +0100 Subject: [PATCH 04/10] aoc10-1 --- src/aoc10-2.lisp | 193 +++++++++++++++++++++++++++++++++++++++++++++ src/aoc10.lisp | 192 ++++++++++++++++++++++++++++++++++++++++++++ src/aoc10input.txt | 140 ++++++++++++++++++++++++++++++++ src/aoc10test.txt | 5 ++ 4 files changed, 530 insertions(+) create mode 100644 src/aoc10-2.lisp create mode 100644 src/aoc10.lisp create mode 100644 src/aoc10input.txt create mode 100644 src/aoc10test.txt diff --git a/src/aoc10-2.lisp b/src/aoc10-2.lisp new file mode 100644 index 0000000..7650e46 --- /dev/null +++ b/src/aoc10-2.lisp @@ -0,0 +1,193 @@ +(defun locate-starting-pos (string line-number) + (loop with starting-pos = nil + for c across string + for char-position from 0 + do + (when (char= c #\S) + (setf starting-pos (cons char-position line-number))) + finally + (return starting-pos))) + +(defun input-parsing (path) + (with-open-file (file path) + (let( (starting-pos nil) (line-length 0) + (node-array nil) (input-array (make-array 0 :adjustable t)) ) + (loop with initial-line = (read-line file nil) + initially + ;;(print initial-line) + (setf line-length (length initial-line)) + (let( (size (+ 1 (length input-array))) ) + (adjust-array input-array size) (decf size) + (setf (aref input-array size) (format nil "~a" initial-line))) + ;;(setf input-string (format nil "~a~a" input-string line)) + (setf starting-pos (locate-starting-pos initial-line 0)) + for line = (read-line file nil) + for line-count from 1 + while line + do + ;;(print line) + ;;(setf input-string (format nil "~a~a" input-string line)) + (let( (size (+ 1 (length input-array))) ) + (adjust-array input-array size) (decf size) + (setf (aref input-array size) (format nil "~a" line))) + (when (not starting-pos) + (setf starting-pos (locate-starting-pos line line-count))) + ;;(setf node-array (make-array '(line-length line-count) :initial-element nil)) + + finally + ;;(print line-length) + ;;(print line-count) + (setf node-array (make-array (list line-length line-count) :initial-element nil)) + (setf (aref node-array (cdr starting-pos) (car starting-pos)) t) + (return (values input-array node-array starting-pos)) + )))) + +(defun determine-paths (input-array starting-pos) + (let ( (current-char nil) (paths-list (list 0 0 0 0))) + ;;N + (when (not (equal (cdr starting-pos) 0)) + (setf current-char (char (aref input-array (- (cdr starting-pos) 1)) (car starting-pos))) + (when (equal (nth 2 (gethash current-char *starting-orientation-hash*)) 1) + (setf (nth 0 paths-list) 1))) + ;;W + (when (not (equal (car starting-pos) 0)) + (setf current-char (char (aref input-array (cdr starting-pos)) (- (car starting-pos) 1))) + (when (equal (nth 3 (gethash current-char *starting-orientation-hash*)) 1) + (setf (nth 1 paths-list) 1))) + ;;S + (when (not (equal (cdr starting-pos) (- (array-dimension input-array 0) 1))) + (setf current-char (char (aref input-array (+ (cdr starting-pos) 1)) (car starting-pos))) + (when (equal (nth 0 (gethash current-char *starting-orientation-hash*)) 1) + (setf (nth 2 paths-list) 1))) + ;;E + (when (not (equal (car starting-pos) (- (length (aref input-array 0)) 1))) + (setf current-char (char (aref input-array (cdr starting-pos)) (+ (car starting-pos) 1))) + (when (equal (nth 1 (gethash current-char *starting-orientation-hash*)) 1) + (setf (nth 3 paths-list) 1))) + paths-list + )) + +(defun paths-list-to-starting-coords (paths-list starting-pos) + (loop for item in paths-list + for item-count from 0 + with first-position = nil + with second-position = nil + while item + do + (when (not (zerop item)) + (cond ((equal item-count 0) (setf first-position + (cons (car starting-pos) (- (cdr starting-pos) 1)))) + ((equal item-count 1) (if (not first-position) + (setf first-position + (cons (- (car starting-pos) 1) (cdr starting-pos) )) + (setf second-position + (cons (- (car starting-pos) 1) (cdr starting-pos) )))) + ((equal item-count 2) (if (not first-position) + (setf first-position + (cons (car starting-pos) (+ (cdr starting-pos) 1)) ) + (setf second-position + (cons (car starting-pos) (+ (cdr starting-pos) 1)) ))) + (t (setf second-position + (cons (+ (car starting-pos) 1) (cdr starting-pos) ))))) + finally + ;;(print first-position) + ;;(print second-position) + (return (values first-position second-position)))) + +(defun calculate-next-move (current-char current-position previous-position) + (let( (east-choice (cons (+ (car current-position) 1) (cdr current-position))) + (south-choice (cons (car current-position) (+ (cdr current-position) 1))) + (west-choice (cons (- (car current-position) 1) (cdr current-position))) + (north-choice (cons (car current-position) (- (cdr current-position) 1))) ) + (format T "~%~a ~A~A" "nexmove from:" current-position previous-position) + ;;(print current-position) + ;;(print (car current-position)) + ;;(print north-choice) + ;;(print west-choice) + (cond ((char= #\| current-char) (if (equal north-choice previous-position) + south-choice + north-choice)) + ((char= #\- current-char) (if (equal east-choice previous-position) + west-choice + east-choice)) + ((char= #\L current-char) (if (equal north-choice previous-position) + east-choice + north-choice)) + ((char= #\J current-char) (if (equal north-choice previous-position) + west-choice + north-choice)) + ((char= #\7 current-char) (if (equal south-choice previous-position) + west-choice + south-choice)) + ((char= #\F current-char) (if (equal south-choice previous-position) + east-choice + south-choice))))) + +(defun steps-to-farthest-point (input-array node-array paths-list starting-pos) + ;; (print "---") + (let( (circle-closed nil) (current-coords (list)) (previous-coords (list starting-pos starting-pos))) + (multiple-value-bind (first-position second-position) + (paths-list-to-starting-coords paths-list starting-pos) + (push first-position current-coords) + (push second-position current-coords) + (setf (aref node-array (cdr first-position) (car first-position)) t) + (setf (aref node-array (cdr second-position) (car second-position)) t) + ;;(print node-array) + (print "----we gamin") + ;;(print current-coords) + + ;;(print (calculate-next-move + + (loop for steps from 1 + while (not circle-closed) + do + (loop with current-char = nil + with temp-coords = nil + for index from 0 + while (< index 2) + do + (setf current-char + (char (aref input-array (cdr (nth index current-coords))) + (car (nth index current-coords))) ) + ;;(print current-char) + ;;(print + (setf temp-coords (calculate-next-move current-char (nth index current-coords) + (nth index previous-coords))) + (setf (nth index previous-coords) (nth index current-coords)) + (setf (nth index current-coords) temp-coords) + (if (not (aref node-array (cdr (nth index current-coords)) + (car (nth index current-coords)))) + (setf (aref node-array (cdr (nth index current-coords)) + (car (nth index current-coords)))t) + (setf circle-closed t)) + ;;(print node-array) + ;;(print current-coords) + + ) + finally + (print node-array) + (print steps) + ) + ;;(format T "~%~A~A" first-position second-position) + ))) + +;; (let( (input-array nil) (node-array nil) ) +(defparameter *starting-orientation-hash* (make-hash-table :test #'equalp :size 7)) +;;N-w-S-E +(setf (gethash #\| *starting-orientation-hash*) '(1 0 1 0)) +(setf (gethash #\- *starting-orientation-hash*) '(0 1 0 1)) +(setf (gethash #\L *starting-orientation-hash*) '(1 0 0 1)) +(setf (gethash #\J *starting-orientation-hash*) '(1 1 0 0)) +(setf (gethash #\7 *starting-orientation-hash*) '(0 1 1 0)) +(setf (gethash #\F *starting-orientation-hash*) '(0 0 1 1)) +(setf (gethash #\. *starting-orientation-hash*) '(0 0 0 0)) + + +;;(print (gethash #\| *starting-orientation-hash*)) + + ;;(multiple-value-bind (input-array node-array starting-pos) (input-parsing "aoc10test.txt") (format T "~%~A~%~A~%~A~A" input-array node-array starting-pos (determine-paths input-array starting-pos))) + +(multiple-value-bind (input-array node-array starting-pos) (input-parsing "aoc10test.txt") + (format T "~%~A~%~A~%~A~%~A~%~a~%" input-array node-array starting-pos (determine-paths input-array starting-pos) "-----") (steps-to-farthest-point input-array node-array (determine-paths input-array starting-pos) starting-pos)) + +;;) diff --git a/src/aoc10.lisp b/src/aoc10.lisp new file mode 100644 index 0000000..9b4b61b --- /dev/null +++ b/src/aoc10.lisp @@ -0,0 +1,192 @@ +(defun locate-starting-pos (string line-number) + (loop with starting-pos = nil + for c across string + for char-position from 0 + do + (when (char= c #\S) + (setf starting-pos (cons char-position line-number))) + finally + (return starting-pos))) + +(defun input-parsing (path) + (with-open-file (file path) + (let( (starting-pos nil) (line-length 0) + (node-array nil) (input-array (make-array 0 :adjustable t)) ) + (loop with initial-line = (read-line file nil) + initially + ;;(print initial-line) + (setf line-length (length initial-line)) + (let( (size (+ 1 (length input-array))) ) + (adjust-array input-array size) (decf size) + (setf (aref input-array size) (format nil "~a" initial-line))) + ;;(setf input-string (format nil "~a~a" input-string line)) + (setf starting-pos (locate-starting-pos initial-line 0)) + for line = (read-line file nil) + for line-count from 1 + while line + do + ;;(print line) + ;;(setf input-string (format nil "~a~a" input-string line)) + (let( (size (+ 1 (length input-array))) ) + (adjust-array input-array size) (decf size) + (setf (aref input-array size) (format nil "~a" line))) + (when (not starting-pos) + (setf starting-pos (locate-starting-pos line line-count))) + ;;(setf node-array (make-array '(line-length line-count) :initial-element nil)) + + finally + ;;(print line-length) + ;;(print line-count) + (setf node-array (make-array (list line-length line-count) :initial-element nil)) + (setf (aref node-array (cdr starting-pos) (car starting-pos)) t) + (return (values input-array node-array starting-pos)) + )))) + +(defun determine-paths (input-array starting-pos) + (let ( (current-char nil) (paths-list (list 0 0 0 0))) + ;;N + (when (not (equal (cdr starting-pos) 0)) + (setf current-char (char (aref input-array (- (cdr starting-pos) 1)) (car starting-pos))) + (when (equal (nth 2 (gethash current-char *starting-orientation-hash*)) 1) + (setf (nth 0 paths-list) 1))) + ;;W + (when (not (equal (car starting-pos) 0)) + (setf current-char (char (aref input-array (cdr starting-pos)) (- (car starting-pos) 1))) + (when (equal (nth 3 (gethash current-char *starting-orientation-hash*)) 1) + (setf (nth 1 paths-list) 1))) + ;;S + (when (not (equal (cdr starting-pos) (- (array-dimension input-array 0) 1))) + (setf current-char (char (aref input-array (+ (cdr starting-pos) 1)) (car starting-pos))) + (when (equal (nth 0 (gethash current-char *starting-orientation-hash*)) 1) + (setf (nth 2 paths-list) 1))) + ;;E + (when (not (equal (car starting-pos) (- (length (aref input-array 0)) 1))) + (setf current-char (char (aref input-array (cdr starting-pos)) (+ (car starting-pos) 1))) + (when (equal (nth 1 (gethash current-char *starting-orientation-hash*)) 1) + (setf (nth 3 paths-list) 1))) + paths-list + )) + +(defun paths-list-to-starting-coords (paths-list starting-pos) + (loop for item in paths-list + for item-count from 0 + with first-position = nil + with second-position = nil + while item + do + (when (not (zerop item)) + (cond ((equal item-count 0) (setf first-position + (cons (car starting-pos) (- (cdr starting-pos) 1)))) + ((equal item-count 1) (if (not first-position) + (setf first-position + (cons (- (car starting-pos) 1) (cdr starting-pos) )) + (setf second-position + (cons (- (car starting-pos) 1) (cdr starting-pos) )))) + ((equal item-count 2) (if (not first-position) + (setf first-position + (cons (car starting-pos) (+ (cdr starting-pos) 1)) ) + (setf second-position + (cons (car starting-pos) (+ (cdr starting-pos) 1)) ))) + (t (setf second-position + (cons (+ (car starting-pos) 1) (cdr starting-pos) ))))) + finally + ;;(print first-position) + ;;(print second-position) + (return (values first-position second-position)))) + +(defun calculate-next-move (current-char current-position previous-position) + (let( (east-choice (cons (+ (car current-position) 1) (cdr current-position))) + (south-choice (cons (car current-position) (+ (cdr current-position) 1))) + (west-choice (cons (- (car current-position) 1) (cdr current-position))) + (north-choice (cons (car current-position) (- (cdr current-position) 1))) ) + (format T "~%~a ~A~A" "nexmove from:" current-position previous-position) + ;;(print current-position) + ;;(print (car current-position)) + ;;(print north-choice) + ;;(print west-choice) + (cond ((char= #\| current-char) (if (equal north-choice previous-position) + south-choice + north-choice)) + ((char= #\- current-char) (if (equal east-choice previous-position) + west-choice + east-choice)) + ((char= #\L current-char) (if (equal north-choice previous-position) + east-choice + north-choice)) + ((char= #\J current-char) (if (equal north-choice previous-position) + west-choice + north-choice)) + ((char= #\7 current-char) (if (equal south-choice previous-position) + west-choice + south-choice)) + ((char= #\F current-char) (if (equal south-choice previous-position) + east-choice + south-choice))))) + +(defun steps-to-farthest-point (input-array node-array paths-list starting-pos) + ;; (print "---") + (let( (circle-closed nil) (current-coords (list)) (previous-coords (list starting-pos starting-pos))) + (multiple-value-bind (first-position second-position) + (paths-list-to-starting-coords paths-list starting-pos) + (push first-position current-coords) + (push second-position current-coords) + (setf (aref node-array (cdr first-position) (car first-position)) t) + (setf (aref node-array (cdr second-position) (car second-position)) t) + ;;(print node-array) + (print "----we gamin") + ;;(print current-coords) + + ;;(print (calculate-next-move + + (loop for steps from 1 + while (not circle-closed) + do + (loop with current-char = nil + with temp-coords = nil + for index from 0 + while (< index 2) + do + (setf current-char + (char (aref input-array (cdr (nth index current-coords))) + (car (nth index current-coords))) ) + ;;(print current-char) + ;;(print + (setf temp-coords (calculate-next-move current-char (nth index current-coords) + (nth index previous-coords))) + (setf (nth index previous-coords) (nth index current-coords)) + (setf (nth index current-coords) temp-coords) + (if (not (aref node-array (cdr (nth index current-coords)) + (car (nth index current-coords)))) + (setf (aref node-array (cdr (nth index current-coords)) + (car (nth index current-coords)))t) + (setf circle-closed t)) + ;;(print node-array) + ;;(print current-coords) + + ) + finally + (print steps) + ) + ;;(format T "~%~A~A" first-position second-position) + ))) + +;; (let( (input-array nil) (node-array nil) ) +(defparameter *starting-orientation-hash* (make-hash-table :test #'equalp :size 7)) +;;N-w-S-E +(setf (gethash #\| *starting-orientation-hash*) '(1 0 1 0)) +(setf (gethash #\- *starting-orientation-hash*) '(0 1 0 1)) +(setf (gethash #\L *starting-orientation-hash*) '(1 0 0 1)) +(setf (gethash #\J *starting-orientation-hash*) '(1 1 0 0)) +(setf (gethash #\7 *starting-orientation-hash*) '(0 1 1 0)) +(setf (gethash #\F *starting-orientation-hash*) '(0 0 1 1)) +(setf (gethash #\. *starting-orientation-hash*) '(0 0 0 0)) + + +;;(print (gethash #\| *starting-orientation-hash*)) + + ;;(multiple-value-bind (input-array node-array starting-pos) (input-parsing "aoc10test.txt") (format T "~%~A~%~A~%~A~A" input-array node-array starting-pos (determine-paths input-array starting-pos))) + +(multiple-value-bind (input-array node-array starting-pos) (input-parsing "aoc10input.txt") + (format T "~%~A~%~A~%~A~%~A~%~a~%" input-array node-array starting-pos (determine-paths input-array starting-pos) "-----") (steps-to-farthest-point input-array node-array (determine-paths input-array starting-pos) starting-pos)) + +;;) diff --git a/src/aoc10input.txt b/src/aoc10input.txt new file mode 100644 index 0000000..8a3f614 --- /dev/null +++ b/src/aoc10input.txt @@ -0,0 +1,140 @@ +7.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FJ|L7|L7L7FJF7F7|L7FJ|F----7L7L7F7F7|L----J||L77FJL-7J-L--7 +.|7....7.LJ|||F--JLJLJFJ|F---7JF7JF--J|F7L7LJLJFJ||FJLJF7|F7L7L7|L7FJL-J|||||||FJ|FJ||L7L-JL7|LJ||LLJLLJ7F--JJL7LJ||LJF-7F--JL7L7L---J|L|.L- +F|.-F7-FJJ.LJLJF7F----JFJL--7L-JL7L--7||L7L---7L-J|L-7FJ|||L7|FJ|FJL---7LJ||||||FJL-7L-JF---JL-7|L---7F--JF7LF7|F-J|F7L7|L---7L-JF--7.|L---| +|L7.||7..F7FF--JLJF7F-7L7F-7|F7F7L--7|||-|F---JF--JF7LJFJLJLLJL-J|F--7FJF-J|||||L7F7L-7FJF--7F-J|F7F-J|F--JL-J||L--J||FJ|F7F7L---JF7|FL-|7F- +J7J|JJJ7.-|-L7F7F7|LJFJFJL7LJ|LJL7F7LJLJFJL---7L-7FJ|F7L7F-7F7F--JL-7LJ7|F7|||LJ7|||F7|L7|F-JL-7||LJF7LJF----7|L7F7FJLJ7LJ||L7F7F-JLJJJJ|-|J +|J||JLLF-.L.|LJLJLJF7L7|F-JF7|F--J|L--7-L7F7F-JF-JL7|||FJL7LJLJF-7F7L7F7LJLJ|L7F-J|||||7||L---7||L7FJL7|L---7|L7|||L-----7LJ7|||L7JFJ-L7L-J| +-77FJ..|.F|F-----7J||FJ||F-J||L---JF--JF7LJLJF-JF7FJLJ|L7|L7F--JFJ|L7LJL7F--JFJ|F7|||||FJL7F--J|L7|L-7L-----JL-JLJ|F7F7F7L--7|||FJFF|.LLFJL7 +L-J|--F-7FLL--7F7L-JLJFJLJF7LJF7F7FL-7FJL---7L-7|||F77L-JF-J|F--JFJFJF7FJ|F7FJFJ|||||||L--JL-7FJ-LJF7L-----------7||LJLJL---JLJLJ7-LJ.|.JFFJ +.FLJ7|LLF-JF7.LJL7F---JLF7|L--JLJL---J|F----JF7LJ|LJL---7|F7||F-7L7|FJLJLLJ||FJFJ|||||L-7F---JL7F--JL-----7F--7F7||L-------7J.||.7.|77FJ7|JF +FLJ.J7-F|J-||7LF-J|F---7||L---------7FJL-7F--JL-7L7F7F--JLJLJLJFJFJ||F7F--7LJL7||LJLJ|F-JL--7F-JL---7F7F-7|L-7LJLJL--------JJJLF7LJ-F|.F-7|L +-J|-7|F-F-7||F7L--JL7F7LJL--------7FJL7F-JL7F7F7|FJ||L--7F-----JFJFJLJLJF7||F-JL--7F-J|F7F-7LJF-----J|||FJ|F-J7F7F7F7|F-7F7F7JF||FL-F|.7J|L| +|F7-77|FL7LJ|||FF7F7LJL7F--------7||F-JL---J|LJ||L7||F--JL----7FJ7L7F-7FJLJFJF--7FJL7FJ||L7L-7L7F--7FJLJL7LJF-7|||||L7|FJ|LJL--JL7-.7J-7L|7J +F|F7JLF7FJF7LJL-JLJL---J|F-------JLJ|F--7F7FJF7LJFJ||L---7F---JL7F-JL7|L-7.|FJF-JL-7||FJL-JF7L7LJF7LJJF--JF7|FJ||||L7LJL-JF7F----JJ.77JL-.7J +L-JF-FJ|L-JL--7F7F7F7F-7||F7F7F-----JL7FJ|LJFJL-7L7|L7F--JL-7F7FJ|F-7||F7L7|L7L-7F-J|||F7F7|L7|JFJL7F7L--7||||FJLJL-JF7F7FJ|L-7F-7F7F7LLL7F7 +|.FJ-L7L7.F7F7LJLJLJ||-||LJ||||F------JL7L-7|F--JFLJ|LJF7F--J||L7|L7||||L-JL7|F-JL-7LJLJLJLJ-|L-JF7LJL7F7||LJLJF--7F-JLJLJJL--J|FJ7LL-.LJ-|| +LF||.LL7L-J||||F7F--JL7LJJFJ|||L-------7|F7LJL-7F7-F---J|L7F7|L7||FJ|||L-7F7LJL-7F7|F---7F7F-JF-7|L7F7LJLJ|F---JF7LJF7LF7F7.F7FJL-7LLL-FJ7|7 +LL--L7JL--7|||FJ|L-7F7|7F-JFJLJLF---7F-J|||F7F-J|L7L7F-7|FJ||L7||||FJ||F7LJL---7||||L7F7LJLJF7|FJ|-LJ|F---JL----JL--JL-JLJ|FJLJF-7|7.LFF.F-- +FFJ.FFF--7||||L7|7FJ|LJFJF-J7F7FJF-7LJF7LJ|||L--JFJFJL7||L-JL7|||LJ|FJLJ|F---7FJ||LJ.LJL-7F7|LJL7|F-7LJF----7F--7F----7F-7LJF-7L7LJ77.FL||F7 +LJLF7|L-7LJ|||FJL7L-JF-JFJF--J|L-J.L--JL-7|||F7F7L-JF-JLJF---J||L7FJ|F--JL--7||FJL-7F----J|||F--J|L7L7-L---7|L-7|L--7.LJ7|F7L7L7|L|FL.FL7-LJ +.|.|L--7L-7|||L-7|F7L|F7L7L--7|F7F7F-----JLJLJLJL7F7L7F7|L-7F7||FJL-J|F7F7F7||||F--JL---7FJ||L--7L7L7L-----JL--JL---JF--7|||FJLLJJL|.F7F-JL7 +F-.L-7FJFFJ|||.FJLJL7LJL-JLF7|||LJLJF----7LF7F7F7||L7LJL-7JLJLJ|L7LF7||LJ||||LJ|L7JF----J||LJF--JFJ.L7F-----------7F7|F-JLJLJF7JLF.J-7L|.FLF +|LF--JL77L7||L7|F--7|F--7JFJLJLJF7F7|F---JFJLJLJ|||FJF---JJLF7FJFJFJLJL-7|||L-7|FJ-L7F---JF7FJF-7|F7FLJF----------J|||L7F7F7FJL7F77FL7-J7F.L +L-L--7FJF7||L7LJL7-LJL-7L-JF----JLJLJL---7|F-7F-J||L7|F7F77F||L7L7L--7F-J||L7FJ|L-7.LJF---JLJFJFJ|||F--JF---7F-----JLJFJ|||||F-J||FF-LJF|777 +FJF--JL-JLJL7L7F7L7F7F7L--7|F------------J|L7|L7|LJFJLJLJL77|L7|FJF--JL-7|L7|L7|F-JFF7|F7F---JJL-J||L-7FJF--J|F-7F7F7FJFJLJLJL--J|7JL|FLJ.77 +F-JF-7F-7F-7L7LJL7LJ|||-F7LJL-7F-------7-FJFJ|FJF-7L7F--7FJFJFJLJ7L-7F7FJL7||FJLJLF-J|LJ||F-----7FJL7FJ|FJF7FJL7||||LJ7L7F---7F--JF7.|FJ-7J| +|F7|FJL7LJLL7L7|L|F-J|L-J|F7F-J|F------JFJFJ7LJLL7|-|L7LLJFJFJJL|7|FLJLJJ-||LJJF7|L-7L-7LJL-7F-7LJF7LJFJL7|||F-JLJ|L----JL--7LJF--J|-JJ-F-.L +LJLJL7FJ|F-7L7L7FJ|F7L--7LJLJF7|L--7F7F7|FJF7.F7FJL7L-JF7.|FJ||.F7J7.F|7JF||JJ.S|FJJL-7L7|F7LJ-L--JL--JF7LJLJ|F--7|F-----7F7L--JF7FJ.|.7LL|J +|..F7LJF7|FJ-L7|L7||L7F7L----J||F--J|||LJ|7|L-JLJF-JLF7||FJL--7F77-J------LJ--FJL7JF7FJFJFJL--7F-------JL---7LJF-JLJF---7||L--7FJLJ|7|.F7F7| +LF-JL77||||-F7||||||FJ|L7F-7F7LJL7F7|LJF7L7|F----JJF7|LJLJF7F-J|L7-|7JL|-|JL-.L-7|FJLJFJJL---7|L----------7FJF7L-7F7|F--J|L--7|L-7F77JLJFJJ- +LL--7L7||||FJLJL-JLJL7|FJL7|||7F7LJLJF-JL7LJL--7F-7||L7F--JLJF-JFJJL77LL7|F7.|-FJ|L--7|F-7.F7||F---7F-----JL7|L7FJ|LJL--7|F7FJ|F7LJ|JJ-F-.|7 +|LJLL7LJLJ|L------7F-J||F7||||FJ|F---JF-7|F----J|FJ||J|L-----JF7L7-F-JJ|J.F7.-JL7|F--J|L7|FJ|||L--7|L-----7FJL7|L7|F----JLJLJ.LJ|F7|JLFF7FLJ +F|77.L---7L7F-----JL-7|||||LJ|L7|L----JFJ|L-----JL-JL-JF7F--7FJL7L7|FL7|-F.F77F-JLJF-7|-||L7|||F--JL------JL--J|FJ||.F------7F7JLJLJ.FJJFJJ| +F7F7F7F7FL7||F7F7F7F7LJLJ|L-7L-J|F--7F-JFJF7F-----7F7F7||L-7LJ-L|FJJ--JJ-|.||-L-7F7|FJL-J|FJLJLJF-7F--7F----7F-JL-JL-JF--7F-J||7J7FJ-J|F7L77 +|LJLJLJL--JLJ|||||LJ|F7F7L7FL--7|L-7LJF7L-JLJF7F7-LJLJLJ|F7L-7JJLJJL7F|J7JFJL-7LLJLJL---7|L--7F7L7LJF-J|7F7FJL-7F-----JF7LJF-JL77F|7JFJL|F-- +L7F---7F7F7F7|LJLJJFJ|LJL7L---7||F7L--JL-----JLJL-7F---7|||F-JF7J-|L--.L-.|F-7|F77F--7F7|L--7||L-JF7L-7|FJLJF7JLJF7LF--JL7FJF--J7-JF7J.LLJLL +LLJF7L||||||||F----JFJ.F7L---7|||||F----------7F-7LJF--J||LJF-77LFL-7F77FLLJFJLJL7L-7LJLJF-7LJ|JF-JL--J|L7F7|L---JL-JF---J|FJJFF7|F||77L|.F. +F--JL-J|||LJ||L7F7F7|F-JL----JLJLJLJF--------7||FJF7L-7FJL--JFJ7-||JLJFF|JLFJF--7L--JF7F7|FJF7L7L7F----JJLJLJF----7F7L----JL7JFJ|-F|L777F7|7 +L7F7F-7|LJF-J|FJ|||||L-7F---7F7F-7F7|F-------JLJL7||F-JL7F7F-JJ..F7-F.|-JJ.L7L7|L7F-7|LJLJL7||FJ7LJF7F7F----7L7F7LLJ|F7F-7F7L7|FJ-FJFJ.FJ|FJ +|LJ||FJL-7L-7|L7|LJLJF7LJFF-J||L7LJLJL----------7LJLJ|LFJ|LJL|.F-||--|J-LLLJL-JF-J|LLJ-F7F7LJLJF---JLJ|L---7L7LJL--7||LJJLJL-J|L-7L7||7LLL|. +7LFJ|L7F-JF7LJFJ|F---JL---JF-JL-JF--7F-7F7F7F7F-JF---7-L7|F7F7F7|||.|||JF7LFF--JF-JF---JLJ|F7F7L-----7L7JF-J7|F7F-7|LJF-7F----JF7|FJL-7J.LLL +L|L-JJLJF7||F7L-JL---7F7F--JF7F7-L-7|L7LJLJLJ|L--JF--JF7LJ|||||L7|L-7L7FJ7LLL---JF7L-----7||||L7F---7L7L-JF-7|||L7|L-7L7LJF----JLJ|F--JFF-J| +FJ|LF---JLJ|||F7F7LF-J|LJF--JLJL---JL7L7F7F77L---7L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JF-JFJF7|||L-7|||FJL--7F--7|||||L7|LJLJFJFJL---7F---7L-7L-----7F-JL-----JLJF7L7FJF-J||L7LJLJJ.F-..L7 +FJ.JFF--7L-7|F--J|||L7LJLJLJF--J.L-7|F7F-JF-JFJ||||F7|||||F---J|F-J|LJLJFJL---7L7L7F---JL-7FJF7L-----7|L--------7JFJL7LJLL-7|L7L----7--|--J| +JF7LFL-7L--J||F7FJ||FJF-7F-7|F7F---JLJ|L-7|F7L7LJ|||||||||L7F-7|L7-L7F--JF-7F7|FJFJL7F7F--JL7|L7.F7F-JL--------7L-JF7L--7F7||FJF----JJ7J|F-J +F||FFJFL7F7FJLJ||.LJL-J|LJFLJ||L-----7|F-J||L7L7FJ||LJLJLJFJ|FJ|FJF7|L7F7L7||||L7L7FJ||L---7||FJFJ|L---7F7FF--7L---JL--7LJ|LJL7L7F|LJL7.|.L. +--JJ-J|LLJ||F--JL7F----------JL------J|L--JL7L7LJFJL-7F--7|FJL7||FJLJFJ|L7|||||FJFJ|FJL-7F-JLJL-JFJF7F-J|L-JF7L------7|L-7L-7|L7|--7LFJFLLF7 +J-J||LL7LFLJL--7FJ|F7F7F-----7F-----7FL---7FJFL--JF7FJL7JLJL-7LJLJF--JFJFJ|||||L-JFJ|F--JL------7L-JLJF-JF--JL-------JF7|L7FJF7LJJ7|-|-7J|L7 +L|LJ7FL-.L.|F-7LJ7LJ||||F----JL7F---JF7F7LLJF-7F-7||L-7L---7|L7F-7L--7L7|FJ|||L-7FJFJL77F-------JF----JF7L-7F7F7F7F---JL7.LJFJL---77-L7-7-7J +F|7F7F|-L.FFL7L7|F7-LJLJL-7F7F-JL----JLJL--7|FJ|FJ||F7|F---JF7LJL|F--JFJ|L7||L7-|L7L-7L7L--7F---7L7F---JL-7LJ||||||F----JF-7L7F---J|LL|7|-LJ +L7-JJ||JLF7JLL7|FJL-7F7F7|LJ||F-7F----7F7F7||L-JL7|LJLJL7F-7||F7FJL7F7L7L7|||FJFJFJF-JFJF-7LJLF-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L7|L7|||L7||L7|||||F7F----7L-7F---7|L--JL7F7||7FFJJF-7|-JJ +LJ.LF-|.FL-JL7FJ||F--J|LJ7||||FJ|F-JF7|FJ|FJLJ|||||FJ||7|||||F-JL7F--J7|FJ||||L--7FJL7||||FJ||F||||||||L---7L--J|F-7LJF7F7FJ|LJL-7JJ.|.LJF7. +FJ.7JF--7|F7FJ|FJ||F7FJJF-J|LJL-JL-7|||L7||F7FJ|||||FJ|FJ||||L7F7||F-7FJL7|||L--7||F7|||LJL7|L7|||LJ|||F7F-JLF77|||L7FJLJ|L-JF7F-J.LF7-|-|F| +|F-L|L-7L-JLJFJL7|LJ||F-JF-JF------J|LJ-|||||L7|||||||||FJ|LJFJ|||||J||F-J||L-77LJLJ||LJF--J|FJ|||F-J|||||JF-JL-JL-7|L-7||F--J|L7J7.L|F7-L|| +|L|||FL|F7F--J|-LJF-J|L7FJF7|F7F-7F7|.F-J|||L-JLJ||LJFJ|L7L-7|FJLJ||FJ||F7||F7|F----JL-7|F-7|L7|||L-7|LJ|L-JF-7F7F-JL--JFJL--7L-J.L|.L-|--L7 +||F7L7L||||7|JF---JF7|FJ|FJLJ||L7LJ|L7L-7||L--7F-JL-7|FJFJF7||L--7LJL7|||||||||L7F7F7F7|LJLLJFJ|||-FJL-7|F7FJ-|||L--7F-7L----J7||-J.FF-|7J-- +777JFJ|LJLJJ||L----JLJL-JL7F-J|FJF-JFJF-J|L---JL-7F7||L7|FJ|||F--JF7F||||||LJ|L7||LJ|||L-77F-JFJLJFJF7FJLJ||F7LJL7F-J|FJF7F7.|L-7|.L-J|LF77. +LFL---F|-LJLF------7JF----JL7FJL7L-7|FJF7L------7||||L-J||JLJ|L-7FJL-J||||L-7|FJLJJFJ||F7|FJF7L7F-JFJ|L-7FJLJL--7|L--JL-JLJL7F|JL7.|L|L7LJ-7 +||L7|.L.|L7-L7F-7F7L-JF-7F7FJL7FJF7LJL7|L7F7F-7FJ||||F--JL-7FJF-JL-7F7|LJ|F-JLJF7F-J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-|7J|7||L|--.|J.--F7F|JFJ7.|JF7J.|--J7F7..JLJ7-|-|--.| +L7LL|FL7L|..L7.LLLJJ--J|.J-JJF777||LJ7L|LL.|--.-JFJ|7LF7.F|F-F-7|JLFJF-J-LJ.LLL77.JJ7.-J|7JL--JLJJ|LFF77|-FJF-.-.||LL--||FLFLJ7J.7J.L7F|.FF7 +L|77|JF|7LF-L|F77-|-FLL|.L-J.LL|7J7LFF7L7..L7.-JJF7.FFJ-J-F|7-L-F--L7L-7J|-7|-F||-7LJ7L7L|7-FLFF-7L|.LLJJJJ.|J|.7F|7F-JF7--|.L||F|LJ-FLJFL-7 +F|-LJ|FJJF-J|.L|J7J.LJ|J.L|7..|LLFJ7L||-L7|.LLJ.FL|-|J.L|F-|7|.||FF-L--J---JF--7JF7-||JFJLJ.FFLJ.-7LJ-L7.7--F7JLF7L-|F7JLJ..F7L7JLFLLF7FLF|J +F|-|.-JL--7F-7F|FL77|.-.FLF7.L|FFJFL-|J..LJ-FJ7L-.J-7.7-J.LLL-JJJF||.L|LLFL7LF..F7.F|L-7|J|--J|L.|7L|J|F||F7|F7LJ|-LFF-J|7LLJJ7||-J|LLJ7-77. +LL-JJJ.7JL7J.|-.L--77-L|JLFJ7.L-7JL.L|J.--7.L-JJJ.L.L7--LJ-|JJLLFFJJ-LL-7JLL.J-L-.F-7JJFF.L-LJL-77-F--J-L7L-LLL-LLJ.JJ|LF-J--JLFL.7JJLLJ-L.F \ No newline at end of file diff --git a/src/aoc10test.txt b/src/aoc10test.txt new file mode 100644 index 0000000..3aea4dd --- /dev/null +++ b/src/aoc10test.txt @@ -0,0 +1,5 @@ +7-F7- +.FJ|7 +SJLL7 +|F--J +LJ.LJ From acbd718eb0d4abcaa2ae489e85b4904526a7d0f7 Mon Sep 17 00:00:00 2001 From: Hane Date: Sun, 7 Jan 2024 17:32:02 +0100 Subject: [PATCH 05/10] wip 10-2 --- src/aoc10-2.lisp | 7 ++++--- src/aoc10.lisp | 2 +- src/aoc10test.txt | 15 ++++++++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/aoc10-2.lisp b/src/aoc10-2.lisp index 7650e46..a4e95c9 100644 --- a/src/aoc10-2.lisp +++ b/src/aoc10-2.lisp @@ -35,9 +35,9 @@ ;;(setf node-array (make-array '(line-length line-count) :initial-element nil)) finally - ;;(print line-length) - ;;(print line-count) - (setf node-array (make-array (list line-length line-count) :initial-element nil)) + (print line-length) + (print line-count) + (setf node-array (make-array (list line-count line-length) :initial-element nil)) (setf (aref node-array (cdr starting-pos) (car starting-pos)) t) (return (values input-array node-array starting-pos)) )))) @@ -165,6 +165,7 @@ ) finally + (print "--") (print node-array) (print steps) ) diff --git a/src/aoc10.lisp b/src/aoc10.lisp index 9b4b61b..befdcd0 100644 --- a/src/aoc10.lisp +++ b/src/aoc10.lisp @@ -37,7 +37,7 @@ finally ;;(print line-length) ;;(print line-count) - (setf node-array (make-array (list line-length line-count) :initial-element nil)) + (setf node-array (make-array (list line-count line-length) :initial-element nil)) (setf (aref node-array (cdr starting-pos) (car starting-pos)) t) (return (values input-array node-array starting-pos)) )))) diff --git a/src/aoc10test.txt b/src/aoc10test.txt index 3aea4dd..adaae96 100644 --- a/src/aoc10test.txt +++ b/src/aoc10test.txt @@ -1,5 +1,10 @@ -7-F7- -.FJ|7 -SJLL7 -|F--J -LJ.LJ +.F----7F7F7F7F-7.... +.|F--7||||||||FJ.... +.||.FJ||||||||L7.... +FJL7L7LJLJ||LJ.L-7.. +L--J.L7...LJS7F-7L7. +....F-J..F7FJ|L7L7L7 +....L7.F7||L7|.L7L7| +.....|FJLJ|FJ|F7|.LJ +....FJL-7.||.||||... +....L---J.LJ.LJLJ... From 7983a35b24aeb287fac83624a9fe6c5db5f7d496 Mon Sep 17 00:00:00 2001 From: Hane Date: Tue, 26 Dec 2023 23:29:19 +0100 Subject: [PATCH 06/10] full aoc5-2 --- src/aoc5-2.lisp | 302 +++++++++++++++++++++++++++++++++------------- src/aoc5input.txt | 2 +- src/aoc5test.txt | 2 +- src/aoc6-2.lisp | 7 +- 4 files changed, 225 insertions(+), 88 deletions(-) diff --git a/src/aoc5-2.lisp b/src/aoc5-2.lisp index b8a4e78..afd2e24 100644 --- a/src/aoc5-2.lisp +++ b/src/aoc5-2.lisp @@ -1,91 +1,231 @@ ;; #!/bin/sbcl --script -(defun seed-list (seed-string) - (let ((temp-string "") (source-parsed nil) (temp-source 0) (temp-range 0) (index 0) (return-list '())) - (loop for c across seed-string - do - (if(char= c #\Space) - (cond ((not source-parsed) - (setf temp-source (parse-integer temp-string) ) - (setf temp-string "") - (setf source-parsed t)) - (t (setf temp-range (parse-integer temp-string)) - (setf temp-string "") - ;(setf index temp-range) - (loop while (< index temp-range) - do - (push (+ temp-source index) return-list) - (incf index) - ) - (setf index 0) - (setf source-parsed nil))) - (setf temp-string (format nil "~a~c" temp-string c))) - finally - (setf temp-range (parse-integer temp-string)) - (loop while (< index temp-range) - do - (push (+ temp-source index) return-list) - (incf index))) - (format T "~%~A" return-list) - return-list)) - -(defun parse-map (seed source dest range) - (format T "~%~d-~d-~d-~d" seed source dest range) - (if(and(>= seed source) (<= seed (+ source range))) - (progn - (+ dest (- seed source))) - seed)) - -(defun parse-file (file - + (defun seed-list (seed-string) + (let ((temp-string "") (return-list '()) (base 0) (base-parsed nil) (range 0)) + (loop for c across seed-string + do + (if(char= c #\Space) + (if(not base-parsed) + (progn + (setf base (parse-integer temp-string)) + (setf return-list (append return-list (list base) )) + (setf base-parsed t) + (setf temp-string "")) + (progn + (setf range (parse-integer temp-string)) + (setf return-list (append return-list (list (+ base (- range 1)) ))) + (setf base-parsed nil) + (setf temp-string ""))) + (setf temp-string (format nil "~a~c" temp-string c))) + finally + (setf range (parse-integer temp-string)) + (setf return-list (append return-list (list (+ base (- range 1)) )))) + return-list)) (with-open-file (file "aoc5input.txt") - (let( (digit-line nil) (temp-first-line "") (temp-string "") (manipulated-line "") (code '()) (numbers '()) (translated '())) + (let( (lowest -1) (digit-line nil) (dest-parsed nil) (temp-first-line "") (range "") (temp-string "") + (manipulated-line "") (dest-exploded '()) (source-exploded '()) (yet-to-translate '()) (translated '())) ;;Prep work (setf temp-first-line (read-line file nil)) (setf manipulated-line (subseq temp-first-line (+ 2 (position #\: temp-first-line :test #'equalp)) (length temp-first-line) )) - (setf numbers (seed-list manipulated-line)) - (dolist (item numbers) (push nil translated)) - (print numbers) + (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) - while line - do - (when (equalp 0 (length line)) - (let((current-index 0)) - (print "hola") - (dolist (item translated) - (setf (nth current-index translated) nil) - (incf current-index)))) - (loop for c across line - do - (if(digit-char-p c) - (progn - (setf digit-line t) - (setf temp-string (format nil "~a~c" temp-string c))) - (if digit-line - (progn - (push (parse-integer temp-string) code) - (setf temp-string "")))) - finally - (when digit-line - (push (parse-integer temp-string) code) - (print code) - (let((current-index 0) (translation 0)) - (dolist (item numbers) - (when (not (nth current-index translated)) - (setf translation (parse-map item (nth 1 code) (nth 0 (last code)) (first code))) - (when (not (equal item translation)) - (setf (nth current-index translated) t) - (setf (nth current-index numbers) translation) - (setf translation 0))) - (incf current-index))) - (setf temp-string "") + (loop for line = (read-line file nil) + while line + do + (when (equalp 0 (length line)) + (print (append yet-to-translate translated)) + (print "----") + (setf yet-to-translate (append yet-to-translate translated)) + (setf translated '())) + (loop for c across line + do + (if(digit-char-p c) + (progn + (setf digit-line t) + (setf temp-string (format nil "~a~c" temp-string c))) + (if digit-line + (progn + (if dest-parsed + (push (parse-integer temp-string) source-exploded) + (progn + (setf dest-parsed t) + (push (parse-integer temp-string) dest-exploded))) + (setf temp-string "")))) + finally + (when digit-line + ;;RANGES + ;;(format T "~%~a" temp-string) + ;;(print "newline") + (setf range (parse-integer temp-string)) + (setf source-exploded (append source-exploded (list (+ (first source-exploded) (- range 1))))) + (setf dest-exploded (append dest-exploded (list (+ (first dest-exploded) (- range 1))))) + ;;DANGER ZONE + (let( (unqualified '() ) (done '()) (source-base (nth 0 source-exploded)) (source-end (nth 1 source-exploded)) + (dest-base (nth 0 dest-exploded)) (dest-end (nth 1 dest-exploded)) (len (list-length yet-to-translate)) ) + (loop with index = 0 + with current-base = 0 + with current-end = 0 + while (< index len) + do + (setf current-base (nth index yet-to-translate)) + (setf current-end (nth (+ index 1) yet-to-translate)) + ;;(format T "~%~a ~a ~a ~a" "Current base:" current-base "Current end:" current-end) + ;;(format T "~%~a ~a ~a ~a" "Source base: " source-base "Source end: " source-end) + ;;(format T "~%~a ~a ~a ~a" "Dest base: " dest-base "Dest end: " dest-end) + (if(or(and(<= current-base source-end) (>= current-base source-base)) (and(>= current-end source-base) (<= current-end source-end)) + (and(<= source-end current-end) (>= source-base current-base)) ) + (progn + ;;(print "based") + (if (> current-end source-end) + (progn + (setf unqualified (append unqualified (list (+ source-end 1) current-end))) + (setf done (append done (list dest-end )))) + (setf done (append done (list (- dest-end (- source-end current-end))) ))) + (if (< current-base source-base) + (progn + (setf unqualified (append unqualified (list current-base (- source-base 1) ))) + (push dest-base done)) + (push (+ dest-base (- current-base source-base)) done)) + ;;(format T "~%~a ~A" "Done:" done) + (setf translated (append translated done)) + (setf done '())) + (progn + ;;(print "unbased") + (setf unqualified (append unqualified (list current-base current-end) )))) + ;;(format T "~%~a ~A ~a ~A" "Run unqualified:" unqualified "Translated:" translated) + (setf index (+ index 2))) + (setf yet-to-translate unqualified) ) + ;;CLEANUP + ;;(format T "~%~a ~A" "SE:" source-exploded) + ;;(format T "~%~a ~A" "DE:" dest-exploded) + ;;(format T "~%~a ~A ~a ~A" "Translated:" translated "Yet to translate:" yet-to-translate) (setf digit-line nil) - (setf code '())) )) - (format T "~%~a ~A" "Result: " numbers) - (let( (lowest (first numbers))) - (dolist (item numbers) - (when (< item lowest) (setf lowest item))) - (print lowest)))) + (setf dest-parsed nil) + (setf temp-string "") + (setf source-exploded '()) + (setf dest-exploded '()) ) + )) + + (format T "~%~a ~A" "final: " (append yet-to-translate translated)) + (print (list-length (append yet-to-translate translated))) + (dolist (item (append yet-to-translate translated)) + (when (or (= lowest -1) (< item lowest)) + (setf lowest item))) + (print lowest))) + + + + +;; ;; #!/bin/sbcl --script +;; (defun seed-list (seed-string file-content) +;; (let ((temp-string "") (lowest -1) (base 0) (base-parsed nil) (range 0)) +;; (loop for c across seed-string +;; do +;; (if(char= c #\Space) +;; (if(not base-parsed) +;; (progn +;; (setf base (parse-integer temp-string)) +;; (setf base-parsed t) +;; (setf temp-string "")) +;; (progn +;; (setf range (parse-integer temp-string)) +;; (loop with current-index = 0 +;; with return-value = 0 +;; while (< current-index range) +;; do +;; (format T "~%~a ~d" "FS:" (+ base current-index)) +;; (setf return-value (transform-value (+ base current-index) file-content)) +;; ;(format T "~%~a ~d-~d-~d-~d ~a ~d" "Seed-List:" base range current-index (+ base current-index) "Retval:" return-value) +;; (if (equalp -1 lowest) +;; (setf lowest return-value) +;; (when(< return-value lowest) +;; (setf lowest return-value))) +;; (incf current-index)) +;; (setf base-parsed nil) +;; (setf temp-string ""))) +;; (setf temp-string (format nil "~a~c" temp-string c))) +;; finally +;; (setf range (parse-integer temp-string)) +;; (loop with current-index = 0 +;; with return-value = 0 +;; while (< current-index range) +;; do +;; (format T "~%~a ~d ~a ~d" "FS:" (+ base current-index) "Index:" current-index) +;; (setf return-value (transform-value (+ base current-index) file-content)) +;; ;(format T "~%~a ~d-~d-~d-~d ~a ~d" "Seed-List:" base range current-index (+ base current-index) "Retval:" return-value) +;; (if (equalp lowest -1) +;; (setf lowest return-value) +;; (when(< return-value lowest) +;; (setf lowest return-value))) +;; (incf current-index)) +;; ) +;; lowest)) + +;; (defun transform-value (seed file-content) +;; (let( (digit-line nil) (stream "") (final-seed 0) (temp-string "") (code '()) (translated nil)) +;; (setf final-seed seed) +;; (setf stream (make-string-input-stream file-content)) +;; (loop for line = (read-line stream nil) +;; while line +;; do +;; ;(print line) +;; (when (equalp 0 (length line)) +;; (setf translated nil)) +;; (loop for c across line +;; do +;; (if(digit-char-p c) +;; (progn +;; (setf digit-line t) +;; (setf temp-string (format nil "~a~c" temp-string c))) +;; (if digit-line +;; (progn +;; (push (parse-integer temp-string) code) +;; (setf temp-string "")))) +;; finally +;; (when digit-line +;; (push (parse-integer temp-string) code) +;; ;(print code) + +;; (when (not translated) +;; (let( (temp-translate 0) ) +;; (setf temp-translate (parse-map final-seed (nth 1 code) (nth 0 (last code)) (first code))) +;; ;(format T "~%~a ~d" "Translated to:" final-seed) +;; (when(not(equalp temp-translate final-seed)) +;; (setf final-seed temp-translate) +;; (setf translated t)))) + +;; (setf temp-string "") +;; (setf digit-line nil) +;; (setf code '())) ) + +;; ) +;; final-seed)) + +;; (defun parse-map (seed source dest range) +;; ;(format T "~%~a ~d-~d-~d-~d" "Parse-map:" seed source dest range) +;; (if(and(>= seed source) (<= seed (+ source range))) +;; (progn +;; (+ dest (- seed source))) +;; seed)) + +;; (with-open-file (file "aoc5input.txt") +;; (let( (file-content "") (manipulated-line "") ) +;; ;;Prep work +;; (setf file-content (read-line file nil)) +;; (setf manipulated-line (subseq file-content (+ 2 (position #\: file-content :test #'equalp)) (length file-content) )) +;; (setf file-content "") +;; (read-line file nil) + +;; (loop for line = (read-line file nil) +;; while line +;; do +;; (if(not(string= file-content "")) +;; (setf file-content (format nil "~a~%" file-content))) +;; (setf file-content (format nil "~a~a" file-content line)) +;; ) +;; ;(print manipulated-line) +;; (print (seed-list manipulated-line file-content)) )) diff --git a/src/aoc5input.txt b/src/aoc5input.txt index 6cab5eb..bd43a49 100644 --- a/src/aoc5input.txt +++ b/src/aoc5input.txt @@ -274,4 +274,4 @@ humidity-to-location map: 2575348595 2130499969 195699098 593882556 705484119 648158843 3871554698 3932373353 42274873 -2998499327 1650316948 79272282 \ No newline at end of file +2998499327 1650316948 79272282 diff --git a/src/aoc5test.txt b/src/aoc5test.txt index bd902a4..f756727 100644 --- a/src/aoc5test.txt +++ b/src/aoc5test.txt @@ -30,4 +30,4 @@ temperature-to-humidity map: humidity-to-location map: 60 56 37 -56 93 4 \ No newline at end of file +56 93 4 diff --git a/src/aoc6-2.lisp b/src/aoc6-2.lisp index 2aef4af..e8a2d09 100644 --- a/src/aoc6-2.lisp +++ b/src/aoc6-2.lisp @@ -25,7 +25,6 @@ (with-open-file (file "aoc6input.txt") (let( (file-lines '()) (time-list '()) (distance-list '()) (result 1) ) - (loop for line = (read-line file nil) while line do @@ -39,7 +38,5 @@ do ;(print (num-ways-to-win (nth index time-list) (nth index distance-list))) (setf result (* result (num-ways-to-win (nth index time-list) (nth index distance-list)))) - (incf index) - ) - (print result) - )) + (incf index)) + (print result))) From 78baf9a52dd0f9cb824bd6ccf407f9d0fe0d2586 Mon Sep 17 00:00:00 2001 From: Hane Date: Sat, 30 Dec 2023 18:46:13 +0100 Subject: [PATCH 07/10] full aoc8 --- src/aoc11.lisp | 97 ++++++ src/aoc11input.txt | 140 ++++++++ src/aoc11test.txt | 10 + src/aoc8-2.lisp | 175 ++++++++++ src/aoc8.lisp | 40 +++ src/aoc8input.txt | 796 +++++++++++++++++++++++++++++++++++++++++++++ src/aoc8test.txt | 11 + 7 files changed, 1269 insertions(+) create mode 100644 src/aoc11.lisp create mode 100644 src/aoc11input.txt create mode 100644 src/aoc11test.txt create mode 100644 src/aoc8-2.lisp create mode 100644 src/aoc8.lisp create mode 100644 src/aoc8input.txt create mode 100644 src/aoc8test.txt diff --git a/src/aoc11.lisp b/src/aoc11.lisp new file mode 100644 index 0000000..33d2e98 --- /dev/null +++ b/src/aoc11.lisp @@ -0,0 +1,97 @@ + +(defun input-parsing (path) + (with-open-file (file path) + (let( (galaxy-columns '()) (data-line nil) (galaxies (make-array 0 :adjustable t)) (current-line 0) ) + ;;Prep work + ;;(defparameter keys (make-array 0 :adjustable t)) + ;;(defparameter parsed '()) + ;;(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) + ;; (let( (size (+ 1 (length keys))) ) + ;; (adjust-array keys size) (decf size) + ;; (setf (aref keys size) key) )) + + (loop for line = (read-line file nil) + with key = "" + with left-value = "" + with right-value = "" + while line + do + (when(zerop current-line) + (dotimes (i (length line)) + (push nil galaxy-columns))) + (loop for c across line + with char-position = 0 + do + (when (char= c #\#) + (let( (size (+ 1 (length galaxies))) ) + (adjust-array galaxies size) (decf size) + (setf (aref galaxies size) (cons current-line char-position)) ) + (format T "~% ~d ~A" char-position galaxy-columns) + (setf (nth char-position galaxy-columns) t) + ;;(setf (nth i parsed) nil) + (setf data-line t)) + (incf char-position) + finally + (if (not data-line) + (incf current-line)) + (incf current-line) + (setf data-line nil)) + ) + galaxies))) + +(print (input-parsing "aoc11test.txt")) + ;;(print "Hola") + ;;(print (aref keys 0)) + + ;; (incf (nth 0 steps-per-key)) + ;; (if(char= c #\L) + ;; (setf (aref keys 0) (car(gethash (aref keys 0) route-hash))) + ;; (setf (aref keys 0) (cdr(gethash (aref keys 0) route-hash)))) + ;; ;;(print (aref keys 0)) + + ;; (when(char= (char (aref keys 0) 2) #\Z) + ;; (format T "~%~a ~d" "Ayo on key 0 found at: " (nth 0 steps-per-key)) + ;; (dotimes (i (length keys)) + ;; ;;(print (+ i 1)) + ;; ;;(print (length keys)) + ;; ;;(when (< (+ i 1) (length keys)) + ;; (when (> i 0) + + ;; ;;WTF + ;; (sb-thread:make-thread (lambda () (hashmap-parse route-hash direction-line (length direction-line) (- i 1) (nth 1 steps-per-key) (nth 0 steps-per-key)) ) ) + ;; ;;(format T "~%~d" i) + ;; ) + ;; ) + ;; (loop while (not (every #'null parsed)) + ;; do + ;; ;;(print parsed) + ;; (sleep 1)) + ;; (dotimes (i (length parsed)) + ;; (if (= i 0) + ;; (setf (nth i parsed) nil) + ;; (setf (nth i parsed) t))) + + ;; (loop with i = 1 + ;; with failure = nil + ;; while (and(< i (length keys)) (not failure)) + ;; do + ;; (setf (nth i steps-per-key) (nth 0 steps-per-key)) + ;; (if(char= (char (aref keys i) 2) #\Z) + ;; (progn + ;; (incf i) ) + ;; (setf failure t)) + ;; finally + ;; (if(= i (length keys)) + ;; (setf goal-to-be-reached t)) + ;; )) + ;; ) + ;; (print (nth 0 steps-per-key)) + ;; (setf keys (make-array 0 :adjustable t)) + ;; (setf parsed '()))) + ;; ) diff --git a/src/aoc11input.txt b/src/aoc11input.txt new file mode 100644 index 0000000..794d39e --- /dev/null +++ b/src/aoc11input.txt @@ -0,0 +1,140 @@ +.....................#......#...................#...............#........................................#.................................. +...........................................................#.............................................................#.................. +.....................................................................#.........#......#...........#.............#........................... +.....................................................#.......................................#.............................................. +......#.................................#..........................................................................................#........ +....................#.........#.............................................................................#............................... +..#.........................................................#.............................................................................#. +........................................................................................#...........#..................#.................... +........#....................................#........................#.........................................................#........... +..............................................................................#................................#............................ +..................................................#............#............................................................................ +.........................#......#........#................................................#..........................................#...... +......#..............................................................................#...............#...................................... +...................................................................#........................................................................ +....................#...........................#............................................................#..............#.....#......... +..................................#....................#.........................................#......#..............................#.... +.#.......................................................................................................................................... +........#.....#........................#...........#.............#.....................#.................................................... +..........................#.................................#.....................#......................................................... +.............................................................................................................................#.............# +...................................#......................................................#....................#............................ +.....................#...................#............#..................#.............................................#...........#........ +..............................................................................................#............................................. +....#..........#...............#..........................................................................#................................. +.............................................#.............................................................................................. +...................................................................#..............#.................................#....................... +..................#........................................................#................................................................ +..#.................................#...................#..............................#.........................................#.......#.. +...............................................................#...............#.....................#..........#.........#................. +.........#......................#.............................................................#............................................. +..............#...............................#............................................................................................. +........................................#.................................#............................................................#.... +..............................................................................................................#......#......#............... +.........................#..........#.............................................#........#................................................ +....................................................................#.....................................#................................. +....#...............#........#...............................#........................#........................................#............ +........................................................#................................................................................... +............................................#...........................#......................#.....#...................................... +.........................................................................................#.............................................#.... +...........#....................#..................................#.................................................#...........#.......... +.#.......................................................................................................................................... +................#........................#..........#....................................................................................... +........................#........................................................................................#.......................... +........................................................................#.........#...................#...................#................. +........................................................#......................................................................#............ +.....#.....................................................................................#................................................ +...............#...................................#.................#..............................................................#....... +.........#..................#..................................#..................................................#......................... +......................................#.......#....................................#......................................................#. +..........................................................................................................#......................#.......... +...#..............#.......................#.....................................................#........................................... +................................#...............................................#..........#................................................ +..........................#......................#......................#................................................................... +..................................................................#................................#........................................ +......................................................#.................................#.........................#...................#..... +..............#..........................#..................................................................................#............... +......#......................#.................................................................#...........#................................ +.............................................................................#.............................................................. +.......................#..........................#......................................................................#..........#....... +.#.................................#................................................................#....................................#.. +........#......#................................................#...............................................#........................... +..........................................................................#.....#.........................#...........#.....#............... +............................#..............#..........#....................................#................................................ +............................................................................................................................................ +............#..........#.................................................................................................................... +............................................................#.......................#..............#........................................ +.....................................#...............................#...................................#.................................. +.........#.....................................................................#.....................................#...............#.....# +#.............#............................................................................................................................. +......................................................#....................................#....................................#........... +...................................................................#............................................#........................... +............................................................................................................................................ +....................#............................#................................................#......................................#.. +.............................#...................................................#.......................................................... +.........................................................................#...............#.................#................................ +.............#.........#.........#.....#......................#............................................................#................ +............................................................................................................................................ +.............................................#..........#.....................#..................................#.......................... +............................................................................................................................................ +...................................#.............#................#.....#.....................................................#............. +....#.....................#..................................#.............................................................................. +............................................................................................................................................ +#.....................................#...................................................................................#................. +...............................................#......................#.....#...................................#........................... +.........#...................#.....................................................#.................#...................................... +.......................#...............................#........................................#..............................#............ +...#.....................................#..................................................................#............................... +...................................................#......................................#...........................................#..... +.................#.......................................................................................................................... +...................................................................................................................#......#................. +.................................#..............#.....#......................#.................#.........#.................................. +#....................................................................#........................................#...........................#. +............................................................................................................................................ +.........................#.................................................................................................................. +...............................#.......................................................................................#.................... +..........#...................................#..................#.....................#....................#............................... +............................................................................#.....#......................................................... +....#............#............................................................................#.......#..........#.......................... +..................................................................................................................................#......... +...................................#...........................................#............................................................ +.............................#..........................#.................................#........#........................................ +..............#....................................................#........................................#.............#...........#..... +...............................................#.............#.......................................................#...................... +........#..............................................................#.................................................................... +.......................................................................................#........#........................................... +......................#........#.........................#..................#........................#......................#............... +.#.........#.....#..............................................#........................................................................#.. +.....................................................#...................................................................................... +.........................................#...........................#..............................................#....................... +.............................................................#................................................#................#............ +......#.......................................#.......................................#...............#..................................... +....................#.......#............................#................#...........................................................#..... +...........#.....................................................................................................#.......................... +..........................................................................................#..............#.................................. +..................................................#..........................................................................#.............. +...............#............................................#.....................................................................#......... +........................#...........................................#............................#..................#....................... +................................................................................#..............................#.......................#.... +......................................#...................................#..............#..............#................................... +..#............................................#..............#...........................................................#................. +.........#........................#...................#..................................................................................... +.............................#.............................................................................................................. +....................................................................................#....................................................... +.........................#.............#............................................................#......#......#.........#......#........ +...................#...........................................................................#...........................................# +.......#...............................................#.....#........#..........#.......................................................... +..............#....................#........................................................................................................ +........................................................................................................#.................#...........#..... +..#...............................................................#.........#.......#....................................................... +.........#......................#..........................#.....................................#............#............................. +...................#.................................#.................................................................#.................... +....................................#....................................................................................................... +...........................#......................................................................................................#......... +............................................#.................#............#...................#.......#...................#................ +............#.....................................#......................................................................................... +...........................................................................................................#......#......................... +.....................................#..............................................#......#................................................ +.........................................................................#..............................................#................... +#....................#........#...................................................................#.....................................#... +.....#........................................#.........#........................#.......................................................... \ No newline at end of file diff --git a/src/aoc11test.txt b/src/aoc11test.txt new file mode 100644 index 0000000..a0bda53 --- /dev/null +++ b/src/aoc11test.txt @@ -0,0 +1,10 @@ +...#...... +.......#.. +#......... +.......... +......#... +.#........ +.........# +.......... +.......#.. +#...#..... \ No newline at end of file diff --git a/src/aoc8-2.lisp b/src/aoc8-2.lisp new file mode 100644 index 0000000..37a11e9 --- /dev/null +++ b/src/aoc8-2.lisp @@ -0,0 +1,175 @@ +#!/bin/sbcl --script + +(defparameter keys (make-array 0 :adjustable t)) +(defparameter parsed '()) +(defparameter steps-per-key '()) +(print (sb-thread:list-all-threads)) + +(with-open-file (file "aoc8input.txt") + (let( (goal-to-be-reached nil) (direction-line "") (route-hash (make-hash-table :test #'equalp :size 800)) ) + ;;Prep work + (defparameter keys (make-array 0 :adjustable t)) + (defparameter parsed '()) + (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 = "" + 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)) + (when(char= #\A (char key 2)) + (let( (size (+ 1 (length keys))) ) + (adjust-array keys size) (decf size) + (setf (aref keys size) key) )) + ) + + ;;(print keys) + ;;(print parsed) + (dotimes (i (length keys)) + (push 0 steps-per-key) + (push t parsed)) + (setf (nth 0 parsed) nil) + ;;(print steps-per-key) + ;;(print parsed))) + + (loop while (not goal-to-be-reached) + do + (loop for c across direction-line + while (not goal-to-be-reached) + do + ;;(print "Hola") + ;;(print (aref keys 0)) + (incf (nth 0 steps-per-key)) + (if(char= c #\L) + (setf (aref keys 0) (car(gethash (aref keys 0) route-hash))) + (setf (aref keys 0) (cdr(gethash (aref keys 0) route-hash)))) + ;;(print (aref keys 0)) + + (when(char= (char (aref keys 0) 2) #\Z) + ;;(format T "~%~a ~d" "Ayo on key 0 found at: " (nth 0 steps-per-key)) + (dotimes (i (length keys)) + ;;(print (+ i 1)) + ;;(print (length keys)) + ;;(when (< (+ i 1) (length keys)) + (when (> i 0) + ;;WTF + (sb-thread:make-thread (lambda (x hashmap dir strlen steps) (hashmap-parse hashmap dir strlen x steps) ) :arguments (list i route-hash direction-line (length direction-line) (nth i steps-per-key) ) ) + ;;(format T "~%~d" i) + ) + ) + ;;(print parsed) + (loop while (not (every #'null parsed)) + do + (print parsed) + (sleep 1)) + (print steps-per-key) + (setf goal-to-be-reached t) + (print (apply #'lcm (append steps-per-key (list (length direction-line))))))))) + (print "awaa") + ;;(print (nth 0 steps-per-key)) + (setf keys (make-array 0 :adjustable t)) + (setf parsed '())) + + (defun starting-char (strlen steps) + (loop while (>= steps strlen) + do + (setf steps (- steps strlen))) + steps) + + (defun hashmap-parse (hashmap direction-string strlen key-position steps) + (let( (current-char (starting-char strlen steps) ) (z-found nil) ) + ;;(print steps) + (loop while (not z-found) + do + (incf steps) + ;;(format T "~%~c" direction-char) + ;;(print current-char) + (if(char= (char direction-string current-char) #\L) + (setf (aref keys key-position) (car(gethash (aref keys key-position) hashmap))) + (setf (aref keys key-position) (cdr(gethash (aref keys key-position) hashmap)))) + + (incf current-char) + (when(= current-char strlen) + (setf current-char 0)) + (when(char= (char (aref keys key-position) 2) #\Z) + (setf z-found t) + (setf (nth key-position parsed) nil) + (setf (nth key-position steps-per-key) steps)) + ) + )) + +;; (defvar *directions*) +;; (defvar *ndirections*) +;; (defvar *map* (make-hash-table :test #'equal)) + +;; ;;(setf *print-circle* t) +;; (defun parse-file (path) +;; (with-open-file (file path) +;; (loop +;; :with first-line = (read-line file nil) +;; :with second-line = (read-line file nil) +;; :initially +;; ;; Parse first line +;; (setf *directions* (coerce first-line 'list)) +;; ;; Turn directions into a cyclical list +;; (setf *ndirections* (length *directions*)) +;; (setf (cdr (last *directions*)) *directions*) +;; :for line = (read-line file nil) +;; :while line +;; :for key = (subseq line 0 3) +;; :for left = (subseq line 7 10) +;; :for right = (subseq line 12 15) +;; :do +;; (setf (gethash key *map*) (cons left right))))) + +;; (defun part-1 () +;; (loop :for direction = (car p) +;; :for current-node = "AAA" :then (if (char= #\L direction) (car paths) (cdr paths)) +;; :for p = *directions* :then (cdr p) +;; :for paths = (gethash current-node *map*) +;; :for n :from 0 +;; :until (string= current-node "ZZZ") +;; ;; :do (format t "Step ~S:~%~tCurrent node: ~S~%~tLast direction: ~S~% Possible paths: ~S~%" n current-node direction paths) +;; :finally +;; (print n))) + +;; (defun part-2 () +;; (loop :with initial-keys = (loop :for key :being :the :hash-keys :of *map* :if (char= (char key 2) #\A) :collect key) +;; :with distance-maps = (loop :for key :in initial-keys :collect (make-hash-table :test #'equal)) +;; :for key :in initial-keys +;; :for distance-map :in distance-maps +;; :do +;; (setf (gethash key distance-map) 0) +;; (explore-map distance-map key 1) +;; :finally +;; (return (apply #'lcm (append (mapcar #'cdar (mapcar #'distance-to-z distance-maps)) (list *ndirections*)))) +;; ;;(return distance-maps) +;; )) + +;; (defun distance-to-z (distance-map) +;; (loop :with z-keys = (loop :for key :being :the :hash-keys :of distance-map :if (char= (char key 2) #\Z) :collect key) +;; :for key :in z-keys +;; :collect (cons key (gethash key distance-map)))) + +;; (defun explore-map (distance-map node distance) +;; (let ((options (gethash node *map*))) +;; (when (> (gethash (car options) distance-map 9999) distance) +;; ;; We found a shorter path +;; (setf (gethash (car options) distance-map) distance) +;; (explore-map distance-map (car options) (1+ distance))) +;; (when (> (gethash (cdr options) distance-map 9999) distance) +;; ;; We found a shorter path +;; (setf (gethash (cdr options) distance-map) distance) +;; (explore-map distance-map (cdr options) (1+ distance))) +;; )) diff --git a/src/aoc8.lisp b/src/aoc8.lisp new file mode 100644 index 0000000..b4ecddd --- /dev/null +++ b/src/aoc8.lisp @@ -0,0 +1,40 @@ +;; #!/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))) diff --git a/src/aoc8input.txt b/src/aoc8input.txt new file mode 100644 index 0000000..ac178d0 --- /dev/null +++ b/src/aoc8input.txt @@ -0,0 +1,796 @@ +LRRLRLRRRLLRLRRRLRLLRLRLRRLRLRRLRRLRLRLLRRRLRRLLRRRLRRLRRRLRRLRLRLLRRLRLRRLLRRRLLLRRRLLLRRLRLRRLRLLRRRLRRLRRRLRRLLRRRLRRRLRRRLRLRRLRLRRRLRRRLRRLRLRRLLRRRLRRLLRRLRRLRLRLRRRLRLLRRRLRRLRRRLLRRLLLLLRRRLRRLLLRRRLRRRLRRLRLLLLLRLRRRLRRRLRLRRLLLLRLRRRLLRRRLRRRLRLRLRRLRRLRRLRLRLLLRLRRLRRLRRRLRRRLLRRRR + +RBX = (TMF, KTP) +RBP = (MKS, MKS) +CGR = (XDR, VDX) +KBX = (DGP, JKM) +BNJ = (NJC, QRL) +BXQ = (DKX, CJQ) +NDX = (PHJ, TRQ) +KFQ = (KXN, GBQ) +LRF = (CTS, MTT) +RTN = (VMK, JTK) +QKP = (FDS, SFG) +BVB = (BHS, VRQ) +NBT = (BPJ, DFF) +HQM = (QMV, XVG) +XMR = (RKH, NJQ) +PHC = (XHP, DKM) +HTX = (BXK, BQP) +TPJ = (TNQ, QDX) +RDJ = (KHB, MFG) +XTF = (PPR, FHG) +DVA = (DBM, MVD) +HFP = (CXV, VCD) +HPS = (GTD, NBL) +LBK = (FVN, LHX) +KKS = (FKM, LHN) +FJV = (LVN, PLP) +MLH = (SFR, RJK) +SVQ = (RCS, FFD) +PTB = (TMC, QCR) +RFL = (RXP, VRL) +PTH = (XTS, GFG) +QNM = (TJR, MHX) +BJT = (PJG, SHG) +JJD = (FMJ, QVV) +GMX = (CLD, QRM) +DGZ = (BSL, BRS) +BVM = (SFC, JGD) +GNQ = (PLP, LVN) +XPG = (VLH, BCM) +PND = (RXV, VGM) +RNV = (GVL, MTB) +JSG = (QVP, XCX) +QHP = (KQG, BML) +XBK = (NPP, CRN) +QRL = (RQH, BGH) +HDJ = (VRQ, BHS) +XPD = (HSB, LRC) +KJK = (XCV, MDG) +NJB = (RKL, SHQ) +MCQ = (XFT, MRQ) +QRC = (XVS, CSN) +FCT = (DFF, BPJ) +MTF = (PQT, CNQ) +RXG = (QVP, XCX) +MVZ = (QRC, GHJ) +RKL = (QQM, BFT) +VRT = (GMJ, BDK) +BNS = (HQV, HPS) +JSQ = (HTC, PGD) +BHB = (VGQ, BTM) +NLP = (RKB, XQB) +FGF = (CVK, VRT) +FPM = (GDS, LTG) +BCX = (NDX, GSL) +GVL = (VCX, PSP) +KRM = (MHK, JCX) +GLJ = (XNX, RKP) +LBV = (FDC, TPJ) +GSP = (KMC, LQR) +TFR = (HXJ, MFJ) +DLX = (FNK, GLJ) +DKX = (XSR, LHP) +SVR = (KPX, QTM) +JMT = (GXV, RTX) +XSX = (HHD, HHD) +RJF = (BRH, HGP) +BDK = (TGX, HKP) +TFF = (DSX, DSX) +TJR = (BKB, LCB) +BDQ = (CLD, QRM) +NTC = (BQL, BQL) +CVS = (RQC, FFV) +BML = (VNT, JRH) +CBK = (TGB, RTN) +HQV = (GTD, NBL) +PDT = (SRQ, MLD) +RXV = (KJK, FCD) +XTS = (SCG, KQJ) +PXG = (LKG, MTQ) +PCX = (FKJ, FCV) +HKR = (LMK, BJR) +CKK = (XSX, XSX) +TNP = (TDH, JPR) +PCH = (RBP, PQH) +KHB = (RQR, BXQ) +CJZ = (CNC, HJX) +JPN = (FRP, QTB) +RKP = (NKH, FQC) +BDP = (GCM, VKT) +HQX = (TQF, NJB) +PFV = (FPM, VNP) +NFQ = (GFX, GXH) +STX = (MCQ, DNS) +CKX = (CFS, BNS) +NRJ = (SBG, TLK) +DHS = (VBH, VMT) +TVL = (BPQ, NBM) +QTF = (MPS, RJB) +FHV = (LMK, BJR) +JCV = (JSQ, STQ) +RGX = (GVL, MTB) +CTS = (PCB, GJV) +RCS = (TNT, XTF) +PCS = (NJH, RLX) +KNG = (CHP, FNN) +FJL = (KKH, QGQ) +CPK = (KTX, CGR) +BLF = (PCQ, TKN) +FCR = (STF, SVQ) +BSL = (GFJ, CDL) +FKS = (GRG, JSB) +FCM = (LFX, RJF) +XLK = (CDP, CBD) +KNB = (VGQ, BTM) +KGC = (TJR, MHX) +JHM = (JSP, XDN) +HFN = (STF, SVQ) +GCM = (CKX, KPS) +CGV = (MHK, JCX) +TQP = (JRM, XSB) +GSM = (FJV, GNQ) +KBL = (DLX, BGD) +CBC = (MQK, RRF) +NJM = (KLQ, BVL) +THG = (CPG, PND) +DXP = (HDJ, BVB) +DTT = (XDN, JSP) +PLP = (BKF, FGP) +MSZ = (MVD, DBM) +BQC = (NPL, VXF) +CGB = (LRM, MTH) +RLX = (DBT, RJN) +RXP = (HFP, JNS) +TTH = (QNF, KNG) +LHS = (QFR, GTN) +NBL = (THT, VTQ) +DRS = (PJH, STX) +PSP = (CPK, QKF) +PPR = (LQK, VSN) +QHT = (RLG, TDG) +FVM = (MLR, HXF) +DHB = (CQC, BKK) +MVP = (GHJ, QRC) +TDG = (RVX, CDB) +LKN = (HXF, MLR) +CNR = (KCV, CDR) +SMC = (BBR, BMS) +QDP = (LXV, VPS) +LLD = (CGC, NGQ) +KXN = (PRR, PSR) +LRC = (SHB, PBK) +SQD = (LBV, CRP) +QTB = (KNS, JTS) +MTT = (GJV, PCB) +GMV = (JNH, MJF) +DTG = (SQD, KVV) +RTV = (DSB, SJB) +CDL = (FTQ, CPN) +JHR = (JRM, XSB) +BFP = (PFG, MTD) +DTB = (NDX, GSL) +SQM = (CXL, NBD) +NBP = (KBN, LQH) +BTC = (LJT, TCV) +PQT = (PXG, BSF) +QDH = (FPM, VNP) +VPT = (PRT, VHJ) +VKC = (GXK, QSB) +NXB = (QKP, TGK) +FDF = (VRT, CVK) +NTG = (FRV, BQR) +RKB = (PHC, JSD) +MHV = (XXL, THG) +PHV = (SNM, TFR) +XRK = (JNN, LKR) +XVS = (CBK, NNM) +GDQ = (BDQ, GMX) +TKR = (CKJ, LVQ) +XCX = (LSP, FNB) +JCX = (FGF, FDF) +MFJ = (DBB, HBH) +BQP = (HRT, DQD) +VNC = (BDQ, GMX) +SSC = (LQH, KBN) +TJD = (QFV, KRS) +NKL = (CKK, DDC) +NTM = (QHG, MCC) +JBQ = (HXV, JPN) +DGP = (FVM, LKN) +SJB = (LRQ, DMG) +LJT = (MMT, MDL) +RFC = (MVM, JXP) +FFV = (TPG, QMD) +PJH = (DNS, MCQ) +VCD = (FHV, HKR) +MPS = (DHH, LPT) +VHJ = (RGX, RNV) +FLT = (FRF, NHG) +DSF = (SDV, VKC) +HJQ = (CDR, KCV) +BQR = (PDX, PMX) +CRJ = (BPN, KKS) +MQN = (PNN, DHB) +KCC = (KMC, LQR) +BTH = (VLH, BCM) +KNS = (GGM, SJS) +SCG = (MBF, RDR) +VDQ = (JNN, LKR) +XFT = (VPT, FLH) +RDR = (GTF, GJR) +CXS = (RRF, MQK) +XDN = (SSF, VGC) +JPR = (VGX, TCF) +BTF = (LKM, GBG) +GCJ = (VPS, LXV) +FGJ = (XVG, QMV) +MBF = (GJR, GTF) +TPG = (TND, QSF) +BNR = (BHG, SMC) +GJV = (FLB, PCX) +LQF = (BJT, KTN) +VSB = (JVB, FVK) +NHB = (HQX, LLQ) +CKC = (PJD, TRS) +JVB = (QQV, NRS) +BKK = (LSR, LJN) +SBV = (GTN, QFR) +JMK = (MFG, KHB) +LPX = (NBP, SSC) +KLJ = (CDX, VTL) +KQJ = (RDR, MBF) +VMK = (JXJ, BMT) +TRS = (LQM, JJD) +KCM = (XBD, XMH) +JCT = (NFQ, NDJ) +FGM = (HMK, PGQ) +QKK = (RLS, LPX) +QJD = (PDT, RPQ) +LHP = (PLN, MQN) +NPL = (TFF, TFF) +XHP = (PJQ, KBL) +HMK = (JNV, XPS) +KMC = (VCG, NTG) +QDX = (TMM, HHM) +VNP = (LTG, GDS) +PDR = (CDX, VTL) +HVK = (BQC, SCN) +QMV = (BNJ, CRL) +DDR = (KRS, QFV) +RDG = (QHP, QXN) +CRL = (NJC, QRL) +SHB = (SQX, JVV) +TSP = (BPX, FVC) +RRF = (KJB, PTB) +CSG = (FRX, RTP) +RPQ = (SRQ, MLD) +VXS = (MTN, DJQ) +PJK = (NGD, NTM) +QHG = (NXT, DHS) +LSP = (MTR, GGH) +SHN = (JJS, RVC) +TNQ = (TMM, HHM) +NPK = (GCM, VKT) +MJF = (NBT, FCT) +JNN = (PTH, HFK) +NRS = (CLT, HGV) +HSX = (BPX, FVC) +MVM = (DSF, NQS) +PBK = (SQX, JVV) +HHD = (DBM, MVD) +MTD = (DVB, BTX) +PXP = (NPP, CRN) +TMF = (LPF, QPD) +BRT = (FJV, GNQ) +MFQ = (BHG, SMC) +DJQ = (MVP, MVZ) +LKR = (PTH, HFK) +STQ = (HTC, PGD) +DXF = (JBX, TRT) +RJN = (PDR, KLJ) +CGC = (KKL, RJV) +SRG = (QKK, LND) +MCC = (DHS, NXT) +JMG = (RLX, NJH) +NKH = (DGF, FJL) +JXP = (DSF, NQS) +GXX = (CKC, MFL) +MXD = (KBC, FGK) +SCH = (XPG, BTH) +XSR = (MQN, PLN) +KKD = (NBD, CXL) +CLJ = (GCN, GCN) +QVV = (THK, LQV) +VLH = (FFB, STD) +RTP = (CBC, CXS) +RVX = (BLF, PTM) +KBN = (JNF, BTC) +PFX = (JHM, DTT) +NVL = (KCM, DLK) +QRM = (CQK, RBB) +HKP = (SHN, TMV) +VXF = (TFF, JRP) +LDL = (LHM, JMT) +BQL = (DRS, VQQ) +FDC = (TNQ, QDX) +MMT = (MSL, JCT) +CXV = (HKR, FHV) +BKB = (FCM, QTC) +HRQ = (RXG, JSG) +RKH = (JFF, TKR) +VQR = (JGD, SFC) +KCV = (LNG, NCV) +XSB = (DTG, DFK) +JGD = (HLP, FNS) +VCK = (RXP, VRL) +GTN = (BCP, CKB) +QDK = (CBD, CDP) +SNF = (JNH, MJF) +FVK = (QQV, NRS) +HHM = (VXK, PJK) +JRM = (DTG, DFK) +QPL = (XLK, QDK) +SCV = (QHP, QXN) +RQC = (QMD, TPG) +LFX = (BRH, HGP) +FRX = (CXS, CBC) +BTM = (FPK, JVF) +BPN = (LHN, FKM) +LRQ = (LSQ, PMP) +TPV = (LQF, KDN) +XBN = (QDS, DXP) +RBB = (FCR, HFN) +XSM = (LNT, STB) +SBR = (PQT, CNQ) +LVM = (SBV, LHS) +KBC = (JHR, TQP) +DLJ = (FGK, KBC) +LKG = (VJX, HLQ) +NXT = (VMT, VBH) +CBD = (HGN, HBG) +BHS = (VTF, MRV) +BTP = (GBG, LKM) +DSM = (CKK, CKK) +LSR = (CMB, NLP) +NPP = (BCX, DTB) +XCV = (SMS, QJD) +PNM = (BPQ, NBM) +VPS = (JJB, XMR) +JNH = (FCT, NBT) +KTN = (SHG, PJG) +FMJ = (LQV, THK) +GFX = (NBB, NBB) +SRQ = (GNS, QGB) +FQC = (DGF, FJL) +MPA = (BRS, BSL) +BMS = (FKS, SKF) +BMT = (JMG, PCS) +QFV = (SCH, FDJ) +STF = (RCS, FFD) +JTS = (GGM, SJS) +NJQ = (TKR, JFF) +MTQ = (HLQ, VJX) +FGK = (TQP, JHR) +JNF = (TCV, LJT) +LKM = (KGC, QNM) +MXV = (BQP, BXK) +FRF = (LVM, HGK) +GGH = (BHB, KNB) +BGH = (KBX, FDN) +LQH = (JNF, BTC) +JVF = (LDS, DCD) +CLT = (QPL, LFV) +HRV = (TRD, RXH) +NBD = (PXP, XBK) +PJD = (JJD, LQM) +XMV = (BBF, LKX) +BCN = (PBH, HPL) +XMH = (JNG, GCX) +HFK = (GFG, XTS) +VTL = (RFC, VPF) +MSL = (NFQ, NDJ) +THH = (KNG, QNF) +PCB = (PCX, FLB) +GBQ = (PRR, PSR) +NMS = (BQC, SCN) +PDX = (BGP, SFH) +LDS = (TLJ, LLD) +HGV = (QPL, LFV) +LMK = (VKX, JCV) +NBM = (PKR, QCS) +NLR = (LKJ, DGZ) +QDN = (TRT, JBX) +MTH = (HMT, NJM) +CKF = (LKJ, LKJ) +FDN = (DGP, JKM) +CDR = (NCV, LNG) +SGJ = (GBQ, KXN) +TMM = (VXK, PJK) +JSL = (CTS, MTT) +QGB = (TBK, NHB) +TDA = (GHJ, QRC) +GTF = (QDP, GCJ) +TCG = (FVK, JVB) +LXJ = (FVN, LHX) +TQF = (RKL, SHQ) +ZZZ = (VQQ, DRS) +NCV = (CRJ, GBL) +BKF = (CJP, PRL) +QPD = (DQN, JBQ) +MFL = (PJD, TRS) +NHG = (HGK, LVM) +MRV = (MLH, TBV) +XHS = (PSN, HRQ) +JJB = (NJQ, RKH) +TGK = (SFG, FDS) +CGS = (TRD, RXH) +GCN = (NCN, CVS) +PNN = (BKK, CQC) +LSQ = (KCC, GSP) +LND = (RLS, LPX) +CPG = (VGM, RXV) +GSF = (HMJ, RMH) +JRH = (VQR, BVM) +FJB = (DTT, JHM) +FKM = (BFK, XCQ) +LPT = (PRD, CGB) +XVG = (CRL, BNJ) +KRS = (FDJ, SCH) +BNL = (BQL, ZZZ) +JMB = (XVD, MBH) +KKH = (RLN, PHV) +MTB = (PSP, VCX) +NCN = (FFV, RQC) +FVC = (QJC, SRG) +FTS = (THG, XXL) +SFG = (BCN, DBN) +RXH = (XQT, SDR) +MLR = (GDQ, VNC) +TRD = (XQT, SDR) +BGD = (GLJ, FNK) +XDJ = (MPS, RJB) +JMJ = (MDJ, RTV) +RVC = (PXQ, NRJ) +QQV = (CLT, HGV) +MLD = (QGB, GNS) +KPH = (HRQ, PSN) +RLN = (TFR, SNM) +JRP = (DSX, HPD) +SJS = (DSM, NKL) +PGD = (CGS, HRV) +HPL = (GKH, CVN) +MQK = (PTB, KJB) +QCR = (MHV, FTS) +VCG = (BQR, FRV) +LXV = (XMR, JJB) +PKR = (QSH, XMV) +JSB = (DLJ, MXD) +VRL = (JNS, HFP) +PHJ = (BTF, BTP) +CXL = (XBK, PXP) +FNN = (TSP, HSX) +XQT = (VHH, QHT) +LQV = (DQK, JMB) +RLS = (NBP, SSC) +TCV = (MDL, MMT) +QTC = (LFX, RJF) +LRK = (MFL, CKC) +MHK = (FGF, FDF) +RLJ = (HJX, CNC) +TLK = (RFL, VCK) +CNC = (HJQ, CNR) +LQL = (FRX, RTP) +QQM = (MFQ, BNR) +VBH = (HLB, JMJ) +GKX = (TGK, QKP) +KQG = (JRH, VNT) +XDR = (DNF, KJV) +GMJ = (HKP, TGX) +VRQ = (VTF, MRV) +HGP = (VNB, LDL) +LNG = (GBL, CRJ) +BSF = (LKG, MTQ) +BRH = (VNB, LDL) +PJQ = (BGD, DLX) +QKF = (CGR, KTX) +QMD = (TND, QSF) +PQH = (MKS, STP) +FRV = (PDX, PMX) +LPF = (JBQ, DQN) +CQM = (TDH, JPR) +HJX = (CNR, HJQ) +AAA = (DRS, VQQ) +TDH = (VGX, TCF) +TGX = (TMV, SHN) +BDH = (XFV, GSF) +GXK = (BFP, TFH) +BFT = (MFQ, BNR) +NGD = (QHG, MCC) +FPK = (DCD, LDS) +MTR = (KNB, BHB) +SNM = (MFJ, HXJ) +HLP = (RHQ, SVR) +JSP = (VGC, SSF) +NJH = (RJN, DBT) +SKF = (GRG, JSB) +PTM = (TKN, PCQ) +QGQ = (PHV, RLN) +SSF = (NVL, JPB) +PCQ = (LTC, PCH) +KJV = (GMS, XGF) +JSD = (XHP, DKM) +RRB = (LQF, KDN) +GJJ = (FLT, BNV) +FJA = (HJX, CNC) +HLQ = (XRK, VDQ) +KTP = (LPF, QPD) +PRD = (LRM, MTH) +QNF = (CHP, FNN) +DQK = (MBH, XVD) +TMS = (CLJ, XML) +QVP = (FNB, LSP) +BPX = (QJC, SRG) +QXN = (KQG, BML) +VGQ = (JVF, FPK) +BRS = (CDL, GFJ) +NQS = (VKC, SDV) +LFV = (XLK, QDK) +SMS = (RPQ, PDT) +BBF = (CGV, KRM) +VMT = (HLB, JMJ) +QSF = (JSL, LRF) +CJQ = (XSR, LHP) +RDF = (KKD, SQM) +MKS = (CKF, CKF) +STD = (MNM, TMS) +DNS = (MRQ, XFT) +MFG = (RQR, BXQ) +GBG = (QNM, KGC) +JNG = (RDG, SCV) +CVN = (GJJ, QVC) +HMT = (BVL, KLQ) +VTQ = (NTC, BNL) +TGB = (JTK, VMK) +PSR = (NPK, BDP) +MDJ = (DSB, SJB) +CKB = (VSB, TCG) +DNF = (GMS, XGF) +LQK = (XFR, RDF) +RHQ = (KPX, QTM) +VKX = (STQ, JSQ) +BRX = (DDR, TJD) +LJN = (NLP, CMB) +DJR = (HMK, PGQ) +VNB = (JMT, LHM) +DBM = (SBR, MTF) +KLQ = (XBN, MNH) +MDL = (MSL, JCT) +SQX = (TPV, RRB) +CLD = (CQK, RBB) +HPD = (RLJ, CJZ) +LHN = (BFK, XCQ) +KJB = (TMC, QCR) +RLG = (RVX, CDB) +PBH = (GKH, CVN) +DMB = (HHD, MSZ) +SDV = (GXK, QSB) +KPX = (XDJ, QTF) +NBB = (MTN, MTN) +BTX = (BRT, GSM) +HGN = (HJT, RBX) +GDS = (XSM, BGG) +KDN = (KTN, BJT) +GSL = (TRQ, PHJ) +SFR = (XHS, KPH) +JNV = (TVL, PNM) +JNS = (VCD, CXV) +LHM = (GXV, RTX) +TFH = (MTD, PFG) +GHJ = (CSN, XVS) +KNQ = (LRK, GXX) +PRT = (RNV, RGX) +JTK = (BMT, JXJ) +MRQ = (VPT, FLH) +TKN = (LTC, PCH) +VSN = (XFR, RDF) +HXJ = (DBB, HBH) +PRL = (THH, TTH) +GCX = (RDG, SCV) +MNH = (DXP, QDS) +CMB = (XQB, RKB) +CHP = (TSP, HSX) +BCP = (TCG, VSB) +LNT = (HQM, FGJ) +FNK = (XNX, RKP) +HRT = (FJB, PFX) +HTC = (CGS, HRV) +SDR = (QHT, VHH) +CQK = (FCR, HFN) +LVN = (FGP, BKF) +FDS = (DBN, BCN) +QCS = (QSH, XMV) +TRT = (KFQ, SGJ) +RQH = (FDN, KBX) +QJC = (QKK, LND) +MVD = (SBR, MTF) +SBG = (RFL, VCK) +DSX = (RLJ, RLJ) +JBX = (KFQ, SGJ) +JVV = (RRB, TPV) +BBR = (FKS, SKF) +KTX = (VDX, XDR) +CSN = (NNM, CBK) +NNM = (RTN, TGB) +VXK = (NGD, NTM) +DQD = (FJB, PFX) +CDB = (BLF, PTM) +GBL = (BPN, KKS) +BGP = (SNT, BRX) +CRP = (FDC, TPJ) +DFK = (KVV, SQD) +LVQ = (KNQ, FBX) +HSB = (PBK, SHB) +PJG = (TNP, CQM) +JPB = (KCM, DLK) +JJS = (PXQ, NRJ) +XGF = (QDH, PFV) +DKM = (KBL, PJQ) +DVB = (GSM, BRT) +TMC = (MHV, FTS) +TRQ = (BTP, BTF) +FLB = (FCV, FKJ) +BVL = (MNH, XBN) +XPA = (NCN, CVS) +XPS = (PNM, TVL) +CPN = (RDJ, JMK) +RQR = (DKX, CJQ) +SFH = (SNT, BRX) +DBT = (KLJ, PDR) +MBH = (XCS, XPD) +DLK = (XMH, XBD) +HBG = (HJT, RBX) +THK = (DQK, JMB) +DGF = (KKH, QGQ) +BPJ = (GKX, NXB) +MTN = (MVP, MVP) +TMV = (RVC, JJS) +GMS = (PFV, QDH) +FDJ = (BTH, XPG) +FFB = (MNM, MNM) +RTX = (LBK, LXJ) +BGG = (LNT, STB) +LRM = (HMT, NJM) +XVD = (XPD, XCS) +THT = (NTC, NTC) +GXH = (NBB, VXS) +LTG = (XSM, BGG) +GKH = (GJJ, QVC) +TNT = (FHG, PPR) +CDP = (HGN, HBG) +DQN = (HXV, JPN) +FNS = (SVR, RHQ) +DSB = (DMG, LRQ) +DCD = (TLJ, LLD) +FTQ = (JMK, RDJ) +VGX = (SFN, BDH) +VDX = (KJV, DNF) +PMX = (SFH, BGP) +VTF = (TBV, MLH) +LQM = (FMJ, QVV) +VNT = (VQR, BVM) +XML = (GCN, QFZ) +VPF = (MVM, JXP) +TBK = (LLQ, HQX) +PXQ = (TLK, SBG) +LKX = (CGV, KRM) +DBN = (PBH, HPL) +XXL = (CPG, PND) +BHG = (BBR, BMS) +VQQ = (STX, PJH) +VHH = (RLG, TDG) +RJK = (KPH, XHS) +BFK = (MXV, HTX) +VJX = (XRK, VDQ) +GFJ = (CPN, FTQ) +GRG = (MXD, DLJ) +CQC = (LJN, LSR) +RJB = (DHH, LPT) +FGP = (CJP, PRL) +BCM = (FFB, STD) +FBX = (GXX, LRK) +FLH = (VHJ, PRT) +GTD = (THT, THT) +GNS = (NHB, TBK) +QTM = (XDJ, QTF) +VGM = (KJK, FCD) +XBD = (JNG, GCX) +QVC = (BNV, FLT) +FCV = (LQL, CSG) +SCN = (NPL, VXF) +KKL = (HVK, NMS) +MDG = (QJD, SMS) +QSB = (BFP, TFH) +LKJ = (BRS, BSL) +XCS = (HSB, LRC) +HLB = (MDJ, RTV) +TLJ = (NGQ, CGC) +MNM = (CLJ, CLJ) +STB = (HQM, FGJ) +HJT = (TMF, KTP) +TND = (LRF, JSL) +FVN = (QDN, DXF) +SNT = (TJD, DDR) +JKM = (LKN, FVM) +LTC = (RBP, PQH) +STP = (CKF, NLR) +DMG = (LSQ, PMP) +CDX = (RFC, VPF) +CNQ = (PXG, BSF) +PMP = (KCC, GSP) +VKT = (CKX, KPS) +CKJ = (FBX, KNQ) +VGC = (JPB, NVL) +LCB = (QTC, FCM) +TCF = (BDH, SFN) +DDC = (XSX, DMB) +SFN = (XFV, GSF) +HXF = (GDQ, VNC) +BPQ = (QCS, PKR) +FFD = (TNT, XTF) +TBV = (SFR, RJK) +DBB = (FGM, DJR) +FHG = (VSN, LQK) +GGM = (DSM, NKL) +RJV = (NMS, HVK) +NGQ = (RJV, KKL) +CFS = (HQV, HPS) +PFG = (BTX, DVB) +VCX = (QKF, CPK) +XCQ = (MXV, HTX) +DHH = (PRD, CGB) +HBH = (DJR, FGM) +RMH = (GMV, SNF) +HXV = (QTB, FRP) +QFZ = (CVS, NCN) +CVK = (BDK, GMJ) +SHQ = (QQM, BFT) +PGQ = (XPS, JNV) +LQR = (NTG, VCG) +QDS = (BVB, HDJ) +CJP = (THH, TTH) +FNB = (GGH, MTR) +PSN = (RXG, JSG) +LHX = (QDN, DXF) +GFG = (SCG, KQJ) +PRR = (NPK, BDP) +QSH = (LKX, BBF) +KVV = (LBV, CRP) +DFF = (NXB, GKX) +JFF = (CKJ, LVQ) +FCD = (MDG, XCV) +SFC = (FNS, HLP) +KPS = (BNS, CFS) +PLN = (PNN, DHB) +SHG = (CQM, TNP) +GJR = (QDP, GCJ) +NDJ = (GFX, GXH) +XQB = (PHC, JSD) +FKJ = (CSG, LQL) +FRP = (KNS, JTS) +MHX = (BKB, LCB) +HGK = (LHS, SBV) +JXJ = (JMG, PCS) +NJC = (RQH, BGH) +LLQ = (TQF, NJB) +QFR = (BCP, CKB) +BXK = (DQD, HRT) +XFR = (KKD, SQM) +XFV = (HMJ, RMH) +HMJ = (GMV, SNF) +BNV = (NHG, FRF) +GXV = (LBK, LXJ) +XNX = (NKH, FQC) +BJR = (VKX, JCV) +CRN = (BCX, DTB) diff --git a/src/aoc8test.txt b/src/aoc8test.txt new file mode 100644 index 0000000..d834763 --- /dev/null +++ b/src/aoc8test.txt @@ -0,0 +1,11 @@ +LR + +11A = (11B, XXX) +12A = (11B, XXX) +11B = (XXX, 11Z) +11Z = (11B, XXX) +22A = (22B, XXX) +22B = (22C, 22C) +22C = (22Z, 22Z) +22Z = (22B, 22B) +XXX = (XXX, XXX) From cebe6b645f6db4f9406b581eeb1af07633e5c57b Mon Sep 17 00:00:00 2001 From: Hane Date: Sun, 31 Dec 2023 01:12:22 +0100 Subject: [PATCH 08/10] full aoc11 --- src/aoc11-2.lisp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ src/aoc11.lisp | 69 +++++++++++++++++++++++++++-------------- src/aoc8-2.lisp | 23 +++----------- 3 files changed, 132 insertions(+), 41 deletions(-) create mode 100644 src/aoc11-2.lisp diff --git a/src/aoc11-2.lisp b/src/aoc11-2.lisp new file mode 100644 index 0000000..4310c6e --- /dev/null +++ b/src/aoc11-2.lisp @@ -0,0 +1,81 @@ +(defun input-parsing (path) + (with-open-file (file path) + (let( (galaxies (make-array 0 :adjustable t)) ) + (loop for line = (read-line file nil) + for current-line from 0 + with galaxy-columns = '() + with galaxies-copy = (make-array 0 :adjustable t) + with data-line = nil + with key = "" + with left-value = "" + with right-value = "" + while line + do + (when(zerop current-line) + (dotimes (i (length line)) + (push nil galaxy-columns))) + + (loop for c across line + with char-position = 0 + do + (when (char= c #\#) + (let( (size (+ 1 (length galaxies))) ) + (adjust-array galaxies size) (adjust-array galaxies-copy size) (decf size) + (setf (aref galaxies size) (cons current-line char-position)) + (setf (aref galaxies-copy size) (cons current-line char-position))) + ;;(format T "~% ~d ~A" char-position galaxy-columns) + (setf (nth char-position galaxy-columns) t) + ;;(setf (nth i parsed) nil) + (setf data-line t)) + (incf char-position) + finally + (if (not data-line) + (setf current-line (+ current-line *replace-value*))) + ;;(incf current-line) + (setf data-line nil)) + finally + ;;(print galaxy-columns) + ;;(setf galaxies-copy galaxies) + (loop for occupied-column in galaxy-columns + for x-index from 0 + do + (when (not occupied-column) + (loop for index from 0 + while (< index (array-total-size galaxies-copy)) + ;;for galaxy in galaxies + do + ;;(print x-index) + ;;(print index) + (when (> (cdr (aref galaxies-copy index)) x-index) + ;;(print (aref galaxies-copy index)) + (setf (cdr (aref galaxies index)) (+ (cdr (aref galaxies index)) *replace-value*))))))) + ;;(y . x) + (print galaxies) + galaxies))) + +(defun calculate-pairs (galaxies) + (loop for base from 0 + with result = 0 + while (< base (array-total-size galaxies)) + do + (loop for comparee from (+ base 1) + with x-movement = 0 + with y-movement = 0 + while (< comparee (array-total-size galaxies)) + do + ;;(print (aref galaxies base)) + ;;(print (aref galaxies comparee)) + (setf y-movement (if(<= (car(aref galaxies base)) (car(aref galaxies comparee))) + (- (car(aref galaxies comparee)) (car(aref galaxies base))) + (- (car(aref galaxies base)) (car(aref galaxies comparee))))) + (setf x-movement (if(<= (cdr(aref galaxies base)) (cdr(aref galaxies comparee))) + (- (cdr(aref galaxies comparee)) (cdr(aref galaxies base))) + (- (cdr(aref galaxies base)) (cdr(aref galaxies comparee))))) + ;;(print y-movement) + ;;(print x-movement) + (setf result (+ result (+ x-movement y-movement)))) + finally + (return result))) + +(defparameter *replace-value* 999999) +(print (calculate-pairs (input-parsing "aoc11input.txt"))) diff --git a/src/aoc11.lisp b/src/aoc11.lisp index 33d2e98..c2b6d4f 100644 --- a/src/aoc11.lisp +++ b/src/aoc11.lisp @@ -1,22 +1,10 @@ - (defun input-parsing (path) (with-open-file (file path) - (let( (galaxy-columns '()) (data-line nil) (galaxies (make-array 0 :adjustable t)) (current-line 0) ) - ;;Prep work - ;;(defparameter keys (make-array 0 :adjustable t)) - ;;(defparameter parsed '()) - ;;(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) - ;; (let( (size (+ 1 (length keys))) ) - ;; (adjust-array keys size) (decf size) - ;; (setf (aref keys size) key) )) - + (let( (galaxies (make-array 0 :adjustable t)) ) (loop for line = (read-line file nil) + for current-line from 0 + with galaxy-columns = '() + with data-line = nil with key = "" with left-value = "" with right-value = "" @@ -24,15 +12,16 @@ do (when(zerop current-line) (dotimes (i (length line)) - (push nil galaxy-columns))) + (push nil galaxy-columns))) + (loop for c across line with char-position = 0 do (when (char= c #\#) (let( (size (+ 1 (length galaxies))) ) (adjust-array galaxies size) (decf size) - (setf (aref galaxies size) (cons current-line char-position)) ) - (format T "~% ~d ~A" char-position galaxy-columns) + (setf (aref galaxies size) (cons current-line char-position )) ) + ;;(format T "~% ~d ~A" char-position galaxy-columns) (setf (nth char-position galaxy-columns) t) ;;(setf (nth i parsed) nil) (setf data-line t)) @@ -40,18 +29,52 @@ finally (if (not data-line) (incf current-line)) - (incf current-line) + ;;(incf current-line) (setf data-line nil)) - ) + finally + (loop for occupied-column in galaxy-columns + for x-index from 0 + do + (when (not occupied-column) + (loop for index from 0 + while (< index (array-total-size galaxies)) + ;;for galaxy in galaxies + do + (when (> (cdr (aref galaxies index)) x-index) + (setf (cdr (aref galaxies index)) (+ (cdr (aref galaxies index)) 1))))))) galaxies))) -(print (input-parsing "aoc11test.txt")) +(defun calculate-pairs (galaxies) + (loop for base from 0 + with result = 0 + while (< base (array-total-size galaxies)) + do + (loop for comparee from (+ base 1) + with x-movement = 0 + with y-movement = 0 + while (< comparee (array-total-size galaxies)) + do + ;;(print (aref galaxies base)) + ;;(print (aref galaxies comparee)) + (setf y-movement (if(<= (car(aref galaxies base)) (car(aref galaxies comparee))) + (- (car(aref galaxies comparee)) (car(aref galaxies base))) + (- (car(aref galaxies base)) (car(aref galaxies comparee))))) + (setf x-movement (if(<= (cdr(aref galaxies base)) (cdr(aref galaxies comparee))) + (- (cdr(aref galaxies comparee)) (cdr(aref galaxies base))) + (- (cdr(aref galaxies base)) (cdr(aref galaxies comparee))))) + ;;(print y-movement) + ;;(print x-movement) + (setf result (+ result (+ x-movement y-movement)))) + finally + result)) + +(print (calculate-pairs (input-parsing "aoc11input.txt"))) ;;(print "Hola") ;;(print (aref keys 0)) ;; (incf (nth 0 steps-per-key)) ;; (if(char= c #\L) - ;; (setf (aref keys 0) (car(gethash (aref keys 0) route-hash))) + ;; (setf (aref keys 0) (cdr(gethash (aref keys 0) route-hash))) ;; (setf (aref keys 0) (cdr(gethash (aref keys 0) route-hash)))) ;; ;;(print (aref keys 0)) diff --git a/src/aoc8-2.lisp b/src/aoc8-2.lisp index 37a11e9..c861017 100644 --- a/src/aoc8-2.lisp +++ b/src/aoc8-2.lisp @@ -6,7 +6,7 @@ (print (sb-thread:list-all-threads)) (with-open-file (file "aoc8input.txt") - (let( (goal-to-be-reached nil) (direction-line "") (route-hash (make-hash-table :test #'equalp :size 800)) ) + (let( (goal-to-be-reached nil) (direction-line "") (route-hash (make-hash-table :test #'equalp :size 800))) ;;Prep work (defparameter keys (make-array 0 :adjustable t)) (defparameter parsed '()) @@ -31,11 +31,7 @@ (when(char= #\A (char key 2)) (let( (size (+ 1 (length keys))) ) (adjust-array keys size) (decf size) - (setf (aref keys size) key) )) - ) - - ;;(print keys) - ;;(print parsed) + (setf (aref keys size) key) ))) (dotimes (i (length keys)) (push 0 steps-per-key) (push t parsed)) @@ -59,16 +55,9 @@ (when(char= (char (aref keys 0) 2) #\Z) ;;(format T "~%~a ~d" "Ayo on key 0 found at: " (nth 0 steps-per-key)) (dotimes (i (length keys)) - ;;(print (+ i 1)) - ;;(print (length keys)) - ;;(when (< (+ i 1) (length keys)) (when (> i 0) - ;;WTF - (sb-thread:make-thread (lambda (x hashmap dir strlen steps) (hashmap-parse hashmap dir strlen x steps) ) :arguments (list i route-hash direction-line (length direction-line) (nth i steps-per-key) ) ) - ;;(format T "~%~d" i) - ) - ) - ;;(print parsed) + (sb-thread:make-thread (lambda (x hashmap dir strlen steps) (hashmap-parse hashmap dir strlen x steps) ) :arguments (list i route-hash direction-line (length direction-line) (nth i steps-per-key))))) + (loop while (not (every #'null parsed)) do (print parsed) @@ -105,9 +94,7 @@ (when(char= (char (aref keys key-position) 2) #\Z) (setf z-found t) (setf (nth key-position parsed) nil) - (setf (nth key-position steps-per-key) steps)) - ) - )) + (setf (nth key-position steps-per-key) steps))))) ;; (defvar *directions*) ;; (defvar *ndirections*) From e59c30eb53699061502b46e108ee026a2f27a3f3 Mon Sep 17 00:00:00 2001 From: Hane Date: Fri, 5 Jan 2024 17:52:53 +0100 Subject: [PATCH 09/10] aoc10-1 --- src/aoc10-2.lisp | 193 +++++++++++++++++++++++++++++++++++++++++++++ src/aoc10.lisp | 192 ++++++++++++++++++++++++++++++++++++++++++++ src/aoc10input.txt | 140 ++++++++++++++++++++++++++++++++ src/aoc10test.txt | 5 ++ 4 files changed, 530 insertions(+) create mode 100644 src/aoc10-2.lisp create mode 100644 src/aoc10.lisp create mode 100644 src/aoc10input.txt create mode 100644 src/aoc10test.txt diff --git a/src/aoc10-2.lisp b/src/aoc10-2.lisp new file mode 100644 index 0000000..7650e46 --- /dev/null +++ b/src/aoc10-2.lisp @@ -0,0 +1,193 @@ +(defun locate-starting-pos (string line-number) + (loop with starting-pos = nil + for c across string + for char-position from 0 + do + (when (char= c #\S) + (setf starting-pos (cons char-position line-number))) + finally + (return starting-pos))) + +(defun input-parsing (path) + (with-open-file (file path) + (let( (starting-pos nil) (line-length 0) + (node-array nil) (input-array (make-array 0 :adjustable t)) ) + (loop with initial-line = (read-line file nil) + initially + ;;(print initial-line) + (setf line-length (length initial-line)) + (let( (size (+ 1 (length input-array))) ) + (adjust-array input-array size) (decf size) + (setf (aref input-array size) (format nil "~a" initial-line))) + ;;(setf input-string (format nil "~a~a" input-string line)) + (setf starting-pos (locate-starting-pos initial-line 0)) + for line = (read-line file nil) + for line-count from 1 + while line + do + ;;(print line) + ;;(setf input-string (format nil "~a~a" input-string line)) + (let( (size (+ 1 (length input-array))) ) + (adjust-array input-array size) (decf size) + (setf (aref input-array size) (format nil "~a" line))) + (when (not starting-pos) + (setf starting-pos (locate-starting-pos line line-count))) + ;;(setf node-array (make-array '(line-length line-count) :initial-element nil)) + + finally + ;;(print line-length) + ;;(print line-count) + (setf node-array (make-array (list line-length line-count) :initial-element nil)) + (setf (aref node-array (cdr starting-pos) (car starting-pos)) t) + (return (values input-array node-array starting-pos)) + )))) + +(defun determine-paths (input-array starting-pos) + (let ( (current-char nil) (paths-list (list 0 0 0 0))) + ;;N + (when (not (equal (cdr starting-pos) 0)) + (setf current-char (char (aref input-array (- (cdr starting-pos) 1)) (car starting-pos))) + (when (equal (nth 2 (gethash current-char *starting-orientation-hash*)) 1) + (setf (nth 0 paths-list) 1))) + ;;W + (when (not (equal (car starting-pos) 0)) + (setf current-char (char (aref input-array (cdr starting-pos)) (- (car starting-pos) 1))) + (when (equal (nth 3 (gethash current-char *starting-orientation-hash*)) 1) + (setf (nth 1 paths-list) 1))) + ;;S + (when (not (equal (cdr starting-pos) (- (array-dimension input-array 0) 1))) + (setf current-char (char (aref input-array (+ (cdr starting-pos) 1)) (car starting-pos))) + (when (equal (nth 0 (gethash current-char *starting-orientation-hash*)) 1) + (setf (nth 2 paths-list) 1))) + ;;E + (when (not (equal (car starting-pos) (- (length (aref input-array 0)) 1))) + (setf current-char (char (aref input-array (cdr starting-pos)) (+ (car starting-pos) 1))) + (when (equal (nth 1 (gethash current-char *starting-orientation-hash*)) 1) + (setf (nth 3 paths-list) 1))) + paths-list + )) + +(defun paths-list-to-starting-coords (paths-list starting-pos) + (loop for item in paths-list + for item-count from 0 + with first-position = nil + with second-position = nil + while item + do + (when (not (zerop item)) + (cond ((equal item-count 0) (setf first-position + (cons (car starting-pos) (- (cdr starting-pos) 1)))) + ((equal item-count 1) (if (not first-position) + (setf first-position + (cons (- (car starting-pos) 1) (cdr starting-pos) )) + (setf second-position + (cons (- (car starting-pos) 1) (cdr starting-pos) )))) + ((equal item-count 2) (if (not first-position) + (setf first-position + (cons (car starting-pos) (+ (cdr starting-pos) 1)) ) + (setf second-position + (cons (car starting-pos) (+ (cdr starting-pos) 1)) ))) + (t (setf second-position + (cons (+ (car starting-pos) 1) (cdr starting-pos) ))))) + finally + ;;(print first-position) + ;;(print second-position) + (return (values first-position second-position)))) + +(defun calculate-next-move (current-char current-position previous-position) + (let( (east-choice (cons (+ (car current-position) 1) (cdr current-position))) + (south-choice (cons (car current-position) (+ (cdr current-position) 1))) + (west-choice (cons (- (car current-position) 1) (cdr current-position))) + (north-choice (cons (car current-position) (- (cdr current-position) 1))) ) + (format T "~%~a ~A~A" "nexmove from:" current-position previous-position) + ;;(print current-position) + ;;(print (car current-position)) + ;;(print north-choice) + ;;(print west-choice) + (cond ((char= #\| current-char) (if (equal north-choice previous-position) + south-choice + north-choice)) + ((char= #\- current-char) (if (equal east-choice previous-position) + west-choice + east-choice)) + ((char= #\L current-char) (if (equal north-choice previous-position) + east-choice + north-choice)) + ((char= #\J current-char) (if (equal north-choice previous-position) + west-choice + north-choice)) + ((char= #\7 current-char) (if (equal south-choice previous-position) + west-choice + south-choice)) + ((char= #\F current-char) (if (equal south-choice previous-position) + east-choice + south-choice))))) + +(defun steps-to-farthest-point (input-array node-array paths-list starting-pos) + ;; (print "---") + (let( (circle-closed nil) (current-coords (list)) (previous-coords (list starting-pos starting-pos))) + (multiple-value-bind (first-position second-position) + (paths-list-to-starting-coords paths-list starting-pos) + (push first-position current-coords) + (push second-position current-coords) + (setf (aref node-array (cdr first-position) (car first-position)) t) + (setf (aref node-array (cdr second-position) (car second-position)) t) + ;;(print node-array) + (print "----we gamin") + ;;(print current-coords) + + ;;(print (calculate-next-move + + (loop for steps from 1 + while (not circle-closed) + do + (loop with current-char = nil + with temp-coords = nil + for index from 0 + while (< index 2) + do + (setf current-char + (char (aref input-array (cdr (nth index current-coords))) + (car (nth index current-coords))) ) + ;;(print current-char) + ;;(print + (setf temp-coords (calculate-next-move current-char (nth index current-coords) + (nth index previous-coords))) + (setf (nth index previous-coords) (nth index current-coords)) + (setf (nth index current-coords) temp-coords) + (if (not (aref node-array (cdr (nth index current-coords)) + (car (nth index current-coords)))) + (setf (aref node-array (cdr (nth index current-coords)) + (car (nth index current-coords)))t) + (setf circle-closed t)) + ;;(print node-array) + ;;(print current-coords) + + ) + finally + (print node-array) + (print steps) + ) + ;;(format T "~%~A~A" first-position second-position) + ))) + +;; (let( (input-array nil) (node-array nil) ) +(defparameter *starting-orientation-hash* (make-hash-table :test #'equalp :size 7)) +;;N-w-S-E +(setf (gethash #\| *starting-orientation-hash*) '(1 0 1 0)) +(setf (gethash #\- *starting-orientation-hash*) '(0 1 0 1)) +(setf (gethash #\L *starting-orientation-hash*) '(1 0 0 1)) +(setf (gethash #\J *starting-orientation-hash*) '(1 1 0 0)) +(setf (gethash #\7 *starting-orientation-hash*) '(0 1 1 0)) +(setf (gethash #\F *starting-orientation-hash*) '(0 0 1 1)) +(setf (gethash #\. *starting-orientation-hash*) '(0 0 0 0)) + + +;;(print (gethash #\| *starting-orientation-hash*)) + + ;;(multiple-value-bind (input-array node-array starting-pos) (input-parsing "aoc10test.txt") (format T "~%~A~%~A~%~A~A" input-array node-array starting-pos (determine-paths input-array starting-pos))) + +(multiple-value-bind (input-array node-array starting-pos) (input-parsing "aoc10test.txt") + (format T "~%~A~%~A~%~A~%~A~%~a~%" input-array node-array starting-pos (determine-paths input-array starting-pos) "-----") (steps-to-farthest-point input-array node-array (determine-paths input-array starting-pos) starting-pos)) + +;;) diff --git a/src/aoc10.lisp b/src/aoc10.lisp new file mode 100644 index 0000000..9b4b61b --- /dev/null +++ b/src/aoc10.lisp @@ -0,0 +1,192 @@ +(defun locate-starting-pos (string line-number) + (loop with starting-pos = nil + for c across string + for char-position from 0 + do + (when (char= c #\S) + (setf starting-pos (cons char-position line-number))) + finally + (return starting-pos))) + +(defun input-parsing (path) + (with-open-file (file path) + (let( (starting-pos nil) (line-length 0) + (node-array nil) (input-array (make-array 0 :adjustable t)) ) + (loop with initial-line = (read-line file nil) + initially + ;;(print initial-line) + (setf line-length (length initial-line)) + (let( (size (+ 1 (length input-array))) ) + (adjust-array input-array size) (decf size) + (setf (aref input-array size) (format nil "~a" initial-line))) + ;;(setf input-string (format nil "~a~a" input-string line)) + (setf starting-pos (locate-starting-pos initial-line 0)) + for line = (read-line file nil) + for line-count from 1 + while line + do + ;;(print line) + ;;(setf input-string (format nil "~a~a" input-string line)) + (let( (size (+ 1 (length input-array))) ) + (adjust-array input-array size) (decf size) + (setf (aref input-array size) (format nil "~a" line))) + (when (not starting-pos) + (setf starting-pos (locate-starting-pos line line-count))) + ;;(setf node-array (make-array '(line-length line-count) :initial-element nil)) + + finally + ;;(print line-length) + ;;(print line-count) + (setf node-array (make-array (list line-length line-count) :initial-element nil)) + (setf (aref node-array (cdr starting-pos) (car starting-pos)) t) + (return (values input-array node-array starting-pos)) + )))) + +(defun determine-paths (input-array starting-pos) + (let ( (current-char nil) (paths-list (list 0 0 0 0))) + ;;N + (when (not (equal (cdr starting-pos) 0)) + (setf current-char (char (aref input-array (- (cdr starting-pos) 1)) (car starting-pos))) + (when (equal (nth 2 (gethash current-char *starting-orientation-hash*)) 1) + (setf (nth 0 paths-list) 1))) + ;;W + (when (not (equal (car starting-pos) 0)) + (setf current-char (char (aref input-array (cdr starting-pos)) (- (car starting-pos) 1))) + (when (equal (nth 3 (gethash current-char *starting-orientation-hash*)) 1) + (setf (nth 1 paths-list) 1))) + ;;S + (when (not (equal (cdr starting-pos) (- (array-dimension input-array 0) 1))) + (setf current-char (char (aref input-array (+ (cdr starting-pos) 1)) (car starting-pos))) + (when (equal (nth 0 (gethash current-char *starting-orientation-hash*)) 1) + (setf (nth 2 paths-list) 1))) + ;;E + (when (not (equal (car starting-pos) (- (length (aref input-array 0)) 1))) + (setf current-char (char (aref input-array (cdr starting-pos)) (+ (car starting-pos) 1))) + (when (equal (nth 1 (gethash current-char *starting-orientation-hash*)) 1) + (setf (nth 3 paths-list) 1))) + paths-list + )) + +(defun paths-list-to-starting-coords (paths-list starting-pos) + (loop for item in paths-list + for item-count from 0 + with first-position = nil + with second-position = nil + while item + do + (when (not (zerop item)) + (cond ((equal item-count 0) (setf first-position + (cons (car starting-pos) (- (cdr starting-pos) 1)))) + ((equal item-count 1) (if (not first-position) + (setf first-position + (cons (- (car starting-pos) 1) (cdr starting-pos) )) + (setf second-position + (cons (- (car starting-pos) 1) (cdr starting-pos) )))) + ((equal item-count 2) (if (not first-position) + (setf first-position + (cons (car starting-pos) (+ (cdr starting-pos) 1)) ) + (setf second-position + (cons (car starting-pos) (+ (cdr starting-pos) 1)) ))) + (t (setf second-position + (cons (+ (car starting-pos) 1) (cdr starting-pos) ))))) + finally + ;;(print first-position) + ;;(print second-position) + (return (values first-position second-position)))) + +(defun calculate-next-move (current-char current-position previous-position) + (let( (east-choice (cons (+ (car current-position) 1) (cdr current-position))) + (south-choice (cons (car current-position) (+ (cdr current-position) 1))) + (west-choice (cons (- (car current-position) 1) (cdr current-position))) + (north-choice (cons (car current-position) (- (cdr current-position) 1))) ) + (format T "~%~a ~A~A" "nexmove from:" current-position previous-position) + ;;(print current-position) + ;;(print (car current-position)) + ;;(print north-choice) + ;;(print west-choice) + (cond ((char= #\| current-char) (if (equal north-choice previous-position) + south-choice + north-choice)) + ((char= #\- current-char) (if (equal east-choice previous-position) + west-choice + east-choice)) + ((char= #\L current-char) (if (equal north-choice previous-position) + east-choice + north-choice)) + ((char= #\J current-char) (if (equal north-choice previous-position) + west-choice + north-choice)) + ((char= #\7 current-char) (if (equal south-choice previous-position) + west-choice + south-choice)) + ((char= #\F current-char) (if (equal south-choice previous-position) + east-choice + south-choice))))) + +(defun steps-to-farthest-point (input-array node-array paths-list starting-pos) + ;; (print "---") + (let( (circle-closed nil) (current-coords (list)) (previous-coords (list starting-pos starting-pos))) + (multiple-value-bind (first-position second-position) + (paths-list-to-starting-coords paths-list starting-pos) + (push first-position current-coords) + (push second-position current-coords) + (setf (aref node-array (cdr first-position) (car first-position)) t) + (setf (aref node-array (cdr second-position) (car second-position)) t) + ;;(print node-array) + (print "----we gamin") + ;;(print current-coords) + + ;;(print (calculate-next-move + + (loop for steps from 1 + while (not circle-closed) + do + (loop with current-char = nil + with temp-coords = nil + for index from 0 + while (< index 2) + do + (setf current-char + (char (aref input-array (cdr (nth index current-coords))) + (car (nth index current-coords))) ) + ;;(print current-char) + ;;(print + (setf temp-coords (calculate-next-move current-char (nth index current-coords) + (nth index previous-coords))) + (setf (nth index previous-coords) (nth index current-coords)) + (setf (nth index current-coords) temp-coords) + (if (not (aref node-array (cdr (nth index current-coords)) + (car (nth index current-coords)))) + (setf (aref node-array (cdr (nth index current-coords)) + (car (nth index current-coords)))t) + (setf circle-closed t)) + ;;(print node-array) + ;;(print current-coords) + + ) + finally + (print steps) + ) + ;;(format T "~%~A~A" first-position second-position) + ))) + +;; (let( (input-array nil) (node-array nil) ) +(defparameter *starting-orientation-hash* (make-hash-table :test #'equalp :size 7)) +;;N-w-S-E +(setf (gethash #\| *starting-orientation-hash*) '(1 0 1 0)) +(setf (gethash #\- *starting-orientation-hash*) '(0 1 0 1)) +(setf (gethash #\L *starting-orientation-hash*) '(1 0 0 1)) +(setf (gethash #\J *starting-orientation-hash*) '(1 1 0 0)) +(setf (gethash #\7 *starting-orientation-hash*) '(0 1 1 0)) +(setf (gethash #\F *starting-orientation-hash*) '(0 0 1 1)) +(setf (gethash #\. *starting-orientation-hash*) '(0 0 0 0)) + + +;;(print (gethash #\| *starting-orientation-hash*)) + + ;;(multiple-value-bind (input-array node-array starting-pos) (input-parsing "aoc10test.txt") (format T "~%~A~%~A~%~A~A" input-array node-array starting-pos (determine-paths input-array starting-pos))) + +(multiple-value-bind (input-array node-array starting-pos) (input-parsing "aoc10input.txt") + (format T "~%~A~%~A~%~A~%~A~%~a~%" input-array node-array starting-pos (determine-paths input-array starting-pos) "-----") (steps-to-farthest-point input-array node-array (determine-paths input-array starting-pos) starting-pos)) + +;;) diff --git a/src/aoc10input.txt b/src/aoc10input.txt new file mode 100644 index 0000000..8a3f614 --- /dev/null +++ b/src/aoc10input.txt @@ -0,0 +1,140 @@ +7.FF7777.|77.-L-77.|F-7-.L77|7F|7-|-JF77FFF777.7FL--F-F..F.-7-F7-J.FFF7JFF7-J7....FFJFL.|-L7F--|-L7L-|-|-|.F77F7F-|7---L-.7-.F-7F|-L77...-.- +J7L-||LL7L|7-J.|.|7LL-|.F7|FJ7----J-7-|LLJ|JJ||L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-7F--JL7L7L---J|L|.L- +F|.-F7-FJJ.LJLJF7F----JFJL--7L-JL7L--7||L7L---7L-J|L-7FJ|||L7|FJ|FJL---7LJ||||||FJL-7L-JF---JL-7|L---7F--JF7LF7|F-J|F7L7|L---7L-JF--7.|L---| +|L7.||7..F7FF--JLJF7F-7L7F-7|F7F7L--7|||-|F---JF--JF7LJFJLJLLJL-J|F--7FJF-J|||||L7F7L-7FJF--7F-J|F7F-J|F--JL-J||L--J||FJ|F7F7L---JF7|FL-|7F- +J7J|JJJ7.-|-L7F7F7|LJFJFJL7LJ|LJL7F7LJLJFJL---7L-7FJ|F7L7F-7F7F--JL-7LJ7|F7|||LJ7|||F7|L7|F-JL-7||LJF7LJF----7|L7F7FJLJ7LJ||L7F7F-JLJJJJ|-|J +|J||JLLF-.L.|LJLJLJF7L7|F-JF7|F--J|L--7-L7F7F-JF-JL7|||FJL7LJLJF-7F7L7F7LJLJ|L7F-J|||||7||L---7||L7FJL7|L---7|L7|||L-----7LJ7|||L7JFJ-L7L-J| +-77FJ..|.F|F-----7J||FJ||F-J||L---JF--JF7LJLJF-JF7FJLJ|L7|L7F--JFJ|L7LJL7F--JFJ|F7|||||FJL7F--J|L7|L-7L-----JL-JLJ|F7F7F7L--7|||FJFF|.LLFJL7 +L-J|--F-7FLL--7F7L-JLJFJLJF7LJF7F7FL-7FJL---7L-7|||F77L-JF-J|F--JFJFJF7FJ|F7FJFJ|||||||L--JL-7FJ-LJF7L-----------7||LJLJL---JLJLJ7-LJ.|.JFFJ +.FLJ7|LLF-JF7.LJL7F---JLF7|L--JLJL---J|F----JF7LJ|LJL---7|F7||F-7L7|FJLJLLJ||FJFJ|||||L-7F---JL7F--JL-----7F--7F7||L-------7J.||.7.|77FJ7|JF +FLJ.J7-F|J-||7LF-J|F---7||L---------7FJL-7F--JL-7L7F7F--JLJLJLJFJFJ||F7F--7LJL7||LJLJ|F-JL--7F-JL---7F7F-7|L-7LJLJL--------JJJLF7LJ-F|.F-7|L +-J|-7|F-F-7||F7L--JL7F7LJL--------7FJL7F-JL7F7F7|FJ||L--7F-----JFJFJLJLJF7||F-JL--7F-J|F7F-7LJF-----J|||FJ|F-J7F7F7F7|F-7F7F7JF||FL-F|.7J|L| +|F7-77|FL7LJ|||FF7F7LJL7F--------7||F-JL---J|LJ||L7||F--JL----7FJ7L7F-7FJLJFJF--7FJL7FJ||L7L-7L7F--7FJLJL7LJF-7|||||L7|FJ|LJL--JL7-.7J-7L|7J +F|F7JLF7FJF7LJL-JLJL---J|F-------JLJ|F--7F7FJF7LJFJ||L---7F---JL7F-JL7|L-7.|FJF-JL-7||FJL-JF7L7LJF7LJJF--JF7|FJ||||L7LJL-JF7F----JJ.77JL-.7J +L-JF-FJ|L-JL--7F7F7F7F-7||F7F7F-----JL7FJ|LJFJL-7L7|L7F--JL-7F7FJ|F-7||F7L7|L7L-7F-J|||F7F7|L7|JFJL7F7L--7||||FJLJL-JF7F7FJ|L-7F-7F7F7LLL7F7 +|.FJ-L7L7.F7F7LJLJLJ||-||LJ||||F------JL7L-7|F--JFLJ|LJF7F--J||L7|L7||||L-JL7|F-JL-7LJLJLJLJ-|L-JF7LJL7F7||LJLJF--7F-JLJLJJL--J|FJ7LL-.LJ-|| +LF||.LL7L-J||||F7F--JL7LJJFJ|||L-------7|F7LJL-7F7-F---J|L7F7|L7||FJ|||L-7F7LJL-7F7|F---7F7F-JF-7|L7F7LJLJ|F---JF7LJF7LF7F7.F7FJL-7LLL-FJ7|7 +LL--L7JL--7|||FJ|L-7F7|7F-JFJLJLF---7F-J|||F7F-J|L7L7F-7|FJ||L7||||FJ||F7LJL---7||||L7F7LJLJF7|FJ|-LJ|F---JL----JL--JL-JLJ|FJLJF-7|7.LFF.F-- +FFJ.FFF--7||||L7|7FJ|LJFJF-J7F7FJF-7LJF7LJ|||L--JFJFJL7||L-JL7|||LJ|FJLJ|F---7FJ||LJ.LJL-7F7|LJL7|F-7LJF----7F--7F----7F-7LJF-7L7LJ77.FL||F7 +LJLF7|L-7LJ|||FJL7L-JF-JFJF--J|L-J.L--JL-7|||F7F7L-JF-JLJF---J||L7FJ|F--JL--7||FJL-7F----J|||F--J|L7L7-L---7|L-7|L--7.LJ7|F7L7L7|L|FL.FL7-LJ +.|.|L--7L-7|||L-7|F7L|F7L7L--7|F7F7F-----JLJLJLJL7F7L7F7|L-7F7||FJL-J|F7F7F7||||F--JL---7FJ||L--7L7L7L-----JL--JL---JF--7|||FJLLJJL|.F7F-JL7 +F-.L-7FJFFJ|||.FJLJL7LJL-JLF7|||LJLJF----7LF7F7F7||L7LJL-7JLJLJ|L7LF7||LJ||||LJ|L7JF----J||LJF--JFJ.L7F-----------7F7|F-JLJLJF7JLF.J-7L|.FLF +|LF--JL77L7||L7|F--7|F--7JFJLJLJF7F7|F---JFJLJLJ|||FJF---JJLF7FJFJFJLJL-7|||L-7|FJ-L7F---JF7FJF-7|F7FLJF----------J|||L7F7F7FJL7F77FL7-J7F.L +L-L--7FJF7||L7LJL7-LJL-7L-JF----JLJLJL---7|F-7F-J||L7|F7F77F||L7L7L--7F-J||L7FJ|L-7.LJF---JLJFJFJ|||F--JF---7F-----JLJFJ|||||F-J||FF-LJF|777 +FJF--JL-JLJL7L7F7L7F7F7L--7|F------------J|L7|L7|LJFJLJLJL77|L7|FJF--JL-7|L7|L7|F-JFF7|F7F---JJL-J||L-7FJF--J|F-7F7F7FJFJLJLJL--J|7JL|FLJ.77 +F-JF-7F-7F-7L7LJL7LJ|||-F7LJL-7F-------7-FJFJ|FJF-7L7F--7FJFJFJLJ7L-7F7FJL7||FJLJLF-J|LJ||F-----7FJL7FJ|FJF7FJL7||||LJ7L7F---7F--JF7.|FJ-7J| +|F7|FJL7LJLL7L7|L|F-J|L-J|F7F-J|F------JFJFJ7LJLL7|-|L7LLJFJFJJL|7|FLJLJJ-||LJJF7|L-7L-7LJL-7F-7LJF7LJFJL7|||F-JLJ|L----JL--7LJF--J|-JJ-F-.L +LJLJL7FJ|F-7L7L7FJ|F7L--7LJLJF7|L--7F7F7|FJF7.F7FJL7L-JF7.|FJ||.F7J7.F|7JF||JJ.S|FJJL-7L7|F7LJ-L--JL--JF7LJLJ|F--7|F-----7F7L--JF7FJ.|.7LL|J +|..F7LJF7|FJ-L7|L7||L7F7L----J||F--J|||LJ|7|L-JLJF-JLF7||FJL--7F77-J------LJ--FJL7JF7FJFJFJL--7F-------JL---7LJF-JLJF---7||L--7FJLJ|7|.F7F7| +LF-JL77||||-F7||||||FJ|L7F-7F7LJL7F7|LJF7L7|F----JJF7|LJLJF7F-J|L7-|7JL|-|JL-.L-7|FJLJFJJL---7|L----------7FJF7L-7F7|F--J|L--7|L-7F77JLJFJJ- +LL--7L7||||FJLJL-JLJL7|FJL7|||7F7LJLJF-JL7LJL--7F-7||L7F--JLJF-JFJJL77LL7|F7.|-FJ|L--7|F-7.F7||F---7F-----JL7|L7FJ|LJL--7|F7FJ|F7LJ|JJ-F-.|7 +|LJLL7LJLJ|L------7F-J||F7||||FJ|F---JF-7|F----J|FJ||J|L-----JF7L7-F-JJ|J.F7.-JL7|F--J|L7|FJ|||L--7|L-----7FJL7|L7|F----JLJLJ.LJ|F7|JLFF7FLJ +F|77.L---7L7F-----JL-7|||||LJ|L7|L----JFJ|L-----JL-JL-JF7F--7FJL7L7|FL7|-F.F77F-JLJF-7|-||L7|||F--JL------JL--J|FJ||.F------7F7JLJLJ.FJJFJJ| +F7F7F7F7FL7||F7F7F7F7LJLJ|L-7L-J|F--7F-JFJF7F-----7F7F7||L-7LJ-L|FJJ--JJ-|.||-L-7F7|FJL-J|FJLJLJF-7F--7F----7F-JL-JL-JF--7F-J||7J7FJ-J|F7L77 +|LJLJLJL--JLJ|||||LJ|F7F7L7FL--7|L-7LJF7L-JLJF7F7-LJLJLJ|F7L-7JJLJJL7F|J7JFJL-7LLJLJL---7|L--7F7L7LJF-J|7F7FJL-7F-----JF7LJF-JL77F|7JFJL|F-- +L7F---7F7F7F7|LJLJJFJ|LJL7L---7||F7L--JL-----JLJL-7F---7|||F-JF7J-|L--.L-.|F-7|F77F--7F7|L--7||L-JF7L-7|FJLJF7JLJF7LF--JL7FJF--J7-JF7J.LLJLL +LLJF7L||||||||F----JFJ.F7L---7|||||F----------7F-7LJF--J||LJF-77LFL-7F77FLLJFJLJL7L-7LJLJF-7LJ|JF-JL--J|L7F7|L---JL-JF---J|FJJFF7|F||77L|.F. +F--JL-J|||LJ||L7F7F7|F-JL----JLJLJLJF--------7||FJF7L-7FJL--JFJ7-||JLJFF|JLFJF--7L--JF7F7|FJF7L7L7F----JJLJLJF----7F7L----JL7JFJ|-F|L777F7|7 +L7F7F-7|LJF-J|FJ|||||L-7F---7F7F-7F7|F-------JLJL7||F-JL7F7F-JJ..F7-F.|-JJ.L7L7|L7F-7|LJLJL7||FJ7LJF7F7F----7L7F7LLJ|F7F-7F7L7|FJ-FJFJ.FJ|FJ +|LJ||FJL-7L-7|L7|LJLJF7LJFF-J||L7LJLJL----------7LJLJ|LFJ|LJL|.F-||--|J-LLLJL-JF-J|LLJ-F7F7LJLJF---JLJ|L---7L7LJL--7||LJJLJL-J|L-7L7||7LLL|. +7LFJ|L7F-JF7LJFJ|F---JL---JF-JL-JF--7F-7F7F7F7F-JF---7-L7|F7F7F7|||.|||JF7LFF--JF-JF---JLJ|F7F7L-----7L7JF-J7|F7F-7|LJF-7F----JF7|FJL-7J.LLL +L|L-JJLJF7||F7L-JL---7F7F--JF7F7-L-7|L7LJLJLJ|L--JF--JF7LJ|||||L7|L-7L7FJ7LLL---JF7L-----7||||L7F---7L7L-JF-7|||L7|L-7L7LJF----JLJ|F--JFF-J| +FJ|LF---JLJ|||F7F7LF-J|LJF--JLJL---JL7L7F7F77L---7L7F7||F7||||L7||F-JF-77L|.LF---JL7F----JLJ|L7|L--7|FJF--JFJLJ|FJL--JFJF-JF7F7-|FJL--7FF--7 +FJ|LL--7F-7LJ||||L7L--JF-JF7F---7F-7FL-J|LJL---7|L7LJLJ||||LJ|FJLJ||FJFJ7-|-FL----7|L---7F-7L-JL---J|L7|F-7L--7LJF7F-7L7|FFJ||L7FJF-7FJ-J.|- +|F|7F-7LJ.L7FJ||L7|F7F7L--J||F--J|FL7F-7|F-----JF7L----J||L7FJL7F-JFJFJF-7F7FF7|F-JL----JL7L-7F7F--7L-J|L7L---JF7|||FJFJ|FJFJ|FJ|FJLLJJ-|7J| +LFF7L7L---7|L-JL-JLJLJ|F--7LJL--7|F-J|FJ||F--7F-JL7F--7F||-||F7|L7L|FJ-|FJ|L-JL7L--7F-7F--JLFJ|||F-JF-7|-L-----J||||L7L7|L7|FJL7|||F7J7FLF-7 +-FJL-JF7F7LJF-7F7F7F--JL-7L--7F7LJL--JL-JLJF7||F--J|F-JFJL-J||||FJFJ|F7|L7L--7FJ7F7LJLLJF7LFJFJLJL7FJFJ|F-------J|||FJFJL-JLJF7||L-JL777.|-| +LL--7FJLJL7FJJLJLJ|L7F-7.|F-7||L---------7FJ|||L--7|L-7L--7FJ|||L7L7LJ||FJF7FJ|F7|L7F7F7|L-JFJLF7.LJFJFJL---7F7F7||||FJF7F-7FJ|LJF--7L7J-F-. +|FJ7LJ.F-7LJF--7F7L7|L7L7LJFJLJF---7F--7-LJFLJ|F--J|F-JF7FJL-JLJFJFJF-J|L7|||FJ||L7LJ||LJF7FJF7||F--JFJF--7FJ|||LJLJLJFJLJFJ|FJF7L-7|FJJJ.L- +7JLF|F-L7L7FJF7LJL-JL7L7|F7L--7L7F7LJF-JF--7-FJL7F7|L-7||L7F----JFL7|F7|FJ||||FJ|.|F-JL--JLJ||LJ|L---JLL-7|L-JLJF7F--7L-7LL7||FJ|F7|LJJ..77| +||.7L7.LL7LJFJL-7F7F7L7||||F--JFJ|L-7L--JF-JFJF7|||L-7|||FJL--7F--7|||||L7|LJLJFJFJL---7F---7L-7L-----7F-JL-----JLJF7L7FJF-J||L7LJLJJ.F-..L7 +FJ.JFF--7L-7|F--J|||L7LJLJLJF--J.L-7|F7F-JF-JFJ||||F7|||||F---J|F-J|LJLJFJL---7L7L7F---JL-7FJF7L-----7|L--------7JFJL7LJLL-7|L7L----7--|--J| +JF7LFL-7L--J||F7FJ||FJF-7F-7|F7F---JLJ|L-7|F7L7LJ|||||||||L7F-7|L7-L7F--JF-7F7|FJFJL7F7F--JL7|L7.F7F-JL--------7L-JF7L--7F7||FJF----JJ7J|F-J +F||FFJFL7F7FJLJ||.LJL-J|LJFLJ||L-----7|F-J||L7L7FJ||LJLJLJFJ|FJ|FJF7|L7F7L7||||L7L7FJ||L---7||FJFJ|L---7F7FF--7L---JL--7LJ|LJL7L7F|LJL7.|.L. +--JJ-J|LLJ||F--JL7F----------JL------J|L--JL7L7LJFJL-7F--7|FJL7||FJLJFJ|L7|||||FJFJ|FJL-7F-JLJL-JFJF7F-J|L-JF7L------7|L-7L-7|L7|--7LFJFLLF7 +J-J||LL7LFLJL--7FJ|F7F7F-----7F-----7FL---7FJFL--JF7FJL7JLJL-7LJLJF--JFJFJ|||||L-JFJ|F--JL------7L-JLJF-JF--JL-------JF7|L7FJF7LJJ7|-|-7J|L7 +L|LJ7FL-.L.|F-7LJ7LJ||||F----JL7F---JF7F7LLJF-7F-7||L-7L---7|L7F-7L--7L7|FJ|||L-7FJFJL77F-------JF----JF7L-7F7F7F7F---JL7.LJFJL---77-L7-7-7J +F|7F7F|-L.FFL7L7|F7-LJLJL-7F7F-JL----JLJL--7|FJ|FJ||F7|F---JF7LJL|F--JFJ|L7||L7-|L7L-7L7L--7F---7L7F---JL-7LJ||||||F----JF-7L7F---J|LL|7|-LJ +L7-JJ||JLF7JLL7|FJL-7F7F7|LJ||F-7F----7F7F7||L-JL7|LJLJL7F-7||F7FJL7F7L7L7|||FJFJFJF-JFJF-7LJLF-JFJL7F-7F7L--J|||LJL-77F7|FJFJL-7J.F7JF7|.LJ +-7.|..|..|F-F-J|L7F7LJLJL7F7LJL7||F--7LJ||||L-7F-JL--7F-J|FJ|||LJF-J||J|FJ|LJ|JL7L7|F-JFL7|LF7|F-JJL||7LJL----JLJF7F7L-JLJL-JF--JJ7J|JLL-7|| +|.|J.77L.F7FJF7L7LJL----7LJL7FFJ|LJF7L-7LJ||F-J|F7FF7||F-JL7|||F7|F-JL-JL-JF-JF-JFJ|L--7FJ|FJ|LJF77FJ|F---------7|LJL---7F7F-J-F7-|L77.7J||| +7J-F-L--FJLJFJL7L7JF7F7JL7F7L-JFJF-JL--J|FJ|L-7LJ|FJLJLJF--J||LJ||L--7F7F--JF7L-7L7|F--JL7|L7|F7|L7L-JL-------7FJL-----7|||L---J|L--L|F7--J- +.JL|7..LL---JF7|FJFJLJL7|LJL-7FJLL----7F7L7|F7|F-JL--7F7L7F7|L7FJ|F-7LJ|L-7FJ|F-JFJ|||F7FJ|FJ|||L7|F7F------7FJL-7F----JLJ|F7F-7L7J7|J|J7FJ7 +F-FL7LF---77FJLJL7L---7L---7FJL-7F7F-7LJ|.LJ|||L-77F7LJL7||||FJL7||FJF-JF-JL7LJF-JFJL7||L7|L7||L7|LJ|L-----7|L--7|L-7F---7|||L7|FJJL-FJ7L7|7 +LFL-F7L7F7L-JF-7FJF--7L---7LJF-7LJLJLL--JF7FJ||F-JFJL-7F|||LJL7FJLJL7L-7L7F7L-7L7FJF-J|L7|L7||L7||F-JF-----JL-7FJ|F7||F7FJLJ|FJLJJ7|LJ-F--J7 +F|JJLL-LJL7F-JFJL-JF7L----JF7|FJF7F--7LF7||L7LJ|F7L7F-JFJ||F--JL-7F-JFFJFJ||F7|FJ|FJF7L7||FJ||FJ|||F7L-------7LJJLJLJ||LJF7LLJF7J7|JJL7L||F- +7|-7.|FLLFJ|F-JF7F-JL7F7F-7|||L7|LJF-JFJ||L7|F7|||FJ|F7L7|||F--7FJL--7L7L7|||||L-JL7|L7|||L7||L7|||||F7F----7L-7F---7|L--JL7F7||7FFJJF-7|-JJ +LJ.LF-|.FL-JL7FJ||F--J|LJ7||||FJ|F-JF7|FJ|FJLJ|||||FJ||7|||||F-JL7F--J7|FJ||||L--7FJL7||||FJ||F||||||||L---7L--J|F-7LJF7F7FJ|LJL-7JJ.|.LJF7. +FJ.7JF--7|F7FJ|FJ||F7FJJF-J|LJL-JL-7|||L7||F7FJ|||||FJ|FJ||||L7F7||F-7FJL7|||L--7||F7|||LJL7|L7|||LJ|||F7F-JLF77|||L7FJLJ|L-JF7F-J.LF7-|-|F| +|F-L|L-7L-JLJFJL7|LJ||F-JF-JF------J|LJ-|||||L7|||||||||FJ|LJFJ|||||J||F-J||L-77LJLJ||LJF--J|FJ|||F-J|||||JF-JL-JL-7|L-7||F--J|L7J7.L|F7-L|| +|L|||FL|F7F--J|-LJF-J|L7FJF7|F7F-7F7|.F-J|||L-JLJ||LJFJ|L7L-7|FJLJ||FJ||F7||F7|F----JL-7|F-7|L7|||L-7|LJ|L-JF-7F7F-JL--JFJL--7L-J.L|.L-|--L7 +||F7L7L||||7|JF---JF7|FJ|FJLJ||L7LJ|L7L-7||L--7F-JL-7|FJFJF7||L--7LJL7|||||||||L7F7F7F7|LJLLJFJ|||-FJL-7|F7FJ-|||L--7F-7L----J7||-J.FF-|7J-- +777JFJ|LJLJJ||L----JLJL-JL7F-J|FJF-JFJF-J|L---JL-7F7||L7|FJ|||F--JF7F||||||LJ|L7||LJ|||L-77F-JFJLJFJF7FJLJ||F7LJL7F-J|FJF7F7.|L-7|.L-J|LF77. +LFL---F|-LJLF------7JF----JL7FJL7L-7|FJF7L------7||||L-J||JLJ|L-7FJL-J||||L-7|FJLJJFJ||F7|FJF7L7F-JFJ|L-7FJLJL--7|L--JL-JLJL7F|JL7.|L|L7LJ-7 +||L7|.L.|L7-L7F-7F7L-JF-7F7FJL7FJF7LJL7|L7F7F-7FJ||||F--JL-7FJF-JL-7F7|LJ|F-JLJF7F-JFJ||||L7|L-J|F-J|L7FJL7F-7F7|L-7F---7F-7L7LF-J77L|-LFJ.- +FJLFF7FF|JF--J|-LJL--7|J||||F-J|FJL---JL7||||-LJ7||||L-7F7FJL7L--7FJ||L-7|L----J|L7FJ|LJLJFJ|F--J||F--J|F-JL7LJLJF-JL--7|L7L-J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||FLFLJ7J.7J.L7F|.FF7 +L|77|JF|7LF-L|F77-|-FLL|.L-J.LL|7J7LFF7L7..L7.-JJF7.FFJ-J-F|7-L-F--L7L-7J|-7|-F||-7LJ7L7L|7-FLFF-7L|.LLJJJJ.|J|.7F|7F-JF7--|.L||F|LJ-FLJFL-7 +F|-LJ|FJJF-J|.L|J7J.LJ|J.L|7..|LLFJ7L||-L7|.LLJ.FL|-|J.L|F-|7|.||FF-L--J---JF--7JF7-||JFJLJ.FFLJ.-7LJ-L7.7--F7JLF7L-|F7JLJ..F7L7JLFLLF7FLF|J +F|-|.-JL--7F-7F|FL77|.-.FLF7.L|FFJFL-|J..LJ-FJ7L-.J-7.7-J.LLL-JJJF||.L|LLFL7LF..F7.F|L-7|J|--J|L.|7L|J|F||F7|F7LJ|-LFF-J|7LLJJ7||-J|LLJ7-77. +LL-JJJ.7JL7J.|-.L--77-L|JLFJ7.L-7JL.L|J.--7.L-JJJ.L.L7--LJ-|JJLLFFJJ-LL-7JLL.J-L-.F-7JJFF.L-LJL-77-F--J-L7L-LLL-LLJ.JJ|LF-J--JLFL.7JJLLJ-L.F \ No newline at end of file diff --git a/src/aoc10test.txt b/src/aoc10test.txt new file mode 100644 index 0000000..3aea4dd --- /dev/null +++ b/src/aoc10test.txt @@ -0,0 +1,5 @@ +7-F7- +.FJ|7 +SJLL7 +|F--J +LJ.LJ From 0360704f690ac9ef00b8ca911d8eae509946dd82 Mon Sep 17 00:00:00 2001 From: Hane Date: Sun, 7 Jan 2024 17:32:02 +0100 Subject: [PATCH 10/10] wip 10-2 --- src/aoc10-2.lisp | 7 ++++--- src/aoc10.lisp | 2 +- src/aoc10test.txt | 15 ++++++++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/aoc10-2.lisp b/src/aoc10-2.lisp index 7650e46..a4e95c9 100644 --- a/src/aoc10-2.lisp +++ b/src/aoc10-2.lisp @@ -35,9 +35,9 @@ ;;(setf node-array (make-array '(line-length line-count) :initial-element nil)) finally - ;;(print line-length) - ;;(print line-count) - (setf node-array (make-array (list line-length line-count) :initial-element nil)) + (print line-length) + (print line-count) + (setf node-array (make-array (list line-count line-length) :initial-element nil)) (setf (aref node-array (cdr starting-pos) (car starting-pos)) t) (return (values input-array node-array starting-pos)) )))) @@ -165,6 +165,7 @@ ) finally + (print "--") (print node-array) (print steps) ) diff --git a/src/aoc10.lisp b/src/aoc10.lisp index 9b4b61b..befdcd0 100644 --- a/src/aoc10.lisp +++ b/src/aoc10.lisp @@ -37,7 +37,7 @@ finally ;;(print line-length) ;;(print line-count) - (setf node-array (make-array (list line-length line-count) :initial-element nil)) + (setf node-array (make-array (list line-count line-length) :initial-element nil)) (setf (aref node-array (cdr starting-pos) (car starting-pos)) t) (return (values input-array node-array starting-pos)) )))) diff --git a/src/aoc10test.txt b/src/aoc10test.txt index 3aea4dd..adaae96 100644 --- a/src/aoc10test.txt +++ b/src/aoc10test.txt @@ -1,5 +1,10 @@ -7-F7- -.FJ|7 -SJLL7 -|F--J -LJ.LJ +.F----7F7F7F7F-7.... +.|F--7||||||||FJ.... +.||.FJ||||||||L7.... +FJL7L7LJLJ||LJ.L-7.. +L--J.L7...LJS7F-7L7. +....F-J..F7FJ|L7L7L7 +....L7.F7||L7|.L7L7| +.....|FJLJ|FJ|F7|.LJ +....FJL-7.||.||||... +....L---J.LJ.LJLJ...