fork download
  1. # http://c...content-available-to-author-only...e.com/a/85196/34718
  2.  
  3. def f(s):
  4.  
  5. # check dimensions
  6. s=s.split("\n")
  7. h=len(s)
  8. w=len(s[0])
  9. if h*w < 60 or h*w > 749 or w<5 or h<4: return False,"Size"
  10.  
  11. # top / bottom
  12. e=0
  13. for c in s[0][1:-1]+s[-1][1:-1]:
  14. if(c in"#-")<1:return False,"T/B"
  15.  
  16. # entrance
  17. if"-"==c:e=1
  18.  
  19. # no spaces in corners -_-
  20. if" "in s[0][0]+s[0][-1]+s[-1][0]+s[-1][-1]: return False,"Corner"
  21.  
  22. # light, table, chair
  23. l=t=c=0
  24.  
  25. # left / right
  26. for r in s[1:-1]:
  27. if(r[0]in"#|")*(r[-1]in"#|")<1: return False,"L/R"
  28.  
  29. # walls, put above
  30. if" "*5in r: return False,"Walls"
  31.  
  32. # light
  33. if"$"in r:l=1
  34.  
  35. # table, chair
  36. if"T"in s[-2]:t=1
  37. if"C"in s[-2]:c=1
  38.  
  39. if l*t*c<1: return False,"L/T/C"
  40.  
  41. # wall columns
  42. for r in zip(*s): # Transpose
  43. if" "*5in`r`[2::5]: # Tuple to string
  44. return False,"Walls"
  45.  
  46. # entrance
  47. if"|"in"".join(s[1:-1])<1>e: return False,"Entrance"
  48.  
  49. # place to stand
  50. if("#"in s[-1][2:-2])<1: return False,"Stand"
  51.  
  52. return True
  53.  
  54. s = """
  55. -####-#####|
  56. #* *** *#
  57. #* $ *#
  58. #**** *** *#
  59. #**T***C* *|
  60. ##-------###"""
  61.  
  62. print f(s[1:])
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
True