n-queens version in c

From: masdeval <masdeval_at_yahoo.com.br>
Date: Tue 17 Aug 2004 01:34:19 PM GMT
Message-ID: <00fd01c4845e$e7b186a0$2806520a@cbraz>
    Friends, 

    i'am trying to codify the n-queens problem like it appears in the eclipse home page using the eclipse c++ interface (see below). Someone could see what's wrong? It didn't work but to me is everything correct.

    Thanks, Christian

    /* n-queens */
  /*queens_lists(N, Board) :-

 length(Board, N),
 Board :: 1..N,
 ( fromto(Board, [Q1|Cols], Cols, []) do
     ( foreach(Q2, Cols), param(Q1), count(Dist,1,_) do
  Q2 #\= Q1,
  Q2 - Q1 #\= Dist,
  Q1 - Q2 #\= Dist
     )
 ), labeling(Board).  */

/* C++ version */ 

  EC_ref Board, N;
  EC_word Q1,Cols,Q2,Dist, Underline;
  Q1 = newvar();
  Cols = newvar();
  Q2 = newvar();
  Dist = newvar();
  Underline = newvar();

  EC_word wlist = nil();
  wlist = list(Cols,wlist);
  wlist = list(Q1,wlist);

  post_goal("lib(ic)");
  //length(Board, N), Board :: 1..N,
  EC_word term1 = term(EC_functor(",",2), term(EC_functor("length",2),Board,N), term(EC_functor("::",2),Board, term(EC_functor("..",2),1,N)));

  //fromto(Board, [Q1|Cols], Cols, [])
  EC_word term2 = term(EC_functor("fromto",4), Board, wlist, Cols, nil());

  //foreach(Q2, Cols), param(Q1), count(Dist,1,_)
  EC_word term3 = term(EC_functor(",",2), term(EC_functor("foreach",2),Q2,Cols), term(EC_functor("param",1),Q1) );
  EC_word term4 = term(EC_functor(",",2), term3, term(EC_functor("count",3),Dist,1,Underline));

  //Q2 #\= Q1, Q2 - Q1 #\= Dist,Q1 - Q2 #\= Dist
  EC_word term5 = term(EC_functor(",",2),term(EC_functor("#\\=",2),Q2,Q1) , term(EC_functor("#\\=",2), term(EC_functor("-",2),Q2,Q1),Dist) );
  EC_word term6 = term(EC_functor(",",2),term5, term(EC_functor("#\\=",2), term(EC_functor("-",2),Q1,Q2), Dist ) );

  // second do
  EC_word term7 = term(EC_functor("do",2),term4,term6);
  //first do
  EC_word term8 = term(EC_functor("do",2), term2, term7 );
  
 //labeling
  EC_word term9 = term(EC_functor("labeling",1),Board);
  
  EC_word term10 = term(EC_functor(",",2),term1,term8);
  EC_word term11 = term(EC_functor(",",2),term10, term9 );

  EC_word body = term( EC_functor(",",2), term11, term(EC_functor("writeln",1),Board ));
   
  post_goal( term( EC_functor("assert",1), term(EC_functor(":-",2),  term(EC_functor("queens_lists",2),N, Board), body )));

  EC_ref aux;
  aux = newvar();
  post_goal(term(EC_functor("queens_lists",2),4,aux));

  if(EC_resume() == EC_succeed)
    printf(" Success ");
 
   
Received on Tue Aug 17 15:28:29 2004

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:29 PM GMT GMT