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(object):
    """docstring for Dice"""
    def __init__(self, numeric_column):
        self.numeric_column=numeric_column
    def roll_to_S_direction(self):
        self.numeric_column=[self.numeric_column[4],self.numeric_column[0],self.numeric_column[2],self.numeric_column[3],self.numeric_column[5],self.numeric_column[1]]
    def roll_to_N_direction(self):
        self.numeric_column=[self.numeric_column[1],self.numeric_column[5],self.numeric_column[2],self.numeric_column[3],self.numeric_column[0],self.numeric_column[4]]
    def roll_to_E_direction(self):
        self.numeric_column=[self.numeric_column[3],self.numeric_column[1],self.numeric_column[0],self.numeric_column[5],self.numeric_column[4],self.numeric_column[2]]
    def roll_to_W_direction(self):
        self.numeric_column=[self.numeric_column[2],self.numeric_column[1],self.numeric_column[5],self.numeric_column[0],self.numeric_column[4],self.numeric_column[3]]

dice=Dice(map(int,raw_input().split()))
direction=raw_input()
for i in direction:
    if i=='S': dice.roll_to_S_direction()
    elif i=='N': dice.roll_to_N_direction()
    elif i=='E': dice.roll_to_E_direction()
    else: dice.roll_to_W_direction()
print dice.numeric_column[0]

Solution (Python):
class Dice(object):
	def __init__(self,List):
		self.face=List
	
	def n_spin(self,List):
		temp=List[0]
		List[0]=List[1]
		List[1]=List[5]
		List[5]=List[4]
		List[4]=temp

	def s_spin(self,List):
		temp=List[0]
		List[0]=List[4]
		List[4]=List[5]
		List[5]=List[1]
		List[1]=temp

	def e_spin(self,List):
		temp=List[0]
		List[0]=List[3]
		List[3]=List[5]
		List[5]=List[2]
		List[2]=temp

	def w_spin(self,List):
		temp=List[0]
		List[0]=List[2]
		List[2]=List[5]
		List[5]=List[3]
		List[3]=temp

dice = Dice(map(int,raw_input().split()))
command = list(raw_input())
for k in command:
	if k=='N':
		dice.n_spin(dice.face)
	elif k=='S':
		dice.s_spin(dice.face)
	elif k=='E':
		dice.e_spin(dice.face)
	else:
		dice.w_spin(dice.face)
print dice.face[0]

Solution (Python):
class Dice:
    def __init__(self, num_list):
        self.vertical_faces = [num_list[0], num_list[1], num_list[5], num_list[4]]
        self.horizonal_faces = [num_list[0], num_list[3], num_list[5], num_list[2]]

    def roll(self, direction):
        if direction == 'N':
            self.vertical_faces = self.vertical_faces[1:] + self.vertical_faces[:1]
            self.horizonal_faces[0] = self.vertical_faces[0]
            self.horizonal_faces[2] = self.vertical_faces[2]
        elif direction == 'S':
            self.vertical_faces = self.vertical_faces[3:] + self.vertical_faces[:3]
            self.horizonal_faces[0] = self.vertical_faces[0]
            self.horizonal_faces[2] = self.vertical_faces[2]
        elif direction == 'E':
            self.horizonal_faces = self.horizonal_faces[1:] + self.horizonal_faces[:1]
            self.vertical_faces[0] = self.horizonal_faces[0]
            self.vertical_faces[2] = self.horizonal_faces[2]
        else:
            self.horizonal_faces = self.horizonal_faces[3:] + self.horizonal_faces[:3]
            self.vertical_faces[0] = self.horizonal_faces[0]
            self.vertical_faces[2] = self.horizonal_faces[2]

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

dice = Dice(num_list)

directions = input()

for i in directions:
    dice.roll(i)

print(dice.vertical_faces[0])

