[Edu-sig] Data Mazes!

kirby urner kirby.urner at gmail.com
Wed Oct 22 04:43:47 CEST 2008


Here's an admittedly somewhat odd-ball pass time:  create a generator
that hides in "x" in some deeply nested data structure, then come up
with a key for retrieving that "x" (might be a buried treasure!).

For example:

If:

x = "Yes!"

maze =  [(),(),{'a':0},([[{'a':1,'b':{('a','b'):{('a','b'):[[{'a':1,'b':{('a','b'):[(),(),{'a':0},([[{'a':1,'b':[[{'a':1,'b':{('a','b'):x,
('c','d'):2}},0],(1,)]},0],(1,)],)], ('c','d'):2}},0],(1,)],
('c','d'):2}, ('c','d'):2}},0],(1,)],)]

then:

maze[3][0][0][0]["b"][("a","b")][("a","b")][0][0]["b"][("a","b")][3][0][0][0]["b"][0][0]["b"][("a","b")]
would be a solution.

Another example:

>>> maze =  [[{'a':1,'b':[[{'a':1,'b':[(),(),{'a':0},([(),(),{'a':0},([(),(),{'a':0},([[{'a':1,'b':[[{'a':1,'b':[[{'a':1,'b':[(),(),{'a':0},([(),(),{'a':0},(x,)],)]},0],(1,)]},0],(1,)]},0],(1,)],)],)],)]},0],(1,)]},0],(1,)]

Solution:

>>> maze[0][0]["b"][0][0]["b"][3][0][3][0][3][0][0][0]["b"][0][0]["b"][0][0]["b"][3][0][3][0]
'Yes!'

OK, I warned you this was dumb.

The fun part was writing a generator to spit out maze/solution pairs.

Kirby


More information about the Edu-sig mailing list