Perl golf wrap up.

| 2 Comments
First off before I get too far, you can copy/paste these from the browser into an editor and it should 'unmuck' properly there. My windows XP machine did anyway. If it is a real problem, ask in the comments, filling in your email address in the comment form and I will send you this post plaintext, or you can check out the nopaste

At my office Samy Kamkar blew everybody out of the water with an awesome 64 character sort replacement:

map{$b=-1;1while$_>$y[++$b]&$b<@y;splice@y,$b,0,$_}@ARGV;print@y

I did modify each of the following to have print@A instead of print"@A" for a consistent print without spaces, and a cost savings of 2 characters.

Hobbs also gets an honerable mention at 97 characters:
@A=@ARGV;{$R|=$A=@A>1&&$A[0]>$A[1];push@G,splice@A,$A,1;@A&&redo;(@A,@G,$R)=@G,redo if$R}print@G


however Chas Owens produced the best seen here at 82 characters f:for$n(@ARGV){$s[$_]>$n&&splice(@s,$_,0,$n)>next f for 0..$#s;push@s,$n};print@s

Thank you everybody for participating. I enjoyed the submissions

2 Comments

If we limit the numbers to non-negative integers we can reduce it to 40 characters:

$A[$_]=$_ for@ARGV;print grep defined,@A

I was inspired to think about it again by this: http://jwz.livejournal.com/1278701.html

About this Entry

This page contains a single entry by leonard published on August 13, 2010 10:29 AM.

Vacation was the previous entry in this blog.

tail -f in perl is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.