AProudLefty
Black Kitty Ain't Happy
There'll be more puzzles, but for now I want to concentrate on this one.
Found this web site: https://discuss.python.org
Posted my question there last night. Included the code I had written. Two people responded. One said the reason I got the same numbers every time is because when the list is modified, there are no zeros in it. I start with
[2, 0, 4, 5, 7, 0, 3, 2] The function modifies it to
[2, 4, 4, 5, 7, 9, 3, 2]
That doesn't sum to thirty, so program send it through function again. But this time, it sends the MODIFIED list through. There are no zeros this time, so list never changes.
When I read that, I thought, "That is so obvious! Why didn't I see that?? I must be really dumb."
So I changed program:
ALst = [1, 2, 3, 4, 5, 6, 7, 8, 9] # Don't use `ALst.'
OldHLine0 = [2, 0, 4, 5, 7, 0, 3, 2]
OldHLine1 = [0, 4, 1, 6, 0, 1, 9, 0]
OldHLine2 = [4, 0, 0, 1, 0, 8, 2, 4]
OldHLine3 = [1, 5, 0, 0, 5, 0, 0, 2]
OldHLine4 = [0, 6, 1, 3, 0, 4, 2, 6]
OldHLine5 = [7, 3, 4, 0, 2, 5, 1, 0]
OldHLine6 = [0, 1, 6, 7, 1, 0, 0, 2]
OldHLine7 = [1, 0, 2, 0, 3, 2, 5, 0]
HLine1 = OldHLine1
def RShuf (ALst, HLst):
--- for I, Value in enumerate (HLst):
------- if Value == 0:
-------- HLst = random.randint (1, 9)
while sum (HLine1) != 30:
-- RShuf (ALst, HLine1)
----- if HLine1 != 30: # This `If' duplicates `While.'
------- HLine1 = OldHLine1 # Added it later.
--- print (HLine1, sum (HLine1))
I thought, "This will do the job. Problem solved!"
However, I'm even dumber than I thought. Still same result. Same digits repeated time after time after time.
So my progress is stalled. For now.
Use copy() method. HLine1 = OldHline1 will cause both to be modified.