Skip to content

Instantly share code, notes, and snippets.

@aharisu
aharisu / gist:629501
Created October 16, 2010 06:12
Life game in Scala ver Iterator
import _root_.scala.util.Random
def lifeGameIterator(stride:Int) = new Iterator[Array[Array[Boolean]]] {
private def pathFilter(num : Int) = num
private def prevFilter(num : Int) = if(num == 0) stride - 1 else num - 1
private def nextFilter(num : Int) = if(num == stride - 1) 0 else num + 1
private def cellArriveGetter(xFilter:(Int)=>Int, yFilter: (Int)=>Int)
(cells:Array[Array[Boolean]], x:Int, y:Int) = cells(yFilter(y))(xFilter(x))
private val _isArriveGetter = List(
(define panel #(5 3 0 0 7 0 0 0 0
6 0 0 1 9 5 0 0 0
0 9 8 0 0 0 0 6 0
8 0 0 0 6 0 0 0 3
4 0 0 8 0 3 0 0 1
7 0 0 0 2 0 0 0 6
0 6 0 0 0 0 2 8 0
0 0 0 4 1 9 0 0 5