Skip to content

Instantly share code, notes, and snippets.

@G33kDude
Created September 21, 2014 18:11
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 G33kDude/0ae329940ad5d0dac1bd to your computer and use it in GitHub Desktop.
Save G33kDude/0ae329940ad5d0dac1bd to your computer and use it in GitHub Desktop.
Ascii =
(
; Necessary newline
+----+
| |
+-------------------------+-----+----+
| | | |
| +-------------------+-----+ |
| | | | |
| | | | |
+-----+-------------------+-----+ |
| | | |
| | | |
+-------------------+-----+ |
| | |
| | |
| | |
+-----+----+
| |
| |
| |
+----+
)
; Convert text into a grid array
Grid := []
for y, Row in StrSplit(Ascii, "`n", "`r")
for x, Char in StrSplit(Row)
Grid[x, y] := Char
; Find corners
Corners := []
Horiz := []
Vert := []
for x, Col in Grid
{
for y, Char in Col
{
if (Grid[x, y] == "+") ; Top left
{
Corners.Insert([x, y])
While NextChar := Grid[NextX := x + A_Index, y]
if (NextChar == "+") ; Top right corner
Horiz[x,y] := [NextX, Horiz[x,y]*]
While NextChar := Grid[x, NextY := y + A_Index]
if (NextChar == "+") ; Bottom left corner
Vert[x,y] := [NextY, Vert[x,y]*]
}
}
}
Squares := 0
for Index, Corner in Corners
for Index, Right in Horiz[Corner*]
for Index, Bottom in Vert[Corner*]
if (Grid[Right, Bottom] == "+")
Squares++
MsgBox, %Squares%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment