How to resolve the algorithm Rep-string step by step in the BQN programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Rep-string step by step in the BQN 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 BQN programming language

Source code in the bqn programming language

# Returns a list of all rep-strings
Reps(÷2˙)((¨)/)(<¨¨1)/1

# Tests
tests 
   "1001110011", "1110111011", "0010010010",
   "1010101010", "1111111111", "0100101101",
   "0100100", "101", "11", "00", "1"


´{ 𝕩':'(•Fmt Reps 𝕩)@+10 }¨tests


  

You may also check:How to resolve the algorithm Wilson primes of order n step by step in the REXX programming language
You may also check:How to resolve the algorithm Range extraction step by step in the Groovy programming language
You may also check:How to resolve the algorithm Abelian sandpile model step by step in the Haskell programming language
You may also check:How to resolve the algorithm Taxicab numbers step by step in the Delphi programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the VTL-2 programming language