3 ms·
It is doing this: sin(555555555555555555), where the 5's are an x number of 5s that increasingly converges on pi, and calculates the correct decimal placement.
by ksaj 2y ago
It is doing this: sin(555555555555555555), where the 5's are an x number of 5s that increasingly converges on pi, and calculates the correct decimal placement.
It's not (quite) as trivial as just copying the pi.
- valicord 2y agoNope, that is not what it does. First, sin(x) ~= x for small x. Second, 1000.../555... = 1.8. Neither of these have anything to do with pi. With these in mind, the program can be simplified as sin(radians(repeated)) * (10 ** (repeat + 2)) = radians(repeated) * 100 * 1.8 / repeated = repeated * pi / 180 * 180 / repeated = pi The main and only reason you get pi in the end is that the radians function is defined as radians(x) = pi * x / 180, which requires knowing the value of pi to begin with. So this program is basically an equivalent of multiply_the_argument_by_pi(555) / 555 except with a few layers of completely unnecessary math on top of it to obscure the magic trick.
- ksaj 2y agoIf that was the case, any number other than 5 would also work. Try that.
- valicord 2y agoAny number works if you adjust the multiplier to preserve the 1000.../555... = 1.8 property. For example: https://www.online-python.com/Um4qevAzo2 https://www.online-python.com/Um4qevAzo2
- ksaj 2y agoAh, that's a missing link I hadn't thought of. This was a result of converting degrees to radians. There is another way as well. from math import sin, acos def nines(repeat: int) -> float: repeated = 2 / int('9' * repeat) value = sin(repeated) * acos(repeated) * (10 ** repeat) return value nines(18) I'm sure this can be edited to accept other values in the same way. Took a while to convince me, but you got there.
- valicord 2y agoHint: it works just as well if you replace the acos argument with 0 value = sin(repeated) * acos(0) * (10 ** repeat) (keep in mind that that acos(0) = pi/2)