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, faces):
        self.faces = tuple(faces)

    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])

    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])

    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])

    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])

    def number(self, face_id):
        return self.faces[face_id - 1]

    def checksame(self, faces):
        self_opposite_face = dict(zip([self.number(i) for i in range(1, 7)],
                                      [self.number(i) for i in range(6, 0, -1)]))
        other_opposite_face = dict(zip([faces.number(i) for i in range(1, 7)],
                                       [faces.number(i) for i in range(6, 0, -1)]))
        if self_opposite_face != other_opposite_face:
            return False
        if self.number(2) in (faces.number(3), faces.number(4)):
            faces.roll_west()
        while self.number(2) != faces.number(2):
            faces.roll_north()
        while self.number(1) != faces.number(1):
            faces.roll_west()
        return self.number(3) == faces.number(3)

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

print("Yes" if dice1.checksame(dice2) else "No")

Submission status: Accepted

Solution code:
class Dice:

    def __init__(self, faces):
        self.faces = tuple(faces)

    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])

    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])

    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])

    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])

    def rotate(self):
        self.faces = (self.faces[0], self.faces[2], self.faces[4],
                      self.faces[1], self.faces[3], self.faces[5])

    def issame(self, other_dice):
        for i in range(4):
            if self.faces[0] == other_dice.faces[0]:
                for j in range(4):
                    if self.faces == other_dice.faces:
                        return True
                    self.rotate()
            self.roll_north()

        for i in range(4):
            if self.faces[0] == other_dice.faces[0]:
                for j in range(4):
                    if self.faces == other_dice.faces:
                        return True
                    self.rotate()
            self.roll_east()
        return False

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

print("Yes" if dice1.issame(dice2) else "No")

Submission status: Accepted

Solution code:
import itertools


def roll(dice, commands):
    for command in commands:
        if command == 'N':
            dice[0], dice[1], dice[5], dice[4] = dice[1], dice[5], dice[4], dice[0]
        elif command == 'S':
            dice[0], dice[1], dice[5], dice[4] = dice[4], dice[0], dice[1], dice[5]
        elif command == 'W':
            dice[0], dice[3], dice[5], dice[2] = dice[2], dice[0], dice[3], dice[5]
        elif command == 'E':
            dice[0], dice[3], dice[5], dice[2] = dice[3], dice[5], dice[2], dice[0]

A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(4):
    for j in range(4):
        for commands in itertools.permutations('S' * i + 'W' * j):
            a = A[::]
            roll(a, commands)
            if B == a:
                print('Yes')
                exit()
print('No')

Submission status: Accepted

Solution code:
import itertools


def roll(dice, commands):
    for command in commands:
        if command == 'N':
            dice[0], dice[1], dice[5], dice[4] = dice[1], dice[5], dice[4], dice[0]
        elif command == 'W':
            dice[0], dice[3], dice[5], dice[2] = dice[2], dice[0], dice[3], dice[5]


def solve():
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    for i in range(4):
        for j in range(4):
            for commands in itertools.permutations('N' * i + 'W' * j):
                a = A[::]
                roll(a, commands)
                if B == a:
                    return True
    return False


if __name__ == '__main__':
    print('Yes' if solve() else 'No')

Submission status: Accepted

Solution code:
import itertools


def solve():
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    for i in range(4):
        for j in range(4):
            for commands in itertools.permutations('N' * i + 'W' * j):
                a = A[::]
                for command in commands:
                    if command == 'N':
                        a[0], a[1], a[5], a[4] = a[1], a[5], a[4], a[0]
                    elif command == 'W':
                        a[0], a[3], a[5], a[2] = a[2], a[0], a[3], a[5]
                if B == a:
                    return True
    return False


if __name__ == '__main__':
    print('Yes' if solve() else 'No')

Submission status: Accepted

Solution code:
import random

