Skip to main content

Thinking with Numbers

Lesson Objective

In this lesson, you will learn how to approach programming problems. We will try to understand the thinking process that is involved in approaching programming problems by building an analogy with numbers and observations related to numbers. This is a self-paced class.

Why should we think with numbers?

You must understand that computers are basically naive devices that process data and convert it into the required results. They use the instructions provided by the programmer to do so. Basically, in the future when you will be required to use your programming skills to solve coding problems, you will find that in order to think of the logic involved in the problems, you will be trying to uncover patterns in the examples provided. This is where numbers and number patterns come into play.

You will also find pattern problems like these to check your logical thinking ability in preliminary tests that you will face for getting hired. They’re like brain teasers, so let's tease your brain into thinking more critically.

Introduction to the Lesson

Today, we will be solving some number puzzles which will mainly test your skills of observation and pattern discovery.

image

This will be a fun and playful lesson and you will be guided through the thought process that is involved in solving these puzzles.You can find a plethora of such problems on various online platforms. We will be discussing 3 different formats for problems in this lesson and they are as follows:

  1. MatchStick Magic
  2. Number Series
  3. KenKen Puzzles

1. Match Stick Magic

We will be looking at some mathematical equations and geometrical shapes made from matchsticks(which are nothing but straight lines of the same length). Let's consider the following problem statement:

Problem Statement: Correct the equation by rearranging exactly two matchsticks image

Think about it, don’t go looking for the answer just yet.Trial and error is how you will learn to solve such brain teasers. If you need a hint, here’s one

Hint: Start your thought process from the right hand side of the equal to sign.

Ways of thinking and dealing with such problems

The way to approach these types of problems is to just observe the structure of the shapes included and try using the information you just gathered in multiple places until a solution clicks. The trick here is the speed with which you can observe and that will just come from practice and forcing your brain to think.

How to approach

Let us consider this arrangement of matchsticks, as you can see that the equation specified in the pattern is wrong. Observation is an important part of this, so keep an eye out.

Observation 1: 9 times 4 is 36 but the answer depicted is 46. Now, the first thing that might come to mind is can we rearrange the 4 in RHS to make it 3 somehow by moving 2 sticks because that will make it 36.

Observation 2: On further inspection we see that to formulate 3 we would need at least 5 sticks but the 4 in RHS has only 4 sticks, and we also can’t take a stick from the other digits because then it would change the equation.

Observation 3: We can also observe that 46 does not appear in the tables of any of the 1 digit numbers from 1 to 9 (Pause and try determining why?). If you were able to determine the reason for the above statement, excellent. If you were not, we are here to discuss just that. Now because we are dealing with multiplication, we have to broaden our mind and think in terms of numbers(factors, multiples, etc.).

Possible pairs of numbers that multiply to the number 46: image

46 does not appear in the tables of any 1 digit number because we can observe that 1, 2, 23, 43 are the factors of 46. So, we can conclude that we surely would have to change the RHS for this to be correct.

Let’s explore more,

  • One option that comes to mind is removing a stick from 6 and making it 5(RHS = 45). Now we would need a 5 * 9 in LHS
  • We already have 9
  • Can we change the 4 to 5 somehow by using the stick from RHS, upon inspection yes we can.

This way, the output will be as shown below image

So that was fun wasn’t it? Let’s do some more of these questions.

Follow Up You can try to identify the solution to some example problems that I am providing. Remember that the problems similar to the coding problems you will face later do not have a single pre-defined algorithm to find their solution. Your job is to find a solution by taking inspiration from the methodologies we discussed above.

Question 1: In the following figure, remove 3 sticks to leave 3 squares image

Check the hint!
Think about the various patterns the squares form and how you can change them.

Check the solution!

Question 2: In the following figure, remove 3 sticks to leave 5 squares image

Check the hint!
Have you forgotten that four small squares together form a single big square.

Check the solution!

Question 3: In the following figure, Move 1 stick to correct the equation image

Check the hint!
Did you try moving one stick from the LHS to RHS

Check the solution!

2. Number Series

We will be looking at some diagrams consisting of numbers and some of the number(s) might be missing from the diagram. Your job is to identify the missing number(s) and to do so you will be using the specified numbers in the diagram to find some pattern. Let's consider the following problem statement:

Problem Statement: Which number should come in the place of the question mark?

Think about how you would approach this problem before moving forward.

Ways of thinking and dealing with such problems

