Skip to content
Sign UpLog In
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
7

π in Kotlin

AmazingMech2418
AmazingMech2418

I think I'm pretty much doing pi approximations in every language now, and I recently learned that Kotlin is expected to beat Java in Android development, so I decided to learn the basics of Kotlin, and here is pi in Kotlin!

Here are the other approximations so far:
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

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

3 years ago

Voters

Comments

TopNew
2
Jakman
Jakman

string interpolation is a bit different in kotlin then hm...

3 years ago
1
AmazingMech2418
AmazingMech2418

@Jakman
Yeah... Not much different though...

3 years ago
2
AtriDey
AtriDey

I actually did a Nilakantha series in Python a day before I saw this, but I got 3.14159265358984 instead of 3.14159265358979.

3 years ago
1
AmazingMech2418
AmazingMech2418

@AtriDey
Try increasing the iterations. :)

3 years ago
1
AtriDey
AtriDey

@AmazingMech2418
It's going infinitely, and it just stopped there. maybe if I leave it for a day to do more iterations... -_-

3 years ago
1
AmazingMech2418
AmazingMech2418

@AtriDey
Maybe? I don't know. I did one in Python too a while back (see the list in this post).

3 years ago
1
AtriDey
AtriDey

@AmazingMech2418
I would get to start running [the repl] (https://repl.it/@AtriDey/Pi-Calculator-v2-Nilakantha) but now nothing works, I broke repl.it again. Fourth time this week; and it's only Tuesday.

3 years ago
1
AmazingMech2418
AmazingMech2418

@AtriDey
What do you mean you broke Repl.it? Is that why the connections are failing?

3 years ago
1
AmazingMech2418
AmazingMech2418

@AtriDey
Also, it's Wednesday...

3 years ago
2
AtriDey
AtriDey

@AmazingMech2418
Wait, it fails for you too? I guess repl.it is down, Cloudfare gave me some sort of notice when I checked the markdown doc.

3 years ago
2
AtriDey
AtriDey

@AmazingMech2418
My brain is broken the fifteenth time this week, and it's only Wednesday.

3 years ago
1
AmazingMech2418
AmazingMech2418

@AtriDey
I'm getting the "Failed to connect, retrying notifications".

3 years ago
2
AtriDey
AtriDey

@AmazingMech2418
Same. Guess it's time to torture the repl.it team by joining the crusade of error reports.

3 years ago
1
AmazingMech2418
AmazingMech2418

@AtriDey
LOL! I don't think that is necessary...

3 years ago
1
focat
focat

oof i got so many errors

2 years ago
1
AmazingMech2418
AmazingMech2418

@Code1Tech
Apparently, Repl.it updated to use correct Kotlin.

2 years ago
1
CodingCactus
CodingCactus

great! What lang is next?

3 years ago
1
AmazingMech2418
AmazingMech2418

@CodingCactus
I'm not really sure. Probably either Swift or Go. I'm still learning Assembly though and might have to do that one later on. Do you have any suggestions?

3 years ago
2
CodingCactus
CodingCactus

@AmazingMech2418
erm, i'll have a look at the list of languages and see which ones have cool names :)

3 years ago
1
AmazingMech2418
AmazingMech2418

@CodingCactus
For that, I've already done all of the classic languages, have done all of the popular ones besides Scheme, Go, and Rust, and plan on doing esolangs last.

3 years ago
1
CodingCactus
CodingCactus

@AmazingMech2418

oooooo..... what about Quil?

3 years ago
1
AmazingMech2418
AmazingMech2418

@CodingCactus
A pretty much failed multipurpose language by Google. It is normally compiled into JavaScript for web development I think.

3 years ago
1
AmazingMech2418
AmazingMech2418

@CodingCactus

image

Quantum???

3 years ago
2
CodingCactus
CodingCactus

@AmazingMech2418
lol, idk I'm just saying languages with nice names

3 years ago
2
AmazingMech2418
AmazingMech2418

@CodingCactus
LOL! I think Quil would be interesting, but it seems like a fairly new language anyways, so maybe save that one for later (definitely going to do it though)?

3 years ago
1
AmazingMech2418
AmazingMech2418

@NoelBryan
I already did QBasic and BASIC is really just the same in syntax and functions.

3 years ago
1
NoelB33
NoelB33

Ok, the first one I found on languages was emacs lisp

@AmazingMech2418

3 years ago
1
AmazingMech2418
AmazingMech2418

@NoelBryan
I've looked at Lisp before and I'm probably going to save the Lisp dialects for later.

3 years ago
2
NoelB33
NoelB33

Idk what bash is, but try it

@AmazingMech2418

3 years ago
1
AmazingMech2418
AmazingMech2418

@NoelBryan
Bash - The classic Bourne Again SHell on all Linux devices. You're right, I should try it!

3 years ago
2
NoelB33
NoelB33

yey!

@AmazingMech2418

3 years ago
1
TheForArkLD
TheForArkLD

@AmazingMech2418
I have idea!
(but this is my own language)
Lets do DefLang!

var defl=require('deflang') var fs=require('fs') defl(fs.readFileSync('main.dfl').toString(),'--stdout')

(Not Esolang)

3 years ago
Load more