Skip to main content
deleted 4 characters in body
Source Link
Doorknob
  • 71.7k
  • 20
  • 143
  • 385

Ruby, 202 198198 193

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

Does a flood-fill, then checks to see if all the elementsthere are 1any 0s left.

Ruby, 202 198

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

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

Ruby, 202 198 193

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

Does a flood-fill, then checks to see if there are any 0s left.

added 10 characters in body
Source Link
Doorknob
  • 71.7k
  • 20
  • 143
  • 385

Ruby, 197202 198

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]|o|d,e=y+o[1]]ife=x+o[0],y+o[1]
f[d,e]if a[d]&&a[d][e]==?0}}
i=af[i=a.index{|x|x.index ?0}
f[i,a[i].index(?0)]
p !(a.flattenjoin.uniq==[index ?1]0)

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

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.

Ruby, 202 198

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

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

Source Link
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.