dividing list

From: Pere Montolio (tmp123_at_menta.net)
Date: 12/14/04

  • Next message: Georgios Tagalakis: "Re: Dividing Lists"
    Date: 14 Dec 2004 11:28:03 -0800
    
    

    In order to add one more posibility to the previous solutions:

    dividelist(A,B,C) :-
            length(A,L),
            L2 is L/2,
            length(B,L2),
            length(C,L2),
            append(B,C,A).

    OK, in this version it is valid only for even length, but it is
    easy to expand it to odd length, if necessary.

    In my opinion, (I'm not teacher, so it is only the opinion of
    a programmer), it has some interesting characteristics, and it
    seems no erroneous (until now):

    It is nice, because it is a single rule, not recursive, and matchs
     the human idea of the split: two list of same length that its
     append gives the parameter.

    It is 100% prolog, because it uses things like call to length with
    first parameter free (=unbound=variable, I do not know the word).

    It is fast, at least in SWI-prolog: 1000 executions for a list of 1000
    elements, for the solution of the previous post, takes 1.3 Minferences
    and 0.73 seconds CPU time. This one takes 0.45 Minferences and 0.57
    seconds (34% inferences and 78% time).

    (sorry if a post that several times, but I've some problems with
    my navigator and google).


  • Next message: Georgios Tagalakis: "Re: Dividing Lists"

    Relevant Pages

    • Re: Dividing Lists
      ... L2 is L/2, ... In my opinion, (I'm not teacher, so it is only the opinion of ... first parameter free. ... This one takes 0.45 Minferences and 0.57 ...
      (comp.lang.prolog)
    • Re: Dividing Lists
      ... L2 is L/2, ... In my opinion, (I'm not teacher, so it is only the opinion of ... first parameter free. ... This one takes 0.45 Minferences and 0.57 ...
      (comp.lang.prolog)
    • Re: Dividing Lists
      ... L2 is L/2, ... In my opinion, (I'm not teacher, so it is only the opinion of ... first parameter free. ... This one takes 0.45 Minferences and 0.57 ...
      (comp.lang.prolog)
    • Re: Dividing Lists
      ... L2 is L/2, ... In my opinion, (I'm not teacher, so it is only the opinion of ... first parameter free. ... This one takes 0.45 Minferences and 0.57 ...
      (comp.lang.prolog)
    • Re: Dividing Lists
      ... L2 is L/2, ... In my opinion, (I'm not teacher, so it is only the opinion of ... first parameter free. ... This one takes 0.45 Minferences and 0.57 ...
      (comp.lang.prolog)