• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 08:14
CEST 14:14
KST 21:14
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
TL.net Map Contest #21: Voting10[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5
Community News
Chinese SC2 server to reopen; live all-star event in Hangzhou16Weekly Cups (Oct 13-19): Clem Goes for Four1BSL Team A vs Koreans - Sat-Sun 16:00 CET6Weekly Cups (Oct 6-12): Four star herO85.0.15 Patch Balance Hotfix (2025-10-8)80
StarCraft 2
General
Weekly Cups (Oct 13-19): Clem Goes for Four RotterdaM "Serral is the GOAT, and it's not close" Chinese SC2 server to reopen; live all-star event in Hangzhou Weekly Cups (March 17-23): Clem Bounces Back DreamHack Open 2013 revealed
Tourneys
$1,200 WardiTV October (Oct 21st-31st) SC2's Safe House 2 - October 18 & 19 INu's Battles #13 - ByuN vs Zoun Tenacious Turtle Tussle Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 496 Endless Infection Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment Mutation # 493 Quick Killers
Brood War
General
BW General Discussion Is there anyway to get a private coach? BGH Auto Balance -> http://bghmmr.eu/ BSL Season 21 OGN to release AI-upscaled StarLeague from Feb 24
Tourneys
[Megathread] Daily Proleagues 300$ 3D!Community Brood War Super Cup #4 [ASL20] Semifinal B Azhi's Colosseum - Anonymous Tournament
Strategy
Roaring Currents ASL final Current Meta [I] Funny Protoss Builds/Strategies BW - ajfirecracker Strategy & Training
Other Games
General Games
Stormgate/Frost Giant Megathread Path of Exile Nintendo Switch Thread Dawn of War IV ZeroSpace Megathread
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Things Aren’t Peaceful in Palestine US Politics Mega-thread The Chess Thread Russo-Ukrainian War Thread Men's Fashion Thread
Fan Clubs
The herO Fan Club!
Media & Entertainment
Anime Discussion Thread Series you have seen recently... [Manga] One Piece Movie Discussion!
Sports
2024 - 2026 Football Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023 Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Our Last Hope in th…
KrillinFromwales
Certified Crazy
Hildegard
The Heroism of Pepe the Fro…
Peanutsc
Rocket League: Traits, Abili…
TrAiDoS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1065 users

Pi approximation

Blogs > Vin{MBL}
Post a Reply
1 2 Next All
Vin{MBL}
Profile Blog Joined September 2006
5185 Posts
April 06 2008 02:40 GMT
#1
Hey. I wrote this program in BASIC (too noob right now to do it in python ) to approximate pi using this method. This is what I have...

i = 0
pi = 1
n = 3

DO WHILE i < 10000
pi = pi - (1 / n)
n = n + 2
pi = pi + (1 / n)
i = i + 1
LOOP
pi = 4 * pi
PRINT pi


It outputs 2.66 etc; though, not pi like I was hoping for. Obviously there's something wrong with the program. Can you guys help me find it?

Myrmidon
Profile Blog Joined December 2004
United States9452 Posts
Last Edited: 2008-04-06 02:53:40
April 06 2008 02:50 GMT
#2
edit nevermind I'm retarded today, yeah the value of n needs to change twice in your loop
new_construct
Profile Blog Joined September 2005
Canada1041 Posts
April 06 2008 02:51 GMT
#3
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
jjl
Profile Blog Joined October 2006
United States85 Posts
Last Edited: 2008-04-06 02:52:48
April 06 2008 02:51 GMT
#4
i think you need another n=n+2 after the the "pi=pi+(1/n)" line

edit: beaten to it, gg new_construct
Vin{MBL}
Profile Blog Joined September 2006
5185 Posts
Last Edited: 2008-04-06 02:53:53
April 06 2008 02:52 GMT
#5
ahh thanks alot

i missed that.
gonna try it now :D

EDIT: IT WORKS YAYYY!!!!!!!
drop
Profile Blog Joined August 2007
Romania306 Posts
Last Edited: 2008-04-06 02:53:48
April 06 2008 02:53 GMT
#6
your lopp does

1-(1/3)
n=3+2
1+(1/5)

***
second recurration
1-(1/5)

edit: ASDF~~!
Insane
Profile Blog Joined November 2003
United States4991 Posts
Last Edited: 2008-04-06 02:56:53
April 06 2008 02:56 GMT
#7
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 -_-
Vin{MBL}
Profile Blog Joined September 2006
5185 Posts
April 06 2008 02:56 GMT
#8
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?
Insane
Profile Blog Joined November 2003
United States4991 Posts
Last Edited: 2008-04-06 03:03:35
April 06 2008 02:58 GMT
#9
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.
Vin{MBL}
Profile Blog Joined September 2006
5185 Posts
April 06 2008 03:03 GMT
#10
I meant from 1 to x

