Non-continuous subsequences: Difference between revisions
Content added Content deleted
(→{{header|Perl 6}}: modernize) |
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 |
<lang rexx>/*REXX program lists non-continuous subsequences (NCS), given a sequence. */ |
||
parse arg list /* |
parse arg list /*obtain the list from the C.L. */ |
||
if list='' then list=1 2 3 4 5 /* |
if list='' then list=1 2 3 4 5 /*Not specified? Use the default*/ |
||
say 'list=' space(list); say /* |
say 'list=' space(list); say /*display the list to terminal. */ |
||
w=words(list) ; #=0 /* |
w=words(list) ; #=0 /*W: words in list; # of NCS. */ |
||
$=left(123456789,w) /*build a string of |
$=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 |
f=left(j,1) /*use the 1st decimal digit of J.*/ |
||
NCS=0 /*not non-continuous |
NCS=0 /*not non-continuous subsequence.*/ |
||
do k=2 to length(j); _=substr(j,k,1) /*pick off a single |
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=_ /* |
f=_ /*now have a new next decimal dig*/ |
||
end /*k*/ |
end /*k*/ |
||
if \NCS then iterate /* |
if \NCS then iterate /*not OK? Then skip this number.*/ |
||
#=#+1 /*Eureka! We found |
#=#+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 |
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 |
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 |
say 'a non-continuous subsequence: ' x /*show non─continous subsequence.*/ |
||
end /*j*/ |
end /*j*/ |
||
if #==0 then #='no' /*make it more gooder |
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> |
||
'''output''' when using the input: <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> |
||
'''output''' when using the following input: <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> |
||
'''output''' when using the following [channel Islands (Great Britain)] as input: <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> |
||
'''output''' when using the following [six noble gases] as input: <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 |
||