title: Print all possible path using haskell
body: <p>I need to write a program to draw all possible paths in a given matrix that can be had by moving in only left, right and up direction.
  One should not cross the same location more than once. Note also that on a particular path, we may or may not use motion in all possible directions.</p>
  
  <p>Path will start in the bottom-left corner in the matrix and will reach the top-right corner.
  Following symbols are used to denote the direction of the motion in the current position:</p>
  
  <pre><code> +---+
   | &gt; |  right
   +---+
   +---+
   | ^ |  up
   +---+
   +---+
   | &lt; |  left
   +---+
  </code></pre>
  
  <p>The symbol <code>*</code> is used in the final location to indicate end of path.</p>
  
  <p>Example:</p>
  
  <p>For a 5x8 matrix, using left, right and up directions, 2 different paths are shown below.</p>
  
  <p>Path 1:</p>
  
  <pre><code> +---+---+---+---+---+---+---+---+
   |   |   |   |   |   |   |   | * |
   +---+---+---+---+---+---+---+---+
   |   |   | &gt; | &gt; | &gt; | &gt; | &gt; | ^ |
   +---+---+---+---+---+---+---+---+
   |   |   | ^ | &lt; | &lt; |   |   |   |
   +---+---+---+---+---+---+---+---+
   |   | &gt; | &gt; | &gt; | ^ |   |   |   |
   +---+---+---+---+---+---+---+---+
   | &gt; | ^ |   |   |   |   |   |   |
   +---+---+---+---+---+---+---+---+
  </code></pre>
  
  <p>Path 2</p>
  
  <pre><code> +---+---+---+---+---+---+---+---+
   |   |   |   | &gt; | &gt; | &gt; | &gt; | * |
   +---+---+---+---+---+---+---+---+
   |   |   |   | ^ | &lt; | &lt; |   |   |
   +---+---+---+---+---+---+---+---+
   |   |   |   |   |   | ^ |   |   |
   +---+---+---+---+---+---+---+---+
   |   |   | &gt; | &gt; | &gt; | ^ |   |   |
   +---+---+---+---+---+---+---+---+
   | &gt; | &gt; | ^ |   |   |   |   |   |
   +---+---+---+---+---+---+---+---+
  </code></pre>
  
  <p>Can anyone help me with this?</p>
  
  <p>I tried to solve using lists. It i soon realized that i am making a disaster. Here is the code i tried with.</p>
  
  <pre><code> solution x y = travel (1,1) (x,y) 
   travelRight (x,y) = zip [1..x] [1,1..] ++ [(x,y)] 
   travelUp (x,y) = zip [1,1..] [1..y] ++ [(x,y)]
   minPaths = [[(1,1),(2,1),(2,2)],[(1,1),(1,2),(2,2)]]
  
   travel startpos (x,y) = rt (x,y) ++ up (x,y)
  
   rt (x,y) | odd y = map (++[(x,y)]) (furtherRight (3,2) (x,2) minPaths)
            | otherwise = furtherRight (3,2) (x,2) minPaths
   up (x,y) | odd x = map (++[(x,y)]) (furtherUp (2,3) (2,y) minPaths)
            | otherwise = furtherUp (2,3) (2,y) minPaths
  
   furtherRight currpos endpos paths | currpos == endpos = (travelRight currpos) : map (++[currpos]) paths
                                     | otherwise = furtherRight (nextRight currpos) endpos ((travelRight currpos) : (map (++[currpos]) paths))
   nextRight (x,y) = (x+1,y)
  
   furtherUp currpos endpos paths | currpos == endpos = (travelUp currpos) : map (++[currpos]) paths
                                  | otherwise = furtherUp (nextUp currpos) endpos ((travelUp currpos) : (map(++[currpos]) paths))
   nextUp (x,y) = (x,y+1)
  
   identify lst = map (map iden) lst
   iden (x,y) = (x,y,1)
  
  
   arrows lst = map mydir lst
   mydir (ele:[]) = "*"
   mydir ((x1,y1):(x2,y2):lst) | x1==x2 = '&gt;' : mydir ((x2,y2):lst)
                               | otherwise = '^' : mydir ((x2,y2):lst)
  
   surroundBox lst = map (map createBox) lst
   bar = "+    -+"
   mid x = "| "++ [x] ++" |"
   createBox chr = bar ++ "\n" ++ mid chr ++ "\n" ++ bar ++ "\n"
  </code></pre>