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

66%
+2 −0
Challenges Connected ​bits

Perl, 152 bytes Pass 64 character string of 1s and 0s on stdin. Zero exit means success; non-zero means failure. perl -ne's/.{8}\K/2/g;@g=/./g;sub c{my($i)=@_;$i<0||$i>71||$g[$i]-$v||($g[$...

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

Answer
#18: Post edited by user avatar jhnc‭ · 2026-06-07T02:44:46Z (3 months ago)
map to set arguments instead of writing out function call four times
  • # Perl, 161 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne's/.{8}\K/2/g;@g=/./g;sub c{my($i)=@_;$i<0||$i>71||$g[$i]-$v||($g[$i]=2)+c($i+9)+c($i+1)+c($i-9)+c($i-1)}c index$_,0;$v=1;c index$_,1;exit 72-grep/2/,@g'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # add sentinels to detect horizontal wrapping
  • s/.{8}\K/2/g;
  • # load input string into array of individual characters
  • @g=/./g;
  • # recursive connectivity search
  • # mark each connected element found
  • sub c{
  • my($i)=@_;
  • $i<0||$i>71 # out of bounds?
  • || $g[$i]-$v # incorrect value?
  • || ($g[$i]=2) # mark value
  • + c($i+9) # recurse
  • + c($i+1)
  • + c($i-9)
  • + c($i-1)
  • }
  • c index$_,0; # search for connected 0s
  • $v=1; c index$_,1; # search for connected 1s
  • exit 72-grep/2/,@g # zero iff 64 values were marked
  • '
  • ```
  • [Try it online!][TIO-mneoflhe]
  • [TIO-mneoflhe]: https://tio.run/##rZLRboIwFIbv@xQn2GUSQajJ4rYO5/0eYTPGYcEmDgitxkV89bECAjPgomPtxWnLn4@/f0/E4vVd2gMvjEEyIWG1iAMmBMLBGhxwV2FEURTzQHqg3QgwJ6AZeE5TYQ3394e3F2tk@XTqO9ZQVbF5B3f/8dnHXHemc4r5k50kmE/GRBX/FfOZibdJ0i/WzkgfuEo7eDhWUlTzuDeJfkAIbx2bQotF5AIPlmyH54ZNlYrQ@oBQhHpsxyWMR6Yfs0j5NKb@LZwfzT8YkN9cQYVkiyWEHmTIIo8M3K/JOjyD5i3WgmnwCJqMN0wzQKVI09TuOBQw4yHScZScjna6csj/ckiWT558Dcpu21avDPpqR3XQhaE6@/JjLWqetL7Yyc3IH4vdcFQBix3JleR0VueVrtlDuYgQ@4L5A3c2anJ8qmv8lAmVlEsf7lTfbKJK1t5RvzRRAfoKI8nDQKRm8A0 "Perl 5 – Try It Online"
  • # Perl, 152 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne's/.{8}\K/2/g;@g=/./g;sub c{my($i)=@_;$i<0||$i>71||$g[$i]-$v||($g[$i]=2)+map{c($i+$_)}9,1,-9,-1}c index$_,0;$v=1;c index$_,1;exit 72-grep/2/,@g'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # add sentinels to detect horizontal wrapping
  • s/.{8}\K/2/g;
  • # load input string into array of individual characters
  • @g=/./g;
  • # recursive connectivity search
  • # mark each connected element found
  • sub c{
  • my($i)=@_;
  • $i<0 || $i>71 # out of bounds?
  • || $g[$i]-$v # incorrect value?
  • # if not,
  • || ($g[$i]=2) # mark value
  • + map {
  • c($i+$_) # and recurse
  • } 9,1,-9,-1
  • }
  • c index$_,0; # search for connected 0s
  • $v=1; c index$_,1; # search for connected 1s
  • exit 72-grep/2/,@g # zero iff 64 values were marked
  • '
  • ```
  • [Try it online!][TIO-mq369m8s]
  • [Perl 5]: https://www.perl.org/
  • [TIO-mq369m8s]: https://tio.run/##rVLRToMwFH3nK26wZltWBl1i5qzMvfsJasjEwppsQChbZoBfF1sQcGGaTWwfbnt7enru6Y1YvLkprsALY0iYSGC9igMmhIaCDdjgrsOIalHMg8QD/VqAsQAdI4dqaC@PLartBAOxexUwYAeeDKgmN6CWKZTXQKy5l8AD6N5qI5gOd6An8Y7pGNQTeSHMSXqbPz@aU9OnS982JzIqEjfdvg8RH9lLhyJ@b2UZ4osZkcF/QvzFQPssG1Zrezoab1dR6kr8GDmjfI4JNubYILkLPHhjB@Rgi6K9TWibIFTphNnU8GMWyffx0i8Kq@eQBar6NNJz1Dw95fTlIf/LQ5Q/ZSe0RKraU/FCoy9W1BpdCWq9rw9bUDdz8seOKiN/DFZHUUNY7UiJJMezyTe4bg@VIEKsM@Y3uh@tJl9fdYme2qGa5dyPO8Z3m6iBne6oX5qoIvoIo4SHgSiM4BM "Perl 5 – Try It Online"
