Any Python Programmers Out There??

yes and I explained it as basically as I can. his issue is wrongly trying to evaluate an element by doing if list[item] == 0

OK, I do get it. (I think.) Code works now. Thank you and thanks to APL for the time you guys spent explaining it.

Now I'm ready to move on. The original problem in the book of puzzles was an 8 X 8 grid. Each horizontal line similar to my PLst: [2, 0, 4, 5, 7, 0, 3, 2] with some of the numbers in each line missing. Those are the ones I filled in with zero.

The challenge is to make each horizontal line AND each vertical line add to thirty. Well, I'll just type the entire puzzle.

[2, 0, 4, 5, 7, 0, 3, 2]
[0, 4, 1, 6, 0, 1, 9, 0]
[4, 0, 0, 1, 0, 8, 2, 4]
[1, 5, 0, 0, 5, 0, 0, 2]
[0, 6, 4, 3, 0, 4, 2, 6]
[7, 3, 4, 0, 2, 5, 1, 0]
[0, 1, 6, 7, 1, 0, 0, 2]
[1, 0, 2, 0, 3, 2, 5, 0]

So all sixteen lines have to add to thirty. Now that you've pointed me in the right direction, I'm going to forge ahead and attempt to finish the puzzle.
 
OK, I do get it. (I think.) Code works now. Thank you and thanks to APL for the time you guys spent explaining it.

Now I'm ready to move on. The original problem in the book of puzzles was an 8 X 8 grid. Each horizontal line similar to my PLst: [2, 0, 4, 5, 7, 0, 3, 2] with some of the numbers in each line missing. Those are the ones I filled in with zero.

The challenge is to make each horizontal line AND each vertical line add to thirty. Well, I'll just type the entire puzzle.

[2, 0, 4, 5, 7, 0, 3, 2]
[0, 4, 1, 6, 0, 1, 9, 0]
[4, 0, 0, 1, 0, 8, 2, 4]
[1, 5, 0, 0, 5, 0, 0, 2]
[0, 6, 4, 3, 0, 4, 2, 6]
[7, 3, 4, 0, 2, 5, 1, 0]
[0, 1, 6, 7, 1, 0, 0, 2]
[1, 0, 2, 0, 3, 2, 5, 0]

So all sixteen lines have to add to thirty. Now that you've pointed me in the right direction, I'm going to forge ahead and attempt to finish the puzzle.

best of luck. let me know your progress.
 
OK, I do get it. (I think.) Code works now. Thank you and thanks to APL for the time you guys spent explaining it.

Now I'm ready to move on. The original problem in the book of puzzles was an 8 X 8 grid. Each horizontal line similar to my PLst: [2, 0, 4, 5, 7, 0, 3, 2] with some of the numbers in each line missing. Those are the ones I filled in with zero.

The challenge is to make each horizontal line AND each vertical line add to thirty. Well, I'll just type the entire puzzle.

[2, 0, 4, 5, 7, 0, 3, 2]
[0, 4, 1, 6, 0, 1, 9, 0]
[4, 0, 0, 1, 0, 8, 2, 4]
[1, 5, 0, 0, 5, 0, 0, 2]
[0, 6, 4, 3, 0, 4, 2, 6]
[7, 3, 4, 0, 2, 5, 1, 0]
[0, 1, 6, 7, 1, 0, 0, 2]
[1, 0, 2, 0, 3, 2, 5, 0]

So all sixteen lines have to add to thirty. Now that you've pointed me in the right direction, I'm going to forge ahead and attempt to finish the puzzle.

Have fun!
 
I got the code ready. The only thing it needs is an algorithm using linear algebra to solve the puzzle.

And yes I cannot wait. :D
 
Waiting impatiently with bated breath on your progress.

<Sigh> I'm afraid it's gonna be a long wait. I always get the same random numbers when I run the code. Have tried to seed random number generator.

import random
Sed = 1

HLine0 = [2, 0, 4, 5, 7, 0, 3, 2]
HLine1 = [0, 4, 1, 6, 0, 1, 9, 0]
HLine2 = [4, 0, 0, 1, 0, 8, 2, 4]
HLine3 = [1, 5, 0, 0, 5, 0, 0, 2]
HLine4 = [0, 6, 1, 3, 0, 4, 2, 6]
HLine5 = [7, 3, 4, 0, 2, 5, 1, 0]
HLine6 = [0, 1, 6, 7, 1, 0, 0, 2]
HLine7 = [1, 0, 2, 0, 3, 2, 5, 0]

def Add30 (PLst):
--- for I, V in enumerate (PLst):
------ global Sed
------ if V == 0:
-------- Sed += 1
-------- random.seed (Sed)
-------- PLst = random.randint (1, 9)
#
Ctr = 0
print (sum (HLine2))
Add30 (HLine2)
while (sum (HLine2) != 30):
--- Add30 (HLine2)
--- Ctr += 1
--- print (Ctr, HLine2, sum (HLine2))
print (HLine2, sum (HLine2))

Tried putting `seed' before the function, after the function, and, in this incarnation, inside the function. Doesn't matter. I always get the same numbers.
 
<Sigh> I'm afraid it's gonna be a long wait. I always get the same random numbers when I run the code. Have tried to seed random number generator.

import random
Sed = 1

HLine0 = [2, 0, 4, 5, 7, 0, 3, 2]
HLine1 = [0, 4, 1, 6, 0, 1, 9, 0]
HLine2 = [4, 0, 0, 1, 0, 8, 2, 4]
HLine3 = [1, 5, 0, 0, 5, 0, 0, 2]
HLine4 = [0, 6, 1, 3, 0, 4, 2, 6]
HLine5 = [7, 3, 4, 0, 2, 5, 1, 0]
HLine6 = [0, 1, 6, 7, 1, 0, 0, 2]
HLine7 = [1, 0, 2, 0, 3, 2, 5, 0]

def Add30 (PLst):
--- for I, V in enumerate (PLst):
------ global Sed
------ if V == 0:
-------- Sed += 1
-------- random.seed (Sed)
-------- PLst = random.randint (1, 9)
#
Ctr = 0
print (sum (HLine2))
Add30 (HLine2)
while (sum (HLine2) != 30):
--- Add30 (HLine2)
--- Ctr += 1
--- print (Ctr, HLine2, sum (HLine2))
print (HLine2, sum (HLine2))

Tried putting `seed' before the function, after the function, and, in this incarnation, inside the function. Doesn't matter. I always get the same numbers.


May I make a suggestion? Make those lists within a list to make 2d array.
 
Back
Top