Programming challenge: wildcard exclusion in cartesian products

Dinko Tenev dinko.tenev at gmail.com
Mon Mar 20 04:38:18 EST 2006


Doug Quale wrote:
> "funkyj" <funkyj at gmail.com> writes:
>
> > One advantage of a generator over filtering the full product is that I,
> > as the user of the generator, am not obligated to iterate over the
> > entire solution space.
> >
> > Are there other _practical_ advantages of generators over mapping &
> > filtering complete sets?
>
> Storage.  You can iterate over problem spaces much too large to fit in
> memory.  Also generate + iterate can be faster because of reduced
> memory pressure.

Hmmm...storage is not an issue in the Prolog version.  It generates a
candidate solution, then checks membership in the wildcard set, then
backtracks (backtracking is caused by "fail" in the test goal.)  On
backtracking, it effectively "forgets" the last solution, so the memory
is freed up (or at least free to be reclaimed through GC.)

Cheers,

Dinko




More information about the Python-list mailing list