How to resolve the algorithm Non-continuous subsequences step by step in the Pop11 programming language
How to resolve the algorithm Non-continuous subsequences step by step in the Pop11 programming language
Table of Contents
Problem Statement
Consider some sequence of elements. (It differs from a mere set of elements by having an ordering among members.) A subsequence contains some subset of the elements of this sequence, in the same order. A continuous subsequence is one in which no elements are missing between the first and last elements of the subsequence. Note: Subsequences are defined structurally, not by their contents. So a sequence a,b,c,d will always have the same subsequences and continuous subsequences, no matter which values are substituted; it may even be the same value.
Task: Find all non-continuous subsequences for a given sequence.
For the sequence 1,2,3,4, there are five non-continuous subsequences, namely:
There are different ways to calculate those subsequences. Demonstrate algorithm(s) that are natural for the language.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Non-continuous subsequences step by step in the Pop11 programming language
Source code in the pop11 programming language
define ncsubseq(l);
lvars acc = [], gap_started = false, is_continuous = true;
define do_it(l1, l2);
dlocal gap_started;
lvars el, save_is_continuous = is_continuous;
if l2 = [] then
if not(is_continuous) then
cons(l1, acc) -> acc;
endif;
else
front(l2) -> el;
back(l2) -> l2;
not(gap_started) and is_continuous -> is_continuous;
do_it(cons(el, l1), l2);
save_is_continuous -> is_continuous;
not(l1 = []) or gap_started -> gap_started;
do_it(l1, l2);
endif;
enddefine;
do_it([], rev(l));
acc;
enddefine;
ncsubseq([1 2 3 4 5]) =>
You may also check:How to resolve the algorithm Peano curve step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Knapsack problem/Bounded step by step in the Perl programming language
You may also check:How to resolve the algorithm Equilibrium index step by step in the Julia programming language
You may also check:How to resolve the algorithm Non-continuous subsequences step by step in the Tcl programming language
You may also check:How to resolve the algorithm Discordian date step by step in the AWK programming language