Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

The 20 Line Challenge / Pi generator

Author
Message
Diggsey
17
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 21st May 2006 11:48
This program calculates Pi to the most decimal places Darkbasic can handle, 5



If you don't understand how it works, here's how:

Circumference = 2*Pi*Radius

so to get Pi you work out Circumference and Radius.
You divide Circumference by 2 and then by the Radius
You are left with Pi
Radius is ten here, so I have to work out the Circumference

I start of with a triangle wich is a quarter of a circle, I then find a point half way between the 2 non rightangle points.

I measure the distance between the new point and the centre and move that point out until it is 10 away from the centre. I then set one of the non rightangle points to the new point and then go through again, however many times. At the end I measure the distance between the two points and multiply it by what segment of the circle it is. (so if it's one hundreth of a circle I multiply by 100).

This gives me the circumference
I divide this by 2 and then by 10, but in this program if one hundreth of a circle it multiplies it by fifty not one hundred and then dividing by 2.
So it just divides by ten and prints the answer.

There are three types of people, those that can count and those that can't.
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 22nd May 2006 19:28
i get 3.14159226418
but pi should be 3.14159265358 etc
close enough for me but just thought i'd point that out (dbpro v6 btw)

life's one big game
spec= 2.6ghz, 1gb ram, 512mb gpu, directx 9.0c, dbpro and classic
Diggsey
17
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 22nd May 2006 19:48
In dbpro, if you define the variables as the variable type with most decimal places, and increase the number of loops by as many as possible before it has an overflow, it should be much more accurate. I'm using DBC and you can't define variables

There are three types of people, those that can count and those that can't.
Diggsey
17
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 22nd May 2006 19:51
Here's the same thing in VBA behind excel. It's much more accurate due to the var types and number of loops

There are three types of people, those that can count and those that can't.

Attachments

Login to view attachments
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 27th May 2006 13:19
Ah well... Don't really need that program. I know pi till 50 decimals out of my head. But then again, I'm a math freak...

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Essal
18
Years of Service
User Offline
Joined: 15th Jan 2006
Location: inside your webcam, watching YOU.
Posted: 28th May 2006 00:23
Quote: "I know pi till 50 decimals out of my head. But then again, I'm a math freak"

Indeed

Check out http://www.freewebs.com/lasse-b for free Stuff for FPSC
Hobgoblin Lord
18
Years of Service
User Offline
Joined: 29th Oct 2005
Location: Fall River, MA USA
Posted: 30th May 2006 21:25
Only 50 Sven, I suggest you try for at least 60 for a more accurate calculation.
Bahamut
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Brighton
Posted: 30th May 2006 21:56
Quote: "Ah well... Don't really need that program. I know pi till 50 decimals out of my head. But then again, I'm a math freak.."


Blimey. I thought I was impressive. I only know the first 10...

3.1415926535 etc

I feel so...average...

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 7th Jun 2006 18:13
Quote: "Only 50 Sven, I suggest you try for at least 60 for a more accurate calculation."


Last year, I knew pi till 100 decimals. I stopped repeating it, so only the first 50 still remain in my head...

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Hobgoblin Lord
18
Years of Service
User Offline
Joined: 29th Oct 2005
Location: Fall River, MA USA
Posted: 16th Jun 2006 03:35
Well Sven to get you back on track here it is to 200

Three Score
19
Years of Service
User Offline
Joined: 18th Jun 2004
Location: behind you
Posted: 16th Jun 2006 11:46
@hobgolblin
omg my eyes!!! so..many...numbers...

I bet that the problem with pi in this program is that x86's decimals are whack(since that actually is a problem)

JouleOS and friends
great thanks to http://galekus.com for FREE HOSTING!
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 16th Jun 2006 14:36
Thx Hobgoblin Lord, but the paper I use(d) contains 3000 decimals

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Hobgoblin Lord
18
Years of Service
User Offline
Joined: 29th Oct 2005
Location: Fall River, MA USA
Posted: 16th Jun 2006 15:04 Edited at: 16th Jun 2006 15:05
actually i got that from a source to 100,000 decimals but i thought that would be a little much for the code box.

http://www.uoguelph.ca/zoology/devobio/210labs/MeiosisQuiz/pi.html
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 16th Jun 2006 17:39
nice...

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Diggsey
17
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 16th Jun 2006 20:32
You can get pi to 1 million decimal places if you search on google.

There are three types of people, those that can count and those that can't.
LordoFire
20
Years of Service
User Offline
Joined: 14th Feb 2004
Location: United States
Posted: 18th Jun 2006 07:59
Haha, very nice little code. THere is a guy I know who has memorized 350 decimals. I really dont think he has a life...or a wife...

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 18th Jun 2006 14:23
I'm not the most nerdiest man on earth:

http://lofi.forum.physorg.com/Japanese-breaks-pi-memory-record_2285.html

Try to beat THAT

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
EddieB
19
Years of Service
User Offline
Joined: 29th Sep 2004
Location: United Kingdom
Posted: 18th Jun 2006 15:06 Edited at: 18th Jun 2006 15:07
Why would you want to know it to "n" decimal places anyway :/

If I want a basic pi, roughly for my games etc. I just used 22/7...

http://www.uoguelph.ca/zoology/devobio/210labs/MeiosisQuiz/pi.html
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 18th Jun 2006 16:00
Because we are FREAKS!!!


It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
zzz
18
Years of Service
User Offline
Joined: 13th Nov 2005
Location: Sweden
Posted: 19th Jun 2006 17:04
Here you go, 4194304 decimals:
http://www.zenwerx.com/pi.php

XGoDSouL
19
Years of Service
User Offline
Joined: 14th Jun 2004
Location:
Posted: 24th Jun 2006 04:34
The method you use, Diggsay, to compute Pi is true, but not efficient in a computer method :
You involve a graphical approach of the problem which is perfect, but computers have flaws in floating point operation, their decimals after some point are no more precise (read literally trash).
The problem is that you're trying to compute it in one iteration. The best way to solve this problem would be working with infinites sums, which can be integrated and then solved... Tons of mathematicians many hundreds / thousands years before us were bumping their head on walls with these calculs.
Try running an Ramanujan equation or the now celeb Bailey-Borwein-Plouffe (published in 1997) one. Your results will be a thousand time more effective

Hope I helped.
Diggsey
17
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 24th Jun 2006 10:38
Thanks, but I was just seeing if I could do it.
I didn't use anything to help me.
Because I thought of it all myself which I'm quite pleased about

There are three types of people, those that can count and those that can't.
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 24th Jun 2006 13:50
Quote: "This program calculates Pi to the most decimal places Darkbasic can handle, 5"


You mean 6 places right?

Diggsey
17
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 24th Jun 2006 16:33
Dark basic classic can do five decimal places
But can do six digits:

3.14159 has 5 decimal places, but six digits.

There are three types of people, those that can count and those that can't.
XGoDSouL
19
Years of Service
User Offline
Joined: 14th Jun 2004
Location:
Posted: 27th Jun 2006 09:30
Hem wait... Does that means that it could handle precisely like 12919287391123145651612873912873.12345 just because it has 5 decimal places? but whoa! why creating 64 bits variables on newers compilators when you can have unlimited precision with darkbasic! just multiplicate by the precision you want and POOF! =) just kidding =P
Try :

