/* edf.js    (EDF : Equations aux Différences Finies)
   Suites récurrentes 
   Suites linéaires à coefficients constant, sans second membre
   Jean-Paul Davalan 2003 jpdvl@wanadoo.fr

*/

function suite(s) {
  var a = s;
  a.replace(/^\s+/,"");
  a.replace(/\s*$/,"");
  b = new Array();
  b = a.split(/\s+/);
  return b;
}

function effectue() {
  var q = "", zn, z,
      x = 0, c = new Array() , v = new Array(),
      s = document.frm.otxt.value, s1 = document.frm.itxt.value;
     
  v = suite(s); var n = v.length;
  c = suite(s1); var m = c.length;

  for(var i = 0; i< m; i++) {
    if(i < n) x = x + parseInt(v[i])*  parseInt(c[i]);
  }
 
  z = document.frm.z.value;
  zn=-1;
  if(z != void(0) && z!="") 
    zn = parseInt(z);

  if( zn <= 0 ) {
    if (v[0] != 0) q = x/v[0];
  } else 
    x = x % zn;
  
  document.frm.otxt.value = x + " "+ s;
  document.frm.q.value = q;
}
  
function efface() {
  document.frm.itxt.value = "";
  document.frm.otxt.value = "";
  document.frm.q.value = "";
  document.frm.z.value = "";
}
function nof() {
;
}

function exemple() {
     this.names=new Array("N","Fibonacci","Lucas","Perrin","Padovan","Pell","numérateurs","argent",
          "aires");
/*
     this.names["Fibonacci"]=new Array("1 1","1 0");
     this.names["Lucas"]=new Array("1 1","1 2");
     this.names["Perrin"]=new Array("0 1 1","2 0 3");
     this.names["Padovan"]=new Array("0 1 1","2 1 1");
     this.names["Pell"]=new Array("2 1","0 1");
     this.names["numérateurs"]=new Array("2 1","1 1");
 */
     function set(u) {
       document.frm.itxt.value=this.names[u][0];
       document.frm.otxt.value=this.names[u][1];
       document.frm.q.value="";
       document.frm.z.value="";
     };
     this.set=set;
     function init(a, b, c) {
       this.names[a]=new Array(b, c);
     }
     this.init=init;
}

var exo = new exemple();
exo.init("N","2 -1","1 0");
exo.init("Fibonacci","1 1","1 0");
exo.init("Lucas","1 1","1 2");
exo.init("Perrin","0 1 1","2 0 3");
exo.init("Padovan","0 1 1","2 1 1");
exo.init("Pell","2 1","0 1");
exo.init("numérateurs","2 1","1 1");
exo.init("tom1","1 0 1","1 1 1");
exo.init("tom2","1 0 0 1","1 1 1 1");
exo.init("argent","4 -1","4 2");
exo.init("aires","14 -1","6 0");