#17: Post edited by user avatar jhnc‭ · 2026-03-31T13:53:53Z (6 months ago)
quick fix for horizontal wrapping
  • **This code is broken (Fails "The grid does not wrap toroidally").**
  • <s>
  • # Perl, 148 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=/./g;sub c{my($i)=@_;$i<0||$i>63||$g[$i]-$v||($g[$i]=2)+c($i+8)+c($i+1)+c($i-8)+c($i-1)}c index$_,0;$v=1;c index$_,1;exit 64-grep/2/,@g'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input string into array of individual characters
  • @g=/./g;
  • # recursive connectivity search
  • # mark each connected element found
  • sub c{
  • my($i)=@_;
  • $i<0||$i>63 # out of bounds?
  • || $g[$i]-$v # incorrect value?
  • || ($g[$i]=2) # mark value
  • + c($i+8) # recurse
  • + c($i+1)
  • + c($i-8)
  • + c($i-1)
  • }
  • c index$_,0; # search for connected 0s
  • $v=1; c index$_,1; # search for connected 1s
  • exit 64-grep/2/,@g # zero iff 64 values were marked
  • '
  • ```
  • [Try it online!][TIO-mmggpw0z]
  • [TIO-mmggpw0z]: https://tio.run/##rZLvToMwFMW/9yluWI2QgXCnLsbK3HsYQ5AV1mQCod0yI766yJ9tbIElTmw/XHo5@XHuKSnPVvfFCMIkA8WlgqWfxVxKQuMVuBAsk5SRNBOxCkG7kmDNQDOpx4p55No3dsTk@g2Cz/cPnQrDnXuMiicnz6mYTW/LEr1Q8WrRTZ7rzbM7McZBqR0/7Co21dqdLTS@CKEb12HQ44oEIOIF31LPdFipQtY2kBEy4luhYHpnRRlP7YltzqNrOL@6XzChHraESsX9BSQhVMgmggqst2QDnkEL/ZXkGjyCprI110wog2NF4QxcJbDiERy49pyBdoZy8H85WOVTJ9@Cqmn76oVBX@yoDbox1Ga/f9mKup3eGzuZDP9YnI6jA7A5Ya3E033oH3Tdf6gWITq/2Ee4s1Hj7qou8dMM9p2kSiSxLKz4Bw "Perl 5 – Try It Online"
  • </s>
  • # Perl, 161 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne's/.{8}\K/2/g;@g=/./g;sub c{my($i)=@_;$i<0||$i>71||$g[$i]-$v||($g[$i]=2)+c($i+9)+c($i+1)+c($i-9)+c($i-1)}c index$_,0;$v=1;c index$_,1;exit 72-grep/2/,@g'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # add sentinels to detect horizontal wrapping
  • s/.{8}\K/2/g;
  • # load input string into array of individual characters
  • @g=/./g;
  • # recursive connectivity search
  • # mark each connected element found
  • sub c{
  • my($i)=@_;
  • $i<0||$i>71 # out of bounds?
  • || $g[$i]-$v # incorrect value?
  • || ($g[$i]=2) # mark value
  • + c($i+9) # recurse
  • + c($i+1)
  • + c($i-9)
  • + c($i-1)
  • }
  • c index$_,0; # search for connected 0s
  • $v=1; c index$_,1; # search for connected 1s
  • exit 72-grep/2/,@g # zero iff 64 values were marked
  • '
  • ```
  • [Try it online!][TIO-mneoflhe]
  • [TIO-mneoflhe]: https://tio.run/##rZLRboIwFIbv@xQn2GUSQajJ4rYO5/0eYTPGYcEmDgitxkV89bECAjPgomPtxWnLn4@/f0/E4vVd2gMvjEEyIWG1iAMmBMLBGhxwV2FEURTzQHqg3QgwJ6AZeE5TYQ3394e3F2tk@XTqO9ZQVbF5B3f/8dnHXHemc4r5k50kmE/GRBX/FfOZibdJ0i/WzkgfuEo7eDhWUlTzuDeJfkAIbx2bQotF5AIPlmyH54ZNlYrQ@oBQhHpsxyWMR6Yfs0j5NKb@LZwfzT8YkN9cQYVkiyWEHmTIIo8M3K/JOjyD5i3WgmnwCJqMN0wzQKVI09TuOBQw4yHScZScjna6csj/ckiWT558Dcpu21avDPpqR3XQhaE6@/JjLWqetL7Yyc3IH4vdcFQBix3JleR0VueVrtlDuYgQ@4L5A3c2anJ8qmv8lAmVlEsf7lTfbKJK1t5RvzRRAfoKI8nDQKRm8A0 "Perl 5 – Try It Online"
#16: Post edited by user avatar jhnc‭ · 2026-03-31T13:05:29Z (6 months ago)
placeholder comment until code fixed
  • # Perl, 148 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=/./g;sub c{my($i)=@_;$i<0||$i>63||$g[$i]-$v||($g[$i]=2)+c($i+8)+c($i+1)+c($i-8)+c($i-1)}c index$_,0;$v=1;c index$_,1;exit 64-grep/2/,@g'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input string into array of individual characters
  • @g=/./g;
  • # recursive connectivity search
  • # mark each connected element found
  • sub c{
  • my($i)=@_;
  • $i<0||$i>63 # out of bounds?
  • || $g[$i]-$v # incorrect value?
  • || ($g[$i]=2) # mark value
  • + c($i+8) # recurse
  • + c($i+1)
  • + c($i-8)
  • + c($i-1)
  • }
  • c index$_,0; # search for connected 0s
  • $v=1; c index$_,1; # search for connected 1s
  • exit 64-grep/2/,@g # zero iff 64 values were marked
  • '
  • ```
  • [Try it online!][TIO-mmggpw0z]
  • [TIO-mmggpw0z]: https://tio.run/##rZLvToMwFMW/9yluWI2QgXCnLsbK3HsYQ5AV1mQCod0yI766yJ9tbIElTmw/XHo5@XHuKSnPVvfFCMIkA8WlgqWfxVxKQuMVuBAsk5SRNBOxCkG7kmDNQDOpx4p55No3dsTk@g2Cz/cPnQrDnXuMiicnz6mYTW/LEr1Q8WrRTZ7rzbM7McZBqR0/7Co21dqdLTS@CKEb12HQ44oEIOIF31LPdFipQtY2kBEy4luhYHpnRRlP7YltzqNrOL@6XzChHraESsX9BSQhVMgmggqst2QDnkEL/ZXkGjyCprI110wog2NF4QxcJbDiERy49pyBdoZy8H85WOVTJ9@Cqmn76oVBX@yoDbox1Ga/f9mKup3eGzuZDP9YnI6jA7A5Ya3E033oH3Tdf6gWITq/2Ee4s1Hj7qou8dMM9p2kSiSxLKz4Bw "Perl 5 – Try It Online"
  • **This code is broken (Fails "The grid does not wrap toroidally").**
  • <s>
  • # Perl, 148 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=/./g;sub c{my($i)=@_;$i<0||$i>63||$g[$i]-$v||($g[$i]=2)+c($i+8)+c($i+1)+c($i-8)+c($i-1)}c index$_,0;$v=1;c index$_,1;exit 64-grep/2/,@g'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input string into array of individual characters
  • @g=/./g;
  • # recursive connectivity search
  • # mark each connected element found
  • sub c{
  • my($i)=@_;
  • $i<0||$i>63 # out of bounds?
  • || $g[$i]-$v # incorrect value?
  • || ($g[$i]=2) # mark value
  • + c($i+8) # recurse
  • + c($i+1)
  • + c($i-8)
  • + c($i-1)
  • }
  • c index$_,0; # search for connected 0s
  • $v=1; c index$_,1; # search for connected 1s
  • exit 64-grep/2/,@g # zero iff 64 values were marked
  • '
  • ```
  • [Try it online!][TIO-mmggpw0z]
  • [TIO-mmggpw0z]: https://tio.run/##rZLvToMwFMW/9yluWI2QgXCnLsbK3HsYQ5AV1mQCod0yI766yJ9tbIElTmw/XHo5@XHuKSnPVvfFCMIkA8WlgqWfxVxKQuMVuBAsk5SRNBOxCkG7kmDNQDOpx4p55No3dsTk@g2Cz/cPnQrDnXuMiicnz6mYTW/LEr1Q8WrRTZ7rzbM7McZBqR0/7Co21dqdLTS@CKEb12HQ44oEIOIF31LPdFipQtY2kBEy4luhYHpnRRlP7YltzqNrOL@6XzChHraESsX9BSQhVMgmggqst2QDnkEL/ZXkGjyCprI110wog2NF4QxcJbDiERy49pyBdoZy8H85WOVTJ9@Cqmn76oVBX@yoDbox1Ga/f9mKup3eGzuZDP9YnI6jA7A5Ya3E033oH3Tdf6gWITq/2Ee4s1Hj7qou8dMM9p2kSiSxLKz4Bw "Perl 5 – Try It Online"
  • </s>
