Unable to load image

Advent of Code Day 5, AKA Stacks 101 :marseyinabox:

I actually stayed up to get a semi-decent score for once (being a eurocel for this is suffering). How are you all faring with shifting boxes around?

![](/images/16702184438592093.webp)

26
Jump in the discussion.

No email address required.

it's funny because doing it this way meant that part 2 was instant : just gotta remove the flip

matlab (:gigachad2:)

A = readlines("input.txt","EmptyLineRule","skip")';

N = (strlength(A(1))+1)/4;
Stacks = strings(1,N);

i = 1;
x = char(A(1));
while isempty(intersect(x,'1'))
    c = x(2:4:end-1);
    for j = 1:N
        if c(j)~=' '
            Stacks(j) = c(j) + Stacks(j);
        end
    end

    i = i+1;
    x = char(A(i));
end

Stacks1 = cellstr(Stacks);
Stacks2 = cellstr(Stacks);
for l = A(i+1:end)
    u = sscanf(l,'move %d from %d to %d');
       
    Stacks1{u(3)} = [Stacks1{u(3)} flip(Stacks1{u(2)}(end-u(1)+1:end))];
    Stacks1{u(2)}(end-u(1)+1:end) = ''; 

    Stacks2{u(3)} = [Stacks2{u(3)} Stacks2{u(2)}(end-u(1)+1:end)];
    Stacks2{u(2)}(end-u(1)+1:end) = ''; 
end

res1 = cellfun(@(x) x(end),Stacks1);
res2 = cellfun(@(x) x(end),Stacks2);

fprintf("Part 1 : %s\n",res1)
fprintf("Part 2 : %s\n",res2)
Jump in the discussion.

No email address required.

@Jinglevann also newlines are borked too,

just gotta remove the flip
matlab (:gigachad2:)

gave just gotta remove the flip matlab (:gigachad2:) both in preview and in the post, had to do double newline for it to work

Jump in the discussion.

No email address required.

Part 2 was kind of stupid. I doubt anyone changed more than 1 or 2 lines of code, there really wasn't much point to it.

Jump in the discussion.

No email address required.



Now playing: Da Banana Bunch (DK64).mp3

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.