Skip to main content
1 of 3
Doorknob
  • 71.7k
  • 20
  • 143
  • 385

Ruby, 197

a=$<.read.split('
').map &:split
f=->x,y{a[x][y]=?1
[[-1,0],[1,0],[0,-1],[0,1]].map{|o|f[d=x+o[0],e=y+o[1]]if a[d]&&a[d][e]==?0}}
i=a.index{|x|x.index ?0}
f[i,a[i].index(?0)]
p a.flatten.uniq==[?1]

Does a flood-fill, then checks to see if all the elements are 1.

Doorknob
  • 71.7k
  • 20
  • 143
  • 385