Problem:
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net.    As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures. Input In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of ' E ', ' N ', ' S ' and ' W ' representing four directions shown in the above figures. Output Print the integer which appears on the top face after the simulation. Constraints  $0 \leq $ the integer assigned to a face $ \leq 100$  $0 \leq $ the length of the command $\leq 100$  Sample Input 1 1 2 4 8 16 32
SE Sample Output 1 8 You are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face labeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction S and then to the direction E , you can see 8 on the top face. Sample Input 2 1 2 4 8 16 32
EESWN Sample Output 2 32

Solution (Python):



class dice():
    def __init__(self, arr):
        self.top = arr[0]
        self.south = arr[1]
        self.east = arr[2]
        self.west = arr[3]
        self.north = arr[4]
        self.bottom = arr[5]

    def rotate(self, ope):
        if ope == 'S':
            self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top
        elif ope == 'N':
            self.top, self.south, self.bottom, self.north = self.south, self.bottom, self.north, self.top
        elif ope == 'E':
            self.top, self.west, self.bottom, self.east = self.west, self.bottom, self.east, self.top
        elif ope == 'W':
            self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top

dc = dice([int(x) for x in input().split(' ')])
opes = list(input())

for op in opes:
    dc.rotate(op)

print(dc.top)

Solution (Python):
class Saikoro:

    def sai(self,one,two,three,four,five,six):
        self.s1=int(one)
        self.s2=int(two)
        self.s3=int(three)
        self.s4=int(four)
        self.s5=int(five)
        self.s6=int(six)

    def turnE(self):
        e=[self.s4,self.s2,self.s1,self.s6,self.s5,self.s3]
        self.s1=e[0]
        self.s2=e[1]
        self.s3=e[2]
        self.s4=e[3]
        self.s5=e[4]
        self.s6=e[5]

    def turnN(self):
        n=[self.s2,self.s6,self.s3,self.s4,self.s1,self.s5]
        self.s1=n[0]
        self.s2=n[1]
        self.s3=n[2]
        self.s4=n[3]
        self.s5=n[4]
        self.s6=n[5]

    def turnS(self):
        s=[self.s5,self.s1,self.s3,self.s4,self.s6,self.s2]
        self.s1=s[0]
        self.s2=s[1]
        self.s3=s[2]
        self.s4=s[3]
        self.s5=s[4]
        self.s6=s[5]

    def turnW(self):
        w=[self.s3,self.s2,self.s6,self.s1,self.s5,self.s4]
        self.s1=w[0]
        self.s2=w[1]
        self.s3=w[2]
        self.s4=w[3]
        self.s5=w[4]
        self.s6=w[5]




l=input().split()
m=list(input())

sai1=Saikoro()
sai1.sai(l[0],l[1],l[2],l[3],l[4],l[5])

n=len(m)
i=0

while i<n:
    if m[i]=="E":
        sai1.turnE()
    elif m[i]=="N":
        sai1.turnN()
    elif m[i]=="S":
        sai1.turnS()
    else:
        sai1.turnW()
    i+=1
print(sai1.s1)

Solution (Python):
n1,n2,n3,n4,n5,n6=map(int,raw_input().split())
act=raw_input()
for i in act:
    if i=="N":
        n11=n1
        n1=n2
        n2=n6
        n6=n5
        n5=n11
    elif i=="S":
        n11=n1
        n1=n5
        n5=n6
        n6=n2
        n2=n11
    elif i=="E":
        n11=n1
        n1=n4
        n4=n6
        n6=n3
        n3=n11
    else :
        n11=n1
        n1=n3
        n3=n6
        n6=n4
        n4=n11
print(n1)

Solution (Python):
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.t=t
        self.f=f
        self.r=r
        self.l=l
        self.b=b
        self.u=u
    def roll(self,i):
        if d=='S':
            key=self.t
            self.t=self.b
            self.b=self.u
            self.u=self.f
            self.f=key
        elif d=='E':
            key=self.t
            self.t=self.l
            self.l=self.u
            self.u=self.r
            self.r=key
        elif d=='N':
            key=self.t
            self.t=self.f
            self.f=self.u
            self.u=self.b
            self.b=key
        else:
            key=self.t
            self.t=self.r
            self.r=self.u
            self.u=self.l
            self.l=key
