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

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)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: