[-] ismail@programming.dev 5 points 11 hours ago

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.

[-] ismail@programming.dev 6 points 1 day ago

TXR

The 'hist-sort' function call does most of the work here, creating an association list of (id . freq) pairs in decreasing order of frequency:

@(next "01-input")
@(collect)
@  ids
@(end)
@;;
@(bind freqs @(hist-sort [map int-str ids]))
@;;
@(output)
1: @[prod (take 3 freqs) car]
2: @[prod (last freqs 3) car]
@(end)
[-] ismail@programming.dev 1 points 1 day ago

I have enjoyed writing solutions in TXR Lisp for some Project Euler problems recently, so that's what I intend using here. It has quite an extensive standard library that comes in handy when solving short competition-style programming problems.

ismail

0 post score
0 comment score
joined 2 years ago