How to resolve the algorithm Rep-string step by step in the BaCon programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Rep-string step by step in the BaCon 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 BaCon programming language
Source code in the bacon programming language
all$ = "1001110011 1110111011 0010010010 1010101010 1111111111 0100101101 0100100 101 11 00 1"
FOR word$ IN all$
FOR x = LEN(word$)/2 DOWNTO 1
ex$ = EXPLODE$(word$, x)
FOR st$ IN UNIQ$(ex$)
IF NOT(REGEX(HEAD$(ex$, 1), "^" & st$)) THEN CONTINUE 2
NEXT
PRINT "Repeating string: ", word$, " -> ", HEAD$(ex$, 1)
CONTINUE 2
NEXT
PRINT "Not a repeating string: ", word$
NEXT
You may also check:How to resolve the algorithm Doomsday rule step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm Letter frequency step by step in the Maple programming language
You may also check:How to resolve the algorithm Short-circuit evaluation step by step in the Factor programming language
You may also check:How to resolve the algorithm Runtime evaluation step by step in the Groovy programming language
You may also check:How to resolve the algorithm Cumulative standard deviation step by step in the Ring programming language