4 9 5 1 7 8 2 0 = 3 6
The above is called an “awesome fraction” because it equals a positive integer and uses each of the digits 0 through 9 exactly once on either side of the equal sign ( = ).
What is the sum of all integers that can be expressed as awesome fractions?
Note : All integers must be expressed without leading zeros. You may make use of the coding environment below:
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
Got it wrong as I was not sure what ints to add up all or denominator/answers...apparently the latter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
A traditional solution in C.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
Here's my solution with a sum of 93,591 - guess I didn't know they had to be UNIQUE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
Log in to reply
We were asked the sum of all integers that could be written in "awesome" form. There is no reason to add any number more than once to the sum.
But it is an easy mistake to make; I thought of it on time and included a
break;
statement in my code.
Log in to reply
That's a very good point. Asperger's got me again!
My very first Pyhton code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Wow, what a beautiful solution! And it takes 0.8s to run compared to 1360s of my 'method'...
Very nice and elegant!
That is very slow. Much slower than Pietro Toniolo's solution.
Log in to reply
It's takes 0.8s instead of 0.4s, but the code is two times shorter than Pietro Toniolo's. I think it's a fair exchange!
Log in to reply
Not really :) Code you published contains 477 characters and Pietro's - 424. I know you could use letters instead "one_digit" etc. But that would not make the code significally shorter.
PS. Code I wrote even longer, so don't take it as an accusation of some sort.
Wrote this code in C, because I don't know Python.
The logic is simple, the product of A x B should be a five digit number.
Case 1
: A (can be 3 digit) x B (must be 2 digit) OR
Case 2
: A (can be 4 digit) x B (must be 1 digit)
No other cases are possible where A,B and (AxB) have unique digits from 0 to 9, i.e. 10 unique digits in total.
The code runs all 3 digit x 2 digit and 4 digit x 1 digit multiples, which results in a 5 digit number and then checks whether A, B & AxB have all unique digits
(I call number Lucky, if it has all unique digits!)
The program calculates sum of all such A and B.
The sum (calculated in the code) will have some repetitions, you may eliminate those from the output (manual checking).
#include <stdio.h>
int main()
{
int sum = 0, rem=0;
//possibilities are 3 x 2 digit or 4 x 1 digit
for (int i=100; i<10000; i++) // 3 to 4 digits
{
for (int j=1; j<100; j++) //1 to 2 digits
{
rem = (i*j)/10000;
if(rem>=1) // check if product is 5 digit (rem > = 1)
{
//check if i,j & (i*j) have all unique numbers from 0 to 9
if(isLucky(i,j,(i*j)))
{
sum = sum + i + j;
printf("Product = %d, D = %d, Q = %d\n\n",i*j,j,i);
}
}
}
}
printf("\nSum = %d",sum);
return 0;
}
int isLucky(int n1, int n2, int n3)
{
// Create an array of size 10 and initialize all
// elements as false. This array is used to check
// if a digit is already seen or not.
int arr[10];
for (int i=0; i<10; i++)
arr[i] = 0;
// Traverse through all digits of given number
while (n1 > 0)
{
// Find the last digit
int digit = n1%10;
// If digit is already seen, return zero
if (arr[digit]==1)
return 0;
// Mark this digit as seen
arr[digit] = 1;
// Remove the last digit from number
n1 = n1/10;
}
while (n2 > 0)
{
// Find the last digit
int digit = n2%10;
// If digit is already seen, return zero
if (arr[digit]==1)
return 0;
// Mark this digit as seen
arr[digit] = 1;
// Remove the last digit from number
n2 = n2/10;
}
while (n3 > 0)
{
// Find the last digit
int digit = n3%10;
// If digit is already seen, return zero
if (arr[digit]==1)
return 0;
// Mark this digit as seen
arr[digit] = 1;
// Remove the last digit from number
n3 = n3/10;
}
return 1;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Result:
1 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
I brute forced it, in a quarter second.
I'm only posting because I wanted to try out the coding environment on the webpage, and it wouldn't let me use a pipe character ("|") in the editor, and I'm not sure where to report bugs.
Yes, I had the same problem, but I could post the code here (see below).
A brute-force program that takes less than half a minute:
import itertools
TotalSet = set()
for a in range(2, 100):
b = set(list(str(a)))
if a > 9 and len(b) == 1:
continue # ignore multiples of 11
Remain = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} - b
Len = len(Remain) // 2
for Term in itertools.permutations(Remain):
for i in range(Len):
Nb1Str = ''.join(Term[:i + 1])
Nb2Str = ''.join(Term[i + 1:])
if(Nb1Str[0] != '0' and Nb2Str[0] != '0'):
Nb1 = int(Nb1Str)
Nb2 = int(Nb2Str)
if(a * Nb1 == Nb2):
print('Success!', a, '*', Nb1, '=', Nb2)
TotalSet |= {a, Nb1}
break
print('Total set:', sorted(TotalSet))
Total = sum(TotalSet)
print('Total:', Total)
Hi,
I obtained 44 'awesome fractions' instead of 35. As you can see, there are more than one fraction for 3,4,7... I don't know if I am wrong, but I would like to know if I am.
3 = 17082 / 5694
3 = 20457 / 6819
3 = 20754 / 6918
3 = 24507 / 8169
3 = 27504 / 9168
4 = 15628 / 3907
4 = 28156 / 7039
4 = 36508 / 9127
6 = 34902 / 5817
7 = 21658 / 3094
7 = 28651 / 4093
7 = 65128 / 9304
7 = 65821 / 9403
27 = 16038 / 594
36 = 17820 / 495
39 = 15678 / 402
45 = 17820 / 396
46 = 32890 / 715
52 = 19084 / 367
54 = 16038 / 297
63 = 58401 / 927
78 = 26910 / 345
297 = 16038 / 54
345 = 26910 / 78
367 = 19084 / 52
396 = 17820 / 45
402 = 15678 / 39
495 = 17820 / 36
594 = 16038 / 27
715 = 32890 / 46
927 = 58401 / 63
3094 = 21658 / 7
3907 = 15628 / 4
4093 = 28651 / 7
5694 = 17082 / 3
5817 = 34902 / 6
6819 = 20457 / 3
6918 = 20754 / 3
7039 = 28156 / 4
8169 = 24507 / 3
9127 = 36508 / 4
9168 = 27504 / 3
9304 = 65128 / 7
9403 = 65821 / 7
Answer: 93591
Log in to reply
The question is: "What is the sum of all integers that can be expressed as awesome fractions?", you may count the 3's, 4's and 7's only once!
Not being a programmer, I found a few solutions then cheated: https://oeis.org/A195814 is a list that could be 'awesome products'
After factoring them I found the sum of the factors. It still took me two tries because I didn't realize at first that two of them factor in two ways.
Problem Loading...
Note Loading...
Set Loading...
We are looking for positive integers a , b , N such that N = a b and such that the numbers a , b , N together use all of the digits from 0 to 9 exactly once. If a is an r -digit number and b an s -digit number, then N is a ( 1 0 − r − s ) -digit number. Thus 1 0 r − 1 ≤ a < 1 0 r 1 0 s − 1 ≤ b < 1 0 s 1 0 9 − r − s ≤ N < 1 0 1 0 − r − s We deduce that 1 0 r + s − 2 ≤ N = a b < 1 0 r + s and hence either 9 − r − s = r + s − 2 or else 9 − r − s = r + s − 1 . The only viable option is that r + s = 5 , and hence that N is a 5 -digit number.
Checking the 5 digit numbers N for factor pairs a , b that, together with N , use all the digits once each, we obtain the following possible values for N : 1 5 6 2 8 1 9 0 8 4 2 6 9 1 0 3 4 9 0 2 1 5 6 7 8 2 0 4 5 7 2 7 5 0 4 3 6 5 0 8 1 6 0 3 8 2 0 7 5 4 2 8 1 5 6 5 8 4 0 1 1 7 0 8 2 2 1 6 5 8 2 8 6 5 1 6 5 1 2 8 1 7 8 2 0 2 4 5 0 7 3 2 8 9 0 6 5 8 2 1 and, finding the suitable factors of each of these 2 0 numbers, we obtain the list of awesome numbers: 3 5 2 4 9 5 6 8 1 9 4 5 4 5 9 4 6 9 1 8 6 6 3 7 1 5 7 0 3 9 7 7 8 9 2 7 8 1 6 9 2 7 2 9 7 3 0 9 4 9 1 2 7 3 6 3 4 5 3 9 0 7 9 1 6 8 3 9 3 6 7 4 0 9 3 9 3 0 4 4 5 3 9 6 5 6 9 4 9 4 0 3 4 6 4 0 2 5 8 1 7 Adding up these 3 5 values gives the answer 9 3 5 5 0 .
The Mathematica code:
does the work. The contents of ndata2 are the possible values of N , and the contents of ndata3 the list of awesome numbers.