Non-continuous subsequences: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added/changed whitespace and comments, elided the STYLE from the PRE html tags.)
Line 1,677: Line 1,677:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX program to list non-continuous subsequences (NCS), given a seq.*/
<lang rexx>/*REXX program lists non-continuous subsequences (NCS), given a sequence. */
parse arg list /*the the list from the CL.*/
parse arg list /*obtain the list from the C.L. */
if list='' then list=1 2 3 4 5 /*Specified? Use default. */
if list='' then list=1 2 3 4 5 /*Not specified? Use the default*/
say 'list=' space(list); say /*show list to the terminal*/
say 'list=' space(list); say /*display the list to terminal. */
w=words(list) ; #=0 /*# words in list; # of NCS*/
w=words(list) ; #=0 /*W: words in list; # of NCS. */
$=left(123456789,w) /*build a string of digits.*/
$=left(123456789,w) /*build a string of decimal digs.*/
tail=right($,max(0,w-2)) /*construct a "fast" tail. */
tail=right($,max(0,w-2)) /*construct a "fast" tail. */


do j=13 to left($,1) || tail /*step through the list. */
do j=13 to left($,1) || tail /*step through the list. */
if verify(j,$)\==0 then iterate /*Not one of the chosen? */
if verify(j,$)\==0 then iterate /*Not one of the chosen? */
f=left(j,1) /*the first digit of j. */
f=left(j,1) /*use the 1st decimal digit of J.*/
NCS=0 /*not non-continuous subseq*/
NCS=0 /*not non-continuous subsequence.*/
do k=2 to length(j); _=substr(j,k,1) /*pick off a single digit. */
do k=2 to length(j); _=substr(j,k,1) /*pick off a single decimal digit*/
if _ <= f then iterate j /*if next digit ≤ then skip*/
if _ <= f then iterate j /*if next digit ≤, then skip it.*/
if _ \== f+1 then NCS=1 /*it's OK as of now. */
if _ \== f+1 then NCS=1 /*it's OK as of now. */
f=_ /*we now got a new next dig*/
f=_ /*now have a new next decimal dig*/
end /*k*/
end /*k*/


if \NCS then iterate /*¬OK? Then skip this num.*/
if \NCS then iterate /*not OK? Then skip this number.*/
#=#+1 /*Eureka! We found one. */
#=#+1 /*Eureka! We found onea digit.*/
x= /*the beginning of the NCS.*/
x= /*the beginning of the NCS. */
do m=1 for length(j) /*build a thingy to display*/
do m=1 for length(j) /*build a sequence string to show*/
x=x word(list,substr(j,m,1)) /*pick off a number to show*/
x=x word(list,substr(j,m,1)) /*pick off a number to display. */
end /*m*/
end /*m*/


say 'a non-continuous subsequence: ' x /*show a non-cont. subseq. */
say 'a non-continuous subsequence: ' x /*show non─continous subsequence.*/
end /*j*/
end /*j*/


if #==0 then #='no' /*make it more gooder Eng. */
if #==0 then #='no' /*make it more gooder Anglesh. */
say; say # "non-continuous subsequence"s(#) 'were found.'
say; say # "non-continuous subsequence"s(#) 'were found.'
exit /*stick a fork in it, we're done.*/
exit /*stick a fork in it, we're done.*/
/*────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────S subroutine───────────────────────*/
s: if arg(1)==1 then return ''; return word(arg(2) 's',1) /*plurals.*/</lang>
s: if arg(1)==1 then return ''; return word(arg(2) 's',1) /*plurals.*/</lang>
{{out}} when using the input: <tt> 1 2 3 4 </tt>
'''output''' &nbsp; when using the input: &nbsp; <tt> 1 2 3 4 </tt>
<pre>
<pre style="overflow:scroll">
list= 1 2 3 4
list= 1 2 3 4


Line 1,722: Line 1,722:
5 non-continuous subsequences were found.
5 non-continuous subsequences were found.
</pre>
</pre>
{{out}} when using the following input: <tt> a e I o u </tt>
'''output''' &nbsp; when using the following input: &nbsp; <tt> a e I o u </tt>
<pre>
<pre style="overflow:scroll">
list= a e I o u
list= a e I o u


Line 1,745: Line 1,745:
16 non-continuous subsequences were found.
16 non-continuous subsequences were found.
</pre>
</pre>
{{out}} when using the [channel Islands (Great Britain)] as input: <tt> Alderney Guernsey Herm Jersey Sark </tt>
'''output''' &nbsp; when using the following [channel Islands (Great Britain)] as input: &nbsp; <tt> Alderney Guernsey Herm Jersey Sark </tt>
<pre>
<pre style="overflow:scroll">
list= Alderney Guernsey Herm Jersey Sark
list= Alderney Guernsey Herm Jersey Sark


Line 1,768: Line 1,768:
16 non-continuous subsequences were found.
16 non-continuous subsequences were found.
</pre>
</pre>
{{out}} when using the following [six noble gases] as input: <tt> helium neon argon krypton xenon radon </tt>
'''output''' &nbsp; when using the following [six noble gases] as input: &nbsp; <tt> helium neon argon krypton xenon radon </tt>
<pre>
<pre style="overflow:scroll">
list= helium neon argon krypton xenon radon
list= helium neon argon krypton xenon radon