We call a natural number n as 'awesome' if at least one of the numbers formed by permutations of digits of n is divisible by 11.
There are x 'awesome' numbers and y 'non-awesome' numbers less than 1001.
Find the ratio x y (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 1 1 0 2 can be permuted to 0 1 2 1
You can't add zeroes at the start of the number like 0 1 2 0 1 being permuted to 1 2 1 0 0 is not allowed, because the original number is intended to be 1 2 0 1 and not 0 1 2 0 1 .
A number is 'non-awesome' if it is not awesome, i.e. none of its permutations is divisible by 11.
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.
Okay, here's something shorter, the program for determining awesome(x) is one line using the any statement ...
1 2 3 4 5 6 7 |
|
This returns k = 2 3 5 , and then you calculate...
Log in to reply
@Agnishom Chattopadhyay 'any' really made it short, didn't it?
Log in to reply
Huh, any is a neat trick, I'll have to remember that.
Yes, this is pretty interesting. I did not know the any command.
But here is a slightly simpler way:
1 |
|
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
Log in to reply
@Aditya Raut – Yeah. I did not know the any function
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
//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
Mathematica
1 2 |
|
1 2 3 4 5 6 7 8 9 10 |
|
I wonder why python doesn't have
++
operator
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 |
|
So upgraded to Python 3.4?
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 |
|
Rather than...
1 |
|
Problem Loading...
Note Loading...
Set Loading...
Python 3.4.2