Problem:


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

Dice III

  Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.

Input

  In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels.

    In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.

Output

  Print "Yes" if two dices are identical, otherwise "No" in a line.

Constraints

$0 \leq $ the integer assigned to a face $ \leq 100$

Sample Input 1

1 2 3 4 5 6
6 2 4 3 5 1

Sample Output 1

Yes

Sample Input 2

1 2 3 4 5 6
6 5 4 3 2 1

Sample Output 2

No



Sample input:
1 2 3 4 5 6
6 2 4 3 5 1


Sample output:
Yes

Submission status: Accepted

Solution code:
#アルゴリズム関数-サイコロを回転させる
def dice_rotation(list1, str1):
    if str1 == "S":
        list1[0],list1[1],list1[4],list1[5] = list1[4],list1[0],list1[5],list1[1]
    elif str1 == "E":
        list1[0],list1[2],list1[3],list1[5] = list1[3],list1[0],list1[5],list1[2]
    elif str1 == "N":
        list1[0],list1[1],list1[4],list1[5] = list1[1],list1[5],list1[0],list1[4]
    elif str1 == "W":
        list1[0],list1[2],list1[3],list1[5] = list1[2],list1[5],list1[0],list1[3]
    return list1

#アルゴリズム関数-上面・前面の番号を指定番号へサイコロを回転させる
def dice_find(list1, int1, int2):
    position_numnber = list1.index(int2)
    if position_numnber == 0:
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 2:
        list1 = dice_rotation(list1, "W")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 3:
        list1 = dice_rotation(list1, "E")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 4:
        list1 = dice_rotation(list1, "S")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 5:
        list1 = dice_rotation(list1, "N")
    position_numnber = list1.index(int1)
    if position_numnber == 2:
        list1 = dice_rotation(list1, "W")
    elif position_numnber == 3:
        list1 = dice_rotation(list1, "E")
    elif position_numnber == 5:
        list1 = dice_rotation(list1, "W")
        list1 = dice_rotation(list1, "W")
    return list1

#インプットdataの格納
input_number = list(map(int, input().split()))
check_number = list(map(int, input().split()))

#処理の実行
check_number = dice_find(check_number, input_number[0], input_number[1])

#結果表示
if input_number == check_number:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, x):
        self.top = x[0]
        self.front = x[1]
        self.right = x[2]
        self.left = x[3]
        self.back = x[4]
        self.bottom = x[5]

    def N(self):
        self.top, self.front, self.bottom, self.back = self.front, self.bottom, self.back, self.top

    def E(self):
        self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom

    def S(self):
        self.top, self.front, self.bottom, self.back = self.back, self.top, self.front, self.bottom

    def W(self):
        self.top, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.top

    def up_front_to_right(self, top, front):
        if (top, front) in [(self.top, self.front), (self.front, self.bottom), (self.bottom, self.back), (self.back, self.top)]:
            return self.right
        elif (top, front) in [(self.front, self.top), (self.bottom, self.front), (self.back, self.bottom), (self.top, self.back)]:
            return self.left
        elif (top, front) in [(self.left, self.front), (self.front, self.right), (self.right, self.back), (self.back, self.left)]:
            return self.top
        elif (top, front) in [(self.front, self.left), (self.right, self.front), (self.back, self.right), (self.left, self.back)]:
            return self.bottom
        elif (top, front) in [(self.top, self.left), (self.left, self.bottom), (self.bottom, self.right), (self.right, self.top)]:
            return self.front
        elif (top, front) in [(self.left, self.top), (self.bottom, self.left), (self.right, self.bottom), (self.top, self.right)]:
            return self.back
        else:
            return -1
            
    def inverse(self,a):
        if a==self.top:
            return self.bottom
        elif a==self.front:
            return self.back
        elif a==self.right:
            return self.left
        elif a==self.left:
            return self.right
        elif a==self.back:
            return self.front
        elif a==self.front:
            return self.back
        else:
            return -1
            
*x,=map(int,input().split())
*y,=map(int,input().split())
dice0=Dice(x)
dice1=Dice(y)
for i in x:
    for j in x:
        if i!=j and i!=dice0.inverse(j):
            a=dice0.up_front_to_right(i,j)
            b=dice1.up_front_to_right(i,j)
            if a!=b:
                print('No')
                exit()
