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

Published on 12 May 2024 09:40 PM

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

Source code in the applesoft programming language

 0 A$ = "thisisatest":B$ = "testing123testing": GOSUB 100"LONGEST COMMON SUBSTRING": PRINT R$;: END 
 100  LET R$ = ""
 110  LET A =  LEN (A$)
 120  LET B =  LEN (B$)
 130  IF A = 0 OR B = 0 THEN  RETURN
 140  FOR B = B TO 1 STEP  - 1
 150      FOR J = B TO 1 STEP  - 1
 160          FOR K = 1 TO A
 170              IF  MID$ (A$,K,J) <  >  LEFT$ (B$,J) THEN  NEXT K
 180          LET R$ =  LEFT$ (B$,J)
 190          IF A > K THEN  RETURN
 200      NEXT J
 210      LET B$ =  MID$ (B$,2)
 220  NEXT B
 230  LET R$ = ""
 240  RETURN

  

You may also check:How to resolve the algorithm Compare a list of strings step by step in the Fortran programming language
You may also check:How to resolve the algorithm MD5 step by step in the AArch64 Assembly programming language
You may also check:How to resolve the algorithm Variable size/Set step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Draw a cuboid step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm AVL tree step by step in the Nim programming language