Solution (Python):
class Dice:
    def __init__(self, num_list):
        self.vertical_faces = [num_list[0], num_list[1], num_list[5], num_list[4]]
        self.horizonal_faces = [num_list[0], num_list[3], num_list[5], num_list[2]]

    def roll(self, direction):
        if direction == 'N':
            self.vertical_faces = self.vertical_faces[1:] + self.vertical_faces[:1]
            self.horizonal_faces[0] = self.vertical_faces[0]
            self.horizonal_faces[2] = self.vertical_faces[2]
        elif direction == 'S':
            self.vertical_faces = self.vertical_faces[3:] + self.vertical_faces[:3]
            self.horizonal_faces[0] = self.vertical_faces[0]
            self.horizonal_faces[2] = self.vertical_faces[2]
        elif direction == 'E':
            self.horizonal_faces = self.horizonal_faces[1:] + self.horizonal_faces[:1]
            self.vertical_faces[0] = self.horizonal_faces[0]
            self.vertical_faces[2] = self.horizonal_faces[2]
        else:
            self.horizonal_faces = self.horizonal_faces[3:] + self.horizonal_faces[:3]
            self.vertical_faces[0] = self.horizonal_faces[0]
            self.vertical_faces[2] = self.horizonal_faces[2]

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

dice = Dice(num_list)

directions = input()

for i in directions:
    dice.roll(i)

print(dice.vertical_faces[0])

Solution (Python):
class Dice:
    def __init__(self, face_vals):
        self.faces = dict(zip(['top', 'south', 'east',
                               'west', 'north', 'bottom'], face_vals))

    def roll(self, direction):
        if direction == 'N':
            self.faces['top'], self.faces['south'], self.faces['bottom'], \
            self.faces['north'] = self.faces['south'], self.faces['bottom'], \
            self.faces['north'], self.faces['top']
        elif direction == 'S':
            self.faces['top'], self.faces['south'], self.faces['bottom'], \
            self.faces['north'] = self.faces['north'], self.faces['top'], \
            self.faces['south'], self.faces['bottom']
        elif direction == 'E':
            self.faces['top'], self.faces['east'], self.faces['bottom'], \
            self.faces['west'] = self.faces['west'], self.faces['top'], \
            self.faces['east'], self.faces['bottom']
        else:
            self.faces['top'], self.faces['east'], self.faces['bottom'], \
            self.faces['west'] = self.faces['east'], self.faces['bottom'], \
            self.faces['west'], self.faces['top']


face_vals = input().split()

dice = Dice(face_vals)

for i in input():
    dice.roll(i)

print(dice.faces['top'])

Solution (Python):
class Dice:
    def __init__(self, face_vals):
        self.faces = dict(zip(['top', 'front', 'right',
                               'left', 'back', 'bottom'], face_vals))

    def roll(self, direction):
        if direction == 'N':
            self.faces['top'], self.faces['front'], self.faces['bottom'], \
            self.faces['back'] = self.faces['front'], self.faces['bottom'], \
            self.faces['back'], self.faces['top']
        elif direction == 'S':
            self.faces['top'], self.faces['front'], self.faces['bottom'], \
            self.faces['back'] = self.faces['back'], self.faces['top'], \
            self.faces['front'], self.faces['bottom']
        elif direction == 'E':
            self.faces['top'], self.faces['right'], self.faces['bottom'], \
            self.faces['left'] = self.faces['left'], self.faces['top'], \
            self.faces['right'], self.faces['bottom']
        else:
            self.faces['top'], self.faces['right'], self.faces['bottom'], \
            self.faces['left'] = self.faces['right'], self.faces['bottom'], \
            self.faces['left'], self.faces['top']


face_vals = input().split()

dice = Dice(face_vals)

for i in input():
    dice.roll(i)

print(dice.faces['top'])

Solution (Python):
class diceClass:
    label = []
    def __init__(self,l):
        if len(l) == 6:
            self.label = l
    def move(self,c):
        if c.upper() == 'N':
            buf = []
            buf.append(self.label[1])
            buf.append(self.label[5])
            buf.append(self.label[2])
            buf.append(self.label[3])
            buf.append(self.label[0])
            buf.append(self.label[4])
            self.label = buf
        elif c.upper() == 'E':
            buf = []
            buf.append(self.label[3])
            buf.append(self.label[1])
            buf.append(self.label[0])
            buf.append(self.label[5])
            buf.append(self.label[4])
            buf.append(self.label[2])
            self.label = buf
        elif c.upper() == 'W':
            buf = []
            buf.append(self.label[2])
            buf.append(self.label[1])
            buf.append(self.label[5])
            buf.append(self.label[0])
            buf.append(self.label[4])
            buf.append(self.label[3])
            self.label = buf
        elif c.upper() == 'S':
            buf = []
            buf.append(self.label[4])
            buf.append(self.label[0])
            buf.append(self.label[2])
            buf.append(self.label[3])
            buf.append(self.label[5])
            buf.append(self.label[1])
            self.label = buf
    def get_label(self):
        return self.label[0]
