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):


import sys
import collections
import unittest

def top_face_after_rolling_dice():
    try:
        faces    = [int(num) for num in input().rstrip().split()]
        rollings = input().rstrip()
    except:
        return __input_error()

    dice = CubicArbitraryValueDice(faces[0], faces[1], faces[2], faces[3], faces[4], faces[5])
    dice.put(dice.TOP, dice.SOUTH, dice.EAST, dice.WEST, dice.NORTH, dice.BOTTOM)
    
    for direction in rollings:
        dice.roll(direction)

    print(dice.faces[dice.direction[dice.TOP]])

class CubicArbitraryValueDice():
    TOP    = "top"
    BOTTOM = "bottom"
    EAST   = "E"
    WEST   = "W"
    SOUTH  = "S"
    NORTH  = "N"
    OPOSITE_DIRECTION_PAIRS = ( (EAST, WEST), (SOUTH, NORTH) )
    
    
    def __init__(self, n_f0, n_f1, n_f2, n_f3, n_f4, n_f5):
        self.faces = [n_f0, n_f1, n_f2, n_f3, n_f4, n_f5]

    
    def put(self, dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5):  
        self.direction = { dir_fi : i for i,dir_fi in enumerate([dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5]) }

    
    def roll(self, direction) : 
        for pair in self.OPOSITE_DIRECTION_PAIRS :
            if direction in pair :
                oposite = pair[0] if (pair[1] == direction) else pair[1]
        
        current = {}
        for direct in (self.TOP, self.BOTTOM, direction, oposite):
            current.update({direct : self.direction[direct]})

        
        for pair in ((direction, self.BOTTOM), (self.BOTTOM, oposite), (oposite, self.TOP), (self.TOP, direction)):
            self.direction[pair[1]] = current[pair[0]]

def __input_error():
    print("input error")
    return -1
'''
class __TestValueClass(unittest.TestCase):
    def testEqual(self, func, tuples, eff_digit = math.nan, print_success = False):
        self.testFunction(self.assertEqual,func,tuples,eff_digit,print_success)
    
    def testFunction(self,assertfunc,func,tuples,eff_digit,print_success):
        
        for item in tuples:
            try:
                if isinstance(item[0], collections.Iterable):
                    value = func(*item[0])
                else:
                    value = func(item[0])
                
                if math.isnan(eff_digit) :
                    assertfunc(value,item[1])
                else :
                    format_str = "{0:."+str(eff_digit)+"g}"
                    assertfunc(format_str.format(value),format_str.format(item[1]))
                    
            except Exception as msg:
                swidth = 15
                print("="*50)
                print("-- Assertion Error in '" + func.__name__ + "' --")
                info = []
                info.append(["arguments"     , item[0]    ])
                info.append(["compared value", item[1]    ])
                info.append(["message"       , "\n" + msg ])
                for state in info :
                    print(state[0].ljust(swidth) + ":", state[1])
                sys.exit()

        if print_success :
            print(func.__name__,": succeeded")
'''

if __name__ == "__main__" :

    top_face_after_rolling_dice()

Solution (Python):


import sys
import collections
import unittest

def top_face_after_rolling_dice():
    try:
        faces    = [int(num) for num in input().rstrip().split()]
        rollings = input().rstrip()
    except:
        return __input_error()

    dice = CubicArbitraryValueDice(faces[0], faces[1], faces[2], faces[3], faces[4], faces[5])
    dice.put(dice.TOP, dice.SOUTH, dice.EAST, dice.WEST, dice.NORTH, dice.BOTTOM)
    
    for direction in rollings:
        dice.roll(direction)

    print(dice.faces[dice.direction[dice.TOP]])

class CubicArbitraryValueDice():
    TOP    = "top"
    BOTTOM = "bottom"
    EAST   = "E"
    WEST   = "W"
    SOUTH  = "S"
    NORTH  = "N"
    OPOSITE_DIRECTION_PAIRS = ( (EAST, WEST), (SOUTH, NORTH) )
    
    
    def __init__(self, n_f0, n_f1, n_f2, n_f3, n_f4, n_f5):
        self.faces = [n_f0, n_f1, n_f2, n_f3, n_f4, n_f5]

    
    def put(self, dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5):  
        self.direction = { dir_fi : i for i,dir_fi in enumerate([dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5]) }

    
    def roll(self, direction) : 
        for pair in self.OPOSITE_DIRECTION_PAIRS :
            if direction in pair :
                oposite = pair[0] if (pair[1] == direction) else pair[1]
        
        current = {}
        for direct in (self.TOP, self.BOTTOM, direction, oposite):
            current.update({direct : self.direction[direct]})

        
        for pair in ((direction, self.BOTTOM), (self.BOTTOM, oposite), (oposite, self.TOP), (self.TOP, direction)):
            self.direction[pair[1]] = current[pair[0]]

def __input_error():
    print("input error")
    return -1
'''
class __TestValueClass(unittest.TestCase):
    def testEqual(self, func, tuples, eff_digit = math.nan, print_success = False):
        self.testFunction(self.assertEqual,func,tuples,eff_digit,print_success)
    
    def testFunction(self,assertfunc,func,tuples,eff_digit,print_success):
        
        pass

        for item in tuples:
            try:
                if isinstance(item[0], collections.Iterable):

                else:
                    value = func(item[0])
                
                if math.isnan(eff_digit) :

                else :


                    
            except Exception as msg:
                swidth = 15
                print("="*50)
                print("-- Assertion Error in '" + func.__name__ + "' --")
                info = []
                info.append(["arguments"     , item[0]    ])
                info.append(["compared value", item[1]    ])
                info.append(["message"       , "\n" + msg ])
                for state in info :
                    print(state[0].ljust(swidth) + ":", state[1])
                sys.exit()

        if print_success :
            print(func.__name__,": succeeded")
'''

if __name__ == "__main__" :

    top_face_after_rolling_dice()

Solution (Python):


import sys
import collections
import unittest

def top_face_after_rolling_dice():
    try:
        faces    = [int(num) for num in input().rstrip().split()]
        rollings = input().rstrip()
    except:
        return __input_error()

    dice = CubicArbitraryValueDice(faces[0], faces[1], faces[2], faces[3], faces[4], faces[5])
    dice.put(dice.TOP, dice.SOUTH, dice.EAST, dice.WEST, dice.NORTH, dice.BOTTOM)
    
    for direction in rollings:
        dice.roll(direction)

    print(dice.faces[dice.direction[dice.TOP]])

class CubicArbitraryValueDice():
    TOP    = "top"
    BOTTOM = "bottom"
    EAST   = "E"
    WEST   = "W"
    SOUTH  = "S"
    NORTH  = "N"
    OPOSITE_DIRECTION_PAIRS = ( (EAST, WEST), (SOUTH, NORTH) )
    
    
    def __init__(self, n_f0, n_f1, n_f2, n_f3, n_f4, n_f5):
        self.faces = [n_f0, n_f1, n_f2, n_f3, n_f4, n_f5]

    
    def put(self, dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5):  
        self.direction = { dir_fi : i for i,dir_fi in enumerate([dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5]) }

    
    def roll(self, direction) : 
        for pair in self.OPOSITE_DIRECTION_PAIRS :
            if direction in pair :
                oposite = pair[0] if (pair[1] == direction) else pair[1]
        
        current = {}
        for direct in (self.TOP, self.BOTTOM, direction, oposite):
            current.update({direct : self.direction[direct]})

        
        for pair in ((direction, self.BOTTOM), (self.BOTTOM, oposite), (oposite, self.TOP), (self.TOP, direction)):
            self.direction[pair[1]] = current[pair[0]]

def __input_error():
    print("input error")
    return -1

class __TestValueClass(unittest.TestCase):
    
    def testEqual(self, func, tuples, eff_digit, print_success):
        self.testFunction(self.assertEqual,func,tuples,eff_digit,print_success)
    
    def testFunction(self,assertfunc,func,tuples,eff_digit,print_success):
        
        pass
'''
        for item in tuples:
            try:
                if isinstance(item[0], collections.Iterable):

                else:
                    value = func(item[0])
                
                if math.isnan(eff_digit) :

                else :


                    
            except Exception as msg:
                swidth = 15
                print("="*50)
                print("-- Assertion Error in '" + func.__name__ + "' --")
                info = []
                info.append(["arguments"     , item[0]    ])
                info.append(["compared value", item[1]    ])
                info.append(["message"       , "\n" + msg ])
                for state in info :
                    print(state[0].ljust(swidth) + ":", state[1])
                sys.exit()

        if print_success :
            print(func.__name__,": succeeded")
'''

