TTA Perl Golf 2

Comments and discussion for articles on the site. To start a new thread, click "Post comment" from an article.

Moderators: Philippe, Tyler, Tony, Johnson

TTA Perl Golf 2

Postby Posting Bot on Wed Oct 25, 2006 3:44 pm

Johnson wrote:

Another Perl Golf challenge. If you know Perl, cool. If not, well, we're about to look like big nerds.

Full article: http://www.teamtotallyawesome.com/op_ed/300
User avatar
Posting Bot
Autonomous Process
 
Posts: 56
Joined: Mon Dec 27, 2004 3:57 pm
Location: Somerville, MA

Postby Tyler on Wed Oct 25, 2006 3:46 pm

Here is my 24 char solution, feel free to revise the hole if you want.
print"2\n3\n5\n13\n89\n"
Oh, I just wanted to see if I could run my own web server. It ain't some big deal like the main nerds would have you believe. This crud is fly-easy if you can make yourself care. - Ray Smuckles
User avatar
Tyler
Founding Member, Chief Morale Officer
 
Posts: 987
Joined: Thu Oct 30, 2003 1:33 pm
Location: in ur base cappin ur flag

Postby Johnson on Wed Oct 25, 2006 3:51 pm

Revised.

Ass.

(I thought it might be a little low under 100)
Steve wrote:Nintendo's like a deadbeat dad. It's really fun when he shows up on holidays, but the rest of the year it's just empty promises and false hope.
User avatar
Johnson
Founding Member, Faceless Warrior
 
Posts: 1408
Joined: Thu Oct 30, 2003 12:32 pm
Location: Andover, MA

Postby Tyler on Wed Oct 25, 2006 4:34 pm

Just so you know, this is the list of Fibonacci primes:
2, 3, 5, 13, 89, 233, 1597, 28657, 514229, 433494437, 2971215073

I'll go ahead and do the hole in the spirit that was intended though.
Oh, I just wanted to see if I could run my own web server. It ain't some big deal like the main nerds would have you believe. This crud is fly-easy if you can make yourself care. - Ray Smuckles
User avatar
Tyler
Founding Member, Chief Morale Officer
 
Posts: 987
Joined: Thu Oct 30, 2003 1:33 pm
Location: in ur base cappin ur flag

Postby Johnson on Thu Oct 26, 2006 9:49 am

My answer: 174 chars. I reserve the right to change, though I don't think I can reduce it any more.

In all honesty, it can only safely do up to about 5,000 before it segfaults, at least on this machine, but eh.

I've split it up on three lines to make it slightly easier to read. As such it's 176, but it's actually 174 when crammed together on one line.
$l=<>;$_=1;(1x$_)!~/^(11+)\1+$/&&push@p,$_ while($_++&&$_<=$l);
@f=(0,1);push@f,@f[-1]+@f[-2]while(@f[-1]<$l);
$c++&&grep(/^$c$/,@f)&&grep(/^$c$/,@p)&&print"$c\n"while($c<=$l);
Steve wrote:Nintendo's like a deadbeat dad. It's really fun when he shows up on holidays, but the rest of the year it's just empty promises and false hope.
User avatar
Johnson
Founding Member, Faceless Warrior
 
Posts: 1408
Joined: Thu Oct 30, 2003 12:32 pm
Location: Andover, MA

Postby Tyler on Thu Oct 26, 2006 6:05 pm

103
-n $a=$b=1;while(($b+=$a)<=$_){$a=$b-$a;push@f,$b}print$_,$/for grep{!grep{$num%$_==0}2..($num=$_)-1}@f
Oh, I just wanted to see if I could run my own web server. It ain't some big deal like the main nerds would have you believe. This crud is fly-easy if you can make yourself care. - Ray Smuckles
User avatar
Tyler
Founding Member, Chief Morale Officer
 
Posts: 987
Joined: Thu Oct 30, 2003 1:33 pm
Location: in ur base cappin ur flag

