title: How to find the number of inversions in a list in Prolog
body: <p>As someone who's new to Prolog, I'm looking to find out what a good way to count the number of inversions in a list.</p>
  
  <p>I know how to flatten a matrix using <code>flatten(Matrix, FlatMatrix)</code>, thus creating a variable that contains a single set of elements in the matrix. However, I'm unsure as to how to go about finding the number of inversions in that list. </p>
  
  <p>From my understanding, the number of inversions in a matrix of numbers from 0...n is the total number of elements that are less than the number being compared (please correct me if I'm wrong on this).</p>
  
  <p>I have a tiny bit of understanding of how <code>setof/3</code> works in Prolog but I'd love to know a more efficient way to tackle the figuring out of the number of inversions in a flattened matrix. Variables in Prolog are strange to me so simple explanations would be best.</p>
  
  <p>Thank you in advance!</p>