class Dice:
  def __init__(self, list = map(str, range(1, 7))):
    self.top = list[0]
    self.front = list[1]
    self.right = list[2]
    self.left = list[3]
    self.back = list[4]
    self.bottom = list[5]

    self.dic = {}
    for i in xrange(6):
      if list[i] in self.dic:
        self.dic[list[i]] += 1
      else:
        self.dic[list[i]] = 1

  def print_all(self):
    print "top = " + self.top + ", front = " + self.front + ", right = " + self.right + ", left = " + self.left + ", back = " + self.back + ", bottom = " + self.bottom

  def roll_N(self):
    temp = self.top
    self.top = self.front
    self.front = self.bottom
    self.bottom = self.back
    self.back = temp

  def roll_S(self):
    temp = self.top
    self.top = self.back
    self.back = self.bottom
    self.bottom = self.front
    self.front = temp

  def roll_W(self):
    temp = self.top
    self.top = self.right
    self.right = self.bottom
    self.bottom = self.left
    self.left = temp

  def roll_E(self):
    temp = self.top
    self.top = self.left
    self.left = self.bottom
    self.bottom = self.right
    self.right = temp

  def roll_C(self):
    temp = self.front
    self.front = self.right
    self.right = self.back
    self.back = self.left
    self.left = temp

  def random_roll(self):
    ram = random.randint(1, 4)
    if ram == 1:
      self.roll_E()
    elif ram == 2:
      self.roll_N()
    elif ram == 3:
      self.roll_S()
    else:
      self.roll_W()

  def getDifference(self, dice):
    same_list = []
    different_list = []
    if self.top == dice.top:
      same_list.append("top")
    else:
      different_list.append("top")
    if self.front == dice.front:
      same_list.append("front")
    else:
      different_list.append("front")
    if self.left == dice.left:
      same_list.append("left")
    else:
      different_list.append("left")
    if self.back == dice.back:
      same_list.append("back")
    else:
      different_list.append("back")
    if self.right == dice.right:
      same_list.append("right")
    else:
      different_list.append("right")
    if self.bottom == dice.bottom:
      same_list.append("bottom")
    else:
      different_list.append("bottom")

    result_list = [same_list, different_list]
    return result_list

  def getList(self):
    list = [self.top, self.front, self.right, self.left, self.back, self.bottom]
    return list

first_dice = Dice(raw_input().split(" "))
second_dice = Dice(raw_input().split(" "))

def print_dices():
  print "first dice: "
  first_dice.print_all()
  print "second dice: "
  second_dice.print_all()
  print first_dice.dic

line = "#######################################"

flag = False
num = 0
debug = 0
while num < 4:
  # debug += 1
  # if debug > 10:
  #   break
  # print line

  dic1_keys = first_dice.dic.keys()
  for i in xrange(len(dic1_keys)):
    if first_dice.dic[dic1_keys[i]] != second_dice.dic[dic1_keys[i]]:
      num = 4
      break

  for i in xrange(len(dic1_keys)):
    if first_dice.dic[dic1_keys[i]] == 6 or first_dice.dic[dic1_keys[i]] == 5:
      num = 4
      flag = True
      break

  # print_dices()

  diferece = first_dice.getDifference(second_dice)
  # print diferece

  same_num = len(diferece[0])
  if same_num == 6:
    break
  elif same_num == 5:
    num = 4
    break

  if "front" in diferece[0] or "back" in diferece[0]:
    first_dice.roll_W()
    num += 1
  elif "left" in diferece[0] or "right" in diferece[0]:
    first_dice.roll_S()
    num += 1
  elif "top" in diferece[0] or "bottom" in diferece[0]:
    first_dice.roll_C()
    num += 1
  else:
    first_dice.random_roll()

if flag == True:
  print "Yes"
elif num == 4:
  print "No"
else:
  print "Yes"

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

POSITIONS = ["top", "south", "east", "west", "north", "bottom"]


class Dice(object):

    def __init__(self, initial_faces):
        self.faces = {p: initial_faces[i] for i, p in enumerate(POSITIONS)}
        self.store_previous_faces()

    def store_previous_faces(self):
        self.previous_faces = self.faces.copy()

    def change_face(self, after, before):
        self.faces[after] = self.previous_faces[before]

    def change_faces(self, rotation):
        self.change_face(rotation[0], rotation[1])
        self.change_face(rotation[1], rotation[2])
        self.change_face(rotation[2], rotation[3])
        self.change_face(rotation[3], rotation[0])

    def roll(self, direction):
        self.store_previous_faces()
        if direction == "E":
            self.change_faces(["top", "west", "bottom", "east"])
        elif direction == "N":
            self.change_faces(["top", "south", "bottom", "north"])
        elif direction == "S":
            self.change_faces(["top", "north", "bottom", "south"])
        elif direction == "W":
            self.change_faces(["top", "east", "bottom", "west"])

    def rolls(self, directions):
        for d in directions:
            self.roll(d)


