Skip to main content
minor update
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
_=>(g=(s,ax,b=ay=x,c=az=x,k=bk=y)=>k--?g(s.add(a+[x+[,by,c]z]),k%4?cz:-cz,ax,by,k):s)(g(new Set,55),0,34,89) 

Try it online!Try it online!

_ => ( // main function ignoring its argument g = ( // g is a helper function taking: s, // s = output set ax, // ax = 1st valuecoordinate by = ax, // by = 2nd valuecoordinate, or ax by default cz = ax, // cz = 3rd valuecoordinate, or ax by default k = by // k = counter, initialized to by ) => // k-- ? // if k is not 0 (decrement afterwards): g( // do a recursive call: s.add( // add to the set: ax + [, by, c]z] // a stringified version of the triplet ), // k % 4 ? cz // rotate by putting cz at the beginning : - cz, // or -cz if k is a multiple of 4 ax, by, // followed by ax and by k // pass the updated counter ) // end of recursive call : // else: s // stop and return the set )( // g(new Set, 55), // first call with ax = by = cz = 55 0, 34, 89 // second call with a =(x, 0y, bz) = 34(0, c =34, 89) ) // 

-5 bytes by using \$\phi\approx 89/55\$, as suggested by alephalpha
-3 bytes by scaling everything up (x55), as suggested by xnor

_=>(g=(s,a,b=a,c=a,k=b)=>k--?g(s.add(a+[,b,c]),k%4?c:-c,a,b,k):s)(g(new Set,55),0,34,89) 

Try it online!

_ => ( // main function ignoring its argument g = ( // g is a helper function taking: s, // s = set a, // a = 1st value b = a, // b = 2nd value, or a by default c = a, // c = 3rd value, or a by default k = b // k = counter, initialized to b ) => // k-- ? // if k is not 0 (decrement afterwards): g( // do a recursive call: s.add( // add to the set: a + [, b, c] // a stringified version of the triplet ), // k % 4 ? c // rotate by putting c at the beginning : - c, // or -c if k is a multiple of 4 a, b, // followed by a and b k // pass the updated counter ) // end of recursive call : // else: s // stop and return the set )( // g(new Set, 55), // first call with a = b = c = 55 0, 34, 89 // second call with a = 0, b = 34, c = 89 ) // 

-5 bytes by using \$\phi\approx 89/55\$, as suggested by alephalpha
-3 bytes by scaling everything (x55), as suggested by xnor

_=>(g=(s,x,y=x,z=x,k=y)=>k--?g(s.add(x+[,y,z]),k%4?z:-z,x,y,k):s)(g(new Set,55),0,34,89) 

Try it online!

_ => ( // main function ignoring its argument g = ( // g is a helper function taking: s, // s = output set x, // x = 1st coordinate y = x, // y = 2nd coordinate, or x by default z = x, // z = 3rd coordinate, or x by default k = y // k = counter, initialized to y ) => // k-- ? // if k is not 0 (decrement afterwards): g( // do a recursive call: s.add( // add to the set: x + [, y, z] // a stringified version of the triplet ), // k % 4 ? z // rotate by putting z at the beginning : - z, // or -z if k is a multiple of 4 x, y, // followed by x and y k // pass the updated counter ) // end of recursive call : // else: s // stop and return the set )( // g(new Set, 55), // first call with x = y = z = 55 0, 34, 89 // second call with (x, y, z) = (0, 34, 89) ) // 

-5 bytes by using \$\phi\approx 89/55\$, as suggested by alephalpha
-3 bytes by scaling everything up (x55), as suggested by xnor

added a commented version
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

Commented

_ => ( // main function ignoring its argument g = ( // g is a helper function taking: s, // s = set a, // a = 1st value b = a, // b = 2nd value, or a by default c = a, // c = 3rd value, or a by default k = b // k = counter, initialized to b ) => // k-- ? // if k is not 0 (decrement afterwards): g( // do a recursive call: s.add( // add to the set: a + [, b, c] // a stringified version of the triplet ), // k % 4 ? c // rotate by putting c at the beginning : - c, // or -c if k is a multiple of 4 a, b, // followed by a and b k // pass the updated counter ) // end of recursive call : // else: s // stop and return the set )( // g(new Set, 55), // first call with a = b = c = 55 0, 34, 89 // second call with a = 0, b = 34, c = 89 ) // 
ZZ YY XX NNNN | | | \__/ | | | | | | | +--> number of triplets | | +------> x | +---------> y +------------> z 
ZZ YY XX NNNN | | | \__/ | | | | | | | +--> number of triplets | | +------> x | +---------> y +------------> z 
ZZ YY XX NNNN | | | \__/ | | | | | | | +--> number of triplets | | +------> x | +---------> y +------------> z 

Commented

_ => ( // main function ignoring its argument g = ( // g is a helper function taking: s, // s = set a, // a = 1st value b = a, // b = 2nd value, or a by default c = a, // c = 3rd value, or a by default k = b // k = counter, initialized to b ) => // k-- ? // if k is not 0 (decrement afterwards): g( // do a recursive call: s.add( // add to the set: a + [, b, c] // a stringified version of the triplet ), // k % 4 ? c // rotate by putting c at the beginning : - c, // or -c if k is a multiple of 4 a, b, // followed by a and b k // pass the updated counter ) // end of recursive call : // else: s // stop and return the set )( // g(new Set, 55), // first call with a = b = c = 55 0, 34, 89 // second call with a = 0, b = 34, c = 89 ) // 
ZZ YY XX NNNN | | | \__/ | | | | | | | +--> number of triplets | | +------> x | +---------> y +------------> z 
saved 2 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES6), 9088 bytes

Returns a set of strings, where each string is a triplet x,y,z.

This version takes inspiration from xnor's approach.

_=>(s=new Set,g=(s,a,b=a,c=a,k=20k=b)=>k--?g(s.add(a+[,b,c]),k%4?c:-c,a,b,k,s.add(a+[,b,c])):s)(g(new Set,55),0,34,89)&&g(55) 

Try it online!Try it online!


JavaScript (V8), 108 bytes

-5 bytes by using \$\phi\approx 89/55\$, as suggested by alephalpha
-3 bytes by scaling everything (x55), as suggested by xnor

A full program printing 20 triplets x,y,z.

[344,900,564,228].map(g=n=>n--&15&&g(n,j=0,print([4,6,8].map(i=>[0,55,89,34][v=n>>i&3]*(v&&n>>j++&1||-1))))) 

Try it online!

Encoding

We use the Cartesian coordinates based on the golden ration as described on Wikipedia, but with a different scale.

Each triplet pattern is encoded with the following bit mask:

ZZ YY XX NNNN | | | \__/ | | | | | | | +--> number of triplets | | +------> x | +---------> y +------------> z 

where \$x\$, \$y\$ and \$z\$ are indices in the lookup array \$[0,1,\phi,\frac{1}{\phi}]\$.

This gives:

Triplet pattern x y z N Bit mask As decimal
\$(\pm 1,\pm 1,\pm 1)\$ 1 1 1 8 01 01 01 1000 344
\$(0,\pm\phi,\pm\frac{1}{\phi})\$ 0 2 3 4 11 10 00 0100 900
\$(\pm\frac{1}{\phi},0,\pm\phi)\$ 3 0 2 4 10 00 11 0100 564
\$(\pm\phi,\pm\frac{1}{\phi},0)\$ 2 3 0 4 00 11 10 0100 228

JavaScript (ES6), 90 bytes

Returns a set of strings, where each string is a triplet x,y,z.

This version takes inspiration from xnor's approach.

_=>(s=new Set,g=(a,b=a,c=a,k=20)=>k--?g(k%4?c:-c,a,b,k,s.add(a+[,b,c])):s)(0,34,89)&&g(55) 

Try it online!


JavaScript (V8), 108 bytes

-5 bytes by using \$\phi\approx 89/55\$, as suggested by alephalpha
-3 bytes by scaling everything (x55), as suggested by xnor

A full program printing 20 triplets x,y,z.

[344,900,564,228].map(g=n=>n--&15&&g(n,j=0,print([4,6,8].map(i=>[0,55,89,34][v=n>>i&3]*(v&&n>>j++&1||-1))))) 

Try it online!

Encoding

We use the Cartesian coordinates based on the golden ration as described on Wikipedia, but with a different scale.

Each triplet pattern is encoded with the following bit mask:

ZZ YY XX NNNN | | | \__/ | | | | | | | +--> number of triplets | | +------> x | +---------> y +------------> z 

where \$x\$, \$y\$ and \$z\$ are indices in the lookup array \$[0,1,\phi,\frac{1}{\phi}]\$.

This gives:

Triplet pattern x y z N Bit mask As decimal
\$(\pm 1,\pm 1,\pm 1)\$ 1 1 1 8 01 01 01 1000 344
\$(0,\pm\phi,\pm\frac{1}{\phi})\$ 0 2 3 4 11 10 00 0100 900
\$(\pm\frac{1}{\phi},0,\pm\phi)\$ 3 0 2 4 10 00 11 0100 564
\$(\pm\phi,\pm\frac{1}{\phi},0)\$ 2 3 0 4 00 11 10 0100 228

JavaScript (ES6), 88 bytes

Returns a set of strings, where each string is a triplet x,y,z.

This version takes inspiration from xnor's approach.

_=>(g=(s,a,b=a,c=a,k=b)=>k--?g(s.add(a+[,b,c]),k%4?c:-c,a,b,k):s)(g(new Set,55),0,34,89) 

Try it online!


JavaScript (V8), 108 bytes

-5 bytes by using \$\phi\approx 89/55\$, as suggested by alephalpha
-3 bytes by scaling everything (x55), as suggested by xnor

A full program printing 20 triplets x,y,z.

[344,900,564,228].map(g=n=>n--&15&&g(n,j=0,print([4,6,8].map(i=>[0,55,89,34][v=n>>i&3]*(v&&n>>j++&1||-1))))) 

Try it online!

Encoding

We use the Cartesian coordinates based on the golden ration as described on Wikipedia, but with a different scale.

Each triplet pattern is encoded with the following bit mask:

ZZ YY XX NNNN | | | \__/ | | | | | | | +--> number of triplets | | +------> x | +---------> y +------------> z 

where \$x\$, \$y\$ and \$z\$ are indices in the lookup array \$[0,1,\phi,\frac{1}{\phi}]\$.

This gives:

Triplet pattern x y z N Bit mask As decimal
\$(\pm 1,\pm 1,\pm 1)\$ 1 1 1 8 01 01 01 1000 344
\$(0,\pm\phi,\pm\frac{1}{\phi})\$ 0 2 3 4 11 10 00 0100 900
\$(\pm\frac{1}{\phi},0,\pm\phi)\$ 3 0 2 4 10 00 11 0100 564
\$(\pm\phi,\pm\frac{1}{\phi},0)\$ 2 3 0 4 00 11 10 0100 228
saved 5 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
added a shorter version
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
saved 3 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
saved 1 byte
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
saved 2 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
minor clarification
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
saved 1 byte
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
saved 5 bytes and added an explanation
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
saved 5 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading