Repository navigation
Stringhe lunghe 2n - Lez19BT1 #48
notedo
started this conversation in
Backtracking
Replies: 1 comment
def esercizioLez19A2BT1(n, sol=[], i=0, spn=0):
if len(sol) == 2 * n:
print(''.join(sol))
return
if i < n:
sol.append('0')
esercizioLez19A2BT1(n, sol, i + 1, spn)
sol.pop()
sol.append('1')
esercizioLez19A2BT1(n, sol, i + 1, spn + 1)
sol.pop()
if i >= n:
if 0 <= spn <= ((2 * n) - (i + 1)):
sol.append('0')
esercizioLez19A2BT1(n, sol, i + 1, spn)
sol.pop()
if spn != 0 and (spn - 1) <= ((2 * n) - (i + 1)):
sol.append('1')
esercizioLez19A2BT1(n, sol, i + 1, spn - 1)
sol.pop() |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
All reactions