X-Git-Url: http://git.jkinsey.net/?p=adventofcode2020.git;a=blobdiff_plain;f=src%2Futilities.lisp;h=ce9aa6d39ce67b27c0608dda35c3adf23e5e18b9;hp=ab6c3e8faa36eb6d59ac780c1ae7d8f6670a142b;hb=HEAD;hpb=63a814f25cb8eff79f8f566f75b7b5fdac549f5f diff --git a/src/utilities.lisp b/src/utilities.lisp index ab6c3e8..ce9aa6d 100644 --- a/src/utilities.lisp +++ b/src/utilities.lisp @@ -6,7 +6,10 @@ (split "\\n" str)) (defun int-list-from (str) - (mapcar #'parse-integer (split "\\n" str))) + (mapcar #'parse-integer (list-from str))) + +(defun list-list-from (str) + (split-sequence "" (list-from str) :test #'string=)) (defun cartesian-product (A B &rest C) (let ((helper (lambda (X Y) @@ -17,6 +20,11 @@ (wrap-A (mapcar #'list A))) (reduce helper C :initial-value (funcall helper wrap-A B)))) +(defun manhattan-distance (a b) + (destructuring-bind ((ax ay) (bx by)) (list a b) + (+ (abs (- ax bx)) + (abs (- ay by))))) + (def-suite util) (in-suite util)