-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathday02.lisp
More file actions
34 lines (26 loc) · 971 Bytes
/
day02.lisp
File metadata and controls
34 lines (26 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(defpackage :aoc/2015/02 #.cl-user::*aoc-use*)
(in-package :aoc/2015/02)
(defun parse-dimentions (string)
(mapcar #'parse-integer (cl-ppcre:split "x" string)))
(defun parse-input (lines) (mapcar #'parse-dimentions lines))
(defun paper (dimensions)
(destructuring-bind (l w h) dimensions
(let ((lw (* l w))
(wh (* w h))
(hl (* h l)))
(+ (+ (* 2 lw) (* 2 wh) (* 2 hl))
(min (* lw) (* wh) (* hl))))))
(defun part1 (list-of-dimentions)
(reduce #'+ list-of-dimentions :key #'paper))
(defun ribbon (dimensions)
(destructuring-bind (l w h) dimensions
(let ((lw (+ l w))
(wh (+ w h))
(hl (+ h l)))
(+ (* 2 (min lw wh hl))
(* l w h)))))
(defun part2 (list-of-dimentions)
(reduce #'+ list-of-dimentions :key #'ribbon))
(define-solution (2015 2) (list-of-dimensions parse-input)
(values (part1 list-of-dimensions) (part2 list-of-dimensions)))
(define-test (2015 2) (1598415 3812909))