in_line = raw_input().split()
dice = diceClass(in_line)
move = raw_input()
for c in move:
    dice.move(c)
print dice.get_label()

Solution (Python):
class Dice(object):
    def __init__(self, top, south, east, west, north, bottom):
        self.top = top
        self.south = south
        self.east = east
        self.west = west
        self.north = north
        self.bottom = bottom

    def get_top(self):
        return self.top

    def rotate(self, directions):
        for direction in directions:
            if direction == 'S':
                self.prev_top = self.top
                self.top = self.north
                self.north = self.bottom
                self.bottom = self.south
                self.south = self.prev_top
            elif direction == 'E':
                self.prev_top = self.top
                self.top = self.west
                self.west = self.bottom
                self.bottom = self.east
                self.east = self.prev_top
            elif direction == 'W':
                self.prev_top = self.top
                self.top = self.east
                self.east = self.bottom
                self.bottom = self.west
                self.west = self.prev_top
            elif direction == 'N':
                self.prev_top = self.top
                self.top = self.south
                self.south = self.bottom
                self.bottom = self.north
                self.north = self.prev_top

dice = Dice(*map(int, input().split()))
dice.rotate(input())
print(dice.get_top())

Solution (Python):



rolls = raw_input().split()
order = raw_input().strip()
nsrolls = [rolls[0],rolls[1],rolls[5],rolls[4]]
werolls = [rolls[0],rolls[2],rolls[5],rolls[3]]
while True:
    if order == "":
        break
    o = order[0]
    if o=="N":
        tmp = nsrolls[0]
        nsrolls.pop(0)
        nsrolls.append(tmp)
        werolls[0]=nsrolls[0]
        werolls[2]=nsrolls[2]
    elif o=="S":
        tmp = nsrolls[-1]
        nsrolls.pop(-1)
        nsrolls.insert(0,tmp)
        werolls[0]=nsrolls[0]
        werolls[2]=nsrolls[2]
    elif o=="W":
        tmp = werolls[0]
        werolls.pop(0)
        werolls.append(tmp)
        nsrolls[0]=werolls[0]
        nsrolls[2]=werolls[2]
    elif o=="E":
        tmp = werolls[-1]
        werolls.pop(-1)
        werolls.insert(0,tmp)
        nsrolls[0]=werolls[0]
        nsrolls[2]=werolls[2]
    else:
        print "invalid order"
    order = order[1:]
print nsrolls[0]

Solution (Python):
def north(d):
    d[0], d[1], d[5], d[4] = d[1], d[5], d[4], d[0]


def west(d):
    d[0], d[2], d[5], d[3] = d[2], d[5], d[3], d[0]


def east(d):
    d[0], d[3], d[5], d[2] = d[3], d[5], d[2], d[0]


def south(d):
    d[0], d[4], d[5], d[1] = d[4], d[5], d[1], d[0]


F = {'N': north, 'W': west, 'E': east, 'S': south}

d, os = list(map(int, input().split())), input()

for o in os:
    F[o](d)

print(d[0])

Solution (Python):
class Dice(object):
  def __init__(self, List):
    self.face = List

  def n_spin(self, List):
    temp = List[0]
    List[0] = List[1]
    List[1] = List[5]
    List[5] = List[4]
    List[4] = temp

  def s_spin(self, List):
    temp = List[0]
    List[0] = List[4]
    List[4] = List[5]
    List[5] = List[1]
    List[1] = temp

  def e_spin(self, List):
    temp = List[0]
    List[0] = List[3]
    List[3] = List[5]
    List[5] = List[2]
    List[2] = temp

  def w_spin(self, List):
    temp = List[0]
    List[0] = List[2]
    List[2] = List[5]
    List[5] = List[3]
    List[3] = temp

dice = Dice(map(int, raw_input().split()))
command = list(raw_input())
for c in command:
  if c == "N":
    dice.n_spin(dice.face)
  elif c == "S":
    dice.s_spin(dice.face)
  elif c == "E":
    dice.e_spin(dice.face)
  elif c == "W":
    dice.w_spin(dice.face)

print dice.face[0]

Solution (Python):
import copy