print('Yes')

Submission status: Accepted

Solution code:
import math

class Dice():
    top   = 0 #上
    left  = 0 #左
    right = 0 #右
    front = 0 #前面
    back  = 0 #後面
    below = 0 #真下

    DEBUG_MODE = False
    def __init__(self,lst,dbg = False):
        if len(lst) == 6:
            self.top   = lst[0]
            self.front = lst[1]
            self.right = lst[2]
            self.left  = lst[3]
            self.back  = lst[4]
            self.below = lst[5]

        if dbg == True:
            self.DEBUG_MODE = True
        else:
            self.DEBUG_MODE = False
    
    def rotate(self,string):
        
        for ch in string:
            if   ch == 'W':
                self.left,self.top,self.right,self.below = self.top,self.right,self.below,self.left

            elif ch == 'E':
                self.left,self.top,self.right,self.below = self.below,self.left,self.top,self.right

            elif ch == 'S':
                self.top,self.back,self.below,self.front = self.back,self.below,self.front,self.top

            elif ch == 'N':
                self.top,self.back,self.below,self.front = self.front,self.top,self.back,self.below
            
            # デバッグモードなら全部の値をモニタする
            if self.DEBUG_MODE:
                self.dbg_PRINT_ALL_VALUE()

    def front_and_top_to_right(self,top,front):

        for i in range(4):
            for j in range(4):
                if self.top == top and self.front == front:
                    return self.right
                self.rotate("W")
            self.rotate("S")
        
        self.rotate("NES") #ヨコ回転
        
        for i in range(2):
            for j in range(4):
                if self.top == top and self.front == front:
                    return self.right
                self.rotate("W")
            self.rotate("SS")
        
        return None

    def equals(self,dice):
        if not isinstance(dice,Dice):
            return False

        for i in range(4):
            for j in range(4):
                if self.__non_rotate_equals(dice):
                    return True
                self.rotate("W")
            self.rotate("S")
        
        self.rotate("NES") #ヨコ回転
        
        for i in range(2):
            for j in range(4):
                if self.__non_rotate_equals(dice):
                    return True
                self.rotate("W")
            self.rotate("SS")
        
        return False

    def __non_rotate_equals(self,dice):
        if (self.top   == dice.top   and
            self.left  == dice.left  and
            self.right == dice.right and
            self.front == dice.front and
            self.back  == dice.back  and
            self.below == dice.below ) :
            return True
        
        return False


        
    def get_topvalue(self):
        return self.top
    
    def dbg_PRINT_ALL_VALUE(self):
        print(f"        bk:{self.back:04} ")
        print(f"le:{self.left:04} tp:{self.top:04} ri:{self.right:04} be:{self.below:04}")
        print(f"        fr:{self.front:04} ")

# 実コードはここに書く
lst  = list(map(int,input().split()))
lst2 = list(map(int,input().split()))
dice = Dice(lst)
dice2 = Dice(lst2)

