💾 Archived View for gemini.circumlunar.space › users › emptyhallway › gournal › 20200701.gmi captured on 2023-07-22 at 17:20:00. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2020-09-24)

-=-=-=-=-=-=-

Calculating Pi

I got to do a fun, weird project recently.

My partner is knitting a shawl with beads in it. They wanted to space the beads semi-randomly, so they thought it would be cute to use digits of pi. For example, knit 3 stitches between the first and second bead, 1 stitch between the second and third bead, 4 stitches between the third and fourth bead, and so on.

On average, this turned out to be way too much space between each bead. What can you do? Well, just use the base 4 representation of pi, right?

There is at least one web site that has base-4 pi out to a hundred or so digits, but that's not nearly enough for this project. So, I got to dig around and learn a little about calculating pi in arbitrary bases. I didn't realize that there are algorithms that let you calculate any arbitrary digit of pi (e.g. the 10,000th digit) without calculating any of the preceeding digits. That's kind of mind-blowing.

Spigot Algorithms

Wikipedia had a link to an article with a Haskell implementation. It was for base-10 digits, of course. I don't know any Haskell, and the terseness of this implementation didn't make it any easier to follow.

Unbounded Spigot Algorithms for the Digits of Pi, by Jeremy Gibbons

But what the heck, there are a couple 10s in there. Just change them to 4s and see what happens. Oh, look, the output matches the base-4 digits of pi that I previously found online. Maybe it's working!

So I had it crank out several thousand digits and put them into an ebook. Now my partner will use it to knit a shawl that (probably) encodes pi into the beads, for no particular reason.

It's nice to actually finish a project once in a while.

emptyhallway

2020-07-01