# [Ruby], 128 bytes <!-- language-all: lang-ruby --> ->n{a=($/+?.*w=n.size*4)*w a[q=w*w/2]=?F c=[1,2,3] n.map{|i|c[j=i/2,2]=c[j+1]*s= ~0**i,-c[j]*s a[q+=s+i/2*w*s]=(68+c[1]).chr} a} [Try it online!][TIO-le0qq54p] [Ruby]: https://www.ruby-lang.org/ [TIO-le0qq54p]: https://tio.run/##TYzNCsIwEITveYoePLSbNP0T8bL25kuEPcSiWMFSG0vQtr56TKVgGQZmPobp@tPLXdDFh2bQGG4SXkqw2EhTv8@wjcAyrR5owSY5YXlkFapM5KIg1si7boexHit1wzrJhR/4yDMCg8EnBahF7IGv8wdHw/0KLBjCcLfnlcooktW1m5ieXNs/TXBRKhWLiNif5eLnFZtJseqFWETkvg "Ruby – 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, 68 (ascii `D`) is added to the value then this is converted to a character, so the possible displayed colours are `A,B,C,E,F,G` 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. # [Ruby], 131 bytes Version with 2D array is slightly longer due to clumsy 2D array initialization in Ruby, and `%7` used to make all colours positive. <!-- language-all: lang-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!][TIO-le0qhmga] [Ruby]: https://www.ruby-lang.org/ [TIO-le0qhmga]: https://tio.run/##dYzBCoMwDIbvfQovg63WWutgp@xFSg6dTKgwkXVSp3av3lVxhx3kJ@RPvvx59rd3qCFk13bScBScO2i5NeOdnk/8obtJCaTOkwpUwbQaYQCXS1QDgmQlknY9ms1cqQZMLplEiDYtkFpIPoJSw7K4iCOJ8RQsbWI69mxx8bbAw8UT7UOtlGCbEH9/u8R40vUvS1Yu2Vo7fKHlDivZpn8evg "Ruby – Try It Online"