##### π in C#

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

Here are the other approximations so far:
Bash - https://repl.it/talk/share/p-in-Bash/36133
Kotlin - https://repl.it/talk/share/p-in-Kotlin/36125
Ruby - https://repl.it/talk/share/p-in-Ruby/34982
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 @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).

You are viewing a single comment. View All
ChezCoder (1588)

Wow, never knew there was so much to pi!

AmazingMech2418 (1039)

@ChezCoder Well, regardless of what @StudentFires may say, pi is the best mathematical constant!

xxpertHacker (860)

@AmazingMech2418 Well, regardless of what AmazingMech2418 may say, neither Pi, nor Tau, are the best mathematical constants!

ChezCoder (1588)

@StudentFires :O! HOW COULD YOU!!!!????????

xxpertHacker (860)

@ChezCoder Easily? It was relatively easy.

HahaYes (1862)

@AmazingMech2418 No e is the best mathematical constant

AmazingMech2418 (1039)

@HahaYes Euler's identity requires pi though...

AmazingMech2418 (1039)

@HahaYes Yes, but all of its usefulness lies in the identity.

AmazingMech2418 (1039)

@HahaYes Without Euler's identity, you wouldn't have imaginary exponents or natural logarithms or anything like that.

AmazingMech2418 (1039)

@HahaYes And the identity is based on radian trigonometry, so it requires pi.

AmazingMech2418 (1039)

@HahaYes Is it `e^iτ` or `e^iπ`?

HahaYes (1862)

@AmazingMech2418 bruh just because pi is used more doesn't mean it is better

HahaYes (1862)

@AmazingMech2418u is so much better for arcs, radians, and anything related to a circle.

AmazingMech2418 (1039)

@HahaYes Just because tau saves one simple step of multiplication in one formula doesn't make it better.

HahaYes (1862)

@AmazingMech2418 Omg is this what nerds do? Have flame wars on math?

AmazingMech2418 (1039)

@HahaYes That's pretty much what we do...

AmazingMech2418 (1039)

@HahaYes Pi vs tau is a large debate... Although it shouldn't be one at all because pi is obviously better.

AmazingMech2418 (1039)

@HahaYes By the way, JavaScript > Python. Another huge debate...

LizFoster (648)

@AmazingMech2418 That's just an incorrect debate :)

AmazingMech2418 (1039)

