Share your repls and programming experiences

← Back to all posts
##### π in R
AmazingMech2418

I think I'm pretty much doing pi approximations in every language now, so, here it is in R!

I was going to do NASM before R (and actually before Raku Haskell even), but ran into some issues with floating point numbers that I'm currently working on fixing (if you know how to fix it, please tell me here: https://repl.it/talk/ask/NASM-Print-Floating-Point/41105).

Credit to @NoelBryan, @TheForArkLD , @Warhawk947 , and @LizFoster for inspiring these approximations. Most of these use the Nilakantha Series, although I also use the arctangent method (multiplying the radian arctangent of 1 by 4 to get pi and getting the arctangent with an infinite series) in three of them (Python, Node, and C).

Also, credit to @HahaYes for inspiring this approximation in R!

Next up is NASM (Assembly; only if I can actually figure it out. I might have to save it for later since it is so difficult to program in. I keep pushing it back anyways due to issues with printing floating point numbers), followed by Dart. If you have any suggestions for after those, please let me know!

Voters
DungeonMaster00
TheForArkLD
Port8080
studentAlfredAl
NoelB33
DynamicSquid
Jakman
matthewproskils
Warhawk947
Viper2211
hotnewtop
HahaYes

I must say, this is pretty elegant

AmazingMech2418

@HahaYes Thank you!

HahaYes
studentAlfredAl

Haha yes! ;) @HahaYes

HahaYes

Definite upvote!

AmazingMech2418

@HahaYes Thank you!

HahaYes

ooooo R.... yay

AmazingMech2418

@HahaYes Thank you!

HahaYes

You should do Lua next. I think that it is a pretty good language

DynamicSquid

# π in Markdown

`.css-o0gntx{position:absolute;left:-9999px;}.css-1v1ju80{-webkit-align-items:stretch;-webkit-box-align:stretch;-ms-flex-align:stretch;align-items:stretch;border-width:0;border-style:solid;box-sizing:border-box;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-basis:auto;-ms-flex-preferred-size:auto;flex-basis:auto;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;position:relative;outline:none;min-height:0;min-width:0;position:absolute;left:-9999px;}3.14159265359`
awesome10

@DynamicSquid true amazingness

DynamicSquid

@awesome10 it took 25 years of programming experience to make that

awesome10

@DynamicSquid amazing. can you teach me?

awesome10

@DynamicSquid actually nevermind, i will now do it.

### and better than you and everyone else.

`.css-o0gntx{position:absolute;left:-9999px;}.css-1v1ju80{-webkit-align-items:stretch;-webkit-box-align:stretch;-ms-flex-align:stretch;align-items:stretch;border-width:0;border-style:solid;box-sizing:border-box;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-basis:auto;-ms-flex-preferred-size:auto;flex-basis:auto;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;position:relative;outline:none;min-height:0;min-width:0;position:absolute;left:-9999px;}3 (approximately)`
DynamicSquid

@awesome10 lol xD

awesome10

@DynamicSquid why are you laughing? it is a true marvel

DynamicSquid

@awesome10 agreed :)

awesome10

@DynamicSquid [yoda voice] yes,yes

awesome10

@awesome10 omg my comment has pi (approximately)(3) upvotes!!!

LizFoster

Wow, you're getting these done quick! Good work!

AmazingMech2418

@LizFoster Thank you! Do you have any suggestions for after I do Dart and (attempt to do) NASM?

LizFoster

@AmazingMech2418 Have you done Qbasic?

AmazingMech2418

@LizFoster Yes. The list of all of them I have done is in the post by the way.

Warhawk947

@AmazingMech2418 do pi in brainf lol

AmazingMech2418

@Warhawk947 I'll save that one for later... LOL! Any non-esolang suggestions?

LizFoster

@AmazingMech2418 Love2D is new, try that one maybe?

AmazingMech2418

@LizFoster I think that is a graphics library...

LizFoster

@AmazingMech2418 Dang! Well then, I don't know wwwwwwwwwww

I don't know what half the languages on here are, so I unfortunately might be useless in helping you pick a next step..
^ ^*

AmazingMech2418

@LizFoster Well, I guess I could try Lua which is what Love2D is for...

LizFoster

@AmazingMech2418 Oh, cool then! Good luck!

AmazingMech2418