if __name__ == "__main__" :

    top_face_after_rolling_dice()

Solution (Python):


import sys
import collections
import unittest

def top_face_after_rolling_dice():
    try:
        faces    = [int(num) for num in input().rstrip().split()]
        rollings = input().rstrip()
    except:
        return __input_error()

    dice = CubicArbitraryValueDice(faces[0], faces[1], faces[2], faces[3], faces[4], faces[5])
    dice.put(dice.TOP, dice.SOUTH, dice.EAST, dice.WEST, dice.NORTH, dice.BOTTOM)
    
    for direction in rollings:
        dice.roll(direction)

    print(dice.faces[dice.direction[dice.TOP]])

class CubicArbitraryValueDice():
    TOP    = "top"
    BOTTOM = "bottom"
    EAST   = "E"
    WEST   = "W"
    SOUTH  = "S"
    NORTH  = "N"
    OPOSITE_DIRECTION_PAIRS = ( (EAST, WEST), (SOUTH, NORTH) )
    
    
    def __init__(self, n_f0, n_f1, n_f2, n_f3, n_f4, n_f5):
        self.faces = [n_f0, n_f1, n_f2, n_f3, n_f4, n_f5]

    
    def put(self, dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5):  
        self.direction = { dir_fi : i for i,dir_fi in enumerate([dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5]) }

    
    def roll(self, direction) : 
        for pair in self.OPOSITE_DIRECTION_PAIRS :
            if direction in pair :
                oposite = pair[0] if (pair[1] == direction) else pair[1]
        
        current = {}
        for direct in (self.TOP, self.BOTTOM, direction, oposite):
            current.update({direct : self.direction[direct]})

        
        for pair in ((direction, self.BOTTOM), (self.BOTTOM, oposite), (oposite, self.TOP), (self.TOP, direction)):
            self.direction[pair[1]] = current[pair[0]]

def __input_error():
    print("input error")
    return -1

class __TestValueClass(unittest.TestCase):
    
    def testEqual(self, func, tuples, eff_digit, print_success = False):
        self.testFunction(self.assertEqual,func,tuples,eff_digit,print_success)
    
    def testFunction(self,assertfunc,func,tuples,eff_digit,print_success):
        
        pass
'''
        for item in tuples:
            try:
                if isinstance(item[0], collections.Iterable):

                else:
                    value = func(item[0])
                
                if math.isnan(eff_digit) :

                else :


                    
            except Exception as msg:
                swidth = 15
                print("="*50)
                print("-- Assertion Error in '" + func.__name__ + "' --")
                info = []
                info.append(["arguments"     , item[0]    ])
                info.append(["compared value", item[1]    ])
                info.append(["message"       , "\n" + msg ])
                for state in info :
                    print(state[0].ljust(swidth) + ":", state[1])
                sys.exit()

        if print_success :
            print(func.__name__,": succeeded")
'''

if __name__ == "__main__" :

    top_face_after_rolling_dice()

Solution (Python):


import sys
import collections
import math
import unittest

def top_face_after_rolling_dice():
    try:
        faces    = [int(num) for num in input().rstrip().split()]
        rollings = input().rstrip()
    except:
        return __input_error()

    dice = CubicArbitraryValueDice(faces[0], faces[1], faces[2], faces[3], faces[4], faces[5])
    dice.put(dice.TOP, dice.SOUTH, dice.EAST, dice.WEST, dice.NORTH, dice.BOTTOM)
    
    for direction in rollings:
        dice.roll(direction)

    print(dice.faces[dice.direction[dice.TOP]])

