Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   [QUIZ] Digits of Pi (#202) (http://www.velocityreviews.com/forums/t857138-quiz-digits-of-pi-202-a.html)

 Daniel Moore 04-24-2009 09:05 PM

[QUIZ] Digits of Pi (#202)

-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=
=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-

The three rules of Ruby Quiz:

1. Please do not post any solutions or spoiler discussion for this
quiz until 48 hours have elapsed from the time this message was
sent.

2. Support Ruby Quiz by submitting ideas and responses
as often as you can!
Visit: <http://rubyquiz.strd6.com/suggestions>

3. Enjoy!

Suggestion: A [QUIZ] in the subject of emails about the problem
helps everyone on Ruby Talk follow the discussion. Please reply to
the original quiz message, if you can.

RSS Feed: http://rubyquiz.strd6.com/quizzes.rss

-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=
=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-

## Digits of Pi (#202)

Geia sas Rubyists,

Pi or =F0 is a mathematical constant whose value is the ratio of any
circle's circumference to its diameter in Euclidean space. Because =F0
is an irrational number, its decimal expansion never ends and does not
repeat. This infinite sequence of digits has fascinated mathematicians
and laymen alike, and much effort over the last few centuries has been
put into computing more digits and investigating the number's
properties.[1]

This week's quiz is to write a Ruby program that can compute the first
100,000 digits of =F0.

[1]: http://en.wikipedia.org/wiki/Pi

Have Fun!
--=20
-Daniel
http://rubyquiz.strd6.com

 Joel VanderWerf 04-24-2009 09:37 PM

Re: [QUIZ] Digits of Pi (#202)

Daniel Moore wrote:
> This week's quiz is to write a Ruby program that can compute the first
> 100,000 digits of ð.

Bonus points for determining the first non-trivial ruby program encoded
in that sequence of digits.

(Represent a program source string as a sequence of octal triplets that
is, or is not, a subsequence of the octal representation of ð.)

Non-trivial means not "", not just a literal, etc. Be imaginative.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

 Todd Benson 04-25-2009 02:53 AM

Re: [QUIZ] Digits of Pi (#202)

2009/4/24 Joel VanderWerf <vjoel@path.berkeley.edu>:
> Daniel Moore wrote:
>>
>> This week's quiz is to write a Ruby program that can compute the first
>> 100,000 digits of =F0.

>
> Bonus points for determining the first non-trivial ruby program encoded i=

n
> that sequence of digits.

Do you mean non-trivial in that it will never fail with the correct
initial conditions? Or simply that it's syntactically correct?

 Joel VanderWerf 04-25-2009 02:57 AM

Re: [QUIZ] Digits of Pi (#202)

Todd Benson wrote:
> 2009/4/24 Joel VanderWerf <vjoel@path.berkeley.edu>:
>> Daniel Moore wrote:
>>> This week's quiz is to write a Ruby program that can compute the first
>>> 100,000 digits of ð.

>> Bonus points for determining the first non-trivial ruby program encoded in
>> that sequence of digits.

>
> Do you mean non-trivial in that it will never fail with the correct
> initial conditions? Or simply that it's syntactically correct?

I dunno. That's why I said be imaginative :)

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

 Joel VanderWerf 04-25-2009 03:13 AM

Re: [QUIZ] Digits of Pi (#202)

Jeff Schwab wrote:
> Joel VanderWerf wrote:
>> Daniel Moore wrote:
>>> This week's quiz is to write a Ruby program that can compute the first
>>> 100,000 digits of ð.

>>
>> Bonus points for determining the first non-trivial ruby program
>> encoded in that sequence of digits.

>
> Interesting idea!
>
> Is there any way of determining whether a given sequence of bytes is a
> valid ruby program, other than running it? If this were my paternus
> lingua, C++, I would start by chucking each candidate sequence at a
> compiler.
>
>> (Represent a program source string as a sequence of octal triplets
>> that is, or is not, a subsequence of the octal representation of ð.)

>
> What is an "octal triplet?" Do you mean that the integer value of each
> byte in the source code should be represented by a sequence of three
> octal digits (e.g. 077 for ?? and 141 for ?a)?
>
> I'm curious: Why octal? It seems an odd choice, given that an "octal
> triplet" corresponds to 9 bits, rather than the 8 in a standard byte.
> Why not "hex pairs?"

You're right, that didn't make much sense. I was just thinking of "\nnn"
and counting to three, but of course that's 9 bits. What I was trying
to do was slice off just enough bits to make a printable char with high
probability. Otherwise, the 128..255 will keep breaking up otherwise
legal program strings.

Base 128 (7 bits) would be better, but there are still some non-printing
chars. Even better would be to skip ascii and use something else, but I
didn't want to get too far into fantasy land...

> Btw, isn't every finite sequence of digits a subsequence of Pi's
> representation in that base? Or is that unknowable?

IIRC that's true. But the _first_ ruby program... gee, that's got to
mean something. :)

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

 Harry Kakueki 04-27-2009 01:09 AM

Re: [QUIZ] Digits of Pi (#202)

>
> This week's quiz is to write a Ruby program that can compute the first
> 100,000 digits of =F0.
>
>

# Is this cheating ? :)

require 'bigdecimal'
require 'bigdecimal/math'
include BigMath

puts PI(100_000)

Harry

--=20
A Look into Japanese Ruby List in English
http://www.kakueki.com/ruby/list.html

 Robert Dober 04-27-2009 05:49 AM

Re: [QUIZ] Digits of Pi (#202)

2009/4/27 Harry Kakueki <list.push@gmail.com>:
>>
>> This week's quiz is to write a Ruby program that can compute the first
>> 100,000 digits of =F0.
>>
>>

>
> # Is this cheating ? =A0:)

I would say no, but...
I honestly could not come up with a solution, always getting confused
how many significant digits I need in the involved constants. Thus I
am really looking forward to the solutions and the summary. (Distant
memories tell me I should do some range arithmetics, we will see)
Sorry to say Harry, but your solution has not enlightened me on the topic ;=
).
Cheers
Robert

 Todd Benson 04-27-2009 06:12 AM

Re: [QUIZ] Digits of Pi (#202)

2009/4/27 Robert Dober <robert.dober@gmail.com>:
> 2009/4/27 Harry Kakueki <list.push@gmail.com>:
>>>
>>> This week's quiz is to write a Ruby program that can compute the first
>>> 100,000 digits of =F0.
>>>
>>>

>>
>> # Is this cheating ? :)

> I would say no, but...
> I honestly could not come up with a solution, always getting confused
> how many significant digits I need in the involved constants. Thus I
> am really looking forward to the solutions and the summary. (Distant
> memories tell me I should do some range arithmetics, we will see)
> Sorry to say Harry, but your solution has not enlightened me on the topic=

;).
> Cheers
> Robert

For what it's worth, I tried a Gauss-Legendre and it halted my PC at a
delta of 1e-10 and smaller (only 10 good digits), and then started to
diverge pretty rapidly, so much so that the program would halt (yes, I
simply sat there and hit the gets over and over). I then tried
Srinavasa's method, and it converged so quickly to 10 places, and
never gave up after that, but it took about 3 hours to run k up to
1024 (without my intervention), which amounts to around 12_000 correct
places.

There's Daniel Shanks, which I might try my hand at eventually, but
the winner for this programming language might end up being
brute-force by-digit deterministic approach mentioned by one of the
first posters.

I think, Robert, cheating would be writing a program that grabs the
digits from the website :)

Todd

 Robert Dober 04-27-2009 01:15 PM

Re: [QUIZ] Digits of Pi (#202)

2009/4/25 Joel VanderWerf <vjoel@path.berkeley.edu>:
>> Btw, isn't every finite sequence of digits a subsequence of Pi's
>> representation in that base? =A0Or is that unknowable?

>
> IIRC that's true. But the _first_ ruby program... gee, that's got to mean
> something. :)

But that means that the representation of pi contains a ruby program
that computes pi itself (although of course it never finishes), and
that for any imaginable programming language capable of that task, eg
a TuringMachine.

I am confused now, but I bet the Ruby program starts exactly at the
42**42 hexdigit - for a well chosen base of course ;)
R.

 Rick DeNatale 04-27-2009 01:27 PM

Re: [QUIZ] Digits of Pi (#202)

On Mon, Apr 27, 2009 at 9:15 AM, Robert Dober <robert.dober@gmail.com> wrot=
e:
> 2009/4/25 Joel VanderWerf <vjoel@path.berkeley.edu>:
>>> Btw, isn't every finite sequence of digits a subsequence of Pi's
>>> representation in that base? =A0Or is that unknowable?

>>
>> IIRC that's true. But the _first_ ruby program... gee, that's got to mea=

n
>> something. :)

>
> But that means that the representation of pi contains a ruby =A0program
> that computes pi itself (although of course it never finishes), and
> that for any imaginable programming language capable of that task, eg
> a TuringMachine.

Been reading Goedel, Escher, Bach again, have we Robert? <G>
--=20
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/pers...-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

All times are GMT. The time now is 07:52 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.