Pen & Paper

Project Euler 145: How many reversible numbers are there below one-billion?

In Problem 145 of Project Euler we move away from Geometry and over to number theory again, with a problem which reads

Some positive integers n have the property that the sum [ n + reverse(n) ] consists entirely of odd (decimal) digits. For instance, 36 + 63 = 99 and 409 + 904 = 1313. We will call such numbers reversible; so 36, 63, 409, and 904 are reversible. Leading zeroes are not allowed in either n or reverse(n).

There are 120 reversible numbers below one-thousand.

How many reversible numbers are there below one-billion (109)?

This one is insanely easy to write a brute force method and that is the first thing I did. However, as we shall see there is a more analytic approach to the problem as well. Continue reading →

Posted by Kristian in Project Euler, 5 comments

Project Euler 79: By analysing a user’s login attempts, can you determine the secret numeric passcode?

Before even starting this problem I would like to say that I have solved the major part of Problem 79 of Project Euler by hand. The problem reads

A common security method used for online banking is to ask the user for three random characters from a passcode. For example, if the passcode was 531278, they may ask for the 2nd, 3rd, and 5th characters; the expected reply would be: 317.

The text file, keylog.txt, contains fifty successful login attempts.

Given that the three characters are always asked for in order, analyse the file so as to determine the shortest possible secret passcode of unknown length.

Posted by Kristian in Project Euler, 20 comments

Proving the fundamental lemma of Arithmetic

Last time I blogged I wrote about why proofs are so difficult. This time we should try to prove something a little more complicated and see if we can get some of the thoughts behind the proof while doing it to see if it really requires that amount of insights or part of a proof can be done by using more or less common sense. My guess is that we can come far with common sense, but we at some point need to rely on some insights or methods we have seen before. Continue reading →

Posted by Kristian in Math, 0 comments

Project Euler 68: What is the maximum 16-digit string for a “magic” 5-gon ring?

We have now been dealing with continued fractions for a good while, except for the last problem which was solved a good while ago. Problem 68 of Project Euler is completely different. It reads

Consider the following “magic” 3-gon ring, filled with the numbers 1 to 6, and each line adding to nine.

Working clockwise, and starting from the group of three with the numerically lowest external node (4,3,2 in this example), each solution can be described uniquely. For example, the above solution can be described by the set: 4,3,2; 6,2,1; 5,1,3.

It is possible to complete the ring with four different totals: 9, 10, 11, and 12. There are eight solutions in total.

 Total Solution Set 9 4,2,3; 5,3,1; 6,1,2 9 4,3,2; 6,2,1; 5,1,3 10 2,3,5; 4,5,1; 6,1,3 10 2,5,3; 6,3,1; 4,1,5 11 1,4,6; 3,6,2; 5,2,4 11 1,6,4; 5,4,2; 3,2,6 12 1,5,6; 2,6,4; 3,4,5 12 1,6,5; 3,5,4; 2,4,6

By concatenating each group it is possible to form 9-digit strings; the maximum string for a 3-gon ring is 432621513.

Using the numbers 1 to 10, and depending on arrangements, it is possible to form 16- and 17-digit strings. What is the maximum 16-digit string for a “magic” 5-gon ring?

Well we could try to pursue a brute force approach but we have 10! = 3628800 combinations to check. An approach I will take in the end of this post. However, we can see if we can solve it by hand. So let’s try greedy algorithm using pen & paper. Continue reading →

Posted by Kristian in Project Euler, 14 comments

Why are proofs so frustrating?

I have often been sitting there swearing when I couldn’t figure out to how to prove something and I know for certain I am not the only one. But why are proofs so difficult when they seem so easy when you read them? This post is about the softer side of proofs, to encourage you to not loose faith when you meet something you can’t prove. Continue reading →

Posted by Kristian in Math, 0 comments

The pigeon hole principle

The pigeon hole principle is a counting argument stating something as simple as “if you have n items which are to be put into m < n boxes then there is at least 2 items in one of the boxes”. My first comment on that was “well duh!”, that is obvious, but it can actually be used to prove some less intuitive things.

So an example if you have 10 balls which are to be put into 9 boxes then at least 1 of the boxes contains at least 2 balls (unless you drop one of them…). But what can we use it for. I will show one of my favourite examples of it which I do not find intuitive at first glance. Continue reading →

Posted by Kristian in Math, 0 comments

Proof method: Multidimensional induction

For the last couple of posts we have been dealing with mathematical induction. This post shall be no different. However, until now we have been limited to one variable, so this post will deal with induction on multiple variables – or in other words multidimensional induction as the headline suggests. I will treat the two dimensional case in this post, but the expansion to n dimensions should be relatively easy. So for now we will assume that we have a statement P(m,n) which we need to prove.

If we have the statement P(m,n) then we need to prove three things:

1. Basecase: We need to prove a base case P(a,b) where a is the smallest value for which m is valid and b is the smallest value where n is valid.
2. Induction over m: We assume that P(k,b) is valid for some positive integer k. Then we need to prove that P(k+1,b) is valid.
3. Induction over n: We assume that P(h,k) is valid for some positive integers h,k. Then we need to prove that P(h,k+1) is valid.

If we can prove these three things then we have proved that P(m,n) is true for all and . point 1 and 2 ensures that the statement is true for all P(m,a) just as in the in the single variable case. Once we have proven that then adding 3 ensures that it holds for all n as well. But let us take an example. Continue reading →

Posted by Kristian in Math, 4 comments

