Wednesday, January 14, 2009

Best. Perl Script. Ever.

A user recently asked:
What has been your best programming experience so far?
The most successful program I've ever written was this Perl script:
map(($r=$_,map(($y=$r-$_/3,$l[24-$r]
.=(
' ','@')[$y**2-20*$y+($_**2)/3<0]),(0..30)),),(0..24));
print join("\n", map(reverse($_).$_, @l)), "\n";

I wrote this for a woman I was dating in 2001. Writing a Perl script for my girlfriend is not as geeky as it sounds, at least in this case. She's also a software developer, and she was taking a Perl class at the time.

I consider this script a great success because she married me in 2007!

I'll leave it as an exercise for the reader to run the script in a console window and see its output (I promise it's not a Trojan Horse or any other kind of evil trick).


I'm posting to my blog the questions I've answered on StackOverflow, which earned the "Good Answer" badge. This was based on my answer to "What is your best programming experience?"

10 comments:

Elise said...

Just ran this script... All I can say is "aww..." and that was extremely nifty!

Colby Gatte said...

Oh my! Extremely clever. I am saving this (with, of course, a link to this page)

PIYUSH said...

hey it's awesome!!!

Amol Parnaik said...

That's brilliant!

Amol Parnaik said...

That's brilliant!

Amol Parnaik said...

That's brilliant!

Cleyton said...

Wonderful!

sandeepsasi said...

Indeed a wonderful script...!!!

Is the motivation behind this 1:

perl -le 'map {$y = $_ / 15; print map {("@", " ")[(-57 > $_ || $_ > -53) && ($_ ** 2 / 1250 + $y ** 2 - 1) ** 3 > $_ ** 2 * $y ** 3 / 2500 && 0.2 * ($_ - 60) ** 2 - 18 > 15 * $y || 15 * $y > ($_ - 60) ** 2 - 15]} -75..75 } reverse -18..18'

Bill Hallahan said...

Kudos. That IS the best perl script ever. No arguing with results!

Shubham Agarwal said...

Awesome...