|
|
Line 2,137: |
Line 2,137: |
|
1 |
|
1 |
|
(no repeat)</pre> |
|
(no repeat)</pre> |
|
|
|
⚫ |
|
|
⚫ |
<lang perl6>for <1001110011 1110111011 0010010010 1010101010 1111111111 0100101101 0100100 101 11 00 1> { |
|
⚫ |
if /^ (.+) $0+: (.*$) <?{ $0.substr(0,$1.chars) eq $1 }> / { |
|
⚫ |
|
|
⚫ |
say .substr(0,$rep), .substr($rep,$rep).trans('01' => '𝟘𝟙'), .substr($rep*2); |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
Here's a technique that relies on the fact that XORing the shifted binary number |
|
⚫ |
should set all the lower bits to 0 if there are repeats. |
|
⚫ |
(The cool thing is that shift will automatically |
|
⚫ |
throw away the bits on the right that you want thrown away.) |
|
⚫ |
This produces the same output as above. |
|
⚫ |
<lang perl6>sub repstr(Str $s) { |
|
⚫ |
|
|
⚫ |
for reverse 1 .. $s.chars div 2 -> $left { |
|
⚫ |
my $right = $s.chars - $left; |
|
⚫ |
return $left if $bits +^ ($bits +> $left) == $bits +> $right +< $right; |
|
⚫ |
|
|
⚫ |
|
|
|
|
|
|
|
|
⚫ |
for '1001110011 1110111011 0010010010 1010101010 1111111111 0100101101 0100100 101 11 00 1'.words { |
|
⚫ |
|
|
⚫ |
say .substr(0,$rep), .substr($rep,$rep).trans('01' => '𝟘𝟙'), .substr($rep*2); |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
|
|
|
|
|
=={{header|Phix}}== |
|
=={{header|Phix}}== |
Line 2,689: |
Line 2,644: |
|
00 => 0 |
|
00 => 0 |
|
1 => not a rep-string</pre> |
|
1 => not a rep-string</pre> |
|
|
|
|
⚫ |
|
|
|
(formerly Perl 6) |
|
⚫ |
<lang perl6>for <1001110011 1110111011 0010010010 1010101010 1111111111 0100101101 0100100 101 11 00 1> { |
|
⚫ |
if /^ (.+) $0+: (.*$) <?{ $0.substr(0,$1.chars) eq $1 }> / { |
|
⚫ |
|
|
⚫ |
say .substr(0,$rep), .substr($rep,$rep).trans('01' => '𝟘𝟙'), .substr($rep*2); |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
Here's a technique that relies on the fact that XORing the shifted binary number |
|
⚫ |
should set all the lower bits to 0 if there are repeats. |
|
⚫ |
(The cool thing is that shift will automatically |
|
⚫ |
throw away the bits on the right that you want thrown away.) |
|
⚫ |
This produces the same output as above. |
|
⚫ |
<lang perl6>sub repstr(Str $s) { |
|
⚫ |
|
|
⚫ |
for reverse 1 .. $s.chars div 2 -> $left { |
|
⚫ |
my $right = $s.chars - $left; |
|
⚫ |
return $left if $bits +^ ($bits +> $left) == $bits +> $right +< $right; |
|
⚫ |
|
|
⚫ |
|
|
|
|
|
|
|
|
⚫ |
for '1001110011 1110111011 0010010010 1010101010 1111111111 0100101101 0100100 101 11 00 1'.words { |
|
⚫ |
|
|
⚫ |
say .substr(0,$rep), .substr($rep,$rep).trans('01' => '𝟘𝟙'), .substr($rep*2); |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
|
|
|
|
=={{header|REXX}}== |
|
=={{header|REXX}}== |