The precision limit is on the first decimal... the *real* answer would be 99999,9... but DarkBasic gives me 99999,8984375... And it isn't the fault of DarkBasic =P I would blame the mathematical co-processor...
Another example :

Which gives me an outstanding 9 decimals precision (because indeed the 0's after are right!)
So there aren't always 5 precise decimals out of mathematical operations with floats. I've read somewhere that results may vary depending on the system you use (the way the floating point operations core are done internally) but I think nowadays it's all standardized (I hope so =))
Floats have a precision on digits... err not even on digits =) If you read the manual :
Quote: "Mighty Quote of the Manual : REAL Range : 3.4E +/- 38 (7 digits)"

So the digit that is on the borderline of real range (for a float... for a double float its 1.7E +/- 308 (15 digits)) will be unsure. And by convention if it's a 1 you must put the next digit with it, otherwise you will loose marks. (oops sorry, damned school ! It remembers me my physics courses, with incertitude calculation =P )

So there's no way to compute Pi in one variable more precisely than apprimatively 7 digits (or 15 digits for the double float).
A way to do it would be to compute each like 7 digits (or 15 digits) in different variables and then say its these variables, one followed by the other (lets say firt variable=3.14 , second variable=1,59 ... which would get us 3.14159...well...as you want to set them...)
Another way to do it would be by poking each digits you compute with an algorithm into memory...
Variables are only little drawers... the mighty Pi Task (ta-dam!) doesn't quite fits in a drawer =)
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Jul 2006 13:12
Quote: " I know pi till 50 decimals out of my head"


