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, 22.06.2019 22:30
One of your customers wants you to build a personal server that he can use in his home. one of his concerns is making sure he has at least one backup of their data stored on the server in the event that a disk fails. you have decided to back up his data using raid. since this server is for personal use only, the customer wants to keep costs down. therefore, he would like to keep the number of drives to a minimum. which of the following raid systems would best meet the customer's specifications? a. raid 0 b. raid 1 c. raid 5 d. raid 10
Answers: 3
question
Computers and Technology, 24.06.2019 09:40
Healthy study habits are best described as
Answers: 1
question
Computers and Technology, 24.06.2019 13:30
What is the most important for you to choose before you build a network?
Answers: 1
question
Computers and Technology, 24.06.2019 14:00
In simple terms, how would you define a protocol?
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, 01.09.2021 17:00
question
Mathematics, 01.09.2021 17:00
Questions on the website: 13722367