Drafting 'x' implementation

Lately, I’ve been implementing a refined version of a classic problem-solving technique for every road block I hit in SC… as well as other languages.

This is (to a certain extent) a repost of a (and if somewhat off-topic, deserves an apology) late comment in a fairly recent question / answer thread.

It occured when I realized that the root problem of most threads arises from some form ambiguity or miscommunication involved in the process of explaining one’s true intent or end-game … consequently leading the the thread consist of mostly ‘hit or miss’ attempts, and so upon reading I felt a certain degree of emphasis regarding the relevancy of certain truth of technique… before appearing to be less than epiphanic.

And so, the method and thesis of this post was only recently seen as being in some way axiomatic to nearly all programs and technical forms of relative problem-solving.

It starts by drafting line by line, from start to finish, (in a new file, or a new IDE ‘session’…) and by isolating x as the main object of focus/implement… just as one typically isolates and identifies variables in similar forms of math, science, logic, etc.

// → with return values in comments

I use [x, y, z], without overthinking it, for global variable names… true name selection should always come after functionality

If one doesn’t wish to use x y or z, then one should always use ~environmentVariables, with a key focus on clarity and transparency.

function: vars can’t be evaluated or othereise inspected after execution, and focusing on stlye or aesthetics before achieving functionality may allow itself to become a wasteful extent of time & energy… and so if resources suffer, than so must expression, and so made necessary is the process of converting ~envirVars to function: vars… this process can only be efficient, and focusing on style choices after satisfying a necessary level of functional implementation, can only serve to enhance one’s level or degree of expressiveness.

[k, v] represents key → value pairs clearly

Iteration can be done using [x, n], while traditional alternatives consist of [i, j], or explicit declaration of [item, index], however… one may consider deeper levels of iteration, and the convention of always using single letter argument names, so that one may infinitely iterate by formatting the syntax to reflect the current level of depth, as in: xx, nn, xxx, nnn, xxxx, nnnn etc.

… and furthermore, a coded demonstration:

explaining difficult problems in 1-3 line premise
or showing one’s intent using pure code if one is able to, for the sake of clarity, e.g:
"transform matrix access from ~grid[y][x] to invert access using ~grid[x][y]

// the following demonstrates a rough version of solution drafting
// the level of verbosity may seem explicit in certain places
// i.e. if one is only in the initial phase self solutiion drafting,
// however, these notations offer a certain sense of clarity,
// involving the accurate & concise comprehension of questions
// posted to these forum threads or elsewhere

x = (36…99) // midi note #'s

x = x.reshape(8, 8) // 8x8, 64 pad matrix


x[0][0] // → 36 (bottom left corner)
x[7][7] // → 99 (top right corner)

x[0][1] // → 37 (one pad to the right of 36)
x[7][6] // → 98 (one pad to the left of 99)

// technically, this usage is ~grid.at(y).at(x), or ~grid[y][x]
// though we access first using the index of which ‘horizontal’ row,
// the first @ value, in this case, represents:
// “which row” or “which row, how high” or “which amount of vertical shift”…
// meaning: it is actually the ‘y’ value entered first, not the ‘x’
// current access is implemented using ~grid.at(y).at(x)
// ? is: how to implement so one may use ~grid[x][y] or x[x][y]
// so that:

x[0][1] // ? → should be 44 and NOT 37
x[0][7] // ? → should be 92 and NOT 43

// so far…

x = x.collect{ |x, n| x = x.select{ |xx, nn| (nn % 8) === n } } // works, but too complex…

Does anyone know of a better way?

Hopefully this technique helps someone here… it mostly involves working backwards from how the solution should look… then exploring options and/or posting any further ?s to the forum list.

…and in case anyone must know:

example SOLUTION:

x = (36..99).reshape(8, 8).flop // → inverts rows and columns in an array-of-arrays

…and also

x = Array2D.fromArray(8, 8, (36..99).reshape(8, 8).flop.flatten) // → usage is now x[x, y]