Perl Challenge: Code Golf [ 2 ]

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 9020 Views - Last Post: 25 September 2012 - 06:59 PM

#1 jumptrooper  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 68
  • View blog
  • Posts: 234
  • Joined: 19-August 10

Perl Challenge: Code Golf [ 2 ]

Post icon  Posted 15 February 2011 - 02:53 PM

Code Golf: Round 2!



Objective: Create an entire* Perl script, in as few characters as possible, that outputs the first 34 rows of Pascal's Triangle. The point is to generate the correct answer with the smallest amount of code.

Required output: You program should produce this, and nothing else.

Other Stuff: Bonus points for doing this in Perl! (Bonus points are good!) If you want to try it in another language, you are more than welcome to. To submit your entry, reply to this post and paste your code in "spoiler" tags. This challenge was originally create by the wonderful people at www.codegolf.com.

*Note: We are looking for a complete program - not just a subroutine. Someone should be able to paste your code into a file, save it, and run it with "perl filename.pl".


Have fun! :donatello:

This post has been edited by jumptrooper: 15 February 2011 - 05:19 PM


Is This A Good Question/Topic? 3
  • +

Replies To: Perl Challenge: Code Golf [ 2 ]

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1102
  • View blog
  • Posts: 6,909
  • Joined: 07-September 06

Re: Perl Challenge: Code Golf [ 2 ]

Posted 15 February 2011 - 04:20 PM

