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:
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
   
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
   
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
   
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]
    
label = list(map(int,input().split()))
d0 = dice(label)
d1 = list(map(int,input().split()))
for op in 'EEENEEENEEESEEESEEENEEEN':
    if d0.get_label() == d1:
        print('Yes')
        break
    d0.roll(op)
else:
    print('No')

Submission status: Accepted

Solution code:
import sys


class Dice(object):
    def __init__(self, faces: list):
        self.list_sn = [faces[5], faces[4], faces[0], faces[1]]  # 6,5,1,2
        self.list_we = [faces[5], faces[2], faces[0], faces[3]]  # 6,5,1,2

    def _roll_positive(self, list_a: list, list_b: list) -> list:
        list_a = list_a[1:] + list_a[0:1]  # Roll one unit in the positive direction.
        list_b[0] = list_a[0]  # Change the bottom face.
        list_b[2] = list_a[2]  # Change the top face.
        return [list_a, list_b]

    def _roll_negative(self, list_a: list, list_b: list) -> list:
        list_a = list_a[3:] + list_a[0:3]
        list_b[0] = list_a[0]  # Change the bottom face.
        list_b[2] = list_a[2]  # Change the top face.
        return [list_a, list_b]

    def roll(self, direction: str):
        if "N" == direction:
            self.list_sn, self.list_we = self._roll_positive(self.list_sn, self.list_we)
        elif "S" == direction:
            self.list_sn, self.list_we = self._roll_negative(self.list_sn, self.list_we)
        elif "E" == direction:
            self.list_we, self.list_sn = self._roll_positive(self.list_we, self.list_sn)
        else:
            self.list_we, self.list_sn = self._roll_negative(self.list_we, self.list_sn)


if __name__ == "__main__":
    faces_dice_a = list(map(lambda x: int(x), input().split()))
    faces_dice_b = list(map(lambda x: int(x), input().split()))
    Dice_a = Dice(faces_dice_a)
    Dice_b = Dice(faces_dice_b)

    for command in "NNNNWNNNWNNNENNNENNNWNNN":  # Check all patterns.
        Dice_b.roll(command)
        if Dice_a.list_sn == Dice_b.list_sn and Dice_a.list_we == Dice_b.list_we:
            print("Yes")
            sys.exit()    
    print("No")

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)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'

    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 equals(self,another):

        ret = False;

        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG = False
                    break
            if FLG == True:
                return True

        return ret

diceA = Dice()
diceB = Dice()

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

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

if diceA.equals(diceB):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#ダイスオブジェクト#############################################################
class dice():
    
    def __init__(self,a,b,c,d,e,f):
        self.A=[a,b,c,d,e,f]
