How to resolve the algorithm Longest common substring step by step in the PicoLisp programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Longest common substring step by step in the PicoLisp 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 PicoLisp programming language
Source code in the picolisp programming language
(de longestCommonSubstring (Str1 Str2)
(setq Str1 (chop Str1) Str2 (chop Str2))
(let Res NIL
(map
'((Lst1)
(map
'((Lst2)
(let Len 0
(find
'((A B) (nand (= A B) (inc 'Len)))
Lst1
Lst2 )
(when (> Len (length Res))
(setq Res (head Len Lst1)) ) ) )
Str2 ) )
Str1 )
(pack Res) ) )
: (longestCommonSubstring "thisisatest" "testing123testing")
-> "test"
You may also check:How to resolve the algorithm Parsing/RPN calculator algorithm step by step in the C# programming language
You may also check:How to resolve the algorithm Call an object method step by step in the Apex programming language
You may also check:How to resolve the algorithm Sierpinski arrowhead curve step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Long multiplication step by step in the Perl programming language
You may also check:How to resolve the algorithm Sum of squares step by step in the Clojure programming language