π in Ruby
AmazingMech2418 (1016)

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

Here are the other approximations so far:
Java - https://repl.it/talk/share/p-in-Java/34978
QBasic - https://repl.it/talk/share/p-in-QBasic/34973
Fortran - https://repl.it/talk/share/p-in-Fortran/34890
APL - https://repl.it/talk/share/p-in-APL/34888
Forth - https://repl.it/talk/share/p-in-Forth/34652
LOLCODE - https://repl.it/talk/share/p-in-LOLCODE/34421
Python and Node.js (Node is linked in post) - https://repl.it/talk/share/2-Approximations-of-p-In-Only-Four-Lines-of-Code/32773
C - https://repl.it/talk/share/p-Approximations-in-C/33461

Credit to @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).

You are viewing a single comment. View All
[deleted]

OMG how many languages you know???
and why you love pi so much???

AmazingMech2418 (1016)

@Zuhdi28 I know quite a few languages. I've actually lost count by now... However, I'm not fluent in all the languages I know. Of course, I have some language preferences that cause me to use those languages more, learn more about those languages, and have more practice with those specific languages, where, after enough time, I'm fluent in those languages. Some (not all) of these languages are JavaScript, Python, C/C++ and Arduino (modified C++), Bash, Batch, BASIC, and Java. However, notice that all of these (besides BASIC) are great for certain areas, but not others. For example, JavaScript is great for web development, server development, and command line app development, but is not the fastest language. Python is among the best for cryptography and data science (of course, Nim and Julia, both which I have yet to learn, are currently projected to be more useful in data science in the future...). C and C++ are the fastest object-oriented languages that exist since they are compiled (although they are slower than Fortran and Forth as I recently discovered). Arduino is specialized for microprocessors and can be quickly converted to Energia (just changing library names...) for other boards like the MSP430. Bash and Batch are both great for quick file manipulation scripts in Linux and Windows respectively. BASIC, of course, is mostly outdated, but it is just so basic that I was able to learn it in a day. And finally, Java is great for Android app development (and also is used in an AP class that I will take next year). Really, if you want to learn as many languages as I know, I'd recommend not learning from a tutorial, but from examples combined with documentation. I've found that it is easier for me to learn by reading an example and figuring out what it does than to read a book or an article on a specific programming language. I'm pretty sure it has to do with developing neuroplasticity. Also, of course, you don't read a book to learn a foreign language and programming languages are (or at least should be) no different.

And for pi, it is clearly the best mathematical constant that exists and I really enjoy math, so, my fascination with pi is simply derived from my interest in math.

[deleted]

@AmazingMech2418 and i am crazy to read this...

AmazingMech2418 (1016)

@Zuhdi28 I really kind of went off topic in explaining the usefulness of each of the languages I'm fluent in...

LizFoster (647)

@AmazingMech2418 Hahahaha, and he thinks you love π?! Kehehehehehehe...

AmazingMech2418 (1016)

@LizFoster LOL! Are you close to finishing your fourth approximation compilation?

AmazingMech2418 (1016)

@LizFoster Also, how is your Pokemon game going?

LizFoster (647)

@AmazingMech2418 Both are going great! I'm putting the last one or two into the π approximations compilation 4. I haven't had much time to get onto the Pokemon game though, things have been pretty hectic lately... T~T

[deleted]

@LizFoster lol yes