title: Prolog: How to break a piece of chocolate into its pieces
body: <p>I've got the following task to do:</p>
  
  <p>Given a rectangular chocolate bar, consisting of m x n small rectangles, and the wish of breaking it into its parts. At each step you can only pick one piece and break it either along any of its vertical lines or along its horizontal lines. How should you break the chocolate bar using the minimum number of steps?</p>
  
  <p>I know you need exactly m x n - 1 steps to break the chocolate bar, but I'm asked to do it "the CS way:"</p>
  
  <p>Define a predicate which selects the minimum number of steps among all alternative possibilities to break the chocolate bar into pieces. Construct a straucture on an additional argument position, which tells you where and how to break the bar and what to do with the resulting two pieces.</p>
  
  <p>My thoughts: after breaking the piece of chocolate once, you have the choice of breaking it either on its vertical or its horizontal lines. So this is my code, but it doesn't work:</p>
  
  <pre><code>break_chocolate(Horizontal, Vertical, Minimum) :-
  break_horizontal(Horizontal, Vertical, Min1),
  break_vertical(Horizontal, Vertical, Min2),
  Minimum is min(Min1, Min2).
  
  break_horizontal(0,0,_).
  break_vertical(0,0,_).
  
  break_horizontal(0, V, Min) :-
      V &gt; 0,
      break_horizontal(0, V, Min).
  
  break_horizontal(H, V, Min) :-
      H1 is H-1,
      Min1 is Min + 1,
      break_vertical(H1, V, Min1).
  
  break_horizontal(H, V, Min) :-
      H1 is H-1,
      Min1 is Min + 1,
      break_vertical(H1, V, Min).
  
  break_vertical(H, V, Min) :-
      V1 is V-1,
      Min1 is Min + 1,
      break_horizontal(H, V1, Min1).
  
  break_vertical(H, V, Min) :-
      V1 is V-1,
      Min1 is Min + 1,
      break_vertical(H, V1, Min1).
  
  break_vertical(H, 0, Min) :-
      H &gt; 0,
      break_horizontal(H, 0, Min).
  </code></pre>
  
  <p>Could anyone help me with this one? </p>