Page 1 of 1
shortest solutions
Posted: Fri Oct 17, 2008 5:00 am
by xrchz
I think it would be interesting to have the top 5 (or so) shortest solutions (programs or proofs) based on some simple measure like the number of characters just for the sake of comparing languages - seeing which languages use the fewest characters (these are a rough proxy for the fit of the language to the task).
Re: shortest solutions
Posted: Fri Oct 17, 2008 7:50 am
by jaap
I think J would win every time...
Re: shortest solutions
Posted: Fri Oct 17, 2008 12:03 pm
by stijn263
jaap wrote:I think J would win every time...
don't forget APL and K, they all look the same
The number of characters in J should be multiplied by some factor ([times]100 should make it comparable to assembly

)
Re: shortest solutions
Posted: Fri Oct 17, 2008 2:41 pm
by hk
In fact you are comparing "apples with pears".
After assembling the program in assembly is a standalone program that can be run on every machine with the same processor.
J, PARI, Mathematica come with a bulky interpreter to interpret your script.
To make it clearer:
When one writes some general code in some seperate units and calls routines from this unit by a very short name, your program could consist of just a few lines.
Nothing prevents me from making a separate unit for say every PE problem, name its calling function/procedure pxxx and call that from my main program. If I then count only the four characters of the call, I would always win.
Now J,PARI , Mathematica etc come with a lot of separate programs built in that you can call with their mnemonic. Does that
make for "very short programs"? That's quite similar to my hack, I think.
Re: shortest solutions
Posted: Fri Oct 17, 2008 3:24 pm
by daniel.is.fischer
Not quite as extreme, but the codesize rather measures available libraries than power of the language.
But four characters is unnecessarily verbose, even using only lowercase ASCII characters, two would last for several years still

Re: shortest solutions
Posted: Fri Oct 17, 2008 4:01 pm
by hk
I'd like my code somehow to reflect what it is about. Your proposal sounds me too much like the J mnemonics.
Re: shortest solutions
Posted: Wed Oct 22, 2008 12:07 am
by Ikcelaks
I'm not going to defend J's readability, but J's digraphs have usefulness for general problems, and the programs would still be short even if they used semi-meaningful identifiers, because the style of combining functions eliminates the need to name the parameters. The brevity is well-earned.
Re: shortest solutions
Posted: Wed Oct 22, 2008 2:12 am
by Harleqin
I think that for a meaningful benchmark, the individual programs or scripts should run on a reference system, and the time used be measured. This gets a bit hard for pen&paper solutions, of course.
Re: shortest solutions
Posted: Wed Oct 22, 2008 4:55 pm
by jdrandall123
Ikcelaks wrote:I'm not going to defend J's readability, but J's digraphs have usefulness for general problems, and the programs would still be short even if they used semi-meaningful identifiers, because the style of combining functions eliminates the need to name the parameters. The brevity is well-earned.
As a J partisan, I agree with this. I would add that J is an array language, so every variable is in principle a multidimensional array, and also a functional language. The latter gets used quite often, but may not be obvious. Here is a general implementation of Newton's method applied to two functions (written a bit more verbosely than usual):
Code: Select all
newton=:1 : '- u % u D. 1'
s=:3 : '(y^2)-2'
t=:3 : '(^.y)-1'
s newton^:_ (2)
1.41421
t newton^:_ (2)
2.71828