fork download
  1. f=lambda m,y=-1,x=0:f(m,m[0].find("S"))if y<0else y<len(m[0])-1and x<len(m)and m[x][y]!="="and(m[x][y]=="E"or m[x][y+1]=="="and any(f(m,y-i,x+1)for i in range(5)[:(m[x][y::-1]+"=").find("=")])or f(m,y+1,x))#test cases
  2. ##True
  3. s1=[' S=', ' E=']
  4. s2=[' S============', ' =', ' #= =', ' =', ' =', ' =', ' E=']
  5. s3=[' S=', ' E=====']
  6. s4=[' S= ', ' ======', ' =', ' =', ' =', ' E====']
  7. s5=[' S= ==', ' =', ' =', ' E=']
  8. ##False
  9. s6=[' S= ', ' ==', ' ', ' ==']
  10. s7=[' S=', ' =', ' ======', ' =', ' E=']
  11. s8=[' S= =', ' = = =', ' = = =', ' =E=']
  12. s9=[' = = =S=', ' = = = =', ' # =', ' = = = ==', ' E= = = ==']
  13.  
  14. #run the tests
  15. for i in range(1,10):
  16. print(i,eval("f(s{})".format(i)))
  17.  
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
(1, True)
(2, True)
(3, True)
(4, True)
(5, True)
(6, False)
(7, False)
(8, False)
(9, False)