That's nothing, I know pi all the way out to the hundredths place! (yes, that means 3.14 and no further for the ppl who will probably think I meant hundreds of digits)


how precise do ppl know this one?

e = 2.71

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 4th Jul 2006 20:14
On my computer your pi generator is accurate to 6 decimal places (7 digits). Even though I am a redneck I can count up to 10 as I have all my fingers. You code prints out:
3.14159226418 compared to:
3.14159265358

I think 3.141592 is 6 places

x1bwork
18
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 5th Jul 2006 15:53
Quote: "Even though I am a redneck I can count up to 10 as I have all my fingers."


gotta admire LiTs humble sarcasm

Les Horribres
18
Years of Service
User Offline
Joined: 20th Nov 2005
Location: My Name is... Merry
Posted: 5th Jul 2006 18:51
Uhh... might I add that if you are trying to create a pi generator you should at least be using a more complicated approach. Primarily the use of arrays as variables. Technically, if you really wanted to use a string, I guess it would do the same thing, but you get my point. The only issue is that so many issues can come up when programming in things like multiplication and division. But you do get a far more accurate answer.

I remember doing that for "e" and finding out that adding the numbers together at the end like 1.01 + .0101 x times where x is defined as (1+1/x)^x actually easied the calculations. (at least on my behalf).

Quote: "I measure the distance between the new point and the centre and move that point out until it is 10 away from the centre. I then set one of the non rightangle points to the new point and then go through again, however many times. At the end I measure the distance between the two points and multiply it by what segment of the circle it is. (so if it's one hundreth of a circle I multiply by 100)."


Let me see If I truly understand. You aren't finding the circumference of a circle but the perimiter hexadecagon?

Your Mod was deleted by the Government.
Jeff Miller
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 5th Jul 2006 19:20
Used to be simple in programs that used radians, like Visual Basic.

PI = 4 * ATN(1)
DarkMasta
17
Years of Service
User Offline
Joined: 21st Apr 2006
Location: Typed on your screen.
Posted: 16th Sep 2006 20:53
Hello everyone. I see you're having quite a fight about the little number pi. So I thought, I'll join.
But no, seriously, I've got quite interested. The idea of making a pi-generator in a 20-liner is refreshingly alternative, but also very dull. Nevertheless, the way the mathematicians interpolated pi was by this row:

PI = 4(1/1-1/3+1/5-1/7+1/9-1/11+1/13-...)

Atleast one can comprehend or derive most of the important irrational numbers in some sort of interpolable formula, else it'll have been as if maths crashed into an invisible wall an' got knocked-out for ever.
The problem with my program is the same with those above — I can only press out 5 dp accurately, after that, there's just casual junk of numbers.

Btw, did you know, that pi also plays a protruding role in nature's ways? The way a river runs has a length ratio to the direct airline is pi to 1. I think that's incredible on my behalf. — At least it's worth commenting.

There yer go with my piece of sub-20-line-coding:


