+ 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

7th Aug 2021, 7:18 PM
Abhay
Abhay - avatar
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.
7th Aug 2021, 11:13 PM
BootInk
BootInk - avatar
+ 2
BootInk would you like to send YouTube source to learn this algorithm please.
8th Aug 2021, 1:25 PM
Ratnapal Shende
Ratnapal Shende - avatar
+ 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
8th Aug 2021, 1:51 PM
BootInk
BootInk - avatar
+ 2
Rautnich Sassi Federico Web can be confusing sometime , also really doesn't answers specific doubts an individual might have .
9th Aug 2021, 12:23 PM
Abhay
Abhay - avatar
7th Aug 2021, 7:32 PM
Abhay
Abhay - avatar
+ 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
7th Aug 2021, 7:49 PM
Calvin Thomas
Calvin Thomas - avatar
+ 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.
7th Aug 2021, 7:54 PM
Abhay
Abhay - avatar
+ 1
Abhay Does this work? :- def foo(a): for i in range(3): print(*(a[0][:i+1] + a[1][i:]), sep="")
7th Aug 2021, 9:00 PM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Calvin Thomas ty again! It definitely works but for this specific matrix only .
7th Aug 2021, 9:47 PM
Abhay
Abhay - avatar
+ 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 .
7th Aug 2021, 9:52 PM
Abhay
Abhay - avatar
9th Aug 2021, 11:42 AM
Tayseer Mahmoud
Tayseer Mahmoud - avatar
+ 1
Kishor Shembe i did that , not what my question is about but ty
9th Aug 2021, 12:21 PM
Abhay
Abhay - avatar
+ 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.
9th Aug 2021, 2:30 PM
Calvin Thomas
Calvin Thomas - avatar
0
Is 1236 a valid path?
7th Aug 2021, 7:28 PM
Calvin Thomas
Calvin Thomas - avatar
0
BootInk tysm !
8th Aug 2021, 9:04 AM
Abhay
Abhay - avatar
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.
9th Aug 2021, 8:27 AM
Kishor Shembe
Kishor Shembe - avatar
- 1
Probably you should diversify your sources. The Web is a treasure of inspiration.
9th Aug 2021, 12:13 PM
Rautnich Sassi Federico
Rautnich Sassi Federico - avatar