Python is really a beginner. It hasn't been long since I started.
The study group gave me a question, but I didn't get close yet and asked, so Python gave me a question If you solve it, I'll analyze it one by one.
I deleted the unproductive comment I just wrote. Instead, I'm going to think about the problem. For your information, it is a difficult problem that takes a long time to actually code.
In theory...
...can solve the problem
So that's a very simple form of theory, and there's a lot more to consider in practice. There is a lot of room for loopholes in the above theory itself. It's like a comprehensive gift set that requires all sorts of applications in the first place. If you ask me to code right now, I think I'll have to use it for a week at my level.
Good luck.
I don't usually do other people's homework.No, I don't know because I'm not good enough. I did it because it looked fun.
It's not my homework anyway, so it doesn't matter if I get it wrong, right? LOL
I think I need to use a different module, but I don't know how to use it, so I just roughly did it.
from random import randrange
list_a = [
['a', 'b', 't', 't', 't'],
['t', 'c', 'd', 'e', 't'],
['t', 't', 't', 'f', 't'],
['b', 'a', 'h', 'g', 'f'],
['c', 'd', 'e', 'f', 'g'],
]
count = 1
move = 0
num1 = randrange(0, 4)
num2 = randrange(0, 4)
print(num1, num2)
a = list_a[num1][num2]
print('reference value', a, order(a))
while 1:
dict_a = {}
a = list_a[num1][num2]
print (f' current location: {num1}, {num2}, {a}')
for i in list_a:
print(i)
try:
if num1 + 1 > 4:
raise
dict_a[ord(list_a[num1 + 1][num2])] = [num1 + 1, num2]
except:
pass
try:
if num1 - 1 < 0:
raise
dict_a[ord(list_a[num1 - 1][num2])] = [num1 - 1, num2]
except:
pass
try:
if num2 + 1 > 4:
raise
dict_a[ord(list_a[num1][num2 + 1])] = [num1, num2 + 1]
except:
pass
try:
if num2 - 1 < 0:
raise
dict_a[ord(list_a[num1][num2 - 1])] = [num1, num2 - 1]
except:
pass
print('dict_a', dict_a)
if count:
print ('There is a chance to move')
r = randrange(0, 1)
if r:
print ('Use travel opportunities')
count -= 1
b = {i:dict_a[i] for i in dict_a if i < ord(a)}
else:
print ('no opportunity to move')
b = {i:dict_a[i] for i in dict_a if i > ord(a)}
else:
print ('no opportunity to move')
b = {i:dict_a[i] for i in dict_a if i > ord(a)}
print(b)
bb = 0
print (previous location: {num1}, {num2}, {a}')
if b:
num_b = randrange(0, len(b))
print('num_b', num_b)
for n, i in enumerate(dict_a.keys()):
c = i
if n == num_b:
break
bb += 1
print('c', c)
num1 = dict_a[c][0]
num2 = dict_a[c][1]
else:
print ('no moveable position')
if count:
print ('Use travel opportunities')
count -= 1
b = {i:dict_a[i] for i in dict_a if i < ord(a)}
if b:
num_b = randrange(0, len(b))
print('num_b', num_b)
for n, i in enumerate(dict_a.keys()):
c = i
if n == num_b:
break
bb += 1
print('c', c)
num1 = dict_a[c][0]
num2 = dict_a[c][1]
if not bb:
print ("End of Movement")
break
move += 1
print('Number of moves:', move)
input()
print ('Final number of movements:', move)
© 2024 OneMinuteCode. All rights reserved.