mirror of
https://github.com/correl/advent-of-code.git
synced 2024-11-22 03:00:05 +00:00
Day 2, Part 2
This commit is contained in:
parent
8612d41d12
commit
791d7d901b
1 changed files with 57 additions and 0 deletions
|
@ -1190,3 +1190,60 @@ feet of wrapping paper* should they order?
|
|||
#+RESULTS[f343fb2890e11ccbcc408d25b441e9a808073e1f]: 2-solution
|
||||
: 1606483
|
||||
|
||||
** Part 2
|
||||
The elves are also running low on ribbon. Ribbon is all the same
|
||||
width, so they only have to worry about the length they need to order,
|
||||
which they would again like to be exact.
|
||||
|
||||
The ribbon required to wrap a present is the shortest distance around
|
||||
its sides, or the smallest perimeter of any one face. Each present
|
||||
also requires a bow made out of ribbon as well; the feet of ribbon
|
||||
required for the perfect bow is equal to the cubic feet of volume of
|
||||
the present. Don't ask how they tie the bow, though; they'll never
|
||||
tell.
|
||||
|
||||
For example:
|
||||
|
||||
- A present with dimensions =2x3x4= requires =2+2+3+3 = 10= feet of
|
||||
ribbon to wrap the present plus =2*3*4 = 24= feet of ribbon for the
|
||||
bow, for a total of =34= feet.
|
||||
- A present with dimensions =1x1x10= requires =1+1+1+1 = 4= feet of
|
||||
ribbon to wrap the present plus =1*1*10 = 10= feet of ribbon for the
|
||||
bow, for a total of =14= feet.
|
||||
|
||||
How many total feet of ribbon should they order?
|
||||
|
||||
----------------------------------------------------------------------
|
||||
|
||||
#+BEGIN_SRC emacs-lisp :var input=2-input :exports both
|
||||
(defun day2/smallest-perimeter (w h l)
|
||||
(min (* 2 (+ l w))
|
||||
(* 2 (+ w h))
|
||||
(* 2 (+ h l))))
|
||||
|
||||
(defun day2/volume (w h l)
|
||||
(* w h l))
|
||||
|
||||
(defun day2/ribbon (w h l)
|
||||
(+ (day2/smallest-perimeter w h l)
|
||||
(day2/volume w h l)))
|
||||
|
||||
(ert-deftest day2/ribbon ()
|
||||
(should (eq 34 (day2/ribbon 2 3 4)))
|
||||
(should (eq 14 (day2/ribbon 1 1 10))))
|
||||
|
||||
(defun day2/sum-ribbon (input)
|
||||
(seq-reduce
|
||||
#'+
|
||||
(seq-map (lambda (dimension-string)
|
||||
(let ((dimensions (day2/parse-dimensions dimension-string)))
|
||||
(eval (cons 'day2/ribbon dimensions))))
|
||||
(split-string input))
|
||||
0))
|
||||
|
||||
(day2/sum-ribbon input)
|
||||
#+END_SRC
|
||||
|
||||
#+RESULTS[c13958a4756029347386f7b48c44959c7b8e3dea]:
|
||||
: 3842356
|
||||
|
||||
|
|
Loading…
Reference in a new issue