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
parse arg list /*obtain the list from the C.L. */▼
tail=right($, max(0, w-2)) /*construct a fast tail for comparisons*/
do j=13 to left($,1) || tail; L=length(j) /*step through list (using smart start)*/
do k=2 to L; _=substr(j, k, 1) /*extract a single decimal digit of J.*/
if _ \== f+1 then NCS=1 /*it's OK as of now (that is, so far).*/
end /*k*/▼
▲ 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
say
▲ x= /*the beginning of the NCS. */
if #==0 then #='no'
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
▲ say 'a non-continuous subsequence: ' x /*show non─continous subsequence.*/
▲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''' when using the input: <tt> 1 2 3 4 </tt>
<pre>
|