RosettaCodeData/Task/Non-continuous-subsequences/Picat/non-continuous-subsequences.picat
2023-07-01 13:44:08 -04:00

22 lines
631 B
Text

import util.
go =>
println(1..4=non_cont(1..4)),
L = "abcde".reverse(),
println(L=non_cont(L)),
println(ernit=non_cont("ernit")),
println(aaa=non_cont("aaa")),
println(aeiou=non_cont("aeiou")),
nl,
println("Printing just the lengths for 1..N for N = 1..20:"),
foreach(N in 1..20)
println(1..N=non_cont(1..N).length) % just the length
end,
nl.
% get all the non-continuous subsequences
non_cont(L) = [ [L[I] : I in S] : S in non_cont_ixs(L.length)].
% get all the index positions that are non-continuous
non_cont_ixs(N) = [ P: P in power_set(1..N), length(P) > 1, P.last() - P.first() != P.length-1].