Home

2024

Worklog

LETSGO Game

Unreasonably Useful: Pen & Paper

Unreasonably Useful: Pen & Paper

Date
November 26, 2024
Hours
0.75
Tags
UnrealCodeC++LETSGO

Didn’t end up writing much code this session. Just a one liner type fix:

This was surprisingly hard to catch. I was assigning a float to this int in a switch statement, but the debugger just straight up skipped the line where it was assigning the wrong value type.

No errs or crash, just kept being 0. Cool.

Easy enough fix though.

The rest of the session was trying to untangle a bit more of a complex problem.

I have the following bit of code:

		BeatStrength = TMap<int, float>();
		
		// For zero based arrays, an even number will resolve to the stronger beat of a larger scale degree
		// 16th note [8] resolves to the 8th note [4] resolves to the quarter note [2]
		// 16th note [6] resolves to the 8th note [3] which does not resolve to the quarter note
		// So we recursively modulus check if note is even, increasing strength value each time its divisible
		// This fills our BeatStrengths
		for (int b = 0; b < Beats; b++)
		{
			const float Base = 0.25f;
			float Strength = Base;
			int Beat = b;
			while(Beat % 2 != 0)
			{
				Strength += Base;
				Beat /= 2;
			}
			BeatStrength.Add(b, Strength); 
			// Intended results
			// [ 0.75, 0.25, 0.5, 0.25, 0.75, 0.25, 0.5, 0.25 ] 16 beat strength array
			
			// Actual results
			// [ 0.25, 0.5, 0.25, 0.75 ]
		}

There’s a couple problems with this approach- specifically that the logic is inverted:

The weakest beat is getting the higher values.

The frustrating part is that it feels like it’s kind of on the right track?

I hate those leetcode programming puzzles, and this feels like one of those.

So I’ve turned to an old, but surprisingly useful tool: pen & paper:

image

First off, moleskin large grid layout? Objectively the best. That’s not an opinion, it’s straight fact.

I like grid paper for these kinds of things because it allows you rearrange the same data in different ways, ensuring the rows/columns stay aligned.

I can’t tell you how many times I’ve stumbled on a solution because I noticed useful patterns on the grid.

I didn’t find the solution today. But tomorrow I’ll have more time to rearrange the data until some eureka moment triggers.