Skip to content

Instantly share code, notes, and snippets.

inp = string(strsplit(fileread("input.txt"),"\n"))';
inp = strip(inp(1:end-1));
instructions = extractBefore(inp,' ');
instr_bak = instructions;
values = str2double(extractAfter(inp,' '));
alreadyExecuted = zeros(length(instructions),1);
pc = 1;
acc = 0;
j = 1;
@ThomasTheGerman
ThomasTheGerman / day7.m
Created December 7, 2020 18:02
Advent of Code Day 7
inp = string(strsplit(fileread("input.txt"),"."))';
inp = string(strip(inp(1:end-1)));
containers = cell(length(inp),2);
containers(:,1) = cellfun(@(x) extractBefore(x,' bags contain '),inp,"UniformOutput",false);
inp = cellfun(@(x) split(x,' contain '),inp,"UniformOutput",false);
containers(:,2) = cellfun(@(x) split(x(2),', '),inp,"UniformOutput",false);
containers(:,2) = cellfun(@(x) replace(x,'bags',''),containers(:,2),"UniformOutput",false);
containers(:,2) = cellfun(@(x) replace(x,'bag',''),containers(:,2),"UniformOutput",false);
target = 'shiny gold';