@LizFoster Thank you!

firefish

@AmazingMech2418 Try in python turtle! Draw 3.14159265358 et cetera

DynamicSquid

@LizFoster oh you haven't posted in a while, if I remember you were making the game?

Jakman

Also do @theangryepicbanana 's programming language for pi.

DynamicSquid

@Jakman Oh thats cool! Was it L?

Jakman
DynamicSquid

@Jakman I just imagine the teacher walking into the classroom being like:

"Okay guys, your projects are due, let's see what you've come up with! John - a number guessing game, not bad. Felix - printing each letter of a word individually, I like it. @theangryepicbanana, how about you? what'd you make?"

Jakman

@DynamicSquid I can see that too. I will make a virus in his language in my free time.

DynamicSquid

@Jakman lol, good luck :)

AmazingMech2418

@Jakman Um... A virus?

Jakman

@AmazingMech2418 I make those for fun. I dont post them on repl because then someone might do bad with them.

Jakman

@DynamicSquid it believe it will be easy. Garbage collection will be done by itself i hope.

theangryepicbanana

for this:

```.css-o0gntx{position:absolute;left:-9999px;}.css-1v1ju80{-webkit-align-items:stretch;-webkit-box-align:stretch;-ms-flex-align:stretch;align-items:stretch;border-width:0;border-style:solid;box-sizing:border-box;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-basis:auto;-ms-flex-preferred-size:auto;flex-basis:auto;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;position:relative;outline:none;min-height:0;min-width:0;position:absolute;left:-9999px;}i <- 0
# Begin while loop
while(i < 150000) {
# Iterate Nilakantha Series
iterate()
# Increment counter variable
i <<- i + 1
}```

I'm pretty sure that you could have used a for-loop instead like:

```.css-o0gntx{position:absolute;left:-9999px;}.css-1v1ju80{-webkit-align-items:stretch;-webkit-box-align:stretch;-ms-flex-align:stretch;align-items:stretch;border-width:0;border-style:solid;box-sizing:border-box;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-basis:auto;-ms-flex-preferred-size:auto;flex-basis:auto;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;position:relative;outline:none;min-height:0;min-width:0;position:absolute;left:-9999px;}i <- 0
# Begin while loop
for(i in 0:150000) {
# Iterate Nilakantha Series
iterate()
}```
AmazingMech2418

@theangryepicbanana Okay. When reading the documentation, I thought R only supported looping through arrays and strings (and other iterable objects), so I just decided to do a while loop instead.

HahaYes

@theangryepicbanana oh look, the guy who yelled at me

AmazingMech2418

@HahaYes What?

HahaYes
theangryepicbanana

@AmazingMech2418 A range (`begin:end`) creates an array so that should be fine

DungeonMaster00

make one in brainf*** and dlang.

AmazingMech2418

@nk1rwc I already did D, actually! I might also do a BrainF one too now that I know the language. Floating point could be tricky though...

Jakman

Do C++ bro.

AmazingMech2418

@Jakman I already did C, so I am not planning on doing C++ since they are both so similar. That is the same reason why I'm not doing BASIC since I already did QBasic.

Jakman

@AmazingMech2418 sounds good. What about F#. It is C# but functional. Also no curly brackets or semicolons in there either.

AmazingMech2418

@Jakman Might do that one after Lua...

Jakman

@AmazingMech2418 sounds good. I will look forward to that.

AmazingMech2418

@Jakman :D I'm about to post the Dart one now. Dart seems like a mixture between C++ and JavaScript with a sprinkle of Python...

Jakman

@AmazingMech2418 to me it is a mix of kotlin and java. Anyways i will be there to check it out.

AmazingMech2418

@Jakman I was about to say it was sort of like a mixture of Kotlin and Java too, but I'm more familiar with JavaScript, although I do know Kotlin and Java pretty well now, and Dart is prototypal OOP like JS.

Jakman

@AmazingMech2418 it looks like it will take off. But i fear that it will be in the same status of ruby. rather than a more mainstream language.

AmazingMech2418

@Jakman Yeah. Though, it is a language by Google and we already saw how much success Go got (it was supported by Google, although not made by them)... By the way, I just posted the approximation in Dart!

Jakman

@AmazingMech2418 yes. I will check the post out now and like it instantly to get it to hot.