class Dice:
    def __init__(self, numbers):
        self.dd = dict(zip(['U', 'S', 'E', 'W', 'N', 'B'], numbers))

    def next(self, o):
        old = copy.deepcopy(self.dd)
        if o == 'E':
            self.dd['B'] = old['E']
            self.dd['U'] = old['W']
            self.dd['E'] = old['U']
            self.dd['W'] = old['B']
        elif o == 'S':
            self.dd['B'] = old['S']
            self.dd['U'] = old['N']
            self.dd['S'] = old['U']
            self.dd['N'] = old['B']
        elif o == 'W':
            self.dd['B'] = old['W']
            self.dd['U'] = old['E']
            self.dd['E'] = old['B']
            self.dd['W'] = old['U']
        elif o == 'N':
            self.dd['B'] = old['N']
            self.dd['U'] = old['S']
            self.dd['S'] = old['B']
            self.dd['N'] = old['U']

dn = [int(n) for n in input().split()]
op = input()
ad = Dice(dn)

for o in op:
    ad.next(o)

print(ad.dd['U'])

Solution (Python):
class Dice():
    def __init__(self, nums):
        self.nums = nums
        self.top, self.front, self.right = 0, 1, 2

    def move(self, op):
        for c in op:
            if c == 'N':
                self.top, self.front = self.front, 5 - self.top
            elif c == 'S':
                self.top, self.front = 5 - self.front, self.top
            elif c == 'E':
                self.top, self.right = 5 - self.right, self.top
            else:
                self.top, self.right = self.right, 5 - self.top

dice = Dice([int(n) for n in input().split()])
dice.move(input())
print(dice.nums[dice.top])

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):
    self.top = 1
    self.front = 2
    self.left = 4

  @property
  def bottom(self):
    return 7 - self.top

  @property
  def back(self):
    return 7 - self.front

  @property
  def right(self):
    return 7 - self.left

  def move(self, direction):
    if direction == 'N':
      bottom = self.bottom
      self.top = self.front
      self.front = bottom
    elif direction == 'W':
      right = self.right
      self.left = self.top
      self.top = right
    elif direction == 'E':
      bottom = self.bottom
      self.top = self.left
      self.left = bottom
    elif direction == 'S':
      back = self.back
      self.front = self.top
      self.top = back

  def __repr__(self):
    print(self.__dict__)

dice = Dice()
numbers = input().split()
for cmd in input():
  dice.move(cmd)
print(numbers[dice.top - 1])

Solution (Python):
class Dice():
    def __init__(self, nums):
        self.nums = nums
        self.top, self.front, self.right = 0, 1, 2
 
    def move(self, op):
        for c in op:
            if c == 'N':
                self.top, self.front = self.front, 5 - self.top
            elif c == 'S':
                self.top, self.front = 5 - self.front, self.top
            elif c == 'E':
                self.top, self.right = 5 - self.right, self.top
            else:
                self.top, self.right = self.right, 5 - self.top
 
dice = Dice([int(n) for n in input().split()])
dice.move(input())
print(dice.nums[dice.top])

Solution (Python):


class dice_class:
    def __init__(self, top, front, right, left, back, bottom):
        self.top    =   top
        self.front  =   front
        self.right  =   right
        self.left   =   left
        self.back   =   back
        self.bottom =   bottom

    def roll(self, s):
        for i in s:
            if i == 'E':
                self.rollE()
            elif i == 'N':
                self.rollN()
            elif i == 'S':
                self.rollS()
            elif i == 'W':
                self.rollW()

    def rollE(self):
        tmp         =   self.top
        self.top    =   self.left
        self.left   =   self.bottom
        self.bottom =   self.right
        self.right  =   tmp

    def rollN(self):
        tmp         =   self.top
        self.top    =   self.front
        self.front  =   self.bottom
        self.bottom =   self.back
        self.back   =   tmp

    def rollS(self):
        tmp         =   self.top
        self.top    =   self.back
        self.back   =   self.bottom
        self.bottom =   self.front
        self.front  =   tmp

    def rollW(self):
        tmp         =   self.top
        self.top    =   self.right
        self.right  =   self.bottom
        self.bottom =   self.left
        self.left   =   tmp

if __name__ == "__main__":
    a = map(int, raw_input().split())
    s = str(raw_input())
    dice = dice_class(a[0], a[1], a[2], a[3], a[4], a[5])
    dice.roll(s)
    print dice.top