@LizFoster LOL! Python is still good, just JS is better... Can you use Python natively in the browser? Also, while Python can do it too, JS is also used for desktop applications (Electron) and command line applications (Node) while React Native can also be used on mobile with JS (I don't think Python can match that).

AmazingMech2418 (1039)

@LizFoster And, please, don't use the TIOBE index as your reason why Python is better. JS is just underrated (should be 1st, not 7th).

AmazingMech2418 (1039)

@HahaYes Well, let's just leave it at Python is best for machine learning and data science and JS for pretty much everything else if you don't care about speed (C is best for speed).

HahaYes (1862)

@AmazingMech2418 I've never like Javascript. It was hyped wayyy to much.

AmazingMech2418 (1039)

@HahaYes How dare you insult the greatest programming language of all time?

HahaYes (1862)

@AmazingMech2418 Name one person who uses Javascript in a coding competition.

HahaYes (1862)

@AmazingMech2418 The greats such as Gennady Korotkevich all use C++

HahaYes (1862)

@AmazingMech2418 Javscript is kind of a ewie langauge. Go learn Java

AmazingMech2418 (1039)

@HahaYes C is better than C++ anyways...

HahaYes (1862)

@AmazingMech2418 C++ is just harder. Also I use VIM

AmazingMech2418 (1039)

@HahaYes LOL! You're funny! You want me to learn a language I already know that I also can barely stand because it is a worse programming language than JS!

HahaYes (1862)

@AmazingMech2418 My man, the older the language, the better it is. It is like wine

AmazingMech2418 (1039)

@HahaYes
You: C++ is just harder.
Me: C - char arrays, C++ - actual STRINGS. Which is harder again?

HahaYes (1862)

@AmazingMech2418 C is a general purpose language. C++ is a pure general purpose language.

AmazingMech2418 (1039)

@HahaYes Nano > Vim, C > C++, JS > Python, Pi > Tau (not mathematically, but in that pi is better), Java < literally everything else.

Jakman (450)

@HahaYes that is right. I started with python and moved on to C#. It is a great transition to harder langs. I understand C to an extent and it looks like art to me.

AmazingMech2418 (1039)

@HahaYes I like older languages too (C, Forth, Fortran, BASIC, etc.) but Java stinks. Security issues (remember when people got hacked in Minecraft) and already about to lose to Kotlin in Android development.

AmazingMech2418 (1039)

@HahaYes So is Nano... Though real coders use Notepad...

HahaYes (1862)

@AmazingMech2418 NOTEPAD IS FOR WINDOWS USERS

AmazingMech2418 (1039)

@ChezCoder I already saw it... You don't need to literally advertise everywhere.

ChezCoder (1588)

@AmazingMech2418 im getting like 50 pings from this :(

HahaYes (1862)

@AmazingMech2418 I've never liked Java, I was making a joke

AmazingMech2418 (1039)

@HahaYes LOL! And, I'm also a Windows user and a Linux user...

HahaYes (1862)

@ChezCoder As you can see Chez, we have a flame war about coding.

AmazingMech2418 (1039)

@HahaYes I have Ubuntu MATE on my Raspberry Pi 3B+. I'm going to download Kali on my Pi 4 and still need to figure out for my other Pi 3B+.

HahaYes (1862)

@AmazingMech2418 Windows doesn't care about developers.

HahaYes (1862)

@AmazingMech2418 Ah, you have a raspberry pi! Cool!

HahaYes (1862)

@AmazingMech2418 VS Code is horrible. It used to be great, but now it is so bloated

AmazingMech2418 (1039)

@HahaYes Honestly, I just use Repl.it, GitHub, Notepad, and of course Nano on my Raspberry Pi 3B+ and my Android phone running Termux.

HahaYes (1862)

@AmazingMech2418 cool, get a raspberry pi 4b?

AmazingMech2418 (1039)

@HahaYes I have a Pi 4 (I think maybe B, I forgot) with 4GB of RAM, but I still have to put an OS on the SD (currently using 32GB, but probably going to upgrade to 128) Unfortunately, Ubuntu MATE doesn't work on my Pi 4 though. I already tried and it didn't work... I even just booted Ubuntu Server, connected to Wifi using commands and USB-added packages to allow those commands to work (don't have Ethernet), and added MATE and it wouldn't work for my monitor. I had to use hdmi_safe as well, so I think it just didn't see the monitor.

HahaYes (1862)

@AmazingMech2418 Are you in college or something?

LizFoster (648)

@AmazingMech2418 WWWWWWWWWWW

So, I have made several optimizations overall, the biggest one so far being that I removed the `show()` function from a class, which should save some space and memory (I will have to write fewer lines overall). I have also removed the `SPRITE` class, since it is not in use at the moment, and I would rather worry about it when it is absolutely necessary.

I removed the black border and extra screen size, since it was a pointless addition. Finally, I have removed the `MOVEPLAYER` class, and the `win.onkey` commands related to this. It was just taking up space when it was not needed..

Do you have any more suggestions? If need be, I can invite you to the repl.

AmazingMech2418 (1039)

@LizFoster Well, I don't really have any suggestions as of right now, but it seems that there is a bug in your code. It says there is bad input on line 91. Do you have any idea what caused this?

LizFoster (648)

@AmazingMech2418 Aaah, yes, I do know what happened there.I have started re-implementing the sprites, using your sprite tool, and the line where the sprite should be (line 91) is technically incomplete.

LizFoster (648)

@AmazingMech2418 Oh yes, also, do I need to keep the `compileLine()` and `compileSprite()` functions in the game's code? They appear to already be in the sprite tool, so I am unsure..

AmazingMech2418 (1039)

@LizFoster `compileLine()` and `compileSprite()` still convert to the hexadecimal form, so they still are needed, but I guess you could probably just move it into the rendering function.

LizFoster (648)

@AmazingMech2418 Oh, yeah, probably. I'll see what I can do. Thank you!