Since these are supposed to represent the 4 fingers on your hand, can you
really have the out-of-order permutations? Or are you really just looking
at the 16 values of corresponding to the binary values 0000 to 1111? What
is the significance of a symbol meaning "pinky finger on opposite side of
index finger"?
-- Paul
-----Original Message-----
From: Ralph Corderoy [mailto:ra...@in...]
Sent: Tuesday, November 20, 2007 11:10 AM
To: Tim Grove
Cc: pyp...@li...; Paul McGuire
Subject: Re: [Pyparsing] multiple tokens but no repeats
Hi Tim,
> I'm trying to represent the logic that I wish to match 0 or more
> tokens, up to a maximum of 4 tokens, but I don't want any repeats of
> tokens already matched within the group of 4. How could I do that?
I'm not sure if you can. Perhaps there's a way to run your own validation
code as each attempt to grow the number of matches occurs?
Otherwise, since there's only four I'd enumerate the alternatives, e.g.
a
ab ac ad
abc abd acb acd adb adc
abcd abdc acbd acdb adbc adcb
If I've got that right, there's 16 alternatives starting with `a'. The
other three follow a similar pattern making 64 in total. You could factor
out the common prefixes to speed up a Regex() a bit if you find that just a
dumb list seems slow. Be sure to check whether order determines whether it
matches the longest possible, e.g. `abcz' should match `abc' and not `a' or
`ab'.
Cheers,
Ralph.
|