def main():
    dice1 = Dice(input().split())  # standard
    dice2 = Dice(input().split())  # to be rolled
    if dice1.faces["south"] == dice2.faces["west"]:
        dice2.roll("E")
    elif dice1.faces["south"] == dice2.faces["east"]:
        dice2.roll("W")
    while dice1.faces["south"] != dice2.faces["south"]:
        dice2.roll("N")
    for n in range(4):
        if (dice1.faces["top"] == dice2.faces["top"] and
                dice1.faces["east"] == dice2.faces["east"]):
            print("Yes")
            break
        else:
            dice2.roll("E")
    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
mask = [[i for i in range(6)], (1, 5, 2, 3, 0, 4), (2, 1, 5, 0, 4,3),(3, 1, 0, 5, 4, 2), (4, 0, 2, 3, 5, 1)]
mask += [[mask[1][i] for i in mask[1]]]
 
def set_top(dice, top):
    return [dice[i] for i in mask[top]]
 
def twist(dice):
    return [dice[i] for i in (0, 3, 1, 4, 2, 5)]
 
def equal(dice1, dice2):
    for i in range(6):
        tmp_dice = set_top(dice2, i)
        for _ in range(4):
            if dice1 == tmp_dice:
                return True
            tmp_dice = twist(tmp_dice)
    return False
         
dice1 = input().split()
dice2 = input().split()
 
print('Yes' if equal(dice1, dice2) else 'No')

Submission status: Accepted

Solution code:
class Dice(object):

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

    def rotate_S(self):
        self.num = [self.num[4], self.num[0], self.num[2], self.num[3], self.num[5], self.num[1]]

    def rotate_N(self):
        self.num = [self.num[1], self.num[5], self.num[2], self.num[3], self.num[0], self.num[4]]

    def rotate_W(self):
        self.num = [self.num[2], self.num[1], self.num[5], self.num[0], self.num[4], self.num[3]]

    def rotate_E(self):
        self.num = [self.num[3], self.num[1], self.num[0], self.num[5], self.num[4], self.num[2]]

    def rotate_M(self):
        self.num = [self.num[0], self.num[2], self.num[4], self.num[1], self.num[3], self.num[5]]

dice1 = Dice(map(int, raw_input().split()))
dice2 = Dice(map(int, raw_input().split()))
yes_flg = False
if len(set(dice1.num) - set(dice2.num)) != 0:
    print 'No'
else:
    num = []
    for i in range(6):
        if dice1.num[0] == dice2.num[i]:
            num.append(i)
    for j in num:
        if j == 1:
            dice2.rotate_N()
        elif j == 2:
            dice2.rotate_W()
        elif j == 3:
            dice2.rotate_E()
        elif j == 4:
            dice2.rotate_S()
        elif j == 5:
            dice2.rotate_S()
            dice2.rotate_S()

        if dice1.num[5] == dice2.num[5]:
            for i in range(4):
                if (dice1.num[1] == dice2.num[1]) & (dice1.num[2] == dice2.num[2]) & (dice1.num[3] == dice2.num[3]):
                    yes_flg = True
                    break
                dice1.rotate_M()
            if yes_flg:
                break
    if yes_flg:
        print 'Yes'
    else:
        print 'No'

Submission status: Accepted

Solution code:
import copy

class Dice(object):
	def __init__(self,List):
		self.face=List
		
	def n_spin(self,a_list):
		List=copy.copy(a_list)
		temp=List[0]
		List[0]=List[1]
		List[1]=List[5]
		List[5]=List[4]
		List[4]=temp
		return List
		
 	def s_spin(self,a_list):
 		List=copy.copy(a_list)
 		temp=List[0]
 		List[0]=List[4]
 		List[4]=List[5]
		List[5]=List[1]
		List[1]=temp
		return List
		
	def e_spin(self,a_list):
		List=copy.copy(a_list)
		temp=List[0]
		List[0]=List[3]
		List[3]=List[5]
		List[5]=List[2]
		List[2]=temp
		return List
		
 	def w_spin(self,a_list):
 		List = copy.copy(a_list)
 		temp=List[0]
 		List[0]=List[2]
 		List[2]=List[5]
		List[5]=List[3]
		List[3]=temp
		return List