class CubicArbitraryValueDice():
    TOP    = "top"
    BOTTOM = "bottom"
    EAST   = "E"
    WEST   = "W"
    SOUTH  = "S"
    NORTH  = "N"
    OPOSITE_DIRECTION_PAIRS = ( (EAST, WEST), (SOUTH, NORTH) )
    
    
    def __init__(self, n_f0, n_f1, n_f2, n_f3, n_f4, n_f5):
        self.faces = [n_f0, n_f1, n_f2, n_f3, n_f4, n_f5]

    
    def put(self, dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5):  
        self.direction = { dir_fi : i for i,dir_fi in enumerate([dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5]) }

    
    def roll(self, direction) : 
        for pair in self.OPOSITE_DIRECTION_PAIRS :
            if direction in pair :
                oposite = pair[0] if (pair[1] == direction) else pair[1]
        
        current = {}
        for direct in (self.TOP, self.BOTTOM, direction, oposite):
            current.update({direct : self.direction[direct]})

        
        for pair in ((direction, self.BOTTOM), (self.BOTTOM, oposite), (oposite, self.TOP), (self.TOP, direction)):
            self.direction[pair[1]] = current[pair[0]]

def __input_error():
    print("input error")
    return -1

class __TestValueClass(unittest.TestCase):
    
    def testEqual(self, func, tuples, eff_digit = None, print_success = False):
        self.testFunction(self.assertEqual,func,tuples,eff_digit,print_success)
    
    def testFunction(self,assertfunc,func,tuples,eff_digit,print_success):
        
        pass
'''
        for item in tuples:
            try:
                if isinstance(item[0], collections.Iterable):

                else:
                    value = func(item[0])
                
                if math.isnan(eff_digit) :

                else :


                    
            except Exception as msg:
                swidth = 15
                print("="*50)
                print("-- Assertion Error in '" + func.__name__ + "' --")
                info = []
                info.append(["arguments"     , item[0]    ])
                info.append(["compared value", item[1]    ])
                info.append(["message"       , "\n" + msg ])
                for state in info :
                    print(state[0].ljust(swidth) + ":", state[1])
                sys.exit()

        if print_success :
            print(func.__name__,": succeeded")
'''

if __name__ == "__main__" :

    top_face_after_rolling_dice()

Solution (Python):


import sys
from collections import Iterable
import unittest

def top_face_after_rolling_dice():
    try:
        faces    = [int(num) for num in input().rstrip().split()]
        rollings = input().rstrip()
    except:
        return __input_error()

    dice = CubicArbitraryValueDice(faces[0], faces[1], faces[2], faces[3], faces[4], faces[5])
    dice.put(dice.TOP, dice.SOUTH, dice.EAST, dice.WEST, dice.NORTH, dice.BOTTOM)
    
    for direction in rollings:
        dice.roll(direction)

    print(dice.faces[dice.direction[dice.TOP]])

class CubicArbitraryValueDice():
    TOP    = "top"
    BOTTOM = "bottom"
    EAST   = "E"
    WEST   = "W"
    SOUTH  = "S"
    NORTH  = "N"
    OPOSITE_DIRECTION_PAIRS = ( (EAST, WEST), (SOUTH, NORTH) )
    
    
    def __init__(self, n_f0, n_f1, n_f2, n_f3, n_f4, n_f5):
        self.faces = [n_f0, n_f1, n_f2, n_f3, n_f4, n_f5]

    
    def put(self, dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5):  
        self.direction = { dir_fi : i for i,dir_fi in enumerate([dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5]) }

    
    def roll(self, direction) : 
        for pair in self.OPOSITE_DIRECTION_PAIRS :
            if direction in pair :
                oposite = pair[0] if (pair[1] == direction) else pair[1]
        
        current = {}
        for direct in (self.TOP, self.BOTTOM, direction, oposite):
            current.update({direct : self.direction[direct]})

        
        for pair in ((direction, self.BOTTOM), (self.BOTTOM, oposite), (oposite, self.TOP), (self.TOP, direction)):
            self.direction[pair[1]] = current[pair[0]]

def __input_error():
    print("input error")
    return -1

class __TestValueClass(unittest.TestCase):
    def testEqual(self, func, tuples, eff_digit = None, print_success = False):
        self.testFunction(self.assertEqual,func,tuples,eff_digit,print_success)
    
    def testFunction(self,assertfunc,func,tuples,eff_digit,print_success):
        
        for item in tuples:
            try:
                if isinstance(item[0], Iterable):
                    value = func(*item[0])
                else:
                    value = func(item[0])
                
                if eff_digit is None :
                    assertfunc(value,item[1])
                else :
                    format_str = "{0:."+str(eff_digit)+"g}"
                    assertfunc(format_str.format(value),format_str.format(item[1]))
                    
            except Exception as msg:
                swidth = 15
                print("="*50)
                print("-- Assertion Error in '" + func.__name__ + "' --")
                info = []
                info.append(["arguments"     , item[0]    ])
                info.append(["compared value", item[1]    ])
                info.append(["message"       , "\n" + msg ])
                for state in info :
                    print(state[0].ljust(swidth) + ":", state[1])
                sys.exit()

        if print_success :
            print(func.__name__,": succeeded")


if __name__ == "__main__" :

    top_face_after_rolling_dice()

Solution (Python):


from sys         import exit
from collections import Iterable
from unittest    import TestCase



def top_face_after_rolling_dice():
    try:
        faces    = [int(num) for num in input().rstrip().split()]
        rollings = input().rstrip()
    except:
        return __input_error()

    dice = CubicArbitraryValueDice(faces[0], faces[1], faces[2], faces[3], faces[4], faces[5])
    dice.put(dice.TOP, dice.SOUTH, dice.EAST, dice.WEST, dice.NORTH, dice.BOTTOM)
    
    for operator in rollings:
        dice.roll(operator)

    print(dice.get_value(dice.TOP))

class CubicArbitraryValueDice():
    (TOP, BOTTOM, EAST, WEST, SOUTH, NORTH, RIGHT, LEFT) = ("top", "bottom", "E", "W", "S", "N", "R", "L")
    (stVALUE, stDIRECTION) = ("value", "direction")

    (plus_x, minus_x, plus_y, minus_y, plus_z, minus_z) = ( (1,0,0), (-1,0,0), (0,1,0), (0,-1,0), (0,0,1), (0,0,-1) )








    ROLL_x2y = ( ( 0,-1, 0), ( 1, 0, 0), ( 0, 0, 1) )
    ROLL_y2x = ( ( 0, 1, 0), (-1, 0, 0), ( 0, 0, 1) )
    ROLL_y2z = ( ( 1, 0, 0), ( 0, 0,-1), ( 0, 1, 0) )
    ROLL_z2y = ( ( 1, 0, 0), ( 0, 0, 1), ( 0,-1, 0) )
    ROLL_z2x = ( ( 0, 0, 1), ( 0, 1, 0), (-1, 0, 0) )
    ROLL_x2z = ( ( 0, 0,-1), ( 0, 1, 0), ( 1, 0, 0) )
    
    DIRECTION = { EAST : plus_x,   WEST : minus_x,  NORTH : plus_y,   SOUTH : minus_y,  TOP   : plus_z,   BOTTOM : minus_z }
    OPERATOR  = { EAST : ROLL_z2x, WEST : ROLL_x2z, NORTH : ROLL_z2y, SOUTH : ROLL_y2z, RIGHT : ROLL_y2x, LEFT   : ROLL_x2y }
    
    
    def __init__(self, n_f0, n_f1, n_f2, n_f3, n_f4, n_f5):
        self.info = [ {self.stVALUE: n_fi} for n_fi in [n_f0, n_f1, n_f2, n_f3, n_f4, n_f5]]

    def put(self, dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5):  
        for (info, dir_fi) in zip(self.info, [dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5]):
            info[self.stDIRECTION] = self.DIRECTION[dir_fi]

    def roll(self, operator) : 
        for info in self.info:

            vector = info[self.stDIRECTION]
            matrix = self.OPERATOR[operator]
            info[self.stDIRECTION] = tuple([sum( [matrix[row][col]*vector[col] for col in range(len(vector))] ) for row in range(len(matrix))])
            
    def get_value(self, direction):
        for info in self.info:
            if info[self.stDIRECTION] == self.DIRECTION[direction] :
                return info[self.stVALUE]
    
    def get_direction(self, value):
        for info in self.info:
            if info[self.stVALUE] == value :
                dir_key_values = self.DIRECTION.items()
                for items in dir_key_values:
                    if info[self.stDIRECTION] in items:
                        return items[0]

def __input_error():
    print("input error")
    return -1
    

class __TestValueClass(TestCase):
    def testEqual(self, func, tuples, eff_digit = None, print_success = False):
        self.testFunction(self.assertEqual,func,tuples,eff_digit,print_success)
    
    def testFunction(self,assertfunc,func,tuples,eff_digit,print_success):
        
        for item in tuples:
            try:
                if isinstance(item[0], Iterable):
                    value = func(*item[0])
                else:
                    value = func(item[0])
                
                if eff_digit is None :
                    assertfunc(value,item[1])
                else :
                    format_str = "{0:."+str(eff_digit)+"g}"
                    assertfunc(format_str.format(value),format_str.format(item[1]))
                    
            except Exception as msg:
                swidth = 15
                print("="*50)
                print("-- Assertion Error in '" + func.__name__ + "' --")
                info = []
                info.append(["arguments"     , item[0]    ])
                info.append(["compared value", item[1]    ])
                info.append(["message"       , "\n" + msg ])
                for info_state in info :
                    print(info_state[0].ljust(swidth) + ":", info_state[1])
                exit()

        if print_success :
            print(func.__name__,": succeeded")


if __name__ == "__main__" :

    top_face_after_rolling_dice()

Solution (Python):


flips = []

die = input().split()
for i in range(6):
    die[i] = [i + 1, die[i]]
text = input()
for x in text:
    flips.append(x)

for x in flips:
    if x == 'S':
        for y in die:
            if 5 in y:
                y[0] = 1
            elif 1 in y:
                y[0] = 2
            elif 2 in y:
                y[0] = 6
            elif 6 in y:
                y[0] = 5
    elif x == 'N':
        for y in die:
            if 5 in y:
                y[0] = 6
            elif 1 in y:
                y[0] = 5
            elif 2 in y:
                y[0] = 1
            elif 6 in y:
                y[0] = 2
    elif x == 'E':
        for y in die:
            if 4 in y:
                y[0] = 1
            elif 1 in y:
                y[0] = 3
            elif 3 in y:
                y[0] = 6
            elif 6 in y:
                y[0] = 4
    else:
        for y in die:
            if 4 in y:
                y[0] = 6
            elif 1 in y:
                y[0] = 4
            elif 3 in y:
                y[0] = 1
            elif 6 in y:
                y[0] = 3

for x in die:
    if x[0] == 1:
        print(x[1])

Solution (Python):

class Dice:
	def __init__(self, label):
		self.d = label

	def north(self):
		d = self.d
		self.d = [d[1],d[5],d[2],d[3],d[0],d[4]]
	
	def east(self):
		d = self.d
		self.d = [d[3],d[1],d[0],d[5],d[4],d[2]]
	
	def west(self):
		d = self.d
		self.d = [d[2],d[1],d[5],d[0],d[4],d[3]]
	
	def south(self):
		d = self.d
		self.d = [d[4],d[0],d[2],d[3],d[5],d[1]]

	def output(self):
		d = self.d
		print(self.d[0])

label = list(map(int, input().split()))
op_list = list(input())
d0 = Dice(label)
for op in op_list:
	if op =='N':
		d0.north()
	if op =='E':
		d0.east()
	if op =='W':
		d0.west()
	if op =='S':
		d0.south()
d0.output()

Solution (Python):

rep={
    "N":[4,0,2,3,5,1],
    "S":[1,5,2,3,0,4],
    "E":[2,1,5,0,4,3],
    "W":[3,1,0,5,4,2]
}

d = input().split(" ")
NSEW = input()
c=[d]
for i in range(len(NSEW)):
    c.append([0,0,0,0,0,0])

for i in range(len(NSEW)):
    r=rep[NSEW[i]]
    for j in range(6):
        c[i+1][r[j]]=c[i][j]
print(c[len(NSEW)][0])

Solution (Python):
class Dice:
    def __init__(self):
        self.up = 1
        self.under = 6
        self.N = 5
        self.W = 4
        self.E = 3
        self.S = 2

    def roll(self, d):
        if d == "N":
            tmp = self.up
            self.up = self.S
            self.S = self.under
            self.under = self.N
            self.N = tmp
        elif d == "W":
            tmp = self.up
            self.up = self.E
            self.E = self.under
            self.under = self.W
            self.W = tmp
        elif d == "E":
            tmp = self.up
            self.up = self.W
            self.W = self.under
            self.under = self.E
            self.E = tmp
        elif d == "S":
            tmp = self.up
            self.up = self.N
            self.N = self.under
            self.under = self.S
            self.S = tmp

    def getUpward(self):
        return self.up

    def setRoll(self,up,under,N,W,E,S):
        self.up = up
        self.under = under
        self.N = N
        self.W = W
        self.E = E
        self.S = S

