12/04/25 17:35:29.26
>>525
Squeak Smalltalk (4.2-ja w/CogVM), 1.8GHz Core i7で5分弱。
life := [:ary2d |
| sum survivs |
sum := ary2d * 0.
#(-1 0 1) do: [:dx | #(-1 0 1) do: [:dy |
sum := sum + ((ary2d collect: [:row | row flipRotated: dx*2]) flipRotated: dy*2)]].
survivs := #(3 4) collect: [:alive |
sum collect: [:row | row collect: [:cell | (cell = alive) asBit]]].
survivs first + (survivs second * ary2d)].
life value: #(
(0 1 1 1 0)
(0 1 0 0 0)
(0 0 1 0 0)
(0 0 0 0 0)
(0 0 0 0 0)).
"=> #(
(0 1 1 0 0)
(0 1 0 1 0)
(0 0 0 0 0)
(0 0 0 0 0)
(0 0 1 0 0)) "
cells := (1 to: 500) collect: [:row | (1 to: 500) collect: [:cell | #(0 1) atRandom]].
[500 timesRepeat: [cells := life value: cells]] timeToRun "=> 267282(msec) "