EDIT: fixed, apparently configuration is valid only if it has strictly 8 queens...
I'm trying to solve this https://open.kattis.com/problems/8queens
my code passed the 2 public test cases but failed the hidden test cases (no additional info given on what it failed)
Looked through it several times, cant figure out what the bug is :S
link: http://pastebin.com/WCv4WZyc
Code:
import sys
d = []
for l in sys.stdin: #
d.append(list(l[i] for i in range(len(l)-1)))
res = False
for j in range(8):
if d[j].count('*') > 1: #check row
res = True
break
r = False
for x in d:
if x[j]=='*': #check column
if r: #if count > 1, break
res = True
break
r = True #if first count, set flag true
r,r2,r3,r4=False, False, False, False
for i in range(8-j):
if d[i][i+j]=='*': #check diagonal towards right
if r:
res = True
break
r = True
if d[i+j][i]=='*': #check diagonal towards btm
if r2:
res = True
break
r2 = True
if d[7-i-j][i]=='*':
if r3:
res = True
break
r3 = True
if d[7-i][i+j]=='*':
if r4:
res = True
break
r4 = True
if res:
break
if res:
print('invalid')
else:
print('valid')