Post History
Sandbox
Knight safe squares [FINALIZED]
#10: Post edited
Knight safe squares
- Knight safe squares [FINALIZED]
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- - You may take input in the format of your choice provided it does not provide additional information that would help solve the challenge
- ## Output
- - A number from 0 to 64, indicating the number of squares that satisfy both of:
- - The square does not contain a knight
- - The square is not a knight's move away from a knight.
- A knight's move is either of:
- - 2 squares horizontally (left or right) and 1 square vertically (up or down)
- - 1 square horizontally (left or right) and 2 squares vertically (up or down)
- [![Knight's moves shown as dots](https://codegolf.codidact.com/uploads/Q4kXyQDf3HZiX5NWncgRS2Fi)](https://en.wikipedia.org/wiki/Knight_(chess)#Movement "View on Wikipedia")
- (thanks to [Wikipedia](https://en.wikipedia.org/wiki/Knight_(chess)#Movement "Wikipedia section on Knight's moves"))
- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
- Test case inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.
- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "******N*",
- "N*******",
- ],
- 47
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
- # Now posted: [Knight safe squares](https://codegolf.codidact.com/posts/287131)
- ---
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- - You may take input in the format of your choice provided it does not provide additional information that would help solve the challenge
- ## Output
- - A number from 0 to 64, indicating the number of squares that satisfy both of:
- - The square does not contain a knight
- - The square is not a knight's move away from a knight.
- A knight's move is either of:
- - 2 squares horizontally (left or right) and 1 square vertically (up or down)
- - 1 square horizontally (left or right) and 2 squares vertically (up or down)
- [![Knight's moves shown as dots](https://codegolf.codidact.com/uploads/Q4kXyQDf3HZiX5NWncgRS2Fi)](https://en.wikipedia.org/wiki/Knight_(chess)#Movement "View on Wikipedia")
- (thanks to [Wikipedia](https://en.wikipedia.org/wiki/Knight_(chess)#Movement "Wikipedia section on Knight's moves"))
- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
- Test case inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.
- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "******N*",
- "N*******",
- ],
- 47
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
#9: Post edited
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- - You may take input in the format of your choice provided it does not provide additional information that would help solve the challenge
- ## Output
- - A number from 0 to 64, indicating the number of squares that satisfy both of:
- - The square does not contain a knight
- - The square is not a knight's move away from a knight.
- A knight's move is either of:
- - 2 squares horizontally (left or right) and 1 square vertically (up or down)
- - 1 square horizontally (left or right) and 2 squares vertically (up or down)
- [![Knight's moves shown as dots](https://codegolf.codidact.com/uploads/Q4kXyQDf3HZiX5NWncgRS2Fi)](https://en.wikipedia.org/wiki/Knight_(chess)#Movement "View on Wikipedia")
- (thanks to [Wikipedia](https://en.wikipedia.org/wiki/Knight_(chess)#Movement "Wikipedia section on Knight's moves"))
- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
- Test case inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.
- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "******N*",
- "N*******",
- ],
- 47
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
- ----
# Sandbox questions- Is there a more useful test case format?- Are there any edge cases that should have test cases?[]()
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- - You may take input in the format of your choice provided it does not provide additional information that would help solve the challenge
- ## Output
- - A number from 0 to 64, indicating the number of squares that satisfy both of:
- - The square does not contain a knight
- - The square is not a knight's move away from a knight.
- A knight's move is either of:
- - 2 squares horizontally (left or right) and 1 square vertically (up or down)
- - 1 square horizontally (left or right) and 2 squares vertically (up or down)
- [![Knight's moves shown as dots](https://codegolf.codidact.com/uploads/Q4kXyQDf3HZiX5NWncgRS2Fi)](https://en.wikipedia.org/wiki/Knight_(chess)#Movement "View on Wikipedia")
- (thanks to [Wikipedia](https://en.wikipedia.org/wiki/Knight_(chess)#Movement "Wikipedia section on Knight's moves"))
- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
- Test case inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.
- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "******N*",
- "N*******",
- ],
- 47
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
- ----
#8: Post edited
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- You may take input in the format of your choice provided your choice of input format does not provide additional information that would help solve the challenge- ## Output
- - A number from 0 to 64, indicating the number of squares that satisfy both of:
- - The square does not contain a knight
- - The square is not a knight's move away from a knight.
- A knight's move is either of:
- - 2 squares horizontally (left or right) and 1 square vertically (up or down)
- - 1 square horizontally (left or right) and 2 squares vertically (up or down)
- [![Knight's moves shown as dots](https://codegolf.codidact.com/uploads/Q4kXyQDf3HZiX5NWncgRS2Fi)](https://en.wikipedia.org/wiki/Knight_(chess)#Movement "View on Wikipedia")
- (thanks to [Wikipedia](https://en.wikipedia.org/wiki/Knight_(chess)#Movement "Wikipedia section on Knight's moves"))
- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
- Test case inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.
- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "******N*",
- "N*******",
- ],
- 47
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
- ---
- # Sandbox questions
- - Is there a more useful test case format?
- - Are there any edge cases that should have test cases?
- []()
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- - You may take input in the format of your choice provided it does not provide additional information that would help solve the challenge
- ## Output
- - A number from 0 to 64, indicating the number of squares that satisfy both of:
- - The square does not contain a knight
- - The square is not a knight's move away from a knight.
- A knight's move is either of:
- - 2 squares horizontally (left or right) and 1 square vertically (up or down)
- - 1 square horizontally (left or right) and 2 squares vertically (up or down)
- [![Knight's moves shown as dots](https://codegolf.codidact.com/uploads/Q4kXyQDf3HZiX5NWncgRS2Fi)](https://en.wikipedia.org/wiki/Knight_(chess)#Movement "View on Wikipedia")
- (thanks to [Wikipedia](https://en.wikipedia.org/wiki/Knight_(chess)#Movement "Wikipedia section on Knight's moves"))
- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
- Test case inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.
- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "******N*",
- "N*******",
- ],
- 47
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
- ---
- # Sandbox questions
- - Is there a more useful test case format?
- - Are there any edge cases that should have test cases?
- []()
#7: Post edited
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- - You may take input in the format of your choice provided your choice of input format does not provide additional information that would help solve the challenge
- ## Output
- - A number from 0 to 64, indicating the number of squares that satisfy both of:
- - The square does not contain a knight
- - The square is not a knight's move away from a knight.
- A knight's move is either of:
- - 2 squares horizontally (left or right) and 1 square vertically (up or down)
- - 1 square horizontally (left or right) and 2 squares vertically (up or down)
- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
Test cases inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "******N*",
- "N*******",
- ],
- 47
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
- ---
- # Sandbox questions
- - Is there a more useful test case format?
- - Are there any edge cases that should have test cases?
- []()
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- - You may take input in the format of your choice provided your choice of input format does not provide additional information that would help solve the challenge
- ## Output
- - A number from 0 to 64, indicating the number of squares that satisfy both of:
- - The square does not contain a knight
- - The square is not a knight's move away from a knight.
- A knight's move is either of:
- - 2 squares horizontally (left or right) and 1 square vertically (up or down)
- - 1 square horizontally (left or right) and 2 squares vertically (up or down)
- [![Knight's moves shown as dots](https://codegolf.codidact.com/uploads/Q4kXyQDf3HZiX5NWncgRS2Fi)](https://en.wikipedia.org/wiki/Knight_(chess)#Movement "View on Wikipedia")
- (thanks to [Wikipedia](https://en.wikipedia.org/wiki/Knight_(chess)#Movement "Wikipedia section on Knight's moves"))
- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
- Test case inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.
- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "******N*",
- "N*******",
- ],
- 47
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
- ---
- # Sandbox questions
- - Is there a more useful test case format?
- - Are there any edge cases that should have test cases?
- []()
#6: Post edited
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- You may take input in the format of your choice - perhaps newline separated lines of 8 characters, or 8 strings of 8 characters, or a string of 64 characters, or 64 strings of 1 character - provided your choice of input style does not provide additional information that would help solve the challenge- ## Output
- - A number from 0 to 64, indicating the number of squares that satisfy both of:
- - The square does not contain a knight
- - The square is not a knight's move away from a knight.
- A knight's move is either of:
- - 2 squares horizontally (left or right) and 1 square vertically (up or down)
- - 1 square horizontally (left or right) and 2 squares vertically (up or down)
- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
- Test cases inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.
- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "******N*",
- "N*******",
- ],
- 47
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
- ---
- # Sandbox questions
- - Is there a more useful test case format?
- - Are there any edge cases that should have test cases?
- []()
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- - You may take input in the format of your choice provided your choice of input format does not provide additional information that would help solve the challenge
- ## Output
- - A number from 0 to 64, indicating the number of squares that satisfy both of:
- - The square does not contain a knight
- - The square is not a knight's move away from a knight.
- A knight's move is either of:
- - 2 squares horizontally (left or right) and 1 square vertically (up or down)
- - 1 square horizontally (left or right) and 2 squares vertically (up or down)
- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
- Test cases inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.
- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "******N*",
- "N*******",
- ],
- 47
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
- ---
- # Sandbox questions
- - Is there a more useful test case format?
- - Are there any edge cases that should have test cases?
- []()
#5: Post edited
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- You may take input as newline separated lines of 8 characters, or as a 2d data structure, or as 8 1d data structures - provided your choice of input style does not provide additional information that would help solve the challenge- ## Output
- - A number from 0 to 64, indicating the number of squares that satisfy both of:
- - The square does not contain a knight
- - The square is not a knight's move away from a knight.
- A knight's move is either of:
- - 2 squares horizontally (left or right) and 1 square vertically (up or down)
- - 1 square horizontally (left or right) and 2 squares vertically (up or down)
- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
- Test cases inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.
- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
- ---
- # Sandbox questions
- - Is there a more useful test case format?
- - Are there any edge cases that should have test cases?
- []()
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- - You may take input in the format of your choice - perhaps newline separated lines of 8 characters, or 8 strings of 8 characters, or a string of 64 characters, or 64 strings of 1 character - provided your choice of input style does not provide additional information that would help solve the challenge
- ## Output
- - A number from 0 to 64, indicating the number of squares that satisfy both of:
- - The square does not contain a knight
- - The square is not a knight's move away from a knight.
- A knight's move is either of:
- - 2 squares horizontally (left or right) and 1 square vertically (up or down)
- - 1 square horizontally (left or right) and 2 squares vertically (up or down)
- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
- Test cases inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.
- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "******N*",
- "N*******",
- ],
- 47
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
- ---
- # Sandbox questions
- - Is there a more useful test case format?
- - Are there any edge cases that should have test cases?
- []()
#4: Post edited
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- - You may take input as newline separated lines of 8 characters, or as a 2d data structure, or as 8 1d data structures - provided your choice of input style does not provide additional information that would help solve the challenge
- ## Output
- - A number from 0 to 64, indicating the number of squares that satisfy both of:
- The square is not a knight's move away from a knight- - The square does not contain a knight
- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
- Test cases inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.
- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
- ---
- # Sandbox questions
- - Is there a more useful test case format?
- - Are there any edge cases that should have test cases?
- []()
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- - You may take input as newline separated lines of 8 characters, or as a 2d data structure, or as 8 1d data structures - provided your choice of input style does not provide additional information that would help solve the challenge
- ## Output
- - A number from 0 to 64, indicating the number of squares that satisfy both of:
- - The square does not contain a knight
- - The square is not a knight's move away from a knight.
- A knight's move is either of:
- - 2 squares horizontally (left or right) and 1 square vertically (up or down)
- - 1 square horizontally (left or right) and 2 squares vertically (up or down)
- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
- Test cases inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.
- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
- ---
- # Sandbox questions
- - Is there a more useful test case format?
- - Are there any edge cases that should have test cases?
- []()
#3: Post edited
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- - You may take input as newline separated lines of 8 characters, or as a 2d data structure, or as 8 1d data structures - provided your choice of input style does not provide additional information that would help solve the challenge
- ## Output
- - A number from 0 to 64, indicating the number of squares that satisfy both of:
- - The square is not a knight's move away from a knight
- - The square does not contain a knight
- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
- Test cases inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.
- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- - You may take input as newline separated lines of 8 characters, or as a 2d data structure, or as 8 1d data structures - provided your choice of input style does not provide additional information that would help solve the challenge
- ## Output
- - A number from 0 to 64, indicating the number of squares that satisfy both of:
- - The square is not a knight's move away from a knight
- - The square does not contain a knight
- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
- Test cases inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.
- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
- ---
- # Sandbox questions
- - Is there a more useful test case format?
- - Are there any edge cases that should have test cases?
- []()
#2: Post edited
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- - You may take input as newline separated lines of 8 characters, or as a 2d data structure, or as 8 1d data structures - provided your choice of input style does not provide additional information that would help solve the challenge
- ## Output
- An integer from 0 to 64, indicating the number of squares that satisfy both of:- - The square is not a knight's move away from a knight
- - The square does not contain a knight
- You are not constrained to using an integer type - for example, a float or string that contains the required integer (and nothing else) is acceptable- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
- Test cases inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.
- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
- Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight.
- ## Input
- - An 8 by 8 grid where each square is either a knight or empty
- - You may choose to take input with any 2 distinct characters representing a knight and an empty square
- - You may take input as newline separated lines of 8 characters, or as a 2d data structure, or as 8 1d data structures - provided your choice of input style does not provide additional information that would help solve the challenge
- ## Output
- - A number from 0 to 64, indicating the number of squares that satisfy both of:
- - The square is not a knight's move away from a knight
- - The square does not contain a knight
- ## Example
- The following example input has knights represented by `N` and empty squares represented by `*`.
- ```text
- ********
- ********
- **N*****
- ********
- ********
- ********
- ******N*
- N*******
- ```
- Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`).
- ```text
- *a*a****
- a***a***
- **N*****
- a***a***
- *a*a*a*a
- *a**a***
- **a***N*
- N***a***
- ```
- So for this example, the output would be `47`.
- ## Test cases
- Test cases inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`.
- ```text
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 64
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 0
- ],
- [
- [
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- "N*N*N*N*",
- "*N*N*N*N",
- ],
- 0
- ],
- [
- [
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- "N***N***",
- "*N***N**",
- "**N***N*",
- "***N***N",
- ],
- 16
- ],
- [
- [
- "N*******",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 61
- ],
- [
- [
- "******N*",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 60
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*****N**",
- ],
- 59
- ],
- [
- [
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- "*N******",
- "********",
- ],
- 59
- ],
- [
- [
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 57
- ],
- [
- [
- "********",
- "********",
- "**N*****",
- "********",
- "********",
- "********",
- "********",
- "********",
- ],
- 55
- ],
- [
- [
- "********",
- "********",
- "****N***",
- "********",
- "***N****",
- "********",
- "********",
- "********",
- ],
- 48
- ],
- [
- [
- "********",
- "********",
- "***N****",
- "*****N**",
- "**N*****",
- "****N***",
- "********",
- "********",
- ],
- 36
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "NN*NNN*N",
- "NNNN*NNN",
- "NN*NNN*N",
- "NNN*N*NN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNN*N*NN",
- "N***NN*N",
- "*NNN*NNN",
- "NN*NNN*N",
- "*NN***NN",
- "N*N*NNNN",
- "NNNNNNNN",
- ],
- 2
- ],
- [
- [
- "*NNNNNNN",
- "NN*NNNNN",
- "N*NNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNN*N",
- "NNNN*NNN",
- "NNNNN*N*",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNN*N*N",
- "NNN*NNN*",
- "NNNNN*NN",
- ],
- 1
- ],
- [
- [
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "*N*NNNNN",
- "NNN*NNNN",
- "N*NNNNNN",
- "NNN*NNNN",
- ],
- 1
- ],
- [
- [
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ],
- [
- [
- "N*N*NNNN",
- "*NNN*NNN",
- "NN*NNNNN",
- "*NNN*NNN",
- "N*N*NNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- "NNNNNNNN",
- ],
- 1
- ]
- ```
- > Explanations in answers are optional, but I'm more likely to upvote answers that have one.
#1: Initial revision
Knight safe squares
Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight. ## Input - An 8 by 8 grid where each square is either a knight or empty - You may choose to take input with any 2 distinct characters representing a knight and an empty square - You may take input as newline separated lines of 8 characters, or as a 2d data structure, or as 8 1d data structures - provided your choice of input style does not provide additional information that would help solve the challenge ## Output - An integer from 0 to 64, indicating the number of squares that satisfy both of: - The square is not a knight's move away from a knight - The square does not contain a knight - You are not constrained to using an integer type - for example, a float or string that contains the required integer (and nothing else) is acceptable ## Example The following example input has knights represented by `N` and empty squares represented by `*`. ```text ******** ******** **N***** ******** ******** ******** ******N* N******* ``` Here it is again with attacked empty squares marked as `a`. The required output is the number of remaining squares (the number of squares still showing `*`). ```text *a*a**** a***a*** **N***** a***a*** *a*a*a*a *a**a*** **a***N* N***a*** ``` So for this example, the output would be `47`. ## Test cases Test cases inputs are given as 8 strings of 8 characters, followed by the output as an integer. Knights are represented by `N` and empty squares are represented by `*`. ```text [ [ "********", "********", "********", "********", "********", "********", "********", "********", ], 64 ], [ [ "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", ], 0 ], [ [ "N*N*N*N*", "*N*N*N*N", "N*N*N*N*", "*N*N*N*N", "N*N*N*N*", "*N*N*N*N", "N*N*N*N*", "*N*N*N*N", ], 0 ], [ [ "N***N***", "*N***N**", "**N***N*", "***N***N", "N***N***", "*N***N**", "**N***N*", "***N***N", ], 16 ], [ [ "N*******", "********", "********", "********", "********", "********", "********", "********", ], 61 ], [ [ "******N*", "********", "********", "********", "********", "********", "********", "********", ], 60 ], [ [ "********", "********", "********", "********", "********", "********", "********", "*****N**", ], 59 ], [ [ "********", "********", "********", "********", "********", "********", "*N******", "********", ], 59 ], [ [ "********", "**N*****", "********", "********", "********", "********", "********", "********", ], 57 ], [ [ "********", "********", "**N*****", "********", "********", "********", "********", "********", ], 55 ], [ [ "********", "********", "****N***", "********", "***N****", "********", "********", "********", ], 48 ], [ [ "********", "********", "***N****", "*****N**", "**N*****", "****N***", "********", "********", ], 36 ], [ [ "NNNNNNNN", "NNN*N*NN", "NN*NNN*N", "NNNN*NNN", "NN*NNN*N", "NNN*N*NN", "NNNNNNNN", "NNNNNNNN", ], 1 ], [ [ "NNNNNNNN", "NNN*N*NN", "N***NN*N", "*NNN*NNN", "NN*NNN*N", "*NN***NN", "N*N*NNNN", "NNNNNNNN", ], 2 ], [ [ "*NNNNNNN", "NN*NNNNN", "N*NNNNNN", "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", ], 1 ], [ [ "NNNNNN*N", "NNNN*NNN", "NNNNN*N*", "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", ], 1 ], [ [ "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", "NNNN*N*N", "NNN*NNN*", "NNNNN*NN", ], 1 ], [ [ "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", "*N*NNNNN", "NNN*NNNN", "N*NNNNNN", "NNN*NNNN", ], 1 ], [ [ "*NNN*NNN", "NN*NNNNN", "*NNN*NNN", "N*N*NNNN", "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", ], 1 ], [ [ "N*N*NNNN", "*NNN*NNN", "NN*NNNNN", "*NNN*NNN", "N*N*NNNN", "NNNNNNNN", "NNNNNNNN", "NNNNNNNN", ], 1 ] ``` > Explanations in answers are optional, but I'm more likely to upvote answers that have one.