Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °
| |
|
|
You are not logged in. #1 2009-05-09 08:24:23
Python!Here's a Python thing I found on www.nerdparadise.com: Code:import random
def find_pi():
hits = 0
trials = 0
while 1:
x = random.random()
y = random.random()
trials += 1
if x * x + y * y < 1:
hits += 1
if trials % 100 == 1:
print hits * 4.0 / trials
find_pi()Yay Pi! How many people here use Python? Linux FTW #4 2009-05-09 15:22:38
Re: Python!Easy to understand code. I like that example because it really shows that pi is real. But it has a veeerryyy slow convergence! "The physicists defer only to mathematicians, and the mathematicians defer only to God ..." - Leon M. Lederman #6 2009-05-10 03:36:49
Re: Python!I made it as far as here: http://www.python.org/download/ but I'm not sure which to download. I'm using Windows XP. There are 10 types of people in the world, those who understand binary, those who don't, and those who can use induction. #7 2009-05-10 04:03:05
Re: Python!Hi boss; Last edited by bobbym (2009-05-10 04:39:14) In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #9 2009-05-10 08:59:48
Re: Python!Hi simron; In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #11 2009-05-11 19:04:04
Re: Python!I agree In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #12 2009-05-20 05:45:07
Re: Python!Ahh, help! Last edited by bossk171 (2009-05-20 05:49:00) There are 10 types of people in the world, those who understand binary, those who don't, and those who can use induction. #14 2009-05-20 09:57:04
Re: Python!
Why is that? Is that some kind of coder's trick I'm not familiar with, or is it simply for portability? There are 10 types of people in the world, those who understand binary, those who don't, and those who can use induction. #15 2009-05-20 14:24:19
Re: Python!Hi bossk171; Last edited by bobbym (2009-05-21 07:26:40) In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #16 2009-06-21 23:59:35
Re: Python!Hey im probably a little old but i wanna learn more math and i've a passing familiarity with python. Code:def seq(n):
n = n+2
return [n, n+2]
def findpi():
pi = 0
k = -1
while True:
i = seq(k)
a = (4.0/i[0])-(4.0/i[1])
pi = pi + a
k= k + 4
print pi
findpi()Im pretty sure 3.0 is "the future", aka an experimental version. All the interesing modules I've found are for 2.5+ Last edited by gwar (2009-06-22 17:19:23) #17 2009-06-22 00:53:33
Re: Python!Hi gwar; Last edited by bobbym (2009-06-22 03:34:56) In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #18 2009-06-23 16:33:15
Re: Python!It was the easiest the use though. Im not sure how to translate this http://en.wikipedia.org/wiki/Bellard%27s_formula Code:n = 0
pi = 1/2^6
while True:
a= -1*n/2^(10*n)*(-2^5/4*(n+1)-1/4*(n+3)+2^8/10*(n+1)-2^6/10*(n+3)-2^2/10*(n+5)-2^2/10*(n+7)+1/10*(n+9))/10*(n+9))
pi+=a
n+=1
print piLast edited by gwar (2009-06-23 16:41:35) #19 2009-06-23 21:42:27
Re: Python!Try this: Code:n = 0
pi = 0
while True:
a= (-1^n)/2^(10*n)*((-2^5)/(4*n+1)-1/(4*n+3)+(2^8)/(10*n+1)-(2^6)/(10*n+3)-(2^2)/(10*n+5)-(2^2)/(10*n+7)+1/10*(n+9)/(10*n+9))
pi+=a
n+=1
print pi/(2^6)You had things like 4*(n+1), when you wanted 4*n+1. Why did the vector cross the road? It wanted to be normal. #20 2009-06-23 23:16:37
Re: Python!Hi gwar; Last edited by bobbym (2009-06-23 23:20:08) In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #21 2009-06-23 23:25:53
Re: Python!My fave algorithm is the one where you choose two random numbers (x,y) and see if they fall inside the unit circle. You won't get many digits out of it, but it sure is intuitive! "The physicists defer only to mathematicians, and the mathematicians defer only to God ..." - Leon M. Lederman #23 2009-06-23 23:47:37
Re: Python!Hi gwar; Last edited by bobbym (2009-06-23 23:48:30) In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. #24 2009-06-24 00:33:34
Re: Python!
It does calculate pi, it's just that it does so by calculating its binary digits, then summing them. Why did the vector cross the road? It wanted to be normal. #25 2009-06-24 01:46:30
Re: Python!Sorry mathsyperson and gwar; Last edited by bobbym (2009-06-24 01:50:49) In mathematics, you don't understand things. You just get used to them. 90% of mathematicians do not understand 90% of currently published mathematics. I am willing to wager that over 75% of the new words that appeared were nothing more than spelling errors that caught on. |