Charlotte selected a subset out of the integers from 1 through 20 inclusive. None of the numbers in the subset is double another number in the subset.
What is the greatest number of integers she could have selected?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Relating your solution to Calvin's comment below,
If a line contains an even number of numbers, than we can take either alternating sequence. This gives us all of the flexibility that there is.
A nice result is that the number of "maximal sets" for integers from 1 to n, is always a power of 2!
"Charlotte selected a set of integers from 1 through 20."
This wording as it stands would seem to indicate that she took all the numbers from 1 to 20. While the text after that clarifies this, it would be preferable, in my opinion, to start with:
"Charlotte picked a subset out of integers from 1 to 20."
This way the situation is clear from the start.
Damn, I forgot to count 20.
The question should have said exactly double.
Log in to reply
What other interpretation is there? As mathematicians, we do not say that "9 is double of 5".
Can you explain to me how you can include 4 if it double 2?
Log in to reply
By not including 2.
I wrote a chess database progam once that would let me add a large number of games and toss them into a binary tree. The LEFT branch was NEXT and the RIGHT branch was ALTERNATIVE. The program would descend through the existing game tree until it encountered a move not already in the tree and add it. With a large number of games, lots of cells have both NEXT and ALTERNATIVE branches, making it nearly impossible to draw even small parts of the tree. The idea was to let me pick through a huge tree and look at only the lines I was interested in.
So my first take was to have each number add to a tree where LEFT is NOT-DOUBLE and RIGHT was DOUBLE. I generated exactly Ms Reece's solution. Because the odds add only to the leftmost node you can actually write this binary tree down!
2 is double 1
Log in to reply
Which is why it is not selected. Only the red ones are the selected ones, the black ones are not.
Not sure If I understand any of the math. But I got the right answer by writing up a lua program to solve it. Took about 5 mins. Just hit execute and there it is, the working set of numbers and the number of integers used. http://tpcg.io/vrbuDu
I am non a native English person, so the word "double" have led me into delusion. I would be better to use "cannot be divided by 2", because of I was thinking, that the number could not be reused.
General solution for integers 1 , … , N :
Consider the binary representation N = … b 4 b 3 b 2 b 1 b 0 2 . Calculate the alternating digit sum a N as follows: a N = b 0 − b 1 + b 2 − b 3 + b 4 − + ⋯ .
The maximum value required in this problem is then m N = 3 2 N + a N .
In the case N = 2 0 = 1 0 1 0 0 2 we have a 2 0 = 0 − 0 + 1 − 0 + 1 = 2 , and m 2 0 = 3 2 ⋅ 2 0 + 2 = 1 4 .
Challenge : Proving the general formula is not easy! Any takers?
That's surprising to have such a nice formula.
Marta's solution is how I approached it, but I don't know how to count the red numbers in the general case.
Log in to reply
Believe it or not, but my formula started with Marta's approach. Then I went to work counting the red numbers.
Hint: The red numbers are precisely those whose binary representation ends in an odd number of zeroes.
Proof by induction on the binary digits of N :
Every positive integer x may be written uniquely as x = 2 i o with o odd and i ≥ 0 . As in Marta's solution, we call a number "red" if i is even and "black" if i is odd. The solution to the problem is the number of red numbers in the given range 1 , … , N .
Dividing a number by two changes its color, from red to black and from black to red.
Now suppose that N = 2 n + b 0 , where b 0 = 0 or 1 . To count R N , the red numbers between 1 , … , N , we start with all the numbers and remove all the black numbers. But these black numbers are precisely double all red numbers in the range 1 , … , n . Therefore we find the recursion relation R N = N − R n .
We are now ready to prove R N = 3 1 ( 2 N + a N ) by induction.
Base step : If N = 0 , then R N = a N = 0 . The equation is clearly satisfied.
Induction step : Let N = 2 n + b 0 ; then a N = b 0 − a n , and suppose that R n = 3 1 ( 2 n + a n ) . Then R N = N − R n = N − 3 1 ( 2 n + a n ) = N − 3 1 ( 2 n + b 0 − a N ) = N − 3 1 N + 3 1 a N = 3 1 ( 2 N + a N )
Since all integers N can be generated from N = 0 in a finite number of such steps, we have proven the statement for all integers N . □
Log in to reply
That's very clever! The general equation I came up with was a little more complicated:
m N = k = 0 ∑ ⌊ lo g 4 N ⌋ ⌊ 2 ⋅ 4 k N + 4 k ⌋
Each term ⌊ 2 ⋅ 4 k N + 4 k ⌋ gives the number of red numbers in the ( k + 1 ) th red-numbered column in Marta's solution, and there are ⌊ lo g 4 N ⌋ + 1 red-numbered columns.
Log in to reply
My initial solution took that direction. Then I realized that the sum was approximately k = 0 ∑ ∞ 2 ⋅ 4 k N = 3 2 N . Then I investigated the differences between 2 N and 3 m N , and realized that it was related to the binary digits.
What really helped me was sequences like m 1 0 = 6 , m 2 0 = 1 4 , m 4 0 = 2 6 , m 8 0 = 5 4 . In each case, m N is nearly two-thirds of N ; but alternatingly the number is rounded op and down. But no such discrepancy arose with m 3 = 2 , m 6 = 4 , and so on. At first I thought multiples of 3 should always give m N = 3 2 N , but that broke down with m 2 1 = 1 5 , m 4 2 = 2 7 , m 8 4 = 5 7 , where m N = 3 2 N ± 1 .
Little mistake: "As in Marta's solution, we call a number "black" if i is even and "red" if i is odd".
Marta colored her numbers in the opposite way. By the way, could you explain or at least give me a hint on how you came up with this formula in the first place?
Log in to reply
For your question: see may reply to David Vreken in this thread.
You are right about the colors. I will swap them.
Hi, Can you derive the same proof without induction ?
Log in to reply
Proving the formula without induction may be more difficult... If you have a suggestion, I'd be happy to hear it!
Log in to reply
@Arjen Vreugdenhil – I have difficulty understanding the part "suppose that Rn = 1/3(2n + an)". On what basis this is taken as an assumption ?
Log in to reply
@Senthil Kumar – That's the formula which Arjen proves. To check if it's generally true, he supposes that it's true for some n and then proves that it must be also true for N = 2 n + b 0 .
Log in to reply
@Uros Stojkovic – I understand why it seems to be coming out of the blue. This is often the case with induction proofs: it's not always clear how the author "invented" an equation. Proving that it works is one thing; figuring out what works is different.
My inspiration for this formula came from calculating R n for the simplest case, n = 2 k . In that case, R n = 2 k − 2 k − 1 + 2 k − 2 − + ⋯ ± 1 = 3 2 k + 1 ± 1 = 3 2 n ± 1 . This gave me the idea of writing R n = 3 2 n + a n , a n = 3 R n − 2 n and seeing how a n behaves. I quickly discovered that when N = 2 n + b , a N = 3 R N − 2 N = 3 ( N − R n ) − 2 N = N − 3 R n = 2 n + b − 3 R n = b − ( 3 R n − 2 n ) = b − a n . Thinking about binary digits, this shows that a N = b 0 − a n = b 0 − ( b 1 − ⋯ ) = b 0 − b 1 + b 2 − + ⋯ Thus I found a useful definition of a n and a valid equation for R n ; in a way, the proof by induction is "working backward", but as a proof it is more elegant.
Log in to reply
@Arjen Vreugdenhil – Now everything makes sense! I see how you brought in binary digits and alternating sum - it's an upgrade of the simplest case! Awesome!
Btw I see you turned 41 recently, happy birthday!
I don't get it. All these numbers confuses me?
Log in to reply
Same here, lol
Marta's solution is easier to understand. Generalizations are always more challenging and require more mathematics. It pays off when you work with bigger values. For instance, if the number 2 0 were replaced by 2 2 2 2 , Marta's method would make you write down long lists, while I would immediately calculate 2 2 2 2 = 1 0 0 0 1 0 1 0 1 1 1 0 2 a 2 2 2 2 = − 1 + 1 − 1 − 1 − 1 − 1 = − 4 m 2 2 2 2 = 3 2 ⋅ 2 2 2 2 − 4 = 1 4 8 0 .
What does the subscript 2 mean next to the binary representation N? I figured it was a mistake but you wrote it again in the example case next to 10100.
Also, this proof clearly works, but do you have a proof for why it does? How did you arrive at this formula in the first place?
Log in to reply
First, I considered that for N = 2 k , m N = 2 k − 2 k − 1 + 2 k − 2 − ⋯ + 1 = 3 2 k + 1 ± 1 = 3 2 N ± 1 . That gave me the idea of stipulation m N = 3 2 N + a N and figuring a formula for a N . Now if N = 2 n + b then a N = 3 m N − 2 N = 3 ( N − m n ) − 2 N = N − 3 m n = 2 n + b − 3 m n = b − ( 3 m n − 2 n ) = b − a n .
Log in to reply
In the first step, why does 2^k-2^k-1+2^k-2...+2^k-k = (2^k+-1)/3. Why divide by three, how did we get 2^k+1, why are we doing this alternating pattern in the first place? I get that it's (all of the numbers)-(the even numbers)+(every fourth even number)-(every eighth even number) but if i'm wrong, what's the reason for the alternating negation? why are we doing +- 1 one line one but +aN on line two, and how did you replace 1 with aN?
Hate to bombard you with questions but you seem to be assuming that some things will lead you to your answer when i don't see why they would.
Log in to reply
@Yonatan Beer – There is a well-known expression for a geometric series: 1 + x + x 2 + x 3 + x 4 + ⋯ + x n = x − 1 x n + 1 − 1 . Now let x = − 2 and n = k . This will give you 1 − 2 + 4 − 8 + − ⋯ + ( − 2 ) k = ( − 2 ) − 1 ( − 2 ) k + 1 + 1 = 3 ( − ) k 2 k + 1 − 1 . Multiply by ( − ) k ; then ± 1 ∓ 2 ± ∓ ⋅ + 2 k = 3 2 k + 1 ∓ 1 , as advertized.
When I had found m N = ( 2 N ± 1 ) / 3 for the specific case N = 2 k , I thought it might be useful to write the general solution as m N = ( 2 N + a N ) / 3 . This does not really solve anything; it merely creates a new problem, namely to find an equation for a N . I already knew that a N = ( − 1 ) k for N = 2 k , but what is it for other values of N ? The recurrence relation m N = N − m n was sufficient to derive the general equation for a n , thereby also solving the original problem.
To maximise the number of integers picked, we first pick all the odd integers(since twice of no number will be equal to them). Thus we have already picked 10 odd integers.
From the remaining integers 2,4,6,8,10,12,14,16,18,20 we can’t choose 2,6,10,14,18 as they are twice the odd integers that we have already picked. From the remaining even integers, we can maximise the number of integers chosen by taking 4,12,16 and 20.
Thus, finally we have the maximum 14 chosen integers- 1,3,4,5,7,9,11,12,13,15,16,17,19,20
Click here for a similar problem
Be careful of the argument. While it is a good idea to 'try and pick the odd numbers", it might not be true that "every maximal sequence must contain all of the odd numbers". As such, this initial restriction might have been too strict, or that it doesn't fully explain what is really happening.
As an example, we could have used the set { 1 , 3 , 4 , 5 , 1 1 , 1 2 , 1 3 , 1 4 , 1 5 , 1 6 , 1 7 , 1 8 , 1 9 , 2 0 } , which misses out 7 and 9. The idea here is to "grab a lot of the large numbers, IE we have numbers from 11 to 20, and clearly cannot use 10.". (Admittedly, this can seem like a really dumb move, but my point is to illustrate that the solution is dependent on the initial assumption, hence doesn't apply to all cases.) What other maximal sets are there?
Log in to reply
Hmm..that’s correct sir....but I still can’t figure out how to prove rigorously that 14 numbers is the maximum that you can pick.
Log in to reply
You're close. Think about how I could "miss out 7 and 9".
Here is an easier, and almost equivalent question.
Charlotte selected a set of integers from 1 through 20. None of the numbers in the set is one more than another number in the set.
What is the greatest number of integers she could have selected?
{1,2,3,5,7,8,9,11,12,13,15,17,19,20} is another subset with 14 elements. Here is a greedy algorithm to get there.
Start with including all odd numbers in the Solution set S. (since odd numbers themselves can not be twice of another number).
So S = {1,3,5,7,9,11,13,15,17,19}
Now iterate over remaining even numbers in order [2,4,6,8,10,12,14,16,18,20]
Add the even number to the set if it does not lead to removal of more numbers in S due to the constraints set in the problem.
Thus you only add {2,8,12,20}.
Of course this does not prove rigorously that 14 is the maximum.
If we iterate over the even numbers in the descending order, we get another solution
{1,3,4,5,7,9,11,12,13,15,16,17,19,20}
Question: Does every permutation converge to a Solution set of length 14.
I don't understand how can you pick 4 12 16 and 20. Could you please explain? The problem clearly states: "None of the numbers in the subset is double another number in the subset". It does not differentiate between odd and even - it just says "another number".
The answer should be 10 and not 14. And for the general solution it is always a sequence of 1,3, 5, 7, 9, 11.... etc.
Why people do not read the problem and immediately jump to a solution which is incorrect?
Log in to reply
Which number in the subset (given by Chandrashekar) is 4 double of?
Is 2 in the subset?
It would help if you had clear instruction. From the given info, 4, 10 and 20 should not be included. Nice try
Log in to reply
Can you elaborate on why 4, 10, and 20 should not be included?
Note that 10 is already not included in the final list (because 5 is in there).
My approach was simple. I was selected those numbers whose double is not there in the integer set, that is, from 11 to 20. Now I start searching for numbers whose double is not between 11 and 20. Therefore I cannot select any number from [6,10]. In 1 to 5, 1 3 4 5 can be chosen.
Final set will be : 1,3,4,5,11,12,13,14,15,16,17,18,19,20. 14 numbers in total.
And since that ends in 14, the highest possible option, the answer can't be higher.
Yet another option: we start by taking all numbers from 11 - 20; none of those ten is the double of another in that group. This eliminates the numbers 5 - 10 from being added to the set, but 1 - 5 still remain eligible. Of those five, the only problem is the 1 - 2 - 4 chain, and by removing 2, we can add all four others to our set, ending up with fourteen elements: {1, 3, 4, 5, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20).
1-3-4-5-7-9-11-12-13-15-16-17-19-20 - Total of numbers = 14
First I did some guess and check in Excel. My first attempt gave me a set of 14 numbers, but that only provides the right answer.
What I came up with is an approach for eliminating numbers that ultimately rests on the logic of Marta's much more elegant answer... Write the numbers out in a line. Look at 10. It's double 5, and half 20. Eliminate 10 and we preserve both of those numbers. Now work down the line (descending in magnitude). 9 pairs with 18, scratch either one. 8 matches with 4 and 16, so sacrificing 8 saves two numbers. 7 and 14 are equivalent, scratch either one. 6 is between 3 and 12; sacrifice it to save them. 5 is safe because 10 is gone. 4 matches with 2 which matches with 1; drop 2. 3 is already safe, 2 is gone, and 1 is safe.
COUNTA(...) in Excel shows 14 numbers in my set. Good enough for now.
I'm not 100% sure the algorithm works in all cases, but what I think is interesting is how starting in the middle and working towards the smallest number narrows attention to the place in the ordered set where you can do the most good (in terms of making the set bigger). It's simple enough to see why it might work by looking at Marta's answer, but I like having a second perspective on it...
According to the question,we know that we must give up two guys in 1,2,4,8,16 at least,which could prevent the "double group".
In a similar way,to make remaining numbers as many as possible,we must abandon 6 in 3,6,12,and 10 in 5,10,20,an unfortunate guy in 7 and 14,as well as the last one in 9 and 18.
And then we get the answer,to give up 6 guys in a minimum situation,14 is the correct one.
We can form sets of multiples of 2 (less than 21) starting with each number from 1 to 20, not building for those numbers already included in a previous set formed. So, we have:
1 -> {1,2,4,8,16}
3 -> {3,6,12}
5 -> {5,10,20}
7 -> {7,14}
9 -> {9, 18}
11 -> {11}
13 -> {13}
15 -> {15}
17 -> {17}
19 -> {19}
Now, the max number of integers that can be selected from each set are the alternating entries starting from the first element which mathematically results in the ceiling value of the (cardinality of each set divided by 2). Now if we add these, the result is 14.
First, list out the numbers 1 through 20. Then, start at 1 and work your way up to 20, considering at each number carefully whether it was a double of a number already added to the set. This collection will not include any numbers which are doubles of others on the list.
Something to notice when picking the integers is patterns like 3,6,12 where we should select the extremes 3,12 because by selecting the 6, we will have to leave 3,12 so we're taking 1 integer (6) instead of selecting 2 (3,12). We will also select odd numbers > 10, since their double is >20.
The list will be: 1 3 4 5 11 12 13 14 15 16 17 18 19 20
For this, I simply started at 1 and used the rule to exclude or include all others as I counted to 20. 1, so 2 is not allowed, 3, then you can use 4 because you already excluded 2. Then 5, 6 is out because you used 3, and so on. Use the same method up to 20 and count how many numbers you have. 1, 3, 4, 5, 7, 9, 11, 12, 13, 15, 16, 17, 19, 20....14 numbers, and there's your answer.
You also know that all odd numbers will be used. So you just have to check at each even number if its half has already been used, then include or exclude accordingly.
A very simple solution for someone like myself who's forgotten all the fancy math they learned at school.
It's easier to make a list of integers 1-20 one at a time. Just look at the previous numbers and see if you have the number that's half of any of the even numbers (all of the odd numbers work). These are the numbers I got: 1, 2, 3, (no 4 because 2 2=4) 5, (no 6 because 3 2=6) 7, 8 (8 because there is no 4), 9, (no 10 because there is a 5) 11, 12, (12 because there is no 6) 13, 15, 17, 19, 20 (20 because there is no 10), which makes 14 possible options.
Is it cheating? Because after you count integers starting on 1 you get 14 - this is already largest possible choice from the answers so why bother checking anything else? :D
Because 2x2=4 so the first 14 integers can't all be included.
Log in to reply
My interpretation of this solution:
For the numbers 1 - 20, when you start selecting numbers in order of lowest (starting on 1), and eliminating the doubles of only the selected numbers as you go, you end up with a list of 14 numbers.
1, 3, 4, 5, 7, 9, 11, 12, 13, 15, 16, 17, 19, 20.
Problem Loading...
Note Loading...
Set Loading...
The table on the left summarizes all the "times two" relationships.
The first line is 1 "times two" is 2 , then this "times two" is 4 etc.
Similarly for all the other lines, each line starting with the lowest number not yet listed so that all numbers from 1 to 20 are included and none of them are repeated.
If a line contains only one number, that number should be included in the set.
If a line contains two numbers, either one may of them be included. We may as well pick the odd one, but that is just an arbitrary pick.
If a line contains three numbers, the first and last should be included. Neighbors in the same line are related "times two" and can't both be picked. (Including the middle one instead would result in fewer numbers as neither of the ends could be included.)
If a line contains five numbers, taking the first, middle, and last is the best option.
Following this procedure, only the red ones end up selected and there are 1 4 of them.