Hello again - rather a newbie here...
I want to work on a sudoku brute-forcer, just for fun.
I am considering different strategies, but first I need to decide on the
data-structure to use for the progress/solution grid.
This being a square, I would have used a 9x9 2-dimensional array in my
teenage years back in the 80's, using BASIC.
What is the equivalent way to store data in python? - It isn't obvious
to me how to do it with lists.
'scuse me for being thick - but give me a little pointer and I will do
the rest. 15 3939
anthonyberet wrote: Hello again - rather a newbie here...
I want to work on a sudoku brute-forcer, just for fun.
I am considering different strategies, but first I need to decide on the data-structure to use for the progress/solution grid.
This being a square, I would have used a 9x9 2-dimensional array in my teenage years back in the 80's, using BASIC.
What is the equivalent way to store data in python? - It isn't obvious to me how to do it with lists.]
Well, you could do a list of lists, or a tuple of tuples, or a
combination thereof.
For example:
val = matrix[indexA][indexB]
-carl 'scuse me for being thick - but give me a little pointer and I will do the rest.
--
Carl J. Van Arsdall cv*********@mvi sta.com
Build and Release
MontaVista Software
anthonyberet wrote: Hello again - rather a newbie here...
I want to work on a sudoku brute-forcer, just for fun.
I know what you mean. I wrote one just for fun too.
I am considering different strategies, but first I need to decide on the data-structure to use for the progress/solution grid.
This being a square, I would have used a 9x9 2-dimensional array in my teenage years back in the 80's, using BASIC.
What is the equivalent way to store data in python? - It isn't obvious to me how to do it with lists.
List of lists.
One list with nine elements, each of which is a list with nine numbers.
[[5,2,7,3,9,8,1,4 ,6],
[3,1,4,....],
....
]
Cheers,
Carl.
anthonyberet wrote: Hello again - rather a newbie here...
I want to work on a sudoku brute-forcer, just for fun.
I am considering different strategies, but first I need to decide on the data-structure to use for the progress/solution grid.
This being a square, I would have used a 9x9 2-dimensional array in my teenage years back in the 80's, using BASIC.
What is the equivalent way to store data in python? - It isn't obvious to me how to do it with lists.
'scuse me for being thick - but give me a little pointer and I will do the rest.
Probably the numeric module: http://numeric.scipy.org/
But you can also do nested lists.
Larry Bates
> I want to work on a sudoku brute-forcer, just for fun.
Well, as everybody seems to be doing these (self included...),
the sudoku solver may become the "hello world" of the new world :) What is the equivalent way to store data in python? - It isn't obvious to me how to do it with lists.
Several other answers have crossed the list. I've done it using
a dictionary of tuples:
grid = {}
for row in range(1,10):
for col in range(1,10):
grid[(row,col)] = value
item = grid[(3,2)]
etc.
Seemed fairly quick and worked for me.
-tkc
anthonyberet wrote: Hello again - rather a newbie here...
I want to work on a sudoku brute-forcer, just for fun.
I am considering different strategies, but first I need to decide on the data-structure to use for the progress/solution grid.
This being a square, I would have used a 9x9 2-dimensional array in my teenage years back in the 80's, using BASIC.
What is the equivalent way to store data in python? - It isn't obvious to me how to do it with lists.
'scuse me for being thick - but give me a little pointer and I will do the rest.
Another approach as already proposed could be, that you define your grid
as a dictionary in a following way:
grid = {}
for column in range(1,10):
for row in range(1,10):
grid[(column, row)] = None
# then you can refer to the cells of the 'array' like:
colNo=5; rowNo=4
valueInCellOfGr id = grid[(colNo, rowNo)]
# and set them like:
grid[(colNo, rowNo)] = 9
print valueInCellOfGr id
print grid[(colNo, rowNo)]
I haven't checked it out, but I can imagine, that this approach could
even have a speed advantage over a list of lists what can become
important in a 'brute-forcer' approach.
Best way is probably to use one of available numeric libraries with
array support, but this is another story.
Claudio
Claudio
Claudio Grondi wrote: Another approach as already proposed could be, that you define your grid as a dictionary in a following way: grid = {} for column in range(1,10): for row in range(1,10): grid[(column, row)] = None # then you can refer to the cells of the 'array' like: colNo=5; rowNo=4 valueInCellOfGr id = grid[(colNo, rowNo)] # and set them like: grid[(colNo, rowNo)] = 9 print valueInCellOfGr id print grid[(colNo, rowNo)]
FWIW, if you leave out the parentheses, it looks more like a genuine 2D
array, which can be nice (actually I think it's the main advantage over
lists of lists):
print grid[colNo, rowNo] Claudio
--Max
Claudio Grondi wrote: anthonyberet wrote: Hello again - rather a newbie here... I am considering different strategies, but first I need to decide on the data-structure to use for the progress/solution grid.
... define your grid as a dictionary in a following way: grid = {} for column in range(1,10): for row in range(1,10): grid[(column, row)] = None # then you can refer to the cells of the 'array' like: colNo=5; rowNo=4 valueInCellOfGr id = grid[(colNo, rowNo)] # and set them like: grid[(colNo, rowNo)] = 9 print valueInCellOfGr id print grid[(colNo, rowNo)]
Though a couple of people have suggested a dictionary, nobody has
yet pointed out that a[i, j] is the same as a[(i, j)] (and looks
less ugly). So, I'd go with dictionaries, and index them as
grid = {}
for column in range(1,10):
for row in range(1,10):
grid[column, row] = None
...
valueInCellOfGr id = grid[col, row]
grid[col, row] = 9
...
--Scott David Daniels sc***********@a cm.org
On 2006-01-26, Larry Bates <la*********@we bsafe.com> wrote: I want to work on a sudoku brute-forcer, just for fun.
I am considering different strategies, but first I need to decide on the data-structure to use for the progress/solution grid.
This being a square, I would have used a 9x9 2-dimensional array in my teenage years back in the 80's, using BASIC.
What is the equivalent way to store data in python? - It isn't obvious to me how to do it with lists.
'scuse me for being thick - but give me a little pointer and I will do the rest.
Probably the numeric module:
http://numeric.scipy.org/
I'd use numeric or numarray. They have built-in notation for
grabbing a row or column.
--
Grant Edwards grante Yow! I appoint you
at ambassador to Fantasy
visi.com Island!!!
Tim Chase wrote: I want to work on a sudoku brute-forcer, just for fun.
Well, as everybody seems to be doing these (self included...), the sudoku solver may become the "hello world" of the new world :)
What is the equivalent way to store data in python? - It isn't obvious to me how to do it with lists.
Several other answers have crossed the list. I've done it using a dictionary of tuples:
grid = {} for row in range(1,10): for col in range(1,10): grid[(row,col)] = value
item = grid[(3,2)]
etc.
Seemed fairly quick and worked for me.
Thanks for the advice (to everyone in the thread).
I think I will go with nested lists.
However, I am running into a conceptual problem.
My approach will be firstly to remove all the impossible digits for a
square by searching the row and column for other occurances.
However, I wondering how to approach the search of the nine regions of
the grid. I am thinking of producing another nested list, again 9x9 to
store the contents of each region, and to update this after each pass
through -and update of- the main grid (row and column).
I am not sure how to most efficiently identify which region any given
square on the grid is actually in - any thoughts, for those that have
done this? - I don't want a massive list of IF conditionals if I can
avoid it. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Innocence |
last post by:
Hi
I've been considering how to optimize map data structures for a tile
based Python game. However, since I'm a Python newbie I lack
experience with Pythons 'exotic' data types like lists and tuples, and
thus I'm unsure whether such types could solve my problem.
My basic thought is this: If my world map consists of 80% water and
20%...
|
by: hzy_104 |
last post by:
Please recommend book on data structures for searching(c++)?
|
by: Amit |
last post by:
Hello,
Can any of you recommend a really good book on data structures and more so,
if it relates to STL data structures, and how they are used to build far
more complex data structures.
Thanks.
|
by: el_roachmeister |
last post by:
For being a good web programmer, is a course on data structures
important? It seems php already has built-in functions for what they
teach in a data structures course. On the other hand all universities
seem to teach this class. I tried taking one but just found it too
boring and irrelevant for what I was doing. What are your thoughts?
|
by: Thomas Paul Diffenbach |
last post by:
Can anyone point me to an open source library of /statically
allocated/ data structures?
I'm writing some code that would benefit from trees, preferably self
balancing, but on an embedded system that doesn't offer dynamic
memory allocation (to be clear: no malloc, no realloc), and with
rather tight memory constraints.
Writing my own...
| |
by: utab |
last post by:
Dear all,
I was reading something on data structures on c++ and in that chapter
it was telling that the same components will be more efficiently
substituted with the STL ones.
So can somebody give me some clues? I think that is better to learn the
STL style than trying to write them with linked lists,pointers and so
on... Maybe I am...
|
by: osp |
last post by:
hi to every one....
i just started out with c++ and i think i am
doing well.i use Robert Laffore to study. which book should i use for
data structures ? please help.
thank you
with regards
osp
|
by: efrat |
last post by:
Hello,
I'm planning to use Python in order to teach a DSA (data structures
and algorithms) course in an academic institute. If you could help out
with the following questions, I'd sure appreciate it:
1. What exactly is a Python list? If one writes a, then is the
complexity Theta(n)? If this is O(1), then why was the name "list"
chosen? If...
|
by: Mik0b0 |
last post by:
Hallo to everyone.
This fall I am going to start data structures as a part of C language
course. The problem is I could not find any satisfying tutorial about
structures in C. There are plenty of books about data structures in C+
+ etc., could anyone please recommend me such a C -specific book ? And
another question: are data structures (like...
|
by: jehugaleahsa |
last post by:
Hello:
When developing data structures for C#, there is an obvious
performance hit when utilizing primitive types. For instance, a recent
hash table implementation I wrote works exceedingly fast on strings.
It can run through a million randomly generated strings in less than
half of a second (in most tests). The built-in dictionary class...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |