𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 𝘁𝗼 𝗢𝗽𝘁𝗶𝗺𝗶𝘇𝗲 𝗣𝘆𝘁𝗵𝗼𝗻 𝗖𝗼𝗱𝗲
Stop jumping into code. Think about the logic first. Use flowcharts. Do manual math. This process helps you write better software.
Example 1: Sum of numbers up to N.
- I started with a while loop.
- I switched to a for loop for readability.
- I ended with a math formula. The formula is the fastest. It removes the need for loops.
Example 2: Sum of prime numbers.
- I checked every number.
- I noticed even numbers are not prime.
- I skipped even numbers to save time. The code became faster.
My learning path:
- Working code.
- Cleaner code.
- Faster code.
- Smarter logic.
Do not worry about the perfect answer first. Make it work. Then make it better. This is how you learn.