How to resolve the algorithm Longest common substring step by step in the 11l programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Longest common substring step by step in the 11l programming language

Table of Contents

Problem Statement

Write a function that returns the longest common substring of two strings. Use it within a program that demonstrates sample output from the function, which will consist of the longest common substring between "thisisatest" and "testing123testing". Note that substrings are consecutive characters within a string.   This distinguishes them from subsequences, which is any sequence of characters within a string, even if there are extraneous characters in between them. Hence, the longest common subsequence between "thisisatest" and "testing123testing" is "tsitest", whereas the longest common substring is just "test".

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Longest common substring step by step in the 11l programming language

Source code in the 11l programming language

F longest_common_substring(s1, s2)
   V ir = 0
   V jr = -1
   L(i1) 0 .< s1.len
      V? i2 = s2.find(s1[i1])
      L i2 != N
         V (j1, j2) = (i1, i2)
         L j1 < s1.len & j2 < s2.len & s2[j2] == s1[j1]
            I j1 - i1 >= jr - ir
               (ir, jr) = (i1, j1)
            j1++
            j2++
         i2 = s2.find(s1[i1], i2 + 1)
   R s1[ir..jr]

print(longest_common_substring(‘thisisatest’, ‘testing123testing’))

  

You may also check:How to resolve the algorithm Pythagorean triples step by step in the Modula-3 programming language
You may also check:How to resolve the algorithm Hello world/Standard error step by step in the Phix programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the NS-HUBASIC programming language
You may also check:How to resolve the algorithm Stirling numbers of the second kind step by step in the Prolog programming language
You may also check:How to resolve the algorithm Gamma function step by step in the Scala programming language