Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > [ANN] Code Golf Challenge : 1,000 Digits Of Pi

Reply
Thread Tools

[ANN] Code Golf Challenge : 1,000 Digits Of Pi

 
 
Carl Drinkwater
Guest
Posts: n/a
 
      09-18-2006
Hi all,

Code Golf's 12th challenge has just been added to the site. It asks you
to calculate the first 1,000 digits of Pi - Something I'm sure most of
you have thought about, but never done. You can see the challenge at :

http://codegolf.com/1000-digits-of-pi

For those who haven't heard of codegolf.com, it can be described as
"allowing you to show off your code-fu by trying to solve coding
problems using the least number of keystrokes."

The site currently supports Perl, PHP, Python and Ruby with Scheme to
(hopefully) follow soon. Your entries are automatically executed and
scored - No need to wait for someone to validate your code.

Other challenges include implementing the Vigenere Cipher, Prime
factors, SHA-256 Hashing as well as the obvious 99 Bottles Of Beer. All
of the challenges are competitive but there is still scope to well in
them, even if you're new to the site.

I hope some of you will find this interesting, and sorry for disturbing
you if not!

Have fun,
Carl.


 
Reply With Quote
 
 
 
 
James Edward Gray II
Guest
Posts: n/a
 
      09-18-2006
On Sep 18, 2006, at 5:33 AM, Carl Drinkwater wrote:

> Hi all,
>
> Code Golf's 12th challenge has just been added to the site. It
> asks you to calculate the first 1,000 digits of Pi - Something I'm
> sure most of you have thought about, but never done. You can see
> the challenge at :
>
> http://codegolf.com/1000-digits-of-pi


Darn it! They blocked my attempt to use open-uri. How's a guy
suppose to cheat with these restrictions. Sheesh!

James Edward Gray II

