Non-continuous subsequences: Difference between revisions
Content added Content deleted
(Added Wren) |
(→{{header|REXX}}: added/changed whitespace and comments, used templates for the output sections.) |
||
Line 2,160: | Line 2,160: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
This REXX version also works with non-numeric (alphabetic) items (as well as numbers). |
This REXX version also works with non-numeric (alphabetic) items (as well as numbers). |
||
<lang rexx>/*REXX program lists all the non─continuous subsequences (NCS), given a sequence. |
<lang rexx>/*REXX program lists all the non─continuous subsequences (NCS), given a sequence. */ |
||
parse arg list /*obtain |
parse arg list /*obtain optional argument from the CL.*/ |
||
if list='' | list== |
if list='' | list=="," then list= 1 2 3 4 5 /*Not specified? Then use the default.*/ |
||
say 'list=' space(list); |
say 'list=' space(list); say /*display the list to the terminal. */ |
||
w=words(list) |
w= words(list) /*W: is the number of items in list. */ |
||
nums= strip( left(123456789, w) ) /*build a string of decimal digits. */ |
|||
tail=right( |
tail= right(nums, max(0, w-2) ) /*construct a fast tail for comparisons*/ |
||
#=0 |
#= 0 /*#: number of non─continuous subseq. */ |
||
do j=13 to left( |
do j=13 to left(nums,1) || tail /*step through list (using smart start)*/ |
||
if verify(j, |
if verify(j, nums) \== 0 then iterate /*Not one of the chosen (sequences) ? */ |
||
f=left(j,1) |
f= left(j, 1) /*use the fist decimal digit of J. */ |
||
NCS=0 |
NCS= 0 /*so far, no non─continuous subsequence*/ |
||
do k=2 |
do k=2 for length(j)-1 /*search for " " " */ |
||
x= substr(j, k, 1) /*extract a single decimal digit of J.*/ |
|||
if x <= f then iterate j /*if next digit ≤, then skip this digit*/ |
|||
if x \== f+1 then NCS= 1 /*it's OK as of now (that is, so far).*/ |
|||
f= x /*now have a new next decimal digit. */ |
|||
⚫ | |||
$= |
|||
⚫ | |||
⚫ | |||
do m=1 for length(j) /*build a sequence string to display. */ |
|||
$= $ word(list, substr(j, m, 1) ) /*obtain a number (or item) to display.*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
end /*j*/ |
|||
say /*help ensure visual fidelity in output*/ |
|||
if #==0 then #= 'no' /*make it look more gooder Angleshy. */ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
say |
|||
⚫ | |||
⚫ | |||
⚫ | |||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
s: if arg(1)==1 then return ''; |
s: if arg(1)==1 then return ''; return word( arg(2) 's', 1) /*simple pluralizer.*/</lang> |
||
{{out|output|text= when using the input of: <tt> 1 2 3 4 </tt>}} |
|||
<pre> |
<pre> |
||
list= 1 2 3 4 |
list= 1 2 3 4 |
||
Line 2,204: | Line 2,205: | ||
5 non-continuous subsequences were found. |
5 non-continuous subsequences were found. |
||
</pre> |
</pre> |
||
{{out|output|text= when using the input of: <tt> a e I o u </tt>}} |
|||
<pre> |
<pre> |
||
list= a e I o u |
list= a e I o u |
||
Line 2,227: | Line 2,228: | ||
16 non-continuous subsequences were found. |
16 non-continuous subsequences were found. |
||
</pre> |
</pre> |
||
{{out|output|text= when using the following [five channel Islands (Great Britain)] as input: <tt> Alderney Guernsey Herm Jersey Sark </tt>}} |
|||
<pre> |
<pre> |
||
list= Alderney Guernsey Herm Jersey Sark |
list= Alderney Guernsey Herm Jersey Sark |
||
Line 2,250: | Line 2,251: | ||
16 non-continuous subsequences were found. |
16 non-continuous subsequences were found. |
||
</pre> |
</pre> |
||
{{out|output|text= when using the following [six noble gases] as input: <tt> helium neon argon krypton xenon radon </tt>}} |
|||
<pre> |
<pre> |
||
list= helium neon argon krypton xenon radon |
list= helium neon argon krypton xenon radon |