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 diceClass:
	def __init__(self, valuelist):
		self.valuelist = valuelist
		self.t = valuelist[0]
		self.b = valuelist[5]
		self.n = valuelist[4]
		self.s = valuelist[1]
		self.e = valuelist[2]
		self.w = valuelist[3]

	def throw(self, direction):
		# N,S,W,E
		if direction == 'N':
			self.t, self.s, self.b, self.n = self.s, self.b, self.n, self.t
		elif direction == 'S':
			self.t, self.s, self.b, self.n = self.n, self.t, self.s, self.b
		elif direction == 'W':
			self.t, self.e, self.b, self.w = self.e, self.b, self.w, self.t
		elif direction == 'E':
			self.t, self.e, self.b, self.w = self.w, self.t, self.e, self.b


arrinput1 = list(map(int, input().split()))
arrinput2 = list(map(int, input().split()))
dirinput = 'WWWWSWWWWSWWWWSWWWWWSWWWWSSWWWW'
dicresult1 = []
dicresult2 = []

dice = diceClass(arrinput1)
dice2 = diceClass(arrinput2)

for s in dirinput:
	dice.throw(s)
	dice2.throw(s)
	if dicresult1.count([[dice.t, dice.s], dice.e]) == 0:
		dicresult1.append([[dice.t, dice.s], dice.e])
	if dicresult2.count([[dice2.t, dice2.s], dice2.e]) == 0:
		dicresult2.append([[dice2.t, dice2.s], dice2.e])

#print(dicresult1)
#print(dicresult2)

for i in dicresult1:
	if dicresult2.count(i) != 1:
		print('No')
		exit(0)

print('Yes')

Submission status: Accepted

Solution code:
class Dice:
  __table =[[0,1,2,3,4,5],[0,2,4,1,3,5],[0,4,3,2,1,5],[0,3,1,4,2,5],
            [1,5,2,3,0,4],[1,2,0,5,3,4],[1,0,3,2,5,4],[1,3,5,0,2,4],
            [2,5,4,1,0,3],[2,4,0,5,1,3],[2,0,1,4,5,3],[2,1,5,0,4,3],
            [3,5,1,4,0,2],[3,1,0,5,4,2],[3,0,4,1,5,2],[3,4,5,0,1,2],
            [4,2,5,0,3,1],[4,5,3,2,0,1],[4,3,0,5,2,1],[4,0,2,3,5,1],
            [5,1,3,2,4,0],[5,3,4,1,2,0],[5,4,2,3,1,0],[5,2,1,4,3,0]]
  __another = []
  def __init__(self,dice):
    self.dice = dice
    for t in self.__table:
      a = []
      for v in t:
        a.append(dice[v])      
      self.__another.append(a)
      
  def output(self):
    print(self.dice[0])
    
  def right_dise(self,a,b):
    for t in self.__another:
      if t[0] == a and t[1] == b:
        return t[2]

  def comparison(self,dice):
    result = 0
    for table_temp in self.__another:
      table_temp = ''.join(map(str,table_temp))
      dice = ''.join(map(str,dice))
      if table_temp == dice:
        print('Yes')
        result = 1
        break
    if result == 0:
      print('No')
        
  def move(self,str):
    if str == 'N':
      temp = self.dice[0]
      self.dice[0] = self.dice[1]
      self.dice[1] = self.dice[5]
      self.dice[5] = self.dice[4]
      self.dice[4] = temp
    elif str == 'S':
      temp = self.dice[0]
      self.dice[0] = self.dice[4]
      self.dice[4] = self.dice[5]
      self.dice[5] = self.dice[1]
      self.dice[1] = temp
    elif str == 'E':
      temp = self.dice[0]
      self.dice[0] = self.dice[3]
      self.dice[3] = self.dice[5]
      self.dice[5] = self.dice[2]
      self.dice[2] = temp
    elif str == 'W':
      temp = self.dice[0]
      self.dice[0] = self.dice[2]
      self.dice[2] = self.dice[5]
      self.dice[5] = self.dice[3]
      self.dice[3] = temp      
  
      
di1 = list(map(int,input().split()))
di2 = list(map(int,input().split()))
di = Dice(di1)

di.comparison(di2)

Submission status: Accepted

Solution code:
import math
import itertools
import sys