Well, I managed to do it in 173 total characters (including the #! up top):

A bit more information:
2 subs
3 loops


<edit>
172
155
</edit>

Spoiler

Was This Post Helpful? 1
  • +
  • -

#3 jumptrooper  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 68
  • View blog
  • Posts: 234
  • Joined: 19-August 10

Re: Perl Challenge: Code Golf [ 2 ]

Posted 15 February 2011 - 05:44 PM

View PostBetaWar, on 15 February 2011 - 03:20 PM, said:

Well, I managed to do it in 173 total characters (including the #! up top):

A bit more information:
2 subs
3 loops


<edit>
172
</edit>

Spoiler

Very nice! I have sad (but easily fixed) news for you though: it doesn't print the very last row required by the specifications. Otherwise, very nice! +50 BONUS POINTS for using Perl!

I did notice a few things that could improve it though - in a few places you didn't put semi-colons (which Perl actually lets skate by), you could hack out some semi-colons in other spots to further reduce the character count. Also - another dirty/non-best-practice-but-it-still-works trick is to omit the beginning "#!..." line. when you run a Perl script using the "perl" command, you can get away without using it. You need that line if you want the program to run all on its own, like a built-in command.
:)
Was This Post Helpful? 0
  • +
  • -

#4 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1102
  • View blog
  • Posts: 6,909
  • Joined: 07-September 06

Re: Perl Challenge: Code Golf [ 2 ]

Posted 15 February 2011 - 11:20 PM

Ah, yeah thanks about the last row. It is difficult since my windows box doesn't seem to allow redirection of output to file, so I can't view the output except for in the command prompt (which sucks). It should be fixed now (off by 1).

As for the semi-colons things I think I have as few semi-colons in the program as I can have without adding whitespace which would be required for the program to run properly. I may be wrong though, this is only the second thing I have done with perl.
Was This Post Helpful? 0
  • +
  • -

#5 madblogr  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 29-March 09

Re: Perl Challenge: Code Golf [ 2 ]

Posted 16 February 2011 - 09:21 AM

160 char
2 loops
2 subs

Spoiler

Was This Post Helpful? 1
  • +
  • -

#6 jumptrooper  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 68
  • View blog
  • Posts: 234
  • Joined: 19-August 10

Re: Perl Challenge: Code Golf [ 2 ]

Posted 16 February 2011 - 09:23 AM

View PostBetaWar, on 15 February 2011 - 10:20 PM, said:

Ah, yeah thanks about the last row. It is difficult since my windows box doesn't seem to allow redirection of output to file, so I can't view the output except for in the command prompt (which sucks). It should be fixed now (off by 1).

As for the semi-colons things I think I have as few semi-colons in the program as I can have without adding whitespace which would be required for the program to run properly. I may be wrong though, this is only the second thing I have done with perl.


Huh... that's odd... My Windows machine let me redirect my output...
I used perl filename.pl > out.txt

About your other point, you may be right - I didn't actually try taking out the other semi-colons. Also, it's fine if you have your code formatted - it doesn't need to be condensed down to a couple lines. :)

This post has been edited by jumptrooper: 16 February 2011 - 09:24 AM

Was This Post Helpful? 0
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: Perl Challenge: Code Golf [ 2 ]

Posted 16 February 2011 - 10:07 AM

I think 131? (Can someone double check!)
1 Loop, 1 Sub.
Spoiler

This post has been edited by AdamSpeight2008: 16 February 2011 - 10:09 AM

Was This Post Helpful? 0
  • +
  • -

#8 jumptrooper  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 68
  • View blog
  • Posts: 234
  • Joined: 19-August 10

Re: Perl Challenge: Code Golf [ 2 ]

Posted 16 February 2011 - 10:36 AM

View Postmadblogr, on 16 February 2011 - 08:21 AM, said:

160 char
2 loops
2 subs

Spoiler

Well done! +50 BONUS POINTS to you!
Was This Post Helpful? 0
  • +
  • -

#9 jumptrooper  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 68
  • View blog
  • Posts: 234
  • Joined: 19-August 10

Re: Perl Challenge: Code Golf [ 2 ]

Posted 16 February 2011 - 10:42 AM

View PostAdamSpeight2008, on 16 February 2011 - 09:07 AM, said:

I think 131? (Can someone double check!)
1 Loop, 1 Sub.
Spoiler

Nice work! Your output is good. And yes, +50 BONUS POINTS!!! The judges also decree +13 EXTRA POINTS for lowest score so far and only one sub routine!
Was This Post Helpful? 0
  • +
  • -

#10 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: Perl Challenge: Code Golf [ 2 ]

Posted 16 February 2011 - 11:40 AM

What do I get for no sub and no loop?
Spoiler

This post has been edited by AdamSpeight2008: 16 February 2011 - 11:43 AM

Was This Post Helpful? 1
  • +
  • -

#11 jumptrooper  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 68
  • View blog
  • Posts: 234
  • Joined: 19-August 10

Re: Perl Challenge: Code Golf [ 2 ]

Posted 16 February 2011 - 12:14 PM

View PostAdamSpeight2008, on 16 February 2011 - 10:40 AM, said:

What do I get for no sub and no loop?
Spoiler


+10 DIRTY TRICK POINTS with a x3 COMBO MULTIPLIER :taz:

The judges have gathered and have decreed that all submissions must do their own grunt work! No copying off their neighbors(website)!

Violators will be punished with shaming emoticons!!

So say-eth the illustrious judges!!
Was This Post Helpful? 0
  • +
  • -

#12 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: Perl Challenge: Code Golf [ 2 ]

Posted 16 February 2011 - 02:06 PM

Down to 114c now.
Spoiler

Was This Post Helpful? 0
  • +
  • -

#13 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: Perl Challenge: Code Golf [ 2 ]

Posted 16 February 2011 - 04:08 PM

I think this one is 82c (First one under 100 :punk: )
Spoiler

Update: 78c
Spoiler

This post has been edited by AdamSpeight2008: 16 February 2011 - 04:26 PM

Was This Post Helpful? 1
  • +
  • -

#14 jumptrooper  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 68
  • View blog
  • Posts: 234
  • Joined: 19-August 10

Re: Perl Challenge: Code Golf [ 2 ]

Posted 16 February 2011 - 05:46 PM

View PostAdamSpeight2008, on 16 February 2011 - 03:08 PM, said:

I think this one is 82c (First one under 100 :punk: )
Spoiler

Update: 78c
Spoiler

I think that one is 212c, but nice job on the 78c one :) ... except that it prints an extra line, but that's not a big deal.

This post has been edited by jumptrooper: 16 February 2011 - 05:49 PM

Was This Post Helpful? 0
  • +
  • -

#15 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: Perl Challenge: Code Golf [ 2 ]

Posted 16 February 2011 - 06:29 PM

First one (82c) was a bad copy n paste job, as it copied twice.
Spoiler

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2