Calculating Pi in Hopscotch




I researched this topic a little and believe that you're spot on with the use of a Spigot algorithm. Due to the limited precision available to use on Hopscotch, a spigot algorithm may be the only way to accomplish this.

I've a few ideas on how to implement the code. Would you like input on what you've done so far, or would you like me to just give it a go?


I have a few things that may of be of use. First off, here is a base 10 spigot algorithm that is in O(n^2) time.

Where v(p,k) is the multiplicity of the prime p in k (the exponent of p in the multiplicative decomposition of k in prime powers, another name is "p-adic valuation").
Example : v(3,18)=2 since 18=2⋅32

I tried and failed to implement this awhile back, but now that there is modulo and floor, it will be much easier.
Another base 10 algorithm is described here:

The hardest part will be summing binomial coefficients, but it also should be pretty simple to implement.

But I really haven't made much progress. Go ahead and give it a shot, and show me what you are doing along the way :smiley:




I'm interested in seeing if this will legitimately work in Hopscotch. Have you attempted coding the Spigot algorithm in-app?


Yeah, but it's close to impossible. Especially calculating the exponent of a certain number in the prime factorization of n, and using lists. If anyone can do it, I'll be thoroughly impressed. Although I doubt that will happen, so I'll offer my account pass as a prize to whoever can do it.



Would be very interesting to see. Wish there were lists/arrays in Hopscotch.


uh. only to ur hs account. thx.


I'm not good at math, can't do this sorry



@BuildASnowman, @Gilbert189, et al
It’s almost Pi Day. Anyone still interested interested in this?

Turns out that implementing a base 10 Rabinowitz and Wagon spigot alogorithm in Hopscotch is actually relatively easy in Hopscotch…


I was thinking of using clones to make a binary calculator which would convert into base 10.

The clones would display the numbers so that high precision calculations would be possible.

Speaking of pi day
Maybe there should be an app with different formulas to calculate pi, and you could watch the process of the formulas run as they diverge to pi.


Those are good ideas. Although the spigot algorithm doesn’t produce a number that converges. It sequentially yields the digits of pi, one at a time. But using clones, the algorithm can calculate 1 digit per frame. And using a Gosper series instead of Euler’s, we only need Log13(10^n) clones to calculate n digits.


With the new (at least, past my time) math functions in Hopscotch, implementing a spigot algorithm should be much simpler. Sadly, I no longer have an IPad :slight_smile: Theoretically, I could use my Hopscotch scripting language thing to make a json file that someone else could upload but I have a feeling this project would be sufficiently complicated as to require some manual error correction in the json, and knowledge of Hopscotch’s json structure has also left my mind.

But I implore any of you that want to try - please do. 2 Pi-days later, we could finally finish this challenge.


This is very interesting and well thought out. I was thinking maybe something to do with sine and cosine and then somehow calculating a diameter.


Actually, the only math functions that are required are +, -, *, /

The Rabinowitz and Wagon algorithm doesn’t even require floating point arithmetic.

Although, it does use modulo but modulo could be coded using other math functions that have always been there.


Here’s screenshots of the calculation (this is the Rabinowitz and Wagon algorithm except using Gosper’s series)


I wish Hopscotch would display the full equations :pensive:

The most significant language aspect that wasn’t available originally are the object variables (with self references).


To calculate a precise amount of digits you also need the floor function, but yeah. When I tried implementing it a while back it just got too complicated because I tried doing modulo and floor with a helper object so I wouldn’t have to re-code it every time I need it, but for reasons I don’t remember (probably timing) it just got waay overcomplicated. Plus the fact that at that time all clone variables were held in speed and rotation.

So, just to clarify, the code above works and produces the right digits?


Here’s a preview. I’m going to limit the calculation to about 4400 digits or else I’ll have to slow down the max calculation speed. If anyone wants to check the project for correctness before 3/14, just let me know :wink:


Well, looks like you’ve done it. After 2 years.



Tomorrow is Pi Day!!