The last stage of contamination
Since this is basically talking about a cellular automaton I give you..
Golly Quicklife rule, 10 bytes
01234/234V
Input the rule, paste the grid into Golly, run pattern. The resulting pattern is the output.
Explanation:
01234 Survive on any number of neighbors
/234 Born on >2 neighbors
V Only directly adjacent neighbors count
Or if you insist on a full RuleLoader rule, 89 bytes:
@RULE X
@TABLE
n_states:2
neighborhood:vonNeumann
symmetries:permute
011001
011101
011111
Rulename is X, same steps as before.
Python 2, 97 bytes
s=' '*6+input()
exec"s=s[1:]+('1'+s)[sum(s[i]<'1'for i in[-6,-1,1,6])>2or'/'>s];"*980
print s[6:]
Try it online. Input is taken as a quoted string with each row delimited by newlines. The 980
is not optimal and can be replaced with a lower multiple of 35. Since it has no impact on the length of this program, I have left the determination of the lowest safe upper bound as an exercise for the reader.
Javascript (ES6), 91 89 87 bytes
As a function which accepts input as an array of numbers or strings.
-2 bytes from Neil (combining assignment of y
with string conversion)
-2 bytes (removing variable j
)
f=x=>(y=x.map((z,i)=>~(i%5&&x[i-1])+~(i%5<4&x[i+1])+~x[i-5]+~x[i+5]<-5|z))+[]==x?y:f(y)
<!-- Snippet demo with array <-> string conversion for convenience -->
<textarea id="input" cols="10" rows="5">0 0 0 0 1
0 0 0 0 1
0 0 0 1 1
0 0 1 1 1
0 1 1 1 1</textarea>
<button id="submit">Run</button>
<pre id="output"></pre>
<script>
strToArray=x=>x.match(/\d/g)
arrayToStr=x=>([]+x).replace(/(.),(.),(.),(.),(.),*/g, '$1 $2 $3 $4 $5\n')
submit.onclick=_=>output.innerHTML=arrayToStr(f(strToArray(input.value)))
</script>