From 527bc4762f9c66c9244f0ac1fbee6357478ac9ef Mon Sep 17 00:00:00 2001 From: HJ Date: Thu, 9 Dec 2021 18:05:04 -0500 Subject: putting all my solutions together in 1 repository --- 2015/day-02/day-02.rkt | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 2015/day-02/day-02.rkt (limited to '2015/day-02/day-02.rkt') diff --git a/2015/day-02/day-02.rkt b/2015/day-02/day-02.rkt new file mode 100644 index 0000000..870e380 --- /dev/null +++ b/2015/day-02/day-02.rkt @@ -0,0 +1,48 @@ +#lang racket +(require "../../jj-aoc.rkt" + threading + racket/struct) + +(struct present (l w h) #:transparent) + +(define presents + (for/list ([size-string (in-lines (open-day 2 2015))]) + (~> size-string + (string-split "x") + (map string->number _) + (apply present _)))) + +;; part 1 +(define (paper-area p) + (define main-area + (~> p + struct->list + (combinations 2) + (map (λ~> (apply * 2 _)) _) + (apply + _))) + (define slack-area + (~> p + struct->list + (sort <) + (take 2) + (apply * _))) + (+ main-area slack-area)) + +(for/sum ([p (in-list presents)]) (paper-area p)) + +;; part 2 +(define (ribbon-length p) + (define ribbon-around-box + (~> p + struct->list + (sort <) + (take 2) + (map (λ~> (* 2)) _) + (apply + _))) + (define ribbon-for-bow + (~> p + struct->list + (apply * _))) + (+ ribbon-around-box ribbon-for-bow)) + +(for/sum ([p (in-list presents)]) (ribbon-length p)) \ No newline at end of file -- cgit v1.2.3