dice_1=Dice(map(int,raw_input().split()))
dice_2=Dice(map(int,raw_input().split()))
emer=copy.copy(dice_2.face)
face_storage=[]
face_storage.append(emer)
judge=False
for a in range(24):
	face_storage.append(dice_2.n_spin(face_storage[a]))
	face_storage.append(dice_2.s_spin(face_storage[a]))
	face_storage.append(dice_2.e_spin(face_storage[a]))
	face_storage.append(dice_2.w_spin(face_storage[a]))
for c in face_storage:
	if c==dice_1.face:
		judge=True
if judge :
	print("Yes")
else :
	print("No")

Submission status: Accepted

Solution code:
class Dice:
    same_dice_index = ('123456', '135246', '142536', '154326',
                       '214365', '231645', '246135', '263415',
                       '312564', '326154', '351624', '365214',
                       '415263', '421653', '456123', '462513',
                       '513462', '536142', '541632', '564312',
                       '624351', '632541', '645231', '653421')

    def __init__(self, num_list):
        self.faces = num_list

    def is_same(self, dice):
        for i in Dice.same_dice_index:
            example_faces = []
            for j in i:
                example_faces.append(self.faces[int(j) - 1])
            if example_faces == dice.faces:
                return 'Yes'
        return 'No'

num_list1 = list(map(int, input().split()))
num_list2 = list(map(int, input().split()))

dice1 = Dice(num_list1)
dice2 = Dice(num_list2)

ans = dice1.is_same(dice2)

print(ans)

Submission status: Accepted

Solution code:
class Dice:
    same_dice_index = ((0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5), (0, 3, 1, 4, 2, 5),
                       (0, 4, 3, 2, 1, 5), (1, 0, 3, 2, 5, 4), (1, 2, 0, 5, 3, 4),
                       (1, 3, 5, 0, 2, 4), (1, 5, 2, 3, 0, 4), (2, 0, 1, 4, 5, 3),
                       (2, 1, 5, 0, 4, 3), (2, 4, 0, 5, 1, 3), (2, 5, 4, 1, 0, 3),
                       (3, 0, 4, 1, 5, 2), (3, 1, 0, 5, 4, 2), (3, 4, 5, 0, 1, 2),
                       (3, 5, 1, 4, 0, 2), (4, 0, 2, 3, 5, 1), (4, 2, 5, 0, 3, 1),
                       (4, 3, 0, 5, 2, 1), (4, 5, 3, 2, 0, 1), (5, 1, 3, 2, 4, 0),
                       (5, 2, 1, 4, 3, 0), (5, 3, 4, 1, 2, 0), (5, 4, 2, 3, 1, 0))

    def __init__(self, str_tpl):
        self.faces = str_tpl

    def is_same(self, dice):
        for i in Dice.same_dice_index:
            for n, j in enumerate(i):
                if dice.faces[n] != self.faces[j]:
                    break
            else:
                return True
        return False


str_tpl1 = tuple(input().split())
dice1 = Dice(str_tpl1)

str_tpl2 = tuple(input().split())
dice2 = Dice(str_tpl2)

if dice1.is_same(dice2):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
class Dice:
    same_dice_index = ((0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5), (0, 3, 1, 4, 2, 5),
                       (0, 4, 3, 2, 1, 5), (1, 0, 3, 2, 5, 4), (1, 2, 0, 5, 3, 4),
                       (1, 3, 5, 0, 2, 4), (1, 5, 2, 3, 0, 4), (2, 0, 1, 4, 5, 3),
                       (2, 1, 5, 0, 4, 3), (2, 4, 0, 5, 1, 3), (2, 5, 4, 1, 0, 3),
                       (3, 0, 4, 1, 5, 2), (3, 1, 0, 5, 4, 2), (3, 4, 5, 0, 1, 2),
                       (3, 5, 1, 4, 0, 2), (4, 0, 2, 3, 5, 1), (4, 2, 5, 0, 3, 1),
                       (4, 3, 0, 5, 2, 1), (4, 5, 3, 2, 0, 1), (5, 1, 3, 2, 4, 0),
                       (5, 2, 1, 4, 3, 0), (5, 3, 4, 1, 2, 0), (5, 4, 2, 3, 1, 0))

    def __init__(self, str_tpl):
        self.faces = str_tpl

    def is_same(self, dice):
        for i in Dice.same_dice_index:
            for n, j in enumerate(i):
                if dice.faces[n] != self.faces[j]:
                    break
            else:
                return 'Yes'
        return 'No'


