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: | Line 1,712: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
This REXX version also works with non-numeric (alphabetic) items (as well as numbers). |
|||
<lang rexx>/*REXX program lists |
<lang rexx>/*REXX program lists all the non─continuous subsequences (NCS), given a sequence. */ |
||
⚫ | |||
parse arg list /*obtain the arguments from the C. L. */ |
|||
if list='' | list==',' then list=1 2 3 4 5 /*Not specified? Then use the default.*/ |
|||
say 'list=' space(list); say /*display the list to the terminal. */ |
|||
w=words(list) /*W: is the number of items in list. */ |
|||
$=left(123456789, w) /*build a string of decimal digits. */ |
|||
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).*/ |
|||
⚫ | |||
⚫ | |||
if \NCS then iterate /*not OK? Then skip this number (item)*/ |
|||
#=#+1 /*Eureka! We found a number (or item).*/ |
|||
@=; do m=1 for L /*build a sequence string to display. */ |
|||
@=@ word(list, substr(j, m, 1)) /*pick off a number (item) to display. */ |
|||
end /*m*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
if \NCS then iterate /*not OK? Then skip this number.*/ |
|||
end /*j*/ |
|||
say |
|||
⚫ | |||
if #==0 then #='no' /*make it look more gooder Angleshy. */ |
|||
⚫ | |||
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*/ |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
⚫ | |||
⚫ | |||
end /*j*/ |
|||
if #==0 then #='no' /*make it more gooder Anglesh. */ |
|||
⚫ | |||
⚫ | |||
/*────────────────────────────────────────────────────────────────────────────*/ |
|||
⚫ | |||
'''output''' when using the input: <tt> 1 2 3 4 </tt> |
'''output''' when using the input: <tt> 1 2 3 4 </tt> |
||
<pre> |
<pre> |