require"open-uri";puts"3."+open("http://www.joyofpi.com/
pi.html").read.gsub(/\s/,"")[/\d{1000}/]

 
Reply With Quote
 
 
 
 
Harold Hausman
Guest
Posts: n/a
 
      09-18-2006
On 9/18/06, James Edward Gray II <> wrote:
> On Sep 18, 2006, at 5:33 AM, Carl Drinkwater wrote:
>
> > Hi all,
> >
> > Code Golf's 12th challenge has just been added to the site. It
> > asks you to calculate the first 1,000 digits of Pi - Something I'm
> > sure most of you have thought about, but never done. You can see
> > the challenge at :
> >
> > http://codegolf.com/1000-digits-of-pi

>
> Darn it! They blocked my attempt to use open-uri. How's a guy
> suppose to cheat with these restrictions. Sheesh!
>
> James Edward Gray II
>
> require"open-uri";puts"3."+open("http://www.joyofpi.com/
> pi.html").read.gsub(/\s/,"")[/\d{1000}/]
>


idk James, that might change it from an exercise in code-fu into an
exercise in who-has-the-shortest-domain-name-fu..

Anyone have any idea how they're safely running the code on the server?

Freaky freaky sandbox action?

-Harold

 
Reply With Quote
 
Carl Drinkwater
Guest
Posts: n/a
 
      09-18-2006
Hi,

>> http://codegolf.com/1000-digits-of-pi

>
> Darn it! They blocked my attempt to use open-uri. How's a guy suppose
> to cheat with these restrictions. Sheesh!


We wouldn't want to make it too easy for you!

> require"open-uri";puts"3."+open("http://www.joyofpi.com/pi.html").read.gsub(/\s/,"")[/\d{1000}/]


Believe it or not, someone is 30-odd bytes better than that and he's
(presumably) actually calculating the digits!

Regards,
Carl.

 
Reply With Quote
 
Carl Drinkwater
Guest
Posts: n/a
 
      09-18-2006
Hi Harold,

> Anyone have any idea how they're safely running the code on the server?
>
> Freaky freaky sandbox action?


No, Freaky freaky jail-and-chroot action - We can support pretty much
any language that way. I might finally get round to writing an article
about how we're doing it, but I've been saying that for months, so I
wouldn't hold my breath!

Regards,
Carl.

 
Reply With Quote
 
James Edward Gray II
Guest
Posts: n/a
 
      09-18-2006
On Sep 18, 2006, at 5:33 AM, Carl Drinkwater wrote:

> Hi all,
>
> Code Golf's 12th challenge has just been added to the site. It
> asks you to calculate the first 1,000 digits of Pi - Something I'm
> sure most of you have thought about, but never done. You can see
> the challenge at :
>
> http://codegolf.com/1000-digits-of-pi


Another blocked cheat! These people clearly do not appreciate
cheating as they should.

James Edward Gray II

#!ruby -rbigdecimal -rbigdecimal/math
include BigMath;puts"3."+BigDecimal.PI(t=1000).to_s[3,t]


 
Reply With Quote
 
John Carter
Guest
Posts: n/a
 
      09-18-2006
On Mon, 18 Sep 2006, James Edward Gray II wrote:

> Another blocked cheat! These people clearly do not appreciate cheating as
> they should.
>
> James Edward Gray II
>
> #!ruby -rbigdecimal -rbigdecimal/math
> include BigMath;puts"3."+BigDecimal.PI(t=1000).to_s[3,t]



Indeed they should appreciate it...
http://www.schneier.com/crypto-gram-0609.html#12

John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email :
New Zealand

"We have more to fear from
The Bungling of the Incompetent
Than from the Machinations of the Wicked." (source unknown)

 
Reply With Quote
 
Martin S. Weber
Guest
Posts: n/a
 
      09-19-2006
On Mon, Sep 18, 2006 at 07:33:57PM +0900, Carl Drinkwater wrote:
> (...)
> I hope some of you will find this interesting, and sorry for disturbing
> you if not!


Code golfing is not for me, yet watching others do is very amusing.
So when will the submitted entries be open to public ?

-Martin

 
Reply With Quote
 
Patrick Hurley
Guest
Posts: n/a
 
      09-19-2006
On 9/18/06, Martin S. Weber <> wrote:
> On Mon, Sep 18, 2006 at 07:33:57PM +0900, Carl Drinkwater wrote:
> > (...)
> > I hope some of you will find this interesting, and sorry for disturbing
> > you if not!

>
> Code golfing is not for me, yet watching others do is very amusing.
> So when will the submitted entries be open to public ?
>
> -Martin
>
>


They are still discussing it on their forums, but I just looked today
and tried out the 99 bottles of beer. I have the shortest Ruby (202
bytes), but I am only tied for 10th place overall. The best Perl entry
is kicking my butt at 176 bytes. I think this is probably due to the
slightly more verbose string interpolation in Ruby, but I am
interested in what could be done to further shrink my script:

@a='#{n} bottle#{n>1?""} of beer'
@b=" on the wall"
(n=99).times{puts eval"\"#@a#@b, #@a.\n\#{n-=1;n<1?(n=99;'Go to the
store and buy some more'):'Take one down and pass it around'},
#@a#@b.\n\n\""}

pth

 
Reply With Quote
 
Carl Drinkwater
Guest
Posts: n/a
 
      09-19-2006
Hi Patrick,

> They are still discussing it on their forums, but I just looked today
> and tried out the 99 bottles of beer. I have the shortest Ruby (202
> bytes), but I am only tied for 10th place overall. The best Perl entry
> is kicking my butt at 176 bytes. I think this is probably due to the
> slightly more verbose string interpolation in Ruby, but I am
> interested in what could be done to further shrink my script:


Very good attempt! Unfortunately, the shortest Ruby is 186 bytes, but
both people who have got that score have better solutions in Perl, so
their Ruby entries don't show on the Overall Leaderboard. (Each
language is scored individually as well as there being an overall
leaderboard.)

> @a='#{n} bottle#{n>1?""} of beer'
> @b=" on the wall"
> (n=99).times{puts eval"\"#@a#@b, #@a.\n\#{n-=1;n<1?(n=99;'Go to the
> store and buy some more'):'Take one down and pass it around'},
> #@a#@b.\n\n\""}


You can save three bytes by including a literal newline instead of \n :

http://pastie.caboo.se/13961

I'm sure you can shave more bytes of it!

Regards,
Carl.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
any tricks to golf this code further? luser- -droog C Programming 7 09-11-2011 05:50 AM
code challenge: generate minimal expressions using only digits 1,2,3 Trip Technician Python 12 02-27-2009 04:49 AM
[ANN] Code Golf Challenge : Oblongular Number Spirals Carl Drinkwater Ruby 19 09-29-2006 06:47 PM
Re: [ANN] Code Golf Challenge : 1,000 Digits Of Pi Calvin Spealman Python 3 09-19-2006 12:22 PM
[ANN] Code Golf Challenge : 1,000 Digits Of Pi Carl Drinkwater Python 7 09-18-2006 09:49 PM



Advertisments