str_tpl1 = tuple(input().split())
dice1 = Dice(str_tpl1)

str_tpl2 = tuple(input().split())
dice2 = Dice(str_tpl2)

print(dice1.is_same(dice2))

Submission status: Accepted

Solution code:
#-*- coding:utf-8 -*-
import sys
rolls1 = raw_input().split()
rolls2 = raw_input().split()
testpare = (rolls1[0],rolls1[5])
testparerev = (rolls1[5],rolls1[0])
rolls2pare = [(rolls2[0],rolls2[5]),(rolls2[2],rolls2[3]),(rolls2[1],rolls2[4])]
#??????????????¢????????¢??§?????´??????????????????????????????????¢????
#??¨??¨????????¢?????£????????????????????´???????????¢???3????????¨??????????¢????????????????????????????
if testpare in rolls2pare:
    pareps = rolls2pare.index(testpare)
    revflag = False
elif testparerev in rolls2pare:
    pareps = rolls2pare.index(testparerev)
    revflag = True
else:
    print "No"
    sys.exit(0)
#?¬???????????????¢??\????????¨????????????????????£??????????¢????
#??????????????????????????????
li1 = [rolls1[1],rolls1[2],rolls1[4],rolls1[3]]
# print pareps
if pareps==0:
    if revflag:
        tmp = rolls2[2]
        rolls2[2] = rolls2[3]
        rolls2[3] = tmp
    li2 = [rolls2[1],rolls2[2],rolls2[4],rolls2[3]]
elif pareps==1:
    if revflag:
        tmp = rolls2[1]
        rolls2[1] = rolls2[4]
        rolls2[4] = tmp
    li2 = [rolls2[0],rolls2[1],rolls2[5],rolls2[4]]
elif pareps==2:
    if revflag:
        tmp = rolls2[0]
        rolls2[0] = rolls2[5]
        rolls2[5] = tmp
    li2 = [rolls2[0],rolls2[3],rolls2[5],rolls2[2]]
else:
    print "No"
    sys.exit(0)
#?????????????????´?¢????
# print li1
# print li2
i=0
j=li2.index(li1[0])
matchflag = True#else??\??£???????????´?????????
for x in xrange(4):
    # print "%s : %s"%(li1[i],li2[j])
    if li1[i]==li2[j]:
        j+=1
        i+=1
    else:
        matchflag =False
        break
    if i>3:
        i=0
    if j>3:
        j=0
if matchflag:
    print "Yes"
else:
    print "No"

Submission status: Accepted

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

if tuple(sorted(d1)) != tuple(sorted(d2)):
    print('No')
    exit()

d1dict = {v: k for k, v in enumerate(d1)}
dms = ((1, 2, 4, 3), (0, 3, 5, 2), (0, 1, 5, 4), (0, 4, 5, 1), (0, 2, 5, 3), (1, 3, 4, 2))

d20 = d1dict[d2[0]]
dm = dms[d20]
try:
    dmi = dm.index(d1dict[d2[1]])
    print('Yes' if d2[2] == d1[dm[(dmi + 1) % 4]]
                   and d2[3] == d1[dm[(dmi + 3) % 4]]
                   and d2[4] == d1[dm[(dmi + 2) % 4]]
                   and d2[5] == d1[5 - d20] else 'No')
except:
    print('No')
    exit()

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self, nums):
        self.nums = nums
        self.top, self.front, self.right = 0, 1, 2

    def __eq__(self, dice):
        for x in "NNNNEEE":
            dice.move(x)
            for _ in range(4):
                dice.move("ESW")
                if self.nums[self.top] == dice.nums[dice.top] and \
                        self.nums[self.front] == dice.nums[dice.front] and \
                        self.nums[self.right] == dice.nums[dice.right] and \
                        self.nums[5 - self.top] == dice.nums[5 - dice.top] and \
                        self.nums[5 - self.front] == dice.nums[5 - dice.front] and \
                        self.nums[5 - self.right] == dice.nums[5 - dice.right]:
                    return True
        return False

    def move(self, op):
        for c in op:
            if c == 'N':
                self.top, self.front = self.front, 5 - self.top
            elif c == 'S':
                self.top, self.front = 5 - self.front, self.top
            elif c == 'E':
                self.top, self.right = 5 - self.right, self.top
            else:
                self.top, self.right = self.right, 5 - self.top

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

