shortest solutions

Announcements, comments, ideas, feedback, and "How do I... ?" questions
Post Reply
xrchz
Posts: 2
Joined: Fri Oct 17, 2008 4:55 am

shortest solutions

Post 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).
User avatar
jaap
Posts: 588
Joined: Tue Mar 25, 2008 3:57 pm
Contact:

Re: shortest solutions

Post by jaap »

I think J would win every time...
User avatar
stijn263
Posts: 1505
Joined: Sat Sep 15, 2007 11:57 pm
Location: Netherlands

Re: shortest solutions

Post 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 :D)
User avatar
hk
Administrator
Posts: 12831
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: shortest solutions

Post 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.
Image
War ruins the life and health of untold numbers of innocent children.
User avatar
daniel.is.fischer
Posts: 2400
Joined: Sun Sep 02, 2007 11:15 pm
Location: Bremen, Germany

Re: shortest solutions

Post 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 :lol:
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
User avatar
hk
Administrator
Posts: 12831
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: shortest solutions

Post by hk »

I'd like my code somehow to reflect what it is about. Your proposal sounds me too much like the J mnemonics.
Image
War ruins the life and health of untold numbers of innocent children.
Ikcelaks
Posts: 28
Joined: Wed Oct 15, 2008 9:08 pm

Re: shortest solutions

Post 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.
Harleqin
Posts: 6
Joined: Sat Oct 18, 2008 1:19 pm

Re: shortest solutions

Post 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.
User avatar
jdrandall123
Posts: 65
Joined: Sun Mar 26, 2006 11:57 am
Location: New York, USA

Re: shortest solutions

Post 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
Post Reply