Fall, 2021
%% Advent of Code 2015 Day 2
% Part 1
P = importdata('AOC2015Day2_input.txt');
n = length(P);
paper = 0;
for i=1:n
s = strsplit(P{i}, 'x');
l = str2num(s{1});
w = str2num(s{2});
h = str2num(s{3});
p = 2*l*w + 2*w*h + 2*h*l;
slack = min([l*w,l*h,w*h]);
paper = paper + p + slack;
end
fprintf("the answer to part 1 is %d\n", paper);
%% Part 2
P = importdata('AOC2015Day2_input.txt');
n = length(P);
ribbon = 0;
for i=1:n
s = strsplit(P{i}, 'x');
l = str2num(s{1});
w = str2num(s{2});
h = str2num(s{3});
r = min([l+l+w+w, l+l+h+h, w+w+h+h]);
bow = l*w*h;
ribbon = ribbon + r + bow;
end
fprintf("the answer to part 2 is %d\n", ribbon);