Programming challenge: wildcard exclusion in cartesian products
Azolex
cretin at des.alpes.ch
Fri Mar 17 11:53:10 EST 2006
sa wrote:
> in k:
>
> cp:{[c;n;p]+(n#c)_vs(!_ c^n)_dvl,/{2_sv+(,/,/:\:)/(),/:@[x;&x=-1;:[;!c]]}'p}
That one goes a long way as a proof of eg evolution theory, you know,
monkeys reproducing shakespeare with a typewriter k-board and all that :)
>
> examples:
>
> cp[2;3;,0 -1 1]
> (0 0 0
> 0 1 0
> 1 0 0
> 1 0 1
> 1 1 0
> 1 1 1)
>
> cp[2;3;(0 -1 1;1 -1 0)]
> (0 0 0
> 0 1 0
> 1 0 1
> 1 1 1)
>
> cp[2;3;(0 -1 1;1 -1 1)]
> (0 0 0
> 0 1 0
> 1 0 0
> 1 1 0)
>
> arguments of cp:
>
> c = cardinality of the input set
> n = power
> p = list of patterns (-1 = wildcard)
>
> the algorithm directly computes the target set. in other words,
> it does not generate the set, then filter the matches from the
> target.
>
> modifying cp to accept s instead of the cardinality of s,
> patterns expressed in terms of elements of s, &c. adds nothing
> of interest to the problem.
More information about the Python-list
mailing list