home

Scientific Computing (Psychology 9040a)

Fall, 2021

Advent of Code 2016 Day 6: Sample solution


%% Advent of Code 2016 Day 6

I = importdata("AOC2016Day6_input.txt");

C = zeros(26,length(I{1}));

for i=1:length(I) % 624 rows of input
    for j=1:length(I{1}) % 8 columns per row
        c = I{i}(j) - 'a' + 1;
        C(c,j) = C(c,j) + 1;
    end
end

[m,i] = max(C);
message = char(i + 'a' -1);
fprintf("the answer to part 1 is %s\n", message);

%% Part 2

[m,i] = min(C);
message = char(i + 'a' -1);
fprintf("the answer to part 2 is %s\n", message);