Hey everyone, this is a difficult math-related algorithm
that I’ve been trying to get to the bottom of for ages.
It comes straight from a critical project, the code here
is slightly modified for testing.
Using a code-based interface for an 8x8 hardware matrix,
I want to first supply the one dimensional array for
the MIDI noteOn/Off messages within the instantiation
of the two-dimensional lookup using Array2D
.
Simple. This part is a no-brainer.
The difficult part comes next… I want to be able to translate
the 2-dimensional lookup into it’s exact 3-dimensional counterpart.
That’s where I need someone’s help… all the code and the testing
is directly below.
The main advantage of this is working towards a more universal
design scheme… only one line would need to be changed (inside
Array2D
) and everything else would follow suit.
Here’s the code:
(((
this .y_
(
( ) .x_
(
Array2D ( 9 , 9 ) .with
(
( 11 , 21 .. 91 ) +.x ( ..8 )
)
)
)
// y.x [ 0 , 0 ] -> lower left corner / origin
.n_
(
fill3D
(
Array , function:
{
|x , y , z|
var a = 0 ;
var b = 0 ;
(
this.n ??
{
this.n_ ( MultiLevelIdentityDictionary [] ) .n
}
)
. put
(
x , y , z , this.
y.x
[
(a
// a ?
)
,
(b
// b ?
)
]
)
}
, planes: 4 , rows: 4 , cols: 4
// planes represent
// adjacent quadrants
// in the 8x8 matrix
// [ 2 ] [ 3 ]
// [ 0 ] [ 1 ]
)
)
;
~n = // the current implementation... 100% equivalent
(
MultiLevelIdentityDictionary [
]
. putTree
(
0 , [ 0 , [ 0
, y.x[0, 0] , 1
, y.x[0, 1] , 2
, y.x[1, 0] , 3
, y.x[1, 1] ] ] ,
0 , [ 1 , [ 0
, y.x[0, 2] , 1
, y.x[0, 3] , 2
, y.x[1, 2] , 3
, y.x[1, 3] ] ] ,
0 , [ 2 , [ 0
, y.x[2, 0] , 1
, y.x[2, 1] , 2
, y.x[3, 0] , 3
, y.x[3, 1] ] ] ,
0 , [ 3 , [ 0
, y.x[2, 2] , 1
, y.x[2, 3] , 2
, y.x[3, 2] , 3
, y.x[3, 3] ] ] ,
1 , [ 0 , [ 0
, y.x[0, 4] , 1
, y.x[0, 5] , 2
, y.x[1, 4] , 3
, y.x[1, 5] ] ] ,
1 , [ 1 , [ 0
, y.x[0, 6] , 1
, y.x[0, 7] , 2
, y.x[1, 6] , 3
, y.x[1, 7] ] ] ,
1 , [ 2 , [ 0
, y.x[2, 4] , 1
, y.x[2, 5] , 2
, y.x[3, 4] , 3
, y.x[3, 5] ] ] ,
1 , [ 3 , [ 0
, y.x[2, 6] , 1
, y.x[2, 7] , 2
, y.x[3, 6] , 3
, y.x[3, 7] ] ] ,
2 , [ 0 , [ 0
, y.x[4, 0] , 1
, y.x[4, 1] , 2
, y.x[5, 0] , 3
, y.x[5, 1] ] ] ,
2 , [ 1 , [ 0
, y.x[4, 2] , 1
, y.x[4, 3] , 2
, y.x[5, 2] , 3
, y.x[5, 3] ] ] ,
2 , [ 2 , [ 0
, y.x[6, 0] , 1
, y.x[6, 1] , 2
, y.x[7, 0] , 3
, y.x[7, 1] ] ] ,
2 , [ 3 , [ 0
, y.x[6, 2] , 1
, y.x[6, 3] , 2
, y.x[7, 2] , 3
, y.x[7, 3] ] ] ,
3 , [ 0 , [ 0
, y.x[4, 4] , 1
, y.x[4, 5] , 2
, y.x[5, 4] , 3
, y.x[5, 5] ] ] ,
3 , [ 1 , [ 0
, y.x[4, 6] , 1
, y.x[4, 7] , 2
, y.x[5, 6] , 3
, y.x[5, 7] ] ] ,
3 , [ 2 , [ 0
, y.x[6, 4] , 1
, y.x[6, 5] , 2
, y.x[7, 4] , 3
, y.x[7, 5] ] ] ,
3 , [ 3 , [ 0
, y.x[6, 6] , 1
, y.x[6, 7] , 2
, y.x[7, 6] , 3
, y.x[7, 7] ] ]
)
)
;
Post << (toUpper(cs
(
Array.fill3D( 4,4,4,
{ |x y z|
~n[x,y,z] === n[x,y,z]
}
)
.flat // remove the tilde in line 81 to see desired result
.every { |x| x.notNil and: x } //
)
)) << ("!") << $\n // -> TRUE!
)))
?