t,f,r,l,b,u=map(int,input().split())
a=list(input())
dice=Dice(t,f,r,l,b,u)
for d in a:
    dice.roll(d)
print(dice.t)

Solution (Python):
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.a=[t,f,r,l,b,u]
        self.direct={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3)}
    def roll(self,d):
        self.a=[self.a[i] for i in self.direct[d]]
        self.t = self.a[0]
        self.f = self.a[1]
        self.r = self.a[2]
        self.l = self.a[3]
        self.b = self.a[4]
        self.u = self.a[5]
t,f,r,l,b,u=map(int,input().split())
dice=Dice(t,f,r,l,b,u)
for d in input():
    dice.roll(d)
print(dice.t)

Solution (Python):
class Dice:
    def __init__(self):
        self.eye = {}
        for k, v in zip(['top', 'front', 'right', 'left', 'back', 'bottom'], input().split()):
            self.eye[k] = int(v)


    def roll(self, dir):
        self.dir = dir
        if self.dir == 'E':
            w = self.eye['top']
            self.eye['top'] = self.eye['left']
            self.eye['left'] = self.eye['bottom']
            self.eye['bottom'] = self.eye['right']
            self.eye['right'] = w
        elif self.dir == 'S':
            w = self.eye['top']
            self.eye['top'] = self.eye['back']
            self.eye['back'] = self.eye['bottom']
            self.eye['bottom'] = self.eye['front']
            self.eye['front'] = w
        elif self.dir == 'W':
            w = self.eye['top']
            self.eye['top'] = self.eye['right']
            self.eye['right'] = self.eye['bottom']
            self.eye['bottom'] = self.eye['left']
            self.eye['left'] = w
        elif self.dir == 'N':
            w = self.eye['top']
            self.eye['top'] = self.eye['front']
            self.eye['front'] = self.eye['bottom']
            self.eye['bottom'] = self.eye['back']
            self.eye['back'] = w


dice = Dice()
for dir in input():
    dice.roll(dir)
print(dice.eye['top'])

Solution (Python):




def intinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

class dice:
    def __init__(self):
        self.data = [0 for i in range(8)]
        a = intinput()
        for i in range(1, 7): self.data[i] = a[i - 1]  
        for i in range(6): self.data[0] += a[i]  
        self.data[7] = a[0] * a[5] + a[1] * a[4] + a[2] * a[3]  
        
        

    def d_read(self, a):
        
        b = []
        for i in range(len(a)): b.append(self.data[a[i]])
        return b

    def d_write(self, b, c):
        
        if len(b) != len(c): return     
        for i in range(len(b)): self.data[c[i]] = b[i]

    def roll(self, direction):
        
        
        if direction == 'S':
            self.d_write(self.d_read([5, 1, 2, 6]), [1, 2, 6, 5])
            
        elif direction == 'N':
            self.d_write(self.d_read([2, 6, 5, 1]), [1, 2, 6, 5])
            
        elif direction == 'W':
            self.d_write(self.d_read([3, 6, 4, 1]), [1, 3, 6, 4])
            
        elif direction == 'E':
            self.d_write(self.d_read([4, 1, 3, 6]), [1, 3, 6, 4])

    def get_upper(self):
        return self.data[1]

def main():
    d = dice()
    command = input()
    for i in range(len(command)):
        d.roll(command[i])
    print(d.get_upper())

if __name__ == "__main__":
    main()

Solution (Python):
class Dice:
    def __init__(self):
        self.side = {"top": 0, "front": 0, "right": 0, "left": 0, "back": 0, "bottom": 0}

    def roll(self, direction):
        self.direction = direction
        if self.direction == "N":
            w = self.side["top"]
            self.side["top"] = self.side["front"]
            self.side["front"] = self.side["bottom"]
            self.side["bottom"] = self.side["back"]
            self.side["back"] = w
        elif self.direction == "S":
            w = self.side["top"]
            self.side["top"] = self.side["back"]
            self.side["back"] = self.side["bottom"]
            self.side["bottom"] = self.side["front"]
            self.side["front"] = w
        elif self.direction == "E":
            w = self.side["top"]
            self.side["top"] = self.side["left"]
            self.side["left"] = self.side["bottom"]
            self.side["bottom"] = self.side["right"]
            self.side["right"] = w
        elif self.direction == "W":
            w = self.side["top"]
            self.side["top"] = self.side["right"]
            self.side["right"] = self.side["bottom"]
            self.side["bottom"] = self.side["left"]
            self.side["left"] = w

