Skip to content

Instantly share code, notes, and snippets.

@Capital-EX
Created May 2, 2020 14:08
Show Gist options
  • Save Capital-EX/f1cf1d1ac9ab8da6d6b4a26cd8d6f1dd to your computer and use it in GitHub Desktop.
Save Capital-EX/f1cf1d1ac9ab8da6d6b4a26cd8d6f1dd to your computer and use it in GitHub Desktop.
{
(set: $grid to
(a: (a: 0, 0, 0, 1, 0),
(a: 0, 1, 0, 1, 0),
(a: 0, 0, 1, 1, 0),
(a: 0, 0, 0, 0, 0),
(a: 0, 0, 0, 0, 0)))
(set: $len to $grid's length)
(for: each _row, ...$grid)[
(for: each _col, ..._row)[{
(if: _col is 1)[#]
(else:)[_]
}]<br>
]<grid|
(live: 0.2s)[
(set: $neighbors to (a:))
(for: each _ri, ...(range: 1, $len))[
(set: $row to (a:))
(for: each _ci, ...(range: 1, $len))[
(set: $n to 0)
(if: _ri - 1 > 0)[
(if: _ci - 1 > 0)
[(set: $n to it + $grid's (_ri - 1)'s (_ci - 1))]
(else:)
[(set: $n to it + $grid's (_ri - 1)'s ($len))]
(set: $n to it + $grid's (_ri - 1)'s (_ci))
(if: _ci + 1 <= $grid's length)
[(set: $n to it + $grid's (_ri - 1)'s (_ci + 1))]
(else:)
[(set: $n to it + $grid's (_ri - 1)'s (1))]
]
(else:)[
(if: _ci - 1 > 0)
[(set: $n to it + $grid's ($len)'s (_ci - 1))]
(else:)
[(set: $n to it + $grid's ($len)'s ($len))]
(set: $n to it + $grid's ($len)'s (_ci))
(if: _ci + 1 <= $grid's length)
[(set: $n to it + $grid's ($len)'s (_ci + 1))]
(else:)
[(set: $n to it + $grid's ($len)'s (1))]
]
(if: _ci - 1 > 0)
[(set: $n to it + $grid's (_ri)'s (_ci - 1))]
(else:)
[(set: $n to it + $grid's (_ri)'s ($len))]
(if: _ci + 1 <= $grid's length)
[(set: $n to it + $grid's (_ri)'s (_ci + 1))]
(else:)
[(set: $n to it + $grid's (_ri)'s (1))]
(if: _ri + 1 <= $grid's length)[
(if: _ci - 1 > 0)
[(set: $n to it + $grid's (_ri + 1)'s (_ci - 1))]
(else:)
[(set: $n to it + $grid's (_ri + 1)'s ($len))]
(set: $n to it + $grid's (_ri + 1)'s (_ci))
(if: _ci + 1 <= $grid's length)
[(set: $n to it + $grid's (_ri + 1)'s (_ci + 1))]
(else:)
[(set: $n to it + $grid's (_ri + 1)'s (1))]
]
(else:)[
(if: _ci - 1 > 0)
[(set: $n to it + $grid's (1)'s (_ci - 1))]
(else:)
[(set: $n to it + $grid's (1)'s ($len))]
(set: $n to it + $grid's (1)'s (_ci))
(if: _ci + 1 <= $grid's length)
[(set: $n to it + $grid's (1)'s (_ci + 1))]
(else:)
[(set: $n to it + $grid's (1)'s (1))]
]
(set: $row to it + (a: $n))
]
(set: $neighbors to it + (a: $row))
]
(set: $new_grid to (a:))
(for: each _ri, ...(range: 1, $len))[
(set: $row to (a:))
(for: each _ci, ...(range: 1, $len))[
(set: _g to $grid's (_ri)'s (_ci))
(set: _n to $neighbors's (_ri)'s (_ci))
(if: _g is 1 and (_n is 2 or _n is 3))
[(set: $row to it + (a: 1))]
(else-if: $_g is 0 and _n is 3)
[(set: $row to it + (a: 1))]
(else:)
[(set: $row to it + (a: 0))]
]
(set: $new_grid to it + (a: $row))
]
(set: $grid to $new_grid)
(replace: ?grid)[(for: each _row, ...$grid)[
(for: each _col, ..._row)[{
(if: _col is 1)[#]
(else:)[_]
}]<br>
]<grid|]
]
(enchant: ?grid, (font: "Monospace"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment