Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

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



Sample input:
1 2 4 8 16 32
SE


Sample output:
8

Submission status: Accepted

Solution code:

class Dice:
    def __init__(self, p):
        self.y = [p[0], p[1], p[5], p[4]]
        self.x = [p[0], p[2], p[5], p[3]]

    def roll(self, c):
        if c in ['N', 'S']:
            if c == 'N':
                self.y.append(self.y.pop(0))
            elif c == 'S':
                self.y.insert(0, self.y.pop())
            self.x[0] = self.y[0]
            self.x[2] = self.y[2]
        else:
            if c == 'E':
                self.x.insert(0, self.x.pop())
            elif c == 'W':
                self.x.append(self.x.pop(0))
            self.y[0] = self.x[0]
            self.y[2] = self.x[2]

    def num(self, n):
        n = n - 1;
        pos_y = [0, 1, 5, 4]
        pos_x = [0, 2, 5, 3]
        if n in pos_y:
            return self.y[pos_y.index(n)]
        else:
            return self.x[pos_x.index(n)]


p = [ int(n) for n in input().split()]
s = input()

dice = Dice(p)

for c in s:
    dice.roll(c)
print(dice.num(1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self, ls = [0 for i in range(6)]):
        self.ls = ls
        
    def now(self):
        return ls
    
    def S_act(self):
        ls = self.ls
        n_ls = [0 for i in range(6)]
        n_ls[0] = ls[4]
        n_ls[1] = ls[0]
        n_ls[2] = ls[2]
        n_ls[3] = ls[3]
        n_ls[4] = ls[5]
        n_ls[5] = ls[1]
        
        return Dice(n_ls)
    
    def N_act(self):
        ls = self.S_act().S_act().S_act().ls
        return Dice(ls)
        
    def E_act(self):
        ls = self.ls
        n_ls = [0 for i in range(6)]
        n_ls[0] = ls[3]
        n_ls[1] = ls[1]
        n_ls[2] = ls[0]
        n_ls[3] = ls[5]
        n_ls[4] = ls[4]
        n_ls[5] = ls[2]
        return Dice(n_ls)
    
    
    def W_act(self):
        ls = self.E_act().E_act().E_act().ls
        return Dice(ls)

        
ls = list(map(int, input().split()))
a = Dice(ls)


act = input()

for i in act:
    func = {'S':a.S_act(), 'E':a.E_act(), 'W': a.W_act(), 'N':a.N_act()}
    a = func[i]
    
    
print(a.ls[0])

Submission status: Accepted

Solution code:
dice = [int(_) for _ in input().split()]
move = [ _ for _ in input()]
dire = {"N": [2,6,3,4,1,5],"S":[5,1,3,4,6,2],
      "E":[4,2,1,6,5,3],"W":[3,2,6,1,5,4]}
em = []
for i in range(len(move)):
    em = dice[:]
    for j in range(len(dice)):
        em[j] = dice[dire[move[i]][j]-1]
    else:
        del dice[:]
        dice.extend(em)
print(dice[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__ (self, p):
        self.y = [p[0], p[1], p[5], p[4]]
        self.x = [p[0], p[2], p[5], p[3]]
        
    def roll(self, c):
        if c in ["N", "S"]:
            if c == "N":
                self.y.append(self.y.pop(0))
            elif c == "S":
                self.y.insert(0, self.y.pop())
            self.x[0] = self.y[0]
            self.x[2] = self.y[2]
        else:
            if c == "E":
                self.x.insert(0, self.x.pop())
            elif c == "W":
                self.x.append(self.x.pop(0))
            self.y[0] = self.x[0]
            self.y[2] = self.x[2]
            
    def num(self, n):
        n = n - 1;
        pos_y = [0, 1, 5, 4]
        pos_x = [0, 2, 5, 3]
        
        if n in pos_y:
            return self.y[pos_y.index(n)]
        else:
            return self.x[pos_x.index(n)]
        
p = [ int(n) for n in input().split() ]
s = input()

dice = Dice(p)

for c in s:
    dice.roll(c)
print(dice.num(1))

Submission status: Accepted

Solution code:
class Dice:
  def make_dice(self, value):
    self.face = value
  def move(self, direc):
    if direc == "N":
      self.face = [self.face[1], self.face[5], self.face[2], self.face[3], self.face[0], self.face[4]]
      return self.face
    elif direc == "E":
      self.face = [self.face[3], self.face[1], self.face[0], self.face[5], self.face[4], self.face[2]]
      return self.face
    elif direc == "S":
      self.face = [self.face[4], self.face[0], self.face[2], self.face[3], self.face[5], self.face[1]]
      return self.face
    elif direc == "W":
      self.face = [self.face[2], self.face[1], self.face[5], self.face[0], self.face[4], self.face[3]]
      return self.face

num = list(map(int, input().split()))
direction = input()
dice = Dice()
dice.make_dice(num)
for i in range(len(direction)):
  dice.move(direction[i])
print(dice.face[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,surfaceNum):
        self.surface = surfaceNum
        
    def east(self):
        self.surface[0], self.surface[2], self.surface[5], self.surface[3] = self.surface[3], self.surface[0], self.surface[2], self.surface[5]
    def west(self):
        self.surface[0], self.surface[2], self.surface[5], self.surface[3] = self.surface[2], self.surface[5], self.surface[3], self.surface[0]
    def south(self):
        self.surface[0], self.surface[1], self.surface[5], self.surface[4] = self.surface[4], self.surface[0], self.surface[1], self.surface[5]
    def north(self):
        self.surface[0], self.surface[1], self.surface[5], self.surface[4] = self.surface[1], self.surface[5], self.surface[4], self.surface[0]
        
    def printTopSurface(self):
        print(self.surface[0])  

surfaceNum = [int(i) for i in input().split()]
rollCommand = list(input())
Dice = Dice(surfaceNum)

for i in range(len(rollCommand)):
    if rollCommand[i] == "E":
        Dice.east()
    if rollCommand[i] == "W":
        Dice.west()
    if rollCommand[i] == "S":
        Dice.south()
    if rollCommand[i] == "N":
        Dice.north()
    
Dice.printTopSurface()

Submission status: Accepted

Solution code:
num = list(map(int, input().split()))
order = input()

for o in order:
    if o == 'N':
        next = '263415'
    elif o == 'W':
        next = '326154'
    elif o == 'S':
        next = '513462'
    else:
        next = '421653'

    temp = [0]*6
    for i,n in enumerate(next):
        temp[i] = num[int(n)-1]

    num = temp

print(num[0])

Submission status: Accepted

Solution code:
dice_ = [int(i) for i in input().split()]
com = list(input())
dice = {
    't':dice_[0],
    'd':dice_[1],
    'r':dice_[2],
    'l':dice_[3],
    'u':dice_[4],
    'b':dice_[5]
}
for i in com:
    # u
    #ltr b
    # d
    if i == "N":
        temp = dice['t']
        dice['t'] = dice['d']
        dice['d'] = dice['b']
        dice['b'] = dice['u']
        dice['u'] = temp
    elif i == "S":
        temp = dice['u']
        dice['u'] = dice['b']
        dice['b'] = dice['d']
        dice['d'] = dice['t']
        dice['t'] = temp
    elif i == "W":
        temp = dice['t']
        dice['t'] = dice['r']
        dice['r'] = dice['b']
        dice['b'] = dice['l']
        dice['l'] = temp
    elif i == "E":
        temp = dice['l']
        dice['l'] = dice['b']
        dice['b'] = dice['r']
        dice['r'] = dice['t']
        dice['t'] = temp
print(dice['t'])

Submission status: Accepted

Solution code:
# coding: utf-8
class Dice:
    
    def __init__(self):
        self.data = {"bottom":5, "west": 3, "north" : 4,
                "east": 2, "south" : 1,"top" : 0}
    
    def moveOne(self, direction):
        if direction == "W":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["west"]
            self.data["west"] = self.data["top"]
            self.data["top"] = self.data["east"]
            self.data["east"] = temp
        elif direction == "E":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["east"]
            self.data["east"] = self.data["top"]
            self.data["top"] = self.data["west"]
            self.data["west"] = temp
        elif direction == "N":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["north"]
            self.data["north"] = self.data["top"]
            self.data["top"] = self.data["south"]
            self.data["south"] = temp
        elif direction == "S":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["south"]
            self.data["south"] = self.data["top"]
            self.data["top"] = self.data["north"]
            self.data["north"] = temp

    def movePart(self,*s):
        for ch in s:
            self.moveOne(ch)
      
    def getSurface(self):
        return self.data["top"]
        
    def printDice(self):
        print(self.data["north"])
        print(str(self.data["west"]) + " " + str(self.data["bottom"]) + " " + str(self.data["east"]) )
        print(self.data["south"])
        print(self.data["top"])


num = list(map(int,input().rstrip().split()))
s = input().rstrip()
dice = Dice()
dice.movePart(*s)
ret = dice.getSurface()
print(num[ret])

Submission status: Accepted

Solution code:
nums = list(map(int, input().split()))
mv = input()


class die:
    face = [0, 0, 0, 0, 0, 0]

    def __init__(self, nums):
        self.face = [nums[f] for f in [0, 3, 1, 2, 4, 5]]

    def roll(self, d):
        c_face = list(self.face)

        if d == 'S':
            self.face = [c_face[f] for f in [4, 1, 0, 3, 5, 2]]
        elif d == 'N':
            self.face = [c_face[f] for f in [2, 1, 5, 3, 0, 4]]
        elif d == 'W':
            self.face = [c_face[f] for f in [3, 0, 2, 5, 4, 1]]
        elif d == 'E':
            self.face = [c_face[f] for f in [1, 5, 2, 0, 4, 3]]


d = die(nums)
for m in mv:
    d.roll(m)
print(d.face[0])

Submission status: Accepted

Solution code:
import math

class Dice:
    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 roll_east(self):
        tmp = self.top
        self.top = self.west
        self.west = self.bottom
        self.bottom = self.east
        self.east = tmp

    def roll_north(self):
        tmp = self.top
        self.top = self.south
        self.south = self.bottom
        self.bottom = self.north
        self.north = tmp

    def roll_south(self):
        tmp = self.top
        self.top = self.north
        self.north = self.bottom
        self.bottom = self.south
        self.south = tmp

    def roll_west(self):
        tmp = self.top
        self.top = self.east
        self.east = self.bottom
        self.bottom = self.west
        self.west = tmp


a, b, c, d, e, f = map(int, input().split())
dice = Dice(a, b, c, d, e, f)
command = input()
for c in command:
    if c == 'E':
        dice.roll_east()
    elif c == 'N':
        dice.roll_north()
    elif c == 'S':
        dice.roll_south()
    elif c == 'W':
        dice.roll_west()
print(dice.top)

Submission status: Accepted

Solution code:
class Dice(object):
    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_s6 = self.s6
        self.s6 = self.s3
        self.s3 = self.s1
        self.s1 = self.s4
        self.s4 = prev_s6
    def west(self):
        prev_s6 = self.s6
        self.s6 = self.s4
        self.s4 = self.s1
        self.s1 = self.s3
        self.s3 = prev_s6
    def north(self):
        prev_s6 = self.s6
        self.s6 = self.s5
        self.s5 = self.s1
        self.s1 = self.s2
        self.s2 = prev_s6
    def south(self):
        prev_s6 = self.s6
        self.s6 = self.s2
        self.s2 = self.s1
        self.s1 = self.s5
        self.s5 = prev_s6
    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 == 'W':
        dice.west()
    elif c == 'E':
        dice.east()
    elif c == 'S':
        dice.south()
print(dice.top())

Submission status: Accepted

Solution code:
class DICE:
    def __init__(self, li = [1,2,3,4,5,6]):
        self.vals = li
        self.nextkeys = [1, 4, 3, 2] # 2 5 4 3 nsew
        self.nowkey = 0
        self.nowval = li[0]
    def operate(self, s):
        c_key = abs(5 - self.nowkey)
        pastkey = self.nowkey
        if s == 'N':
            self.nowkey = self.nextkeys[0]
            self.nextkeys[0] = c_key
            self.nextkeys[1] = pastkey
        elif s == 'S':
            self.nowkey = self.nextkeys[1]
            self.nextkeys[1] = c_key
            self.nextkeys[0] = pastkey
        elif s == 'E':
            self.nowkey = self.nextkeys[2]
            self.nextkeys[2] = c_key
            self.nextkeys[3] = pastkey
        elif s == 'W':
            self.nowkey = self.nextkeys[3]
            self.nextkeys[3] = c_key
            self.nextkeys[2] = pastkey
        self.nowval = self.vals[self.nowkey]

v = list(map(int, input().split()))
s = input()
dice = DICE(v)
for i in s:
    dice.operate(i)
print(dice.nowval)

Submission status: Accepted

Solution code:
class Dice:
        def __init__(self, strLabel):
                self.label = strLabel.split()
                self.label[0] = int(self.label[0])
                self.label[1] = int(self.label[1])
                self.label[2] = int(self.label[2])
                self.label[3] = int(self.label[3])
                self.label[4] = int(self.label[4])
                self.label[5] = int(self.label[5])
        def roll(self, r):
                if r == 'E':
                        temp = self.label[3]
                        self.label[3] = self.label[5]
                        self.label[5] = self.label[2]
                        self.label[2] = self.label[0]
                        self.label[0] = temp
                elif r == 'W':
                        temp = self.label[0]
                        self.label[0] = self.label[2]
                        self.label[2] = self.label[5]
                        self.label[5] = self.label[3]
                        self.label[3] = temp
                elif r == 'N':
                        temp = self.label[0]
                        self.label[0] = self.label[1]
                        self.label[1] = self.label[5]
                        self.label[5] = self.label[4]
                        self.label[4] = temp
                elif r == 'S':
                        temp = self.label[4]
                        self.label[4] = self.label[5]
                        self.label[5] = self.label[1]
                        self.label[1] = self.label[0]
                        self.label[0] = temp

dice = Dice(input())
rollList = list(input())

for i in range(len(rollList)):
        dice.roll(rollList[i])

print(dice.label[0])

Submission status: Accepted

Solution code:
class dice:
    def __init__(self, first, second, third, fourth, fifth, sixth):
        self.up = first
        self.down = sixth
        self.S = second
        self.E = third
        self.N = fifth
        self.W = fourth
    def move(self, direction):
        if direction == "S":
            temp = self.up
            self.up = self.N
            self.N = self.down
            self.down = self.S
            self.S = temp 
            return self
        elif direction == "E":
            temp = self.up
            self.up = self.W
            self.W = self.down
            self.down = self.E
            self.E = temp
            return self
        elif direction == "N":
            temp = self.up
            self.up = self.S
            self.S = self.down
            self.down = self.N
            self.N = temp
            return self
        else:
            temp = self.up
            self.up = self.E
            self.E = self.down
            self.down = self.W
            self.W = temp
            return self

nums = list(map(int,input().split()))
dice1 = dice(nums[0], nums[1], nums[2], nums[3], nums[4], nums[5])
command = input()
commandlen = len(command)
for i in range(commandlen):
    dice1 = dice1.move(command[i])
print(str(dice1.up))

Submission status: Accepted

Solution code:
class Dice:

    def __init__(self, faces=(1, 2, 3, 4, 5, 6)):
        self.faces = faces
        self.current = {
            'top': faces[0],
            'south': faces[1],
            'east': faces[2],
            'west': faces[3],
            'north': faces[4],
            'bottom': faces[5],
        }

    def roll_north(self):
        new = dict()
        new['top'] = self.current['south']
        new['south'] = self.current['bottom']
        new['east'] = self.current['east']
        new['west'] = self.current['west']
        new['north'] = self.current['top']
        new['bottom'] = self.current['north']

        self.current = new

    def roll_south(self):
        new = dict()
        new['top'] = self.current['north']
        new['south'] = self.current['top']
        new['east'] = self.current['east']
        new['west'] = self.current['west']
        new['north'] = self.current['bottom']
        new['bottom'] = self.current['south']

        self.current = new

    def roll_east(self):
        new = dict()
        new['top'] = self.current['west']
        new['south'] = self.current['south']
        new['east'] = self.current['top']
        new['west'] = self.current['bottom']
        new['north'] = self.current['north']
        new['bottom'] = self.current['east']

        self.current = new

    def roll_west(self):
        new = dict()
        new['top'] = self.current['east']
        new['south'] = self.current['south']
        new['east'] = self.current['bottom']
        new['west'] = self.current['top']
        new['north'] = self.current['north']
        new['bottom'] = self.current['west']

        self.current = new

faces = input().split(' ')
for i, n in enumerate(faces):
    faces[i] = int(n)
rolls = [roll for roll in input()]

dice = Dice(faces=faces)
for roll in rolls:

    if roll == 'N':
        dice.roll_north()

    if roll == 'S':
        dice.roll_south()

    if roll == 'E':
        dice.roll_east()

    if roll == 'W':
        dice.roll_west()

print(dice.current['top'])

Submission status: Accepted

Solution code:
dice = input().split()
roll = input()
for s in roll:
    if s == "N":
        next = list("263415")
    elif s == "E":
        next = list("421653")
    elif s == "S":
        next = list("513462")
    else:
        next = list("326154")

    tmp = [0] * 6
    for i, n in enumerate(next):
        tmp[i] = dice[int(n) - 1]
    dice = tmp
print(dice[0])

Submission status: Accepted

Solution code:
def rotateDice(direction: str, dice: dict) -> dict:
    if direction == 'S':
        dice['S'], dice['F'], dice['N'], dice['B'] = dice['F'], dice['N'], dice['B'], dice['S']
    elif direction == 'E':
        dice['E'], dice['F'], dice['W'], dice['B'] = dice['F'], dice['W'], dice['B'], dice['E']
    elif direction == 'W':
        dice['W'], dice['F'], dice['E'], dice['B'] = dice['F'], dice['E'], dice['B'], dice['W']
    elif direction == 'N':
        dice['N'], dice['F'], dice['S'], dice['B'] = dice['F'], dice['S'], dice['B'], dice['N']
    return dice


dice_list = list(map(int, input().split()))
dice = {'FSEWNB'[i]: dice_list[i] for i in range(6)}
for c in input():
    dice = rotateDice(c, dice)
print(dice['F'])

Submission status: Accepted

Solution code:
class Dice():
    
    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]


    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5


    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])


    def get_Top(self):
        return self.number[0]


dice = Dice()
table = list(map(int,input().split()))
dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

loc_array = str(input())
for tmp_loc in loc_array:
    dice.roll(tmp_loc)
print("%d"%(dice.get_Top()))

Submission status: Accepted

Solution code:
f = list(map(int, input().split()))
m = input()
p = [0, 1, 2]
for i in range(len(m)):
	t = p[0]
	if m[i] == "N":
		p[0] = p[1]
		p[1] = 5 - t
	elif m[i] == "W":
		p[0] = p[2]
		p[2] = 5 - t
	elif m[i] == "S":
		p[0] = 5 - p[1]
		p[1] = t
	elif m[i] == "E":
		p[0] = 5 - p[2]
		p[2] = t
print(f[p[0]])

Submission status: Accepted

Solution code:
class Dice(object):
    def __init__(self, faces):
        self.top = faces[0]
        self.south = faces[1]
        self.east = faces[2]
        self.west = faces[3]
        self.north = faces[4]
        self.bottom = faces[5]

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


def main() -> None:
    *dice_values, = map(int, input().split())
    dice_x = Dice(dice_values)

    commands = input()
    for command in commands:
        dice_x.rotate(command)

    print(dice_x.top)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
dice = [int(i) for i in input().split()]
dir = input()
dev1 = [0, 1, 5, 4]
dev2 = [0, 3, 5, 2]
dev3 = [1, 3, 4, 2]
current = 0
for i in dir:
    if i == "W":
        current = dev2[dev2.index(current) - 1]
        dev1.reverse()
        dev1, dev3 = dev3, dev1
    elif i == "S":
        current = dev1[dev1.index(current) - 1]
        dev3.reverse()
        dev2, dev3 = dev3, dev2
    elif i == "N":
        if dev1.index(current) == 3:
            current = dev1[0]
        else:
            current = dev1[dev1.index(current) + 1]
        dev2.reverse()
        dev2, dev3 = dev3, dev2
    elif i == "E":
        if dev2.index(current) == 3:
            current = dev2[0]
        else:
            current = dev2[dev2.index(current) + 1]
        dev3.reverse()
        dev1, dev3 = dev3, dev1
print(dice[current])

Submission status: Accepted

Solution code:
n = list(map(int,input().split()))

order = input()
a1, a2, a3, a4, b1, b2 = 1, 5, 6, 2, 3, 4 

#print(a1, a2, a3, a4, b1, b2)
#print(order)
for i in order:
    if i == 'N':
        a_1 = a4
        a_2 = a1
        a_3 = a2
        a_4 = a3
        b_1 = b1
        b_2 = b2
        a1, a2, a3, a4, b1, b2 = a_1, a_2, a_3, a_4, b_1, b_2
        #print(a1, a2, a3, a4, b1, b2)
    elif i == 'S':
        a_1 = a2
        a_2 = a3
        a_3 = a4
        a_4 = a1
        b_1 = b1
        b_2 = b2
        a1, a2, a3, a4, b1, b2 = a_1, a_2, a_3, a_4, b_1, b_2
        #print(a1, a2, a3, a4, b1, b2)
    elif i == 'E':
        a_1 = b2
        a_2 = a2
        b_1 = a1
        a_3 = b1
        b_2 = a3
        a_4 = a4
        a1, a2, a3, a4, b1, b2 = a_1, a_2, a_3, a_4, b_1, b_2
        #print(a1, a2, a3, a4, b1, b2)
    else:
        a_1 = b1
        b_1 = a3
        a_3 = b2
        b_2 = a1
        a_2 = a2
        a_4 = a4
        a1, a2, a3, a4, b1, b2 = a_1, a_2, a_3, a_4, b_1, b_2
        #print(a1, a2, a3, a4, b1, b2)
        
print(n[int(a1)-1])

Submission status: Accepted

Solution code:
progression = list(map(int,input().split()))
order = input()

dice = progression
order_list = list(order)
direction = [0,"S","E","W","N",0]
up_down_0 = [0,0]
up_down_1 = [0,0]
up_down_2 = [0,0]


up_down_0[0],up_down_0[1] = progression[0],progression[5]
up_down_1[0],up_down_1[1] = progression[2],progression[3]
up_down_2[0],up_down_2[1] = progression[1],progression[4]

num_under = 0
num_upper = 0


for i in order_list:
    
    if i == "N":
        num_under = direction.index("N")

    elif i == "E":
        num_under = direction.index("E")
        
    elif i == "S":
        num_under = direction.index("S")
        
    elif i == "W":
        num_under = direction.index("W")
        
    dice[num_under],dice[5] =dice[5],dice[num_under]

    if dice[5] == up_down_0[0]:
        num_upper = dice.index(up_down_0[1])
        dice[num_upper],dice[0] = dice[0],dice[num_upper]

    elif dice[5] == up_down_0[1]:
        num_upper = dice.index(up_down_0[0])
        dice[num_upper],dice[0] = dice[0],dice[num_upper]

    elif dice[5] == up_down_1[0]:
        num_upper = dice.index(up_down_1[1])
        dice[num_upper],dice[0] = dice[0],dice[num_upper]

    elif dice[5] == up_down_1[1]:
        num_upper = dice.index(up_down_1[0])
        dice[num_upper],dice[0] = dice[0],dice[num_upper]

    elif dice[5] == up_down_2[0]:
        num_upper = dice.index(up_down_2[1])
        dice[num_upper],dice[0] = dice[0],dice[num_upper]


    elif dice[5] == up_down_2[1]:
        num_upper = dice.index(up_down_2[0])
        dice[num_upper],dice[0] = dice[0],dice[num_upper]

    
    direction[num_under],direction[num_upper] = direction[num_upper],direction[num_under]
    
    
print(dice[0])

Submission status: Accepted

Solution code:
def main():
    one, two, three, four, five, six = map(lambda n: int(n), input().split(' '))
    d = Dice(one, two, three, four, five, six)
    s = input()
    for i in s:
        d.roll(i)
    print(d.top)

class Dice:
    def __init__(self, one, two, three, four, five, six):
        self.top = one
        self.bottom = six
        self.s = two
        self.n = five
        self.e = three
        self.w = four 
    

    def roll(self, d):
        top = self.top
        bottom = self.bottom
        s = self.s
        n = self.n
        e = self.e
        w = self.w
        if d == "S":
            self.bottom = s
            self.s = top
            self.top = n
            self.n = bottom
        elif d == "N":
            self.bottom = n
            self.s = bottom
            self.top = s
            self.n = top
        elif d == "W":
            self.bottom = w
            self.w = top
            self.top = e
            self.e = bottom
        else:
            self.bottom = e
            self.e = top
            self.top = w
            self.w = bottom
        

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
d=input().split()
for o in input():d=[d[int(i)]for i in{'N':"152304",'W':"215043",'E':"310542",'S':"402351"}[o]]
print(d[0])

Submission status: Accepted

Solution code:
import sys

INVERSE_ROTATIONS = {
    'N': [
        [1, 0, 0],
        [0, 0, -1],
        [0, 1, 0]
    ],
    'S': [
        [1, 0, 0],
        [0, 0, 1],
        [0, -1, 0]
    ],
    'E': [
        [0, 0, -1],
        [0, 1, 0],
        [1, 0, 0]
    ],
    'W': [
        [0, 0, 1],
        [0, 1, 0],
        [-1, 0, 0]
    ]
}


def mul(mat1, mat2):
    return [
        [
            sum(mat1[i][k] * mat2[k][j] for k in range(3))
            for j in range(3)
        ]
        for i in range(3)
    ]


faces = [int(n) for n in sys.stdin.readline().strip().split()]
commands = sys.stdin.readline().strip()

rotation = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
for c in commands:
    rotation = mul(rotation, INVERSE_ROTATIONS[c])
location = [rotation[i][2] for i in range(3)]

number = {
    (1, 0, 0): 3,
    (-1, 0, 0): 4,
    (0, 1, 0): 5,
    (0, -1, 0): 2,
    (0, 0, 1): 1,
    (0, 0, -1): 6
}[tuple(location)]

print(faces[number - 1])

Submission status: Accepted

Solution code:
dice=input().split()
dice=[int(s) for s in dice]
deg=list(input())
for i in deg:
    if i=="E":
        dice[0],dice[2],dice[5],dice[3]=dice[3],dice[0],dice[2],dice[5]
    if i=="W":
        dice[0],dice[2],dice[5],dice[3]=dice[2],dice[5],dice[3],dice[0]
    if i=="N":
        dice[0],dice[1],dice[5],dice[4]=dice[1],dice[5],dice[4],dice[0]
    if i=="S":
        dice[0],dice[4],dice[5],dice[1]=dice[4],dice[5],dice[1],dice[0]
print(dice[0])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, face_val=None):
        self.top = 1
        self.front = 2
        self.left = 4
        self.FaceValue = {}
        if face_val is None or len(face_val) != 6:
            face_val = [1, 2, 3, 4, 5, 6]

        for i, val in enumerate(face_val):
            self.FaceValue[i+1] = val

    def dice_move(self, direction):
        if direction == 'S':
            tmp = self.top
            self.top = 7 - self.front
            self.front = tmp
        elif direction == 'W':
            tmp = self.top
            self.top = 7 - self.left
            self.left = tmp
        elif direction == 'E':
            tmp = self.top
            self.top = self.left
            self.left = 7 - tmp
        elif direction == 'N':
            tmp = self.top
            self.top = self.front
            self.front = 7 - tmp

    def top_value(self):
        return self.FaceValue[self.top]

    def __repr__(self):
        return f'({self.top},{self.front},{self.left})'


faces = input().split()
directions = input()

dice = Dice(faces)
for direction in directions:
    #print(direction, dice, end=',to,')
    dice.dice_move(direction)
    #print(dice)

print(dice.top_value())