#判定オブジェクト###############################################################
class determine():

    def __init__(self,P,Q):
        self.P=P
        self.Q=Q
    def run(self):
  
        if (self.P.A[0]==self.Q.A[0] and self.P.A[5]==self.Q.A[5]):

            if self.P.A[1]==self.Q.A[1] and self.P.A[2]==self.Q.A[2] and self.P.A[3]==self.Q.A[3] and self.P.A[4]==self.Q.A[4]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[2] and self.P.A[2]==self.Q.A[4] and self.P.A[3]==self.Q.A[1] and self.P.A[4]==self.Q.A[3]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[4] and self.P.A[2]==self.Q.A[3] and self.P.A[3]==self.Q.A[2] and self.P.A[4]==self.Q.A[1]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[3] and self.P.A[2]==self.Q.A[1] and self.P.A[3]==self.Q.A[4] and self.P.A[4]==self.Q.A[2]:
                print("Yes")
            else:
                print("No")
        elif (self.P.A[0]==self.Q.A[1] and self.P.A[5]==self.Q.A[4]):
            if self.P.A[1]==self.Q.A[5] and self.P.A[2]==self.Q.A[2] and self.P.A[3]==self.Q.A[3] and self.P.A[4]==self.Q.A[0]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[2] and self.P.A[2]==self.Q.A[0] and self.P.A[3]==self.Q.A[5] and self.P.A[4]==self.Q.A[3]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[0] and self.P.A[2]==self.Q.A[3] and self.P.A[3]==self.Q.A[2] and self.P.A[4]==self.Q.A[5]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[3] and self.P.A[2]==self.Q.A[5] and self.P.A[3]==self.Q.A[0] and self.P.A[4]==self.Q.A[2]:
                print("Yes")
            else:
                print("No")

        elif (self.P.A[0]==self.Q.A[2]and self.P.A[5]==self.Q.A[3]):
            if self.P.A[1]==self.Q.A[1] and self.P.A[2]==self.Q.A[5] and self.P.A[3]==self.Q.A[0] and self.P.A[4]==self.Q.A[4]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[5] and self.P.A[2]==self.Q.A[4] and self.P.A[3]==self.Q.A[1] and self.P.A[4]==self.Q.A[0]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[4] and self.P.A[2]==self.Q.A[0] and self.P.A[3]==self.Q.A[5] and self.P.A[4]==self.Q.A[1]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[0] and self.P.A[2]==self.Q.A[1] and self.P.A[3]==self.Q.A[4] and self.P.A[4]==self.Q.A[5]:
                print("Yes")
            else:
                print("No")

        elif (self.P.A[0]==self.Q.A[3] and self.P.A[5]==self.Q.A[2]):
            if self.P.A[1]==self.Q.A[1] and self.P.A[2]==self.Q.A[0] and self.P.A[3]==self.Q.A[5] and self.P.A[4]==self.Q.A[4]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[0] and self.P.A[2]==self.Q.A[4] and self.P.A[3]==self.Q.A[1] and self.P.A[4]==self.Q.A[5]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[4] and self.P.A[2]==self.Q.A[5] and self.P.A[3]==self.Q.A[0] and self.P.A[4]==self.Q.A[1]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[5] and self.P.A[2]==self.Q.A[1] and self.P.A[3]==self.Q.A[4] and self.P.A[4]==self.Q.A[0]:
                print("Yes")
            else:
                print("No")

        elif (self.P.A[0]==self.Q.A[4] and self.P.A[5]==self.Q.A[1]):
            if self.P.A[1]==self.Q.A[0] and self.P.A[2]==self.Q.A[2] and self.P.A[3]==self.Q.A[3] and self.P.A[4]==self.Q.A[5]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[2] and self.P.A[2]==self.Q.A[5] and self.P.A[3]==self.Q.A[0] and self.P.A[4]==self.Q.A[3]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[5] and self.P.A[2]==self.Q.A[3] and self.P.A[3]==self.Q.A[2] and self.P.A[4]==self.Q.A[0]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[3] and self.P.A[2]==self.Q.A[0] and self.P.A[3]==self.Q.A[5] and self.P.A[4]==self.Q.A[2]:
                print("Yes")
            else:
                print("No")


        elif (self.P.A[0]==self.Q.A[5] and self.P.A[5]==self.Q.A[0]):
            if self.P.A[1]==self.Q.A[3] and self.P.A[2]==self.Q.A[4] and self.P.A[3]==self.Q.A[1] and self.P.A[4]==self.Q.A[2]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[4] and self.P.A[2]==self.Q.A[2] and self.P.A[3]==self.Q.A[3] and self.P.A[4]==self.Q.A[1]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[2] and self.P.A[2]==self.Q.A[1] and self.P.A[3]==self.Q.A[4] and self.P.A[4]==self.Q.A[3]:
                print("Yes")
            elif self.P.A[1]==self.Q.A[1] and self.P.A[2]==self.Q.A[3] and self.P.A[3]==self.Q.A[2] and self.P.A[4]==self.Q.A[4]:
                print("Yes")
            else:
                print("No")
        else:
            print("No")
     
##実行部分######################################################################
if __name__=="__main__":
    #入力用関数の定義##########################################
    def in_data():
       input_text=""
       input_text=input()
       array=[]
       array=input_text.split()
       return array
    ###########################################################
    ###ダイスの目の入力
    
    number=in_data()
    #一つ目のダイス
    ob1=dice( number[0], number[1], number[2], number[3], number[4], number[5])

    number=in_data()
    #二つ目のダイス
    ob2=dice( number[0], number[1], number[2], number[3], number[4], number[5])

    ##同一かどうかの判定
    det=determine(ob1,ob2)
        # method
    det.run()
#################################################################################

Submission status: Accepted

