--- Day 13: Origami ---

December 13

Listening to: A random smattering of songs that Spotify's Algorithms think I'll like


A folding puzzle! This looks interesting.

It looks like they garuntee that there will be no dots along the folds, which will make this fairly simple. For everything AFTER a fold, the new row would be the fold row minus that dot's row, and that will be the new row. There's a few potentially tricky things with it, but starting with the naive assumption usually works, the edge cases don't tend to happen.

if (dir == "x") {
    // Step 1: Move Marks
    for (int y = 0; y < paper.size(); y++)
    for (int x = 0; x < cols-foldAt; x++)
        if (paper[y][foldAt+x])
            paper[y][foldAt-x] = true;

    // Step 2: Remove folded rows
    for (int y = 0; y < paper.size(); y++)
        paper[y].erase(paper[y].begin()+foldAt, paper[y].end());
} else if (dir == "y") {
    // Step 1: Move marks
    for (int y = 0; y < rows-foldAt; y++)
    for (int x = 0; x < paper[y].size(); x++)
        if (paper[foldAt+y][x])
            paper[foldAt-y][x] = true;

    // Step 2: Remove folded rows
    paper.erase(paper.begin()+foldAt, paper.end());
}

Ugh. My friend finished today's stuff super fast, but I keep getting caught up with mixing up X and Y, because the coordinates are just... off for me today? I don't know why.

Anyway, this crashed after three folds and I don't know why, but it still did the first fold correctly! I feel like my code is extremely ugly though...


It looks like for part two, I need to fold all of the paper and print it out. I still need to figure out why it crashed, but it prints out and everything just fine. It did the initial output properly.

... and it took two seconds to figure out. I was referencing the initial paper size the whole time, not the current size.

if (dir == "x") {
    // Step 1: Move Marks
    for (int y = 0; y < paper.size(); y++)

Just that small change.... ugh... at least I got it pretty quickly


My solutions for today's puzzles