Welcome Back Readers!
So, how is it going? We hope that you are enjoying the problems on Pattern. So, this problem is a really interesting problem. Here we will learn the concept of Patterns for the first time. So, the problem states that we have to print the given pattern. So, let's first understand Patterns
Important Links : Question Video , Solution Video
So we were able to print a Hello for "n" number of lines. So we can take the help of this concept and take a bit further to get out final desired result.
We program the following code for the given problem.
But, for understanding purpose, we ignore the inner loop for the time being and call it magic as it is something magical for us about which, we have no knowledge except the fact that it performs perfectly for the input value fed into it.
This magic is an important concept in the field of Software Engineering and is known as Abstraction.
Abstraction is the process of extracting the underlying structures, patterns or properties of a mathematical concept, removing any dependence on real world objects with which it might originally have been connected, and generalizing it so that it has wider applications or matching among other abstract descriptions of equivalent phenomena.
Abstraction is a fundamental concept in computer science and software development, and is similar in nature to the process of generalization.
Abstraction means giving your thinking a layered overview. When working on a layer based or placed over another layer, we have faith that the layer related or below is going to work perfectly.
Here, we do not question the working of the inner loop (labelled magic in illustration).We just focus on the outer loop with iterating variable "i" .We have faith on our magic code that it is going to work.
The thought process is that if magic is given an input value (i itself is the input value in the example in place) it will give out its output error-free. We have no concern as to how it produces the output.
This process can be correlated with a construction of a house. A person hires three men; an electrician, a painter, and a partitioner.
The Electrician is supposed to provide (create or enhance) electric points in the house for electric services in the house according to the wishes of the person.
The Painter is supposed to paint the house according to the wishes of the person.
The Partitioner is supposed to partition the house into parts in accordance with wishes of the person.
All three men work according to the wishes of the person in exchange for some currency.The person has no idea about how the work of the three men is executed or how they will do their work, he just knows that upon payment of certain amount of currency, he will get his desired specifications in his house. This is his faith (working on abstraction). If he was concerned with the working of every layer (each of the three men's work), he would not be able to get his job done properly (finished house).
Drawing similiarity into our programming world, whenever a user executes a program and the program asks user for input, the user is not concerned as to how the program will execute, he is only concerned with the correct output. He has faith on the skills of the programmer that he has programmed a competent code which will provide him with required/desired output. The currency involved in executing a program is the time & memory which is required for execution.
Coming back to our problem at hand, the outer loop we wrote has the duty to provide the inner loop proper values for which it prints correspondingly.
The current written program displays this pattern as output, which is
similar to what we desire, but not the same. As discussed earlier, we
need to provide tabs in between the stars while printing them.
To achieve this, we make amends to the print statement inside the inner loop and add a " " after printing each star.
Now this solution is complete for the given problem,and provides us with the desired output.
This output is produced when 5 is entered as input value.