Wherever you plan to go,
it's the next step you never know.
DarkMasta
17
Years of Service
User Offline
Joined: 21st Apr 2006
Location: Typed on your screen.
Posted: 19th Sep 2006 09:18
Programming a pi generator is simply on the edge of DB or DBPro's purpose. It only shows, that DBPro is made for games, which require a high visual output thrust. But as for precise maths and so forth — I'd rather use Turbo Pascal, even if it's right down low like DOS.

The best thing is to get the first dozen dps of Pi and insert them in whatever you need.

Bottomofthetheme.

Wherever you plan to go,
it's the next step you never know.
sneaky smith12
17
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 20th Sep 2006 01:05
to get more digits into the decimal places why not try and get it into a string or something and use your text functions...

just a thought

had a great laugh reading this thread... no offense

If at first you dont succeed, LOWER YOUR STANDARDS.
DarkMasta
17
Years of Service
User Offline
Joined: 21st Apr 2006
Location: Typed on your screen.
Posted: 26th Sep 2006 16:42
Yeah, someone already wrote a program for accurate mathematical calculations and uses strings there too for practically unlimited dps.

Wherever you plan to go,
it's the next step you never know.
Pegasus Flight Resources
17
Years of Service
User Offline
Joined: 6th Oct 2006
Location: Vermont
Posted: 15th Nov 2006 23:13
BTW, just so that you guys know, you can run a program on your computer called PiFast that calculates Pi to however many digits you wish. I used it on my web server, and got a text file with 100,000,000 digits, and I was trying to get 100,000,000,000 digits. The program fails around 20,000,000,000 on my computers.

I was bored one day, so I started to memorize pi as well, so here some of it is:
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808...

Also, you can look at the site for PiFast, and you can see the calculations that they use, including two methods for calculating pi, a method for calculating the square root of 2, and a method for calculating e.

If you really want it, I'll post a link to the text file with 100 million digits of pi (I think it has that, or maybe more.)

I have the honor to remain your most humble and Ob't Sv't in our war against the King.

--
Patrick Reilly
1st Coy.
Colonel Seth Warner's Regiment
TKF15H
20
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 20th Nov 2006 03:12
Quote: "I have the honor to remain your most humble and Ob't Sv't in our war against the King."

What did Elvis ever do to you?

Code Dragon
17
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 23rd Nov 2006 02:01 Edited at: 23rd Nov 2006 02:03
Quote: "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808..."


That's quite alot of digits. People don't seem to have much respect for pi anymore, currently the Wikipedia file on pi has been spammed with crude language.

[edit]
It seems the respect is back, someone just deleted it.

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 25th Nov 2006 17:34
Big news!

The 60y old Akira Haraguchi broke his own record on 4 October for memorizing pi. His last record was 83 431 decimals, and now he increased the number to 100 000 decimals flat.
- Article from Pythagoras: a dutch math-magazine -

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Pegasus Flight Resources
17
Years of Service
User Offline
Joined: 6th Oct 2006
Location: Vermont
Posted: 29th Nov 2006 03:00
Dear sir,
Elvis never laid a hand near me (I'm way too young for that!). That salutation is just a common expression that reenactors, specifically American Revolution reenactors normally sign out with. There are many variations, and that is the one I use.

I would still hope that there is respect for Pi. It is a wonderful number, and it isn't explained enough in our current education system. People always approximate it to either 3.14 or 22/7, never anything more precise, which IMO is ridiculous. If you want the most precise results, use the most precise measurements.

I have the honor to remain your most humble and Ob't Sv't in our war against the King.

--
Patrick Reilly
1st Coy.
Colonel Seth Warner's Regiment
Code Dragon
17
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 1st Dec 2006 01:29
I heard about the idiot circle squarers who "discovered" the exact value of pi. Some say 3, some say 3.14, one even said 17.

Xenocythe
18
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 1st Dec 2006 02:17
What the hell guys. All I know is 3.14



Login to post a reply

Server time is: 2024-03-29 00:53:20
Your offset time is: 2024-03-29 00:53:20