Solution code:
import random
def dice_move(a,s):
    if s=="E":
        return [a[3],a[1],a[0],a[5],a[4],a[2]]
    elif s=="S":
        return [a[4],a[0],a[2],a[3],a[5],a[1]]
    elif s=="W":
        return [a[2],a[1],a[5],a[0],a[4],a[3]]
    elif s=="N":
        return [a[1],a[5],a[2],a[3],a[0],a[4]]
    
a=list(map(int,input().split()))
b=list(map(int,input().split()))
h=("N","W","S","E")
for i in range(20000):
    num=random.randrange(4)
    a=dice_move(a,h[num])
    if a==b:
        print("Yes")
        exit()
print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# ITP1_11_C

class Dice:
    def __init__(self, num):
        self.num = num
        
    def roll(self, direction):
        """ 転がす処理 """
        data = []
        new_num = []
        if direction == "N":
            data = [1, 5, 2, 3, 0, 4]
        elif direction == "S":
            data = [4, 0, 2, 3, 5, 1]
        elif direction == "E":
            data = [3, 1, 0, 5, 4, 2]
        elif direction == "W":
            data = [2, 1, 5, 0, 4, 3]
        elif direction == "L":
            data = [0, 2, 4, 1, 3, 5]
        elif direction == "R":
            data = [0, 3, 1, 4, 2, 5]

        for i in data:
            new_num.append(self.num[i])
        self.num = new_num
        
def dice_roll1(dice, dice_tf):
    dice_roll = ""
    top = dice_tf[0]
    
    if dice.num.index(top) == 1:
        dice_roll = "N"
    elif dice.num.index(top) == 2:
        dice_roll = "W"
    elif dice.num.index(top) == 3:
        dice_roll = "E"
    elif dice.num.index(top) == 4:
        dice_roll = "S"
    elif dice.num.index(top) == 5:
        dice_roll = "NN"
        
    return dice_roll

def dice_roll2(dice, dice_tf):
    dice_roll = ""
    front = dice_tf[1]

    if dice.num.index(front) == 2:
        dice_roll = "L"
    elif dice.num.index(front) == 3:
        dice_roll = "R"
    elif dice.num.index(front) == 4:
        dice_roll = "LL"
        
    return dice_roll

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

dice_tf = dice1.num[:2]

direction = dice_roll1(dice2, dice_tf)
for i in direction:
    dice2.roll(i)
direction = dice_roll2(dice2, dice_tf)
for i in direction:
    dice2.roll(i)

if dice1.num[2] == dice2.num[2]:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
houkou={'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)}
S1=list(map(int,input().split()))
S2=list(map(int,input().split()))
for i in "SSSSEEEENEEEENEEEENEEEENWSSSSWSSSSWSSSSWNWSSSSEEEEWSSSSEEEEWSSSSEEEEWNWSSSSEEEEWSSSSEEEEWSSSSEEEEWNWSSSSEEEEWSSSSEEEEWSSSSEEEEW:":
  if S1==S2:
    print("Yes")
    break
  if i==":":
    print("No")
    break
  S1=[S1[j]for j in houkou[i]]
  #print(S1)

Submission status: Accepted

Solution code:
from sys import exit

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

d1 = list(map(int, input().split()))
d2 = list(map(int, input().split()))


for k in 'EE':
    for i in 'NNNN':
        for j in 'RRRR':
            if d1 == d2:
                print('Yes')
                exit(0)
            else:
                d2 = rotate(d2, j)
                
        d2 = rotate(d2, i)
        
    d2 = rotate(d2, k)
            
print('No')

Submission status: Accepted

Solution code:
class Dice:
    N = [0, 1, 5, 4]
    S = N[::-1]
    E = [0, 3, 5, 2]
    W = E[::-1]
    R = [1, 2, 4, 3]
    L = R[::-1]

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

    def __eq__(self, other):
        if isinstance(other, Dice):
            newdice = Dice(other.numbers.copy())
            for n in range(6):
                if 1 <= n <= 3:
                    newdice.toX('N')
                elif n == 4:
                    newdice.toX('N')
                    newdice.toX('E')
                elif n == 5:
                    [newdice.toX('E') for _ in range(2)]
                for _ in range(4):
                    if self.numbers == newdice.numbers:
                        return True
                    newdice.toX('R')

            else:
                return False

        else:
            return False

    def toX(self, x):
        data = getattr(self, x)
        self.numbers.append(0)
        for k in range(5):
            i1 = data[k - 1] if k != 0 else 6
            i2 = data[k] if k != 4 else 6
            self.numbers[i1] = self.numbers[i2]
        del self.numbers[6]

    def setTopandFront(self, top, front):
        while self.numbers[0] != top:
            if self.numbers.index(top) in self.N:
                self.toX('N')
            else:
                self.toX('E')
        while self.numbers[1] != front:
            self.toX('R')


dice1 = Dice([int(i) for i in input().split()])
dice2 = Dice([int(i) for i in input().split()])
if dice1 == dice2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self,rot,Face):
        self.rot= rot
        self.Face = Face
    def Rotate(rot,Face):
        r=len(rot)
        intFace=[int(Face[i]) for i in range(6)]

        for i in range(r):
            Temp=[intFace[i] for i in range(6)]

            if rot[i]== "E":
                intFace[0]=Temp[3]
                intFace[1]=Temp[1]
                intFace[2]=Temp[0]
                intFace[3]=Temp[5]
                intFace[4]=Temp[4]
                intFace[5]=Temp[2]

            elif rot[i]== "W":
                intFace[0]=Temp[2]
                intFace[1]=Temp[1]
                intFace[2]=Temp[5]
                intFace[3]=Temp[0]
                intFace[4]=Temp[4]
                intFace[5]=Temp[3]

            elif rot[i]== "N":
                intFace[0]=Temp[1]
                intFace[1]=Temp[5]
                intFace[2]=Temp[2]
                intFace[3]=Temp[3]
                intFace[4]=Temp[0]
                intFace[5]=Temp[4]

            elif rot[i]== "S":
                intFace[0]=Temp[4]
                intFace[1]=Temp[0]
                intFace[2]=Temp[2]
                intFace[3]=Temp[3]
                intFace[4]=Temp[5]
                intFace[5]=Temp[1]

        return intFace
