## Puzzles in the Book

Seven friends went to a pub and kept their caps (one each), outside. Each cap had an identifiable mark. At the time of leaving, they picked up one cap each, at random and wore it. They found that none of them was wearing a cap belonging to him. In how many ways can this happen?

##### Solution:

In all, there are 1,854 ways in which this can happen. This class of problems is known as “Derangement Problem”. How this number is arrived at, what are the theoretical considerations etc are discussed in detail in my book.

Use the ten digits from 0 to 9 once and once only, for making three integer numbers N_{1}, N_{2 }and N_{3 }such that N_{1} multiplied by N_{2} gives the product N_{3}. How many such number combinations can be made? As a variation of the problem, if the nine digits 1 to 9 are to be used only (no zeroes), how many combinations of above type can be made?

##### Solution:

With N_{1} of two digits, N_{2} of three digits and N_{3} of five digits, there are 16 solutions. If we take N_{1} of single digit, N_{2} of four digits and N_{3} of five digits, there are 15 solutions. Some of the solutions out of the 31 use only nine digits, omitting 0 (zero). How to get these solutions and how to write the computer program are discussed in my book.

Using the nine digits from 1 to 9, once and only once, make two, three or four proper fractions in such a way that when the fractions are added together, will produce the sum as 1.

##### Solution:

Eighty seven solutions exist for this problem. How to generate these solutions, including how to formulate the problem as well as the computer programs are all given in my book. As a variation, the sum can be any integer, not necessarily 1. As another variation, the sum can be a simpler proper fraction itself. For both the variations, method of solutions and computer programs are given in my book.

There is a necklace having nine total beads. There are two types of beads, some white and the rest black. In how many ways can the necklace be formed? In doing so, a mirror image or rotated variation of an earlier solution is not to be counted as a new solution. In short, we wish to have only the original solutions.

##### Solution:

Total 44 solutions exist involving different number of white and black beads. How to find these solutions, how to write computer program for comparison and elimination of mirror images and rotations, etc are given in my book. Also worked out, is a similar problem using three colors instead of two.

This problem is taken from “Mindsport” column of Sunday “Times of India” dated June 9, 1996. The problem statement is as follows “If you take six building blocks, two of each colour, it’s possible to pile them in such a way that one block (of other colour) is between the red pair, two blocks between the blue pair and three between the yellow pair. Or if you think no problem is worth its weight in copper nitrate unless numbers are substituted for the coloured blocks then 1, 2 and 3 will do the job quite nicely, thank you. Meaning, you now have the number 312132. Not counting its reversal, this was found by the Scottish mathematician C Dudley Langford, to be a unique answer to the problem of arranging the six digits so that there is one digit between the 1’s, two digits between the 2’s and three digits between the 3’s.

“There is a similar unique solution for four pairs of differently coloured blocks to stop all of you whove been babbling on and on about not getting problems with ‘unique’ solutions. Happy now? (And if that is too easy, try with five pairs).

“For non-babblers, on the other hand, there are 25 solutions for seven pair”.

##### Solution:

The problem statement says that there are 25 solutions for this problem with seven colors. I was able to find 26 solutions. Obviously, my method is more efficient and exhaustive. This method and the computer program based on my method are given in my book. When the solutions were sent to the paper, my letter and the solutions were published without commenting as to how the problem setter missed a solution and why.

Right angled triangles have fascinated mankind for generations. Pythagoras gave us the famous theorem that the square of the (length of the) hypotenuse equals the sum the squares of the (lengths of the) other two sides. In India, it is debated whether Pythagoras was really the first one to discover or prove this rule. In fact, this author’s mother’s maternal uncle has written a book showing that a part in the Vedas, called “Shalba Sutra” has given this rule centuries before Pythagoras. The credit, according to the Sanskrit scholars, thus goes to Shalba, for the discovery of so called Pythagoras theorem. The “Sutra” (i.e., the formula) was routinely and extensively used while constructing square shaped altars (with right angled corners) for performing religious rites.

The aim of this section is not to enter into the above controversy about the discovery of the rule. There is a recreational aspect, which this section proposes to discuss. There are some integer sets which represent the sides and hypotenuse of a right angle triangle. How does one generate hundreds or thousands of Pythagorean triangles in integers?

##### Solution:

In the range of integers from 1 to 10,000 my book gives 1,593 solutions. The computer program for solving the problem is also given in the CD with my book.

