         }
         return nil
     }
+    
+    private func locationOf(point: Point<Int>) -> Int {
+        return  point.x + columns * point.y
+    }
+    
+    private func locationOf(x: Int, y: Int) -> Int {
+        return x + columns * y
+    }
+    
+    private func pointAt(index: Int) -> Point<Int> {
+        return Point(index % columns, index / columns)
+    }
+    
 }

    }
    
    var topRight: Point<Int> {
        return Point(x: columns - 1, y: 0)
    }
    
    var bottomLeft: Point<Int> {
        return Point(x: 0, y: rows - 1)
    }
    
    var bottomRight: Point<Int> {
        return Point(x: columns - 1, y: rows - 1)
    }
    
    func valueAt(point: Point<Int>) -> Int? {

    return Point(lhs.x * rhs.x, lhs.y * rhs.y)
}

/// Provides a generator over a Matrix so that we can do stuff
/// like transform elements on the fly
struct MatrixGenerator: GeneratorType, SequenceType {

    typealias Generator = MatrixGenerator
    typealias Element = Point<Int>

    let columns: Int
    let rows: Int
    private var counter: Int = 0
    
    init(_ columns: Int, _ rows: Int) {
        self.columns = columns
        self.rows = rows
    }
    
    func generate() -> Generator {
        return self
    }
    
    mutating func next() -> Element? {
        if counter == columns * rows {
            return nil
        }
        
        defer {
            counter += 1
        }
        
        return Point(counter % columns, counter / rows)
    }
}

struct Matrix {
    
    static let origin: Point<Int> = Point(0, 0)
    
    let columns: Int
    let rows: Int