dice = Dice()
for s, n in zip(dice.side, input().split()):
    dice.side[s] = n

for direction in input():
    dice.roll(direction)
print(dice.side["top"])

Solution (Python):
class Dice():
    def __init__(self, numbers):
        self.top = numbers[0]
        self.s = numbers[1]
        self.e = numbers[2]
        self.w = numbers[3]
        self.n = numbers[4]
        self.bot = numbers[5]
    def rot(self, dir):
        top, s, e, w, n, bot = (self.top, self.s, self.e, self.w, self.n, self.bot)
        if dir == 'N':
            self.top = s
            self.s = bot
            self.e = e
            self.w = w
            self.n = top
            self.bot = n
        elif dir == 'S':
            self.top = n
            self.s = top
            self.e = e
            self.w = w
            self.n = bot
            self.bot = s
        elif dir == 'E':
            self.top = w
            self.s = s
            self.e = top
            self.w = bot
            self.n = n
            self.bot = e
        elif dir == 'W':
            self.top = e
            self.s = s
            self.e = bot
            self.w = top
            self.n = n
            self.bot = w
    def getTop(self):
        return self.top

li = list(map(int, input().split()))
D = Dice(li)
command = input()
for dir in command:
    D.rot(dir)
print(D.getTop())

Solution (Python):

class Dice:

	top = 0
	south = 1
	east = 2
	west = 3
	north = 4
	bottom = 5

	def __init__(self, faces):
		self.faces = faces

	def roll(self, direction):

		top_ = self.top
		south_ = self.south
		east_ = self.east
		west_ = self.west
		north_ = self.north
		bottom_ = self.bottom

		if direction == 'E':
			self.top = west_
			self.east = top_
			self.bottom = east_
			self.west = bottom_
		elif direction == 'N':
			self.top = south_
			self.south = bottom_
			self.bottom = north_
			self.north = top_
		elif direction == 'S':
			self.top = north_
			self.south = top_
			self.bottom = south_
			self.north = bottom_
		elif direction == 'W':
			self.top = east_
			self.east = bottom_
			self.bottom = west_
			self.west = top_
		else:
			return

	def get_top(self):
		return faces[self.top]

faces = list(map(int, input().split()))
directions = str(input())

dice = Dice(faces)

for direction in directions:
	dice.roll(direction)

print(dice.get_top())

Solution (Python):
class Dice(object):

    def __init__(self, n):
        self.n = n
    def move(self, to):
        if to == 'N':
            self.n[0], self.n[1], self.n[4], self.n[5] = self.n[1], self.n[5], self.n[0], self.n[4]
        elif to == 'E':
            self.n[0], self.n[2], self.n[3], self.n[5] = self.n[3], self.n[0], self.n[5], self.n[2]
        elif to == 'S':
            self.n[0], self.n[1], self.n[4], self.n[5] = self.n[4], self.n[0], self.n[5], self.n[1]
        elif to == 'W':
            self.n[0], self.n[2], self.n[3], self.n[5] = self.n[2], self.n[5], self.n[0], self.n[3]
    def top(self):
        return self.n[0]

dice = Dice([int(i) for i in input().split()])
move = input()
for m in move:
    dice.move(m)
print(dice.top())

Solution (Python):
class dice:
    def __init__(self):
        self.d = list(map(int, input().split()))
        self.dir = list(input())
        
    def move(self):
        up = [0,1,2,3] 
        for a in self.dir:
            if a == "E":
                up = [0, 7-up[3], up[2], up[1]]
            elif a == "W":
                up = [0, up[3], up[2], 7-up[1]]
            elif a == "N":
                up = [0, up[2], 7-up[1], up[3]]
            else:
                up = [0, 7-up[2], up[1], up[3]]
        print(self.d[up[1]-1])
ob = dice()
ob.move()

Solution (Python):
dice = {'N':(2, 6, 3, 4, 1, 5),'E':(4, 2, 1, 6, 5, 3),'W':(3, 2, 6, 1, 5, 4),'S':(5, 1, 3, 4, 6, 2)}
num = input().split()
for alf in input():
    num = [num[i-1]for i in dice[alf]]
print(num[0])

Solution (Python):


class Dice:
    def __init__(self, a1, a2, a3, a4, a5, a6):
        
        self.v = [a5, a1, a2, a6] 
        self.h = [a4, a1, a3, a6] 
        

    
    def top(self):
        return self.v[1]

    
    def north(self):
        newV = [self.v[1], self.v[2], self.v[3], self.v[0]]
        self.v = newV
        self.h[1] = self.v[1]
        self.h[3] = self.v[3]
        return self.v, self.h

    
    def south(self):
        newV = [self.v[3], self.v[0], self.v[1], self.v[2]]
        self.v = newV
        self.h[1] = self.v[1]
        self.h[3] = self.v[3]
        return self.v, self.h

    
    def east(self):
        newH = [self.h[3], self.h[0], self.h[1], self.h[2]]
        self.h = newH
        self.v[1] = self.h[1]
        self.v[3] = self.h[3]
        return self.v, self.h

    
    def west(self):
        newH = [self.h[1], self.h[2], self.h[3], self.h[0]]
        self.h = newH
        self.v[1] = self.h[1]
        self.v[3] = self.h[3]
        return self.v, self.h


d = input().rstrip().split()
dice1 = Dice(d[0], d[1], d[2], d[3], d[4], d[5])

command = list(input().rstrip())


for i, a in enumerate(command):
    if a == 'N':
        dice1.north()
    elif a == 'S':
        dice1.south()
    elif a == 'E':
        dice1.east()
    elif a == 'W':
        dice1.west()
print(dice1.top())

Solution (Python):
class Dice:
    
    def __init__(self, val):
        self.top = val[0]
        self.flat1 = val[3]
        self.flat2 = val[1]
        self.flat3 = val[2]
        self.flat4 = val[4]
        self.bottom = val[5]
        
    def doSouth(self):
        temp = self.bottom
        self.bottom = self.flat2
        self.flat2 = self.top
        self.top = self.flat4
        self.flat4 = temp

    def doNorth(self):
        temp = self.bottom
        self.bottom = self.flat4
        self.flat4 = self.top
        self.top = self.flat2
        self.flat2 = temp

    def doWest(self):
        temp = self.top
        self.top = self.flat3
        self.flat3 = self.bottom
        self.bottom = self.flat1
        self.flat1 = temp


    def doEast(self):
        temp = self.top
        self.top = self.flat1
        self.flat1 = self.bottom
        self.bottom = self.flat3
        self.flat3 = temp
    
    def doget(self):
        list = [self.top, self.flat2, self.flat3, self.flat1, self.flat4, self.bottom]
        return(list)

def transform(dice, motion):
    if motion == 'S':
        dice.doSouth()
    elif motion == 'N':
        dice.doNorth()
    elif motion == 'W':
        dice.doWest()
    elif motion == 'E':
        dice.doEast()

N = input().split()
dice = Dice(N)
motion = input()
for i in range(len(motion)):
    transform(dice, motion[i])
print(dice.top)

Solution (Python):
class Dice:
    def __init__(self,numbers):
        self.surface=numbers

    def roll_E(self):
        self.surface[0],self.surface[2],self.surface[3],self.surface[5]=self.surface[3],self.surface[0],self.surface[5],self.surface[2]
    def roll_N(self):
        self.surface[0],self.surface[1],self.surface[4],self.surface[5]=self.surface[1],self.surface[5],self.surface[0],self.surface[4]
    def roll_S(self):
        self.surface[0],self.surface[1],self.surface[4],self.surface[5]=self.surface[4],self.surface[0],self.surface[5],self.surface[1]
    def roll_W(self):
        self.surface[0],self.surface[2],self.surface[3],self.surface[5]=self.surface[2],self.surface[5],self.surface[0],self.surface[3]
    def result(self):
        return self.surface[0]