if dice.equals(dice2):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import random
class Dice:
    def __init__(self, dice):
        self.dice = dice
        self.rule={'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3)}
    def output(self):
        return self.dice
    def move(self, direction):
        for _ in direction: self.dice = [self.dice[y] for y in self.rule[_]]
        return self.dice

dice_1 = Dice([int(x) for x in input().split()])
dice_2 = Dice([int(x) for x in input().split()])

Dir = 'NSEW'

for _ in range(10000):
    dice_2.move(Dir[random.randint(0,3)])
    if dice_1.output() == dice_2.output(): break

print('No') if _ == 9999 else print('Yes')

Submission status: Accepted

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

def dicing(lis, inst):
    if inst == 'N':
        ans_lis = [lis[1],lis[5],lis[2],lis[3],lis[0],lis[4]]
    if inst == 'W':
        ans_lis = [lis[2],lis[1],lis[5],lis[0],lis[4],lis[3]]
    if inst == 'S':
        ans_lis = [lis[4],lis[0],lis[2],lis[3],lis[5],lis[1]]
    if inst == 'E':
        ans_lis = [lis[3],lis[1],lis[0],lis[5],lis[4],lis[2]]
    
    return(ans_lis)

def turn_right(lis):
    inst = list('ENW')
    for i in range(len(inst)):
        lis = dicing(lis, inst[i])
    return(lis)

def find_above(lis, num1, num2):
    inst1 = list('NNNEWW')
    for i in range(len(inst1)):
        if lis[0] == num1 and lis[5] == num2:
            break
        
        lis = dicing(lis, inst1[i])
        if lis[0] == num1 and lis[5] == num2:
            break
    return(lis)

YN = 'No'

lis = [1,2,3,4,5,6]
lis = find_above(dice1, dice2[0], dice2[5])
for j in range(4):
    lis = turn_right(lis)
    if lis == dice2:
        YN = 'Yes'
        break

print(YN)

Submission status: Accepted

Solution code:
from collections import deque

class Dice():
    def __init__(self, seq):
        self.v = deque([seq[5], seq[4], seq[0], seq[1]])
        self.h = deque([seq[3], seq[0], seq[2], seq[5]])

    def lotate(self, direction):

        if   direction == "E":
            self.h.rotate()
            self.v[2] = self.h[1]
            self.v[0] = self.h[3]

        elif direction == "W":
            self.h.rotate(-1)
            self.v[2] = self.h[1]
            self.v[0] = self.h[3]

        elif direction == "N":
            self.v.rotate(-1)
            self.h[1] = self.v[2]
            self.h[3] = self.v[0]

        elif direction == "S":
            self.v.rotate()
            self.h[1] = self.v[2]
            self.h[3] = self.v[0]

        else:
            pass

    def disp_top_face(self):
        return self.v[2]

    def disp_front_face(self):
        return self.v[3]

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

    def disp_right_face(self):
        return self.h[2]

    def disp_left_face(self):
        return self.h[0]

    def disp_bottom_face(self):
        return self.h[3]

if __name__ == "__main__":

    param = input().split(" ")

    seq = [int(a) for a in param]
    d1 = Dice(seq)

    param = input().split(" ")

    seq = [int(a) for a in param]
    d2 = Dice(seq)

    top1 = d1.disp_top_face()
    front1 = d1.disp_front_face()

    flag = 1

    while(flag):

        for _ in range(4):

            d2.lotate("S")

            if d2.disp_top_face() == top1:
                flag = 0
                break

        if flag :
            d2.lotate("E")

    for _ in range(4):

        if d1.disp_front_face() == d2.disp_front_face():
            break

        d2.lotate("E")
        d2.lotate("S")
        d2.lotate("W")

    # print(str(d2.disp_top_face()) + " " + str(d1.disp_top_face()))
    # print(str(d2.disp_front_face()) + " " + str(d1.disp_front_face()))
    # print(str(d2.disp_bottom_face()) + " " + str(d1.disp_bottom_face()))
    # print(str(d2.disp_back_face()) + " " + str(d1.disp_back_face()))
    # print(str(d2.disp_left_face()) + " " + str(d1.disp_left_face()))
    # print(str(d2.disp_right_face()) + " " + str(d1.disp_right_face()))

    if d2.disp_bottom_face() == d1.disp_bottom_face() and \
       d2.disp_front_face() == d1.disp_front_face() and \
       d2.disp_left_face() == d1.disp_left_face() and \
       d2.disp_right_face() == d1.disp_right_face() and \
       d2.disp_back_face() == d1.disp_back_face():
       print("Yes")
    else:
       print("No")

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self, dice_labels):
        self.label = {
            'top': dice_labels[0],
            'south': dice_labels[1],
            'east': dice_labels[2],
            'west': dice_labels[3],
            'north': dice_labels[4],
            'bottom': dice_labels[5]
        }

    def roll(self, str_direction):
        if str_direction == 'E':
            self.__roll_to_east()
        elif str_direction == 'W':
            self.__roll_to_west()
        elif str_direction == 'S':
            self.__roll_to_south()
        elif str_direction == 'N':
            self.__roll_to_north()

    def turn(self, str_direction):
        if str_direction == 'L':
            self.__turn_left()
        elif str_direction == 'R':
            self.__turn_right()

    def __roll_to_east(self):
        self.label['top'], self.label['east'], self.label['west'], self.label['bottom'] = (self.label['west'], self.label['top'], self.label['bottom'], self.label['east'])

    def __roll_to_west(self):
        self.label['top'], self.label['east'], self.label['west'], self.label['bottom'] = (self.label['east'], self.label['bottom'], self.label['top'], self.label['west'])

    def __roll_to_south(self):
        self.label['top'], self.label['south'], self.label['north'], self.label['bottom'] = (self.label['north'], self.label['top'], self.label['bottom'], self.label['south'])

    def __roll_to_north(self):
        self.label['top'], self.label['south'], self.label['north'], self.label['bottom'] = (self.label['south'], self.label['bottom'], self.label['top'], self.label['north'])

    def __turn_right(self):
        self.label['south'], self.label['east'], self.label['west'], self.label['north'] = (self.label['east'], self.label['north'], self.label['south'], self.label['west'])

    def __turn_left(self):
        self.label['south'], self.label['east'], self.label['west'], self.label['north'] = (self.label['west'], self.label['south'], self.label['north'], self.label['east'])