meaning not including 1

>_>
Insane
Profile Blog Joined November 2003
United States4991 Posts
Last Edited: 2008-04-06 03:06:06
April 06 2008 03:05 GMT
#11
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 &rarr; i = 0, 1, 2, 3, 4
Maybe a geographical thing, dunno!
drop
Profile Blog Joined August 2007
Romania306 Posts
April 06 2008 03:05 GMT
#12
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)

Vin{MBL}
Profile Blog Joined September 2006
5185 Posts
April 06 2008 03:07 GMT
#13
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 &rarr; 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.
Insane
Profile Blog Joined November 2003
United States4991 Posts
April 06 2008 03:08 GMT
#14
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.
Insane
Profile Blog Joined November 2003
United States4991 Posts
Last Edited: 2008-04-06 03:12:32
April 06 2008 03:09 GMT
#15
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 &rarr; 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-
Vin{MBL}
Profile Blog Joined September 2006
5185 Posts
Last Edited: 2008-04-06 03:18:50
April 06 2008 03:11 GMT
#16
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
Insane
Profile Blog Joined November 2003
United States4991 Posts
Last Edited: 2008-04-06 03:15:22
April 06 2008 03:14 GMT
#17
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.
tiffany
Profile Joined November 2003
3664 Posts
April 06 2008 03:29 GMT
#18
i wrote a primes sieve program in C, let me know if you would like some help
Insane
Profile Blog Joined November 2003
United States4991 Posts
April 06 2008 03:29 GMT
#19
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
Vin{MBL}
Profile Blog Joined September 2006
5185 Posts
April 06 2008 03:30 GMT
#20
hahaha nice!

Why did you use 1.0 and 3.0 instead of just 3 and 1 though?
1 2 Next All
Please log in or register to reply.
Live Events Refresh
OSC
11:00
Mid Season Playoffs
Creator vs SpiritLIVE!
Nicoract vs GgMaChine
SKillous vs sebesdes
Solar vs Cure
WardiTV511
Liquipedia
Replay Cast
10:00
SC2's Safe House 2: Playoffs
CranKy Ducklings145
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft: Brood War
Rain 8710
Horang2 2771
GuemChi 2747
Bisu 1819
Leta 1084
Flash 978
hero 889
Jaedong 697
firebathero 555
Hyun 327
[ Show more ]
BeSt 298
Mini 297
Soma 230
PianO 220
Soulkey 206
Last 194
Light 191
EffOrt 190
ZerO 164
Free 115
Snow 114
Killer 109
JYJ102
Barracks 101
Aegong 87
JulyZerg 81
ToSsGirL 77
Pusan 65
Mind 61
Rush 59
ggaemo 41
Stork 33
Sharp 28
sas.Sziky 28
Icarus 20
Shinee 16
ajuk12(nOOB) 15
Movie 15
Noble 14
HiyA 14
zelot 13
Sacsri 11
yabsab 11
SilentControl 10
ivOry 8
Bale 6
Mong 1
Terrorterran 0
Dota 2
XaKoH 392
XcaliburYe220
BananaSlamJamma184
Dendi107
canceldota64
420jenkins28
League of Legends
JimRising 385
Counter-Strike
olofmeister1885
x6flipin488
zeus222
edward45
Other Games
summit1g6988
singsing2267
B2W.Neo578
Pyrionflax182
Hui .152
Sick135
oskar66
Mew2King57
Trikslyr14
ZerO(Twitch)8
hiko0
Organizations
Counter-Strike
PGL251
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• iopq 0
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos2731
• Lourlo437
Upcoming Events
OSC
3h 46m
Tenacious Turtle Tussle
10h 46m
The PondCast
21h 46m
OSC
23h 46m
WardiTV Invitational
1d 22h
Online Event
2 days
RSL Revival
2 days
RSL Revival
2 days
WardiTV Invitational
2 days
Afreeca Starleague
3 days
Snow vs Soma
[ Show More ]
Sparkling Tuna Cup
3 days
WardiTV Invitational
3 days
CrankTV Team League
4 days
RSL Revival
4 days
Wardi Open
4 days
CrankTV Team League
5 days
Replay Cast
5 days
WardiTV Invitational
5 days
CrankTV Team League
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Acropolis #4 - TS2
WardiTV TLMC #15
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
C-Race Season 1
IPSL Winter 2025-26
EC S1
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
BSL 21 Non-Korean Championship
RSL Offline Finals
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
CranK Gathers Season 2: SC II Pro Teams
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.