How to resolve the algorithm Rep-string step by step in the PL/I programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Rep-string step by step in the PL/I programming language

Table of Contents

Problem Statement

Given a series of ones and zeroes in a string, define a repeated string or rep-string as a string which is created by repeating a substring of the first N characters of the string truncated on the right to the length of the input string, and in which the substring appears repeated at least twice in the original. For example, the string 10011001100 is a rep-string as the leftmost four characters of 1001 are repeated three times and truncated on the right to give the original string. Note that the requirement for having the repeat occur two or more times means that the repeating unit is never longer than half the length of the input string.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Rep-string step by step in the PL/I programming language

Source code in the pl/i programming language

rep: procedure options (main); /* 5 May 2015 */
   declare s bit (10) varying;
   declare (i, k) fixed binary;

main_loop:
   do s = '1001110011'b, '1110111011'b, '0010010010'b, '1010101010'b,
          '1111111111'b, '0100101101'b, '0100100'b, '101'b, '11'b, '00'b, '1'b;
      k = length(s);
      do i = k/2 to 1 by -1;
         if substr(s, 1, i) = substr(s, i+1, i) then
            do;
               put skip edit (s, ' is a rep-string containing ', substr(s, 1, i) ) (a);
               iterate main_loop;
            end;
      end;
      put skip edit (s, ' is not a rep-string') (a);
   end;

end rep;

  

You may also check:How to resolve the algorithm Smarandache-Wellin primes step by step in the RPL programming language
You may also check:How to resolve the algorithm Hilbert curve step by step in the Python programming language
You may also check:How to resolve the algorithm String comparison step by step in the Oforth programming language
You may also check:How to resolve the algorithm Cantor set step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Literals/String step by step in the Oz programming language