#returnしてなかったわ インデント幅も注意

Face1 = input().split()
Face2 = input().split()
rot=""

###################
#同じ整数があるので前のは使えず。ごっそり修正
####################3
D1=["","N","W","E","S","NN"]
D2= ["","NWS","NWSNWS","NWSNWSNWS",]
same=False
for k in range(6):
    for i in range(4):
        rot = D1[k]+D2[i]

        dice=Dice(rot,Face2)
        tempFace= Dice.Rotate(rot,Face2)
        j=0
        while j<6:
            if tempFace[j]!=int(Face1[j]):
                break
            else:
                if j==5:
                    same=True
                j+=1
if same:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

    def set_number(self, d0, d1, d2, d3, d4, d5):
        self.number[0] = d0
        self.number[1] = d1
        self.number[2] = d2
        self.number[3] = d3
        self.number[4] = d4
        self.number[5] = d5

    def roll(self, command):
        if   command == "E":
            self.set_number(self.number[3],self.number[1],self.number[0],self.number[5],self.number[4],self.number[2])
        elif command == "N":
            self.set_number(self.number[1],self.number[5],self.number[2],self.number[3],self.number[0],self.number[4])
        elif command == "S":
            self.set_number(self.number[4],self.number[0],self.number[2],self.number[3],self.number[5],self.number[1])
        elif command == "W":
            self.set_number(self.number[2],self.number[1],self.number[5],self.number[0],self.number[4],self.number[3])
        else:
            raise

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

    def get_d2(self, d0, d1):
        flag_correct = False
        
        for command in self.command_allpattern:
            self.roll(command)

            if ((d0 == self.number[0]) and
                (d1 == self.number[1])):
                d2 = self.number[2]
                flag_correct = True

        if flag_correct:
            return d2
        else:
            raise

    def is_equal_dice_number(self, Dice):
        if set(Dice.number) == set(self.number):
            return True
        else:
            return False

    def equal_dice(self, Dice):

        if not self.is_equal_dice_number(Dice):
            return("No")


        flag_correct = False

        for command in self.command_allpattern:
            Dice.roll(command)

            if ((Dice.number[0] == self.number[0]) and
                (Dice.number[1] == self.number[1]) and
                (Dice.number[2] == self.number[2]) and
                (Dice.number[3] == self.number[3]) and
                (Dice.number[4] == self.number[4]) and
                (Dice.number[5] == self.number[5])):
                flag_correct = True

        if flag_correct:
            return("Yes")
        else:
            return("No")



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

