2024/01-1
This commit is contained in:
commit
842b599d61
4 changed files with 1030 additions and 0 deletions
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
input linguist-vendored=true
|
1000
2024/day-01/input
vendored
Normal file
1000
2024/day-01/input
vendored
Normal file
File diff suppressed because it is too large
Load diff
26
2024/day-01/stage-1.lisp
Normal file
26
2024/day-01/stage-1.lisp
Normal file
|
@ -0,0 +1,26 @@
|
|||
(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))))
|
||||
(sorted (cons (sort (copy-seq (car lists)) #'<)
|
||||
(sort (copy-seq (cdr lists)) #'<))))
|
||||
(reduce #'+ (mapcar (lambda (itm1 itm2) (abs (- itm1 itm2)))
|
||||
(car sorted)
|
||||
(cdr sorted)))))
|
||||
|
||||
(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"))))
|
3
manifest.scm
Normal file
3
manifest.scm
Normal file
|
@ -0,0 +1,3 @@
|
|||
(specifications->manifest
|
||||
(list "sbcl"
|
||||
"sbcl-cl-strings"))
|
Loading…
Reference in a new issue