Mathematical Intervention to the World of Programming
Programming and Mathematics
Programming is the art of directing a computer to perform an arbitrary action that uses certain rules and principles and results in a number of useful applications, websites, software, operating systems, and so on.
As we know, there are different styles of writing programs, so each problem requires a corresponding style approach.
Style is a well-known paradigm.
Below are some approaches that will be discussed separately:
Object-Oriented
Functional
Logical
Imperative
Object-oriented
programming allows having objects, each of which has its methods. Functional programming allows writing programs in the form of mathematical equations and functions, while logical programming is a paradigm based on the proof of an automatic theorem and is considered a separate branch of mathematics that studies the logical principles of information according to the given facts and the rules of the inference.
As for the imperative approach
, it allows designing the program step by step, making simultaneous modifications. All the mentioned approaches are somehow related to mathematics.
Mathematics teaches to use and apply algorithms that are a great start to develop logic.
In the search for optimal solutions to different problems, analytical thinking is one of the tools obtained by studying mathematics.
What is an algorithm?
It is an operation, a set of rules that allows finding solutions to even the most challenging problems. By solving mathematical problems, we develop our logic and analytical thinking, which helps us find various solutions to the given problem by dividing it into smaller parts and analyzing them sequentially.
Analytical thinking involves the following:
- Understand the requirements of the problem
- Thoroughly consider all the possible details that can help find the solution
- Find the optimal solution to the problem based on the given information
It is not reasonable to start without considering the above-mentioned three points as there will be a risk of facing problems, for which one will have to start from scratch, making fundamental changes in the whole logic of the solution.
Taking all this into consideration, let’s understand how and where it is applied in computer science.
Let’s start with game development, where mathematical knowledge is essential in creating games and providing different functional capabilities.
All the games where the characters perform actions, such as moving, running, fighting, etc., require mathematical and trigonometric knowledge that will allow organizing the characters’ accurate movements through making precise calculations.
If you want to delve into game development in the future, then algebra, trigonometry, and geometry are the exact sciences you’ll need to emphasize.
In the advanced programming spheres like AI (Artificial Intelligence
) and ML (Machine Learning
), it is nearly impossible to make decisions without mathematical knowledge.
The part of mathematics that extends to AI and ML is statistics.
Data is the primary foundation in these two fields, and the process of analyzing and consuming that data is statistics.
The knowledge of modeling and cryptography is also important here. Both of them use arbitrary numbers generated with the help of mathematical-logical thinking.
Logical problems are also very common in the field of programming, especially during interviews. Enormous companies like Google
, Microsoft
, or Meta
use such questions when selecting new employees.
Let’s take a look at some of them.
Problem 1: Why are maintenance hole covers round?
Solution: When a maintenance hole has a circular structure, the possibility that the cover will fall into it is minimal because of the diameter.
Problem 2: On the table, you have five containers filled with seemingly identical pills, each weighing 10 grams except for the one filled with toxic pills. Weighing only once, find the container with toxic pills, given that each toxic pill is 9 grams.
Solution: The first step is to number the containers. Then take a different number of pills from each container (for example, one pill from container#1, two pills from container#2, and so on) and put them on the scales. Let’s suppose the number displayed on the scales is 141. The maximum weight of all ten-gram pills will be 150 grams (multiplying the total number of pills by ten). The next step is to do the following operation with that number: 150–141=9 and find out the weight of one toxic pill. As a result, it will be clear that the toxic pills are in container#1 because only one pill was taken from that container.
Problem 3: We have two empty buckets, one of which has a volume of 5 liters, the other — 3 liters. How to fill the five-liter bucket with four liters of water?
Solution: There are multiple solutions, let’s consider one of them. First, let’s fully fill the big bucket and immerse the small one in it. In this way, we will empty the big bucket with three liters, leaving two liters there. Then we’ll pour these two liters into the small bucket and will repeat the step. As a result, we’ll have two liters again, to which we’ll add two liters of water that we already have in the small bucket.
Problem 4: How to divide a cake into eight pieces by cutting it only three times?
Solution: We need to divide the cake into four equal parts by cutting twice. Then we need to make the third horizontal cut right in the middle of the cake. Even though the cake will not look appetizing after that, at least the problem will be solved.
When solving such problems, you need to pay attention to a few important points. First, be attentive to the details considering all the possible options. Second, ask for additional information as they sometimes expect the candidate to ask clarifying questions (when analyzing the problem or building some logic).
- Approach the problem from different viewpoints.
- Avoid awkward silence; you can analyze the incorrect versions loudly.
- When solving a logical problem, mathematical formulas are not always helpful. Everything depends on the position you are applying for. Remember that the solutions to such problems do not require in-depth knowledge in a particular sphere.
So, is it possible to develop logic and how to do that?
In order to have flexible logic or become a mathematician, a few short hours are not enough. The people who have achieved significant success in this field, have done it with diligence and hard work, spending hours and hours finding a solution to a particular problem.
Another helpful piece of advice is to avoid comparing your skills and abilities to those of others while studying. The final and complete understanding of knowledge is more important than the time spent on it, isn’t it?
Here are some tips to help you go ahead confidently:
- Create a studying environment where nothing and no one will distract you. Turn your phone off and forget about social networks.
- Study every day whenever and wherever possible. Always remember that time is very valuable to be spent inefficiently. Give reasonless habits up; they only waste your time.
- Take short breaks. Avoid working on the same task for hours because it can cause stress. Breaks will help have some rest and approach the problem from other angles.
- Practice is also essential, so try to constantly repeat what you have learned and solve as many problems as possible. When learning something new, write it down, and try to think of other options or solutions. If some mathematical topics are difficult for you, don’t hesitate to start your study right from there.
- If you fail at something continuously or the solution is incorrect, start from the very beginning. Do not look for excuses to procrastinate in finding new solutions. In such cases, it is crucial not only to find the correct answer but also to understand why the previous one was incorrect.
Remember that the time spent on studies is never wasted!