Hobbyist programmer

  • 0 Posts
  • 3 Comments
Joined 2 years ago
cake
Cake day: September 7th, 2024

help-circle
  • TXR

    (defun day02-pt1 ()
      (let ((pgm (file-get-string "02-input"))
            (col-num (pairlis "roygbv" 1..7)))
        (cdr (reduce-left (tb ((pos . dist) nxpos) 
                            (cons nxpos (+ dist (wrap 1 6 (- nxpos pos)))))
                          (map (lopip (assoc col-num) cdr) pgm)
                          '(1 . 0)))))
    

    I didn’t solve part 2 programmatically. I simply used Emacs’ 'count-matches' command to count occurrences of the 5 characters (not 6, as one of them never occurs!), and calculated the answer manually.