# overlapping sets

Fri Mar 24 08:18:49 CET 2006

```On Thu, 2006-03-23 at 22:55 -0800, kpp9c wrote:
> I have a question... and ... whew ... i am gonna be honest, i haven't
> the slightest clue how to even start ... i am not sure if i used up all
> my good will here or can take a mulligan.. i love to try to at least
> post some lame broken code of my own at first... but like i said, not
> being a math person i am not even sure how to start or if it is even
> possible.
>
> here's the deal... i have a dictionary that defines some collections..
> like so:
>
> sets = { ('one') : [0, 4, 7, 9 ],
> ('two') : [0, 3, 7, 9 ],
> ('three') : [0, 4, 7, 11],
> ('four') : [0, 3, 7, 10 ],
> ('five') : [0, 4, 7, 10 ],
> ('six') : [0, 4, 8, 10 ],
> ('seven') : [0, 3, 6, 10],
> ('eight') : [0, 3, 6, 9 ],
> ('nine') : [0, 3, 7, 11 ],
> ('ten') : [0, 5, 7, 10 ] }

Look at this from the perspective of a graph.

Now draw a line between nodes that are "compatable" in the way you
describe.

You can use a dict to represent a graph.

If I have this graph:

A - B
B - C
A - C
C - D

then

{'A':'BC', # Remember, strings are sequences in their own right, I'm too
lazy to write ['B','C']
'B':'AC',
'C':'ABD' }

You are going to do the same.  Just make your lists tuples instead,
lists can't be dict keys.  Now, lookup your current node in your dict
and you will get your neighboors.  Use random.choice to pick one, and
move on.

I don't know what the ('eight'), ('nine') keys are all about, but your
biggest impediment is how you are looking at the problem.

For reference http://www.python.org/doc/essays/graphs.html

As for detecting neighboors, sure that's easy, but first you have to try
to use a for loop first on your own to tell how many positional items
any two lists differ by.

Cheers and good luck - Adam DePrince

```