def check_same_dice(dice1, dice2):
    for direction in ['top', 'bottom', 'east', 'west', 'south', 'north']:
        if dice1.label[direction] != dice2.label[direction]:
            return False
    return True

dice_labels1 = input().split(' ')
dice_labels2 = input().split(' ')
dice1 = Dice(dice_labels1)
dice2 = Dice(dice_labels2)
same_pattern_list = []

for i in range(0, 4):
    for j in range(0, 4):
        for k in range(0, 4):
            dice2.roll('E')
            same_pattern_list.append(check_same_dice(dice1, dice2))
        dice2.roll('N')
        same_pattern_list.append(check_same_dice(dice1, dice2))
    dice2.turn('R')
    same_pattern_list.append(check_same_dice(dice1, dice2))

if True in same_pattern_list:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
D = [
    (1, 5, 2, 3, 0, 4), # 'U'
    (3, 1, 0, 5, 4, 2), # 'R'
    (4, 0, 2, 3, 5, 1), # 'D'
    (2, 1, 5, 0, 4, 3), # 'L'
]

*L1, = map(int, input().split())
*L2, = map(int, input().split())

p = (0, 0, 0, 1, 1, 2, 2, 3)*3
ok = 0
for k in p:
    if L1 == L2:
        ok = 1
    L2[:] = [L2[e] for e in D[k]]

print("Yes" if ok else "No")

Submission status: Accepted

Solution code:
def lotate(dic, dire):
    if dire == 'N':
        x,y,z,w = dic['up'], dic['back'], dic['bottom'], dic['front']
        dic['back'], dic['bottom'], dic['front'], dic['up'] = x,y,z,w
    elif dire == 'S':
        x, y, z, w = dic['up'], dic['back'], dic['bottom'], dic['front']
        dic['front'], dic['up'], dic['back'], dic['bottom'] = x, y, z, w
    elif dire == 'W':
        x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']
        dic['left'], dic['bottom'], dic['right'], dic['up'] = x, y, z, w
    elif dire == 'E':
        x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']
        dic['right'], dic['up'], dic['left'], dic['bottom'] = x, y, z, w
    return dic


a1,b1,c1,d1,e1,f1 = map(int, input().split())
a2,b2,c2,d2,e2,f2 = map(int, input().split())
dic1 = {'up': a1, 'front': b1, 'right': c1, 'left': d1, 'back': e1, 'bottom': f1}
dic2 = {'up': a2, 'front': b2, 'right': c2, 'left': d2, 'back': e2, 'bottom': f2}
ans = 'No'
if dic1 == dic2:
    ans = 'Yes'
else:
    s = 'EEENEEENEEESEEESEEENEEEN'
    for i in s:
        dic2 = lotate(dic2, i)
        if dic1 == dic2:
            ans = 'Yes'
            break
print(ans)

Submission status: Accepted

Solution code:
import random


class Dice(object):

    def __init__(self, *args):
        self.faces = [None]
        self.faces.extend(args)
        self.top = self.faces[1]
        self.up = self.faces[5]
        self.down = self.faces[2]
        self.left = self.faces[4]
        self.right = self.faces[3]
        self.back = self.faces[6]

    def roll(self, direction):
        if direction == "N":
            self.top, self.up, self.down, self.back = self.down, self.top, self.back, self.up
        elif direction == "S":
            self.top, self.up, self.down, self.back = self.up, self.back, self.top, self.down
        elif direction == "W":
            self.top, self.left, self.right, self.back = self.right, self.top, self.back, self.left
        elif direction == "E":
            self.top, self.left, self.right, self.back = self.left, self.back, self.top, self.right
        else:
            raise ValueError("{} is not valid direction.".format(direction))

    def __eq__(self, other):
        return (
           self.top, self.up, self.left, self.down, self.right, self.back
        ) == (
            other.top, other.up, other.left, other.down, other.right, other.back
        )


