π in Rust
I think I'm pretty much doing pi approximations in every language now, so, here it is in Rust!
Like with my approximation in Go, in order to understand the object-orientedness of the language, I used structs. Though, with Rust's safe memory system, I had to do some research to figure out mutable structs...
For anyone interested in learning Rust, as it is such a fast-growing language, think of it as almost a combination of Swift and Go, but with immutability by default. There are other parts to it, but with the basics, that is pretty much how you can explain Rust in a single sentence.
Here are the other approximations so far:
Go - https://repl.it/talk/share/p-in-Go/40950
Swift - https://repl.it/talk/share/p-in-Swift/36150
C# - https://repl.it/talk/share/p-in-C/36141
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).
Also, credit to @rediar for inspiring this approximation in Rust!
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), followed by Raku (Perl 6), followed by Haskell, followed by R, followed by Dart. If you have any suggestions for after those, please let me know! I'm also thinking about making a multi-language tutorial on the transpilation of programs between languages such as what I am doing with the pi approximations.
Good work! None of this makes any sense to me in terms of the coding language T~T It is quite awesome nevertheless.
@LizFoster LOL! Thank you! Rust is quite different from Python and C++... It uses structure-based inheritance instead of class-based inheritance. It is more like C and Go which also use the same object-oriented features (although C doesn't allow methods in structures and is not considered object-oriented).
@AmazingMech2418 Ah, that's too bad. I wish there was a way to post status updates on HERE, where I can actually get feedback on my work; last time I was constantly posting new stuff I was told I should stop spamming, so... T~T
Though I'm not sure, I thought you were able to see posts even without an account; then again, I don't know and haven't really checked, so that may be wrong..
I think my computer is glitching. every time I press run it just turns back in to the button run after 1 second when it should keep being the stop button. it just says rustc 1.36.0