3. Patterns #
Created Friday 18 October 2019
One of the most important topics. These are simple things, but they require clarity in the for and while loops. The best approach is the one Nidhi Agarwal already taught. How to solve a problem? A:
- Analyze the problem.
- Break down the problem into smaller problems/steps.
- Write down the solution on paper.
- Verify the solution, using random examples. If we get stuck change the solution.
- Write code, this is just a formality.
- As we print line by line, we need a loop to traverse the lines. Just write a blank while loop for this, for most problems. Now we just have to concentrate on the current line. Use i for the row counter, and j for the column counter.
- For keeping track of column, use another variable.
- We need to observe things mathematically or geometrically, or by using grids, get the hard values, then write the loops.
- Guess the number, then check the 1st and last and an intermediate case. Done. Proof: mathematical induction.
- Don’t think of the number of variables used.