• @xthexder
    link
    fedilink
    English
    11
    edit-2
    5 months ago

    Ah yes, my favorite recurring lemmy post! It even has the same incorrect test output.

    Last time I saw this I did a few calculations based on comments people made:
    https://l.sw0.com/comment/32691 (when are we going to be able to link to comments across instances?)

    • There are 9592 prime numbers less than 100,000. Assuming the test suite only tests numbers 1-99999, the accuracy should actually be only 90.408%, not 95.121%
    • The 1 trillionth prime number is 29,996,224,275,833. This would mean even the first 29 trillion primes would only get you to 96.667% accuracy.

    In response to the question of how long it would take to round up to 100%:

    • The density of primes can be approximated using the Prime Number Theorem: 1/ln(x). Solving 99.9995 = 100 - 100 / ln(x) for x gives e^200000 or 7.88 × 10^86858. In other words, the universe will end before any current computer could check that many numbers.
    • lad
      link
      fedilink
      English
      15 months ago

      But you can use randomised test-cases. Better yet, you can randomise values in test-cases once and throw away the ones you don’t like and get arbitrarily close to 100% with a reasonable amount of tests