23 lines
596 B
Common Lisp
23 lines
596 B
Common Lisp
(ql:quickload :cl-ppcre)
|
|
(ql:quickload :alexandria)
|
|
|
|
(defun addx (amount)
|
|
(list 0 amount))
|
|
|
|
(defun noop ()
|
|
'(0))
|
|
|
|
(defun exec (program)
|
|
(let ((instr (ppcre:split "\\n" program)))
|
|
(alexandria:flatten
|
|
(append (list 1)
|
|
(loop :for line :in instr
|
|
:collect (eval (read-from-string (concatenate 'string "(" line ")"))))))))
|
|
|
|
(defun strength-at-cycle (program cycle)
|
|
(* cycle (reduce '+ (subseq program 0 cycle))))
|
|
|
|
(defun part-one (input)
|
|
(reduce '+ (loop :for x :in (list 20 60 100 140 180 220)
|
|
:collect (strength-at-cycle (exec (uiop:read-file-string input)) x))))
|