f1 = [int(i) for i in input().split()]
f2 = [int(i) for i in input().split()]
dice1 = Dice(*f1)
dice2 = Dice(*f2)
ans = "No"
i = 0
while i < 10000:
    if dice1 == dice2:
        ans = "Yes"
        break
    dice2.roll(random.choice(["N", "S", "W", "E"]))
    i += 1
print(ans)

Submission status: Accepted

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

def East(a,b,c,d,e,f):
    return [d, b, a, f, e, c]
def West(a,b,c,d,e,f):
    return [c, b, f, a, e, d]
def South(a,b,c,d,e,f):
    return [e, a, c, d, f, b]
def North(a,b,c,d,e,f):
    return [b, f, c, d, a, e]
def Rot(a,b,c,d,e,f):
    return [a,d,b,e,c,f]



flag=0
for idx in range(0, 5):
    change=South(*change)
    if change==change_after:
        flag=flag+1
    for idx2 in range(0,4):
        change=Rot(*change)
        if change==change_after:
           flag=1+flag
           
for idx in range(0, 5):
    change=West(*change)
    if change==change_after:
        flag=flag+1
    for idx2 in range(0,4):
        change=Rot(*change)
        if change==change_after:
           flag=1+flag
if flag==0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self, up, back, right, left, front, down):
        self.up = up
        self.down = down
        self.right = right
        self.left = left
        self.front = front
        self.back = back
    
    def north(self):
        temp = self.up
        self.up = self.back
        self.back = self.down
        self.down = self.front
        self.front = temp
    
    def south(self):
        temp = self.up
        self.up = self.front
        self.front = self.down
        self.down = self.back
        self.back = temp
        
    def east(self):
        temp = self.up
        self.up = self.left
        self.left = self.down
        self.down = self.right
        self.right = temp
    
    def west(self):
        temp = self.up
        self.up = self.right
        self.right = self.down
        self.down = self.left
        self.left = temp
    
    def counterclockwise(self):
        temp = self.back
        self.back = self.left
        self.left = self.front
        self.front = self.right
        self.right = temp
    
    def clockwise(self):
        temp = self.back
        self.back = self.right
        self.right = self.front
        self.front = self.left
        self.left = temp
        
    def operate(self, op):
        if op == "N":
            self.north()
        elif op == "S":
            self.south()
        elif op == "E":
            self.east()
        elif op == "W":
            self.west()
        
    def fix_up(self, up):
        if self.down == up:
            self.north()
            self.north()
        elif self.right == up:
            self.west()
        elif self.left == up:
            self.east()
        elif self.front == up:
            self.south()
        elif self.back == up:
            self.north()

    def fix_back_with_fixed_up(self, back):
        if self.right == back:
            self.clockwise()
        elif self.left == back:
            self.counterclockwise()
        elif self.front == back:
            self.clockwise()
            self.clockwise()
            
    def equals_narrow_sense(self, dice):
        if self.up == dice.up and self.down == dice.down and self.right == dice.right and self.left == dice.left and self.back == dice.back and self.front == dice.front:
            return True
        else:
            return False
            
            
up, back, right, left, front, down = map(int, input().split())
dice1 = Dice(up, back, right, left, front, down)

up, back, right, left, front, down = map(int, input().split())
dice2 = Dice(up, back, right, left, front, down)

equal_flag = False
for i in range(6):
    if 0 < i <= 3:
        dice1.north()
    elif i == 4:
        dice1.west()
    elif i == 5:
        dice1.east()
        dice1.east()
    
    for l in range(4):
        dice1.clockwise()
        
        for j in range(6):
            if 0 < j <= 3:
                dice2.north()
            elif j == 4:
                dice2.west()
            elif j == 5:
                dice2.east()
                dice2.east()
                
            for k in range(4):
                dice2.clockwise()

                if dice1.equals_narrow_sense(dice2):
                    equal_flag = True
                    break

        if equal_flag:
            break

