Programming for me is an art: the art of solving problems, where each one must be taken into consideration and be solved, following a particular list of determined actions. I assume that the readers of this article are non-programmers who have no idea about programming. Welcome to Programming For Dummies, Part I. This series of articles will take you into the world of programming and problem solving and will help you learn how to code simple and complex programs.
To begin, I want to ask a question: What is the result of one plus one?
Some would say two, while others would say ten. They're both wrong, because there is no result unless you define what you are adding. This a common mistake. However, since we have all implicitly agreed that adding involves numbers, one plus one equals two.
Problems and Problem Solving
From ancient times, Man has been solving problems; just consider mathematics, physics, astronomy and many other sciences that were devised to solve everyday problems.
A common problem was what I posited above: "How much is something plus some other thing?" From those simple questions today we have a whole set of mathematical theories governing operations as simple as addition and subtraction or as advanced as limits and differentials.
To solve a problem, we have to have a correct understanding of the problem, which is why we need definitions. Imagine that we have 10 kg of apples and we define the selling price as 0,30 euro per kilogram. How much money will we get if we sell the apples? Simple multiplication tells us that will get 3 euros, but the key is understanding how we reached that conclusion.
0,30 + 0,30 + ... + 0,30 = 10 x 0,30 = 3,00 euros
Simple problems like that are, well...simple. How about something more complicated like how to cook spaghetti?
- Gather the ingredients
- Fill a pot halfway with water and put it on the stove
- Let the water boil
- Add the spaghetti
- Cook until ready (be sure to let them cook no more and no less than necessary, approx. 11-13 mins)
To solve the problem we created a list of discrete steps, and similarly, by following a list of defined steps you can solve most problems. There are three categories of problems:
[list][*]
Solvable: The ones that have been solved and have a solution.
Unsolvable: The ones that cannot be solved.
Open: The ones that have not been solved yet.
We will mostly meet solvable problems in our programming career. There are different methods available to solve these problems and arrive at the same result. However, sometimes we will find an open problem, whereupon we need to either solve the problem, or mark it as unsolvable.
To solve a problem you have to create an algorithm. An algorithm is the process of problem-solving by creating a list of logical steps needed to solve the problem. An example is the spaghetti cooking problem above.
Variables
In school we learned to do more than simple addition and subtraction: we also learned how to solve equations. A simple equation would be:
3*x=24
where we want to know the value of x. Let's try to solve this one:
3*x 24
3*x=24 <=> --- = --- <=> x = 24/3, x=8
3 3
So x equals 8. X is a variable, meaning that it can take any value that will solve the equation. In programming, variables are placed in three major categories: logical, numeric, and alphanumeric. Logical variables can only be true or false. Numeric variables can only be numbers. Alphanumeric variables can be any type of character, where a character is defined as a letter, number or symbol.
Conclusion
Today we have learned that everything in this world is a problem. Not all problems have a solution, so we learned how to think in order to arrive at a solution for a solvable or an as-yet unsolved problem. The second part will continue on with more about variables, and dealin-depth with condition checking. |