4 ms·
But... This code just outputs almost-zero. It clearly just sets `repeated` to a number very close to zero, takes the sin of it - which will also be close to ze
by plasticeagle 2y ago
But...
This code just outputs almost-zero. It clearly just sets `repeated` to a number very close to zero, takes the sin of it - which will also be close to zero - and then multiplies that by a small number.
I don't think this is how discoveries are going to be made.
What am I missing here?
- ksaj 2y agoIt outputs a very close estimation of pi every time. The slash-* is from how HN interprets the code (poorly). Here's a corrected one using a margin: from math import sin, radians def fives(repeat: int) -> float: repeated = 1 / int('5' * repeat) value = sin(radians(repeated)) * (10 ** (repeat + 2)) return value fives(18) Cut/paste that into your python repl, and make sure the lines are intact without the HN extra indents. Change the 18 to any int you want (except it overflows at 308... easy to fix, but not worth bothering). It might be close to zero... but it's much more like 3.14... when you run it.
- plasticeagle 2y agoYes, that does fix it. But using `sin`, and `radians` means that you equation to generate pi already has pi in it.
- ksaj 2y agoSure. But make the connection with the 5s. It isn't just copying that pi. It is getting there in a very non-direct route. You can do the same with 9s, for the same reason you might be picking up on if you don't trivialize that there is another pi in the mix. You can't escape it when you're talking about circular things, regardless. Every proof or non-coincidental estimate of pi (ie: not 22/7) out there has pi embedded in the proof somehow. Dismissing it is like saying the Pythagorean theorem is bollocks because they also add up to the same number of degrees. Even though you're describing it in lengths, the degrees don't disappear. This code is very much like that. Just not triangular.
- valicord 2y agoThe thing is that in this particular case it does in fact just copy the pi. You're essentially calculating radians(x)*180/x, which by definition is equal to pi. The radians function is doing all the heavy lifting, unlike say using the Taylor series or some other approximation approach.
- ksaj 2y agoIt 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.