fork(1) download
  1. r=range
  2. t=r(9)
  3. a=r(81)
  4. def s(x):
  5. if x<0:return 1
  6. while(x
  7. and
  8. n[x]):x-=1
  9. for l in t:
  10. n[x]=l+1
  11. if 0==any(i/9==j/9
  12. or
  13. i%9==j%9
  14. or
  15. i/27==j/27
  16. and
  17. i%9/3==j%9/3
  18. for
  19. i
  20. in
  21. a
  22. for
  23. j
  24. in
  25. r(i)if
  26. n[i]and
  27. n[i]==n[j])and s(x-1):return 1
  28. n[x]=0
  29. n=[int(x)for i in range(9) for x in raw_input() if x > ' ']
  30. s(80)
  31. for i in a:print n[i],chr(32-i%9/8*22),
  32.  
Success #stdin #stdout 0.66s 10928KB
stdin
0 0 0 0 0 6 0 0 0
0 5 9 0 0 0 0 0 8
2 0 0 0 0 8 0 0 0
0 4 5 0 0 0 0 0 0
0 0 3 0 0 0 0 0 0
0 0 6 0 0 3 0 5 4
0 0 0 3 2 5 0 0 6
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
stdout
3   8   7   2   5   6   4   1   9 
1   5   9   4   3   7   2   6   8 
2   6   4   1   9   8   5   3   7 
7   4   5   6   1   2   8   9   3 
8   1   3   5   4   9   6   7   2 
9   2   6   8   7   3   1   5   4 
4   7   1   3   2   5   9   8   6 
6   3   2   9   8   1   7   4   5 
5   9   8   7   6   4   3   2   1