Ad
  • Custom User Avatar

    A more traditional parser. Note the use of a container class ("State" in this case) to provide a mechanism for the inner functions to modify the variables. This is just to follow the initial architecture of a single parse function -- a better way would be to create a Calculator class with a parse() method.

  • Custom User Avatar

    Though this is a sensible and elegant algorithm, I would not qualify it as especially fast, as the title suggests.
    It definitely is fast enough for small primes, but try running this one for example:

    Test.expect(isprime(1734822086675357441), "1734822086675357441 is prime")
    

    Here an output of the timing for this test on my machine:

    $ time python3 kumite-quick-prime.py
    1734822086675357441 True
    
    real    1m24.664s
    user    1m24.610s
    sys     0m0.010s
    

    I wrote up an alternative version, which is able to produce output pretty fast for larger numbers as well.
    Here the timing of an example run using this code:

    $ time python3 kumite-quick-prime.py
    1734822086675357441 True
    1734822086675357442 False
    1734822086675357443 False
    
    real    0m0.038s
    user    0m0.030s
    sys     0m0.000s
    

    So let's say that there is room for improvement ;-)

    Kind regards,
    Maurice