dice=Dice(input().split())
orders=input()
for i in orders:
    if i=='E':
        dice.roll_E()
    if i=='N':
        dice.roll_N()
    if i=='S':
        dice.roll_S()
    if i=='W':
        dice.roll_W()
print(int(dice.result()))

Solution (Python):
class diceClass:
	def __init__(self, valuelist):
		self.valuelist = valuelist
		self.t = valuelist[0]
		self.b = valuelist[5]
		self.n = valuelist[4]
		self.s = valuelist[1]
		self.e = valuelist[2]
		self.w = valuelist[3]

	def throw(self, direction):
		
		if direction == 'N':
			self.t, self.s, self.b, self.n = self.s, self.b, self.n, self.t
		elif direction == 'S':
			self.t, self.s, self.b, self.n = self.n, self.t, self.s, self.b
		elif direction == 'W':
			self.t, self.e, self.b, self.w = self.e, self.b, self.w, self.t
		elif direction == 'E':
			self.t, self.e, self.b, self.w = self.w, self.t, self.e, self.b


arrinput = list(map(int, input().split()))
dirinput = input()
dice = diceClass(arrinput)
for s in dirinput:
	dice.throw(s)
print(dice.t)

Solution (Python):
def Nroll(list):
	a = [list[1],list[5],list[2],list[3],list[0],list[4]]
	return a
def Wroll(list):
	a = [list[2],list[1],list[5],list[0],list[4],list[3]]
	return a
dice = list(map(int,input().split()))
roll = str(input())
pos = [0,1,2,3,4,5]
for i in roll:
	if i == "N":
		pos = Nroll(pos)
	elif i == "S":
		pos = Nroll(Nroll(Nroll(pos)))
	elif i == "W":
		pos = Wroll(pos)
	else:
		pos = Wroll(Wroll(Wroll(pos)))
print(dice[pos[0]])

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
x=input()
for i in range(len(x)):
    if x[i]=="S":
        a,b,c,d,e,f=e,a,c,d,f,b
    if x[i]=="E":
        a,b,c,d,e,f=d,b,a,f,e,c
    if x[i]=="N":
        a,b,c,d,e,f=b,f,c,d,a,e
    if x[i]=="W":
        a,b,c,d,e,f=c,b,f,a,e,d
print(a)

Solution (Python):
d1=[0 for i in range(6)]
d1[:]=(int(x) for x in input().split())
t1=[0 for i in range(6)]
order=input()
for i in range(len(order)):
  if order[i]=='N':
    t1[0]=d1[1]
    t1[1]=d1[5]
    t1[2]=d1[2]
    t1[3]=d1[3]
    t1[4]=d1[0]
    t1[5]=d1[4]
  if order[i]=='S':
    t1[0]=d1[4]
    t1[1]=d1[0]
    t1[2]=d1[2]
    t1[3]=d1[3]
    t1[4]=d1[5]
    t1[5]=d1[1]
  if order[i]=='E':
    t1[0]=d1[3]
    t1[1]=d1[1]
    t1[2]=d1[0]
    t1[3]=d1[5]
    t1[4]=d1[4]
    t1[5]=d1[2]
  if order[i]=='W':
    t1[0]=d1[2]
    t1[1]=d1[1]
    t1[2]=d1[5]
    t1[3]=d1[0]
    t1[4]=d1[4]
    t1[5]=d1[3]
  
  d1=list(t1)

print(d1[0])

