1 / 5
Mar 2009

I just noticed that some of the fastest solutions to INUMBER (http://www.spoj.pl/problems/INUMBER3) are in Python. I solved this one quite a while back, and I remember that I had to do a bit of optimizing just to get my C++ solution to pass. Can someone please share their fast code secrets for this problem?

Thanks in advance.

  • created

    Mar '09
  • last reply

    Mar '09
  • 4

    replies

  • 265

    views

  • 2

    users

  • 3

    links

It's just machine code (possibly compiled from low-level C or Assembly), encoded in a variable, and hooked in to run through the Python interpreter smile.

Thanks for the clarification. I guess it is the only way to get a 'python' submission run that fast.

OTOH, I noticed that the third fastest Python solution is by Tim Peters (http://www.spoj.pl/ranks/INUMBER/lang=PYTH6). I'd be surprised if even he had used something like that.

Tim Peters' solution is indeed perfectly valid Python code (only highly optimized smile ). I'm afraid I don't know Python well enough to explain the general idea.

BTW, in the overall ranks you will find that there exist faster solutions in other languages (spoj.pl/ranks/INUMBER/2).

I knew Tim Peters must have used some really masterful techniques. I guess I'll just have to figure them out myself.

Thanks for all your help.