How does one construct a table of powers of 2, say, 2n, for the values of n from 0 (zero) to 150?

##### Solution:

The method, the computer program and the table are given in my book.

How does one construct a table of powers of 3, say, 3n, for the values of n from 0 (zero) to 100?

##### Solution:

The method, the computer program and the table are given in my book.

The universal constant

e is the base of Naperian logarithms. Any power of e is defined by the infinite series as follows :

x x^{2} x^{3}

*e*^{x} = 1 + — + — + — + . . .

1! 2! 3!

If we substitute x = 1 in the above series, we get the value of e. Compute the value of e to 1,000 decimal places.

##### Solution:

I have devised a very simple method to do this. So simple, that I have manually worked out the value of e to 100 decimals. For 1,000 decimals, one has to use computer. The simple method, computer program and the results are all given in my book.

Pi is the well known universal constant, generally denoted by the Greek letter π, is the ratio of the circumference of a circle to its diameter. It is generally accepted now that for getting the value to millions of decimals, one has to resort to supercomputers, make use of complex algorithms and then take reciprocal of some computed parameter. These procedures are beyond the reach of a common person because he/she does not have access to supercomputers.

Using ordinary computers, compute the value of π to 1,000 decimal places.

##### Solution:

I have devised a method using Machin’s formula by which for lesser number of decimals (e.g. 1,000) one can use an ordinary computer. The method and computer program are given in my book.

Magic square is formed by arranging a series of numbers in a tabular form with the same number of rows as columns, i.e., it is akin to filling up cells of a square grid with the given numbers. This filling up is done in such a way that the numbers in each row add to the same total. The numbers in each column also add to the same total. It is further expected that at least the numbers on the principal diagonals of the square should add to the same total. This constant total is called the Magic Total (MT) of the Magic Square (MS).

The squares can have odd number of elements in each row/column or even number of elements and accordingly, it is called as an odd magic square or an even magic square. If the magic square is filled with the natural numbers from 1 to n^{2}, whether the square is odd or even, the MT is given by the expression

MT = n (n^{2} + 1) / 2, where n is the number of cells in the side of the MS, i.e., the size of the MS.

Write computer programs for forming MS and for study of its properties.

##### Solution:

Different methods for generating MS of odd and even numbers in its side, computer programs for generating MS, computer programs for testing their properties and results; all are given in my book in a chapter specially devoted to this problem. Analysis of results and discussions on their implications are also discussed in my book

Ramanujan, the great 20th century Indian mathematician, posed this problem. The problem is stated as In a long street with houses numbered 1, 2, 3, N (N being more than 50 and less than 500) on one side of the street, a person (say Ramanujan) has a house. The house numbers on all houses on left hand side of Ramanujan’s house added up exactly the same as the house numbers added up on right hand side of Ramanujan’s house. Find Ramanujan’s house number and N, the last number in the street.

A variation of the above problem was published in the Mindsport column of Sunday edition of The Times of India dated July 27, 1997. In the variation, the starting house number in the street was not 1, but A. Also, the limit of N was given as between 100 and 1,000. How many solutions are there?

If one is familiar with the house numbering system in Western countries, all odd numbered houses are on one side of the street and all even numbered houses are on the other side of the street. Two variations of the problem can be thought of. (i) If the house is on odd numbered side of the street, or, (ii) the house is on the even numbered side. If the other definition of the problem is as before, how many solutions are there?

##### Solution:

For the original problem proposed by Ramanujan, the answer is house number 204 in a street having last house number 288. This is a unique solution for the numbers between 50 and 500 as intended by Ramanujan. There are 1,324 solutions if the house number and last number in the street are below 1,000. For only odd numbered houses on Ramanujan’s side, there are 534 solutions and for only even numbered houses on Ramanujan’s side, there are 573 solutions. The formulation, computer programs and answers are given in my book.

Find four positive integers such that their sum is a perfect square of an integer. Further, sum of any two integers out of four is also a perfect square. Expressed mathematically,

a + b + c + d = s^{2}

where

a + b = t^{2}

a + c = u^{2}

a + d = v^{2}

b + c = w^{2}

b + d = x^{2}

c + d = y^{2}

Find the values of a, b, c and d.

##### Solution:

Surprisingly large number of solutions exist for this problem. I have located 64,326 solutions that are given in my book. Method of solving the problem, computer program (for exhaustive hunt for solutions) and actual values of a, b, c and d are all given in my book.

There is a story connected with the last illness of the great mathematician Ramanujan. His guide went to meet Ramanujan in hospital. The guide commented that the taxicab in which he traveled had a number 1,729, that is divisible by 13 and hence unlucky (Christians consider the number 13 as unlucky). Ramanujan replied that 1,729 is a very lucky number because it is the smallest number that can be expressed as a sum of two cubes in two ways.

12^{3} + 1^{3} = 1,729 and also

10^{3} + 9^{3} = 1,729

From this story, a problem that easily comes to mind is, which are the other numbers that can be expressed in a similar manner as a sum of two cubes in two ways? To put mathematically, we need to find a number X such that

X = a^{3} + b^{3} = c^{3} + d^{3}

Here, a, b, c, d and X are all integers.

##### Solution:

I have worked out 2,251 solutions for this problem. Among these, there are 12 solutions in which there is a third pair of numbers whose cubes also add to the same total. Formulation of the problem, method of solving, computer programs and all solutions are given in my book.

A mint has ten chests full of coins. Unfortunately, one chest contains counterfeit coins sent to the mint for melting and this chest has got mixed up with the chests containing good coins. It is necessary to identify the counterfeit coin chest and isolate it so that the other coins can be issued for circulation. Each good coin weighs 10 g. It is known that each counterfeit coin weighs 9 g or 11 g. In one weighing the bad coin box is to be identified when unlimited number of standard weights are available.

##### Solution:

Number the chests from 1 to 10. Take 1 coin from chest 1, 2 coins from chest 2 and so on. You would be taking total 55 coins. Weigh these coins against standard weights. The number of grams by which the weight differs from 550 g will indicate the chest number of bad coins, whether the bad coins are lighter or heavier.

What is the minimum number of standard weights required for weighing any quantity in round (integer) kg between 1 kg and 40 kg?

##### Solution:

Four weights, 1 kg, 3 kg, 9 kg and 27 kg are sufficient for the purpose.

There are 12 coins. One of them is counterfeit, either lighter or heavier than the rest, it is not known which. A balance with two pans is available. The coins are to be weighed against one another and the counterfeit coin is to be identified in three weighings. It is also to be determined whether the counterfeit is lighter or heavier than the rest.

##### Solution:

A generalized computer program has been written to solve not only this problem but also for 39 coins in 4 weighings, 120 coins in 5 weighings and so on up to 8 weighings. The program is discussed in details in my book.

This is an old and well known problem. Problem is to place eight queens on a chessboard in such a way that no queen checks (i.e. attacks) any other queen. It is assumed that the reader knows what a queen in chess means. It forms a part of the army in the game of chess. It can move any number of squares on the board in vertical, horizontal or diagonal direction. In other words, the problem requires that no two queens are to be placed on the same column, or same row, or on the same diagonal of the board.

##### Solution:

Theoretically, 92 solutions are possible and all are given in my book. A method to identify mirror images and/or rotations of earlier solution has been developed. Using the same, only 12 solutions remain. The elimination method and the computer program for it are also discussed in my book.

Similar to the previous problem, now eight rooks are to be placed on the chessboard in such a way that no rook checks (i.e. attacks) any other rook. A rook can move any number of squares on the board in vertical or horizontal direction. In other words, the problem requires that no two rooks be placed on the same column, or same row of the board.

##### Solution:

Theoretically, 40,320 solutions are possible. If we eliminate the mirror images and rotations, only 5,282 “independent” solutions remain. These solutions and the computer program to generate them are given in my book.

Consider a standard chessboard with total 64 small squares (also referred to as cells) arranged as 8 rows and 8 columns within a large square. A form of Cartesian co-ordinate system designates the cells. The columns are labeled a through h from left to right and the rows are numbered 1 to 8 from bottom upwards. This is the standard system used by chess players to record their moves in a game.

A knight is a piece used (and forms a part of the army of each player) while playing chess. Its standard move is defined as two squares horizontally and one square vertically, or, two squares vertically and one square horizontally. In Indian languages, this move is commonly known as moving two-and-a-half squares. Since, alternate squares on a chess board are colored white and black, a knight moving (jumping) from a white square lands invariably on a black square and vice versa.