Postby Johnson on Thu Oct 26, 2006 6:12 pm

How do you run that? I'm semi-Perl-retarded, though I tried a variety of things.
Steve wrote:Nintendo's like a deadbeat dad. It's really fun when he shows up on holidays, but the rest of the year it's just empty promises and false hope.
User avatar
Johnson
Founding Member, Faceless Warrior
 
Posts: 1408
Joined: Thu Oct 30, 2003 12:32 pm
Location: Andover, MA

Postby Tyler on Fri Oct 27, 2006 9:58 am

If you're putting it in a file, put the "-n" on the shebang line, so like #!/usr/bin/perl -n
Oh, I just wanted to see if I could run my own web server. It ain't some big deal like the main nerds would have you believe. This crud is fly-easy if you can make yourself care. - Ray Smuckles
User avatar
Tyler
Founding Member, Chief Morale Officer
 
Posts: 987
Joined: Thu Oct 30, 2003 1:33 pm
Location: in ur base cappin ur flag

Postby Johnson on Fri Oct 27, 2006 10:02 am

Can't modify not in scalar assignment at tyler.pl line 2, near "1;"
Execution of tyler.pl aborted due to compilation errors.
Steve wrote:Nintendo's like a deadbeat dad. It's really fun when he shows up on holidays, but the rest of the year it's just empty promises and false hope.
User avatar
Johnson
Founding Member, Faceless Warrior
 
Posts: 1408
Joined: Thu Oct 30, 2003 12:32 pm
Location: Andover, MA

Postby Tyler on Fri Oct 27, 2006 12:31 pm

I can't replicate the error at all, did you try re-copy/pasting?
Oh, I just wanted to see if I could run my own web server. It ain't some big deal like the main nerds would have you believe. This crud is fly-easy if you can make yourself care. - Ray Smuckles
User avatar
Tyler
Founding Member, Chief Morale Officer
 
Posts: 987
Joined: Thu Oct 30, 2003 1:33 pm
Location: in ur base cappin ur flag

Postby mostL33T on Sat Oct 28, 2006 12:33 pm

Stole Tyler's solution and got it down to 73 chars:

-n $a=$b=1;while(($b+=$a)<=$_){$a=$b-$a;print$b,$/if!grep{$b%$_<1}2..$b-1}
User avatar
mostL33T
Registered User
 
Posts: 29
Joined: Wed Jan 14, 2004 4:03 am
Location: Maynard, MA

Postby Tyler on Mon Oct 30, 2006 10:57 am

nicely done
Oh, I just wanted to see if I could run my own web server. It ain't some big deal like the main nerds would have you believe. This crud is fly-easy if you can make yourself care. - Ray Smuckles
User avatar
Tyler
Founding Member, Chief Morale Officer
 
Posts: 987
Joined: Thu Oct 30, 2003 1:33 pm
Location: in ur base cappin ur flag

Postby Johnson on Mon Oct 30, 2006 11:20 am

Unfortunately, most's solution was posted after the deadline. Tyler's doesn't run on mere mortals' computers. Looks like I win. Again.
Steve wrote:Nintendo's like a deadbeat dad. It's really fun when he shows up on holidays, but the rest of the year it's just empty promises and false hope.
User avatar
Johnson
Founding Member, Faceless Warrior
 
Posts: 1408
Joined: Thu Oct 30, 2003 12:32 pm
Location: Andover, MA

Postby Tyler on Mon Oct 30, 2006 12:51 pm

oh are you wrong about that
Oh, I just wanted to see if I could run my own web server. It ain't some big deal like the main nerds would have you believe. This crud is fly-easy if you can make yourself care. - Ray Smuckles
User avatar
Tyler
Founding Member, Chief Morale Officer
 
Posts: 987
Joined: Thu Oct 30, 2003 1:33 pm
Location: in ur base cappin ur flag


Return to Article Discussion

Who is online

Users browsing this forum: No registered users and 0 guests

cron