
(ql:quickload "str") ;; (defun file-get-contents (filename) ;; (with-open-file (stream filename) ;; (let ((contents (make-string ;; (file-length stream)))) ;; (read-sequence contents stream) ;; contents))) (defun file-get-lines (filename) (with-open-file (stream filename) (loop :for line = (read-line stream nil) :while line :collect line))) ;; (defun string-to-list (the-string) ;; (loop :for char :across the-string ;; :collect char)) ;; (defun char-to-integer-list (char-list) ;; (mapcar #'digit-char-p char-list)) (defun path-add-item (x yys zzs) (let* ((y (car yys)) (ys (cdr yys)) (z (car zzs)) (zs (cdr zzs)) (m (if (> y z) y z)) (ms (if (> y z) ys zs))) (cons (+ x m) (cons x ms)))) (defmacro zipWith3 (f xs ys zs) `(mapcar ,f ,xs ,ys ,zs)) (defun path-add-item-zip (acc xs) (zipWith3 #'path-add-item xs acc (cdr acc))) (defun foldl (f acc xs) (if (not xs) acc (foldl f (funcall f acc (car xs)) (cdr xs)))) (defun string-split (x) (str:split #\space x)) (defun map-parse-integer (xs) (mapcar #'parse-integer xs)) (defmacro map-string-split (xs) `(mapcar #'string-split ,xs)) (defmacro head (xs) `(car ,xs)) (defmacro tail (xs) `(cdr ,xs)) (defun pair-double (x) (list x x)) (defun e18 () (let* ((string-lines (file-get-lines #P"n.txt")) (string-lists (map-string-split string-lines)) (number-tower (mapcar #'map-parse-integer string-lists)) (r-tower (reverse number-tower)) (acc (mapcar #'pair-double (head r-tower)))) (foldl #'path-add-item-zip acc (tail r-tower))))
CL-USER> (e18) ((1074 75 64 82 87 82 75 73 28 83 32 91 78 58 73 93)) CL-USER>
— Me@2023-12-20 07:32:00 PM
.
.
2023.12.21 Thursday (c) All rights reserved by ACHK

You must be logged in to post a comment.