Solution (Python):


class dice_class:
    def __init__(self, list):
        self.num = list

    def roll(self, s):
        for i in s:
            if i == 'E':
                self.rollE()
            elif i == 'N':
                self.rollN()
            elif i == 'S':
                self.rollS()
            elif i == 'W':
                self.rollW()

    def rollE(self):
        self.num = [self.num[3], self.num[1], self.num[0], self.num[5], self.num[4], self.num[2]]

    def rollN(self):
        self.num = [self.num[1], self.num[5], self.num[2], self.num[3], self.num[0], self.num[4]]

    def rollS(self):
        self.num = [self.num[4], self.num[0], self.num[2], self.num[3], self.num[5], self.num[1]]

    def rollW(self):
        self.num = [self.num[2], self.num[1], self.num[5], self.num[0], self.num[4], self.num[3]]


if __name__ == "__main__":
    dice = dice_class(map(int, raw_input().split()))
    s = str(raw_input())
    dice.roll(s)
    print dice.num[0]

Solution (Python):
class Dice:
    def __init__(self):
        self.front = '1'
        self.back = '6'
        self.top = '5'
        self.bottom = '2'
        self. right = '3'
        self.left = '4'
    def turnRight(self):
        temp = self.top
        self.top = self.left
        self.left = self.bottom
        self.bottom = self.right
        self.right = temp
        return self.top
    def turnLeft(self):
        temp = self.top
        self.top = self.right
        self.right = self.bottom
        self.bottom = self.left
        self.left = temp
        return self.top
    def turnFront(self):
        temp = self.top
        self.top = self.back
        self.back = self.bottom
        self.bottom = self.front
        self.front = temp
        return self.top
    def turnBack(self):
        temp = self.top
        self.top = self.front
        self.front = self.bottom
        self.bottom = self.back
        self.back = temp
        return self.top

mydice = Dice()
mydice.top, mydice.front, mydice.right, mydice.left, mydice.back, mydice.bottom = input().split()
orders = input()

for order in orders:
    if order == 'E':
        mydice.turnRight()
    elif order == 'W':
        mydice.turnLeft()
    elif order == 'S':
        mydice.turnFront()
    elif order == 'N':
        mydice.turnBack()
    else:
        print('Input error')
        break
print(mydice.top)

Solution (Python):
class Dice:

    def __init__(self):
        d = map(int, raw_input().split(" "))
        self.c = raw_input()
        self.rows = [d[0], d[4], d[5], d[1]]
        self.cols = [d[0], d[2], d[5], d[3]]

    def __move_next(self, x, y):
        temp = y.pop(0)
        y.append(temp)
        x[0] = y[0]
        x[2] = y[2]

    def __move_prev(self, x, y):
        temp = y.pop(3)
        y.insert(0, temp)
        x[0] = y[0]
        x[2] = y[2]

    def execute(self):
        for i in self.c:
            self.__move(i, self.rows, self.cols)

    def __move(self, com, x, y):
        if com == "N":
            self.__move_prev(y, x)
        elif com == "S":
            self.__move_next(y, x)
        elif com == "E":
            self.__move_prev(x, y)
        elif com == "W":
            self.__move_next(x, y)

    def print_top(self):
        print self.rows[0]

dice = Dice()
dice.execute()
dice.print_top()

Solution (Python):
class Dice:
    def __init__(self,u,s,e,w,n,d):
        self.n = n
        self.e = e
        self.s = s
        self.w = w
        self.u = u
        self.d = d
    def roll(self,dir):
        if (dir == "N"):
            tmp = self.n
            self.n = self.u
            self.u = self.s
            self.s = self.d
            self.d = tmp
        elif (dir == "E"):
            tmp = self.e
            self.e = self.u
            self.u = self.w
            self.w = self.d
            self.d = tmp
        elif (dir == "S"):
            tmp = self.s
            self.s = self.u
            self.u = self.n
            self.n = self.d
            self.d = tmp
        elif (dir == "W"):
            tmp = self.w
            self.w = self.u
            self.u = self.e
            self.e = self.d
            self.d = tmp

spots = raw_input().split()
operations = raw_input()

dice = Dice(*spots)
for i in operations:
    dice.roll(i)

print dice.u

