Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

60%
+1 −0
Challenges Connected ​bits

AWK, 145 bytes Pass 64 character string of 1s and 0s on stdin. Zero exit means success; non-zero means failure. awk 'function n(i){i<1||i>72||c-$i||($i=2)+n(i+9)+n(i+1)+n(i-9)+n(i-1)}{gsub...

posted 6mo ago by jhnc‭  ·  edited 6mo ago by jhnc‭

Answer
#4: Post edited by user avatar jhnc‭ · 2026-03-31T14:01:30Z (6 months ago)
quick fix for horizontal wrapping
  • **This code is broken (Fails: "The grid does not wrap toroidally")**
  • <s>
  • # AWK, 127 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```
  • awk 'function n(i){i<1||i>64||c-$i||($i=2)+n(i+8)+n(i+1)+n(i-8)+n(i-1)}{n(index($0,0));c=1;n(index($0,1));exit/[01]/}' FS= OFS=
  • ```
  • Comments:
  • ```
  • awk '
  • function n(i){
  • i<1||i>64 || # out of bounds?
  • c-$i || # incorrect value?
  • ($i=2)+\
  • n(i+8)+n(i+1)+n(i-8)+n(i-1) # mark(replace) then recurse
  • }
  • {
  • n(index($0,0)); # find connected 0s
  • c=1; n(index($0,1)); # find connected 1s
  • exit /[01]/ # zero iff no 0s or 1s left
  • }
  • ' FS= OFS=
  • ```
  • * Same basic logic as my Perl answer
  • * `FS=` (non-standard but widely implemented) splits line into fields containing individual characters
  • * `OFS=` - assigning to a field cause line to be rewritten with fields separated by `OFS`; clearing it means result is unchanged (affects `index`)
  • [Try it online!][TIO-mmgi6y0b]
  • [TIO-mmgi6y0b]: https://tio.run/##rVJRS8MwEH7Przi6Ci1rWU5ExNoJgoov@rBHESldikFJpclw0PS317Td2o1WsNaEcLnLx3ff3SX6ei9nkKQZKCYVvEWZYFKSHD4zLlQC1okEfwmWBzaFgpCb2/uHxxzuVuGTOa9QlMlGxIqnAoTD3ZxfodZ8eX6mdezbXGvH5uGpOzeP84vGYG38xvPRLXJC4pAGAANCiMGINds6NvWo6wZxiMFBCE2IkBnbcgWLZ4ovC1IL3zlwDVYSfUhmwSVYKtuYy0AWr6kWuJCKRWtIE6gYSVGWdOIyeau0BCeuPc9EOVN58H95sOpPPaCOqKp2yI5s9GhFXaMbQV3v948dqB8ZnNhRZfhHQ3uKWsLGwxqJx7uNt7j@H6pBiPQX@4Dux1bjblRj9DSFfQM "AWK – Try It Online"
  • </s>
  • # AWK, 145 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```
  • awk 'function n(i){i<1||i>72||c-$i||($i=2)+n(i+9)+n(i+1)+n(i-9)+n(i-1)}{gsub(/.{8}/,"&2");n(index($0,0));c=1;n(index($0,1));exit/[01]/}' FS= OFS=
  • ```
  • Comments:
  • ```
  • awk '
  • function n(i){
  • i<1||i>72 || # out of bounds?
  • c-$i || # incorrect value?
  • ($i=2)+\
  • n(i+9)+n(i+1)+n(i-9)+n(i-1) # mark(replace) then recurse
  • }
  • {
  • gsub(/.{8}/,"&2"); # add sentinels to detect horizontal wrap
  • n(index($0,0)); # find connected 0s
  • c=1; n(index($0,1)); # find connected 1s
  • exit /[01]/ # zero iff no 0s or 1s left
  • }
  • ' FS= OFS=
  • ```
  • * Same basic logic as my Perl answer
  • * `FS=` (non-standard but widely implemented) splits line into fields containing individual characters
  • * `OFS=` - assigning to a field cause line to be rewritten with fields separated by `OFS`; clearing it means result is unchanged (affects `index`)
  • [Try it online!][TIO-mneompza]
  • [AWK]: https://www.gnu.org/software/gawk/manual/gawk.html
  • [TIO-mneompza]: https://tio.run/##rVJNT4QwEL33V0y6aCAL0uHiB7ImJmq86MGjMQZZ0EbTNbQbNwF@O/KxwG5Asyu2IcNMX99M34z/9Z5PIFrEoEKp4M2PRSglSeAz5kJFQA8kWDOgJmgMMkIur25u7xK4fvDui@8ZsjxaikDxhQChcyPh55imfHbspGlgaTxNdY17jjEtDqentcHKWLVnoZElhAQecwEGCiGvcvmi20fJSWab9NChhkuKa2IernSNmcww3MBDdyOERYiQSbjiCuxHhk82qd6yduACaOR/yJDCGVAVL4ufgcRmLQBwIVXoz2ERQclIsjxnI1eRt0xLcORqeEaWM5YH/5cHS32qBnVE5WuH7J5C711RJ3RdUKd9c9iB@pHBjm29DP9oWK@ilrD2sELi9m7jLa4/QxUIke2wN@h@lBrXrdqnnkahhmXXxm3j@0PUwoYn6pchqom@AQ "AWK – Try It Online"
#3: Post edited by user avatar jhnc‭ · 2026-03-31T13:06:39Z (6 months ago)
placeholder comment until code fixed
  • # AWK, 127 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```
  • awk 'function n(i){i<1||i>64||c-$i||($i=2)+n(i+8)+n(i+1)+n(i-8)+n(i-1)}{n(index($0,0));c=1;n(index($0,1));exit/[01]/}' FS= OFS=
  • ```
  • Comments:
  • ```
  • awk '
  • function n(i){
  • i<1||i>64 || # out of bounds?
  • c-$i || # incorrect value?
  • ($i=2)+\
  • n(i+8)+n(i+1)+n(i-8)+n(i-1) # mark(replace) then recurse
  • }
  • {
  • n(index($0,0)); # find connected 0s
  • c=1; n(index($0,1)); # find connected 1s
  • exit /[01]/ # zero iff no 0s or 1s left
  • }
  • ' FS= OFS=
  • ```
  • * Same basic logic as my Perl answer
  • * `FS=` (non-standard but widely implemented) splits line into fields containing individual characters
  • * `OFS=` - assigning to a field cause line to be rewritten with fields separated by `OFS`; clearing it means result is unchanged (affects `index`)
  • [Try it online!][TIO-mmgi6y0b]
  • [TIO-mmgi6y0b]: https://tio.run/##rVJRS8MwEH7Przi6Ci1rWU5ExNoJgoov@rBHESldikFJpclw0PS317Td2o1WsNaEcLnLx3ff3SX6ei9nkKQZKCYVvEWZYFKSHD4zLlQC1okEfwmWBzaFgpCb2/uHxxzuVuGTOa9QlMlGxIqnAoTD3ZxfodZ8eX6mdezbXGvH5uGpOzeP84vGYG38xvPRLXJC4pAGAANCiMGINds6NvWo6wZxiMFBCE2IkBnbcgWLZ4ovC1IL3zlwDVYSfUhmwSVYKtuYy0AWr6kWuJCKRWtIE6gYSVGWdOIyeau0BCeuPc9EOVN58H95sOpPPaCOqKp2yI5s9GhFXaMbQV3v948dqB8ZnNhRZfhHQ3uKWsLGwxqJx7uNt7j@H6pBiPQX@4Dux1bjblRj9DSFfQM "AWK – Try It Online"
  • **This code is broken (Fails: "The grid does not wrap toroidally")**
  • <s>
  • # AWK, 127 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```
  • awk 'function n(i){i<1||i>64||c-$i||($i=2)+n(i+8)+n(i+1)+n(i-8)+n(i-1)}{n(index($0,0));c=1;n(index($0,1));exit/[01]/}' FS= OFS=
  • ```
  • Comments:
  • ```
  • awk '
  • function n(i){
  • i<1||i>64 || # out of bounds?
  • c-$i || # incorrect value?
  • ($i=2)+\
  • n(i+8)+n(i+1)+n(i-8)+n(i-1) # mark(replace) then recurse
  • }
  • {
  • n(index($0,0)); # find connected 0s
  • c=1; n(index($0,1)); # find connected 1s
  • exit /[01]/ # zero iff no 0s or 1s left
  • }
  • ' FS= OFS=
  • ```
  • * Same basic logic as my Perl answer
  • * `FS=` (non-standard but widely implemented) splits line into fields containing individual characters
  • * `OFS=` - assigning to a field cause line to be rewritten with fields separated by `OFS`; clearing it means result is unchanged (affects `index`)
  • [Try it online!][TIO-mmgi6y0b]
  • [TIO-mmgi6y0b]: https://tio.run/##rVJRS8MwEH7Przi6Ci1rWU5ExNoJgoov@rBHESldikFJpclw0PS317Td2o1WsNaEcLnLx3ff3SX6ei9nkKQZKCYVvEWZYFKSHD4zLlQC1okEfwmWBzaFgpCb2/uHxxzuVuGTOa9QlMlGxIqnAoTD3ZxfodZ8eX6mdezbXGvH5uGpOzeP84vGYG38xvPRLXJC4pAGAANCiMGINds6NvWo6wZxiMFBCE2IkBnbcgWLZ4ovC1IL3zlwDVYSfUhmwSVYKtuYy0AWr6kWuJCKRWtIE6gYSVGWdOIyeau0BCeuPc9EOVN58H95sOpPPaCOqKp2yI5s9GhFXaMbQV3v948dqB8ZnNhRZfhHQ3uKWsLGwxqJx7uNt7j@H6pBiPQX@4Dux1bjblRj9DSFfQM "AWK – Try It Online"
  • </s>
#2: Post edited by user avatar jhnc‭ · 2026-03-07T15:56:05Z (6 months ago)
link to TIO
  • # awk, 127 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```
  • awk 'function n(i){i<1||i>64||c-$i||($i=2)+n(i+8)+n(i+1)+n(i-8)+n(i-1)}{n(index($0,0));c=1;n(index($0,1));exit/[01]/}' FS= OFS=
  • ```
  • Comments:
  • ```
  • awk '
  • function n(i){
  • i<1||i>64 || # out of bounds?
  • c-$i || # incorrect value?
  • ($i=2)+\
  • n(i+8)+n(i+1)+n(i-8)+n(i-1) # mark(replace) then recurse
  • }
  • {
  • n(index($0,0)); # find connected 0s
  • c=1; n(index($0,1)); # find connected 1s
  • exit /[01]/ # zero iff no 0s or 1s left
  • }
  • ' FS= OFS=
  • ```
  • * Same basic logic as my Perl answer
  • * `FS=` (non-standard but widely implemented) splits line into fields containing individual characters
  • * `OFS=` - assigning to a field cause line to be rewritten with fields separated by `OFS`; clearing it means result is unchanged (affects `index`)
  • # AWK, 127 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```
  • awk 'function n(i){i<1||i>64||c-$i||($i=2)+n(i+8)+n(i+1)+n(i-8)+n(i-1)}{n(index($0,0));c=1;n(index($0,1));exit/[01]/}' FS= OFS=
  • ```
  • Comments:
  • ```
  • awk '
  • function n(i){
  • i<1||i>64 || # out of bounds?
  • c-$i || # incorrect value?
  • ($i=2)+\
  • n(i+8)+n(i+1)+n(i-8)+n(i-1) # mark(replace) then recurse
  • }
  • {
  • n(index($0,0)); # find connected 0s
  • c=1; n(index($0,1)); # find connected 1s
  • exit /[01]/ # zero iff no 0s or 1s left
  • }
  • ' FS= OFS=
  • ```
  • * Same basic logic as my Perl answer
  • * `FS=` (non-standard but widely implemented) splits line into fields containing individual characters
  • * `OFS=` - assigning to a field cause line to be rewritten with fields separated by `OFS`; clearing it means result is unchanged (affects `index`)
  • [Try it online!][TIO-mmgi6y0b]
  • [TIO-mmgi6y0b]: https://tio.run/##rVJRS8MwEH7Przi6Ci1rWU5ExNoJgoov@rBHESldikFJpclw0PS317Td2o1WsNaEcLnLx3ff3SX6ei9nkKQZKCYVvEWZYFKSHD4zLlQC1okEfwmWBzaFgpCb2/uHxxzuVuGTOa9QlMlGxIqnAoTD3ZxfodZ8eX6mdezbXGvH5uGpOzeP84vGYG38xvPRLXJC4pAGAANCiMGINds6NvWo6wZxiMFBCE2IkBnbcgWLZ4ovC1IL3zlwDVYSfUhmwSVYKtuYy0AWr6kWuJCKRWtIE6gYSVGWdOIyeau0BCeuPc9EOVN58H95sOpPPaCOqKp2yI5s9GhFXaMbQV3v948dqB8ZnNhRZfhHQ3uKWsLGwxqJx7uNt7j@H6pBiPQX@4Dux1bjblRj9DSFfQM "AWK – Try It Online"
#1: Initial revision by user avatar jhnc‭ · 2026-03-07T15:46:54Z (6 months ago)
# awk, 127 bytes

Pass 64 character string of 1s and 0s on stdin.

Zero exit means success; non-zero means failure.

```
awk 'function n(i){i<1||i>64||c-$i||($i=2)+n(i+8)+n(i+1)+n(i-8)+n(i-1)}{n(index($0,0));c=1;n(index($0,1));exit/[01]/}' FS= OFS=
```

Comments:

```
awk '
    function n(i){
        i<1||i>64 ||  # out of bounds?
        c-$i ||       # incorrect value?
        ($i=2)+\
        n(i+8)+n(i+1)+n(i-8)+n(i-1)  # mark(replace) then recurse
    }
    {
             n(index($0,0));  # find connected 0s
        c=1; n(index($0,1));  # find connected 1s

        exit /[01]/  # zero iff no 0s or 1s left
    }
' FS= OFS=
```

* Same basic logic as my Perl answer
* `FS=` (non-standard but widely implemented) splits line into fields containing individual characters
* `OFS=` - assigning to a field cause line to be rewritten with fields separated by `OFS`; clearing it means result is unchanged (affects `index`)