--- Day 10: CRTs ---

December 10

Listening to: Justice


Okay. Yeah sure. I'll just make a replacement CRT in the middle of a jungle. Great.


I mean... this seems kinda arbitrarily simple? It's a 2-instruction instruction set, with one register. And it's just kind of... checking the state in some arbitrary way. Odd.

int Check_Cycles[7] = {20, 60, 100, 140, 180, 220, INT_MAX};
while (!input.eof())
{
    getline(input, line);
    clock++;

    if (clock >= Check_Cycles[i]) signalSums += (X * Check_Cycles[i++]);       

    switch (line[0])
    {
        case 'a': //addx
            clock++;
            
            if (clock >= Check_Cycles[i]) signalSums += (X * Check_Cycles[i++]);

            X += stoi(line.substr(5));
            break;
        
        case 'n': // noop
            break;
    }
}

I didn't like how I had to repeat that signal sums check, but with the clock cycle summing rules laid out, there wansn't quite an elegant way to do it, at least, not that I found.


It's a odd one-row kind of renderer? Not that different from an (Atari 2600)[https://www.wired.com/2009/03/racing-the-beam/], basically just syncing the CPU to the scanlines. Er. "Scanlines".

I could do something fancy, with holding memroy or something, but... I could just print out to the console what currently needs to be drawn. The CRT wouldn't have 'memory', just the phosphors. Fire and forget.

Either way, it was a smiple change to get it to work. Remove all of the summing stuff, and replace the clock increments with the following, and it just... worked.

void drawPoint()
{
    int pos = c++ % ROW_SIZE;

    if (pos == 0) cout << endl; // New row, newline

    char outchar = abs(pos-X) > 1 ? '.' : '#';
    cout << outchar;
}

Time taken: 45 minutes

My solutions for today's puzzles