Non-continuous subsequences: Difference between revisions

→‎{{header|REXX}}: added/changed whitespace and comments, used templates for the output sections.
(Added Wren)
(→‎{{header|REXX}}: added/changed whitespace and comments, used templates for the output sections.)
Line 2,160:
=={{header|REXX}}==
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. */
parse arg list /*obtain theoptional argumentsargument from the CCL. L. */
if list='' | list=='",'" then list= 1 2 3 4 5 /*Not specified? Then use the default.*/
say 'list=' space(list); say say /*display the list to the terminal. */
w= words(list) /*W: is the number of items in list. */
$nums= strip( left(123456789, w) ) /*build a string of decimal digits. */
tail= right($nums, max(0, w-2) ) /*construct a fast tail for comparisons*/
#= 0 /* [↓] L#: lengthnumber of non─continuous Jth itemsubseq. */
do j=13 to left($nums,1) || tail; L=length(j) /*step through list (using smart start)*/
if verify(j, $nums) \== 0 then iterate /*Not one of the chosen (sequences) ? */
f= left(j, 1) /*use the fist decimal digit of J. */
NCS= 0 /*thereso isn'tfar, ano non─continuous subseq. subsequence*/
do k=2 tofor length(j)-1 L; _=substr(j, k, 1) /*extractsearch for " " a single" decimal digit of J.*/
if _ < x= substr(j, k, 1) f then iterate j /*ifextract nexta digitsingle ≤,decimal thendigit skipof this digitJ.*/
if _ \== f+1if x then NCS<=1 f then iterate j /*it'sif OKnext asdigit of≤, nowthen skip (that is, sothis far).digit*/
f=_ if x \== f+1 then NCS= 1 /*it's OK as of /*now have a(that is, newso next decimal digitfar). */
end f= x /*know have a new next decimal digit. */
end /*mk*/
$=
if \NCS then iterate /*not OK? Then skip this number (item)*/
exit #= # + 1 /*stickEureka! a forkWe infound it,a number we're(or all doneitem). */
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 end /*jm*/
 
say 'a non─continuous subsequence: ' @ $ /*show the non─continuous subsequence. */
if \NCS then iterate /*not OK? Then skip this number (item)*/
#=#+1 end /*Eureka! We found a number (or item).j*/
say @=; do m=1 for L /*build a sequence string to display. /*help ensure visual fidelity in output*/
if #==0 then #= 'no' @=@ word(list, substr(j, m, 1)) /*pickmake offit alook numbermore (item)gooder to displayAngleshy. */
say # "non─continuous subsequence"s(#) 'were found.' /*handle plurals.*/
end /*m*/
ifexit #==0 then #='no' /*makestick ita lookfork morein gooderit, Angleshy. we're all done. */
 
say 'a non─continuous subsequence: ' @ /*show the non─continuous subsequence. */
end /*j*/
say
if #==0 then #='no' /*make it look more gooder Angleshy. */
say # "non─continuous subsequence"s(#) 'were found.'
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
s: if arg(1)==1 then return ''; return word( arg(2) 's', 1) /*simple pluralizer.*/</lang>
'''{{out|output''' |text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> 1 &nbsp; 2 &nbsp; 3 &nbsp; 4 </tt>}}
<pre>
list= 1 2 3 4
Line 2,204 ⟶ 2,205:
5 non-continuous subsequences were found.
</pre>
'''{{out|output''' |text=&nbsp; when using the following input of: &nbsp; &nbsp; <tt> a &nbsp; e &nbsp; I &nbsp; o &nbsp; u </tt>}}
<pre>
list= a e I o u
Line 2,227 ⟶ 2,228:
16 non-continuous subsequences were found.
</pre>
'''{{out|output''' |text=&nbsp; when using the following [five channel Islands (Great Britain)] as input: &nbsp; &nbsp; <tt> Alderney &nbsp; Guernsey &nbsp; Herm &nbsp; Jersey &nbsp; Sark </tt>}}
<pre>
list= Alderney Guernsey Herm Jersey Sark
Line 2,250 ⟶ 2,251:
16 non-continuous subsequences were found.
</pre>
'''{{out|output''' |text=&nbsp; when using the following [six noble gases] as input: &nbsp; &nbsp; <tt> helium &nbsp; neon &nbsp; argon &nbsp; krypton &nbsp; xenon &nbsp; radon </tt>}}
<pre>
list= helium neon argon krypton xenon radon