;;;; 2.lisp (defpackage #:aoc/2015/2 (:use #:cl) (:shadow #:+problem-2-input+)) (in-package #:aoc/2015/2) (defparameter +problem-2-input+ (list (list 3 11 24) (list 13 5 19) (list 1 9 27) (list 24 8 21) (list 6 8 17) (list 19 18 22) (list 10 9 12) (list 12 2 5) (list 26 6 11) (list 9 23 15) (list 12 8 17) (list 13 29 10) (list 28 18 6) (list 22 28 26) (list 1 5 11) (list 29 26 12) (list 8 28 29) (list 27 4 21) (list 12 7 16) (list 7 4 23) (list 15 24 8) (list 15 14 2) (list 11 6 29) (list 28 19 9) (list 10 3 1) (list 5 20 13) (list 10 25 1) (list 22 17 7) (list 16 29 3) (list 18 22 8) (list 18 11 19) (list 21 24 20) (list 4 7 17) (list 22 27 12) (list 1 26 6) (list 5 27 24) (list 29 21 3) (list 25 30 2) (list 21 26 2) (list 10 24 27) (list 10 16 28) (list 18 16 23) (list 6 5 26) (list 19 12 20) (list 6 24 25) (list 11 20 7) (list 4 8 5) (list 2 13 11) (list 11 17 1) (list 13 24 6) (list 22 29 16) (list 4 24 20) (list 10 25 10) (list 12 29 23) (list 23 27 12) (list 11 21 9) (list 13 2 6) (list 15 30 2) (list 8 26 24) (list 24 7 30) (list 22 22 8) (list 29 27 8) (list 28 23 27) (list 13 16 14) (list 9 28 20) (list 21 4 30) (list 21 20 20) (list 11 17 30) (list 9 14 22) (list 20 2 6) (list 10 11 14) (list 1 8 23) (list 23 19 19) (list 26 10 13) (list 21 12 12) (list 25 7 24) (list 1 28 17) (list 20 23 9) (list 2 24 27) (list 20 24 29) (list 1 3 10) (list 5 20 14) (list 25 21 3) (list 15 5 22) (list 14 17 19) (list 27 3 18) (list 29 23 19) (list 14 21 19) (list 20 8 3) (list 22 27 12) (list 24 15 18) (list 9 10 19) (list 29 25 28) (list 14 22 6) (list 4 19 28) (list 4 24 14) (list 17 19 17) (list 7 19 29) (list 28 8 26) (list 7 20 16) (list 11 26 29) (list 2 18 3) (list 12 7 18) (list 11 15 21) (list 24 7 26) (list 2 22 23) (list 2 30 5) (list 1 19 8) (list 15 29 10) (list 15 26 22) (list 20 16 14) (list 25 29 22) (list 3 13 19) (list 1 12 30) (list 3 15 27) (list 19 9 11) (list 30 8 21) (list 26 12 20) (list 11 17 19) (list 17 25 1) (list 19 24 12) (list 30 6 20) (list 11 19 18) (list 18 15 29) (list 18 8 9) (list 25 15 5) (list 15 6 26) (list 13 27 19) (list 23 24 12) (list 3 15 28) (list 17 10 10) (list 15 4 7) (list 15 27 7) (list 21 8 11) (list 9 18 2) (list 7 20 20) (list 17 23 12) (list 2 19 1) (list 7 26 26) (list 13 23 8) (list 10 3 12) (list 11 1 9) (list 1 11 19) (list 25 14 26) (list 16 10 15) (list 7 6 11) (list 8 1 27) (list 20 28 17) (list 3 25 9) (list 30 7 5) (list 17 17 4) (list 23 25 27) (list 23 8 5) (list 13 11 1) (list 15 10 21) (list 22 16 1) (list 12 15 28) (list 27 18 26) (list 25 18 5) (list 21 3 27) (list 15 25 5) (list 29 27 19) (list 11 10 12) (list 22 16 21) (list 11 8 18) (list 6 10 23) (list 21 21 2) (list 13 27 28) (list 2 5 20) (list 23 16 20) (list 1 21 7) (list 22 2 13) (list 11 10 4) (list 7 3 4) (list 19 2 5) (list 21 11 1) (list 7 27 26) (list 12 4 23) (list 12 3 15) (list 25 7 4) (list 20 7 15) (list 16 5 11) (list 1 18 26) (list 11 27 10) (list 17 6 24) (list 19 13 16) (list 6 3 11) (list 4 19 18) (list 16 15 15) (list 1 11 17) (list 19 11 29) (list 18 19 1) (list 1 25 7) (list 8 22 14) (list 15 6 19) (list 5 30 18) (list 30 24 22) (list 11 16 2) (list 21 29 19) (list 20 29 11) (list 27 1 18) (list 20 5 30) (list 12 4 28) (list 3 9 30) (list 26 20 15) (list 18 25 18) (list 20 28 28) (list 21 5 3) (list 20 21 25) (list 19 27 22) (list 8 27 9) (list 1 5 15) (list 30 6 19) (list 16 5 15) (list 18 30 21) (list 4 15 8) (list 9 3 28) (list 18 15 27) (list 25 11 6) (list 17 22 15) (list 18 12 18) (list 14 30 30) (list 1 7 23) (list 27 21 12) (list 15 7 18) (list 16 17 24) (list 11 12 19) (list 18 15 21) (list 6 18 15) (list 2 21 4) (list 12 9 14) (list 19 7 25) (list 22 3 1) (list 29 19 7) (list 30 25 7) (list 6 27 27) (list 5 13 9) (list 21 4 18) (list 13 1 16) (list 11 21 25) (list 27 20 27) (list 14 25 9) (list 23 11 15) (list 22 10 26) (list 15 16 4) (list 14 16 21) (list 1 1 24) (list 17 27 3) (list 25 28 16) (list 12 2 29) (list 9 19 28) (list 12 7 17) (list 6 9 19) (list 15 14 24) (list 25 21 23) (list 26 27 25) (list 7 18 13) (list 15 10 6) (list 22 28 2) (list 15 2 14) (list 3 24 18) (list 30 22 7) (list 18 27 17) (list 29 18 7) (list 20 2 4) (list 4 20 26) (list 23 30 15) (list 5 7 3) (list 4 24 12) (list 24 30 20) (list 26 18 17) (list 6 28 3) (list 29 19 29) (list 14 10 4) (list 15 5 23) (list 12 25 4) (list 7 15 19) (list 26 21 19) (list 18 2 23) (list 19 20 3) (list 3 13 9) (list 29 21 24) (list 26 13 29) (list 30 27 4) (list 20 10 29) (list 21 18 8) (list 7 26 10) (list 29 16 21) (list 22 5 11) (list 17 15 2) (list 7 29 5) (list 6 18 15) (list 23 6 14) (list 10 30 14) (list 26 6 16) (list 24 13 25) (list 17 29 20) (list 4 27 19) (list 28 12 11) (list 23 20 3) (list 22 6 20) (list 29 9 19) (list 10 16 22) (list 30 26 4) (list 29 26 11) (list 2 11 15) (list 1 3 30) (list 30 30 29) (list 9 1 3) (list 30 13 16) (list 20 4 5) (list 23 28 11) (list 24 27 1) (list 4 25 10) (list 9 3 6) (list 14 4 15) (list 4 5 25) (list 27 14 13) (list 20 30 3) (list 28 15 25) (list 5 19 2) (list 10 24 29) (list 29 30 18) (list 30 1 25) (list 7 7 15) (list 1 13 16) (list 23 18 4) (list 1 28 8) (list 24 11 8) (list 22 26 19) (list 30 30 14) (list 2 4 13) (list 27 20 26) (list 16 20 17) (list 11 12 13) (list 28 2 17) (list 15 26 13) (list 29 15 25) (list 30 27 9) (list 2 6 25) (list 10 26 19) (list 16 8 23) (list 12 17 18) (list 26 14 22) (list 13 17 4) (list 27 27 29) (list 17 13 22) (list 9 8 3) (list 25 15 20) (list 14 13 16) (list 8 7 13) (list 12 4 21) (list 27 16 15) (list 6 14 5) (list 28 29 17) (list 23 17 25) (list 10 27 28) (list 1 28 21) (list 18 2 30) (list 25 30 16) (list 25 21 7) (list 2 3 4) (list 9 6 13) (list 19 6 10) (list 28 17 8) (list 13 24 28) (list 24 12 7) (list 5 19 5) (list 18 10 27) (list 16 1 6) (list 12 14 30) (list 1 2 28) (list 23 21 2) (list 13 3 23) (list 9 22 10) (list 10 17 2) (list 24 20 11) (list 30 6 14) (list 28 1 16) (list 24 20 1) (list 28 7 7) (list 1 24 21) (list 14 9 7) (list 22 8 15) (list 20 1 21) (list 6 3 7) (list 7 26 14) (list 5 7 28) (list 5 4 4) (list 15 7 28) (list 30 16 23) (list 7 26 2) (list 1 2 30) (list 24 28 20) (list 5 17 28) (list 4 15 20) (list 15 26 2) (list 1 3 23) (list 22 30 24) (list 9 20 16) (list 7 15 2) (list 6 21 18) (list 21 21 29) (list 29 10 10) (list 4 3 23) (list 23 2 18) (list 29 24 14) (list 29 29 16) (list 22 28 24) (list 21 18 24) (list 16 21 6) (list 3 9 22) (list 9 18 4) (list 22 9 9) (list 12 9 13) (list 18 21 14) (list 7 8 29) (list 28 28 14) (list 1 6 24) (list 11 11 3) (list 8 28 6) (list 11 16 10) (list 9 16 16) (list 6 6 19) (list 21 5 12) (list 15 17 12) (list 3 6 29) (list 19 1 26) (list 10 30 25) (list 24 26 21) (list 1 10 18) (list 6 1 16) (list 4 17 27) (list 17 11 27) (list 15 15 21) (list 14 23 1) (list 8 9 30) (list 22 22 25) (list 20 27 22) (list 12 7 9) (list 9 26 19) (list 26 25 12) (list 8 8 16) (list 28 15 10) (list 29 18 2) (list 25 22 6) (list 4 6 15) (list 12 18 4) (list 10 3 20) (list 17 28 17) (list 14 25 13) (list 14 10 3) (list 14 5 10) (list 7 7 22) (list 21 2 14) (list 1 21 5) (list 27 29 1) (list 6 20 4) (list 7 19 23) (list 28 19 27) (list 3 9 18) (list 13 17 17) (list 18 8 15) (list 26 23 17) (list 10 10 13) (list 11 5 21) (list 25 15 29) (list 6 23 24) (list 10 7 2) (list 19 10 30) (list 4 3 23) (list 22 12 6) (list 11 17 16) (list 6 8 12) (list 18 20 11) (list 6 2 2) (list 17 4 11) (list 20 23 22) (list 29 23 24) (list 25 11 21) (list 22 11 15) (list 29 3 9) (list 13 30 5) (list 17 10 12) (list 10 30 8) (list 21 16 17) (list 1 5 26) (list 22 15 16) (list 27 7 11) (list 16 8 18) (list 29 9 7) (list 25 4 17) (list 10 21 25) (list 2 19 21) (list 29 11 16) (list 18 26 21) (list 2 8 20) (list 17 29 27) (list 25 27 4) (list 14 3 14) (list 25 29 29) (list 26 18 11) (list 8 24 28) (list 7 30 24) (list 12 30 22) (list 29 20 6) (list 3 17 1) (list 6 15 14) (list 6 22 20) (list 13 26 26) (list 12 2 1) (list 7 14 12) (list 15 16 11) (list 3 21 4) (list 30 17 29) (list 9 18 27) (list 11 28 16) (list 22 3 25) (list 18 15 15) (list 2 30 12) (list 3 27 22) (list 10 8 8) (list 26 16 14) (list 15 2 29) (list 12 10 7) (list 21 20 15) (list 2 15 25) (list 4 14 13) (list 3 15 13) (list 29 8 3) (list 7 7 28) (list 15 10 24) (list 23 15 5) (list 5 7 14) (list 24 1 22) (list 1 11 13) (list 26 4 19) (list 19 16 26) (list 5 25 5) (list 17 25 14) (list 23 7 14) (list 24 6 17) (list 5 13 12) (list 20 20 5) (list 22 29 17) (list 11 17 29) (list 25 6 4) (list 29 8 16) (list 28 22 24) (list 24 23 17) (list 16 17 4) (list 17 8 25) (list 22 9 13) (list 24 4 8) (list 18 10 20) (list 21 23 21) (list 13 14 12) (list 23 26 4) (list 4 10 29) (list 2 18 18) (list 19 5 21) (list 2 27 23) (list 6 29 30) (list 21 9 20) (list 6 5 16) (list 25 10 27) (list 5 29 21) (list 24 14 19) (list 19 11 8) (list 2 28 6) (list 19 25 6) (list 27 1 11) (list 6 8 29) (list 18 25 30) (list 4 27 26) (list 8 12 1) (list 7 17 25) (list 7 14 27) (list 12 9 5) (list 14 29 13) (list 18 17 5) (list 23 1 3) (list 28 5 13) (list 3 2 26) (list 3 7 11) (list 1 8 7) (list 12 5 4) (list 2 30 21) (list 16 30 11) (list 3 26 4) (list 16 9 4) (list 11 9 22) (list 23 5 6) (list 13 20 3) (list 4 3 2) (list 14 10 29) (list 11 8 12) (list 26 15 16) (list 7 17 29) (list 18 19 18) (list 8 28 4) (list 22 6 13) (list 9 23 7) (list 11 23 20) (list 13 11 26) (list 15 30 13) (list 1 5 8) (list 5 10 24) (list 22 25 17) (list 27 20 25) (list 30 10 21) (list 16 28 24) (list 20 12 8) (list 17 25 1) (list 30 14 9) (list 14 18 6) (list 8 28 29) (list 12 18 29) (list 9 7 18) (list 6 12 25) (list 20 13 24) (list 22 3 12) (list 5 23 22) (list 8 10 17) (list 7 23 5) (list 10 26 27) (list 14 26 19) (list 10 18 24) (list 8 4 4) (list 16 15 11) (list 3 14 9) (list 18 5 30) (list 29 12 26) (list 16 13 12) (list 15 10 7) (list 18 5 26) (list 14 1 6) (list 10 8 29) (list 3 4 9) (list 19 4 23) (list 28 17 23) (list 30 7 17) (list 19 5 9) (list 26 29 28) (list 22 13 17) (list 28 2 1) (list 20 30 8) (list 15 13 21) (list 25 23 19) (list 27 23 1) (list 4 6 23) (list 29 29 24) (list 5 18 7) (list 4 6 30) (list 17 15 2) (list 27 4 2) (list 25 24 14) (list 28 8 30) (list 24 29 5) (list 14 30 14) (list 10 18 19) (list 15 26 22) (list 24 19 21) (list 29 23 27) (list 21 10 16) (list 7 4 29) (list 14 21 3) (list 21 4 28) (list 17 16 15) (list 24 7 13) (list 21 24 15) (list 25 11 16) (list 10 26 13) (list 23 20 14) (list 20 29 27) (list 14 24 14) (list 14 23 12) (list 18 6 5) (list 3 18 9) (list 8 18 19) (list 20 26 15) (list 16 14 13) (list 30 16 3) (list 17 13 4) (list 15 19 30) (list 20 3 8) (list 13 4 5) (list 12 10 15) (list 8 23 26) (list 16 8 15) (list 22 8 11) (list 12 11 18) (list 28 3 30) (list 15 8 4) (list 13 22 13) (list 21 26 21) (list 29 1 15) (list 28 9 5) (list 27 3 26) (list 22 19 30) (list 4 11 22) (list 21 27 20) (list 22 26 7) (list 19 28 20) (list 24 23 16) (list 26 12 9) (list 13 22 9) (list 5 6 23) (list 20 7 2) (list 18 26 30) (list 3 6 28) (list 24 18 13) (list 28 19 16) (list 25 21 25) (list 25 19 23) (list 22 29 10) (list 29 19 30) (list 4 7 27) (list 5 12 28) (list 8 26 6) (list 14 14 25) (list 17 17 2) (list 5 27 11) (list 8 2 2) (list 3 20 24) (list 26 10 9) (list 22 28 27) (list 18 15 20) (list 12 11 1) (list 5 14 30) (list 7 3 16) (list 2 16 16) (list 18 20 15) (list 13 14 29) (list 1 17 12) (list 13 5 23) (list 19 4 10) (list 25 19 11) (list 15 17 14) (list 1 28 27) (list 11 9 28) (list 9 10 18) (list 30 11 22) (list 21 21 20) (list 2 1 5) (list 2 25 1) (list 7 3 4) (list 22 15 29) (list 21 28 15) (list 12 12 4) (list 21 30 6) (list 15 10 7) (list 10 14 6) (list 21 26 18) (list 14 25 6) (list 9 7 11) (list 22 3 1) (list 1 16 27) (list 1 14 23) (list 2 13 8) (list 14 19 11) (list 21 26 1) (list 4 28 13) (list 12 16 20) (list 21 13 9) (list 3 4 13) (list 14 9 8) (list 21 21 12) (list 27 10 17) (list 6 20 6) (list 28 23 23) (list 2 28 12) (list 8 10 10) (list 3 9 2) (list 20 3 29) (list 19 4 16) (list 29 24 9) (list 26 20 8) (list 15 28 26) (list 18 17 10) (list 7 22 10) (list 20 15 9) (list 6 10 8) (list 7 26 21) (list 8 8 16) (list 15 6 29) (list 22 30 11) (list 18 25 8) (list 6 21 20) (list 7 23 25) (list 8 25 26) (list 11 25 27) (list 22 18 23) (list 3 2 14) (list 16 16 1) (list 15 13 11) (list 3 9 25) (list 29 25 24) (list 9 15 1) (list 12 4 1) (list 23 30 20) (list 3 1 23) (list 6 10 29) (list 28 13 24) (list 4 19 17) (list 6 6 25) (list 27 29 17) (list 12 13 2) (list 10 7 13) (list 14 15 8) (list 22 2 3) (list 27 17 19) (list 23 10 16) (list 5 9 25) (list 9 25 14) (list 11 18 6) (list 18 10 12) (list 9 4 15) (list 7 16 14) (list 17 24 10) (list 11 4 6) (list 12 9 17) (list 22 18 12) (list 6 24 24) (list 6 22 23) (list 5 17 30) (list 6 9 5) (list 17 20 10) (list 6 8 12) (list 14 17 13) (list 29 10 17) (list 22 4 5) (list 10 19 30) (list 22 29 11) (list 10 12 29) (list 21 22 26) (list 16 6 25) (list 1 26 24) (list 30 17 16) (list 27 28 5) (list 30 13 22) (list 7 26 12) (list 11 24 30) (list 1 17 25) (list 22 1 3) (list 29 24 6) (list 4 8 24) (list 13 9 20) (list 8 12 9) (list 21 25 4) (list 23 23 28) (list 5 2 19) (list 29 3 15) (list 22 1 14) (list 3 23 30) (list 8 25 3) (list 15 8 14) (list 30 14 6) (list 23 27 24) (list 19 1 2) (list 10 9 13) (list 13 8 7) (list 8 13 22) (list 5 15 20) (list 17 14 8) (list 5 11 20) (list 5 10 27) (list 24 17 19) (list 21 2 3) (list 15 30 26) (list 21 19 15) (list 2 7 23) (list 13 17 25) (list 30 15 19) (list 26 4 10) (list 2 25 8) (list 9 9 10) (list 2 25 8) (list 19 21 30) (list 17 26 12) (list 7 5 10) (list 2 22 14) (list 10 17 30) (list 1 8 5) (list 23 2 25) (list 22 29 8) (list 13 26 1) (list 26 3 30) (list 25 17 8) (list 25 18 26) (list 26 19 15) (list 8 28 10) (list 12 16 29) (list 30 6 29) (list 28 19 4) (list 27 26 18) (list 15 23 17) (list 5 21 30) (list 8 11 13) (list 2 26 7) (list 19 9 24) (list 3 22 23) (list 6 7 18) (list 4 26 30) (list 13 25 20) (list 17 3 15) (list 8 20 18) (list 23 18 23) (list 28 23 9) (list 16 3 4) (list 1 29 14) (list 20 26 22) (list 3 2 22) (list 23 8 17) (list 19 5 17) (list 21 18 20) (list 17 21 8) (list 30 28 1) (list 29 19 23) (list 12 12 11) (list 24 18 7) (list 21 18 14) (list 14 26 25) (list 9 11 3) (list 10 7 15) (list 27 6 28) (list 14 26 4) (list 28 4 1) (list 22 25 29) (list 6 26 6) (list 1 3 13) (list 26 22 12) (list 6 21 26) (list 23 4 27) (list 26 13 24) (list 5 24 28) (list 22 16 7) (list 3 27 24) (list 19 28 2) (list 11 13 9) (list 29 16 22) (list 30 10 24) (list 14 14 22) (list 22 23 16) (list 14 8 3) (list 20 5 14) (list 28 6 13) (list 3 15 25) (list 4 12 22) (list 15 12 25) (list 10 11 24) (list 7 7 6) (list 8 11 9) (list 21 10 29) (list 23 28 30) (list 8 29 26) (list 16 27 11) (list 1 10 2) (list 24 20 16) (list 7 12 28) (list 28 8 20) (list 14 10 30) (list 1 19 6) (list 4 12 20) (list 18 2 7) (list 24 18 17) (list 16 11 10) (list 1 12 22) (list 30 16 28) (list 18 12 11) (list 28 9 8) (list 23 6 17) (list 10 3 11) (list 5 12 8) (list 22 2 23) (list 9 19 14) (list 15 28 13) (list 27 20 23) (list 19 16 12) (list 19 30 15) (list 8 17 4) (list 10 22 18) (list 13 22 4) (list 3 12 19) (list 22 16 23) (list 11 8 19) (list 8 11 6) (list 7 14 7) (list 29 17 29) (list 21 8 12) (list 21 9 11) (list 20 1 27) (list 1 22 11) (list 5 28 4) (list 26 7 26) (list 30 12 18) (list 29 11 20) (list 3 12 15) (list 24 25 17) (list 14 6 11))) (defun sort-inputs (&optional (input +problem-2-input+)) (loop :for l :in input :collect (sort l #'<))) (defun area (box) (declare (type list box)) (assert (= (length box) 3)) (let ((first (first box)) (second (second box)) (third (third box))) (+ (* 3 first second) (* 2 second third) (* 2 first third)))) (defun part1 (&optional (input +problem-2-input+)) (let ((sum 0)) (loop :for box :in (sort-inputs input) :do (incf sum (area box))) sum)) (defun ribbon (box) (declare (type list box)) (assert (= (length box) 3)) (let ((first (first box)) (second (second box)) (third (third box))) (+ (* 2 (+ first second)) (* first second third)))) (defun part2 (&optional (input +problem-2-input+)) (let ((sum 0)) (loop :for box :in (sort-inputs input) :do (incf sum (ribbon box))) sum))