Any demoscener from Mensa?
category: residue [glöplog]
gargaj: four edges of the square intersect non dotted grid intersections anyway.
ok doom :)
In a afternoon drinking coffe with a mathemacian friend, she showed me that 1089*9=9801, so, two natural numbers, A and B, A with 4 decimal digits and B with 1 decimal digit and bigger or equal than 2, when multiplied give the result of the reversed digits of A.
She asked me to find all the solutions/posibilities. The problem was absolutely silly, there are only 2 solutions, the one in the example and 2178*4=8712.
So, I thought, what if A is not 4 digits but N digits long? Could you find a function f(N) wich returns the numbers of solutions for N digits?
She asked me to find all the solutions/posibilities. The problem was absolutely silly, there are only 2 solutions, the one in the example and 2178*4=8712.
So, I thought, what if A is not 4 digits but N digits long? Could you find a function f(N) wich returns the numbers of solutions for N digits?
yes, i could.
... if i could show why these numbers are divisible by 10^(N-1)-1 :/
anes, I'm not asking for a demostration. Anyway, I've demostrated it without what you are searching for, but what are you searching for is a well know discrete math property AFAIK. Search google for it and 99.
yeah i know the divisibility rule but i can't prove it for these kind of numbers :) how far i've come is:
for N digits we have
M * 11 * (99...9)
and
(10 - M) * 11 * (99...9)
(99...9 is N-2 9's) decimal reverse of each other
since only (1-9) and (2-8) are product pairs that sum up to 10 we have two number for each digit.
i know why such numbers are divisible by 11 and i know why the sum of them and their reverse is divisible by 10.
if they don't have to divisible by (99...9) there could be more numbers also. but two of them ruined my sunday already :)
for N digits we have
M * 11 * (99...9)
and
(10 - M) * 11 * (99...9)
(99...9 is N-2 9's) decimal reverse of each other
since only (1-9) and (2-8) are product pairs that sum up to 10 we have two number for each digit.
i know why such numbers are divisible by 11 and i know why the sum of them and their reverse is divisible by 10.
if they don't have to divisible by (99...9) there could be more numbers also. but two of them ruined my sunday already :)
Well, I guess Adok has to come to the rescue here. Where is he?
Well, I think I will post the solutions if you are not able to solve it... I will give you some few days more...
Sorry,I did not see a solution after 15 minutes and decided not to burn more time on this.. Next one maybe :)
Let me give it a go:
You are asking for a function to find the number of possible vectors of solution (x0, ..., xn, a) for an equation:
(10^n * x0 + 10^(n-1) * x1 + ... + xn) * a = 10^n * xn + ... + x0
depending on n, where x0, ..., xn, a, n are natural numbers and a >= 2.
I suggest writing a program that finds the solutions for n = 1, n = 2, n = 3, n = 4, ... and then checking out if it seems to be something like a function. It may also be possible that it isn't a function.
C'mon, you're coders, it should be a piece of cake.
You are asking for a function to find the number of possible vectors of solution (x0, ..., xn, a) for an equation:
(10^n * x0 + 10^(n-1) * x1 + ... + xn) * a = 10^n * xn + ... + x0
depending on n, where x0, ..., xn, a, n are natural numbers and a >= 2.
I suggest writing a program that finds the solutions for n = 1, n = 2, n = 3, n = 4, ... and then checking out if it seems to be something like a function. It may also be possible that it isn't a function.
C'mon, you're coders, it should be a piece of cake.
adok, that reasoning is soo middle ages.
For all the non-coders out there:
Code:
So... here you go. Work of 10 minutes. Worked correctly right after the first build.// This program is to solve a mathematical problem from pouet.net
// (written by adok^hugi)
#include <stdio.h>
int x[10];
void track (int n, int a, int i)
{
int j, s, k, t, r1, r2;
// first digit of a number must not be 0
s = (i == 0) ? 1 : 0;
for (j = s; j <= 9; j++)
{
x[i] = j;
if (i < n)
{
// increment next digit
track (n, a, i + 1);
}
else
{
// check if this corresponds
t = 1;
r1 = 0;
for (k = 0; k <= n; k++)
{
r1 += t * x[k];
t *= 10;
}
r2 = 0;
for (k = 0; k <= n; k++)
{
t /= 10;
r2 += t * x[k];
}
if (r1 * a == r2)
{
// solution found; print it
printf ("n=%u: %u * ", n, a);
for (k = n + 1; k > 0; k--)
{
printf ("%u", x[k - 1]);
}
printf ("\n");
}
}
}
}
void solve (int n)
{
int a;
for (a = 2; a <= 9; a++)
{
track (n, a, 0);
}
}
void main ()
{
int n;
for (n = 1; n < 10; n++)
{
solve (n);
}
}
pouet seems to have fucked a bit up: printf ("n"); should be printf ("\n"); with a "\" before the "n".
By looking at Adok's code snipset, he's using DOS endings on a UNIX machine.
just so you know.
just so you know.
I think someone is confusion a function (as in a programming language) with a mathematical function.
Adok: I think a solution with O(1) is requested.
adok, ok sorry. Got your reasoning from above..
But solving it by reverse engineering a simple function from a brute force heuristic approachs still lacks some beauty.. Also its not a proof.
F(n) as well could be: 3 for N divisible by 1000, 2 ow.
F(N) that is.
btw your code doesn't work correctly.
Quote:
n=6: 6 * 0934065
lol
anes: Thanks for pointing this out, try that:
Code:
It's still running, but the results so far are interesting: for n = 2 to n = 6, it always displays 2 results, and in one of each pair, a = 4, and in the other, a = 9.// This program is to solve a mathematical problem from pouet.net
// (written by adok^hugi)
#include <stdio.h>
int x[10];
void track (int n, int a, int i)
{
int j, s, k, t, r1, r2;
// first digit of a number must not be 0
s = (i == 0) ? 1 : 0;
for (j = s; j <= 9; j++)
{
x[i] = j;
if (i < n)
{
// increment next digit
track (n, a, i + 1);
}
else
{
// check if this corresponds
t = 1;
r1 = 0;
for (k = 0; k <= n; k++)
{
r1 += t * x[k];
t *= 10;
}
r2 = 0;
for (k = 0; k <= n; k++)
{
t /= 10;
r2 += t * x[k];
}
if (r2 * a == r1)
{
// solution found; print it
printf ("n=%u: %u * %u\n", n, a, r2);
}
}
}
}
void solve (int n)
{
int a;
for (a = 2; a <= 9; a++)
{
track (n, a, 0);
}
}
void main ()
{
int n;
for (n = 1; n < 10; n++)
{
solve (n);
}
}
your n is always one digit less.
Yes, that's on purpose. 10^0 = 1 after all.