New answers tagged

4

Reinventing the wheel Now I will try not to sound too harsh, but did you attempt to google the problem at hand before starting? Building habits in programming is important, but it is equally important to building upon existing code. A quck search gives me the following useful links here, here and here. General comments l = len(nums) - 1 This needs a better ...


4

You can reduce a lot of your code just by using pythons builtin abs function. I also used list comprehension to shorted your code, so your entire loop code is now in one line. This also looks like a great candidate for a function. Now, you can pass any collection of numbers to the function, allowing you to reuse this code however many times you want. from ...


3

It's more common to use Euler's method to find GCD, rather than factorising both numbers. However, I'll continue reviewing with the existing algorithm, as there's useful insights to be found. First, let's look at factors(). Our factors variable is being used as a counter or multiset, and Python provides us with a collections.Counter class for that. With ...


3

Coming from a math background and with no C++ experience, here's what I notice: You jump between if (condition) { body inline } and if (condition) { body by itself } Stick with the second. Your function and parameter names need to be more descriptive. Failing that, you should comment why you're doing what you're doing. precision should be iterations. ...


Top 50 recent answers are included