def isPrime(a):
if a < 2:return False
for i in range(2,a):
if a % i == 0:return False
return True
def check(a):
s = []
for i in range(8):
if a % 3 == 0:
s.append('A')
elif a % 3 == 1:
s.append('B')
else:
s.append('C')
a //= 3
s.append('C')
s.append('C')
# print(s)
if s[7] == 'A':return False
mlen = 1
cnt = 1
for i in range(1,10):
if s[i] == s[i - 1]:
cnt += 1
mlen = max(mlen,cnt)
else:
cnt = 1
# 8
if s[7] == 'A':return False
# 7
if chr(cnt + 65 - 2) != s[6]:return False
# 6
cnt = 0
for i in range(10):
if i == 5:continue
if s[i] == s[5]:cnt+=1
if chr(cnt + 65 - 1) != s[5]:return False
# 5
if s[4] == 'A' and s[1] != s[2] : return False
if s[4] == 'B' and s[3] != s[4] : return False
if s[4] == 'C' and s[5] != s[6] : return False
if s[4] == 'A' and (s[3] == s[4] or s[5] == s[6]):return False
if s[4] == 'B' and (s[1] == s[2] or s[5] == s[6]):return False
if s[4] == 'C' and (s[1] == s[2] or s[3] == s[4]):return False
# 4
t = abs(ord(s[3]) - ord(s[2]))
if t == 2 and s[3] != 'A':return False
if t == 1 and s[3] != 'B':return False
if t == 0 and s[3] != 'C':return False
# 3
a,c = 0,0
for it in s:
if it == 'A':a += 1
if it == 'C':c += 1
t = abs(a - c)
if t == 3 and s[2] != 'A':return False
if t == 2 and s[2] != 'B':return False
if t == 1 and s[2] != 'C':return False
if t < 1 or t > 3:return False
# 2
b = 0
for it in s:
if it == 'B': b += 1
if chr(b + 65 - 2) != s[1]:return False
cnt = 0
if isPrime(a): cnt += 1
if isPrime(b): cnt += 1
if isPrime(c): cnt += 1
if s[0] != chr(cnt + 65 - 1): return False
print(''.join(s))
return s.copy()
for i in range(10000):
if check(i):
pass
第九第十都选C(别问为什么)。
将所有可能的答案一一做检验,将符合题目要求的唯一答案输出即可。
题目链接
原创不易,感谢支持。