dice1 = Dice()
dice1.set_number(list_face1[0], list_face1[1], list_face1[2], list_face1[3], list_face1[4], list_face1[5])


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

dice2 = Dice()
dice2.set_number(list_face2[0], list_face2[1], list_face2[2], list_face2[3], list_face2[4], list_face2[5])

print(dice1.equal_dice(dice2))

Submission status: Accepted

Solution code:
# ITP_11_C
class Dice :
    def __init__(self, dice) :
        self.dice = dice
    def roll(self, direction):
        tmp = self.dice[:]
        if direction == "N":
            self.dice[0] = tmp[1]
            self.dice[1] = tmp[5]
            self.dice[4] = tmp[0]
            self.dice[5] = tmp[4]
        elif direction == "E":
            self.dice[0] = tmp[3]
            self.dice[2] = tmp[0]
            self.dice[3] = tmp[5]
            self.dice[5] = tmp[2]
        elif direction == "W":
            self.dice[0] = tmp[2]
            self.dice[2] = tmp[5]
            self.dice[3] = tmp[0]
            self.dice[5] = tmp[3]
        else:
            self.dice[0] = tmp[4]
            self.dice[1] = tmp[0]
            self.dice[4] = tmp[5]
            self.dice[5] = tmp[1]

    def check_dice(self, another):
        for dire in "NNNNWNNNWNNNENNNENNNWNNN":
            self.roll(dire)
            check = True
            for i in range(6):
                if self.dice != another.dice:
                    check = False
                    break
            if check == True:
                break
        return check
    def get_dice_nums(self):
        return(self.dice)
    
    def dice_top(self):
        print(self.dice[0])
    
dice1 = Dice(list(map(str, input().split())))
dice2 = Dice(list(map(str, input().split())))

judge = dice1.check_dice(dice2)
if judge == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from enum import Enum
import sys
import math

# 0:中央 1:南 2:東 3:西 4:北 5:裏側


class Dice():

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

    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 query(self, another_dice):

        self.save_data = [i for i in range(6)]
        # 元の値の保存
        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]

        is_same_face = False
        for i in range(len(self.order)):
            self.roll(self.order[i])
            if [f == s for f, s in zip(self.number, another_dice)].count(False) == 0:
                is_same_face = True
                break

        # 元の値の復元
        for i in range(len(self.number)):
            self.number[i] = self.save_data[i]
        return is_same_face


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

second_dice = list(map(int,input().split()))
if dice.query(second_dice) == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import random
def dice(a, b, c, d, e, f, l) :  #def = 関数定義
  if(l == "N") :
    return [b, f, c, d, a, e]
  elif(l == "S") :
    return [e, a, c, d, f, b]
  elif(l == "W") :
    return [d, b, a, f, e, c]
  else :
    return [c, b, f, a, e, d]
  
d1 = list(map(int, input().split()))
a, b, c, d, e, f = map(int, input().split())
L = ["N", "S", "W", "E"]

cnt = 0

while(cnt <= 10000) :
  x = random.randrange(4)  #0～3の中からランダムに1つ整数を選択
  d1 = dice(d1[0], d1[1], d1[2], d1[3], d1[4], d1[5], L[x])
  
  if(d1[0] == a and d1[1] == b and d1[2] == c and d1[3] == d 
     and d1[4] == e and d1[5] == f) :
    print("Yes")
    break
  elif(cnt == 10000) :
    print("No")
    break
  else :
    cnt += 1

Submission status: Accepted

Solution code:
class Dice():
	def __init__(self):
		self.number = [int(i) for i in range(1,7)]
	
	def set_number(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,s):
		tmp = self.number
		if s == "S":
			self.set_number(tmp[4],tmp[0],tmp[2],tmp[3],tmp[5],tmp[1])
		elif s == "E":
			self.set_number(tmp[3],tmp[1],tmp[0],tmp[5],tmp[4],tmp[2])
		elif s == "N":
			self.set_number(tmp[1],tmp[5],tmp[2],tmp[3],tmp[0],tmp[4])
		elif s == "W":
			self.set_number(tmp[2],tmp[1],tmp[5],tmp[0],tmp[4],tmp[3])

	def get_number(self,i):
		# top: 0, front: 1, right: 2, left: 3, back: 4, bottom: 5 
		return self.number[i]

	def get_position(self,i):
		return self.number.index(i)

