How to resolve the algorithm Search a list step by step in the TUSCRIPT programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Search a list step by step in the TUSCRIPT programming language
Table of Contents
Problem Statement
Find the index of a string (needle) in an indexable, ordered collection of strings (haystack). Raise an exception if the needle is missing. If there is more than one occurrence then return the smallest index to the needle. Return the largest index to a needle that has multiple occurrences in the haystack.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Search a list step by step in the TUSCRIPT programming language
Source code in the tuscript programming language
$$ MODE TUSCRIPT
SET haystack="Zig'Zag'Wally'Ronald'Bush'Krusty'Charlie'Bush'Bozo"
PRINT "haystack=",haystack
LOOP needle="Washington'Bush'Wally"
SET table =QUOTES (needle)
BUILD S_TABLE needle = table
IF (haystack.ct.needle) THEN
BUILD R_TABLE needle = table
SET position=FILTER_INDEX(haystack,needle,-)
RELEASE R_TABLE needle
PRINT "haystack contains ", needle, " on position(s): ",position
ELSE
PRINT "haystack not contains ",needle
ENDIF
RELEASE S_TABLE needle
ENDLOOP
You may also check:How to resolve the algorithm Substitution cipher step by step in the Arturo programming language
You may also check:How to resolve the algorithm Text processing/1 step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm File input/output step by step in the Phix programming language
You may also check:How to resolve the algorithm Primality by Wilson's theorem step by step in the Polyglot:PL/I and PL/M programming language
You may also check:How to resolve the algorithm Universal Turing machine step by step in the Sidef programming language