How to Solve Programming Problems Like a Pro

Поділитися
Вставка
  • Опубліковано 2 січ 2025

КОМЕНТАРІ • 11

  • @thecodinglion
    @thecodinglion  7 годин тому

    Access our free newsletter: thecodinglion.beehiiv.com

  • @FoXcodeZ
    @FoXcodeZ 13 днів тому +5

    Optimization: The for loop inside the isPrime function doesn't need to iterate over even numbers, as all prime numbers (except 2) are odd.

    • @the_daily_improvement
      @the_daily_improvement 13 днів тому +3

      I am not really good at programming but i don't think this solution will optimize thee problem. Nice try by the way.

    • @thecodinglion
      @thecodinglion  13 днів тому +1

      Nice try. But it is still not optimized

    • @E.N77
      @E.N77 День тому +1

      Dude ... He was not giving a course on how to optimize the code ... He just give an example for us to understand the problem solving ....
      And by the way ...
      That's not optimization you basically add another problem to solve
      Instead : you can make the loop go through the half of the round (number) 🤝

    • @FoXcodeZ
      @FoXcodeZ 23 години тому

      @@E.N77 He literally asked for that type of comment at 3:00, so you misunderstood my point. Rejecting unnecessary elements is part of optimization, aligning with Donald Knuth's statement: "Premature optimization is the root of all evil".

  • @christiantld
    @christiantld 4 дні тому +1

    Optimizing the function isPrime:
    - if num is 2 return true
    - if is even return false (all primes are odd)
    - we don't need to iterate over all numbers, just to square root of given number
    Optimizing the function printPrimesInRange:
    I'm not sure if it is a real optimization but i thought about using recursion over the elements of the array