Created
July 28, 2016 02:30
-
-
Save rayfix/bfe8ca5654302d66f31c3a8609e2a9ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct PokeCorrall { | |
| let rows: Int, columns: Int | |
| var grid: [Double] | |
| init(rows: Int, columns: Int) { | |
| self.rows = rows | |
| self.columns = columns | |
| grid = Array(count: rows * columns, repeatedValue: 0.0) | |
| } | |
| func indexIsValidForRow(row: Int, column: Int) -> Bool { | |
| return row >= 0 && row < rows && column >= 0 && column < columns | |
| } | |
| subscript(row: Int, column: Int) -> Double { | |
| get { | |
| assert(indexIsValidForRow(row, column: column), "Index out of range") | |
| return grid[(row * columns) + column] | |
| } | |
| set { | |
| assert(indexIsValidForRow(row, column: column), "Index out of range") | |
| grid[(row * columns) + column] = newValue | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment