Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ ¹ ² ³ °
 

You are not logged in. #1 20090509 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 20090509 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 20090510 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 20090510 04:03:05
Re: Python!Hi boss; Last edited by bobbym (20090510 04:39:14) In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof. #9 20090510 08:59:48
Re: Python!Hi simron; In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof. #12 20090520 05:45:07
Re: Python!Ahh, help! Last edited by bossk171 (20090520 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 20090520 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 20090520 14:24:19
Re: Python!Hi bossk171; Last edited by bobbym (20090521 07:26:40) In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof. #16 20090621 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 (20090622 17:19:23) #17 20090622 00:53:33
Re: Python!Hi gwar; Last edited by bobbym (20090622 03:34:56) In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof. #18 20090623 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 pi Last edited by gwar (20090623 16:41:35) #19 20090623 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 20090623 23:16:37
Re: Python!Hi gwar; Last edited by bobbym (20090623 23:20:08) In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof. #21 20090623 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 20090623 23:47:37
Re: Python!Hi gwar; Last edited by bobbym (20090623 23:48:30) In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof. #24 20090624 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 20090624 01:46:30
Re: Python!Sorry mathsyperson and gwar; Last edited by bobbym (20090624 01:50:49) In mathematics, you don't understand things. You just get used to them. I have the result, but I do not yet know how to get it. All physicists, and a good many quite respectable mathematicians are contemptuous about proof. 