Tom is decorating the pavement in his garden with N square tiles. Each tile is divided into four triangles of different colors (white - 'W', red - 'R', green - 'G' and blue - 'B'). A tile is described as a string of four characters denoting respectively, the color of the upper, right, bottom and left triangle. For example, the tile in the figure below is described as "WRGB".
Tom arranged the tiles in a row and decided to rotate some of them to obtain a pretty sequence. He considers a sequence of tiles pretty if each pair of adjacent tiles shares one side of the same color.
Write a function:
def solution(A)
that, given an array A of N strings, representing the sequence of tiles, returns the minimum number of 90-degree rotations (clockwise or counter-clockwise) that Tom has to perform.
Examples:
1. Given A = ["RGBW", "GBRW"], the function should return 1.
Tom can rotate the second tile counter-clockwise once to obtain a pretty sequence.
2. Given A = ["WBGR", "WBGR", "WRGB", "WRGB", "RBGW"], the function should return 4.
Tom can obtain a pretty sequence by rotating the first and third tiles counter-clockwise and the second and fourth tiles clockwise.
3. Given A = ["RBGW", "GBRW", "RWGB", "GBRW"], the function should return 2.
Tom can rotate the first tile clockwise twice to obtain a pretty sequence.
4. Given A = ["GBRW", "RBGW", "BWGR", "BRGW"], the function should return 2.
Tom can rotate the first two tiles clockwise to obtain a pretty sequence.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string representing a tile has 4 letters (exactly one occurrence of 'R', 'G', 'B' and 'W').
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def solution(A):
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def solution(A):
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
rotate(A[i])
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def solution(A):
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
rotate(A[i],)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def solution(A):
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
elif:
rotate(A[i],1)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def solution(A):
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
elif ispretty(rotate(A[i],1), A[i+1]):
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def solution(A):
cnt=0
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
elif ispretty(rotate(A[i],1), A[i+1]):
cnt+=1
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def solution(A):
cnt=0
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
elif ispretty(rotate(A[i],1), A[i+1]):
cnt+=1
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
def solution(A):
cnt=0
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
elif ispretty(rotate(A[i],1), A[i+1]):
cnt+=1
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
elif ispretty(rotate(A[i],1), A[i+1]):
cnt+=1
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
elif ispretty(rotate(A[i],1), A[i+1]):
cnt+=1
continue
elif ispretty(A[i], A[i+1]):
cnt+=1
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(rotate(A[i],1), A[i+1]):
cnt+=1
continue
elif ispretty(A[i], A[i+1]):
cnt+=1
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(rotate(A[i],1), A[i+1]):
cnt+=1
break
elif ispretty(A[i], A[i+1]):
cnt+=1
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(rotate(A[i],j), A[i+1]):
cnt+=1
break
elif ispretty(A[i], A[i+1]):
cnt+=1
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(rotate(A[i],j+1), A[i+1]):
cnt+=1
break
elif ispretty(A[i], A[i+1]):
cnt+=2
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(rotate(A[i],j+1), A[i+1]):
cnt+=1
break
elif ispretty(A[i], (A[i+1])):
cnt+=2
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(rotate(A[i],j+1), A[i+1]):
cnt+=1
break
elif ispretty(A[i], rotate(A[i+1],j+1)):
cnt+=2
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(rotate(A[i],j+1), A[i+1]):
cnt+=1
break
elif ispretty(A[i], rotate(A[i+1],j+1)):
cnt+=1
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(rotate(A[i],j+1), A[i+1]):
cnt+=1
break
elif ispretty(A[i], rotate(A[i+1],j+1)):
cnt+=1
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(4):
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(rotate(A[i],j+1), A[i+1]):
cnt+=1
break
elif ispretty(A[i], rotate(A[i+1],j+1)):
cnt+=1
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(4):
A[0] = rotate(A[0],i)
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(rotate(A[i],j+1), A[i+1]):
cnt+=1
break
elif ispretty(A[i], rotate(A[i+1],j+1)):
cnt+=1
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(4):
A[0] = rotate(A[0],i)
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
elif ispretty(A[i], rotate(A[i+1],j+1)):
cnt+=1
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(4):
A[0] = rotate(A[0],i)
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
cnt+=1
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(4):
A[0] = rotate(A[0],i)
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
cnt+=()
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(4):
A[0] = rotate(A[0],i)
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(4):
A[0] = rotate(A[0],i)
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
continue
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(4):
A[0] = rotate(A[0],i)
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(4):
A[0] = rotate(A[0],i)
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
cnt=0
for i in range(4):
A[0] = rotate(A[0],i)
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
cnt=0
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
cnt=0
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
return max(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
return max(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
cnt
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
return max(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
return max(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
return max(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
return max(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return max(answer)
[1, 3, 3, 3]
[5, 5, 6, 6]
[2, 2, 3, 3]
[3, 3, 4, 4]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
[1, 3, 3, 3]
[5, 5, 6, 6]
[2, 2, 3, 3]
[3, 3, 4, 4]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
if i==3
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
[1, 3, 3, 1]
[5, 5, 6, 4]
[2, 2, 3, 1]
[3, 3, 4, 2]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
print(A[0])
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
RGBW GBWR WRGB BWRG [1, 3, 3, 1]
WBGR BGRW RWBG GRWB [5, 5, 6, 4]
RBGW BGWR WRBG GWRB [2, 2, 3, 1]
GBRW BRWG WGBR RWGB [3, 3, 4, 2]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
print(A[0])
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[:]
for i in range(4):
cnt=0
A[0] = rotate(A[0],i)
print(A[0])
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[:]
for i in range(4):
cnt=0
A[0] = rotate(initA,i)
print(A[0])
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[:]
for i in range(4):
cnt=0
A[0] = rotate(initA,i)
print(A[0])
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
['RGBW', 'GBRW'] ['GBRW', 'RGBW'] ['RGBW', 'GBRW'] ['RGBW', 'GBRW'] [0, 1, 2, 1]
['WBGR', 'WBGR', 'WRGB', 'WRGB', 'RBGW'] ['WBGR', 'WRGB', 'WRGB', 'RBGW', 'WBGR'] ['WRGB', 'WRGB', 'RBGW', 'WBGR', 'WBGR'] ['WRGB', 'RBGW', 'WBGR', 'WBGR', 'WRGB'] [3, 4, 5, 4]
['RBGW', 'GBRW', 'RWGB', 'GBRW'] ['GBRW', 'RWGB', 'GBRW', 'RBGW'] ['RWGB', 'GBRW', 'RBGW', 'GBRW'] ['GBRW', 'RBGW', 'GBRW', 'RWGB'] [0, 1, 2, 1]
['GBRW', 'RBGW', 'BWGR', 'BRGW'] ['RBGW', 'BWGR', 'BRGW', 'GBRW'] ['BWGR', 'BRGW', 'GBRW', 'RBGW'] ['BRGW', 'GBRW', 'RBGW', 'BWGR'] [1, 2, 3, 2]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[:]
for i in range(4):
cnt=0
A[0] = rotate(initA, i)
print(A[0])
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0:1]
for i in range(4):
cnt=0
A[0] = rotate(initA, i)
print(A[0])
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
Traceback (most recent call last): File "exec.py", line 115, in <module> main() File "exec.py", line 91, in main result = solution( A ) File "/tmp/exec_user_poagiv62/solution.py", line 25, in solution if ispretty(A[i], A[i+1]): File "/tmp/exec_user_poagiv62/solution.py", line 8, in ispretty return True if s1[1] == s2[3] else False IndexError: list index out of rangestdout:
['RGBW']
Traceback (most recent call last): File "exec.py", line 115, in <module> main() File "exec.py", line 91, in main result = solution( A ) File "/tmp/exec_user_poagiv62/solution.py", line 25, in solution if ispretty(A[i], A[i+1]): File "/tmp/exec_user_poagiv62/solution.py", line 8, in ispretty return True if s1[1] == s2[3] else False IndexError: list index out of rangestdout:
['WBGR']
Traceback (most recent call last): File "exec.py", line 115, in <module> main() File "exec.py", line 91, in main result = solution( A ) File "/tmp/exec_user_poagiv62/solution.py", line 25, in solution if ispretty(A[i], A[i+1]): File "/tmp/exec_user_poagiv62/solution.py", line 8, in ispretty return True if s1[1] == s2[3] else False IndexError: list index out of rangestdout:
['RBGW']
Traceback (most recent call last): File "exec.py", line 115, in <module> main() File "exec.py", line 91, in main result = solution( A ) File "/tmp/exec_user_poagiv62/solution.py", line 25, in solution if ispretty(A[i], A[i+1]): File "/tmp/exec_user_poagiv62/solution.py", line 8, in ispretty return True if s1[1] == s2[3] else False IndexError: list index out of rangestdout:
['GBRW']
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
print()
for i in range(4):
cnt=0
A[0] = rotate(initA, i)
print(A[0])
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
print(initA, end=':')
for i in range(4):
cnt=0
A[0] = rotate(initA, i)
print(A[0])
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
RGBW:RGBW GBWR BWRG WRGB [1, 3, 2, 2]
WBGR:WBGR BGRW GRWB RWBG [5, 5, 5, 5]
RBGW:RBGW BGWR GWRB WRBG [2, 2, 2, 2]
GBRW:GBRW BRWG RWGB WGBR [3, 3, 3, 3]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for i in range(4):
cnt=0
A[0] = rotate(initA, i)
print(A[0])
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for i in range(4):
cnt=0
print(initA, end=':')
A[0] = rotate(initA, i)
print(A[0])
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
RGBW:RGBW RGBW:GBWR RGBW:BWRG RGBW:WRGB [1, 3, 2, 2]
WBGR:WBGR WBGR:BGRW WBGR:GRWB WBGR:RWBG [5, 5, 5, 5]
RBGW:RBGW RBGW:BGWR RBGW:GWRB RBGW:WRBG [2, 2, 2, 2]
GBRW:GBRW GBRW:BRWG GBRW:RWGB GBRW:WGBR [3, 3, 3, 3]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for i in range(4):
cnt=0
A[0] = rotate(initA, i)
print(A[0])
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for i in range(4):
cnt=0
A[0] = rotate(initA, i)
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
[1, 3, 2, 2]
[5, 5, 5, 5]
[2, 2, 2, 2]
[3, 3, 3, 3]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for i in range(4):
cnt=0
A[0] = rotate(initA, i)
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for i in range(4):
cnt=0
A[0] = rotate(initA, i)
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] =
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for i in range(4):
cnt=0
A[0] = rotate(initA, i)
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
answer.append(cnt)
print(answer)
return min(answer)
[1, 2, 4, 2]
[5, 5, 7, 5]
[6, 4, 5, 4]
[6, 4, 7, 4]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for i in range(4):
cnt=0
A[0] = rotate(initA, i)
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
pri
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for i in range(4):
cnt=0
A[0] = rotate(initA, i)
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(j,"번째")
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for i in range(4):
cnt=0
A[0] = rotate(initA, i)
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(i,"번째", j+1, "돌림")
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for i in range(4):
cnt=0
A[0] = rotate(initA, i)
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(i+1,"번째", j+1, "돌림")
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
answer.append(cnt)
print(answer)
return min(answer)
1 ?? 1 ?? 1 ?? 1 ?? 1 ?? 2 ?? 1 ?? 3 ?? [1, 2, 4, 2]
1 ?? 2 ?? 2 ?? 2 ?? 4 ?? 1 ?? 1 ?? 1 ?? 2 ?? 3 ?? 3 ?? 3 ?? 4 ?? 3 ?? 1 ?? 1 ?? 2 ?? 3 ?? 3 ?? 3 ?? 4 ?? 2 ?? 1 ?? 1 ?? 2 ?? 3 ?? 3 ?? 3 ?? 4 ?? 1 ?? [5, 5, 7, 5]
1 ?? 2 ?? 2 ?? 2 ?? 3 ?? 2 ?? 1 ?? 3 ?? 2 ?? 3 ?? 3 ?? 3 ?? 1 ?? 3 ?? 2 ?? 3 ?? 3 ?? 3 ?? 1 ?? 3 ?? 2 ?? 3 ?? 3 ?? 3 ?? [6, 4, 5, 4]
1 ?? 2 ?? 2 ?? 2 ?? 3 ?? 2 ?? 1 ?? 3 ?? 2 ?? 1 ?? 3 ?? 3 ?? 1 ?? 3 ?? 2 ?? 2 ?? 3 ?? 2 ?? 1 ?? 3 ?? 2 ?? 3 ?? 3 ?? 1 ?? [6, 4, 7, 4]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for i in range(4):
cnt=0
A[0] = rotate(initA, i)
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(i+1,"", j+1, "돌림")
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for i in range(4):
cnt=0
A[0] = rotate(initA, i)
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(i+1,":", j+1, "돌림")
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for i in range(4):
cnt=0
A[0] = rotate(initA, i)
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(i+1,":", j+1, "rotate")
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
answer.append(cnt)
print(answer)
return min(answer)
1 : 1 rotate 1 : 1 rotate 1 : 2 rotate 1 : 3 rotate [1, 2, 4, 2]
1 : 2 rotate 2 : 2 rotate 4 : 1 rotate 1 : 1 rotate 2 : 3 rotate 3 : 3 rotate 4 : 3 rotate 1 : 1 rotate 2 : 3 rotate 3 : 3 rotate 4 : 2 rotate 1 : 1 rotate 2 : 3 rotate 3 : 3 rotate 4 : 1 rotate [5, 5, 7, 5]
1 : 2 rotate 2 : 2 rotate 3 : 2 rotate 1 : 3 rotate 2 : 3 rotate 3 : 3 rotate 1 : 3 rotate 2 : 3 rotate 3 : 3 rotate 1 : 3 rotate 2 : 3 rotate 3 : 3 rotate [6, 4, 5, 4]
1 : 2 rotate 2 : 2 rotate 3 : 2 rotate 1 : 3 rotate 2 : 1 rotate 3 : 3 rotate 1 : 3 rotate 2 : 2 rotate 3 : 2 rotate 1 : 3 rotate 2 : 3 rotate 3 : 1 rotate [6, 4, 7, 4]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
A[0] = rotate(initA, i)
if i==3:
cnt+=1
else:
cnt+=i
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(i+1,":", j+1, "rotate")
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
A[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(i+1,":", j+1, "rotate")
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
A[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(i+1,":", j+1, "rotate")
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
answer.append(cnt)
print(answer)
return min(answer)
1 : 1 rotate 1 : 1 rotate 1 : 2 rotate 1 : 3 rotate [1, 2, 4, 2]
1 : 2 rotate 2 : 2 rotate 4 : 1 rotate 1 : 1 rotate 2 : 3 rotate 3 : 3 rotate 4 : 3 rotate 1 : 1 rotate 2 : 3 rotate 3 : 3 rotate 4 : 2 rotate 1 : 1 rotate 2 : 3 rotate 3 : 3 rotate 4 : 1 rotate [5, 5, 7, 5]
1 : 2 rotate 2 : 2 rotate 3 : 2 rotate 1 : 3 rotate 2 : 3 rotate 3 : 3 rotate 1 : 3 rotate 2 : 3 rotate 3 : 3 rotate 1 : 3 rotate 2 : 3 rotate 3 : 3 rotate [6, 4, 5, 4]
1 : 2 rotate 2 : 2 rotate 3 : 2 rotate 1 : 3 rotate 2 : 1 rotate 3 : 3 rotate 1 : 3 rotate 2 : 2 rotate 3 : 2 rotate 1 : 3 rotate 2 : 3 rotate 3 : 1 rotate [6, 4, 7, 4]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
A[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(ri+1,":", j+1, "rotate")
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
A[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(r, ",",i+1,":", j+1, "rotate")
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
answer.append(cnt)
print(answer)
return min(answer)
0 , 1 : 1 rotate 1 , 1 : 1 rotate 2 , 1 : 2 rotate 3 , 1 : 3 rotate [1, 2, 4, 2]
0 , 1 : 2 rotate 0 , 2 : 2 rotate 0 , 4 : 1 rotate 1 , 1 : 1 rotate 1 , 2 : 3 rotate 1 , 3 : 3 rotate 1 , 4 : 3 rotate 2 , 1 : 1 rotate 2 , 2 : 3 rotate 2 , 3 : 3 rotate 2 , 4 : 2 rotate 3 , 1 : 1 rotate 3 , 2 : 3 rotate 3 , 3 : 3 rotate 3 , 4 : 1 rotate [5, 5, 7, 5]
0 , 1 : 2 rotate 0 , 2 : 2 rotate 0 , 3 : 2 rotate 1 , 1 : 3 rotate 1 , 2 : 3 rotate 1 , 3 : 3 rotate 2 , 1 : 3 rotate 2 , 2 : 3 rotate 2 , 3 : 3 rotate 3 , 1 : 3 rotate 3 , 2 : 3 rotate 3 , 3 : 3 rotate [6, 4, 5, 4]
0 , 1 : 2 rotate 0 , 2 : 2 rotate 0 , 3 : 2 rotate 1 , 1 : 3 rotate 1 , 2 : 1 rotate 1 , 3 : 3 rotate 2 , 1 : 3 rotate 2 , 2 : 2 rotate 2 , 3 : 2 rotate 3 , 1 : 3 rotate 3 , 2 : 3 rotate 3 , 3 : 1 rotate [6, 4, 7, 4]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
A[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(0, r, ",",i+1,":", j+1, "rotate")
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
answer.append(cnt)
print(answer)
return min(answer)
0 0 , 1 : 1 rotate 0 1 , 1 : 1 rotate 0 2 , 1 : 2 rotate 0 3 , 1 : 3 rotate [1, 2, 4, 2]
0 0 , 1 : 2 rotate 0 0 , 2 : 2 rotate 0 0 , 4 : 1 rotate 0 1 , 1 : 1 rotate 0 1 , 2 : 3 rotate 0 1 , 3 : 3 rotate 0 1 , 4 : 3 rotate 0 2 , 1 : 1 rotate 0 2 , 2 : 3 rotate 0 2 , 3 : 3 rotate 0 2 , 4 : 2 rotate 0 3 , 1 : 1 rotate 0 3 , 2 : 3 rotate 0 3 , 3 : 3 rotate 0 3 , 4 : 1 rotate [5, 5, 7, 5]
0 0 , 1 : 2 rotate 0 0 , 2 : 2 rotate 0 0 , 3 : 2 rotate 0 1 , 1 : 3 rotate 0 1 , 2 : 3 rotate 0 1 , 3 : 3 rotate 0 2 , 1 : 3 rotate 0 2 , 2 : 3 rotate 0 2 , 3 : 3 rotate 0 3 , 1 : 3 rotate 0 3 , 2 : 3 rotate 0 3 , 3 : 3 rotate [6, 4, 5, 4]
0 0 , 1 : 2 rotate 0 0 , 2 : 2 rotate 0 0 , 3 : 2 rotate 0 1 , 1 : 3 rotate 0 1 , 2 : 1 rotate 0 1 , 3 : 3 rotate 0 2 , 1 : 3 rotate 0 2 , 2 : 2 rotate 0 2 , 3 : 2 rotate 0 3 , 1 : 3 rotate 0 3 , 2 : 3 rotate 0 3 , 3 : 1 rotate [6, 4, 7, 4]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
A[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(0, r, ",",i+1,":", j+1, "rotate")
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
A[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(0, r, ",",i+1,":", j+1, "rotate")
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
A[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(0, r, ",",i+1,":", j+1, "rotate")
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
break
answer.append(cnt)
print(answer)
return min(answer)
0 0 , 1 : 1 rotate 0 1 , 1 : 1 rotate 0 2 , 1 : 2 rotate 0 3 , 1 : 3 rotate [1, 2, 4, 2]
0 0 , 1 : 2 rotate 0 0 , 2 : 2 rotate 0 0 , 4 : 1 rotate 0 1 , 1 : 1 rotate 0 1 , 2 : 3 rotate 0 1 , 3 : 3 rotate 0 1 , 4 : 3 rotate 0 2 , 1 : 1 rotate 0 2 , 2 : 3 rotate 0 2 , 3 : 3 rotate 0 2 , 4 : 2 rotate 0 3 , 1 : 1 rotate 0 3 , 2 : 3 rotate 0 3 , 3 : 3 rotate 0 3 , 4 : 1 rotate [5, 5, 7, 5]
0 0 , 1 : 2 rotate 0 0 , 2 : 2 rotate 0 0 , 3 : 2 rotate 0 1 , 1 : 3 rotate 0 1 , 2 : 3 rotate 0 1 , 3 : 3 rotate 0 2 , 1 : 3 rotate 0 2 , 2 : 3 rotate 0 2 , 3 : 3 rotate 0 3 , 1 : 3 rotate 0 3 , 2 : 3 rotate 0 3 , 3 : 3 rotate [6, 4, 5, 4]
0 0 , 1 : 2 rotate 0 0 , 2 : 2 rotate 0 0 , 3 : 2 rotate 0 1 , 1 : 3 rotate 0 1 , 2 : 1 rotate 0 1 , 3 : 3 rotate 0 2 , 1 : 3 rotate 0 2 , 2 : 2 rotate 0 2 , 3 : 2 rotate 0 3 , 1 : 3 rotate 0 3 , 2 : 3 rotate 0 3 , 3 : 1 rotate [6, 4, 7, 4]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
A[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(0, r, ",",i+1,":", j+1, "rotate",)
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
A[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(0, r, ",",i+1,":", j+1, "rotate", A[i], A)
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
A[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(0, r, ",",i+1,":", j+1, "rotate", A[i], rotate(A[i+1],j+1))
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
break
answer.append(cnt)
print(answer)
return min(answer)
0 0 , 1 : 1 rotate RGBW BRWG 0 1 , 1 : 1 rotate GBWR RWGB 0 2 , 1 : 2 rotate BWRG GBRW 0 3 , 1 : 3 rotate WRGB WGBR [1, 2, 4, 2]
0 0 , 1 : 2 rotate WBGR GRWB 0 0 , 2 : 2 rotate GRWB GBWR 0 0 , 4 : 1 rotate WRGB BGWR 0 1 , 1 : 1 rotate BGRW RWBG 0 1 , 2 : 3 rotate RWBG RGBW 0 1 , 3 : 3 rotate RGBW BWRG 0 1 , 4 : 3 rotate BWRG RBGW 0 2 , 1 : 1 rotate GRWB WBGR 0 2 , 2 : 3 rotate WBGR WRGB 0 2 , 3 : 3 rotate WRGB GBWR 0 2 , 4 : 2 rotate GBWR GWRB 0 3 , 1 : 1 rotate RWBG BGRW 0 3 , 2 : 3 rotate BGRW BWRG 0 3 , 3 : 3 rotate BWRG RGBW 0 3 , 4 : 1 rotate RGBW WRBG [5, 5, 7, 5]
0 0 , 1 : 2 rotate RBGW RWGB 0 0 , 2 : 2 rotate RWGB GBRW 0 0 , 3 : 2 rotate GBRW RWGB 0 1 , 1 : 3 rotate BGWR BRWG 0 1 , 2 : 3 rotate BRWG WGBR 0 1 , 3 : 3 rotate WGBR BRWG 0 2 , 1 : 3 rotate GWRB GBRW 0 2 , 2 : 3 rotate GBRW RWGB 0 2 , 3 : 3 rotate RWGB GBRW 0 3 , 1 : 3 rotate WRBG WGBR 0 3 , 2 : 3 rotate WGBR BRWG 0 3 , 3 : 3 rotate BRWG WGBR [6, 4, 5, 4]
0 0 , 1 : 2 rotate GBRW GWRB 0 0 , 2 : 2 rotate GWRB GRBW 0 0 , 3 : 2 rotate GRBW GWBR 0 1 , 1 : 3 rotate BRWG BGWR 0 1 , 2 : 1 rotate BGWR RBWG 0 1 , 3 : 3 rotate RBWG RGWB 0 2 , 1 : 3 rotate RWGB RBGW 0 2 , 2 : 2 rotate RBGW WGRB 0 2 , 3 : 2 rotate WGRB WBRG 0 3 , 1 : 3 rotate WGBR WRBG 0 3 , 2 : 3 rotate WRBG BWGR 0 3 , 3 : 1 rotate BWGR BRGW [6, 4, 7, 4]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
A[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(0, r, ",",i+1,":", j+1, "rotate", A)
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
A[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(0, r, ",",i+1,":", j+1, "rotate", A)
if j==2:
cnt+=1
else:
cnt+=j+1
A[i+1] = rotate(A[i+1],j+1)
break
answer.append(cnt)
print(answer)
return min(answer)
0 0 , 1 : 1 rotate ['RGBW', 'GBRW'] 0 1 , 1 : 1 rotate ['GBWR', 'BRWG'] 0 2 , 1 : 2 rotate ['BWRG', 'RWGB'] 0 3 , 1 : 3 rotate ['WRGB', 'GBRW'] [1, 2, 4, 2]
0 0 , 1 : 2 rotate ['WBGR', 'WBGR', 'WRGB', 'WRGB', 'RBGW'] 0 0 , 2 : 2 rotate ['WBGR', 'GRWB', 'WRGB', 'WRGB', 'RBGW'] 0 0 , 4 : 1 rotate ['WBGR', 'GRWB', 'GBWR', 'WRGB', 'RBGW'] 0 1 , 1 : 1 rotate ['BGRW', 'GRWB', 'GBWR', 'WRGB', 'BGWR'] 0 1 , 2 : 3 rotate ['BGRW', 'RWBG', 'GBWR', 'WRGB', 'BGWR'] 0 1 , 3 : 3 rotate ['BGRW', 'RWBG', 'RGBW', 'WRGB', 'BGWR'] 0 1 , 4 : 3 rotate ['BGRW', 'RWBG', 'RGBW', 'BWRG', 'BGWR'] 0 2 , 1 : 1 rotate ['GRWB', 'RWBG', 'RGBW', 'BWRG', 'RBGW'] 0 2 , 2 : 3 rotate ['GRWB', 'WBGR', 'RGBW', 'BWRG', 'RBGW'] 0 2 , 3 : 3 rotate ['GRWB', 'WBGR', 'WRGB', 'BWRG', 'RBGW'] 0 2 , 4 : 2 rotate ['GRWB', 'WBGR', 'WRGB', 'GBWR', 'RBGW'] 0 3 , 1 : 1 rotate ['RWBG', 'WBGR', 'WRGB', 'GBWR', 'GWRB'] 0 3 , 2 : 3 rotate ['RWBG', 'BGRW', 'WRGB', 'GBWR', 'GWRB'] 0 3 , 3 : 3 rotate ['RWBG', 'BGRW', 'BWRG', 'GBWR', 'GWRB'] 0 3 , 4 : 1 rotate ['RWBG', 'BGRW', 'BWRG', 'RGBW', 'GWRB'] [5, 5, 7, 5]
0 0 , 1 : 2 rotate ['RBGW', 'GBRW', 'RWGB', 'GBRW'] 0 0 , 2 : 2 rotate ['RBGW', 'RWGB', 'RWGB', 'GBRW'] 0 0 , 3 : 2 rotate ['RBGW', 'RWGB', 'GBRW', 'GBRW'] 0 1 , 1 : 3 rotate ['BGWR', 'RWGB', 'GBRW', 'RWGB'] 0 1 , 2 : 3 rotate ['BGWR', 'BRWG', 'GBRW', 'RWGB'] 0 1 , 3 : 3 rotate ['BGWR', 'BRWG', 'WGBR', 'RWGB'] 0 2 , 1 : 3 rotate ['GWRB', 'BRWG', 'WGBR', 'BRWG'] 0 2 , 2 : 3 rotate ['GWRB', 'GBRW', 'WGBR', 'BRWG'] 0 2 , 3 : 3 rotate ['GWRB', 'GBRW', 'RWGB', 'BRWG'] 0 3 , 1 : 3 rotate ['WRBG', 'GBRW', 'RWGB', 'GBRW'] 0 3 , 2 : 3 rotate ['WRBG', 'WGBR', 'RWGB', 'GBRW'] 0 3 , 3 : 3 rotate ['WRBG', 'WGBR', 'BRWG', 'GBRW'] [6, 4, 5, 4]
0 0 , 1 : 2 rotate ['GBRW', 'RBGW', 'BWGR', 'BRGW'] 0 0 , 2 : 2 rotate ['GBRW', 'GWRB', 'BWGR', 'BRGW'] 0 0 , 3 : 2 rotate ['GBRW', 'GWRB', 'GRBW', 'BRGW'] 0 1 , 1 : 3 rotate ['BRWG', 'GWRB', 'GRBW', 'GWBR'] 0 1 , 2 : 1 rotate ['BRWG', 'BGWR', 'GRBW', 'GWBR'] 0 1 , 3 : 3 rotate ['BRWG', 'BGWR', 'RBWG', 'GWBR'] 0 2 , 1 : 3 rotate ['RWGB', 'BGWR', 'RBWG', 'RGWB'] 0 2 , 2 : 2 rotate ['RWGB', 'RBGW', 'RBWG', 'RGWB'] 0 2 , 3 : 2 rotate ['RWGB', 'RBGW', 'WGRB', 'RGWB'] 0 3 , 1 : 3 rotate ['WGBR', 'RBGW', 'WGRB', 'WBRG'] 0 3 , 2 : 3 rotate ['WGBR', 'WRBG', 'WGRB', 'WBRG'] 0 3 , 3 : 1 rotate ['WGBR', 'WRBG', 'BWGR', 'WBRG'] [6, 4, 7, 4]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
A[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
print(0, r, ",",i+1,":", j+1, "rotate", A)
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(A):
return
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
A[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(A)-1):
if ispretty(A[i], A[i+1]):
continue
else:
for j in range(3):
if ispretty(A[i], rotate(A[i+1],j+1)):
A[i+1] = rotate(A[i+1],j+1)
print(0, r, ",",i+1,":", j+1, "rotate", A)
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
0 0 , 1 : 1 rotate ['RGBW', 'BRWG'] 0 1 , 1 : 1 rotate ['GBWR', 'RWGB'] 0 2 , 1 : 2 rotate ['BWRG', 'GBRW'] 0 3 , 1 : 3 rotate ['WRGB', 'WGBR'] [1, 2, 4, 2]
0 0 , 1 : 2 rotate ['WBGR', 'GRWB', 'WRGB', 'WRGB', 'RBGW'] 0 0 , 2 : 2 rotate ['WBGR', 'GRWB', 'GBWR', 'WRGB', 'RBGW'] 0 0 , 4 : 1 rotate ['WBGR', 'GRWB', 'GBWR', 'WRGB', 'BGWR'] 0 1 , 1 : 1 rotate ['BGRW', 'RWBG', 'GBWR', 'WRGB', 'BGWR'] 0 1 , 2 : 3 rotate ['BGRW', 'RWBG', 'RGBW', 'WRGB', 'BGWR'] 0 1 , 3 : 3 rotate ['BGRW', 'RWBG', 'RGBW', 'BWRG', 'BGWR'] 0 1 , 4 : 3 rotate ['BGRW', 'RWBG', 'RGBW', 'BWRG', 'RBGW'] 0 2 , 1 : 1 rotate ['GRWB', 'WBGR', 'RGBW', 'BWRG', 'RBGW'] 0 2 , 2 : 3 rotate ['GRWB', 'WBGR', 'WRGB', 'BWRG', 'RBGW'] 0 2 , 3 : 3 rotate ['GRWB', 'WBGR', 'WRGB', 'GBWR', 'RBGW'] 0 2 , 4 : 2 rotate ['GRWB', 'WBGR', 'WRGB', 'GBWR', 'GWRB'] 0 3 , 1 : 1 rotate ['RWBG', 'BGRW', 'WRGB', 'GBWR', 'GWRB'] 0 3 , 2 : 3 rotate ['RWBG', 'BGRW', 'BWRG', 'GBWR', 'GWRB'] 0 3 , 3 : 3 rotate ['RWBG', 'BGRW', 'BWRG', 'RGBW', 'GWRB'] 0 3 , 4 : 1 rotate ['RWBG', 'BGRW', 'BWRG', 'RGBW', 'WRBG'] [5, 5, 7, 5]
0 0 , 1 : 2 rotate ['RBGW', 'RWGB', 'RWGB', 'GBRW'] 0 0 , 2 : 2 rotate ['RBGW', 'RWGB', 'GBRW', 'GBRW'] 0 0 , 3 : 2 rotate ['RBGW', 'RWGB', 'GBRW', 'RWGB'] 0 1 , 1 : 3 rotate ['BGWR', 'BRWG', 'GBRW', 'RWGB'] 0 1 , 2 : 3 rotate ['BGWR', 'BRWG', 'WGBR', 'RWGB'] 0 1 , 3 : 3 rotate ['BGWR', 'BRWG', 'WGBR', 'BRWG'] 0 2 , 1 : 3 rotate ['GWRB', 'GBRW', 'WGBR', 'BRWG'] 0 2 , 2 : 3 rotate ['GWRB', 'GBRW', 'RWGB', 'BRWG'] 0 2 , 3 : 3 rotate ['GWRB', 'GBRW', 'RWGB', 'GBRW'] 0 3 , 1 : 3 rotate ['WRBG', 'WGBR', 'RWGB', 'GBRW'] 0 3 , 2 : 3 rotate ['WRBG', 'WGBR', 'BRWG', 'GBRW'] 0 3 , 3 : 3 rotate ['WRBG', 'WGBR', 'BRWG', 'WGBR'] [6, 4, 5, 4]
0 0 , 1 : 2 rotate ['GBRW', 'GWRB', 'BWGR', 'BRGW'] 0 0 , 2 : 2 rotate ['GBRW', 'GWRB', 'GRBW', 'BRGW'] 0 0 , 3 : 2 rotate ['GBRW', 'GWRB', 'GRBW', 'GWBR'] 0 1 , 1 : 3 rotate ['BRWG', 'BGWR', 'GRBW', 'GWBR'] 0 1 , 2 : 1 rotate ['BRWG', 'BGWR', 'RBWG', 'GWBR'] 0 1 , 3 : 3 rotate ['BRWG', 'BGWR', 'RBWG', 'RGWB'] 0 2 , 1 : 3 rotate ['RWGB', 'RBGW', 'RBWG', 'RGWB'] 0 2 , 2 : 2 rotate ['RWGB', 'RBGW', 'WGRB', 'RGWB'] 0 2 , 3 : 2 rotate ['RWGB', 'RBGW', 'WGRB', 'WBRG'] 0 3 , 1 : 3 rotate ['WGBR', 'WRBG', 'WGRB', 'WBRG'] 0 3 , 2 : 3 rotate ['WGBR', 'WRBG', 'BWGR', 'WBRG'] 0 3 , 3 : 1 rotate ['WGBR', 'WRBG', 'BWGR', 'BRGW'] [6, 4, 7, 4]
# you cBn write to stdout for debugging purposes, e.g.
# print("this is B debug messBge")
def rotBte(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else FBlse
def check(B):
return
def solution(B):
Bnswer=[]
initB = B[0]
for r in rBnge(4):
cnt=0
B[0] = rotBte(initB, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in rBnge(len(B)-1):
if ispretty(B[i], B[i+1]):
continue
else:
for j in rBnge(3):
if ispretty(B[i], rotBte(B[i+1],j+1)):
B[i+1] = rotBte(B[i+1],j+1)
print(0, r, ",",i+1,":", j+1, "rotBte", B)
if j==2:
cnt+=1
else:
cnt+=j+1
breBk
Bnswer.Bppend(cnt)
print(Bnswer)
return min(Bnswer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def check(B):
return
def solution(B):
answer=[]
initA = B[0]
for r in range(4):
cnt=0
B[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(B)-1):
if ispretty(B[i], B[i+1]):
continue
else:
for j in range(3):
if ispretty(B[i], rotate(B[i+1],j+1)):
B[i+1] = rotate(B[i+1],j+1)
print(0, r, ",",i+1,":", j+1, "rotate", B)
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def solution(A):
answer=[]
initA = B[0]
for r in range(4):
cnt=0
B[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(B)-1):
if ispretty(B[i], B[i+1]):
continue
else:
for j in range(3):
if ispretty(B[i], rotate(B[i+1],j+1)):
B[i+1] = rotate(B[i+1],j+1)
print(0, r, ",",i+1,":", j+1, "rotate", B)
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def solution(A):
answer=[]
B=A[:]
initA = B[0]
for r in range(4):
cnt=0
B[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(B)-1):
if ispretty(B[i], B[i+1]):
continue
else:
for j in range(3):
if ispretty(B[i], rotate(B[i+1],j+1)):
B[i+1] = rotate(B[i+1],j+1)
print(0, r, ",",i+1,":", j+1, "rotate", B)
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def solution(A):
answer=[]
B=A[:]
initA = A[0]
for r in range(4):
cnt=0
B[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(B)-1):
if ispretty(B[i], B[i+1]):
continue
else:
for j in range(3):
if ispretty(B[i], rotate(B[i+1],j+1)):
B[i+1] = rotate(B[i+1],j+1)
print(0, r, ",",i+1,":", j+1, "rotate", B)
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
B=A[:]
B[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(B)-1):
if ispretty(B[i], B[i+1]):
continue
else:
for j in range(3):
if ispretty(B[i], rotate(B[i+1],j+1)):
B[i+1] = rotate(B[i+1],j+1)
print(0, r, ",",i+1,":", j+1, "rotate", B)
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
0 0 , 1 : 1 rotate ['RGBW', 'BRWG'] 0 1 , 1 : 2 rotate ['GBWR', 'RWGB'] 0 3 , 1 : 3 rotate ['WRGB', 'WGBR'] [1, 3, 2, 2]
0 0 , 1 : 2 rotate ['WBGR', 'GRWB', 'WRGB', 'WRGB', 'RBGW'] 0 0 , 2 : 2 rotate ['WBGR', 'GRWB', 'GBWR', 'WRGB', 'RBGW'] 0 0 , 4 : 1 rotate ['WBGR', 'GRWB', 'GBWR', 'WRGB', 'BGWR'] 0 1 , 1 : 3 rotate ['BGRW', 'RWBG', 'WRGB', 'WRGB', 'RBGW'] 0 1 , 2 : 1 rotate ['BGRW', 'RWBG', 'RGBW', 'WRGB', 'RBGW'] 0 1 , 3 : 3 rotate ['BGRW', 'RWBG', 'RGBW', 'BWRG', 'RBGW'] 0 2 , 3 : 2 rotate ['GRWB', 'WBGR', 'WRGB', 'GBWR', 'RBGW'] 0 2 , 4 : 2 rotate ['GRWB', 'WBGR', 'WRGB', 'GBWR', 'GWRB'] 0 3 , 1 : 1 rotate ['RWBG', 'BGRW', 'WRGB', 'WRGB', 'RBGW'] 0 3 , 2 : 3 rotate ['RWBG', 'BGRW', 'BWRG', 'WRGB', 'RBGW'] 0 3 , 3 : 1 rotate ['RWBG', 'BGRW', 'BWRG', 'RGBW', 'RBGW'] 0 3 , 4 : 3 rotate ['RWBG', 'BGRW', 'BWRG', 'RGBW', 'WRBG'] [5, 4, 6, 5]
0 0 , 1 : 2 rotate ['RBGW', 'RWGB', 'RWGB', 'GBRW'] 0 0 , 2 : 2 rotate ['RBGW', 'RWGB', 'GBRW', 'GBRW'] 0 0 , 3 : 2 rotate ['RBGW', 'RWGB', 'GBRW', 'RWGB'] 0 1 , 1 : 1 rotate ['BGWR', 'BRWG', 'RWGB', 'GBRW'] 0 1 , 2 : 1 rotate ['BGWR', 'BRWG', 'WGBR', 'GBRW'] 0 1 , 3 : 1 rotate ['BGWR', 'BRWG', 'WGBR', 'BRWG'] 0 3 , 1 : 3 rotate ['WRBG', 'WGBR', 'RWGB', 'GBRW'] 0 3 , 2 : 3 rotate ['WRBG', 'WGBR', 'BRWG', 'GBRW'] 0 3 , 3 : 3 rotate ['WRBG', 'WGBR', 'BRWG', 'WGBR'] [6, 4, 2, 4]
0 0 , 1 : 2 rotate ['GBRW', 'GWRB', 'BWGR', 'BRGW'] 0 0 , 2 : 2 rotate ['GBRW', 'GWRB', 'GRBW', 'BRGW'] 0 0 , 3 : 2 rotate ['GBRW', 'GWRB', 'GRBW', 'GWBR'] 0 1 , 1 : 1 rotate ['BRWG', 'BGWR', 'BWGR', 'BRGW'] 0 1 , 2 : 3 rotate ['BRWG', 'BGWR', 'RBWG', 'BRGW'] 0 1 , 3 : 1 rotate ['BRWG', 'BGWR', 'RBWG', 'RGWB'] 0 2 , 2 : 1 rotate ['RWGB', 'RBGW', 'WGRB', 'BRGW'] 0 2 , 3 : 3 rotate ['RWGB', 'RBGW', 'WGRB', 'WBRG'] 0 3 , 1 : 3 rotate ['WGBR', 'WRBG', 'BWGR', 'BRGW'] [6, 4, 4, 2]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
B=A[:]
B[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(B)-1):
if ispretty(B[i], B[i+1]):
continue
else:
for j in range(3):
if ispretty(B[i], rotate(B[i+1],j+1)):
B[i+1] = rotate(B[i+1],j+1)
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
print(answer)
return min(answer)
[1, 3, 2, 2]
[5, 4, 6, 5]
[6, 4, 2, 4]
[6, 4, 4, 2]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
B=A[:]
B[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(B)-1):
if ispretty(B[i], B[i+1]):
continue
else:
for j in range(3):
if ispretty(B[i], rotate(B[i+1],j+1)):
B[i+1] = rotate(B[i+1],j+1)
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
B=A[:]
B[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(B)-1):
if ispretty(B[i], B[i+1]):
continue
else:
for j in range(3):
if ispretty(B[i], rotate(B[i+1],j+1)):
B[i+1] = rotate(B[i+1],j+1)
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
return min(answer)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def rotate(s, num):
return s[num:]+s[:num]
def ispretty(s1, s2):
return True if s1[1] == s2[3] else False
def solution(A):
answer=[]
initA = A[0]
for r in range(4):
cnt=0
B=A[:]
B[0] = rotate(initA, r)
if r==3:
cnt+=1
else:
cnt+=r
for i in range(len(B)-1):
if ispretty(B[i], B[i+1]):
continue
else:
for j in range(3):
if ispretty(B[i], rotate(B[i+1],j+1)):
B[i+1] = rotate(B[i+1],j+1)
if j==2:
cnt+=1
else:
cnt+=j+1
break
answer.append(cnt)
return min(answer)
The solution obtained perfect score.