pouët.net

Go to bottom

Any demoscener from Mensa?

category: residue [glöplog]
gargaj: four edges of the square intersect non dotted grid intersections anyway.
ok doom :)
added on the 2006-11-19 16:45:02 by texel texel
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?
added on the 2006-11-19 17:00:24 by texel texel
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.
added on the 2006-11-19 21:36:18 by texel texel
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 :)
Well, I guess Adok has to come to the rescue here. Where is he?
added on the 2006-11-25 18:07:53 by Stelthzje Stelthzje
Well, I think I will post the solutions if you are not able to solve it... I will give you some few days more...
added on the 2006-11-25 18:26:56 by texel texel

Sorry,I did not see a solution after 15 minutes and decided not to burn more time on this.. Next one maybe :)
added on the 2006-11-25 18:29:36 by Stelthzje Stelthzje
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.
added on the 2006-11-26 11:28:20 by Adok Adok
adok, that reasoning is soo middle ages.
For all the non-coders out there:

Code:// 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); } }
So... here you go. Work of 10 minutes. Worked correctly right after the first build.
added on the 2006-11-26 12:54:48 by Adok Adok
pouet seems to have fucked a bit up: printf ("n"); should be printf ("\n"); with a "\" before the "n".
added on the 2006-11-26 12:56:40 by Adok Adok
By looking at Adok's code snipset, he's using DOS endings on a UNIX machine.

just so you know.
added on the 2006-11-26 13:00:51 by LiraNuna LiraNuna

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.


added on the 2006-11-26 13:09:59 by Stelthzje Stelthzje

adok, ok sorry. Got your reasoning from above..
added on the 2006-11-26 13:11:42 by Stelthzje Stelthzje

But solving it by reverse engineering a simple function from a brute force heuristic approachs still lacks some beauty.. Also its not a proof.
added on the 2006-11-26 13:13:08 by Stelthzje Stelthzje
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
added on the 2006-11-26 13:53:00 by elkmoose elkmoose
anes: Thanks for pointing this out, try that:
Code:// 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); } }
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.
added on the 2006-11-26 14:24:19 by Adok Adok
your n is always one digit less.
Yes, that's on purpose. 10^0 = 1 after all.
added on the 2006-11-26 14:41:34 by Adok Adok

login

Go to top