if equal_flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys

class Dice():
    top=0
    n=1
    e=3
    w=2
    s=4
    bottom=5
    dice=[1,2,3,4,5,6]
    def __init__(self,num):
        self.dice=num

    def roll(self,direction):
        if(direction=="N"):
            self.top,self.bottom,self.n,self.s = self.n,5-self.n,5-self.top,self.top
        elif(direction=="E"):
            self.top,self.bottom,self.e,self.w = self.e,5-self.e,5-self.top,self.top
        elif(direction=="W"):
            self.top,self.bottom,self.e,self.w = self.w,5-self.w,self.top,5-self.top
        elif(direction=="S"):
            self.top,self.bottom,self.n,self.s = self.s,5-self.s,self.top,5-self.top

    def equal(self,another):
        if(self.dice[self.top] != another.dice[another.top]):
            return False
        if(self.dice[self.n] != another.dice[another.n]):
            return False
        if(self.dice[self.e] != another.dice[another.e]):
            return False
        if(self.dice[self.w] != another.dice[another.w]):
            return False
        if(self.dice[self.s] != another.dice[another.s]):
            return False
        if(self.dice[self.bottom] != another.dice[another.bottom]):
            return False

        return True


dicea=Dice(list(map(int,input().split())))
diceb=Dice(list(map(int,input().split())))

roll_order="NNNNWNNNWNNNENNNENNNWNNNN"
for i in range(len(roll_order)):
    if(dicea.equal(diceb)):
        print("Yes")
        sys.exit()
    else:
        diceb.roll(roll_order[i])
print("No")

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,u,s,e,w,n,d):
        self.u = u
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.d = d
    
    def rot(self,way):
        # vertically
        if way == 0:
            c = self.u
            self.u = self.n
            self.n = self.d
            self.d = self.s
            self.s = c
        #rotate
        if way == 1:
            c = self.e
            self.e = self.n
            self.n = self.w
            self.w = self.s
            self.s = c
        #holizantally
        if way == 2:
            c = self.w
            self.w = self.d
            self.d = self.e
            self.e = self.u
            self.u = c

u,s,e,w,n,d = map(int,input().split())
dice1 = Dice(u,s,e,w,n,d)
uu,ss,ee,ww,nn,dd = map(int,input().split())
dice2 = Dice(uu,ss,ee,ww,nn,dd)

count = 0
flag = 0
while True:
    if dice1.u == dice2.u:
        for s in range(5):
            if dice1.s == dice2.s and dice1.e == dice2.e and dice1.w == dice2.w and dice1.n == dice2.n:
                if dice1.d == dice2.d:
                    flag = 1
                    print('Yes')
                break
            else:
                dice2.rot(1)
        if not flag:
            if dice1.d == dice2.s and dice1.u == dice2.n:
                print('Yes')
                
            elif dice1.d == dice2.e and dice1.u == dice2.w:
                print('Yes')
                
            elif dice1.d == dice2.w and dice1.u == dice2.e:
                print('Yes')
                
            elif dice1.d == dice2.n and dice1.u == dice2.s:
                print('Yes')
            else:
                print('No')
        break
    elif count < 5:
        dice2.rot(0)
        count += 1
    elif count == 5:
        dice2.rot(1)
        count = 0

Submission status: Accepted

Solution code:
def roll(s, rolllist):
    news = list(s)
    for i in range(6):
        news[i] = s[rolllist[i]]
    return news


rl = {0: [0, 1, 2, 3, 4, 5],
      1: [1, 5, 2, 3, 0, 4],  # N
      2: [2, 1, 5, 0, 4, 3],  # W
      3: [3, 1, 0, 5, 4, 2],  # E
      4: [4, 0, 2, 3, 5, 1],  # S
      5: [5, 4, 2, 3, 1, 0]}
rollz = [0, 3, 1, 4, 2, 5]
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
if not (s1[0] in s2):
    print("No")
    exit()
# t = s2.index(s1[0])
tl = [i for i, x in enumerate(s2) if x == s1[0]]
for t in tl:
    s2 = roll(s2, rl[t])
    ss = s2
    for i in range(6):
        if s1 == ss:
            print("Yes")
            exit()
        ss = roll(ss, rollz)
