Cause and Effect Mr.11 & divisibility!

We call a natural number n n as 'awesome' if at least one of the numbers formed by permutations of digits of n n is divisible by 11.

There are x x 'awesome' numbers and y y 'non-awesome' numbers less than 1001.

Find the ratio y x \dfrac{y}{x} (as a decimal value).


Details and assumptions :

  • All the numbers are represented in base 10.

  • If a number already has zeroes, they can be brought to the start during permutations. e.g 1102 1102 can be permuted to 0121 0121

  • You can't add zeroes at the start of the number like 01201 01201 being permuted to 12100 12100 is not allowed, because the original number is intended to be 1201 1201 and not 01201 01201 .

  • A number is 'non-awesome' if it is not awesome, i.e. none of its permutations is divisible by 11.

This is a part of the set 11≡ awesome (mod remainders)


The answer is 3.255319.

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.

6 solutions

Pranjal Jain
Jun 11, 2015

Python 3.4.2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def isawesome(x):
    for i in permutations(str(x)):
        m=''.join(i)
        if int(m)%11==0:
            return 1
        else:
            continue
    return 0
n=0
for i in range(1,1001):
    if isawesome(i):
        n+=1
print((1000-n)/n) #Returns 3.255

Okay, here's something shorter, the program for determining awesome(x) \text{awesome(x)} is one line using the any statement ...

1
2
3
4
5
6
7
from itertools import permutations
def awesome(x):
    return any(int(''.join(i))%11==0 for i in permutations(str(x)))
k=0
for i in range(1,1001):
         if awesome(i)==True:
                     k+=1

This returns k = 235 k=235 , and then you calculate...

Aditya Raut - 5 years, 12 months ago

Log in to reply

@Agnishom Chattopadhyay 'any' really made it short, didn't it?

Aditya Raut - 5 years, 12 months ago

Log in to reply

Huh, any is a neat trick, I'll have to remember that.

Brock Brown - 5 years, 12 months ago

Yes, this is pretty interesting. I did not know the any command.

But here is a slightly simpler way:

1
return  (True in int(''.join(i))%11==0 for i in permutations(str(x)))

Agnishom Chattopadhyay - 5 years, 12 months ago

Log in to reply

@Agnishom Chattopadhyay That's basically the same thing, right? You asked it to check if there's True in any of the outputs... Just that you didn't use the word any :P

Aditya Raut - 5 years, 11 months ago

Log in to reply

@Aditya Raut Yeah. I did not know the any function

Agnishom Chattopadhyay - 5 years, 11 months ago

Here 's a really lengthy and nooby solution in C++. Adding it here for the sake of variety. :)

EDIT: I edited the code a bit to also output the ratio directly so that we don't have to manually use a calculator to get the final required ratio.

Prasun Biswas - 5 years, 10 months ago
Bill Bell
Aug 10, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
from itertools import permutations
from fractions import Fraction

def isAwesome(k):
    for p in permutations(list(str(k))):
        if int(''.join(p))%11==0:
            return True
            break
    else:
        return False
x=0
y=0
for n in range(1,1001):
    if isAwesome(n):
        x+=1
    else:
        y+=1
print 1.*Fraction(y,x)

Samarth Agarwal
Jul 26, 2015

//java: int i=0,a,b,c,d,e,f,g,h,j,k,x=0;

for(i=100;i<999;i++)

{

a=i%10;//ones

d=i/10;

b=d%10;//tens

c=i/100;//hundreds

e=((100*a)+(10*b)+c)%11;

f=((100*a)+(10*c)+b)%11;

g=((100*b)+(10*a)+c)%11;

h=((100*b)+(10*c)+a)%11;

k=((100*c)+(10*a)+b)%11;

j=((100*c)+(10*b)+a)%11;

if(e==0||f==0||g==0||h==0||k==0||j==0)

  x=x+1;

}

System.out.println(x);//this gives awesomes in 100 to 999

1000 is not awsome in 1-99 there are 9 awesomes so y/x can be found

Roel Baars
Jul 1, 2015

Mathematica

1
2
awesome =  Sum[If[Or @@  Divisible[FromDigits /@ Permutations[IntegerDigits[n]], 11], 1, 0], {n, 1, 1001}]
N[(1001 - awesome)/awesome]

Arulx Z
Jun 30, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
>>> from itertools import permutations
>>> awe = 0.0
>>> for x in xrange(1, 1001):
        for y in list(map("".join, permutations(str(x)))):
            if int(y) % 11 == 0:
                awe += 1
                break

>>> print (1000 - awe) / awe
3.25531914894

I wonder why python doesn't have ++ operator

Brock Brown
Jun 16, 2015

I did basically the same thing that Pranjal did.

Python 3.4:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
from itertools import permutations as combos
def awesome(n):
    for combo in combos(str(n)):
        test = ''.join(combo)
        if test[0] != '0' and int(test) % 11 == 0:
            return True
    return False
x = 0
y = 0
for n in range(1001):
    if awesome(n):
        x += 1
    else:
        y += 1
print("Answer:", y/x)

So upgraded to Python 3.4?

Pranjal Jain - 5 years, 12 months ago

Log in to reply

Yup. Apparently, Python 3 is the present and future of Python or something.

I've got to say that the thing I'll miss the most is being able to use...

1
print "Hello world!"

Rather than...

1
print("Hello world!")

Brock Brown - 5 years, 12 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...