Note that there are some explanatory texts on larger screens.

plurals
  1. POCount in prolog - Impossible to do
    text
    copied!<p>EDIT : More simple :</p> <p>I changed my code to simplify. A predicate "nbarret" return the numbers of stations i want.</p> <p>So there is my new code, but it doesn't change anything :</p> <pre><code>nb_stations([],0). nb_stations([S,Li,Dir,SS],X):-nbarret(Li,S,SS,Dir,Y),X is X1 + Y. nb_stations([S,Li,Dir,SS|Tr],X):- nbarret(Li,S,SS,Dir,Y),nb_stations([SS|Tr],X is X1 + Y). </code></pre> <p>In this case, i have an error :</p> <pre><code>ERROR: is/2: Arguments are not sufficiently instantiated Exception: (8) (_G2031 is _G2270+1)is _G2711+5 ? creep Exception: (7) nb_stations([charles_de_gaulle_etoile, m6, nation, bir_hakeim], _G2031 is _G2270+1) ? creep Exception: (6) nb_stations([la_defense, rerA, vincennes, charles_de_gaulle_etoile, m6, nation, bir_hakeim], _G2031) ? creep </code></pre> <p>/-------------------------------------------------------------/</p> <p>Old code (deprecated, i keep for comprehension) :</p> <pre><code>nb_stations([S,Li,Dir,SS|Tr],X):-num_stations(S,Li,Dir1,ND,_,_),Dir=Dir1,!, num_stations(SS,Li,Dir1,NA,_,_),Dir=Dir1,!, calculer(ND,NA,Y),X is X1 + Y,nb_stations([SS|Tr],X). nb_stations([S,Li,Dir,SS|Tr],X):-num_stations(S,Li,_,_,Dir2,ND),!, num_stations(SS,Li,_,_,Dir2,NA),!, Dir=Dir2,!,calculer(ND,NA,Y),X is X1 + Y,nb_stations([SS|Tr],X). calculer(ND,NA,X):-X is ND - NA. </code></pre> <p>More Details :</p> <p>When you call nb_stations, you have to inform a path in a List, with the departure station, the lign of the transport, the direction, and then the station you will stop. If we have more next, it will be the correspondence. In this example : nb_stations([la_defense,rerA,vincennes,charles_de_gaulle_etoile,m6,nation,bir_hakeim],X).</p> <p>You start in la_defense, you take the "rerA" transport, and you take "vincennes" for the direction. Then you stop in "charles_de_gaulle_etoile", and you take the m6 (metro), the direction is "nation", and you are arrived in "bir_hakeim". So my code count the number of stations i pass in this travel.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload