+ 1

backtracking

https://code.sololearn.com/cw7aGVNKm2dW/#py. The combination of for loop+recursion has made me confused. without a for loop, '0' is executed only one time according to the base case. However, when I call a function inside a for loop, 6 numbers 0 are executed.

10th Aug 2019, 8:53 PM
Khai123
Khai123 - avatar
9 Respuestas
+ 2
If you have a proper IDE, I suggest "Stepping" through the code, this might help explain the transformation
10th Aug 2019, 8:59 PM
Steven M
Steven M - avatar
+ 1
I tried but I could not understand that part of the code. Im new to backtracking:((
10th Aug 2019, 9:00 PM
Khai123
Khai123 - avatar
+ 1
#does this kinda help? #num is basically the step def permute(i,length, num): num+=1 print(num, 'i=',i) print(num, 'length=', length) if i==length: print(0) print(num,'i=',i) print(num,'length=', length) else: for j in range(i,length): print(num,'i=',i) print(num,'length=', length) permute(i+1,length, num) string="abc" string=list(string) print(permute(0,len(string), 0)) '''it kinda helps illustrate where you're at in the loop/recursive operation. Dont get upset, recursive operations are difficult, but practice makes perfect.'''
10th Aug 2019, 9:31 PM
Steven M
Steven M - avatar
+ 1
your code is more understandable thanks
10th Aug 2019, 9:34 PM
Khai123
Khai123 - avatar
0
I tried to watch yt videos but they did not help sr i am so dumb
10th Aug 2019, 9:21 PM
Khai123
Khai123 - avatar
0
Dont get angry with me:(( sr i am so stupid
10th Aug 2019, 9:33 PM
Khai123
Khai123 - avatar
0
backtracking is so complex
10th Aug 2019, 9:33 PM
Khai123
Khai123 - avatar
0
what are you trying to achieve? 😅
10th Aug 2019, 11:00 PM
Anton Böhler
Anton Böhler - avatar
0
I'm trying to understand how a for loop works when it is combined with recursion. I am new to backtracking. i just understand recursion at basic level. Backtracking is sth too hard for me:)
10th Aug 2019, 11:09 PM
Khai123
Khai123 - avatar