Non-continuous subsequences: Difference between revisions

Content added Content deleted
(Added Elixir)
m (→‎{{header|REXX}}: added/changed whitespace and comments, changed indentations, made other cosmetic improvements.)
Line 1,712:
 
=={{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 non─continuous subsequences (NCS), given a sequence. */
parse arg list /*obtain the list from the C.L. */
ifparse arg list='' then list=1 2 3 4 5 /*Notobtain specified?the arguments Usefrom the default C. L. */
sayif 'list='' space(| list); say==',' then list=1 2 3 4 5 /*displayNot thespecified? list toThen terminal.use the default.*/
wsay 'list=words' space(list); say ; #=0 /*W:display the wordslist into list;the terminal. # of NCS. */
$w=leftwords(123456789,wlist) /*buildW: a stringis the number of decimalitems digsin list. */
tail$=rightleft($,max(0123456789, w-2)) /*constructbuild a string "fast"of decimal taildigits. */
tail=right($, max(0, w-2)) /*construct a fast tail for comparisons*/
#=0 x= /*the beginning[↓] of the NCS. L: length of Jth item. */
do j=13 to left($,1) || tail; L=length(j) /*step through list (using smart start)*/
if _verify(j, $)\== f+10 then NCS=1 iterate /*it'sNot OK asone of now. the chosen (sequences) ? */
parse arg list f=left(j,1) /*obtainuse the listfist fromdecimal thedigit C.Lof J. */
NCS=0 f=_ /*nowthere haveisn't a new nextnon─continuous decimalsubseq. dig*/
do k=2 to L; _=substr(j, k, 1) /*extract a single decimal digit of J.*/
if _ <= f then iterate j /*if next digit ≤, then skip it.this digit*/
if _ \== f+1 then NCS=1 /*it's OK as of now (that is, so far).*/
exit f=_ /*sticknow have a fork innew it, we'renext donedecimal digit. */
end /*k*/
 
do j=13 if to\NCS left($,1) ||then tailiterate /*step through the list. /*not OK? Then skip this number (item)*/
if verify(j,$)\= #=0#+1 then iterate /*Not one of the chosen? /*Eureka! We found a number (or item).*/
f @=left(j,1); do m=1 for L /*usebuild thea 1stsequence decimalstring digitto of Jdisplay. */
NCS=0 @=@ word(list, substr(j, m, 1)) /*pick off a number (item) to display. /*not non-continuous subsequence.*/
do k=2 to length(j); _=substr(j,k,1)end /*pick off a single decimal digitm*/
if _ <= f then iterate j /*if next digit ≤, then skip it.*/
if _ \== f+1 then NCS=1 /*it's OK as of now. */
f=_ /*now have a new next decimal dig*/
end /*k*/
 
say 'a non-continuousnon─continuous subsequence: ' x @ /*show non─continousthe non─continuous subsequence. */
if \NCS then iterate /*not OK? Then skip this number.*/
#=#+1 end /*Eureka! We found onea digit.j*/
say
x= /*the beginning of the NCS. */
if #==0 then #='no' do m=1 for length(j) /*buildmake it look more agooder sequenceAngleshy. string to show*/
say; say # "non-continuousnon─continuous subsequence"s(#) 'were found.'
x=x word(list,substr(j,m,1)) /*pick off a number to display. */
exit /*stick a fork in it, we're all done. */
end /*m*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
 
s: if arg(1)==1 then return ''; return word(arg(2) 's', 1) /*pluralspluralizer.*/</lang>
say 'a non-continuous subsequence: ' x /*show non─continous subsequence.*/
end /*j*/
 
if #==0 then #='no' /*make it more gooder Anglesh. */
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>
'''output''' &nbsp; when using the input: &nbsp; <tt> 1 2 3 4 </tt>
<pre>