26 lines
786 B
Common Lisp
26 lines
786 B
Common Lisp
|
(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"))))
|