2024/01-2
This commit is contained in:
parent
842b599d61
commit
496e18cce2
1 changed files with 25 additions and 0 deletions
25
2024/day-01/stage-2.lisp
Normal file
25
2024/day-01/stage-2.lisp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
(require 'asdf)
|
||||||
|
|
||||||
|
(asdf:load-system "cl-strings")
|
||||||
|
|
||||||
|
(require :cl-strings)
|
||||||
|
|
||||||
|
(defun diff (data)
|
||||||
|
(let* ((lists (reduce (lambda (acc itm) (cons (cons (parse-integer (car itm)) (car acc)) (cons (parse-integer (cadr itm)) (cdr acc))))
|
||||||
|
(mapcar (lambda (line) (cl-strings:split line " "))
|
||||||
|
(cl-strings:split data "
|
||||||
|
"))
|
||||||
|
:initial-value (cons (list) (list)))))
|
||||||
|
(reduce (lambda (acc itm)
|
||||||
|
(+ acc (* (car itm) (cdr itm))))
|
||||||
|
(mapcar (lambda (itm) (cons itm (count itm (cdr lists)))) (car lists))
|
||||||
|
:initial-value 0)))
|
||||||
|
|
||||||
|
(format t "~s~%" (diff "3 4
|
||||||
|
4 3
|
||||||
|
2 5
|
||||||
|
1 3
|
||||||
|
3 9
|
||||||
|
3 3"))
|
||||||
|
|
||||||
|
(format t "~s~%" (diff (string-right-trim '(#\Space #\Newline) (uiop:read-file-string "input"))))
|
Loading…
Reference in a new issue