Solution (Python):
class Dice:
    def __init__(self):
        self.dice=[i for i in range(6)]
        self.workspace=[i for i in range(6)]
        self.top=self.dice=[0]
    
    def set(self,numbers):
        self.dice=[i for i in numbers]
        self.workspace=[i for i in numbers]
        
    def rotate(self,command):
        if command == "W":
            self.workspace=[self.dice[2], self.dice[1], self.dice[5], self.dice[0], self.dice[4], self.dice[3]]
            self.dice=self.workspace
        elif command == "E":
            self.workspace=[self.dice[3], self.dice[1], self.dice[0], self.dice[5], self.dice[4], self.dice[2]]
            self.dice = self.workspace
        
        if command == "S":
            self.workspace=[self.dice[4], self.dice[0], self.dice[2], self.dice[3], self.dice[5], self.dice[1]]
            self.dice=self.workspace
        elif command == "N":
            self.workspace=[self.dice[1], self.dice[5], self.dice[2], self.dice[3], self.dice[0], self.dice[4]]
            self.dice=self.workspace
            
    def get_top(self):
        self.top=self.dice[0]
        print(self.top)
        
    def debug(self,numbers):
        print(numbers)
    
        
numbers=list(map(int,input().split()))
dice=Dice()
dice.set(numbers)
commands=input()
for i in range(len(commands)):
      dice.rotate(commands[i])
dice.get_top()

Solution (Python):
class Dice():
    
    def __init__(self, labels):
        self.__pip = labels
        
    def get_top(self):
        return self.__pip[0]
        
    def roll_e(self): 
        self.__pip[0], self.__pip[3], self.__pip[5], self.__pip[2] = \
            self.__pip[3], self.__pip[5], self.__pip[2], self.__pip[0]
            
    def roll_n(self): 
        self.__pip[0], self.__pip[1], self.__pip[5], self.__pip[4] = \
            self.__pip[1], self.__pip[5], self.__pip[4], self.__pip[0]
            
    def roll_s(self): 
        self.__pip[0], self.__pip[4], self.__pip[5], self.__pip[1] = \
            self.__pip[4], self.__pip[5], self.__pip[1], self.__pip[0]
    
    def roll_w(self): 
        self.__pip[0], self.__pip[2], self.__pip[5], self.__pip[3] = \
            self.__pip[2], self.__pip[5], self.__pip[3], self.__pip[0]
    
    def roll_dice(self, command):
        if command == 'E':
            self.roll_e()
        elif command == 'N':
            self.roll_n()
        elif command == 'S':
            self.roll_s()
        else:
            self.roll_w()


def main():
    dice = Dice(list(input().split()))
    commands = input()
    for i in commands:
        dice.roll_dice(i)
    print(dice.get_top())
    
    
if __name__ == "__main__":
    main()

Solution (Python):
class Dice:
    def __init__(self,s1,s2,s3,s4,s5,s6):
        self.s1 = s1
        self.s2= s2
        self.s3= s3
        self.s4= s4
        self.s5 = s5
        self.s6= s6
    def east(self):
        prev_s1 = self.s1           
        prev_s3 = self.s3
        prev_s4 = self.s4
        prev_s6 = self.s6
        self.s1 = prev_s4
        self.s3 = prev_s1
        self.s4 = prev_s6
        self.s6 = prev_s3
    def west(self):
        prev_s1 = self.s1
        prev_s3 = self.s3
        prev_s4 = self.s4
        prev_s6 = self.s6
        self.s1 = prev_s3
        self.s3 = prev_s6
        self.s4 = prev_s1
        self.s6 = prev_s4
    def south(self):
        prev_s1 = self.s1
        prev_s2 = self.s2
        prev_s5 = self.s5
        prev_s6 = self.s6
        self.s1 = prev_s5
        self.s2 = prev_s1
        self.s5 = prev_s6
        self.s6 = prev_s2
    def north(self):
        prev_s1 = self.s1
        prev_s2 = self.s2
        prev_s5 = self.s5
        prev_s6 = self.s6
        self.s1 = prev_s2
        self.s2 = prev_s6
        self.s5 = prev_s1
        self.s6 = prev_s5
    def top(self):
        return self.s1
s1,s2,s3,s4,s5,s6 = map(int,input().split())
dice = Dice(s1,s2,s3,s4,s5,s6)
order = input()
for c in order:
    if c =='N':
        dice.north()
    elif c =='S':
        dice.south()
    elif c =='E':
        dice.east()
    elif c == 'W':
        dice.west()
print(dice.top())

