Forum: Python Sep 11th, 2007 |
| Replies: 9 Views: 3,344 Is there any problem in making the self argument in the action functions mandatory?
import functools
class SubDevice(object):
def __init__(self, action):
#always pass a reference... |
Forum: Python Aug 19th, 2007 |
| Replies: 8 Views: 3,002 #solve sudoku by backtracking
def solve_sudoku(board):
#i is the first non-filled place, and the one we're going to try different values for
i=board.find('0')
#if i == -1, the puzzle is... |
Forum: Python Aug 17th, 2007 |
| Replies: 15 Views: 2,263 Which is exactly what numerology does. (just completing your post).
I just realized now that the modulus trick demands the OP to treat 0 as 9 -- don't forget about that! |
Forum: Python Aug 16th, 2007 |
| Replies: 8 Views: 3,002 There are basically two ways to solve a sudoku:
1) Solve it by logic, using simple rules such as the ones we, human beings, use, such as "if a square has only one possibility, than that number... |
Forum: Python Aug 16th, 2007 |
| Replies: 15 Views: 2,263 Of course I knew that :P But somehow my brain didn't make the connection. Thanks for the trick! |
Forum: Python Aug 15th, 2007 |
| Replies: 15 Views: 2,263 There is a lot of bad style / redundancies in your code, which is perfectly acceptable since you're a beginner. Your use of while loops when for loops would do is a clear sign of that. Something also... |
Forum: Python Jun 28th, 2007 |
| Replies: 7 Views: 20,121 I third that statement. Time to look at some tutorials as to how to work with threads! |
Forum: Python Jun 28th, 2007 |
| Replies: 5 Views: 2,782 If you have an array of choices arr_choices, it's trivial to get a random element from it (I advise you to take a look at the documentation for the random module, if you haven't already):
import... |
Forum: Python Jun 28th, 2007 |
| Replies: 2 Views: 933 First, I have to tell you that the data will be separated by one space only, regardless of how many there were in the original file. This is a simple code which has no concerns whatsoever with... |
Forum: Python Jun 16th, 2007 |
| Replies: 4 Views: 1,200 You have mistyped __init__ :)
It's __int__ in your phonedb class, look carefully... |
Forum: Python Jun 8th, 2007 |
| Replies: 8 Views: 4,092 You're finding difficulties with Python and "just" moving to C? Let me warn you, you're walking into dangerous territory... C isn't nearly as simple as it sounds. |
Forum: Python Jun 6th, 2007 |
| Replies: 38 Views: 10,323 When I realized the filter was actually bigger, I transformed the map-loop into a comprehension as well:
p=lambda x:[i for i in range(2,x+1) if all([i%x for x in range(2,i**0.5+1)])]
Can... |
Forum: Python Jun 6th, 2007 |
| Replies: 38 Views: 10,323 Note that it's not the sqrt(len(primes(n)) natural number, it's the sqrt(len(primes(n)) prime.
I'm curious as to how this works exactly, perhaps it's because the primes array grows faster than... |
Forum: Python Jun 5th, 2007 |
| Replies: 209 Views: 96,924 Luckily, I have kept most of the useless stuff I wrote when I was a beginner. I knew they helped a lot, even though they were quite trivial, and note that I'm listing everything here (even the... |
Forum: Python May 21st, 2007 |
| Replies: 209 Views: 96,924 Easy. The call to sub_one(x) prints x, calls sub_one(x-1), and prints x-1!
x before if --> 5
x before if --> 4
x before if --> 3
x before if --> 2
x before if --> 1 (the if is not executed... |