here is my code for problem broken watch using python
N = int(raw_input())
for Z in range(1,N+1):
A =
[[1,1,1,1,1,1,0],[0,1,1,0,0,0,0],[1,1,0,1,1,0,1],[1,1,1,1,0,0,1],[0,1,1,0,0,1,1],[1,0,1,1,0,1,1],[1,0,1,1,1,1,1],[1,1,1,0,0,0,0],[1,1,1,1,1,1,1],[1,1,1,1,0,1,1]]
b = raw_input()
B = []
for i in range(int(b[0])):
B.append([])
w = 0
for i in b[2:]:
if i == " ":
w +=1
else:
B[w].append(int(i))
Must = [0,0,0,0,0,0,0]
for i in B:
for r in range(7):
if i[r] == 1:
Must[r] = 1
else:
pass
def MustMatch(l1,l2):
result = True
for i in range(7):
if Must[i] == l2[i] ==1 and l2.count(1) >= l1.count(1):
if l1[i] == 1:
pass
else:
result = False
if l1[i] == 1:
if l2[i] == 1:
continue
else:
result = False
return result
def Matches(l1,l2):
result = 0
for i in range(len(l1)):
if l1[i] == 1 == l2[i]:
result +=1
return result
def GSI(l):
li = l[:]
result = []
for i in range(len(li)):
m = li.index(min(li))
result.append(m)
li[m] = ""
return result[::-1]
ANS = "ERROR!"
S = []
w = 0
while w < len(B):
if w == 0:
s = []
scores = []
for i in range(10):
if MustMatch(B[w],A[i]) == True:
scores.append(Matches(B[w],A[i]))
else:
scores.append(0)
s = GSI(scores)
for i in s:
if scores[i] > 0:
S.append(i)
else:
s = []
scores = []
for i in S:
if MustMatch(B[w],A[i-w]) == True:
scores.append(Matches(B[w],A[i-w]))
else:
scores.append(0)
for i in range(len(S)):
if scores[i] > 0:
s.append(S[i])
S = s
w+=1
if len(S) == 1:
ANS = ""
for i in range(7):
if Must[i] == 1:
ANS = ANS+str(A[S[0]-w][i])
else:
ANS = ANS+str(0)
print "Case #%i: %s" % (Z,ANS)
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/c0188ece-7fdf-45e2-8780-6083b3b35b06%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.