class Dice:
  # self.numbers = []
  # self.faces = {
  #   'top': None,
  #   'back': None,    
  #   'right': None,    
  #   'left': None,    
  #   'front': None,    
  #   'bottom': None,
  # }

  def __init__(self, int_array):
    self.numbers = int_array
    self.faces = {}
    self.faces['top'] = self.numbers[0]
    self.faces['back'] = self.numbers[1]
    self.faces['right'] = self.numbers[2]
    self.faces['left'] = self.numbers[3]
    self.faces['front'] = self.numbers[4]
    self.faces['bottom'] = self.numbers[5]

  def getNum(self, n):
    return self.numbers[n-1]

  def getFace(self, f):
    return self.faces[f]

  def getRightFace(self, t, b):
    top = self.faces['top']
    back = self.faces['back']
    right = self.faces['right']
    left = self.faces['left']
    front = self.faces['front']
    bottom = self.faces['bottom']

    if t == self.getNum(2):
      self.rotate('N')

    elif t == self.getNum(4):
      self.rotate('E')

    elif t == self.getNum(5):
      self.rotate('S')

    elif t == self.getNum(3):
      self.rotate('W')

    elif t == self.getNum(6):
      for _ in range(2):
        self.rotate('N')

    while self.getFace('back') != b:
      self.rotate('R')

    result = self.getFace('right')
      
    self.faces['top'] = top
    self.faces['back'] = back
    self.faces['right'] = right
    self.faces['left'] = left
    self.faces['front'] = front
    self.faces['bottom'] = bottom

    return result

  def rotate(self, direction):
    if direction == 'N': # 前回り
      top = self.getFace('top') #一時保存

      self.faces['top'] = self.faces['back']
      self.faces['back'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['front']
      self.faces['front'] = top
      
    elif direction == 'E': # 右回り
      top = self.faces['top'] #一時保存

      self.faces['top'] = self.faces['left']
      self.faces['left'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['right']
      self.faces['right'] = top
      
    elif direction == 'S': # 後ろ回り
      top = self.faces['top'] #一時保存

      self.faces['top'] = self.faces['front']
      self.faces['front'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['back']
      self.faces['back'] = top
      
    elif direction == 'W': # 左回り
      top = self.faces['top'] #一時保存

      self.faces['top'] = self.faces['right']
      self.faces['right'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['left']
      self.faces['left'] = top
      
    elif direction == 'R': # その場右回り
      back = self.faces['back'] #一時保存

      self.faces['back'] = self.faces['left']
      self.faces['left'] = self.faces['front']
      self.faces['front'] = self.faces['right']
      self.faces['right'] = back
      
    elif direction == 'L': # その場左回り
      back = self.faces['back'] #一時保存

      self.faces['back'] = self.faces['right']
      self.faces['right'] = self.faces['front']
      self.faces['front'] = self.faces['left']
      self.faces['left'] = back

def isSameDice(dice_1, dice_2):
  faces = ['top', 'back', 'right', 'left', 'front', 'bottom']

  for _ in range(4):
    for _ in range(4):
      flag = True

      for face in faces:
        if dice_1.getFace(face) != dice_2.getFace(face):
          flag = False
          break

      if flag:
        return True
      dice_1.rotate('R')

    dice_1.rotate('N')

  dice_1.rotate('E')
  for _ in range(4):
    flag = True

    for face in faces:
      if dice_1.getFace(face) != dice_2.getFace(face):
        flag = False
        break

    if flag:
      return True
    dice_1.rotate('R')

  for _ in range(2):
    dice_1.rotate('W')
  for _ in range(4):
    flag = True

    for face in faces:
      if dice_1.getFace(face) != dice_2.getFace(face):
        flag = False
        break

    if flag:
      return True
    dice_1.rotate('R')

  return False
      
def main():
  input_1 = list(map(int, input().split()))
  input_2 = list(map(int, input().split()))

  dice_1 = Dice(input_1)
  dice_2 = Dice(input_2)
  
  if(isSameDice(dice_1, dice_2)):
    print('Yes')
  else:
    print('No')

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
d,e=[input().split()for _ in'12'];e[3:5]=e[4],e[3]
t=0
for p in('012345','152304','215043','310542','402351','513240'):
 f=[d[int(j)]for j in p];f[3:5]=f[4:2:-1]
 if f[0]==e[0]:
  f=f[1:5]*2
  for j in range(4):
   if f[j:j+4]==e[1:5]:t=1
print(('No','Yes')[t])

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self):
        self.u=1
        self.w=2
        self.s=3
        self.e=4
        self.n=5
        self.d=6
        self.dic={"W":0,"S":1,"E":2,"N":3}
    
    def __init__(self,u,w,s,e,n,d):
        self.u=u
        self.w=w
        self.s=s
        self.e=e
        self.n=n
        self.d=d
        self.dic={"W":0,"S":1,"E":2,"N":3}

    def rot(self,way):
        if isinstance(way,str):
            way=self.dic[way]

        if(way==0):
            c=self.u
            self.u=self.e
            self.e=self.d
            self.d=self.w
            self.w=c
        elif way==1:
            c=self.u
            self.u=self.n
            self.n=self.d
            self.d=self.s
            self.s=c
        elif way==2:
            c=self.u
            self.u=self.w
            self.w=self.d
            self.d=self.e
            self.e=c

import random
u,s,e,w,n,d=map(int,input().split())
dice=Dice(u,w,s,e,n,d)
u,s,e,w,n,d=map(int,input().split())
dice_b=Dice(u,w,s,e,n,d)
ok=False
for i in range (1000):
    dice.rot(random.randint(0,3))
    if(dice.u==dice_b.u and dice.d==dice_b.d and dice.w==dice_b.w and dice.s==dice_b.s and dice.e==dice_b.e and dice.n==dice_b.n):
        ok=True
if ok:
    print('Yes')
else :
    print('No')

Submission status: Accepted

Solution code:
def roll_e(d):
    w = []
    w = d
    d[0], d[1], d[2], d[3], d[4], d[5] = w[3], w[1], w[0], w[5], w[4], w[2]
    return d

def roll_s(d):
    w = []
    w = d
    d[0], d[1], d[2], d[3], d[4], d[5] = w[4], w[0], w[2], w[3], w[5], w[1]
    return d

d1 = input().split()
d2 = input().split()
no_flag = 0

i = 0
while d1[1] != d2[1]:
    if i == 7:
        no_flag = 1
        break
    elif i == 4:
        d2 = roll_e(d2)
    d2 = roll_s(d2)
    i += 1

i = 0
while d1[0] != d2[0] or 4 > i or no_flag == 1:
    d2 = roll_e(d2)
    i += 1

if d1 == d2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

def move(x):
    # N
    if x == 0:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[1],d[5],d[2],d[3],d[0],d[4]
    # W
    elif x == 1:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[2],d[1],d[5],d[0],d[4],d[3]

    # E
    elif x == 2:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[3],d[1],d[0],d[5],d[4],d[2]
    # S
    elif x == 3:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[4],d[0],d[2],d[3],d[5],d[1]

# そのまま
    elif x == 4:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[0],d[1],d[2],d[3],d[4],d[5]
#ひっくり返し
    elif x == 5:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[5],d[4],d[2],d[3],d[1],d[0]

#頂点維持のまま回転
    elif x == 6:
        d[0],d[1],d[2],d[3],d[4],d[5] = d[0],d[2],d[4],d[1],d[3],d[5]

d = [dice1[0],dice1[1],dice1[2],dice1[3],dice1[4],dice1[5]]
for i in range(6):
    move(i)
    if d == dice2:
        eq = 1
        break
    else:
        for j in range(4):
            move(6)

            if d == dice2:
                eq = 1
                break
    d = [dice1[0],dice1[1],dice1[2],dice1[3],dice1[4],dice1[5]]


if eq == 0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
class Dice:
    
    keys = [ 
        "top", 
        "front", 
        "right", 
        "left", 
        "back", 
        "bottom"
        ]
    keys_for_top = [
            ["front", "right", "back", "left", "bottom"],
            ["bottom", "right", "top", "left", "back"],
            ["bottom", "back", "top", "front", "left"],
            ["bottom", "front", "top", "back", "right"],
            ["bottom", "left", "top", "right", "front"],
            ["front", "left", "back", "right", "top"]
        ]

    def __init__(self, eye1, eye2, eye3, eye4, eye5, eye6):
        self.__eyes = {
            "top": eye1,
            "front": eye2,
            "right": eye3,
            "left": eye4,
            "back": eye5,
            "bottom": eye6
        }

    def set_eyes(self, eye1, eye2, eye3, eye4, eye5, eye6):
        self.__eyes["top"] = eye1
        self.__eyes["front"] = eye2
        self.__eyes["right"] = eye3
        self.__eyes["left"] = eye4
        self.__eyes["back"] = eye5
        self.__eyes["bottom"] = eye6
    
    def get_eyes(self, key):
        return self.__eyes[key]

    def N(self):
        self.set_eyes(
            self.get_eyes("front"),
            self.get_eyes("bottom"),
            self.get_eyes("right"),
            self.get_eyes("left"),
            self.get_eyes("top"),
            self.get_eyes("back")
            )
    def S(self):
        self.set_eyes(
            self.get_eyes("back"),
            self.get_eyes("top"),
            self.get_eyes("right"),
            self.get_eyes("left"),
            self.get_eyes("bottom"),
            self.get_eyes("front")
            )
        
    def E(self):
        self.set_eyes(
            self.get_eyes("left"),
            self.get_eyes("front"),
            self.get_eyes("top"),
            self.get_eyes("bottom"),
            self.get_eyes("back"),
            self.get_eyes("right")
            )
        
    def W(self):
        self.set_eyes(
            self.get_eyes("right"),
            self.get_eyes("front"),
            self.get_eyes("bottom"),
            self.get_eyes("top"),
            self.get_eyes("back"),
            self.get_eyes("left")
            )
    
    def print_top(self):
        print(self.get_eyes("top"))

    def guess_right_from_top_front(self, top, front):
        key_top = None
        key_front = None
        
        for key in Dice.keys:
            if top == self.get_eyes(key):
                key_top = key
            if front == self.get_eyes(key):
                key_front = key
        

        for i in range(6):
            if key_top == Dice.keys[i]:
                for j in range(4):
                    if key_front == Dice.keys_for_top[i][j]:
                        return Dice.keys_for_top[i][(j + 1) % 4]
        return False

    @classmethod
    def generate_all_states(cls, dice):
        dices = []
        for i in range(6):
            for j in range(4):
                dices.append(cls(
                    dice.get_eyes(Dice.keys[i]),
                    dice.get_eyes(Dice.keys_for_top[i][j]),
                    dice.get_eyes(Dice.keys_for_top[i][(j + 1) % 4]),
                    dice.get_eyes(Dice.keys_for_top[i][(j + 3) % 4]),
                    dice.get_eyes(Dice.keys_for_top[i][(j + 2) % 4]),
                    dice.get_eyes(Dice.keys_for_top[i][4])
                    ))
        return dices
    
    @classmethod
    def is_same_states(cls, dice1, dice2):
        for i in range(6):
            if dice1.get_eyes(Dice.keys[i]) != dice2.get_eyes(Dice.keys[i]):
                return False
        return True
    
    @classmethod
    def is_same_dices(cls, dice1, dice2):
        all_states_dice2 = Dice.generate_all_states(dice2)
        for i in range(24):
            if Dice.is_same_states(dice1, all_states_dice2[i]):
                return True
        return False   

eyes1 = list(map(int, input().split()))
eyes2 = list(map(int, input().split()))

dice1 = Dice(eyes1[0], eyes1[1], eyes1[2], eyes1[3], eyes1[4], eyes1[5])
dice2 = Dice(eyes2[0], eyes2[1], eyes2[2], eyes2[3], eyes2[4], eyes2[5])
if Dice.is_same_dices(dice1, dice2):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

#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 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,labels):
       self.stat =  labels
    
    def roll_E(self):
        self.stat[0],self.stat[2],self.stat[3],self.stat[5] = self.stat[3],self.stat[0],self.stat[5],self.stat[2]
        
    def roll_N(self):
        self.stat[0],self.stat[1],self.stat[5],self.stat[4] = self.stat[1],self.stat[5],self.stat[4],self.stat[0]
        
    def roll_S(self):
        self.stat[0],self.stat[1],self.stat[5],self.stat[4] = self.stat[4],self.stat[0],self.stat[1],self.stat[5]
        
    def roll_W(self):
        self.stat[0],self.stat[2],self.stat[5],self.stat[3] = self.stat[2],self.stat[5],self.stat[3],self.stat[0]
        
    def get_top(self):
        return self.stat[0]
        
    def get(self):
        return list(self.stat)
        
dice1 = Dice(input().split())
dice2 = Dice(input().split())

#print(dice1.get())
#print(dice2.get())
flag = False

for i in range(20):
    dice2.roll_N()
    #print(dice2.get())
    if dice1.get() == dice2.get() :
        flag = True
        break
    for j in range(20):
        dice2.roll_E()
        #print(dice2.get())
        if dice1.get() == dice2.get() :
            flag = True
            break
        for k in range(20):
            dice2.roll_S()
            #print(dice2.get())
            if dice1.get() == dice2.get() :
                flag = True
                break
if flag:print("Yes")
else:print("No")

Submission status: Accepted

Solution code:

class Dice:
    def __init__(self,a,b,c,d,e,f):
        self.face1 = a
        self.face2 = b
        self.face3 = c
        self.face4 = d
        self.face5 = e
        self.face6 = f

    def above_face(self):
        return self.face1

    def roll(self, order):
        if order == 'N':
            tmp = self.face1
            self.face1 = self.face2
            self.face2 = self.face6
            self.face6 = self.face5
            self.face5 = tmp
        elif order == 'S':
            tmp = self.face1
            self.face1 = self.face5
            self.face5 = self.face6
            self.face6 = self.face2
            self.face2 = tmp
        elif order == 'W':
            tmp = self.face1
            self.face1 = self.face3
            self.face3 = self.face6
            self.face6 = self.face4
            self.face4 = tmp
        else:
            tmp = self.face1
            self.face1 = self.face4
            self.face4 = self.face6
            self.face6 = self.face3
            self.face3 = tmp

a,b,c,d,e,f = map(int,input().split())
dice1 = Dice(a,b,c,d,e,f)
a,b,c,d,e,f = map(int,input().split())
dice2 = Dice(a,b,c,d,e,f)
import random

flag = False

for i in 'NNNNWNNNWNNNENNNENNNWNNN':
    dice1.roll(i)
    if dice1.face1 == dice2.face1 and dice1.face2 == dice2.face2 and dice1.face3 == dice2.face3 \
            and dice1.face4 == dice2.face4 and dice1.face5 == dice2.face5 and dice1.face6 == dice2.face6:
        flag = True
        break
if flag == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
class Dice():

    def __init__(self, dice_list):
        self.state = [0 for _ in range(6)]
        self.state[0] = dice_list[0]
        self.state[1] = dice_list[1]
        self.state[2] = dice_list[2]
        self.state[3] = dice_list[3]
        self.state[4] = dice_list[4]
        self.state[5] = dice_list[5]

    def north(self):
        tmp = self.state[0]
        self.state[0] = self.state[1]
        self.state[1] = self.state[5]
        self.state[5] = self.state[4]
        self.state[4] = tmp

    def west(self):
        tmp = self.state[0]
        self.state[0] = self.state[2]
        self.state[2] = self.state[5]
        self.state[5] = self.state[3]
        self.state[3] = tmp

    def south(self):
        tmp = self.state[0]
        self.state[0] = self.state[4]
        self.state[4] = self.state[5]
        self.state[5] = self.state[1]
        self.state[1] = tmp


    def east(self):
        tmp = self.state[0]
        self.state[0] = self.state[3]
        self.state[3] = self.state[5]
        self.state[5] = self.state[2]
        self.state[2] = tmp

    
if __name__ == '__main__':
    duce_num1 = list(map(int, input().split()))
    duce_num2 = list(map(int, input().split()))

    dice1 = Dice(duce_num1)
    ans = 'No'
    flag = False

    dice2 = Dice(duce_num2)
    for i in range(4):
        for j in range(4):
            if dice1.state[1] == dice2.state[1]:
                flag = True
                break
            dice2.east()

        if dice1.state[1] == dice2.state[1]:
            flag = True
            break

        dice2.north()

    if flag == False:
        dice2 = Dice(duce_num2)
        dice2.west()
        dice2.south()
        for i in range(4):
            if dice1.state[1] == dice2.state[1]:
                flag = True
                break
            dice2.west()

    if flag == False:
        dice2 = Dice(duce_num2)
        dice2.east()
        dice2.south()
        for i in range(4):
            if dice1.state[1] == dice2.state[1]:
                break
            dice2.west()

    for i in range(4):
        if dice1.state == dice2.state:
            ans = 'Yes'
            break
        dice2.west()
        
    print(ans)

Submission status: Accepted

Solution code:
ptn=["23542","14631",
"12651","15621",
"13641","32453"]

def rNO(d):
  global ptn
  for i,e in enumerate(ptn):
    if d in e:
      return i
  return 0

dice1 = list(input().split(" "))
dice2 = list(input().split(" "))

e = dice1[2]

#dice1の１，２番目はdice2で何番目？
d2=["",""]
for i ,v in enumerate(dice2):
  if dice1[0] == v:
    d2[0] = str(i + 1)
  if dice1[1] == v:
    d2[1] = str(i + 1)

d2Idx = rNO("".join(d2))

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

Submission status: Accepted

Solution code:

#0:上面　1:S 2:E 3:W 4:N 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):#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])
        else:
            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])
            flag = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    flag = False
                    break
            if flag == True:
                return True
        
        return ret
          

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

table2 = list(map(int, input().split()))
dice2.setNumber(table2[0],table2[1],table2[2],table2[3],table2[4],table2[5])#init
# loc_array=str(input())

# order = 'NNNNWNNNWNNNENNNENNNWNNN'
# for tmp_order in order:
#     dice1.roll(tmp_order)
#     if dice1.number[0]==dice2.number[0] and dice1.number[1]==dice2.number[1]:
#         print('Yes')
#         break
#     print('No')

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

Submission status: Accepted

Solution code:
import random

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

    def S(self):
        temp = self.number
        self.number = [temp[4], temp[0], temp[2], temp[3], temp[5], temp[1]]

    def N(self):
        temp = self.number
        self.number = [temp[1], temp[5], temp[2], temp[3], temp[0], temp[4]]

    def E(self):
        temp = self.number
        self.number = [temp[3], temp[1], temp[0], temp[5], temp[4], temp[2]]

    def W(self):
        temp = self.number
        self.number = [temp[2], temp[1], temp[5], temp[0], temp[4], temp[3]]

    def order(self, str):
        for ch in str:
            if ch == "S":
                self.S()
            elif ch == "N":
                self.N()
            elif ch == "E":
                self.E()
            else:
                self.W()

    def query(self, top, front):
        while True:
            drc = random.randint(0, 3)
            self.order("NEWS"[drc])
            if self.number[0] == top and self.number[1] == front:
                break

number1 = list(map(int, input().split()))
number2 = list(map(int, input().split()))

dice1 = Dice(number1)
dice2 = Dice(number2)

dice1.query(dice2.number[0], dice2.number[1])
if dice1.number == dice2.number:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import enum
class Direction(enum.Enum):
    N = "N"
    E = "E"
    W = "W"
    S = "S"

    @classmethod
    def value_of(cls, value):
        return [v for v in cls if v.value == value][0]


class Dice:
    def __init__(self, *value_list):
        self.__value_list = list(value_list)

    def rotate(self, direction):
        l = self.__value_list
        if  direction == Direction.N:
            l[0],l[1],l[5],l[4] = l[1],l[5],l[4],l[0]
        elif  direction == Direction.E:
            l[0],l[2],l[5],l[3] = l[3],l[0],l[2],l[5]
        elif  direction == Direction.W:
            l[0],l[2],l[5],l[3] = l[2],l[5],l[3],l[0]
        elif  direction == Direction.S:
            l[0],l[1],l[5],l[4] = l[4],l[0],l[1],l[5]

    def adjust_top_front(self, top_value, front_value):
        for _ in range(2):
            for _ in range(3):
                if self.front_value() == front_value:
                    break
                self.rotate(Direction.N)
            if self.front_value() == front_value:
                break
            self.rotate(Direction.E)
        
        for _ in range(3):
            if self.top_value() == top_value:
                break
            self.rotate(Direction.E)
    
    def is_same_dice(self, othere_dice):
        return (self.top_value() == othere_dice.top_value()
        and self.bottom_value() == othere_dice.bottom_value()
        and self.front_value() == othere_dice.front_value()
        and self.behind_value() == othere_dice.behind_value()
        and self.right_value() == othere_dice.right_value()
        and self.left_value() == othere_dice.left_value())

    def top_value(self):
        return self.__value_list[0]

    def bottom_value(self):
        return self.__value_list[5]

    def front_value(self):
        return self.__value_list[1]

    def behind_value(self):
        return self.__value_list[4]

    def right_value(self):
        return self.__value_list[2]

    def left_value(self):
        return self.__value_list[3]


dice1 = Dice(*input().split())
dice2 = Dice(*input().split())
dice1.adjust_top_front(dice2.top_value(), dice2.front_value())
print("Yes" if dice1.is_same_dice(dice2) else "No")