Hacker News new | past | comments | ask | show | jobs | submit login

Sure. 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.




The 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.


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.


Nope, 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.


If that was the case, any number other than 5 would also work. Try that.


Any number works if you adjust the multiplier to preserve the 1000.../555... = 1.8 property. For example: https://www.online-python.com/Um4qevAzo2


Ah, 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.


Hint: 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)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: