So, surely you've all seen #LizFoster's attempts at calculating π, I'm here to do the exact some thing.
I take great honor in introducing to you, one of the most powerful coding languages:
Without a doubt, this is designed wholly with the intent to compete with #LizFoster, I am going to attempt to apply my post on memoization, to this project. After I make another tutorial, soon. Update, it's done: C++ Variadic Lambdas For Beginners
C++ is compiled, and the compiler can be set to create different binary outputs depending on the preference of the programmer. You have to weigh compile time against run time; I prefer longer compile time and faster run times.
To modify it's output and compile speeds, you have to manually set compiler flags when running the compiler. I'm using the optimization flags not normally activated by Repl, which Python doesn't have access to, as Python is an interpreted language. Compiled > interpreted
Running a binary without recompiling it is incredibly fast, by default, Repl always recompiles code when clicking "Run."
Try it out, I've set it to not recompile, so it has an extremely fast startup speed!
I will annotate my code later for readability and understanding. Most of it was done with the intent of high speed, but I still need help with the competitive input and output, the only thing that came to mind was desyncing stdio.
Here's a few Repl's I threw together after heavy optimization and graphing:
Cough cough... D is better than C++
If I figure out how to use an
if statement in Bash, I'll put all of these into 1 Repl.
"Not very accurate, nor very fast."
It is true though, I am not really going for speed with my approximations.
_ ____ _ ____ _ ____ | | / \ | | / \ | | / \ | | | | _ | | | | _ | | | | _ | | | | | | | | | | | | | | | | | | | |_| | | | | |_| | | | | |_| | | | |___ | | | |___ | | | |___ | | | | |_| | | |_| | | |_| | | ___| | ___| | ___| | | | | | | __|______|__ __|______|__ __|______|__ \ / \ / \ / \________/ \________/ \________/
@LizFoster I'll try to remember to tag everyone who wants to learn them! For now my tutorials are advanced coding and syntax, you'd be lost if you read them. Give it a week (or month more likely) of learning C++, then check out post: C++ Variadic Lambdas For Beginners.
Oh, and btw, totally unrelated, Repl supports HTML (you know what HTML is right?), but Repl doesn't support XHTML, can go to the link in my bio and upvote the language request? Hopefully this isn't too much for you; thanks!
Can I join the competition? (well, it's not really much of a competition since @LizFoster wasn't even going for speed anyways and also doesn't know any lower-level languages yet (she has expressed some interest in learning C++)) So, what is faster than C++? How about C? First, triangle sums: https://repl.it/@AmazingMech2418/p-in-C and second, the Nilakantha Series: https://repl.it/@AmazingMech2418/p-in-C-2 The first is slower between iterations, but is more accurate and the second is faster between iterations, but less accurate.
@AmazingMech2418 They're more accurate? How so?
Also, this post was just an attempt at getting cycles; like, if Liz could do it, I can, right?.
I'm going to break down my recent post into smaller posts for readability. C++ Variadic Lambdas For Beginners It's practically a small book because it's so long.
@LizFoster if and when you learn C++ to a sufficient degree, you ought to look at it.
I just love seeing that it works period!
SF, in the post:
I use them to see if something works and whether or not my ideas are on the right track. When I have working code I transfer it to a better language entirely. The underlying concepts remain the same though.
This allows quick development speed and a consumer quality product.
Not everyone can easily switch between languages, some have a harder time than others.
@StudentFires It looks like you just copied everything, golfed it, and then replaced printf with cout and also broke the second one (was my first) when trying to golf it. Yeah, π is 3.14..., not 3.57... What even is the point of changing it to C++? You can program in C++ with C and it takes very few changes to program in C with C++.
[Replying to comment before C++ remakes of my C pi approximations] @StudentFires Well, yours takes a while to get the same number of digits... I honestly don't even know if it can because I didn't wait that long. However, with @LizFoster 's, it takes much less time to get to the same number of correct digits. Of course the zeta(2) method is not the most accurate or the fastest, but it is still actually faster and more accurate than whatever method you used.
Do you know why desyncing with stdio is breaking this Repl: p-in-C-1?
Also, who does measuring the areas of trapezoids calculate PI?
@StudentFires Okay. It doesn't break it. Trapezoidal sums work just like Riemann Sums in calculating π. In this one, it takes a quarter of a unit circle and splits it up with trapezoids of equal width and then finds the area of that quarter of the circle using the sum of those trapezoids. Then, it multiplies by 4 since the area of a quarter of a unit circle is π/4 to get π. However, it is multiplied by 2 at the end since the area of a trapezoid is
h(b1+b2)/2 and you can just remove the "
/2" and divide the 4 by 2 so you only have to multiply by 2 at the end.
@CodingCactus Well... I linked 5 different Repls... so, which one? The one I have linked as the main Repl is getting an error right now.
Outputting the iterations left to do would slow it down significantly.
Also, I can't, it's currently a pure, tail recursive function, output isn't allowed.
Oh just found out it's a bit slow at or past 10^10. Better than Liz though.