Submission status: Accepted

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

class dice_class:
    def __init__(self, list):
        self.num = list

    def sut(self, top):  #set_up_top
        i = 0
        while i < 3:
            if self.num[0] == top:
                break
            else:
                self.roll('E')
            if self.num[0] == top:
                break
            else:
                self.roll('N')
            i += 1

    def suf(self, front):   #set_up_front
        i = 0
        while i < 4:
            if self.num[1] == front:
                break
            else:
                self.roll('SEN')
            i += 1

    def roll(self, s):
        for i in s:
            if i == 'E':
                self.rollE()
            elif i == 'N':
                self.rollN()
            elif i == 'S':
                self.rollS()
            elif i == 'W':
                self.rollW()

    def rollE(self):
        self.num = [self.num[3], self.num[1], self.num[0], self.num[5], self.num[4], self.num[2]]

    def rollN(self):
        self.num = [self.num[1], self.num[5], self.num[2], self.num[3], self.num[0], self.num[4]]

    def rollS(self):
        self.num = [self.num[4], self.num[0], self.num[2], self.num[3], self.num[5], self.num[1]]

    def rollW(self):
        self.num = [self.num[2], self.num[1], self.num[5], self.num[0], self.num[4], self.num[3]]


if __name__ == "__main__":
    dice1 = dice_class(map(int, raw_input().split()))
    dice2 = dice_class(map(int, raw_input().split()))
    flg = False

    for i in range(6):
        if i % 2:
            dice1.roll('E')
        else:
            dice1.roll('N')
        dice2.sut(dice1.num[0])
        dice2.suf(dice1.num[1])
        if dice1.num == dice2.num:
            flg = True
            break

    if flg:
        print "Yes"
    else:
        print "No"

Submission status: Accepted

Solution code:
import sys
class Dice:
    def __init__(self):
        self.front = '1'
        self.back = '6'
        self.top = '5'
        self.bottom = '2'
        self. right = '3'
        self.left = '4'
    def turnRight(self):
        temp = self.top
        self.top = self.left
        self.left = self.bottom
        self.bottom = self.right
        self.right = temp
        return self.top
    def turnLeft(self):
        temp = self.top
        self.top = self.right
        self.right = self.bottom
        self.bottom = self.left
        self.left = temp
        return self.top
    def turnFront(self):
        temp = self.top
        self.top = self.back
        self.back = self.bottom
        self.bottom = self.front
        self.front = temp
        return self.top
    def turnBack(self):
        temp = self.top
        self.top = self.front
        self.front = self.bottom
        self.bottom = self.back
        self.back = temp
        return self.top
    def __eq__(self, other):
        return (self.top, self.bottom, self.front, self.back, self.right, self.left) == other
    def __ne__(self, other):
        return (self.top, self.bottom, self.front, self.back, self.right, self.left) != other
def judge(obj1, obj2):
    if obj1 == obj2:
        print('Yes')
        sys.exit()
    else:
        return

A = Dice()
B = Dice()
A.top, A.front, A.right, A.left, A.back, A.bottom = input().split()
B.top, B.front, B.right, B.left, B.back, B.bottom = input().split()

for rot1 in range(4):
    for rot2 in range(4):
        judge(A, B)
        B.turnRight()
    B.turnFront()
B.turnRight()
B.turnFront()
for rot in range(4):
    judge(A,B)
    B.turnRight()
B.turnBack()
B.turnBack()
for rot in range(4):
    judge(A,B)
    B.turnRight()
print('No')

Submission status: Accepted

Solution code:
def move_dice(d, dir):
    if(dir == 'N'):
        d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4]
    if(dir == 'S'):
        d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1]
    if(dir == 'E'):
        d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2]
    if(dir == 'W'):
        d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3]