myd = Dice()
myd.up, myd.S, myd.E, myd.W, myd.N, myd.under = map(int,input().split())
do = input()
for i in do:
        myd.roll(i)
print(myd.getUpward())

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

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

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

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

F = {'N':north,'W':west,'S':south,'E':east}
d,os = list(map(int,input().split())),input()
for o in os:
    F[o](d)

print(d[0])

Solution (Python):
def main():
    nums = list(map(int, input().split(' ')))
    directs = input()

    d = Dice(nums)

    for c in directs:
        if 'N' == c:
            d.toN()

        if 'S' == c:
            d.toS()

        if 'E' == c:
            d.toE()

        if 'W' == c:
            d.toW()

    print(d.top)

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

        self._top    = 0
        self._front  = 1
        self._right  = 2
        self._left   = 3
        self._back   = 4
        self._bottom = 5

    def toN(self):
        self._back, self._top, self._front, self._bottom = self._top, self._front, self._bottom, self._back
        return self

    def toS(self):
        self._back, self._top, self._front, self._bottom =  self._bottom, self._back, self._top, self._front
        return self

    def toW(self):
        self._left, self._top, self._right, self._bottom = self._top, self._right, self._bottom, self._left
        return self

    def toE(self):
        self._left, self._top, self._right, self._bottom = self._bottom, self._left, self._top, self._right
        return self

    def get_top(self):
        return self.labels[self._top]

    top = property(get_top)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    nums = list(map(int, input().split(' ')))
    directs = input()

    d = Dice(nums)

    for c in directs:
        if 'N' == c:
            d.toN()

        if 'S' == c:
            d.toS()

        if 'E' == c:
            d.toE()

        if 'W' == c:
            d.toW()

    print(d.top)

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

        self._tb = (0, 5)
        self._fb = (1, 4)
        self._lr = (3, 2)

    def toN(self):
        tb = self._tb
        self._tb = self._fb
        self._fb = tuple(reversed(tb))

        return self

    def toS(self):
        tb = self._tb
        self._tb = tuple(reversed(self._fb))
        self._fb = tb

        return self

    def toW(self):
        tb = self._tb
        self._tb = tuple(reversed(self._lr))
        self._lr = tb

        return self

    def toE(self):
        tb = self._tb
        self._tb = self._lr
        self._lr = tuple(reversed(tb))

        return self

    def get_top(self):
        return self.labels[self._tb[0]]

    top = property(get_top)

if __name__ == '__main__':
    main()

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

Solution (Python):
u, s, e, w, n, d = list(map(int, input().split()))
insts = input()
for inst in insts:
    if inst == 'N':
        u, s, n, d = s, d, u, n
    elif inst == 'E':
        u, e, w, d = w, u, d, e
    elif inst == 'S':
        u, s, n, d = n, u, d, s
    elif inst == 'W':
        u, e, w, d = e, d, u, w
print(u)

Solution (Python):
u, s, e, w, n, d = list(map(int, input().split()))
insts = input()
for inst in insts:
    if inst == 'N':
        u, s, n, d = s, d, u, n
    elif inst == 'E':
        u, e, w, d = w, u, d, e
    elif inst == 'S':
        u, s, n, d = n, u, d, s
    elif inst == 'W':
        u, e, w, d = e, d, u, w
print(u)

Solution (Python):
u, s, e, w, n, d = map(int, input().split())
insts = input()
for inst in insts:
    if inst == 'N':
        u, s, n, d = s, d, u, n
    elif inst == 'E':
        u, e, w, d = w, u, d, e
    elif inst == 'S':
        u, s, n, d = n, u, d, s
    elif inst == 'W':
        u, e, w, d = e, d, u, w
print(u)

Solution (Python):
u, s, e, w, n, d = map(int, input().split())
insts = input()
for inst in insts:
    if inst == 'N':
        u, s, n, d = s, d, u, n
    elif inst == 'E':
        u, e, w, d = w, u, d, e
    elif inst == 'S':
        u, s, n, d = n, u, d, s
    elif inst == 'W':
        u, e, w, d = e, d, u, w
print(u)