Page 1 of 1

Terrible at introductions so let's hop right to it

PostPosted: Mon Oct 09, 2017 2:02 am
by Phillip Odam
As Doug phrased it, I'm a late member of the flood from facebook after that vice video about him. If I haven't already lost you let's move on.

So I fell across this old post viewtopic.php?f=13&t=940 and Doug showed off the succinctness and some may say the beauty of Perl. The final, shortest solution being

#!/usr/bin/perl
$\ = $/;
for (0 .. 9) {print}

So of course I was left wondering could this be shortened. But before moving ahead, the length of that solution with all unnecessary whitespace removed is as follows

$\=$/;for(0..9){print}

My first shortening was to move the print to before the for loop (don't recall the name of this coding format, let's call it statement prior to control) so we can drop the curlies around the print and the parentheses on the for loop condition

$\=$/;print for 0..9

Remaining with this code format we can drop the assignment and instead explicitly detail what is to be printed. You'll notice the typical whitespace between print and the double qoute and between double quote and for is actually optional

print"$_$/"for 0..9

Lastly, we can save another character by dropping the quotes and concatenate the strings using period

print$_.$/for 0..9

And now in long form :-)

#!/usr/bin/perl
print $_ . $/ for 0 .. 9

Here's an attempt with an alternative approach which performs one print statement for all 10 lines by joining the range/array together with the new line character sequence. The blank string literal is included since the new line character sequence is only used to join two adjoining array elements, meaning no new line would be appended after the 9 if the blank weren't included

print join $/,(0..9,"")

However as you can see this is actually longer than what we'd started with, so much for that! Now, perhaps we get even shorter by having Perl write out and execute machine code... but can you really say that's a Perl solution

Re: Terrible at introductions so let's hop right to it

PostPosted: Mon Oct 09, 2017 6:28 pm
by Doug Coulter
I almost beat even that, using say, but by the time you add use Modern::Perl...it's not good anymore. Maybe after installing a later version, but that's kinda cheating.
The reason many people flinch when you mention perl, and worse with golf is: https://everything2.com/title/SelfGOL
The craziest golf ever, by probably the smartest guy in the community.

While it's fun, these days I kinda strive to go the other way - un obfuscate, I type fast and neither I or my computer care much about keystrokes, just how long it takes to get the answer from here.
But it's still a fun game...

Oh, and welcome aboard!

Re: Terrible at introductions so let's hop right to it

PostPosted: Tue Jan 09, 2018 6:45 am
by RB Blackstone
Wow. Very cool.

Tight code is fascinating, but I like to write un-obfuscated code for the next guy.

The next guy is usually me. I may not be able to build that house of cards in my head the second time.

Still, it is cool to see.

-RB

Re: Terrible at introductions so let's hop right to it

PostPosted: Tue Jan 09, 2018 11:39 am
by Donovan Ready
Ditto, RB. I don't have to edit my code very often, but when I do I like to be able to... :mrgreen:

Welcome, Phillip!

Re: Terrible at introductions so let's hop right to it

PostPosted: Thu Jan 11, 2018 9:22 pm
by Doug Coulter
Golf is fun if the goal is well-defined. I just make it up on comments...half my comments anyway are about the code that doesn't have to be there to check the stuff I know the state of anyway.