subject

Import random def copy_1d(lst):
b = []
for item in lst:
b. append(item)
return b
def copy_two_d(a):
b = []
for sublist in a:
b. append(copy_1d(sublist))
return b
def three_d_false(n):
pre_1 = [False]
pre_1 *= n
pre_2 = []
for i in range(n):
pre_2.append(copy_1d(pre_1))
final = []
for i in range(n):
final. append(copy_two_d(pre_2))
return final
def three_d_selfavoid(n, trials):
deadEnds = 0
length = 0
for i in range(trials):
been_there = three_d_false(n)
x = n // 2
y = n // 2
z = n // 2
while x > 0 and x < n - 1 and y > 0 and y < n - 1 and z > 0 and z < n - 1:
been_there[x][y][z] = True
print(x, y, z)
if been_there[x + 1][y][z] and been_there[x - 1][y][z] and been_there[x][y - 1][z] and been_there[x][y + 1][z] and been_there[x][y][z + 1] and been_there[x][y][z - 1]:
deadEnds += 1
break
r = random. randrange(1, 7)
if r == 1 and not been_there[x + 1][y][z]:
x = x + 1
length += 1
print(1)
elif r == 2 and not been_there[x - 1][y][z]:
x = x - 1
length += 1
print(2)
elif r == 3 and not been_there[x][y + 1][z]:
y = y + 1
length += 1
print(3)
elif r == 4 and not been_there[x][y - 1][z]:
y = y - 1
length += 1
print(4)
elif r == 5 and not been_there[x][y][z + 1]:
z = z + 1
length += 1
print(5)
elif r == 6 and not been_there[x][y][z - 1]:
z = z - 1
length += 1
print(6)
print(length / trials, deadEnds / trials * 100)
three_d_selfavoid(3, 100)

However, when I run this, it just keeps x, y, and z at 1, 1, and 1. What's wrong...

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 06:00
What makes myhexadecimalnumber a child of mynumber? which methods does myhexadecimalnumber inherit directly from the mynumber class? what can an instance of the mynumber class do? what can an instance of the myhexadecimalnumber class do? which methods are overridden? why are they overridden? how many examples of overloading are there? why was this done? where is the super keyword used? what is it doing? why isn’t the incoming value set immediately in the second myhexadecimalnumber constructor? how many examples can you find of an inherited method being called?
Answers: 1
question
Computers and Technology, 23.06.2019 15:00
What is the total resistance in a circuit that contains three 60 ohm resistors connected in a series? a. 20 ohms b. 120 ohms c. 60 ohms d. 180 ohms
Answers: 2
question
Computers and Technology, 23.06.2019 17:00
The camera still is bad even with the new iphone xr and especially in low light it is even worst because you can see the pixels more if its in low light. if all you apple customers want apple to fix this then lets fill there feedback with complaints about the
Answers: 1
question
Computers and Technology, 23.06.2019 20:30
1. for which of the following are you not required to signal beforehand? a. changing lanes b. speeding up c. stopping
Answers: 2
You know the right answer?
Import random def copy_1d(lst):
b = []
for item in lst:
b. append(item)
ret...
Questions
question
Mathematics, 14.07.2021 23:40
question
Chemistry, 14.07.2021 23:40
question
Mathematics, 14.07.2021 23:50
question
History, 14.07.2021 23:50
question
Mathematics, 14.07.2021 23:50
Questions on the website: 13722361