Solution (Python):
N = list(map(int,input().split()))
S = list(input())
for i in S:
    if i == "E":
        N[0],N[2],N[3],N[5] = N[3],N[0],N[5],N[2]
    elif i == "W":
        N[3],N[0],N[5],N[2] = N[0],N[2],N[3],N[5]
    elif i == "S":
        N[0],N[1],N[4],N[5] = N[4],N[0],N[5],N[1]
    else:
        N[4],N[0],N[5],N[1] = N[0],N[1],N[4],N[5]
print(N[0])

Solution (Python):
class Dice:
    def __init__(self,dim=list(range(1,7))):
        self.dim = dim

    def roll(self,direction):
        if direction == "N":
            buff = self.dim[0]
            self.dim[0] = self.dim[1]
            self.dim[1] = self.dim[5]
            self.dim[5] = self.dim[4]
            self.dim[4] = buff

        if direction == "E":
            buff = self.dim[3]
            self.dim[3] = self.dim[5]
            self.dim[5] = self.dim[2]
            self.dim[2] = self.dim[0]
            self.dim[0] = buff

        if direction == "W":
            buff = self.dim[0]
            self.dim[0] = self.dim[2]
            self.dim[2] = self.dim[5]
            self.dim[5] = self.dim[3]
            self.dim[3] = buff

        if direction == "S":
            buff = self.dim[0]
            self.dim[0] = self.dim[4]
            self.dim[4] = self.dim[5]
            self.dim[5] = self.dim[1]
            self.dim[1] = buff

lst = list(map(int,input().split()))

D = Dice(lst)
code = input()
for i in code:
    D.roll(i)

print(D.dim[0])

Solution (Python):
class dice:
    def __init__(self, X):
        self.x = [0] * 6
        self.x[0] = X[0]
        self.x[1] = X[1]
        self.x[2] = X[2]
        self.x[3] = X[3]
        self.x[4] = X[4]
        self.x[5] = X[5]

    def roll(self, d):
        if d == 'S':
            self.x[0], self.x[1], self.x[2], self.x[3], self.x[4], self.x[5] = \
            self.x[4], self.x[0], self.x[2], self.x[3], self.x[5], self.x[1]
        elif d == 'E':
            self.x[0], self.x[1], self.x[2], self.x[3], self.x[4], self.x[5] = \
            self.x[3], self.x[1], self.x[0], self.x[5], self.x[4], self.x[2]
        elif d == 'W':
            self.x[0], self.x[1], self.x[2], self.x[3], self.x[4], self.x[5] = \
            self.x[2], self.x[1], self.x[5], self.x[0], self.x[4], self.x[3]
        elif d == 'N':
            self.x[0], self.x[1], self.x[2], self.x[3], self.x[4], self.x[5] = \
            self.x[1], self.x[5], self.x[2], self.x[3], self.x[0], self.x[4]

X = list(map(int, input().split()))
directions = list(input())
d_one = dice(X)
for dist in directions:
    d_one.roll(dist)
print(d_one.x[0])

Solution (Python):
class Dice():
    def __init__(self, numbers):
        self.numbers = numbers
        S = [1, 5, 2, 3, 0, 4]
        N = [4, 0, 2, 3, 5, 1]
        W = [3, 1, 0, 5, 4, 2]
        E = [2, 1, 5, 0, 4, 3]
        self.tumble = {'S': S, 'N': N, 'W': W, 'E': E}
        
    def rol(self, command):
        prev = self.numbers.copy()
        for i, t in enumerate(self.tumble[command]):
            self.numbers[t] = prev[i]

numbers = list(map(int, input().split()))
commands = input()

dice = Dice(numbers)
for c in commands:
    dice.rol(c)
print(dice.numbers[0])