if __name__ == '__main__':
	dice_numA = [int(i) for i in input().split()]
	dice_numB = [int(i) for i in input().split()]

	diceA = Dice()
	diceA.set_number(dice_numA[0],dice_numA[1],dice_numA[2],dice_numA[3],dice_numA[4],dice_numA[5])
	diceB = Dice()
	diceB.set_number(dice_numB[0],dice_numB[1],dice_numB[2],dice_numB[3],dice_numB[4],dice_numB[5])

	topA = diceA.get_number(0)
	frontA = diceA.get_number(1)

	while diceB.get_number(1) != frontA:
		if diceB.get_position(frontA) == 2 or diceB.get_position(frontA) == 3:
			diceB.roll("E")
		else:
			diceB.roll("S")
	while diceB.get_number(0) != topA:
		diceB.roll("E")

	if dice_numA == [diceB.get_number(0),diceB.get_number(1),diceB.get_number(2),diceB.get_number(3),diceB.get_number(4),diceB.get_number(5)]:
		print("Yes")
	else:
		print("No")

Submission status: Accepted

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


    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 next(self,direction):
        for i in range(6):
            self.tmp[i] = self.number[i]

        if direction == 'E':
            self.setNumber(self.tmp[3], self.tmp[1], self.tmp[0], self.tmp[5], self.tmp[4], self.tmp[2])
        elif direction == 'N':
            self.setNumber(self.tmp[1], self.tmp[5], self.tmp[2], self.tmp[3], self.tmp[0], self.tmp[4])
        elif direction == 'S':
            self.setNumber(self.tmp[4], self.tmp[0], self.tmp[2], self.tmp[3], self.tmp[5], self.tmp[1])
        elif direction == 'W':
            self.setNumber(self.tmp[2], self.tmp[1], self.tmp[5], self.tmp[0], self.tmp[4], self.tmp[3])
    def get_result(self):
        return self.number[0]

    def cheak(self,altanative):

        flag = True

        for i in range(len(self.set_cmd)):
            self.next(self.set_cmd[i])
            flag = True
            for j in range(6):
                if self.number[j] != altanative.number[j]:
                    flag = False
                    break
            else:
                if flag == True:
                    return flag

        return flag

dice1 = Dice()
dice2 = Dice()

fig1 = list(map(int,input().split()))
dice1.setNumber(fig1[0],fig1[1],fig1[2],fig1[3],fig1[4],fig1[5])
fig2 = list(map(int,input().split()))
dice2.setNumber(fig2[0],fig2[1],fig2[2],fig2[3],fig2[4],fig2[5])

is_TRUE = dice1.cheak(dice2)
if(is_TRUE):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

    def roll(self, axis, count=1):
        while count < 0:
            count += 4
        if axis == "X":
            for _ in range(count):
                self.top, self.back, self.bottom, self.front = self.front, self.top, self.back, self.bottom
        elif axis == "Y":
            for _ in range(count):
                self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom
        elif axis == "Z":
            for _ in range(count):
                self.front, self.left, self.back, self.right = self.right, self.front, self.left, self.back
        elif axis == "N":
            self.roll("X", 1)
        elif axis == "W":
            self.roll("Y", -1)
        elif axis == "S":
            self.roll("X", -1)
        elif axis == "E":
            self.roll("Y", 1)


def solve(d1, d2):
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return "Yes"
        d2.roll("Z")
    d2.roll("X")
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return "Yes"
        d2.roll("Y")
    d2.roll("X")
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return "Yes"
        d2.roll("Z")
    d2.roll("X")
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return "Yes"
        d2.roll("Y")
    d2.roll("X")
    d2.roll("Y")
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return "Yes"
        d2.roll("X")
    d2.roll("Y", 2)
    for _ in range(4):
        if d1.top == d2.top and d1.bottom == d2.bottom and d1.front == d2.front and d1.back == d2.back and d1.left == d2.left and d1.right == d2.right:
            return "Yes"
        d2.roll("X")
    return "No"


labels1 = [int(c) for c in input().split()]
labels2 = [int(c) for c in input().split()]
d1 = Dice(labels1)
d2 = Dice(labels2)
print(solve(d1, d2))