Project Euler 57: Investigate the expansion of the continued fraction for the square root of two.

I found Problem 57 of Project Euler to be a rather interesting problem, with more than one solution. The problem description reads

It is possible to show that the square root of two can be expressed as an infinite continued fraction.

√ 2 = 1 + 1/(2 + 1/(2 + 1/(2 + … ))) = 1.414213…

By expanding this for the first four iterations, we get:

1 + 1/2 = 3/2 = 1.5
1 + 1/(2 + 1/2) = 7/5 = 1.4
1 + 1/(2 + 1/(2 + 1/2)) = 17/12 = 1.41666…
1 + 1/(2 + 1/(2 + 1/(2 + 1/2))) = 41/29 = 1.41379…

The next three expansions are 99/70, 239/169, and 577/408, but the eighth expansion, 1393/985, is the first example where the number of digits in the numerator exceeds the number of digits in the denominator.

In the first one-thousand expansions, how many fractions contain a numerator with more digits than denominator?

First thing I will present is a brute force solution, which for all practical purposes are fast enough. The second solution is a closed form approximation to the problem, so it can be solved as fast as you can punch the calculator. Continue reading →

Posted by Kristian in Project Euler, 15 comments

Proof method: Strong Induction

As I promised in the Proof by induction post, I would follow up to elaborate on the proof by induction topic. Here is part of the follow up, known as the proof by strong induction.  What I covered last time, is sometimes also known as weak induction.

In weak induction the induction step goes:

Induction step: If P(k) is true then  P(k+1) is true as well.

Strong induction expands the concept to:

Induction step: If P(m), P(m+1), P(m+2)… P(k) is true then  P(k+1) is true as well for some k > m.

The difference between the two methods is what assumptions we need to make in the induction step. To switch to the metaphor of dominoes again – in the weak induction we need to know that the previous domino is toppled, then the next one will topple as well. In strong induction we need to know that all the previous ones has toppled before we can ensure that the next one will fall as well.

Both methods have the same logical strength when we apply them, since in order to get to the k’th domino we need to topple 1,2,3,…k-1 anyway. However, sometimes strong induction makes the proof of the induction step easier.

Strong Induction Example 1

I have shamelessly stolen this example from Hammack since I think it brilliantly shows when strong induction is better to use. But lets first see what happens if we try to use weak induction on the following:

Proposition: if , then 12|(n4 – n2)

Weak induction

Base case: we need to prove that 12|(14 – 12) = 12|(1- 1) = 0, which is divisible by 12 by definition.

Induction step: We assume that the 12|(k4 – k2) is true such that (n4 – n2) = 12a for some . We then need to show that ((k+1)4 – (k+1)2) = 12b for some .

My approach would be to a direct proof such that

(k+1)4 – (k+1)2 = k4 + 4k3 + 6k2 + 4k + 1 – (k2 + 2k + 1) =  (k4 – k2) + 4k3 + 6k2 + 2k = 12a + 4k3 + 6k2 + 2k

How do we proceed from there? I don’t have a clue. If you can show me how to continue of this road I would be glad to hear it.

Strong induction

The weak induction method failed. However, we can show that n = k-5 implies that the statement is true for k+1, so we need to expand the base case to include everything up to n = 6.

Base case:
n = 1:  12|(14 – 12) = 12|(1- 1) = 0 = 012
n = 2:  12|(24 – 22) = 12|16-12 = 12 = 1
12
n = 3:  12|(34 – 32) = 12|(81 – 9) = 72  = 612
n = 4:  12|(44 – 42) = 12|(256- 16) = 240 = 20 * 12
n = 5:  12|(54 – 52) = 12|(625- 25) = 600 = 50
12
n = 6:  12|(64 – 62) = 12|(1296- 36) = 1260 = 105*12

So far it fits really well.

Induction step: let and assume that 12|(m4 – m2) for , now we need to prove that 12|((k+1)4 – (k+1)2)  is true as well.

Let us define l =  k-5 for which we assume the proposition to be true such that  (l4 -l2) = 12a for some value of a. We need to show that 12|((l+6)4 – (l+6)2) is true.  So let us try with a direct approach

(l+6)4 – (l+6)2= (l4 +24l3 + 180l2 + 864l + 1296) – (l2 + 12l + 36) = (l4 – l2) +24l3 + 180l2 + 852l + 1260 = 12a +12(2l3 + 15l2 + 71l + 105).

This statement is clearly divisible by 12, and thus proofs the proposition.

QED

So in order to prove it for n = k+1 = 7 we need n = k-5 = 1 to prove it, but that is handled in the base case, same goes for all the n = 8,9,10,11,12 and then we start to rely on the fact that we can prove n= 8 through the induction step.

Image Credits

The metaphor of dominoes also gave rise to the chosen post photo, which was kindly shared under the creative common license by Malkav. My crop of the photo is of course shared under the same conditions.

Posted by Kristian in Math, 15 comments

Proof methods: Proof by mathematical induction

It has been a while since I last posted something about proof methods, but lets dig that up again and take a look at a fourth method. The first three were direct proof, proof by contradiction and contrapositive proofs. Proof by induction is a somewhat different nature.

I have been reading quite a few blog posts recently and they all seem to be witty and clever, so I really wanted to add a joke right here on induction. But I honestly couldn’t find one I think was funny enough. So if you could just laugh or smirk for a few seconds before reading on, my day is saved. Continue reading →

Posted by Kristian in Math, 4 comments