Solution (Python):
class Dice:
  
  def __init__(self, input_dice):
    self.flow = [input_dice[3], input_dice[1], input_dice[0], input_dice[5], input_dice[2], input_dice[4]]
    self.dice = [i for i in range(6)]
  
  def setNumber(self, n0, n1, n2, n3, n4, n5):
    self.dice[0] = n0
    self.dice[1] = n1
    self.dice[2] = n2
    self.dice[3] = n3
    self.dice[4] = n4
    self.dice[5] = n5
    return self.dice
    
  def roll(self, dir):
    if dir == 'S':
      self.setNumber(self.flow[0], self.flow[2], self.flow[5], self.flow[1], self.flow[4], self.flow[3])
      self.flow = self.dice
      return self.dice
    if dir == 'N':
      self.setNumber(self.flow[0], self.flow[3], self.flow[1], self.flow[5], self.flow[4], self.flow[2])
      self.flow = self.dice
      return self.dice
    if dir == 'W':
      self.setNumber(self.flow[2], self.flow[1], self.flow[4], self.flow[0], self.flow[3], self.flow[5])
      self.flow = self.dice
      return self.dice
    if dir == 'E':
      self.setNumber(self.flow[3], self.flow[1], self.flow[0], self.flow[4], self.flow[2], self.flow[5])
      self.flow = self.dice
      return self.dice

dice = list(map(int, input().split()))
d = Dice(dice)
dir = list(input())
for i in range(len(dir)):
  d.roll(dir[i])
print(d.dice[2])

Solution (Python):
def dice():
    dnum = list(map(int,input().split()))
    up = dnum[0]
    un = dnum[5]
    ri = dnum[2]
    le = dnum[3]
    fr = dnum[1]
    ba = dnum[4]
    tmp = int(0)
    tmp2 = int(0)
    ordertmp = input()
    order = list(ordertmp)
    
    for x in order :
        if (x == "S"):
            tmp = fr
            tmp2 = un
            fr = up
            up = ba
            un = tmp
            ba = tmp2

        elif (x == "N"):
            tmp = un
            tmp2 = up
            up = fr
            un = ba
            fr = tmp
            ba = tmp2

        elif (x == "E"):
            tmp = up
            tmp2 = un
            up = le
            un = ri
            ri = tmp
            le = tmp2

        elif (x == "W"):
            tmp = un
            tmp2 = up
            up = ri
            un = le
            ri = tmp
            le = tmp2
    print(up)

dice()

Solution (Python):
class Dice:
    def __init__(self, list):
        self.list = list  
    def roll_n(self):
        self.list = [self.list[1], self.list[5], self.list[2], self.list[3], self.list[0], self.list[4]]
    def roll_s(self):
        self.list = [self.list[4], self.list[0], self.list[2], self.list[3], self.list[5], self.list[1]]
    def roll_e(self):
        self.list = [self.list[3], self.list[1], self.list[0], self.list[5], self.list[4], self.list[2]]
    def roll_w(self):
        self.list = [self.list[2], self.list[1], self.list[5], self.list[0], self.list[4], self.list[3]]
    def print0(self):
        print(self.list[0])


list = list(map(int, input().split()))
direct = input()
instance = Dice(list)
for i in direct:
    if i == 'N':
        instance.roll_n()
    if i == 'S':
        instance.roll_s()
    if i == 'E':
        instance.roll_e()
    if i == 'W':
        instance.roll_w()
instance.print0()

Solution (Python):
d = list(map(int, input().split()))
op = list(input())

for o in op:
    b = [x for x in d]
    if o == "S":
        b[0] = d[4]
        b[1] = d[0]
        b[4] = d[5]
        b[5] = d[1]
    elif o == "E":
        b[0] = d[3]
        b[2] = d[0]
        b[3] = d[5]
        b[5] = d[2]
    elif o == "W":
        b[0] = d[2]
        b[2] = d[5]
        b[3] = d[0]
        b[5] = d[3]
    elif o == "N":
        b[0] = d[1]
        b[1] = d[5]
        b[4] = d[0]
        b[5] = d[4]
    for i in range(6):
        d[i] = b[i]

print(d[0])

Solution (Python):
def f(list,num):
    if list=="E":
        num[0],num[2],num[5],num[3] =num[3],num[0],num[2],num[5]
    elif list=="W":
        num[0],num[2],num[5],num[3] =num[2],num[5],num[3],num[0]
    elif list=="N":
        num[0],num[1],num[5],num[4]=num[1],num[5],num[4],num[0]
    else:
        num[0],num[1],num[5],num[4]=num[4],num[0],num[1],num[5]
L=list(map(int,input().split()))
A=list(str(input()))
for i in range(len(A)):
  f(A[i],L)
print(L[0])