[Tutor] Another set question

Alan Gauld alan.gauld at yahoo.co.uk
Sun Apr 30 10:58:13 EDT 2017


On 30/04/17 00:58, Phil wrote:

> Thank you Ben. A rethink of the problem during the 20 hours since 
> I posted my most recent question has led to a solution.

You don;t say what so i'll go with what you say below...

> The strings are the given numbers while the sets are 
> the likely candidates.

I would probably combine both such that for each cell you
have a tuple containing the given number and the set of
candidates. In some cases the number may be a sentinel
(such as -1) to indicate no number yet, and for some
cells the set will be empty.

But by always having both available your data handling
becomes consistent, you always know that you get a tuple
and you know can easily test the sentinel to see3 if
the value is set or not. And you never need to
test types.

Everything should become much more consistent. (The storage
overhead is minimal for a suduko game - it might be different
if you were doing something with a massive grid...)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list