| Bytes | Lang | Time | Link |
|---|---|---|---|
| 040 | JavaScript V8 | 250313T230156Z | Lucenapo |
| 048 | JavaScript Node.js | 250330T043732Z | Andrew B |
| 068 | Maple | 250314T160046Z | dharr |
| 050 | JavaScript ES6 | 250313T135646Z | Arnauld |
| 031 | Ruby | 250315T215251Z | Level Ri |
| 037 | Zsh | 250314T085119Z | roblogic |
| 035 | Python | 250313T223305Z | xnor |
| 036 | Ruby | 250313T185501Z | Level Ri |
| nan | Python 3 | 250314T200213Z | 3RR0R404 |
| 011 | Jelly | 250313T173851Z | Jonathan |
| 046 | Bash | 250314T144314Z | fast eth |
| 016 | Charcoal | 250313T171439Z | Neil |
| 021 | J | 250313T183951Z | m90 |
| 020 | Uiua 0.15.0dev.2 | 250313T134508Z | Tbw |
JavaScript (Node.js), 50 48 bytes
t=>[18,2,3,5,3,20,7,6,2,K=14,7,2].map(x=>K+=7*x)
Starting point was Arnauld's diagram. I played around with the numbers so that they were all divisible by 7. Sorted the numbers and generated differences which are small values. Then used the map function to do a reduce type operation, which is a lot shorter when using map instead of reduce.
Maple, 68 bytes
proc(p)w:=[0,p[1],add(p)];w,7-~w end~(combinat:-permute([1,2,4],2));
Outputs [[0,1,3],[7,6,4],[0,1,5],[7,6,2],[0,2,3],[7,5,4],[0,2,6],[7,5,1],[0,4,5],[7,3,2],[0,4,6],[7,3,1]]
Calculates the vertices, based on the following observation. Starting from the binary coordinates [0,0,0] we find the 6 triangles including this vertex have binary coordinates [0,0,0], [0,0,0] with 1 bit flipped, and [0,0,0] with that bit and also a second bit flipped, e.g., [0,0,0],[0,1,0],[0,1,1]. Thinking in bit-reversed order, we can get these by 0, add 1, add 1 and add 4 or triangle [0,1,5].
The other 6 triangles can be obtained by subtracting each vertex from 7 (corresponding to the triangles including coordinates [1,1,1], and just flipping all bits), e.g., [0,1,5] becomes [7,6,2].
Ungolfed version:
u:=combinat:-permute([1,2,4],2); # gives [[1,2],[1,4],[2,1],[2,4],[4,1],[4,2]];
q:=proc(p) # takes one of above, e.g., [1,4]
w:=[0,p[1],add(p)]; # w := [0, 0+1, 0+1+4] = [0,1,5]
x:=7-~w; # x := [7-0, 7-1, 7-5] = [7,6,2]
w,x # output both
end;
q~(u); # map q over u
Probably I should have abandoned the algorithmic approach for one using predefined vertices; after all just writing the output takes only 48 bytes. But the question does instruct us to "generate" the indices :-). Maple is not very efficient with bit manipulations so I avoided them here, but the bit manipulations might be more efficient in another language.
JavaScript (ES6), 50 bytes
Returns a list of 12 triplets.
f=n=>n>11?[]:[[x=~~n%6+1,3*x%7,n>5?7:0],...f(-~n)]
Triangles
This generates the following triangles:
JavaScript (ES6), 41 bytes
This version is inspired by xnor's approach, but uses multiples of \$21\$ ordered from lowest to highest and delta-encoded.
Returns a list of 12 integers.
t=>[..."551225222631"].map(n=>t=~~t+n*21)
Ruby, 31 bytes
"64RWkh".bytes{|i|p i+50,i+550}
A semi-hardcoded solution using conversion of characters to their ascii codes. Prints six 3-digit decimal numbers corresponding to triangles containing the vertex 1, intercalated with six numbers corresponding to triangles containing the opposing vertex 6. Cube unfolding shown below.
0--2--6
| /| /|
|/ |/ |
1--3--7--6
| /| /|
|/ |/ |
1--5--4--6
| /| /|
|/ |/ |
1--0--2
Zsh, 41 37 bytes
for i (13 26 32 45 51 64)<<<"0$i
7$i"
Generates the list found by Arnauld.
-2 bytes, thanks to @Neil
-2 bytes, replaced \\n with actual newline
Python, 35 bytes
for c in b"+NQ<B-3HYm":print(c*7)
Outputs the triangles hardcoded as three-digit numbers.
301
203
546
567
420
462
315
357
105
504
623
763
The bytestring holds numbers from 0 to 127 encoded as ASCII characters, of which two are unprintable. We multiply each value by 7 to reach more three-digit numbers. Fortunately, multiples of 7 suffice to represent each triangle, because there's enough choices in splitting each face and ordering each triangle's vertices.
34 bytes as object method producing a list (or 29 if just the list is allowed, thanks to @globglogabgalab)
[c*7for c in b"+NQ<B-3HYm"].copy
Ruby, 36 bytes
As noted by GB a port of the approach used by Arnauld and Lucenaposition is shorter than my original answer.
12.times{|i|p [i/6*7,k=1+i%6,k*3%7]}
Ruby, 38 bytes
My original answer, which was posted before Lucenaposition and shorter than Arnauld's at the time of posting. It's also nicely algorithmic.
j=2
12.times{|i|p [j,j^=4>>i%3,i/6*7]}
The triangles are per the unfolded cube net below. For the last point in each of the 12 triangles, we output 6 points with polar vertex 0 then 6 points with polar vertex 7.
For the other two points in the triangle we go round 6 vertices of the equator twice, changing one bit per iteration. on each iteration we output the before and after points, which are the other two vertices of our triangle.
1--3--7
| /| /|
|/ |/ |
0--2--6--7
| /| /|
|/ |/ |
0--4--5--7
| /| /|
|/ |/ |
0--1--3
Python 3, actually calculated 59/104 bytes
104 bytes (for 1 digit n), can do any number of dimensions:
n=3
R=range
for i in R(2**n):bin(i).count('1')%2or print(*[(i,i^2**j,i^2**k)for k in R(n)for j in R(k)])
59 bytes, 3 dimensions only:
for i in 0,3,5,6:print((i,i^1,i^2),(i,i^1,i^4),(i,i^2,i^4))
we take the triangles "rooted" (with corner opposite hypotenuse) in corners whose bitsum is even. this guarantees we cover the whole shape without overlap (in any number of dimensions)
to move along any given axis we just bitwise xor with a power of 2 corresponding to it
Jelly, 16 11 bytes
“Ɠæ,ṖG’b8ṡ3
A niladic Link that yields a list of the twelve triples.
See the order visually on Desmos.
How?
“Ɠæ,ṖG’b8ṡ3 - Link: no arguments
“Ɠæ,ṖG’ - 578487238572
b8 - convert to base eight
-> [1,0,3,2,6,0,4,1,5,3,7,6,5,4]
ṡ3 - overlapping slices of length three
I also had a search to see if I could use a fourteen-letter word from Jelly's dictionary for something like this for 10 bytes:
“¬Ṛṡ»O%8ṡ3 - Link: no arguments
“¬Ṛṡ» - "hydrocephaloid"
O - ordinals -> [104,121,100,114,111,99,101,112,104,97,108,111,105,100]
%9 - mod 9 -> [5,4,1,6,3,0,2,4,5,7,0,3,6,1]
ṡ3 - overlapping slices of length three
That was the only list I could find that had two of each of six of the values \$[0,7]\$ (using %8, %9, %⁵ (\$10\$), and %⁴ (\$16\$)) and one each of the other two such that all slices of five are composed of five different values, but it still doesn't have all the properties it needs to make it produce a valid triangle walk. There are some others like this using thirteen-letter words with a leading space, like " contraception" (“ı2ġ») with %8, but none of those are valid either.
Bash, 46 bytes
echo 03{1,2} 27{3,6} 06{2,4} 05{1,4} 47{6,5} 17{5,3}
Explanation: I followed Arnauld's diagram . For each cube's face in the diagram, I took the diagonal drawn there, and the two remaining vertices of that face.
I admit, there is nothing smart in this solution. Instead of actually using code to generate the solution, I use code to merely output a pre-computed "paper-based" solution.
Charcoal, 26 16 bytes
F⁶E07⁺κ⭆²﹪X³⁺ιμ⁷
Try it online! Link is to verbose version of code. Explanation: Now uses @Lucenaposition's observation that the equator is the powers of 3 modulo 7.
F⁶ Loop `6` times and print
07 Literal string `07`
E Map over characters
² Literal integer `2`
⭆ Map over implicit range
³ Literal integer `3`
X Raised to power
ι Outer value
⁺ Plus
μ Inner value
﹪ Modulo
⁷ Literal integer `7`
⁺ Concatenated to
κ Current character
J, 21 bytes
'31204153726475'[\~3:
Produces all 12 triangles from one strip (taking every 3 consecutive digits from the string).
[ is the identity function; \ is used to apply it to infixes of equal length; ~ swaps arguments – this rearrangement is to allow the whole thing to be a verb (which ignores its argument) rather than a constant value.
Uiua 0.15.0-dev.2, 20 bytes SBCS
°⋯♭₃≡⊞↻¤⇡3⋯⊂+4.⧈∘3⇡4
A full program that outputs an 12×3 array. I bet there is some more clever arithmetic way to do this.
Explanation
♭₂°⋯≡⊞↻¤⇡3⋯⊂+4.⧈∘3⇡4
⇡4 # 0_1_2_3
⧈∘3 # 3-size windows: [0_1_2 1_2_3]
⊂+4. # join with that array plus 4, top and bottom faces
⋯ # to binary
≡⊞↻¤⇡3 # on each row, construct the table of all three rotations of its rows
°⋯ # from binary
♭₂ # flatten into rank 2 array
