The examples used here are from the weekly challenge problem statement and demonstrate the working solution.
You are given a list of numbers. Write a script to implement JortSort. It should return true/false depending if the given list of numbers are already sorted.
:-initialization(main). jort(). jort([H0, H1|]):- H1 >= H0. jort([H0, H1|T]):- H1 >= H0, jort([H1|T]). main:- (jort([1, 2, 3, 4, 5]), format("1~n", _); format("0~n", _)), (jort([1, 3, 2, 4, 5]), format("1~n", _); format("0~n", _)), (jort([1, 2, 3, 4, 5, 6]), format("1~n", _); format("0~n", _)), halt.
$ gplc prolog/ch-1.p $ prolog/ch-1 1 0 1
Anyway, this is pretty easily done in Prolog especially in this case where we only are
to be given a list of numbers. The code as written only goes in one direction in that it
only verifies a list as requested. This could go in the other direction with a little
between/3 and generate a sorted list too. But would that ruin the joke? Make it
funnier? I found the whole exercise so unamusing I didn't bother!
Maybe the amusing part of this whole "joke" sort was, ironically, just how stupid I found the whole thing.