Recently, I watched a video about a riddle named Cheat Death (watch it check out the channel too!). So I thought about a python code to solve it. It works and solved the riddle too (Not relevant to the given code). I also wrote a code which prints every 5 dice roll sequence and the final position of the player in the snake-ladder board.
fr=[4,5,19,21,28,35,44,47,52,53,59,70,76,81,88,98] #Snakes and ladders start positions.
to=[75,15,41,3,50,96,82,30,23,94,95,91,41,62,67,12] #Snakes and ladders end positons.
def jump(n): #Returns position after each roll.
if n in fr: return to[fr.index(n)]
else: return n
pos=[1,0,0,0,0,0] #Position after each roll (pos[0] is the initial position).
for a in range(1,7): #a,b,c,d,e is the dice value of each roll.
pos[1]=jump(pos[0]+a)#pos[i] is the position after ith roll.
for b in range(1,7):
pos[2]=jump(pos[1]+b)
for c in range(1,7):
pos[3]=jump(pos[2]+c)
for d in range(1,7):
pos[4]=jump(pos[3]+d)
for e in range(1,7):
pos[5]=jump(pos[4]+e)
print(a,b,c,d,e," ",pos[5],end="") #(Dice value in each roll, Final position)
print(end=" ") #For neat printing.
if pos[5]<=9: print(end=" ") #For neat printing.
I know nested for loop isnβt the best way to do it. So, can you please help me to make this code more efficient.