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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Longest common substring step by step in the zkl 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 zkl programming language

Source code in the zkl programming language

fcn lcd(a,b){
   if(b.len()
   foreach n,m in ([a.len()..1,-1],a.len()-n+1){
      s:=a[m,n];
      if(b.holds(s)) return(s);
   }
   ""
}

lcd("testing123testing","thisisatest").println();

  

You may also check:How to resolve the algorithm Integer sequence step by step in the Fortran programming language
You may also check:How to resolve the algorithm Top rank per group step by step in the Picat programming language
You may also check:How to resolve the algorithm Parse an IP Address step by step in the Perl programming language
You may also check:How to resolve the algorithm Program name step by step in the F# programming language
You may also check:How to resolve the algorithm File size step by step in the 8086 Assembly programming language