All pastes #931392 Raw Edit

Mine

public java v1 · immutable
·published 2008-03-07 03:44 UTC
rendered paste body
class Grid{  public final int size;  Cell[] cells;  Cell[][] rows;  Cell[][] cols;  Cell[][] squares;  // Constructs a 9x9 grid  public Grid(){    this(9);  }  // Constructs a size x size grid  public Grid(int size){    this.size = size;    cells = new Cell[size * size];        // Allocate subsets    rows = new Cell[size][size];    cols = new Cell[size][size];    squares = new Cell[size][size];    // Initialize the cells    for(int i=0; i<cells.length; i++){      cells[i] = new Cell(size);    }    // Build the row subsets    for(int i=0; i<size; i++)      System.arrayCopy(cells, size*i, rows[i], 0, size);    // Build the column subsets    for(int i=0; i<size; i++){      for(int j=0; j<size; j++)        col[i][j] = cells[i + size*j];    }    // Build the square subsets    int len = (int)Math.sqrt(size);    for(int i=0; i<cells.length; i+=size){      System.arrayCopy(cells, i, squares[i], 0, len);      System.arrayCopy(cells, i+size, squares[i], len, len);      System.arrayCopy(cells, i+2*size, squares[i], 2*len, len);    }  }  // Rest of class snipped}