Dominosa Small by rolf

R=range;d=[]
for i in R(5):d+=[map(int,raw_input())]
s=set()
t=[]
def Q():
 f=0 
 for j in R(5):
  for i in R(6):
   if d[j][i]!="*":
    f=1;break
  if f:break
 if f: 
  a=d[j][i];p=i+j*6
  for o in 0,1:
   if i<5+o and j<5-o:
    b=d[j+o][i+1-o]
    if b!="*":
     q=i+1+j*6+o*5;e=tuple(sorted([a,b]))
     if e not in s:s.add(e);d[j][i]="*";d[j+o][i+1-o]="*";t.append((p,q));Q();t.pop();d[j+o][i+1-o]=b;d[j][i]=a;s.remove(e)
 else:
  for z in t:print"%d,%d"%z,
Q()

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page