Anonymous user
Non-continuous subsequences: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments, elided the STYLE from the PRE html tags.
(→{{header|Perl 6}}: modernize) |
m (→{{header|REXX}}: added/changed whitespace and comments, elided the STYLE from the PRE html tags.) |
||
Line 1,677:
=={{header|REXX}}==
<lang rexx>/*REXX program
parse arg list /*
if list='' then list=1 2 3 4 5 /*
say 'list=' space(list); say /*
w=words(list) ; #=0 /*
$=left(123456789,w) /*build a string of
tail=right($,max(0,w-2)) /*construct a "fast" tail. */
do j=13 to left($,1) || tail /*step through the list. */
if verify(j,$)\==0 then iterate /*Not one of the chosen? */
f=left(j,1) /*use the
NCS=0 /*not non-continuous
do k=2 to length(j); _=substr(j,k,1) /*pick off a single
if _ <= f then iterate j /*if next digit ≤, then skip it.*/
if _ \== f+1 then NCS=1 /*it's OK as of now. */
f=_ /*
end /*k*/
if \NCS then iterate /*
#=#+1 /*Eureka! We found
x= /*the beginning of the NCS. */
do m=1 for length(j) /*build a
x=x word(list,substr(j,m,1)) /*pick off a number to
end /*m*/
say 'a non-continuous subsequence: ' x /*show
end /*j*/
if #==0 then #='no' /*make it more gooder
say; say # "non-continuous subsequence"s(#) 'were found.'
exit /*stick a fork in it, we're done.*/
/*────────────────────────────────────────────────────────────────────────────*/
s: if arg(1)==1 then return ''; return word(arg(2) 's',1) /*plurals.*/</lang>
<pre>
list= 1 2 3 4
Line 1,722:
5 non-continuous subsequences were found.
</pre>
<pre>
list= a e I o u
Line 1,745:
16 non-continuous subsequences were found.
</pre>
<pre>
list= Alderney Guernsey Herm Jersey Sark
Line 1,768:
16 non-continuous subsequences were found.
</pre>
<pre>
list= helium neon argon krypton xenon radon
|