Count and count...

If you write all the whole numbers upto 100000, the number of times you write the digit '1' is A and the number of times you write the digit '2' is B. what is the value of A-B ?

Note : if you write 11 , then you will count it as writing '1' twice.


Try more combinatorics problems.


The answer is 1.

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.

7 solutions

Vaibhav Prasad
Mar 25, 2015

Every time we write a 1 1 , it is accompanied by a 2 2

But we have an extra number 100000 100000 and thus A B = 1 A-B=1

Pranjal Jain
Jan 5, 2015

It seems that till 99999 99999 , all the digits are degenerate (Chemistry term for equal energy orbitals, here used for equal probability) . While writing 100000 100000 , we will write digit 1 1 extra time, so A B = 1 A-B=1

Thank you for this extra (chemistry) vocabulary.

Leonblum Iznotded - 2 years, 11 months ago
David Orrell
May 11, 2016

For the units digit, a 1 will appear once every 10 numbers --> 0.1 of the time.

For the tens digit, a 1 will appear 10 times every 100 numbers --> 0.1 of the time.

For the hundreds digit, a 1 will appear 100 times every 1000 numbers --> 0.1 of the time...

Number of 1s = 10^5, plus the 1 in 100000, so 100001 ones appear.

The same goes for 2s, but there is no 2 in the number 100000, so 2 appears 100000 times.

A - B = 100001 - 100000 = 1

Not the easiest way to do it, but yes that is a valid explanation.

Peter Byers - 4 years, 7 months ago
Brock Brown
Mar 25, 2015

Python 2.7:

1
2
3
4
5
6
A = 0
B = 0
for n in xrange(100001):
    A += str(n).count('1')
    B += str(n).count('2')
print "Answer:", A-B

Fabricio Kolberg
Nov 26, 2017

This one is easily solvable with the following observation: for numbers 1 through 99999, the number of 1s and 2s is equal. To verify that this is true, it suffices to check that the function that takes a number between 1 and 99999, swaps every 1 in that number with a 2, and vice versa, is bijective.

We are then left with 100000, which gives us a-b=1.

Peter Byers
Nov 5, 2016

Let f(n) be the number obtained by replacing the digit 1 in n with the digit 2, and vice versa. Then f is a bijection on {1,...,99999}, so A-B=1.

Jade Mijares
Mar 26, 2015

1 will be written the same times as 2 from 1 to 99999. A B = 1 A - B = 1 because of 100000.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...