This seems correct. I did an example with different d values to show that they still construct the same square. I think this may be the ticket in
This math is really convenient computer-wise, because integer division [ex 11//2 = 5, 14//3 = 4] by 8 is just chopping off the last 3 bits, and seeing anything mod 8 is just looking at the last 3 bits. Looking at the last three bits would be the same as doing an AND operation with 7, which is a holy number, coincidences don't exist.
So You do all this stuff and basically each triangle ends up being:
(n-1)//8 + (f-1)//8 + (nn)//8 + (2d-1)(n-1)//8 + 1
I'm thinking that you start off and you get these values
(n-1)%8
(f-1)%8
(2d-1)*(n-1)%8
nn%8
and then follow some type of recipe or something to generate the square
The values are:
(e,n) = (1,1)
1, 5, 13, 25, 41,..
which are the sums of consecutive squares.
(1+0 = 1) (1+4=5) (4+9=13) (9+16=25)..
(e,n) = (2,1)
1, 3, 9, 19, 33,..
are sums of the same square plus one
1 = 0+0+1, 3 = 1+1+1, 9 = 4+4+1, 19 = 9+9+1, 33 = 16+16+1.
(3,1)
2,6,14,26,42
sum of consecutive squares plus one.
(4,1)
2,4,10,20,34,
sums of the same square plus two.
A(e,1,t) =
if(e even):
shift = e/2
2tt + shift
if(e odd):
shift = (e-1)/2
t*t + (t+1)(t+1) + shift