print("No")

Submission status: Accepted

Solution code:
face = [0]*6
class Dice():

    def __init__(self):
        self.number = [inp[i] for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'

    def setnumbers(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 spin(self, command):
        for i in range(6):
            face[i] = self.number[i]
        if command == 'S':
            self.setnumbers(face[4], face[0], face[2], face[3], face[5], face[1])
            # print('command is S')
        elif command == 'N':
            self.setnumbers(face[1], face[5], face[2], face[3], face[0], face[4])
            # print('command is N')
        elif command == 'E':
            self.setnumbers(face[3], face[1], face[0], face[5], face[4], face[2])
            # print('command is E')
        elif command == 'W':
            self.setnumbers(face[2], face[1], face[5], face[0], face[4], face[3])
            # print('command is W')
    def equal(self, another):
        set = False
        for i in self.order:
            self.spin(i)
            FLAG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLAG = False
                    break
            if FLAG == True:
                return True
        return set
inp = list(map(int, input().split()))

dice1 = Dice()
dice2 = Dice()

dice1.setnumbers(inp[0], inp[1], inp[2], inp[3], inp[4], inp[5])
inp = list(map(int, input().split()))
dice2.setnumbers(inp[0], inp[1], inp[2], inp[3], inp[4], inp[5])
if dice1.equal(dice2):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
f = list(map(int, input().split()))
s = list(map(int, input().split()))
yes = 0

for _ in range(4):
    s[0],s[2],s[5],s[3] = s[2],s[5],s[3],s[0]
    for _ in range(4):
        s[1],s[2],s[4],s[3] = s[2],s[4],s[3],s[1]
        if f == s:
            yes = 1

for _ in range(4):
    s[0],s[1],s[5],s[4] = s[1],s[5],s[4],s[0]
    for _ in range(4):
        s[1],s[2],s[4],s[3] = s[2],s[4],s[3],s[1]
        if f == s:
            yes = 1

if yes == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import random

class Dice():
    def __init__(self):
        self.face = [i for i in range(6)]
        self.memo = [i for i in range(6)]

    def setface(self,initface):
        for i in range(6):
            self.face[i] = initface[i]

    def roll(self,direction):
        for i in range(6):
            self.memo[i] = self.face[i]
        index = {'E':(3,1,0,5,4,2),'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'W':(2,1,5,0,4,3)}
        for i in range(6):
            self.face[i] = self.memo[index[direction][i]]

    def top(self):
        return self.face[0]

dice1 = Dice()
dice2 = Dice()
dice1.setface(list(map(int,input().split())))
dice2.setface(list(map(int,input().split())))

for i in range(10000):
    dice2.roll(['E','N','S','W'][random.randint(0,3)])
    for j in range(6):
        if dice1.face[j]!=dice2.face[j]:
            break
    else:
        print('Yes')
        break
else:
    print('No')

Submission status: Accepted

Solution code:
class dice:
    def __init__(self, f):
        assert(len(f) == 6)
        self.face = f
        self.N = [1, 5, 2, 3, 0, 4]
        self.S = [4, 0, 2, 3, 5, 1]
        self.E = [3, 1, 0, 5, 4, 2]
        self.W = [2, 1, 5, 0, 4, 3]
        self.R = [0, 2, 4, 1, 3, 5]

    def rotate(self, dir):
        rot = self.__getattribute__(dir)
        old = self.face
        new = [-1 for _ in range(6)]
        for i in range(6):
            new[i] = old[rot[i]]
        self.face = new

    def __eq__(self, E):
        D = self
        for _ in range(4):
            # print(f'a {D.face}')
            if D.face[0] == E.face[0]:
                for _ in range(4):
                    # print(f'b {D.face}')
                    if D.face == E.face:
                        return True
                    else:
                        D.rotate('R')
            D.rotate('N')
        for _ in range(4):
            # print(f'c {D.face}')
            if D.face[0] == E.face[0]:
                for _ in range(4):
                    # print(f'd {D.face}')
                    if D.face == E.face:
                        return True
                    else:
                        D.rotate('R')
            D.rotate('E')
        return False

A = dice(list(map(int, input().split())))
B = dice(list(map(int, input().split())))
print('Yes' if A == B else 'No')