The problem is to start from any square on the board (place the knight there) and move the knight successively in such a way that the knight visits each square on the board once and only once. If the last square it visits is such that given one more move, it could have come back to the starting square, then the tour is called closed. When the tour is closed, knight can start at any square on the board and come back to the same square by following the sequential moves in the manner used earlier. In the literature on the subject, a closed tour is also called a re-entrant tour.

How many closed tours are possible?

##### Solution:

Using a computer program and different starting/ending points, I have generated 324,861,840 solutions for the full board. The entire theory, computer programs etc are given in my book. Also given, are methods for eliminating mirror images and rotations of existing solutions. Based on the book, two papers (articles) are presented on this website. Further work is going on.

Total 72 matchsticks are divided into three stacks (piles), each containing different number of sticks. In the first move, as many matchsticks are picked up from the first pile as there exist in the second pile and are then added to the second pile. In the second move, as many matchsticks are picked up from the second pile as there exist in the third pile and are then added to the third pile. In the third move, as many matchsticks are picked up from the third pile as there exist in the first pile and are then added to the first pile. After these three moves, all the piles contain equal number of sticks. How many sticks were there originally in each pile?

##### Solution:

This involves “Diophantine Equations” of the first order. Creating and solving such equations is discussed fully in my book.

Three types of articles are to be purchased. The first one costs Rupees 5 each. The second one is Re 1 each and three articles of the third kind are available for 1 Rupee. Exactly one hundred rupees are to be spent for purchasing exactly 100 articles. There must be at least one article of each kind in the purchased lot. How many articles of each kind should be purchased?

##### Solution:

This involves “Diophantine Equations” of the first order. Creating and solving such equations is discussed fully in my book.

This puzzle had appeared in the “Mindsport” column of Sunday supplement of The Times of India, dated 12th May 1996. Five Parvatas cost 3 drams, seven Sarasas cost 5 drams, nine Hansas cost 7 drams and three Barhis cost 9 drams. Here, Parvata, Sarasa, Hansa and Barhi refer to the names of birds and dram refers to the name of some currency. Exactly one hundred drams are to be spent for purchasing exactly 100 birds. There must be at least one bird of each kind in the purchased lot. How many birds of each kind should be purchased?

##### Solution:

This involves “Diophantine Equations” of the first order. Creating and solving such equations is discussed fully in my book.

A rich old man realised that he was about to die. He did not want his seven sons to fight among themselves after his death to settle upon the division of his property. Accordingly, he gave each of them a fixed asset of different value. After this, he noted that the first son had the lowest share of the property. He therefore directed that the remaining six should each contribute money equivalent of firsts asset and pay the money to the first son. After this transaction, he noted that the second son was now poorest (or least rich, to be precise). Once again, the other six contributed money equivalent of seconds property value reduced by the amount he had contributed for the first transaction. The total was paid to second son. The process had to be continued for all sons as they went on becoming progressively least rich. Fortunately, after all the seven transactions, each son had equal share of the old man’s property. What was the minimum value of old man’s assets?

##### Solution:

A number (integer), when divided by 91, leaves a remainder 19; divided by 81, remainder is 18; divided by 71, remainder is 17; divided by 61, remainder is 16; divided by 51, remainder is 15; divided by 41, remainder is 14; divided by 31, remainder is 13; finally, when divided by 21, leaves a remainder 12. What is the minimum value of this number?

##### Solution:

A person received a cheque for a certain amount of money, but while cashing it, the teller mistook the number of dollars for the number of cents and conversely. Not noticing this, the person spent 68 cents and then discovered to his surprise that he had twice as much money as the cheque was originally drawn for. Determine the smallest amount of money for which the cheque could have been drawn for.

##### Solution:

**About The Book**

The book contains 20 interesting problems solved by the author using computer programming and 6 problems without the use of computer. The latter are given in the last chapter called “Magic of Algebra”.

A reader need not have any exposure to computer programming to enjoy the problems and the solutions thereto, some knowledge of programming is likely to add spice though. Persons from software business are likely to find some inspiring thoughts and programming ideas that may be useful to them in their work. It is hoped that software professionals use the material for improving their skills or training fresh recruits.

The programming skills used for solving the problems range from very simple to very complex. In all the cases, logic is explained in detail including derivation of formulae.

The program listing for each problem, an executable version of the program, voluminous results and some additional material are all given in a Compact Disc (CD) that accompanies this book.