Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.