Solution (Python):
def move_dice(d, dir):
    if(dir == 'N'):
        d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4]
    if(dir == 'S'):
        d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1]
    if(dir == 'E'):
        d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2]
    if(dir == 'W'):
        d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3]


dice = list(map(int, input().split()))
command = input()
for c in command:
    move_dice(dice, c)
print(dice[0])

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

    def north(self):
        self.change([2, 6, 3, 4, 1, 5])

    def south(self):
        self.change([5, 1, 3, 4, 6, 2])

    def east(self):
        self.change([4, 2, 1, 6, 5, 3])

    def west(self):
        self.change([3, 2, 6, 1, 5, 4])

    def change(self, convert):
        result = []
        for i in range(6):
            result.append(self.labels[convert[i] - 1])

        self.labels = result


dice = Dice(list(map(int, input().split())))
for direction in input():
    if direction == 'N':
        dice.north()
    if direction == 'S':
        dice.south()
    if direction == 'E':
        dice.east()
    if direction == 'W':
        dice.west()

print(dice.labels[0])

Solution (Python):



dice = [0 for i in range(6)]

dice = list(input().split())

order = list(input())

for i in range(0, len(order)):
    
    if order[i] == "S":
        temp = dice[0]
        dice[0] = dice[4]
        dice[4] = dice[5]
        dice[5] = dice[1]
        dice[1] = temp
    
    elif order[i] == "E":
        temp = dice[0]
        dice[0] = dice[3]
        dice[3] = dice[5]
        dice[5] = dice[2]
        dice[2] = temp
    
    elif order[i] == "W":
        temp = dice[0]
        dice[0] = dice[2]
        dice[2] = dice[5]
        dice[5] = dice[3]
        dice[3] = temp
    
    elif order[i] == "N":
        temp = dice[0]
        dice[0] = dice[1]
        dice[1] = dice[5]
        dice[5] = dice[4]
        dice[4] = temp
print("{0}".format(dice[0]))

Solution (Python):
ns=list(map(int,input().split()))
rs=input()

def rot(d, r):
    if r == 'N':
        return [d[1], d[5], d[2], d[3], d[0], d[4]]
    if r == 'E':
        return [d[3], d[1], d[0], d[5], d[4], d[2]]
    if r == 'W':
        return [d[2], d[1], d[5], d[0], d[4], d[3]]
    if r == 'S':
        return [d[4], d[0], d[2], d[3], d[5], d[1]]
    return d

for r in rs:
    ns = rot(ns, r)

print(ns[0])

Solution (Python):







































class Dice:
	def __init__(self, dice_num):
		self.side_top=1
		self.side_bot=6
		self.side_Nor=5
		self.side_Eas=3
		self.side_Sau=2
		self.side_Wes=4
		self.dice_num = dice_num

	def op_N(self):
		self.side_top, self.side_bot, self.side_Nor, self.side_Sau =\
		self.side_Sau, self.side_Nor, self.side_top, self.side_bot

	def op_E(self):
		self.side_top, self.side_bot, self.side_Eas, self.side_Wes =\
		self.side_Wes, self.side_Eas, self.side_top, self.side_bot

	def op_S(self):
		self.side_top, self.side_bot, self.side_Nor, self.side_Sau =\
		self.side_Nor, self.side_Sau, self.side_bot, self.side_top

	def op_W(self):
		self.side_top, self.side_bot, self.side_Eas, self.side_Wes =\
		self.side_Eas, self.side_Wes, self.side_bot, self.side_top

	def print_side_top(self):
		print( dice_num[self.side_top-1] )

	def print_side_all(self):
		print( "top:{}, bot:{}, Nor:{}, Eas{}, Sau:{}, Wes,{}.".format(self.side_top, self.side_bot, self.side_Nor, self.side_Eas, self.side_Sau, self.side_Wes ) )

dice_num = list( map(int, input().split()))
op = input()

dice_roll = Dice(dice_num) 
for i in op:
	if i == "N":
		dice_roll.op_N()
	elif i =="E":
		dice_roll.op_E()
	elif i =="S":
		dice_roll.op_S()
	elif i =="W":
		dice_roll.op_W()
	else:
		print("?????°??°")

dice_roll.print_side_top()

Solution (Python):




























































































class Dice:
	def __init__(self, dice_num):	  
		self.dice_state=[1,6,5,3,2,4] 
		self.dice_num = dice_num

	def op_N(self):
		self.dice_state = [ self.dice_state[i-1] for i in [5,3,1,4,2,6] ]

	def op_E(self):
		self.dice_state = [ self.dice_state[i-1] for i in [6,4,3,1,5,2] ]

	def op_S(self):
		self.dice_state = [ self.dice_state[i-1] for i in [3,5,2,4,1,6] ]

	def op_W(self):
		self.dice_state = [ self.dice_state[i-1] for i in [4,6,3,2,5,1] ]

	def get_state_top(self):
		
		return self.dice_state[0]

	def get_num_top(self):
		return self.dice_num[self.dice_state[0]-1]

	def print_side_top(self):
		print( self.dice_num[self.dice_state[0]-1] )

	def print_side_all(self):
		print( "top:{}, bot:{}, Nor:{}, Eas{}, Sau:{}, Wes,{}.".format(self.side_top, self.side_bot, self.side_Nor, self.side_Eas, self.side_Sau, self.side_Wes ) )


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

dice_roll = Dice(dice_num) 

Func_set = {'N': dice_roll.op_N, 'W': dice_roll.op_W, 'E': dice_roll.op_E, 'S': dice_roll.op_S}

for i in input():
	Func_set[i]()

dice_roll.print_side_top()

Solution (Python):
face = map(int, raw_input().split())
order = raw_input()

dice = [ [ 0, face[0] ],
              [ 1, face[1] ],
              [ 2, face[2] ],
              [ 3, face[3] ],
              [ 4, face[4] ],
              [ 5, face[5] ]]
temp = 0

for i in order:
    if i == 'N':
        temp = dice[0][1]
        dice[0][1] = dice[1][1]
        dice[1][1] = dice[5][1]
        dice[5][1] = dice[4][1]
        dice[4][1] = temp
    if i == 'E':
        temp = dice[0][1]
        dice[0][1] = dice[3][1]
        dice[3][1] = dice[5][1]
        dice[5][1] = dice[2][1]
        dice[2][1] = temp
    if i == 'S':
        temp = dice[0][1]
        dice[0][1] = dice[4][1]
        dice[4][1] = dice[5][1]
        dice[5][1] = dice[1][1]
        dice[1][1] = temp
    if i == 'W':
        temp = dice[0][1]
        dice[0][1] = dice[2][1]
        dice[2][1] = dice[5][1]
        dice[5][1] = dice[3][1]
        dice[3][1] = temp

print dice[0][1]

Solution (Python):

class dise:
    def __init__(self, label):
        self.label1 = label[0]
        self.label2 = label[1]
        self.label3 = label[2]
        self.label4 = label[3]
        self.label5 = label[4]
        self.label6 = label[5]
    
    def N_rotation(self):
        reg = self.label1
        self.label1 = self.label2
        self.label2 = self.label6
        self.label6 = self.label5
        self.label5 = reg
        
    def E_rotation(self):
        reg = self.label1
        self.label1 = self.label4
        self.label4 = self.label6
        self.label6 = self.label3
        self.label3 = reg
        
    def S_rotation(self):
        reg = self.label1
        self.label1 = self.label5
        self.label5 = self.label6
        self.label6 = self.label2
        self.label2 = reg
        
    def W_rotation(self):
        reg = self.label1
        self.label1 = self.label3
        self.label3 = self.label6
        self.label6 = self.label4
        self.label4 = reg

dise1 = dise(input().split())
order = list(input())

for i in order:
    if i == 'N':
        dise1.N_rotation()
    elif i == 'E':
        dise1.E_rotation()
    elif i == 'S':
        dise1.S_rotation()
    elif i == 'W':
        dise1.W_rotation()

print(dise1.label1)

Solution (Python):
class dice:
    def __init__(self,label):
        self.d = label
    def roll(self,op):
        d = self.d
        if   op=='N': self.d = [d[1],d[5],d[2],d[3],d[0],d[4]]
        elif op=='E': self.d = [d[3],d[1],d[0],d[5],d[4],d[2]]
        elif op=='W': self.d = [d[2],d[1],d[5],d[0],d[4],d[3]]
        elif op=='S': self.d = [d[4],d[0],d[2],d[3],d[5],d[1]]
    def print(self):
        print(self.d[0])

label = list(map(int,input().split()))
op_list = list(input())
d0 = dice(label)
for op in op_list:
    d0.roll(op)
d0.print()