How to Solve Programming Problems Like a Pro

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ม.ค. 2025

ความคิดเห็น • 14

  • @thecodinglion
    @thecodinglion  5 วันที่ผ่านมา

    Access our free newsletter: thecodinglion.beehiiv.com

  • @FoXcodeZ
    @FoXcodeZ 18 วันที่ผ่านมา +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 18 วันที่ผ่านมา +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  18 วันที่ผ่านมา +1

      Nice try. But it is still not optimized

    • @E.N77
      @E.N77 6 วันที่ผ่านมา +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 6 วันที่ผ่านมา

      @@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 9 วันที่ผ่านมา +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

  • @ladiyehl
    @ladiyehl 4 วันที่ผ่านมา

    I gotcha you bro