The method of dealing with numbers series problems like this one is to just observe the numbers that are known and find patterns between those numbers. The basic approach that I would suggest for such problems is to just look for relationships and patterns between numbers in all directions i.e. vertically, horizontally, diagonally etc. Along with that, your numerical ability also plays an important role here i.e. how quickly you can perform basic arithmetic operations.

Tip: I would suggest you learn squares and cubes of at least the first 15 numbers. This would turn out to be very helpful in the future.

How to approach

Step 1: If we consider the sample problem we have taken, we can observe that we have been given 3 individual circular shapes with 4 parts each. So, from this we can conclude that a common pattern is followed in all three of these circles.

Step 2: To uncover the pattern, we just brainstorm by remembering these two things: Look for relationships and patterns between numbers in all directions i.e. vertically, horizontally, diagonally etc. as I already specified. Check for the exact arithmetic operations being performed here.

Step 3: Observe that the diagonal elements from bottom-left to top-right are being multiplied and the result consists of 2 digits that are represented by the digits from bottom-right to top-left in that order. For example in the first circle, 7 x 8 = 56 So, the number that is missing is 6 (9 x 4 = 3 6)

Follow Up

You can try to identify the solution to some example problems provided below. Remember that the problems similar to the coding problems you will face later do not have a single pre-defined algorithm to find their solution. Your job is to find a solution by taking inspiration from the methodologies discussed above.

Question 1: Find out the number that should come in place of the question mark.

Check the hint!
Please take a closer look at the numbers in alternate columns.
Check the solution!
4 + 8 = 12 + x => x = 0

Question 2: Find out the number that should come in place of the question mark.

Check the hint!
Take the product of the 1st and 2nd column and do a basic mathematical operation with the 3rd column.
Check the solution!
(6 x 12) – 5 = 67

Question 3: Find out the number that should come in place of the question mark.

Check the hint!
Look at the digits from the upper half and lower half as 3 digit numbers. Eg: fig1 has 496, 992
Check the solution!
358 x 2 = 716, so 1

3. KenKen Puzzles

We will be looking at some special puzzle games in this section. We have already previously talked about the importance of quickness in using basic arithmetic operations. Well, KenKen puzzles test just that particular ability.

Problem Statement: Here, we are given a grid of size 4x4 and it has been divided into highly outlined areas as we can see.

  • These heavily outlined areas are called “cages”
  • The top left corner of each cage has a number and an arithmetic operation associated with it, the number defines the result that we must get after applying the specified arithmetic operation on the numbers in the cage.
  • Each row and column must be uniquely filled with numbers within a range and this range is decided by grid size (4x4 grid means we have to fill each row and column with numbers from 1 to 4).

Approach to KenKen puzzles

These puzzles will help us in making decisions in a constrained manner which is very helpful while solving problems. Here, you can’t use a number more than once in a row or column.(It's like a sudoku!) Similarly, while solving coding problems you might be constrained to not use some tools by an interviewer in an interview.

Step 1: In the puzzle we can see that, first of all we see that there are two cages with only one cell and they can only have one number i.e. 3 and 1. Take this as the starting point, and move forward with the consideration fix 3 and 1 there. Hence we can’t use 3 in the 2nd row and 2nd column and 1 in the 4th row and 1st column.

Step 2: Now, we just have to consider the possible combinations of numbers that can work by keeping the constraints in mind. For example, in the top left most cage, we have 1-, the possible combinations that can achieve this result are 1,2(X); 2,1; 2,3(X); 3,4; 4,3(X). The combinations marked with X are not possible due to the constraints we obtained by filling the initial unit cells.1,2 → 1 is already in the first column 2,3 & 4,3 → 3 is already in the second column

Step 3: We can see that we’re left with two possible combinations 2,1 and 3,4. Now, again we take 3,4 and fill the box, we see that we are only left with 2 and 4 for the first column.

Step 4: This is a problem, because we have to fill the middle-left cage with 1- which is not possible with 2 and 4. Hence, we have reached the only possible combination for the top-left cage i.e. 2,1. Similarly, we can use the already filled cells to fill the cells that are empty. Remember, the process of elimination of possibilities is the key here.

Complete Solution:

Follow Up

You can try to solve more of these puzzles and if you are still stuck, try solving KenKen Puzzles of size 3x3 online and then using the experience you will be able to solve the harder 4x4 puzzles.

Solve the given KenKen puzzle:

Check the solution!

And if you think we are done with Numbers, here is what we wanted to say.

Source: Giphy