Pi digits (again) - an unbounded spigot program
|
05-12-2024, 05:03 PM
(This post was last modified: 05-12-2024 07:42 PM by EdS2.)
Post: #1
|
|||
|
|||
Pi digits (again) - an unbounded spigot program
There's a previous mention of Jeremy Gibbons' unbounded spigot not too far away (1, 2) but I don't think I've seen a running version here.
Anyone care to convert the following Basic code, or something close to this JavaScript code, to an HP-71B, or perhaps to a Free42 based calculator, or a Prime, or perhaps a Sharp Pocket Computer? Strictly, for this spigot to work properly, we need a bignum package, but it turns out to do something interesting even if you just use ordinary floating point numbers. We might get 40 digits of pi on Free42, for example - or we might not! Because this code will only print some number of correct digits in any given environment, it might be worth reformulating with a FOR NEXT loop that counts out the correct digits and then stops. (Ideally, also print the first incorrect digit too, so we know we've reached the right point.) Code: 10 q = 1: r = 0: t = 1: k = 1: n = 3: l = 3 You can see this code running in a BBC Micro context as a one-liner here. (Edit: this link works as expected in Chrome, not in Safari, sorry about that. Not sure about other browsers. If you don't see a pi program running, just copy the text from the box above and paste it in as a replacement to the left pane of owlet.) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)