Skip to content

Instantly share code, notes, and snippets.

@jhannes
Created January 26, 2012 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhannes/1684503 to your computer and use it in GitHub Desktop.
Save jhannes/1684503 to your computer and use it in GitHub Desktop.
CoffeeScript from irb.no 26th january
class exports.Minefield
constructor: (@cells)->
hints: ->
((@hint(row,col) for col in @cols()).join("") for row in @rows())
rows: -> [0...@cells.length]
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