Simple program in Prolog 
Author Message
 Simple program in Prolog

I am free to ask for help in Prolog programming...

I need a prolog program which in given sorted list search for element of
that list, using binary search method ...

Can somebody help me?

Thank you in advance...



Tue, 21 Jun 2005 01:10:49 GMT  
 Simple program in Prolog

: I need a prolog program which in given sorted list search
: for element of that list, using binary search method ...
Please explain what kind of data-structure you are supposed to use.
(trees, single-linked lists, etc.)

Regards,
Stefan

--
Stefan Kral            http://www.complang.tuwien.ac.at/skral/



Tue, 21 Jun 2005 05:28:32 GMT  
 Simple program in Prolog

Quote:


>: I need a prolog program which in given sorted list search
>: for element of that list, using binary search method ...
>Please explain what kind of data-structure you are supposed to use.
>(trees, single-linked lists, etc.)

And who will get the grade if we do your homework....

A.L



Tue, 21 Jun 2005 07:26:42 GMT  
 Simple program in Prolog

Quote:

> Can somebody help me?

Yes.

--
Common sense is instinct, and enough of it is genius.
                -- Josh Billings



Tue, 21 Jun 2005 09:20:56 GMT  
 Simple program in Prolog

: I need a prolog program which in given sorted list search for element of
: that list, using binary search method ...
Please explain what kind of binary search method you are supposed
to use.

Best Regards,
Stefan

--
Stefan Kral            http://www.complang.tuwien.ac.at/skral/



Fri, 24 Jun 2005 00:36:28 GMT  
 Simple program in Prolog
Quote:

> I am free to ask for help in Prolog programming...

> I need a prolog program which in given sorted list search for element of
> that list, using binary search method ...

> Can somebody help me?

> Thank you in advance...

/*

  Prolog is language and language is a vehicle of the imagination, so I
suggest you use your imagination.

  What you do when you look up an author's name in the card catalog at
the library?

  Suppose L is a stricty ordered list and suppose

             divide(L,FrontHalf,BackHalf)

is true if and only if FrontHalf is the front half of list L and
BackHalf is the back half of L, where for the sake of specificity we
will arbitrarily stipulate that FrontHalf and BackHalf either have equal
lengths or else the length of BackHalf is one greater than the length of
FrontHalf.

  Then
*/
  lookup(X,L) :-
    write('L='),write(L),nl,
    divide(L,FrontHalf,BackHalf),
    check_against(X,FrontHalf,BackHalf).
/*
where
*/
  check_against(X,FrontHalf,[Y|RestOfBackHalf]) :-
    X < Y ...
  check_against(X,FrontHalf,[Y|RestOfBackHalf]) :-
    X = Y ...
  check_against(X,FrontHalf,[Y|RestOfBackHalf]) :-
    X > Y ...

etc.

  It's really quite extraordinary how this works,
but the power of Prolog comes from the power of language,
not the other way around.

--

    "You do know how to whistle, don't you, Steve?"



Fri, 24 Jun 2005 10:05:44 GMT  
 Simple program in Prolog

Quote:
> Please explain what kind of binary search method you are supposed
> to use.

single-linked list ... it is important that this program can be consulted
in Amzi 16-bit Logic Explorer ver 3.3 Mar96 ...
 Thank you in advance ...


Sat, 25 Jun 2005 01:41:18 GMT  
 Simple program in Prolog
On Mon, 6 Jan 2003 18:41:18 +0100, "Nina Krmpoti?"

Quote:

>> Please explain what kind of binary search method you are supposed
>> to use.

>single-linked list ... it is important that this program can be consulted
>in Amzi 16-bit Logic Explorer ver 3.3 Mar96 ...
> Thank you in advance ...

OK, but what about going to the library and looking for books? What
about asking google for "prolog binary sarch"?.... It took me 10
seconds to find Prolog implementation of binary search.  Easier to
ask others to do the homework?...

A.L.



Sun, 26 Jun 2005 07:40:33 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Simple Prolog Program Needed

2. Simple Prolog Examples/Programs

3. Prolog/Lisp vs other languages (was Simple Prolog Question)

4. Simple Diagramming Program for Fortran Language Programs

5. Porting Turbo Prolog programs to ISO Prolog

6. How to call another Prolog program from a program

7. include a program Prolog in a program C

8. Programming in PROLOG vs. Programming in Logic

9. Programming in logic vs. Programming in PROLOG

10. simple messaging system in Prolog

11. simple scheduling in prolog?

12. a simple ( i hope ) prolog problem

 

 
Powered by phpBB® Forum Software