Skip to content
← Back to Community
π in Bash
Profile icon
AmazingMech2418

I think I'm pretty much doing pi approximations in every language now, so, here it is in the classic Linux shell: Bash!

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

Note: Bash is SLOW

Voters
Profile icon
Code1Tech
Profile icon
ANDREWVOSS
Profile icon
TheForArkLD
Profile icon
NoelB33
Profile icon
Navinor
Profile icon
CodingCactus
Profile icon
AmazingMech2418
Comments
hotnewtop
Profile icon
Navinor

nice!

Profile icon
AmazingMech2418

@Warhawk947
Thank you!

Profile icon
NoelB33

I think repl.it is down, I can’t access any repls but I’ll try it later!

Profile icon
AmazingMech2418

@NoelBryan
I think it is.
@AtriDey
is having the issues too.

Profile icon
AtriDey

@AmazingMech2418
@NoelBryan
I reported it, but I'm taking it down since there are dozens of other reports already and the repl.it team is struggling as is.

Profile icon
NoelB33
Profile icon
NoelB33

The repl works now! Bash is slow, your right, but that’s really cool!

Profile icon
AmazingMech2418

@NoelBryan
Thank you!

Profile icon
NoelB33

If you want another language, do scheme

@AmazingMech2418

Profile icon
AmazingMech2418

@NoelBryan
I said I was going to save Lisp dialects for last... Also, I am about to post C#.

Profile icon
NoelB33

Oh, idk what scheme actually is lol

@AmazingMech2418

Profile icon
AmazingMech2418

@NoelBryan
Scheme and Clojure are Lisp dialects.

Profile icon
NoelB33
Profile icon
Code1Tech

cool! im also working on c#. im learning the basics so i can use unity!


@AmazingMech2418

Profile icon
AmazingMech2418

@Code1Tech
Thank you! Nice!

Profile icon
CodingCactus

is it supposed to say command not found???

Profile icon
AmazingMech2418

@CodingCactus
Oops. I need to uncomment line 1.

Profile icon
AmazingMech2418

@CodingCactus
Should work now.

Profile icon
CodingCactus

YAY

Profile icon
AmazingMech2418

@CodingCactus
When you forget to install a non-native Bash package...

Profile icon
Code1Tech

its so funny how u can delete the main.sh file without forking lol
i used a bash cmd called rm (rm main.sh) so easy lol

Profile icon
AmazingMech2418

@Code1Tech
You can do that in any repls. You can use os.system in Python for example.

Profile icon
Code1Tech

@Code1Tech

bash

Profile icon
Code1Tech

just made a file


@Code1Tech

Profile icon
AmazingMech2418

@Code1Tech
It is not a defense system... It's just a repl. It has a Bash command line and only saves temporarily on your version of the repl.

Profile icon
Code1Tech

ik its just ive never done that


@AmazingMech2418

Profile icon
AmazingMech2418

@Code1Tech
I've done it many times. LOL! It's fun when you can hack a Tic-Tac-Toe game by making a copy of the source code and piping it into the repl using the curl command.

Profile icon
Code1Tech

i tried deleting runner using -f.. it said -f isnt a thing.. could you help me? i started using bash yesterday lol.


@AmazingMech2418

Profile icon
Code1Tech
Profile icon
AmazingMech2418

@Code1Tech
rmdir is what you need, but I don't think you have access to delete that directory.

Profile icon
Code1Tech

@AmazingMech2418

bash2

Profile icon
Code1Tech

i did use look at the picture ^^


@AmazingMech2418

Profile icon
AmazingMech2418

@Code1Tech
You just use rmdir. No -f.

Profile icon
Code1Tech

hmmm i tried but it says no permission. the only choice is to make a fake runner using mkdir and del that (lol.) but i have seen people delete runner..

@AmazingMech2418

Profile icon
Code1Tech

oof cant even make a fake dir next to the real one.


@AmazingMech2418

Profile icon
Code1Tech

omg i just deleted _test_runner.py
(i didnt know bash runs on python.. prob bc it might be written in python bc its a shell)

bash3

@AmazingMech2418

Profile icon
HahaYes

Well since you did C I must do C++

Profile icon
AmazingMech2418

@HahaYes
I decided not to do C++ since it is really just changing the output method from printf to cout and changing the library to iostream.

Profile icon
HahaYes

@AmazingMech2418
Check mine out, it isn't the best, but it works.