+ 4
How to print all possible paths from top left to bottom right of the matrix ? [Solved]
So i have wrote a code for the above problem and it does print the possible paths but i can't understand how to refactor it to print the full paths. Note: you are only allowed to move only one block either right or down. https://code.sololearn.com/cF23CMDkquYH/?ref=app
17 Answers
+ 1
https://code.sololearn.com/cD1W91uK49qc
Explanations are given in the numerous comments I left in code. Hope it helps, and great question by the way, you've got my upvote.
+ 2
BootInk would you like to send YouTube source to learn this algorithm please.
+ 2
For those that want a video lecture on BFS algorithms, of which is related to my code bit solution:
https://www.youtube.com/watch?v=oDqjPvD54Ss
+ 2
Rautnich Sassi Federico Web can be confusing sometime , also really doesn't answers specific doubts an individual might have .
+ 1
Calvin Thomas yes
+ 1
Abhay How about this one? :-
def foo(a): [print(*(a[0][j:i+1] + a[1][i:]), sep="") for j in range(3) for i in range(j, 3)]
# Shows all the possible paths from the top list to the bottom one
# I hope that this works
+ 1
Calvin Thomas ty . It works fine but it should print only the first three paths .
Maybe i should have been clear about the problem . The problem asks to print all the possible paths from the very top left element to bottom right element , no other path in btw them.
+ 1
Abhay Does this work? :-
def foo(a):
for i in range(3):
print(*(a[0][:i+1] + a[1][i:]), sep="")
+ 1
Calvin Thomas ty again! It definitely works but for this specific matrix only .
+ 1
✩✮★✮✩ tyvm . It works fine but doesn't makes much sense to me now but i will definitely look into it later .
I was just hoping it to be easy or maybe someone could give me hint on how should i refactor my code but i appreciate the help .
+ 1
check that
https://code.sololearn.com/c9IJEr9XTz3h
+ 1
Kishor Shembe i did that , not what my question is about but ty
+ 1
Abhay Yeah. Stackoverflow, Quora and Reddit have their own limitations. Especially when you find it difficult to express your question in the search bar without any code mention; in a compact way, I mean.
0
Is 1236 a valid path?
0
BootInk tysm !
0
The problem is to print all the possible paths from top left to bottom right of a mXn matrix with the constraints that from each cell you can either move only to right or down. The algorithm is a simple recursive algorithm, from each cell first print all paths by going down and then print all paths by going right.
- 1
Probably you should diversify your sources. The Web is a treasure of inspiration.