|
|
edit nevermind I'm retarded today, yeah the value of n needs to change twice in your loop
|
when it loops, the n at pi=pi-(1/n) didn't change, u need to add another n=n+2 at the beginning of the loop and set initial value of n to 1 or something
|
i think you need another n=n+2 after the the "pi=pi+(1/n)" line
edit: beaten to it, gg new_construct
|
ahh thanks alot
i missed that. gonna try it now :D
EDIT: IT WORKS YAYYY!!!!!!!
|
your lopp does
1-(1/3) n=3+2 1+(1/5)
*** second recurration 1-(1/5)
edit: ASDF~~!
|
United States4991 Posts
You need to do n = n + 2 before you LOOP. Edit: Wow, open a page and get some food then come back and reply and the whole world has already posted -_-
|
I really really like doing these cool math things. Although I'm a programming noob and all. >_> are there any other rules/formulas I can do something like this with?
How would I go about writing a program that lists all primes from 1 to x? (where x is a number the user inputs). is that above my level?
|
United States4991 Posts
On April 06 2008 11:56 Vin{MBL} wrote: I really really like doing these cool math things. Although I'm a programming noob and all. >_> are there any other rules/formulas I can do something like this with?
How would I go about writing a program that lists all primes from 1 to x? (where x is a number the user inputs). is that above my level? No, it's not really above your level. The "simple" algorithm is the sieve of eratosthenes, which is frequently done in intro programming classes. If you want to do the primes, I recommend you implement that before trying the more advanced sieve of atkin<strike>s</strike>.
Edit: it's atkin, not atkins, oops. also here are some links for it:
http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes http://en.wikipedia.org/wiki/Sieve_of_Atkin
Edit2: fyi 1 isn't considered a prime number Edit3: I've never had to implement the sieve of atkin for any of my classes, by the way. If you do decide to do it and aren't familiar with the notation used in the pseudocode, reply here and I'll clarify it for you.
|
I meant from 1 to x
meaning not including 1
>_>
|
United States4991 Posts
On April 06 2008 12:03 Vin{MBL} wrote: I meant from 1 to x
meaning not including 1
>_> Generally when I say "from a to b", I mean the lower limit is inclusive and the upper limit is exclusive For example, i goes from 0 to 5 → i = 0, 1, 2, 3, 4 Maybe a geographical thing, dunno!
|
atkins diet :D
Vin - I advise you to use the Excel VBA btw (I know it's not the best, but you will probably use it at work one day - so start getting used to it)
anyway, does any of you have any examples of more complicated VBA macros? I mean I can make the algorythms, but I dont know the syntax too well (e.g. it took me some time to figure out the: Worksheets("1").Cells(1, 1) = Pi in Excel)
|
On April 06 2008 12:05 HnR)Insane wrote:Show nested quote +On April 06 2008 12:03 Vin{MBL} wrote: I meant from 1 to x
meaning not including 1
>_> Generally when I say "from a to b", I mean the lower limit is inclusive and the upper limit is exclusive For example, i goes from 0 to 5 → i = 0, 1, 2, 3, 4 Maybe a geographical thing, dunno!
hahah maybe i just suck at communicating math :D
is there anyway to get a goto command in python? from google it seems like there isn't one. i'm trying to convert that pi program from basic to python.
|
United States4991 Posts
On April 06 2008 12:05 drop wrote: atkins diet :D
Vin - I advise you to use the Excel VBA btw (I know it's not the best, but you will probably use it at work one day - so start getting used to it)
anyway, does any of you have any examples of more complicated VBA macros? I mean I can make the algorythms, but I dont know the syntax too well (e.g. it took me some time to figure out the: Worksheets("1").Cells(1, 1) = Pi in Excel)
This sounds like a terrible way to learn programming, and I've never had to know VBA anywhere -0- It depends upon what sort of job you are going into, I guess.
|
United States4991 Posts
On April 06 2008 12:07 Vin{MBL} wrote:Show nested quote +On April 06 2008 12:05 HnR)Insane wrote:On April 06 2008 12:03 Vin{MBL} wrote: I meant from 1 to x
meaning not including 1
>_> Generally when I say "from a to b", I mean the lower limit is inclusive and the upper limit is exclusive For example, i goes from 0 to 5 → i = 0, 1, 2, 3, 4 Maybe a geographical thing, dunno! hahah maybe i just suck at communicating math :D is there anyway to get a goto command in python? from google it seems like there isn't one. i'm trying to convert that pi program from basic to python. :/ "Go To Statement Considered Harmful" - Edsger Dijkstra 'Modern' programming doesn't use goto statements, and you should avoid them. You can achieve the same effects from the use of functions and loops. (ed: though you don't really need any functions for the pi program, I just meant that in general.)
I don't really know Python, but I'll take a look at it -0-
|
is there anyway to get a while do in python? I can't find it here
Are you a compsci graduate Insane? I'm a high school junior that's having a bit of a problem deciding between compsci and engineering. (since I have little programming experience because CompSci classes in my country are basically non- existant
|
United States4991 Posts
On April 06 2008 12:11 Vin{MBL} wrote:is there anyway to get a while do in python? I can't find it here I don't know basic either, lol a for loop will work for what you want though. Googling around it looks like you want something like for i in range(0, 1000):
Are you a compsci graduate Insane? I'm a junior that's having a bit of a problem deciding between compsci and engineering. (since I have little programming experience because CompSci classes in my country are basically non- existant
No, I'm a comp sci undergraduate in my 3rd year.
Edit: I just downloaded python, gonna install now.
|
i wrote a primes sieve program in C, let me know if you would like some help
|
United States4991 Posts
Cool, my first python program.
<pre> pi = 1.0 n = 3.0 for i in range (1, 10000): pi = pi - (1.0/n) n += 2 pi = pi + (1.0/n) n += 2 print pi * 4 </pre> Probably violating all sorts of python coding conventions 3.14164265609
|
hahaha nice!
Why did you use 1.0 and 3.0 instead of just 3 and 1 though?
|
|
|
|