#15: Post edited by user avatar jhnc‭ · 2026-03-07T15:20:10Z (6 months ago)
marking in-place avoids array reset
  • # Perl, 154 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=/./g;sub c{my($i)=@_;$i<0||$i>63||$s[$i]++||$g[$i]-$c?0:1+c($i+8)+c($i+1)+c($i-8)+c($i-1)}$r=c index$_,0;@s=();$c=1;$r+=c index$_,1;exit$r-64'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input into array
  • @g = /./g;
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($i) = @_;
  • $i<0||$i>63 # bounds check
  • || $s[$i]++ # already visited?
  • || $g[$i]-$c # correct value?
  • ? 0
  • : 1 + c($i+8)+c($i+1)+c($i-8)+c($i-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c index$_,0;
  • @s=(); $c=1; $r += c index$_,1;
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit $r-64
  • '
  • ```
  • [Try it online!][TIO-mmfi7ljd]
  • [TIO-mmfi7ljd]: https://tio.run/##rZLvboIwFMW/9ylusEskwOzNNrPYob7HshjFok0ckLYmLnOvPgZUQYMmc6z9cPvn5Me5p2RCbZ7yHsSpAiO0gfVcJUJrQpMNhBCt04yTTMnExODcaQjG4Ph0xvPpKhzcD1ac6O0Cos/3jz6VbjidcSpf2H5P5Xj4UBT9SuWb5xWrVbkKaDRhI/SiQu09u7aircFhH6D7RchUh32X0yhkHC7YI1SFEchkKXZ05jNey5FT5Z1cISekB2InDVAVDB85XBntj/hQNV6gtBHzJaRxxbFxWBpMwInnGy0cGIFj1FY4PhTR8TxnHUcBLHkEO44jp6Odrhz8Xw6W@VTJN6Cy20v1xqBvdtQEbQ012R8vG1H75OKLnXWGfyys5agG2h1WSjyf9Xmta/9DlQiR/WKe4K5GjYenusWPbew7zYxME50HyQ8 "Perl 5 – Try It Online"
  • # Perl, 148 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=/./g;sub c{my($i)=@_;$i<0||$i>63||$g[$i]-$v||($g[$i]=2)+c($i+8)+c($i+1)+c($i-8)+c($i-1)}c index$_,0;$v=1;c index$_,1;exit 64-grep/2/,@g'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input string into array of individual characters
  • @g=/./g;
  • # recursive connectivity search
  • # mark each connected element found
  • sub c{
  • my($i)=@_;
  • $i<0||$i>63 # out of bounds?
  • || $g[$i]-$v # incorrect value?
  • || ($g[$i]=2) # mark value
  • + c($i+8) # recurse
  • + c($i+1)
  • + c($i-8)
  • + c($i-1)
  • }
  • c index$_,0; # search for connected 0s
  • $v=1; c index$_,1; # search for connected 1s
  • exit 64-grep/2/,@g # zero iff 64 values were marked
  • '
  • ```
  • [Try it online!][TIO-mmggpw0z]
  • [TIO-mmggpw0z]: https://tio.run/##rZLvToMwFMW/9yluWI2QgXCnLsbK3HsYQ5AV1mQCod0yI766yJ9tbIElTmw/XHo5@XHuKSnPVvfFCMIkA8WlgqWfxVxKQuMVuBAsk5SRNBOxCkG7kmDNQDOpx4p55No3dsTk@g2Cz/cPnQrDnXuMiicnz6mYTW/LEr1Q8WrRTZ7rzbM7McZBqR0/7Co21dqdLTS@CKEb12HQ44oEIOIF31LPdFipQtY2kBEy4luhYHpnRRlP7YltzqNrOL@6XzChHraESsX9BSQhVMgmggqst2QDnkEL/ZXkGjyCprI110wog2NF4QxcJbDiERy49pyBdoZy8H85WOVTJ9@Cqmn76oVBX@yoDbox1Ga/f9mKup3eGzuZDP9YnI6jA7A5Ya3E033oH3Tdf6gWITq/2Ee4s1Hj7qou8dMM9p2kSiSxLKz4Bw "Perl 5 – Try It Online"
#14: Post edited by user avatar jhnc‭ · 2026-03-06T23:13:45Z (6 months ago)
typo
  • # Perl, 154 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=/./g;sub c{my($i)=@_;$i<0||$i>63||$s[$i]++||$g[$i]-$c?0:1+c($i+8)+c($i+1)+c($i-8)+c($i-1)}$r=c index$_,0;@s=();$c=1;$r+=c index$_,1;exit$r-64'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input into array
  • @g = /./g];
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($i) = @_;
  • $i<0||$i>63 # bounds check
  • || $s[$i]++ # already visited?
  • || $g[$i]-$c # correct value?
  • ? 0
  • : 1 + c($i+8)+c($i+1)+c($i-8)+c($i-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c index$_,0;
  • @s=(); $c=1; $r += c index$_,1;
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit $r-64
  • '
  • ```
  • [Try it online!][TIO-mmfi7ljd]
  • [TIO-mmfi7ljd]: https://tio.run/##rZLvboIwFMW/9ylusEskwOzNNrPYob7HshjFok0ckLYmLnOvPgZUQYMmc6z9cPvn5Me5p2RCbZ7yHsSpAiO0gfVcJUJrQpMNhBCt04yTTMnExODcaQjG4Ph0xvPpKhzcD1ac6O0Cos/3jz6VbjidcSpf2H5P5Xj4UBT9SuWb5xWrVbkKaDRhI/SiQu09u7aircFhH6D7RchUh32X0yhkHC7YI1SFEchkKXZ05jNey5FT5Z1cISekB2InDVAVDB85XBntj/hQNV6gtBHzJaRxxbFxWBpMwInnGy0cGIFj1FY4PhTR8TxnHUcBLHkEO44jp6Odrhz8Xw6W@VTJN6Cy20v1xqBvdtQEbQ012R8vG1H75OKLnXWGfyys5agG2h1WSjyf9Xmta/9DlQiR/WKe4K5GjYenusWPbew7zYxME50HyQ8 "Perl 5 – Try It Online"
  • # Perl, 154 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=/./g;sub c{my($i)=@_;$i<0||$i>63||$s[$i]++||$g[$i]-$c?0:1+c($i+8)+c($i+1)+c($i-8)+c($i-1)}$r=c index$_,0;@s=();$c=1;$r+=c index$_,1;exit$r-64'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input into array
  • @g = /./g;
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($i) = @_;
  • $i<0||$i>63 # bounds check
  • || $s[$i]++ # already visited?
  • || $g[$i]-$c # correct value?
  • ? 0
  • : 1 + c($i+8)+c($i+1)+c($i-8)+c($i-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c index$_,0;
  • @s=(); $c=1; $r += c index$_,1;
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit $r-64
  • '
  • ```
  • [Try it online!][TIO-mmfi7ljd]
  • [TIO-mmfi7ljd]: https://tio.run/##rZLvboIwFMW/9ylusEskwOzNNrPYob7HshjFok0ckLYmLnOvPgZUQYMmc6z9cPvn5Me5p2RCbZ7yHsSpAiO0gfVcJUJrQpMNhBCt04yTTMnExODcaQjG4Ph0xvPpKhzcD1ac6O0Cos/3jz6VbjidcSpf2H5P5Xj4UBT9SuWb5xWrVbkKaDRhI/SiQu09u7aircFhH6D7RchUh32X0yhkHC7YI1SFEchkKXZ05jNey5FT5Z1cISekB2InDVAVDB85XBntj/hQNV6gtBHzJaRxxbFxWBpMwInnGy0cGIFj1FY4PhTR8TxnHUcBLHkEO44jp6Odrhz8Xw6W@VTJN6Cy20v1xqBvdtQEbQ012R8vG1H75OKLnXWGfyys5agG2h1WSjyf9Xmta/9DlQiR/WKe4K5GjYenusWPbew7zYxME50HyQ8 "Perl 5 – Try It Online"
#13: Post edited by user avatar jhnc‭ · 2026-03-06T23:07:31Z (6 months ago)
no need to split into x/y
  • # Perl, 229 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=map[/./g],/.{8}/g;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;(grep$_-$_%8,@_)||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$r=c($i>>3,$i%8);@s=();$c=1;$r+=c($I>>3,$I%8);exit$r-64'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input into 2d array
  • @g = map[/./g], /.{8}/g;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • (grep$_-$_%8,@_) # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c($i>>3, $i%8);
  • @s=(); $c=1; $r += c($I>>3, $I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit $r-64
  • '
  • ```
  • [Try it online!][TIO-mmfhc5bp]
  • [TIO-mmfhc5bp]: https://tio.run/##rVLbboJAEH3fr5isYyIBIpteQtyg9tFvMIZQXHRTBbKLiab210u5VKhRk1o6@7BzOXuYOUMq1OYp70GUKMiEzmAdqFhoTTDegAfhOkk5SZWMswhoX4M9Bmqhz/PpytsG6VynG5kNhwtrF6dB@EYHL67hVgiUnoyXYo@@RR3KcdaGjHKid68Qvm8PA9xbeDC8qc8HKyVS9G30@6419Y3jEfUc94s5HhamWUSrU2RjSCbOiJlh8dxkJUHlFo7Jatc@y9rM@CBkqr2BwTH0HA5XRiaovAIvx@MHC2XfNXjzgHFUZlmcVcVZWSSkB2IvM0BlPz9yuGGXH7KgEhRkrDMRLCGJKp5a5poNJkCjYKMFhRHQTO0EtaBYCc9zp6MVhCUfYR3txNOxna487H95WKlPpXxLVE577b5T6Ls7aoWuG2q1PxVb0GXm6sbOJmN/vJyLjhrCOmIVkp2fJt/gLv@hCsSY84vzg@6m1Ox7Vff0Uw/2maSZTGKd2/EX "Perl 5 – Try It Online"
  • # Perl, 154 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=/./g;sub c{my($i)=@_;$i<0||$i>63||$s[$i]++||$g[$i]-$c?0:1+c($i+8)+c($i+1)+c($i-8)+c($i-1)}$r=c index$_,0;@s=();$c=1;$r+=c index$_,1;exit$r-64'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input into array
  • @g = /./g];
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($i) = @_;
  • $i<0||$i>63 # bounds check
  • || $s[$i]++ # already visited?
  • || $g[$i]-$c # correct value?
  • ? 0
  • : 1 + c($i+8)+c($i+1)+c($i-8)+c($i-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c index$_,0;
  • @s=(); $c=1; $r += c index$_,1;
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit $r-64
  • '
  • ```
  • [Try it online!][TIO-mmfi7ljd]
  • [TIO-mmfi7ljd]: https://tio.run/##rZLvboIwFMW/9ylusEskwOzNNrPYob7HshjFok0ckLYmLnOvPgZUQYMmc6z9cPvn5Me5p2RCbZ7yHsSpAiO0gfVcJUJrQpMNhBCt04yTTMnExODcaQjG4Ph0xvPpKhzcD1ac6O0Cos/3jz6VbjidcSpf2H5P5Xj4UBT9SuWb5xWrVbkKaDRhI/SiQu09u7aircFhH6D7RchUh32X0yhkHC7YI1SFEchkKXZ05jNey5FT5Z1cISekB2InDVAVDB85XBntj/hQNV6gtBHzJaRxxbFxWBpMwInnGy0cGIFj1FY4PhTR8TxnHUcBLHkEO44jp6Odrhz8Xw6W@VTJN6Cy20v1xqBvdtQEbQ012R8vG1H75OKLnXWGfyys5agG2h1WSjyf9Xmta/9DlQiR/WKe4K5GjYenusWPbew7zYxME50HyQ8 "Perl 5 – Try It Online"
#12: Post edited by user avatar jhnc‭ · 2026-03-06T22:46:10Z (6 months ago)
bitshift avoids float>int conversion
  • # Perl, 233 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=map[/./g],/.{8}/g;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;(grep$_-$_%8,@_)||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$r=c(int$i/8,$i%8);@s=();$c=1;$r+=c(int$I/8,$I%8);exit$r-64'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input into 2d array
  • @g = map[/./g], /.{8}/g;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • (grep$_-$_%8,@_) # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c(int$i/8, $i%8);
  • @s=(); $c=1; $r += c(int$I/8, $I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit $r-64
  • '
  • ```
  • [Try it online!][TIO-mmfh2pw0]
  • [TIO-mmfh2pw0]: https://tio.run/##rVLbboJAEH3fr5isYwIBIpu0DXFDpY9@gzGE4qKbIpBdTDS1v17KpUqNmtTa2Yedy9nDzBkKodLHagBJrqAUuoRVpDKhNcEsBR/iVV5wUiiZlQnQoQbnGaiNIa@Cpb@OipkuUlmORnN7kxVR/EaNF8/0WgRKX2YLscXQpi7lOO1DRjnRm1eI39c7A7c27kw/CLmxVKLA0MFw6NlBaO73qGe4nc9wN7esOloeIgdjMnHHzIrr5xZrCFq3dizWuc5J1mHmByGB9g2TY@y7HC6MTFD5sVGPinLk2SiHnsmPTxhHZX2Xp0152pQJGYDYyhJQOU8PHK7Y@cdsaEUFmelSRAvIk5ank7pjgwnQJEq1oDAGWqqNoDbUa@FV5d5pNWHDR9idduC5s517edj/8rBGn1b5nqiZ9tJ9o9A3d9QL3TXUa38o9qDzzMWNnUzG/ni5Zx0dCbuItUh2eo75I@78H2pBjLm/OD/orkrNvld1Sz/dYJ95Uco805WTfQE "Perl 5 – Try It Online"
  • # Perl, 229 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=map[/./g],/.{8}/g;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;(grep$_-$_%8,@_)||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$r=c($i>>3,$i%8);@s=();$c=1;$r+=c($I>>3,$I%8);exit$r-64'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input into 2d array
  • @g = map[/./g], /.{8}/g;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • (grep$_-$_%8,@_) # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c($i>>3, $i%8);
  • @s=(); $c=1; $r += c($I>>3, $I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit $r-64
  • '
  • ```
  • [Try it online!][TIO-mmfhc5bp]
  • [TIO-mmfhc5bp]: https://tio.run/##rVLbboJAEH3fr5isYyIBIpteQtyg9tFvMIZQXHRTBbKLiab210u5VKhRk1o6@7BzOXuYOUMq1OYp70GUKMiEzmAdqFhoTTDegAfhOkk5SZWMswhoX4M9Bmqhz/PpytsG6VynG5kNhwtrF6dB@EYHL67hVgiUnoyXYo@@RR3KcdaGjHKid68Qvm8PA9xbeDC8qc8HKyVS9G30@6419Y3jEfUc94s5HhamWUSrU2RjSCbOiJlh8dxkJUHlFo7Jatc@y9rM@CBkqr2BwTH0HA5XRiaovAIvx@MHC2XfNXjzgHFUZlmcVcVZWSSkB2IvM0BlPz9yuGGXH7KgEhRkrDMRLCGJKp5a5poNJkCjYKMFhRHQTO0EtaBYCc9zp6MVhCUfYR3txNOxna487H95WKlPpXxLVE577b5T6Ls7aoWuG2q1PxVb0GXm6sbOJmN/vJyLjhrCOmIVkp2fJt/gLv@hCsSY84vzg@6m1Ox7Vff0Uw/2maSZTGKd2/EX "Perl 5 – Try It Online"
#11: Post edited by user avatar jhnc‭ · 2026-03-06T22:37:25Z (6 months ago)
negative exit seems to be okay (-1 --> 255, -2 --> 254, etc)
  • # Perl, 234 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=map[/./g],/.{8}/g;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;(grep$_-$_%8,@_)||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$r=c(int$i/8,$i%8);@s=();$c=1;$r+=c(int$I/8,$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input into 2d array
  • @g = map[/./g], /.{8}/g;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • (grep$_-$_%8,@_) # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c(int$i/8, $i%8);
  • @s=(); $c=1; $r += c(int$I/8, $I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
  • [Try it online!][TIO-mmfggg5z]
  • [TIO-mmfggg5z]: https://tio.run/##rVLbboJAEH3fr5isYwIBhE3axrih8uo3GEMsrkiiQHYx0ai/XsqlQg2a1NLZh53bHs6cIRVy@5oPYJ1IyITKYLOUsVCKYLwFF4JNknKSyijO1kCHCqx3oCb6PPdCd7dM5/bIDhemPTqNL3bIMXKjeCUO6JvUoRxnbcgoV/sPEpx2Rw0PJh511/O5FkqRom@hPxybnq@fz6jmeFjM8bgwjCIKr5GFAZk6E2YExXODlQCVWzgGq13rJmsx/UKIp1xN5xi4Doc7UxKUbqAV02Fkj02MhmOdN08YR2l8l2dleVaWCRmAOEQZvL1YKDk8sO7HTKh0hChWmViuIFlXOLW6NRpMga6XWyUoTIBmci@oCcUmeJ47Pa0ALPEI62lXnJ50@uKw/8VhpT6V8i1QOe29@0mhn2bUCl0TarW/Ftumbubuxm4mY3@8nA6jBrCOWNXJbk@Tb/q6/1DVxJjzi/MD7qHU7HtVz/CpB/tM0ixKYpVb8Rc "Perl 5 – Try It Online"
  • # Perl, 233 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=map[/./g],/.{8}/g;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;(grep$_-$_%8,@_)||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$r=c(int$i/8,$i%8);@s=();$c=1;$r+=c(int$I/8,$I%8);exit$r-64'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input into 2d array
  • @g = map[/./g], /.{8}/g;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • (grep$_-$_%8,@_) # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c(int$i/8, $i%8);
  • @s=(); $c=1; $r += c(int$I/8, $I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit $r-64
  • '
  • ```
  • [Try it online!][TIO-mmfh2pw0]
  • [TIO-mmfh2pw0]: https://tio.run/##rVLbboJAEH3fr5isYwIBIpu0DXFDpY9@gzGE4qKbIpBdTDS1v17KpUqNmtTa2Yedy9nDzBkKodLHagBJrqAUuoRVpDKhNcEsBR/iVV5wUiiZlQnQoQbnGaiNIa@Cpb@OipkuUlmORnN7kxVR/EaNF8/0WgRKX2YLscXQpi7lOO1DRjnRm1eI39c7A7c27kw/CLmxVKLA0MFw6NlBaO73qGe4nc9wN7esOloeIgdjMnHHzIrr5xZrCFq3dizWuc5J1mHmByGB9g2TY@y7HC6MTFD5sVGPinLk2SiHnsmPTxhHZX2Xp0152pQJGYDYyhJQOU8PHK7Y@cdsaEUFmelSRAvIk5ank7pjgwnQJEq1oDAGWqqNoDbUa@FV5d5pNWHDR9idduC5s517edj/8rBGn1b5nqiZ9tJ9o9A3d9QL3TXUa38o9qDzzMWNnUzG/ni5Zx0dCbuItUh2eo75I@78H2pBjLm/OD/orkrNvld1Sz/dYJ95Uco805WTfQE "Perl 5 – Try It Online"
#10: Post edited by user avatar jhnc‭ · 2026-03-06T22:18:35Z (6 months ago)
shorter array load
  • # Perl, 246 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=map[split//],unpack"(A8)8",$_;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;(grep$_-$_%8,@_)||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$r=c(int$i/8,$i%8);@s=();$c=1;$r+=c(int$I/8,$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input into 2d array
  • @g = map[split//], unpack"(A8)8", $_;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • (grep$_-$_%8,@_) # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c(int$i/8, $i%8);
  • @s=(); $c=1; $r += c(int$I/8, $I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
  • [Try it online!][TIO-mmfg3y6l]
  • [Perl 5]: https://www.perl.org/
  • [TIO-mmfg3y6l]: https://tio.run/##rVLbboJAEH3fr5isYwIBIpu0DXFDpY9@gzGE4qKbIpBdTDS1v17KpUqNmtTa2Yedy9nDzBkKodLHagBJrqAUuoRVpDKhNcEsBR/iVV5wUiiZlQnQoQbnGaiNIa@Cpb@OipkuUlmORnN7kxVR/EaNF8/0WgRKX2YLscXQpi7lOO1DRjnRm1eI39c7A7c27kw/CLmxVKLA0MFw6NlBaO73qGe4nc9wN7esOloeIgdjMnHHzIrr5xZrCFq3dizWuc5J1mHmByGB9g2TY@y7HC6MTFD5sVGPinLk2SiHnsmPTxhHZX2Xp0152pQJGYDYyhKeHhxUHK7Y@cdsaEUFmelSRAvIk5ank7pjgwnQJEq1oDAGWqqNoDbUa@FV5d5pNWHDR9idduC5s517edj/8rBGn1b5nqiZ9tJ9o9A3d9QL3TXUa38o9qDzzMWNnUzG/ni5Zx0dCbuItUh2eo75I@78H2pBjLm/OD/orkrNvld1Sz/dYJ95Uco805WTfQE "Perl 5 – Try It Online"
  • # Perl, 234 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=map[/./g],/.{8}/g;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;(grep$_-$_%8,@_)||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$r=c(int$i/8,$i%8);@s=();$c=1;$r+=c(int$I/8,$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input into 2d array
  • @g = map[/./g], /.{8}/g;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • (grep$_-$_%8,@_) # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c(int$i/8, $i%8);
  • @s=(); $c=1; $r += c(int$I/8, $I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
  • [Try it online!][TIO-mmfggg5z]
  • [TIO-mmfggg5z]: https://tio.run/##rVLbboJAEH3fr5isYwIBhE3axrih8uo3GEMsrkiiQHYx0ai/XsqlQg2a1NLZh53bHs6cIRVy@5oPYJ1IyITKYLOUsVCKYLwFF4JNknKSyijO1kCHCqx3oCb6PPdCd7dM5/bIDhemPTqNL3bIMXKjeCUO6JvUoRxnbcgoV/sPEpx2Rw0PJh511/O5FkqRom@hPxybnq@fz6jmeFjM8bgwjCIKr5GFAZk6E2YExXODlQCVWzgGq13rJmsx/UKIp1xN5xi4Doc7UxKUbqAV02Fkj02MhmOdN08YR2l8l2dleVaWCRmAOEQZvL1YKDk8sO7HTKh0hChWmViuIFlXOLW6NRpMga6XWyUoTIBmci@oCcUmeJ47Pa0ALPEI62lXnJ50@uKw/8VhpT6V8i1QOe29@0mhn2bUCl0TarW/Ftumbubuxm4mY3@8nA6jBrCOWNXJbk@Tb/q6/1DVxJjzi/MD7qHU7HtVz/CpB/tM0ixKYpVb8Rc "Perl 5 – Try It Online"
#9: Post edited by user avatar jhnc‭ · 2026-03-06T22:08:53Z (6 months ago)
  • # Perl, 246 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=map[split//],unpack"(A8)8",$_;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;(grep$_-$_%8,@_)||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$r=c(int$i/8,$i%8);@s=();$c=1;$r+=c(int$I/8,$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input into 2d array
  • @g = map[split//], unpack"(A8)8", $_;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • (grep$_-$_%8,@_) # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c(int$i/8, $i%8);
  • @s=(); $c=1; $r += c(int$I/8, $I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
  • [Try it online!][TIO-mmfflylp]
  • [TIO-mmfflylp]: https://tio.run/##rVLbboJAEH3fr5isYwIBIpu0DXFDpY9@gzGE4qKbIpBdTDS1v17KpUqNmtTa2Yedy9nDzBkKodLHagBJrqAUuoRVpDKhNcEsBR/iVV5wUiiZlQnQoQbnGaiNIa@Cpb@OipkuUlmORnN7kxVR/EaNF8/0WgRKX2YLscXQpi7lOO1DRjnRm1eI39c7A7c27kw/CLmxVKLA0MFw6NlBaO73qGe4nc9wN7esOloeIgdjMnHHzIrr5xZrCFq3dizWuc5J1mHmByGB9g2TY@y7HC6MTFD5sVGPinLk2SiHnsmPTxhHZX2Xp0152pQJGYDYyhKeHhxUHK7Y@cdsaEUFmelSRAvIk5ank7pjgwnQJEq1oDAGWqqNoDbUa@FV5d5pNWHDR9idduC5s517edj/8rBGn1b5nqiZ9tJ9o9A3d9QL3TXUa38o9qDzzMWNnUzG/ni5Zx0dCbuItUh2eo75I@78H2pBjLm/OD/orkrNvld1Sz/tYJ95Uco805WTfQE "Perl 5 – Try It Online"
  • # Perl, 246 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=map[split//],unpack"(A8)8",$_;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;(grep$_-$_%8,@_)||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$r=c(int$i/8,$i%8);@s=();$c=1;$r+=c(int$I/8,$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input into 2d array
  • @g = map[split//], unpack"(A8)8", $_;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • (grep$_-$_%8,@_) # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c(int$i/8, $i%8);
  • @s=(); $c=1; $r += c(int$I/8, $I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
  • [Try it online!][TIO-mmfg3y6l]
  • [Perl 5]: https://www.perl.org/
  • [TIO-mmfg3y6l]: https://tio.run/##rVLbboJAEH3fr5isYwIBIpu0DXFDpY9@gzGE4qKbIpBdTDS1v17KpUqNmtTa2Yedy9nDzBkKodLHagBJrqAUuoRVpDKhNcEsBR/iVV5wUiiZlQnQoQbnGaiNIa@Cpb@OipkuUlmORnN7kxVR/EaNF8/0WgRKX2YLscXQpi7lOO1DRjnRm1eI39c7A7c27kw/CLmxVKLA0MFw6NlBaO73qGe4nc9wN7esOloeIgdjMnHHzIrr5xZrCFq3dizWuc5J1mHmByGB9g2TY@y7HC6MTFD5sVGPinLk2SiHnsmPTxhHZX2Xp0152pQJGYDYyhKeHhxUHK7Y@cdsaEUFmelSRAvIk5ank7pjgwnQJEq1oDAGWqqNoDbUa@FV5d5pNWHDR9idduC5s517edj/8rBGn1b5nqiZ9tJ9o9A3d9QL3TXUa38o9qDzzMWNnUzG/ni5Zx0dCbuItUh2eo75I@78H2pBjLm/OD/orkrNvld1Sz/dYJ95Uco805WTfQE "Perl 5 – Try It Online"
#8: Post edited by user avatar jhnc‭ · 2026-03-06T22:02:18Z (6 months ago)
shorter bounds check
  • Perl, 252 bytes
  • ---
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=map[split//],unpack"(A8)8",$_;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;$x<0||$x>7||$y<0||$y>7||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$r=c(int$i/8,$i%8);@s=();$c=1;$r+=c(int$I/8,$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input into array
  • @g = map[split//], unpack"(A8)8", $_;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • $x<0||$x>7||$y<0||$y>7 # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c(int $i/8, $i%8);
  • @s=(); $c=1; $r += c(int $I/8, $I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
  • [Try it online!][TIO-mmfecw3b]
  • [TIO-mmfecw3b]: https://tio.run/##rZJtb4IwEMff91Nc6plIgEiTPRg71L30MxhjGKI2UyAtJpC5rz4GRWEGTeZcm9C73vXH3b@NA7l9zDuwiiQkgUpg48kwUIpguAUX/E0UcxJLESYroF0F9giohQueT9buzotnKt6KpN@fW/sw9vx32nsdGAOdgcIV4TJIcWFRh3KcNi6jXO3fiP@xy3qYWpgZ7qQ4kL44hwOmo@fim2k707aaYTqfYTY3zcJbnzwbfTJ2hsz0C4jJSow2C8NklWmf7drM@CRkotyewdF3HQ4X@iYoXb9X9IuiP7BQdAcGr48wjtI8hqdleFqGCelAkIoEnh5slByujPbPLNDKgghVEnhLiFaaU@ld0WAMdOVtVUBhCDSR@4BaUNwNz3PnzlEASx5hd44T585y7uWw/@WwUh@tfAMqu7203ij0zRU1QlcFNdqfgk1Se@fijZ11xv64OK2KamDlMZ3Jzme9X@e135BOYsz5xfyBuyo1O17VLfXoxr6iOBFRqHI7/AY "Perl 5 – Try It Online"
  • # Perl, 246 bytes
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=map[split//],unpack"(A8)8",$_;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;(grep$_-$_%8,@_)||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$r=c(int$i/8,$i%8);@s=();$c=1;$r+=c(int$I/8,$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input into 2d array
  • @g = map[split//], unpack"(A8)8", $_;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • (grep$_-$_%8,@_) # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c(int$i/8, $i%8);
  • @s=(); $c=1; $r += c(int$I/8, $I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
  • [Try it online!][TIO-mmfflylp]
  • [TIO-mmfflylp]: https://tio.run/##rVLbboJAEH3fr5isYwIBIpu0DXFDpY9@gzGE4qKbIpBdTDS1v17KpUqNmtTa2Yedy9nDzBkKodLHagBJrqAUuoRVpDKhNcEsBR/iVV5wUiiZlQnQoQbnGaiNIa@Cpb@OipkuUlmORnN7kxVR/EaNF8/0WgRKX2YLscXQpi7lOO1DRjnRm1eI39c7A7c27kw/CLmxVKLA0MFw6NlBaO73qGe4nc9wN7esOloeIgdjMnHHzIrr5xZrCFq3dizWuc5J1mHmByGB9g2TY@y7HC6MTFD5sVGPinLk2SiHnsmPTxhHZX2Xp0152pQJGYDYyhKeHhxUHK7Y@cdsaEUFmelSRAvIk5ank7pjgwnQJEq1oDAGWqqNoDbUa@FV5d5pNWHDR9idduC5s517edj/8rBGn1b5nqiZ9tJ9o9A3d9QL3TXUa38o9qDzzMWNnUzG/ni5Zx0dCbuItUh2eo75I@78H2pBjLm/OD/orkrNvld1Sz/tYJ95Uco805WTfQE "Perl 5 – Try It Online"
#7: Post edited by user avatar jhnc‭ · 2026-03-06T21:20:31Z (6 months ago)
link to test harness version
  • Perl, 252 bytes
  • ---
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -pE'@g=map[split//],unpack"(A8)8",$_;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;$x<0||$x>7||$y<0||$y>7||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$r=c(int$i/8,$i%8);@s=();$c=1;$r+=c(int$I/8,$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```perl
  • perl -pE'
  • # load input into array
  • @g = map[split//], unpack"(A8)8", $_;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • $x<0||$x>7||$y<0||$y>7 # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c(int $i/8, $i%8);
  • @s=(); $c=1; $r += c(int $I/8, $I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
  • Perl, 252 bytes
  • ---
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -ne'@g=map[split//],unpack"(A8)8",$_;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;$x<0||$x>7||$y<0||$y>7||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$r=c(int$i/8,$i%8);@s=();$c=1;$r+=c(int$I/8,$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```perl
  • perl -ne'
  • # load input into array
  • @g = map[split//], unpack"(A8)8", $_;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • $x<0||$x>7||$y<0||$y>7 # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c(int $i/8, $i%8);
  • @s=(); $c=1; $r += c(int $I/8, $I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
  • [Try it online!][TIO-mmfecw3b]
  • [TIO-mmfecw3b]: https://tio.run/##rZJtb4IwEMff91Nc6plIgEiTPRg71L30MxhjGKI2UyAtJpC5rz4GRWEGTeZcm9C73vXH3b@NA7l9zDuwiiQkgUpg48kwUIpguAUX/E0UcxJLESYroF0F9giohQueT9buzotnKt6KpN@fW/sw9vx32nsdGAOdgcIV4TJIcWFRh3KcNi6jXO3fiP@xy3qYWpgZ7qQ4kL44hwOmo@fim2k707aaYTqfYTY3zcJbnzwbfTJ2hsz0C4jJSow2C8NklWmf7drM@CRkotyewdF3HQ4X@iYoXb9X9IuiP7BQdAcGr48wjtI8hqdleFqGCelAkIoEnh5slByujPbPLNDKgghVEnhLiFaaU@ld0WAMdOVtVUBhCDSR@4BaUNwNz3PnzlEASx5hd44T585y7uWw/@WwUh@tfAMqu7203ij0zRU1QlcFNdqfgk1Se@fijZ11xv64OK2KamDlMZ3Jzme9X@e135BOYsz5xfyBuyo1O17VLfXoxr6iOBFRqHI7/AY "Perl 5 – Try It Online"
#6: Post edited by user avatar jhnc‭ · 2026-03-06T20:16:22Z (6 months ago)
int has lower precedence than /
  • Perl, 256 bytes
  • ---
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -pE'@g=map[split//],unpack"(A8)8",$_;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;$x<0||$x>7||$y<0||$y>7||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$r=c(int($i/8),$i%8);@s=();$c=1;$r+=c(int($I/8),$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```perl
  • perl -pE'
  • # load input into array
  • @g = map[split//], unpack"(A8)8", $_;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • $x<0||$x>7||$y<0||$y>7 # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c(int($i/8),$i%8);
  • @s=(); $c=1; $r += c(int($I/8),$I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
  • Perl, 252 bytes
  • ---
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -pE'@g=map[split//],unpack"(A8)8",$_;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;$x<0||$x>7||$y<0||$y>7||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$r=c(int$i/8,$i%8);@s=();$c=1;$r+=c(int$I/8,$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```perl
  • perl -pE'
  • # load input into array
  • @g = map[split//], unpack"(A8)8", $_;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • $x<0||$x>7||$y<0||$y>7 # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c(int $i/8, $i%8);
  • @s=(); $c=1; $r += c(int $I/8, $I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
#5: Post edited by user avatar jhnc‭ · 2026-03-06T20:12:00Z (6 months ago)
undefined $c is 0 when used in arithmetic
  • Perl, 261 bytes
  • ---
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -pE'@g=map[split//],unpack"(A8)8",$_;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;$x<0||$x>7||$y<0||$y>7||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$c=0;$r=c(int($i/8),$i%8);@s=();$c=1;$r+=c(int($I/8),$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```perl
  • perl -pE'
  • # load input into array
  • @g = map[split//], unpack"(A8)8", $_;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • $x<0||$x>7||$y<0||$y>7 # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $c=0; $r = c(int($i/8),$i%8);
  • @s=(); $c=1; $r += c(int($I/8),$I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
  • Perl, 256 bytes
  • ---
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -pE'@g=map[split//],unpack"(A8)8",$_;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;$x<0||$x>7||$y<0||$y>7||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$r=c(int($i/8),$i%8);@s=();$c=1;$r+=c(int($I/8),$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```perl
  • perl -pE'
  • # load input into array
  • @g = map[split//], unpack"(A8)8", $_;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • $x<0||$x>7||$y<0||$y>7 # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $r = c(int($i/8),$i%8);
  • @s=(); $c=1; $r += c(int($I/8),$I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
#4: Post edited by user avatar jhnc‭ · 2026-03-06T20:06:09Z (6 months ago)
  • Perl, 261 bytes
  • ---
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -pE'@g=map[split//],unpack"(A8)8",$_;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;$x<0||$x>7||$y<0||$y>7||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$c=0;$r=c(int($i/8),$i%8);@s=();$c=1;$r+=c(int($I/8),$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```perl
  • perl -pE'
  • # load input into array
  • @g = map[split//], unpack"(A8)8", $_;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • $x<0||$x>7||$y<0||$y>7 # bounds check
  • || $s[$x][$y]++ || # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $c=0; $r = c(int($i/8),$i%8);
  • @s=(); $c=1; $r += c(int($I/8),$I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
  • Perl, 261 bytes
  • ---
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -pE'@g=map[split//],unpack"(A8)8",$_;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;$x<0||$x>7||$y<0||$y>7||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$c=0;$r=c(int($i/8),$i%8);@s=();$c=1;$r+=c(int($I/8),$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```perl
  • perl -pE'
  • # load input into array
  • @g = map[split//], unpack"(A8)8", $_;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • $x<0||$x>7||$y<0||$y>7 # bounds check
  • || $s[$x][$y]++ # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $c=0; $r = c(int($i/8),$i%8);
  • @s=(); $c=1; $r += c(int($I/8),$I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
#3: Post edited by user avatar jhnc‭ · 2026-03-06T20:04:56Z (6 months ago)
  • Perl, 263 bytes
  • ---
  • Takes input as 64 character string of 1s and 0s.
  • ```
  • perl -E'@g=map[split//],unpack"(A8)8",$_=<>;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;$x<0||$x>7||$y<0||$y>7||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$c=0;$r=c(int($i/8),$i%8);@s=();$c=1;$r+=c(int($I/8),$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```
  • perl -E'
  • # load input into array
  • @g = map[split//], unpack"(A8)8", $_=<>;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • $x<0||$x>7||$y<0||$y>7 # bounds check
  • || $s[$x][$y]++ || # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $c=0; $r = c(int($i/8),$i%8);
  • @s=(); $c=1; $r += c(int($I/8),$I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
  • Perl, 261 bytes
  • ---
  • Pass 64 character string of 1s and 0s on stdin.
  • Zero exit means success; non-zero means failure.
  • ```perl
  • perl -pE'@g=map[split//],unpack"(A8)8",$_;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;$x<0||$x>7||$y<0||$y>7||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$c=0;$r=c(int($i/8),$i%8);@s=();$c=1;$r+=c(int($I/8),$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```perl
  • perl -pE'
  • # load input into array
  • @g = map[split//], unpack"(A8)8", $_;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • $x<0||$x>7||$y<0||$y>7 # bounds check
  • || $s[$x][$y]++ || # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $c=0; $r = c(int($i/8),$i%8);
  • @s=(); $c=1; $r += c(int($I/8),$I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
#2: Post edited by user avatar jhnc‭ · 2026-03-06T19:55:55Z (6 months ago)
  • Perl, 263 bytes
  • Takes input as 64 character string of 1s and 0s.
  • ```
  • perl -E'@g=map[split//],unpack"(A8)8",$_=<>;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;$x<0||$x>7||$y<0||$y>7||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$c=0;$r=c(int($i/8),$i%8);@s=();$c=1;$r+=c(int($I/8),$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```
  • perl -E'
  • # load input into array
  • @g = map[split//], unpack"(A8)8", $_=<>;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • $x<0||$x>7||$y<0||$y>7 # bounds check
  • || $s[$x][$y]++ || # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $c=0; $r = c(int($i/8),$i%8);
  • @s=(); $c=1; $r += c(int($I/8),$I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
  • Perl, 263 bytes
  • ---
  • Takes input as 64 character string of 1s and 0s.
  • ```
  • perl -E'@g=map[split//],unpack"(A8)8",$_=<>;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;$x<0||$x>7||$y<0||$y>7||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$c=0;$r=c(int($i/8),$i%8);@s=();$c=1;$r+=c(int($I/8),$I%8);exit 64-$r'
  • ```
  • Comments:
  • ```
  • perl -E'
  • # load input into array
  • @g = map[split//], unpack"(A8)8", $_=<>;
  • # locate first 0 and 1
  • $i = index$_,"0";
  • $I = index$_,"1";
  • # recursive connectivity search
  • # returns count of connected elements
  • sub c{
  • my ($x,$y) = @_;
  • $x<0||$x>7||$y<0||$y>7 # bounds check
  • || $s[$x][$y]++ || # already visited?
  • || $g[$x][$y]-$c # correct value?
  • ? 0
  • : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1) # recurse
  • }
  • # count connected 0s/1s
  • $c=0; $r = c(int($i/8),$i%8);
  • @s=(); $c=1; $r += c(int($I/8),$I%8);
  • # sum of connected 0s and 1s should total 64 for success
  • # non-zero exit code means failure
  • exit 64-$r
  • '
  • ```
#1: Initial revision by user avatar jhnc‭ · 2026-03-06T19:55:28Z (6 months ago)
Perl, 263 bytes

Takes input as 64 character string of 1s and 0s.

```
perl -E'@g=map[split//],unpack"(A8)8",$_=<>;$i=index$_,"0";$I=index$_,"1";sub c{my($x,$y)=@_;$x<0||$x>7||$y<0||$y>7||$s[$x][$y]++||$g[$x][$y]-$c?0:1+c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)}$c=0;$r=c(int($i/8),$i%8);@s=();$c=1;$r+=c(int($I/8),$I%8);exit 64-$r'
```

Comments:

```
perl -E'
    # load input into array
    @g = map[split//], unpack"(A8)8", $_=<>;

    # locate first 0 and 1
    $i = index$_,"0";
    $I = index$_,"1";

    # recursive connectivity search
    # returns count of connected elements
    sub c{
        my ($x,$y) = @_;

        $x<0||$x>7||$y<0||$y>7  # bounds check
        || $s[$x][$y]++ ||      # already visited?
        || $g[$x][$y]-$c        # correct value?
        ? 0
        : 1 + c($x+1,$y)+c($x,$y+1)+c($x-1,$y)+c($x,$y-1)  # recurse
    }

    # count connected 0s/1s
           $c=0; $r  = c(int($i/8),$i%8);
    @s=(); $c=1; $r += c(int($I/8),$I%8);

    # sum of connected 0s and 1s should total 64 for success
    # non-zero exit code means failure
    exit 64-$r
'
```