Create new instance of Python class in C

Sybren Stuvel sybrenUSE at YOURthirdtower.com.imagination
Sat Sep 10 04:23:15 EDT 2005


phil hunt enlightened us with:
> Why do you need to maske lots of copies?

The puzzles are stored in a NxN list of strings. The strings contain
all the numerals that that block can contain. So a 9x9 puzzle contains
81 strings "123456789" when it's "empty".

My creation function picks a block that isn't a given, and fixes it to
one of it's possible values. It then tries to solve the puzzle. If it
works, it's done creating the puzzle. If it doesn't work, it starts
over again in a recursive manner.

The solver solves the puzzle in-place. That means that if I want to
keep the original puzzle (the one that could be solved), I have to
make a copy.

> And when you say "lots of" what numbers do you mean? 100? 1000000?

That depends a lot. The parts "picks a block that isn't a given" and
"fixes it to one if it's possible values" are both randomized.
Sometimes it's 100, sometimes it's 50000.

> The reason I ask is I recently wrote a program to solve Sudoku
> puzzles, and IIRC it didn't make copies at all.

My solver doesn't create copies either. The creator does.

I think I'll change my algorithm to just solve the puzzle and don't
care about the original minimal puzzle that could be solved. I'll
create a fully solved puzzle, and then use another routine to remove
givens at random until the required number of givens is left. Of
course, still maintaining solvability.

That last part would require copying, but not as much as in the
current situation.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
                                             Frank Zappa



More information about the Python-list mailing list