Post History
Indicate whether the 1s and 0s in an 8 by 8 grid are connected. The grid Connectedness is by orthogonal adjacency (up, down, left, right). Diagonal adjacency does not count. If all of the 1s ...
#2: Post edited
- Indicate whether the `1`s and `0`s in an 8 by 8 grid are connected.
- ## The grid
- - Connectedness is by orthogonal adjacency (up, down, left, right).
- - Diagonal adjacency does not count.
- - If all of the `1`s can be reached by orthogonal steps from any other `1`, stepping on only `1`s, then the set of `1`s is connected.
- - If all of the `0`s can be reached by orthogonal steps from any other `0`, stepping on only `0`s, then the set of `0`s is connected.
- - The grid does not wrap toroidally. The left hand edge is not adjacent to the right hand edge, and the top edge is not adjacent to the bottom edge.
- ## Input
- - An 8 by 8 grid of `1`s and `0`s. This can be in any format that does not contribute to solving the challenge. For example:
- - 8 strings of 8 characters.
- - A string of 64 characters.
- - A string of newline separated strings of 8 characters.
- - A sequence of 8 8 bit values.
- - A 64 bit value (such as an unsigned integer).
- ## Output
- - An indication of whether all of the like values are connected. That is, all of the `1`s are connected and all of the `0`s are connected.
- - This could be one of 2 distinct values to indicate true or false, or any truthy or falsy value if your language has this concept.
- ## Examples
- ### Connected
- ```text
- 00000000
- 00000000
- 01111000
- 01111000
- 01111000
- 00000000
- 00000000
- 00000000
- 00000000
- ```
- ### `1`s not connected
- ```text
- 11111111
- 00000000
- 00000000
- 00000000
- 00000000
- 00000000
- 00000000
- 11111111
- ```
- ### `0`s not connected
- Diagonal connection does not count.
- ```text
- 11111111
- 11001111
- 11001111
- 11110011
- 11110011
- 11111111
- 11111111
- 11111111
- ```
- ### Neither connected
- ```text
- 00000001
- 00000010
- 00000100
- 00001000
- 00010000
- 00100000
- 01000000
- 10000000
- ```
- ### Trivially connected
- The empty set is considered to be connected, so if there are no `1`s, the set of `1`s is connected. Similarly for `0`s.
- ```text
- 00000000
- 00000000
- 00000000
- 00000000
- 00000000
- 00000000
- 00000000
- 00000000
- ```
- ```text
- 11111111
- 11111111
- 11111111
- 11111111
- 11111111
- 11111111
- 11111111
- 11111111
- ```
- ## Test cases
- Each test case is in the format `input : output`.
- ### Unsigned integer input
- ```text
- 0 : true
- 18446744073709551615 : true
- 1 : true
- 257 : true
- 258 : false
- 33909453996687360 : true
- 18374686479671623935 : false
- 18433180446528372735 : false
- 72624976668147840 : false
- 18375105691386724735 : true
- 67178694441613952 : true
- 18375101293340213631 : false
- ```
- ### Binary input
- ```text
- 0000000000000000000000000000000000000000000000000000000000000000 : true
- 1111111111111111111111111111111111111111111111111111111111111111 : true
- 0000000000000000000000000000000000000000000000000000000000000001 : true
- 0000000000000000000000000000000000000000000000000000000100000001 : true
- 0000000000000000000000000000000000000000000000000000000100000010 : false
- 0000000001111000011110000111100000000000000000000000000000000000 : true
- 1111111100000000000000000000000000000000000000000000000011111111 : false
- 1111111111001111110011111111001111110011111111111111111111111111 : false
- 0000000100000010000001000000100000010000001000000100000010000000 : false
- 1111111100000001011111010100010101010101010111010100000101111111 : true
- 0000000011101110101010101010101010101010101010101011101010000000 : true
- 1111111100000001011110010100010101010101010111010100000101111111 : false
- ```
- ## Scoring
- This is a [code golf challenge]. Your score is the number of bytes in your code. Lowest score for each language wins.
- > Explanations are optional, but I'm more likely to upvote answers that have one.
- [code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"
- Indicate whether the `1`s and `0`s in an 8 by 8 grid are connected.
- ## The grid
- - Connectedness is by orthogonal adjacency (up, down, left, right).
- - Diagonal adjacency does not count.
- - If all of the `1`s can be reached by orthogonal steps from any other `1`, stepping on only `1`s, then the set of `1`s is connected.
- - If all of the `0`s can be reached by orthogonal steps from any other `0`, stepping on only `0`s, then the set of `0`s is connected.
- - The grid does not wrap toroidally. The left hand edge is not adjacent to the right hand edge, and the top edge is not adjacent to the bottom edge.
- ## Input
- - An 8 by 8 grid of `1`s and `0`s. This can be in any format that does not contribute to solving the challenge. For example:
- - 8 strings of 8 characters.
- - A string of 64 characters.
- - A string of newline separated strings of 8 characters.
- - A sequence of 8 8 bit values.
- - A 64 bit value (such as an unsigned integer).
- ## Output
- - An indication of whether all of the like values are connected. That is, all of the `1`s are connected and all of the `0`s are connected.
- - This could be one of 2 distinct values to indicate true or false, or any truthy or falsy value if your language has this concept.
- ## Examples
- ### Connected
- ```text
- 00000000
- 00000000
- 01111000
- 01111000
- 01111000
- 00000000
- 00000000
- 00000000
- 00000000
- ```
- ### `1`s not connected
- ```text
- 11111111
- 00000000
- 00000000
- 00000000
- 00000000
- 00000000
- 00000000
- 11111111
- ```
- ### `0`s not connected
- Diagonal connection does not count.
- ```text
- 11111111
- 11001111
- 11001111
- 11110011
- 11110011
- 11111111
- 11111111
- 11111111
- ```
- ### Neither connected
- ```text
- 00000001
- 00000010
- 00000100
- 00001000
- 00010000
- 00100000
- 01000000
- 10000000
- ```
- ### Trivially connected
- The empty set is considered to be connected, so if there are no `1`s, the set of `1`s is connected. Similarly for `0`s.
- ```text
- 00000000
- 00000000
- 00000000
- 00000000
- 00000000
- 00000000
- 00000000
- 00000000
- ```
- ```text
- 11111111
- 11111111
- 11111111
- 11111111
- 11111111
- 11111111
- 11111111
- 11111111
- ```
- ## Test cases
- Each test case is in the format `input : output`.
- ### Unsigned integer input
- ```text
- 0 : true
- 18446744073709551615 : true
- 1 : true
- 257 : true
- 258 : false
- 33909453996687360 : true
- 18374686479671623935 : false
- 18433180446528372735 : false
- 72624976668147840 : false
- 18375105691386724735 : true
- 67178694441613952 : true
- 18375101293340213631 : false
- 4050987864819775544 : false
- 215245557596160 : false
- ```
- ### Binary input
- ```text
- 0000000000000000000000000000000000000000000000000000000000000000 : true
- 1111111111111111111111111111111111111111111111111111111111111111 : true
- 0000000000000000000000000000000000000000000000000000000000000001 : true
- 0000000000000000000000000000000000000000000000000000000100000001 : true
- 0000000000000000000000000000000000000000000000000000000100000010 : false
- 0000000001111000011110000111100000000000000000000000000000000000 : true
- 1111111100000000000000000000000000000000000000000000000011111111 : false
- 1111111111001111110011111111001111110011111111111111111111111111 : false
- 0000000100000010000001000000100000010000001000000100000010000000 : false
- 1111111100000001011111010100010101010101010111010100000101111111 : true
- 0000000011101110101010101010101010101010101010101011101010000000 : true
- 1111111100000001011110010100010101010101010111010100000101111111 : false
- 0011100000111000000000000000000000000000000000000011100000111000 : false
- 0000000000000000110000111100001111000011000000000000000000000000 : false
- ```
- ## Scoring
- This is a [code golf challenge]. Your score is the number of bytes in your code. Lowest score for each language wins.
- > Explanations are optional, but I'm more likely to upvote answers that have one.
- [code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"
#1: Initial revision
Connected bits
Indicate whether the `1`s and `0`s in an 8 by 8 grid are connected. ## The grid - Connectedness is by orthogonal adjacency (up, down, left, right). - Diagonal adjacency does not count. - If all of the `1`s can be reached by orthogonal steps from any other `1`, stepping on only `1`s, then the set of `1`s is connected. - If all of the `0`s can be reached by orthogonal steps from any other `0`, stepping on only `0`s, then the set of `0`s is connected. - The grid does not wrap toroidally. The left hand edge is not adjacent to the right hand edge, and the top edge is not adjacent to the bottom edge. ## Input - An 8 by 8 grid of `1`s and `0`s. This can be in any format that does not contribute to solving the challenge. For example: - 8 strings of 8 characters. - A string of 64 characters. - A string of newline separated strings of 8 characters. - A sequence of 8 8 bit values. - A 64 bit value (such as an unsigned integer). ## Output - An indication of whether all of the like values are connected. That is, all of the `1`s are connected and all of the `0`s are connected. - This could be one of 2 distinct values to indicate true or false, or any truthy or falsy value if your language has this concept. ## Examples ### Connected ```text 00000000 00000000 01111000 01111000 01111000 00000000 00000000 00000000 00000000 ``` ### `1`s not connected ```text 11111111 00000000 00000000 00000000 00000000 00000000 00000000 11111111 ``` ### `0`s not connected Diagonal connection does not count. ```text 11111111 11001111 11001111 11110011 11110011 11111111 11111111 11111111 ``` ### Neither connected ```text 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000 ``` ### Trivially connected The empty set is considered to be connected, so if there are no `1`s, the set of `1`s is connected. Similarly for `0`s. ```text 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ``` ```text 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 ``` ## Test cases Each test case is in the format `input : output`. ### Unsigned integer input ```text 0 : true 18446744073709551615 : true 1 : true 257 : true 258 : false 33909453996687360 : true 18374686479671623935 : false 18433180446528372735 : false 72624976668147840 : false 18375105691386724735 : true 67178694441613952 : true 18375101293340213631 : false ``` ### Binary input ```text 0000000000000000000000000000000000000000000000000000000000000000 : true 1111111111111111111111111111111111111111111111111111111111111111 : true 0000000000000000000000000000000000000000000000000000000000000001 : true 0000000000000000000000000000000000000000000000000000000100000001 : true 0000000000000000000000000000000000000000000000000000000100000010 : false 0000000001111000011110000111100000000000000000000000000000000000 : true 1111111100000000000000000000000000000000000000000000000011111111 : false 1111111111001111110011111111001111110011111111111111111111111111 : false 0000000100000010000001000000100000010000001000000100000010000000 : false 1111111100000001011111010100010101010101010111010100000101111111 : true 0000000011101110101010101010101010101010101010101011101010000000 : true 1111111100000001011110010100010101010101010111010100000101111111 : false ``` ## Scoring This is a [code golf challenge]. Your score is the number of bytes in your code. Lowest score for each language wins. > Explanations are optional, but I'm more likely to upvote answers that have one. [code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"
