title: Prolog change for 100 cents
body: <p>I am new to Prolog and I want to write a function that returns all different ways to make change for a dollar (100 cents). We have 2-cent coins, 11-cent coins, 38-cent coins, and, interestingly,  -8-cent coins (a coin worth -8 cents). Also we only have 10 pieces of "-8" cent coins in total. (no upper bound for other kinds of coins)</p>
  
  <p>Here is my try:</p>
  
  <pre><code>change100([P2, P11, P38, Pn8]):- 
      Pn8 =&lt; 10,
      Pn8 &gt;= 0,
      P2 &gt;= 0, P11 &gt;= 0, P38 &gt;= 0,
      D is 2 * P2 + 11 * P11 + 38 * P38 - 8 * Pn8,
      D = 100.
  </code></pre>
  
  <p>But it doesn't work. When I run it and query</p>
  
  <pre><code>?- change100(A).
  </code></pre>
  
  <p>I got message</p>
  
  <pre><code>ERROR:
  
  =&lt; /2: Arguments are not sufficiently instantiated.
  </code></pre>
  
  <p>Why is this? How can I fix it?</p>
  
  <hr>
  
  <h3>The original problem statement:</h3>
  
  <blockquote>
    <p>There are 4 kinds of coins: a 2-cent piece, an 11-cent piece, a 38-cent piece, and, interestingly, a -8-cent piece (a coin worth -8 cents). Even more interesting, a total of only 10 -8- cent pieces have ever been created, so you never need to worry about situations with more than 10 -8-cent pieces.</p>
    
    <p>How many different ways can you make change for a dollar (100 cents)?</p>
    
    <p>For example, one way to make change for 100 cents is to use 4 2-cent pieces, 8 11-cent pieces, 2 38-cent pieces, and 9 -8-cent pieces.</p>
    
    <p>It’s possible to have 0 of some coins, e.g. 50 2-cent pieces is one way to make change for a dollar.</p>
    
    <p>Write a Prolog function called change100(Coins) that begins like this:</p>
    
    <blockquote>
  <pre><code>  change100([P2, P11, P38, Pn8]) :-
         % ...
  </code></pre>
    </blockquote>
    
    <p>P2 is the number of 2-cent coins, P11 is the number of 11-cent coins, and so on. Keep in mind that, as specified in the problem description, Pn8 is at most 10.</p>
  </blockquote>