π in Swift
I think I'm pretty much doing pi approximations in every language now, so, here it is in Swift! By the way, compare this to Kotlin and see why Kotlin is starting to take over Java in Android development (Swift is for Mac and iOS development).
Here are the other approximations so far:
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, thank you to @HahaYes for inspiring this approximation to be done in Swift after attempting your own version with a binary search algorithm!
Cool. I dont think you needed a class tho. Is swift a language where everything is done in a class in that case?
@Jakman I know I don't need a class (could have just done a function), but I plan on eventually creating mobile apps with Kotlin and Swift, so I should know how to do classes in them.
Ah, stealing my thunder I see
@HahaYes LOL! Yeah, I guess. However, I did the Nilakantha Series.
@AmazingMech2418 Ah, you chose the easier path.
Binary search algorithm sucks btw
Cool!I viewed your all pi!
@TheForArkLD Thank you!
@AmazingMech2418 And if you can calculate pi in my own language then i am happy :)
@TheForArkLD Currently, I'm not even planning on doing it in any of my own languages (XPL, EAGL, Inventor, Adapt, etc.), so, I'm sorry, but I likely won't do it in your language.
@AmazingMech2418 hmmmm ok
(but Someday do it please :))
noice
@Warhawk947 Thank you!
This ones pretty fast also
@NoelBryan This one is also a lot like Kotlin. Honestly, after seeing the similarities, I just copied and pasted and changed the for loop and changed println
to print
.
@NoelBryan Thank you! The two languages are nearly identical, just that they have different functions, a one-letter difference in function declarations (fun
in Kotlin, func
in Swift), and different loop and conditional syntaxes.
Oh, maybe I can learn a bit of Kotlin then, I’m learning a bit of swift also but I’m no good at it @AmazingMech2418
@NoelBryan If you are better at Python, do Swift. If you are better at JavaScript, C, C++, or any other C-family language with the same syntax, learn Kotlin first.
@Codemonkey51 Thank you! By the way, that was fast!
Yep I check new :) @AmazingMech2418
@Codemonkey51 I do too. Actually, I said that was fast. I should use a better word instead. Maybe "swift"? LOL!
@Codemonkey51 LOL! I just noticed that I'm on the "hot" page of Repl.it Talk 4 times...
lol @AmazingMech2418 also congrats on 300 cycles
@Codemonkey51 Thank you!
@DigitCommander Thank you!