[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Jan 10 18:44:15 2003 
Subject:Forwarded: Re: Silly Pop-11 Programming Challenge 2003 
From:A . Sloman 
Volume-ID:1030110.01 

Non-member submission from [David Young <davidy@cogs.susx.ac.uk>]
Date: Fri, 10 Jan 2003 18:30:23 +0000 (GMT)

Well having been trumped by Steve's own entry (it goes faster than mine,
in case you haven't checked - its other merits are apparent), I thought
I'd have a crack at the "simple, transparent, concise" prize. (I can't
remember if those are amongst the judging criteria, but it seems in the
spirit of the thing to make up my own.)

However, this isn't so easy in Pop-11, so I've gone for the "cheating"
prize too, as you'll see. Here, then, is my latest version - not fast,
only does lists (though of course that is easy to fudge) - but the core
code is just two lines (or 4 if you count the rather standard definition
of delete), and the rest is a wrapper to pay lip service to the Pop-11
part of the challenge.

I'll also stake a claim for the Jonathan Cunningham "get it done
quickly" prize - this one didn't take long at all, honest, and was right
at the first or second go. Neither statement was true for the previous
attempt.

This seems to be a two-horse race. I guess everyone else must have real
work to do, or else like crosswords or surfing.

David

----------------------------------------------------------------------

uses ploginpop

prolog_compile(stringin('                                              \
    delete(A, [A|L], L).                                               \
    delete(A, [X|L1], [X|L2]) :- delete(A, L1, L2).                    \
    permutation([], []).                                               \
    permutation(L1, [A|L2]) :- delete(A, L1, L3), permutation(L3, L2). \
'));


define perm_list(l) /* -> rep */;
    lvars p, plog_perm_list = |< permutation(^l, ?p) >|;
    lconstant expired = mishap(% 0, 'Calling expired permutation repeater' %);

    procedure /* -> perm */;
        if plog_perm_list() then
            p
        else
            expired -> plog_perm_list;
            termin
        endif
    endprocedure

enddefine;