diff options
Diffstat (limited to 'tests/general/meander.icn')
-rw-r--r-- | tests/general/meander.icn | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/general/meander.icn b/tests/general/meander.icn new file mode 100644 index 0000000..e1d2df7 --- /dev/null +++ b/tests/general/meander.icn @@ -0,0 +1,33 @@ +# +# M E A N D E R I N G S T R I N G S +# + +# This main procedure accepts specifications for meandering strings +# from standard input with the alphabet separated from the length by +# a colon. + +procedure main() + local line, alpha, n + while line := read() do $( + line ? if $( + alpha := tab(upto(':')) & + move(1) & + n := integer(tab(0)) + $) + then write(meander(alpha,n)) + else stop("*** erroneous input ***") + $) +end + +procedure meander(alpha,n) + local result, t, i, c, k + i := k := *alpha + t := n-1 + result := repl(alpha$<1$>,t) + while c := alpha$<i$> do $( + if find(result$<-t:0$> || c,result) + then i -:= 1 + else $(result ||:= c; i := k$) + $) + return result +end |