Skip to main content
4 of 9
deleted 46 characters in body
Level River St
  • 26.7k
  • 4
  • 37
  • 105

Ruby, 126 124 bytes

->n{a=($/+?.*w=n.size*4)*w
a[q=w*w/2]=?2
c=[1,2,3]
n.map{|i|c[j=i/2,2]=c[j+1]*s= ~0**i,-c[j]*s
a[q+=s+j*w*s]="#{c[1]%7}"}
a}

Try it online!

Takes an array of numbers 0,1,2,3 corresponding to E,W,S,N or equivalently x+=1,x-=1, z+=1,z-=1. Outputs the path of the cube traced on a string of w*w periods, where w is four times the length of the input.

The cube is represented as a vector c=[x,y,z] starting at [1,2,3] which rolls in the xz plane. The colour is determined by the current y coordinate. If the cube is rotated 180 degrees, the y coordinate becomes negative, so the possible values are -3,-2,-1,1,2,3 with opposite faces adding to zero. To display, the number is taken mod 7 and this is converted to a character, so the possible displayed colours are 1,2,3,4,5,6

The vector is rotated by 90 degrees by swapping two coordinates and changing the sign of one of them, similar to Arnauld's answer, but where he uses an array, I use the formula c[j,2]=c[j+1]*s,-c[j]*s where c[j,2] is a block of 2 array elements starting at j=0 or 1 and s is the sign of the rotation, +1 or -1.

Commented code

->n{a=($/+?.*w=n.size*4)*w            #make a string of w*w periods separated in lines by /n 
a[q=w*w/2]=?F                         #set q to the centre of the field (padding by the /n characters ensures w*w/2 is central horizontally as well as vertically)
c=[1,2,3]                             #put an F at position q. Set up a vector c for colours x,y,z
n.map{|i|                             #iterate through array of directions. j=1 for vertical, 0 for horizontal. s=1 for increase, -1 for decrease
c[j=i/2,2]=c[j+1]*s= ~0**i,-c[j]*s    #in accordance with value of j, swap c[0]&c[1] or c[1]&c[2] and change the sign of one in accordance with s
a[q+=s+j*w*s]="#{c[1]%7}"}            #modify the value of q by s (horizontal) or (1+w)s (vertical) and save colour%7 at a[q]
a}                                    #return the final string a. 

Ruby, 131 bytes

Version with 2D array is slightly longer due to clumsy 2D array initialization in Ruby.

->n{a=(0..w=n.size*4).map{[0]*w}
c=[1,a[z=x=w/2][x]=2,3]
n.map{|i|c[j=i/2,2]=c[j+1]*s= ~0**i,-c[j]*s
a[z+=s*j][x+=s-s*j]=c[1]%7}
a}

Try it online!

Level River St
  • 26.7k
  • 4
  • 37
  • 105