def rotate_right_dice(d):
    d[1], d[2], d[3], d[4] = d[3], d[1], d[4], d[2]

def to_up_dice(d, num_index):
    move_num = {0:0, 1:3, 2:2, 3:0, 4:1, 5:2}
    if(num_index==2 or num_index==3):
        move_dice(d, 'E')
    for _ in range(move_num[num_index]):
        move_dice(d, 'N')

def to_front_dice(d, num):
    while(d[1] != num):
        rotate_right_dice(d)

def equal_dice(d1, d2):
    for i in range(6):
        tmp_d = list(d1)
        to_up_dice(tmp_d, i)
        for _ in range(4):
            if(tmp_d == d2): return 'Yes'
            else: rotate_right_dice(tmp_d)
    return 'No'



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

print(equal_dice(dice1, dice2))

Submission status: Accepted

Solution code:
import sys


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

    def north(self):
        self.change([2, 6, 3, 4, 1, 5])

    def south(self):
        self.change([5, 1, 3, 4, 6, 2])

    def east(self):
        self.change([4, 2, 1, 6, 5, 3])

    def west(self):
        self.change([3, 2, 6, 1, 5, 4])

    def change(self, convert):
        result = []
        for i in range(6):
            result.append(self.labels[convert[i] - 1])

        self.labels = result

directions = 'EEEESEEEESEEEESEEEESNWSEEEESSEEEE'

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

for direction in directions:
    if direction == 'N':
        dice1.north()
    if direction == 'S':
        dice1.south()
    if direction == 'E':
        dice1.east()
    if direction == 'W':
        dice1.west()

    if dice1.labels == dice2.labels:
        print('Yes')
        sys.exit(0)

print('No')

Submission status: Accepted

Solution code:
#   2???????????????????????????????????????????????????????????°??????

#   ??????????????¢????????????????????????
#   top = 1 front = 2 right = 3 left = 4 back = 5 bottom = 6
class Dice:
    def __init__(self, nums):
        self.face = nums
    #   2->1->5->6
    def turnSouth(self):
        temp = self.face[0]
        self.face[0] = self.face[4]
        self.face[4] = self.face[5]
        self.face[5] = self.face[1]
        self.face[1] = temp
        return self
    #   4->1->3->6
    def turnEast(self):
        temp = self.face[0]
        self.face[0] = self.face[2]
        self.face[2] = self.face[5]
        self.face[5] = self.face[3]
        self.face[3] = temp
        return self
    #   3->1->4->6
    def turnWest(self):
        temp = self.face[0]
        self.face[0] = self.face[3]
        self.face[3] = self.face[5]
        self.face[5] = self.face[2]
        self.face[2] = temp
        return self
    #   5->1->2->6
    def turnNorth(self):
        temp = self.face[0]
        self.face[0] = self.face[1]
        self.face[1] = self.face[5]
        self.face[5] = self.face[4]
        self.face[4] = temp
    #   2->3->5->4
    def turnRight(self):
        temp = self.face[1]
        self.face[1] = self.face[2]
        self.face[2] = self.face[4]
        self.face[4] = self.face[3]
        self.face[3] = temp
        return self
    #   2->4->5->3
    def turnLeft(self):
        temp = self.face[1]
        self.face[1] = self.face[3]
        self.face[3] = self.face[4]
        self.face[4] = self.face[2]
        self.face[2] = temp
        return self
    def equals(self, Dice):
        #   ?????¢??????????????????????????????
        for i in range(0, 4):
            if self.face[0] == Dice.face[0]:
                #   ??£??¢???????????????????????¢????????????????????¢
                for j in range(0, 4):
                    if self.face[1] == Dice.face[1]:
                        if self.face == Dice.face:
                            return True
                    Dice.turnRight()
            Dice.turnNorth()
        #   ?????¢??????????????????????????????
        for i in range(0, 4):
            if self.face[0] == Dice.face[0]:
                #   ??£??¢???????????????????????¢????????????????????¢
                for j in range(0, 4):
                    if self.face[1] == Dice.face[1]:
                        if self.face == Dice.face:
                            return True
                    Dice.turnRight()
            Dice.turnEast()
        return False

#   Dice?????????
Dice1 = Dice(input().split())
Dice2 = Dice(input().split())

if Dice1.equals(Dice2):
    print("Yes")
else:
    print("No")