Created
January 26, 2012 19:20
-
-
Save jhannes/1684503 to your computer and use it in GitHub Desktop.
CoffeeScript from irb.no 26th january
This file contains 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
class exports.Minefield | |
constructor: (@cells)-> | |
hints: -> | |
((@hint(row,col) for col in @cols()).join("") for row in @rows()) | |
rows: -> [[email protected]] | |
cols: -> [0...@cells[0].length] | |
hint: (row,col) -> | |
return "*" if @hasMine(row,col) | |
count = 0 | |
for r in [row-1..row+1] | |
for c in [col-1..col+1] | |
count++ if @hasMine(r,c) | |
count | |
hasMine: (row,col) -> | |
return false unless 0 <= row < @cells.length | |
return false unless 0 <= col < @cells[0].length | |
@cells[row][col] == '*' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment