Unlock the Mystery of Kaprekar's Constant

  • Context: Undergrad 
  • Thread starter Thread starter Jonny_trigonometry
  • Start date Start date
  • Tags Tags
    Constant Mystery
Click For Summary

Discussion Overview

The discussion revolves around Kaprekar's constant, specifically the process of reaching the number 6174 through a series of operations on four-digit numbers. Participants explore the properties of this constant, its relation to different digit lengths, and the potential for programming simulations to investigate the behavior of various numbers.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant describes the process of taking any four-digit number without repeated digits, rearranging it from greatest to least, and subtracting its mirror image to eventually reach 6174.
  • Another participant notes that three-digit numbers lead to 495, while two-digit numbers enter a cycle, suggesting a potential relationship between the digit sums and the base of the number system.
  • A participant expresses interest in programming a simulation to map out all four-digit numbers and their iterations to reach 6174, while also questioning the behavior of five-digit numbers.
  • Code snippets are shared, demonstrating an implementation in C to calculate the number of iterations needed for numbers between 3600 and 3630 to reach 6174, with a limit on iterations to prevent infinite loops.
  • One participant seeks clarification on the code, asking about the purpose of the custom Pow function and the use of addresses in printf and scanf functions.
  • Another participant explains the custom Pow function's purpose and the structure of the program, while expressing confusion about external resources related to Kaprekar's constant.

Areas of Agreement / Disagreement

Participants generally agree on the process leading to Kaprekar's constant for four-digit numbers, but there is uncertainty regarding the behavior of two-digit and five-digit numbers. The discussion includes multiple viewpoints on the implications of digit sums and programming approaches, with no consensus reached on all aspects.

Contextual Notes

The discussion includes assumptions about the properties of numbers in different bases and the behavior of specific digit lengths, which remain unresolved. The effectiveness of the proposed programming approach is also not fully established.

Jonny_trigonometry
Messages
451
Reaction score
0
I just ran across this today:

http://www.trottermath.net/recurops/kaprekar.html

I find this pretty neat, so I just had to post it.

take any four digit number w/o repreated digits, and re-order from greatest to least, then subtract it's mirror image number from it and repeat, you will end up with 6174.

For three digit numbers, you will end up with 495.

for two digit numbers, you will end up in a period four cycle... I think.

I don't know how five digit numbers work. I just haven't really studied this idea for more than a half hour...

I've noticed that the three and four digit numbers add to 18, and since only 99 can add to 18 for two digit numbers, it must cycle through without landing on one specific number, since 99 doesn't have more than one arrangement, for that matter neither does 999 or 9999.

I wonder if the number 18 comes up due to the 10 base number system? maybe for any base, this thing will happen as long as the final number's digits all add to 2*(N-1) where N is the base of the number system, also provided it doesn't take repeated digits to add to that number?

I kinda want to make a program to map out all the four digit numbers, and find all the interations needed for each four digit number to reach 6174, negating the ones which won't work.
 
Mathematics news on Phys.org
It's 2:30 in the morning and I'm putting off chem homework that was due 2 weeks ago to do this... :rolleyes:
I have know idea why i just wrote this, but have fun with it. :wink:
why don't the newlines and tabs show up?
Code:
#include <stdio.h>

int Pow(int);

#define START 3600
#define END 3630
#define N 4
#define LIMIT 50

int main (void)
{
	int i, j, k, num, count, arr[N], temp, high, low;
	for (i = START; i <= END ; i++)
	{
		num = i;
		count = 0;
		while (num != 6174)
		{
			for (j = 0; j < N; j++)
			{
				arr[j] = num % 10;
				num = num / 10;
			}
			for (j = 0; j < (N - 1); j++)
			{
				for (k = 0; k < (N - 1 - j); k++)
				{
					if (arr[k] > arr[k+1])
					{
						temp = arr[k+1];
						arr[k+1] = arr[k];
						arr[k] = temp;
					}
				}
			}
			high = low = 0;
			for (j = 0; j < N; j++)
			{
				high += arr[j] * Pow(j);
				low += arr[j] * Pow(N - 1 - j);
			}
			num = high - low;
			//printf("%d, %d, %d\n", high, low, num);
			count++;
			if (count >= LIMIT)
			{
				printf("Exceeds limit...\n");
				count = -1;
				break;
			}
		}
		if (count >= 0) printf("%d\n", count);
	}
	return 0;
}

int Pow(int x)
{
	int val = 1, i = 0;
	while (i < x)
	{
		val = val * 10;
		i++;
	}
	return val;
}
 
Last edited:
durt said:
It's 2:30 in the morning and I'm putting off chem homework that was due 2 weeks ago to do this... :rolleyes:
I have know idea why i just wrote this, but have fun with it. :wink:
why don't the newlines and tabs show up?
Code:
#include <stdio.h>
int Pow(int);
#define START 3600
#define END 3630
#define N 4
#define LIMIT 50
int main (void)
{
int i, j, k, num, count, arr[N], temp, high, low;
for (i = START; i <= END ; i++)
{
num = i;
count = 0;
while (num != 6174)
{
for (j = 0; j < N; j++)
{
arr[j] = num % 10;
num = num / 10;
}
for (j = 0; j < (N - 1); j++)
{
for (k = 0; k < (N - 1 - j); k++)
{
if (arr[k] > arr[k+1])
{
temp = arr[k+1];
arr[k+1] = arr[k];
arr[k] = temp;
}
}
}
high = low = 0;
for (j = 0; j < N; j++)
{
high += arr[j] * Pow(j);
low += arr[j] * Pow(N - 1 - j);
}
num = high - low;
//printf("%d, %d, %d\n", high, low, num);
count++;
if (count >= LIMIT)
{
printf("Exceeds limit...\n");
count = -1;
break;
}
}
if (count >= 0) printf("%d\n", count);
}
return 0;
}
int Pow(int x)
{
int val = 1, i = 0;
while (i < x)
{
val = val * 10;
i++;
}
return val;
}


hmm... I'm not as savy in C as you are. It's kinda hard for me to follow, but I know that breaks can be avoided in almost all cases. Do you need the int Pow(int) to be global? by the way, what is Pow(int), a header file function in stdio.h? Do you need an & in front of printf values, or is that scanf? I like the program so far though. Good work!:smile:
 
Pow(int) returns 10^(parameter), and I defined it myself. There is a similar function, pow(), in math.h, but Pow() is so simple, I just tossed it in there (math.h is not needed now). Its scanf that you have to right to addresses. Anyway, you just define your start and end numbers, and the program will display the number of iterations needed to reach 6174. LIMIT is the maximum number of iterations the program will go through for a single number before giving up. This is a failsafe in case a number that never reaches 6174 occurs. All those for loops just assign the digits of num to an array, sorts the array (bubble sort), and converts the array back into the two numbers that have to be subtracted.

But perhaps all this has been in vain... http://kaprekar.sourceforge.net/proof/proof_r.php"
I don't get it, but then again I didn't read it...
 
Last edited by a moderator:

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 68 ·
3
Replies
68
Views
12K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 125 ·
5
Replies
125
Views
20K