Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more
  • Great kata. Reminded me how great mathematitian Euclides was.

  • Your algorithm is bad. With x and y being as big as few thousand, you may have to do around 1,000,000 iterations. Multiply this by 100 random tests and...

  • .

  • Most probably endless loop in your code.

    Issue is kata-related, use question tag if you require help.

  • This comment is hidden because it contains spoiler information about the solution

  • I've passed tests average 500 ms but when I try to attempt I am facing with this error
    Execution Timed Out
    help me please

  • This comment is hidden because it contains spoiler information about the solution

  • Me too. And I don't feel like maths help should be spoilers... this is after all a coding site, not a maths site. IMO spoilers should only be information that spoils how to implement the maths...

  • [Editing my reply to remove the spoiler.]

    If you have a "naive looping" implementation (generally something an algorithm that times-out or takes a long time), think about ways you can eliminate or reduce loops.

    Some general rules of thumb:

    • Mathematically, "multiplication accomplished by repeated addition" is going to be slower than using a multiplication instruction.
    • Similarly, "division accomplished by repeated subtraction" is likewise going to be slower than using a division instruction.
    • Ask yourself, "Is my algorithm doing too much? Is it solving for things it doesn't need to? Can I simplify it? Is it using/allocating resources it doesn't need?"
    • Familiarize yourself with classic algorithms and datastructures
    • Familiarize yourself with important programming paradigm shifts like functional vs object orientation vs procedural

    ...and while you're at it, take some time to review the solutions of others after you finish:

    • Are their solutions elegant/simple? (in comparison to your own?)
    • Did they use language or framework features you weren't aware of?
    • In short, is their code idiomatic?
    • Are their solutions "over clever"? (Be careful though, until you really know the language and what's possible/idiomatic, new stuff can sometimes seem overly clever or confusing.)

    Most importantly, if you take away nothing else...

    Just lose yourself in the joy of learning something new. Having fun while gaining skill is the sweet spot you want to strive for. You might just find that your naive-looping code was the springboard you needed to appreciate ever better ways of expressing ideas in code. cheers!

  • yeah indeed! :D

  • Well, that means you need a better algorithm ;-)

  • I know well, it times out if I raise it too high :)

  • Seems already implemented

  • Not a suggestion ;-)

  • Yes, and a certain number in your program is too small ;-)

  • Loading more items...