Join the millions that use us for their forum communities. Create your own forum today.
zIFBoards - Free Forum Hosting
Welcome to Dozensonline. We hope you enjoy your visit.
You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, and sending personal messages. Registration is simple, fast, and completely free. (You will be asked to confirm your email address before we sign you on.)
Join our community!
If you're already a member please log in to your account to access all of our features:

Name:   Password:


 

 Kaprekar's Constant 6174
Ged
Posted: Feb 19 2015, 01:08 PM


Casual Member


Group: Members
Posts: 83
Member No.: 16
Joined: 6-August 05



I have just found this and I have tried it and it works! But is there a similar one for Dozenal? I tried four-digits and you get a round:-

Kaprekar's Constant 6174

1. Take any four-digit number except 1111, 2222, ..., 9999.
Leading zeros are aloud.

2. Arrange the digits in increasing and then decreasing order to get two four-digit numbers, add leading zeros if necessary.

3.Subtract the smaller number from the bigger number.

4. Repeat steps 2 and 3.

In at most 7 iterations, this process will ALWAYS produce 6174.

Top
jim
Posted: Feb 21 2015, 08:26 AM


Regular


Group: Members
Posts: 165
Member No.: 641
Joined: 20-April 12



I don't understand it but I see 9's.

7 cubed x 18 = 6174

Jim
Top
wendy.krieger
Posted: Feb 21 2015, 12:10 PM


Dozens Demigod


Group: Members
Posts: 2,432
Member No.: 655
Joined: 11-July 12



In base 12, it seems to settle down to some cycles as shown. [CONFIRMED]

3EE8 - 8284 - 6376
7EE4 - 7375 - 4198 - 8374 - 5287 - 6196

Base 18 seems to do just two iterations of 3; [CONFIRMED]

10 1 15 8 - 14 1 15 4 - 14 9 7 4
6 1 15 12 - 14 5 11 4 - 10 5 11 8

In base 120, the cycles are shorter, giving eg (7260 cases to test).

0 0 0 0
72 23 95 48

40 23 95 80 - 72 39 79 48
88 7 111 32 - 104 55 63 16

88 23 95 32 - 72 55 63 48 - 24 7 111 96 - 104 71 47 16
88 39 79 32 - 56 39 79 64 - 40 7 111 80 - 104 39 79 16
88 55 63 32 - 56 7 111 64 - 104 7 111 16 - 104 87 31 16
88 71 47 32 - 56 23 95 64 - 72 7 111 48 - 104 23 95 16

This is interesting. If you add 1 1 0 to these numbers, they all correspond to fifteenths, but the first is just fifths, and the second is a composite of thirds and fifths. Each of the fifteenths ie 8n (n=1 to 14) occur exactly 6 times.

Here is the rexx script if you want to play with it.

Even more interesting, is that 6174 + 110 = 6284, and this is 3/5 1/5 4/5 2/5. That's exactly the same as twelfty's 72 23 95 48, and indeed, the same formation works in all bases which are multiples of 5, eg

20 gives 12 3 15 8. 15 gives 9 2 11 6 etc.

CODE

/* rexx */
parse arg base tail; sz=0;
do forever;  sz=sz+1
 parse var tail s.sz tail; s.sz = s.sz+0
 if tail = '' then leave; end;
do ll = 1 to 22
call sortme
call kaprekar
ax = format(ll, 4)':'
do a=1 to sz; ax = ax s.a; end
say ax
end

exit

sortme:
do b=1 to sz; t.b = -1  
do a=1 to sz; t.b = max(t.b, s.a); end
do a=1 to sz; if s.a < t.b then iterate; s.a = -1; leave; end
end;
return
kaprekar:
do a=1 to sz; aa = sz+1-a; s.a = t.a - t.aa; end
do a=1 to sz; ab = sz-a; aa = ab+1;
  if s.aa < 0 then do; s.aa = s.aa + base; s.ab = s.ab -1; end
  end;
return


KAPREKAR.REX base d0 d1 ....
eg k 10 7 1 6 5

This sorts the digits into ascending and descending order, eg 7 6 5 1 and 1 5 6 7, and subtracts them (6, 1, -1, -6). The negative digits are eliminated as in hand arithetic, by adding base, and subtract 1 from the next column.

This is iterated and printed LL times. 22 seems a suited value on a 25-line screen.
Top
dgoodmaniii
Posted: Feb 21 2015, 08:42 PM


Dozens Demigod


Group: Admin
Posts: 1,927
Member No.: 554
Joined: 21-May 09



QUOTE (Ged @ Feb 19 2015, 01:08 PM)
I have just found this and I have tried it and it works! But is there a similar one for Dozenal?

I'm writing a program to test this. I'll report the results tonight; I'm halfway through and need to do something else. But this looks like fun.
Top
wendy.krieger
Posted: Feb 21 2015, 10:23 PM


Dozens Demigod


Group: Members
Posts: 2,432
Member No.: 655
Joined: 11-July 12



Base 40 settles down to a single value, while base 55 has a period of 20 items.

Base 120 can be used to derive 15. Add 1.1.0 to each element of the cycle, divide the digits by 8, and then subtract 1.1.0, eg

88.71.47.32 gives 88,72,48,32 gives 11,9,6,4 gives 11,8,5,4
Top
dgoodmaniii
Posted: Feb 22 2015, 12:19 AM


Dozens Demigod


Group: Admin
Posts: 1,927
Member No.: 554
Joined: 21-May 09



Programs used to produce the following are at the bottom of this post.

First off, I could find no pattern for four-digit numbers in dozenal. I ran 100; different numbers for 10; iterations each and produced no patterns; indeed, the number of duplicates was lower than I would expect even from chance. (Not actually, of course, but it surprised me.) Of course, I may have made some horrible coding mistake to make it not work, but it did work for the decimal version pretty smoothly, so I don't think I have.

For five digit numbers, however, there was a definite pattern, and the number is 83E74. I haven't jiggered the program to record the number of iterations necessary to produce this, but only five of the 100; different trial numbers (randomly selected) failed to produce this number. I have not yet investigated if these are simply five identical digits, which the rules originally suggested specifically exclude, or what. I hope to learn more about this later tonight when I get some more leisure time.

So, in conclusion: 5-digit numbers, 83E74.

The below program is "check.sh"; it takes the number offered as its first argument, does no error-checking whatsoever, calls a function to split the given number into itself arranged ascending and descending, then does the necessary subtraction, prints the result, and loops again. Now that I have an idea what the right number is, I'll probably tell it to stop when it reaches said number and report the number of iterations necessary to reach it; until then, here it is.

CODE

#/bin/bash
# +AMDG

num=$1;
function rearrange
{
digits=`echo $num | grep -o .`;
digits=`echo "$digits" | sed -e 's/\([0-9]\)/ 0\1 /g'`
digits=`echo "$digits" | sed -e 's/X/10/g'`
digits=`echo "$digits" | sed -e 's/E/11/g'`
ascdigs=`echo $digits | awk 'BEGIN{RS=" ";} {print $1}' | sort`
descdigs=`echo $digits | awk 'BEGIN{RS=" ";} {print $1}' | sort -r`
ascdigs=`echo $ascdigs | sed -e 's/10/X/g'`
ascdigs=`echo $ascdigs | sed -e 's/11/E/g'`
descdigs=`echo $descdigs | sed -e 's/10/X/g'`
descdigs=`echo $descdigs | sed -e 's/11/E/g'`
ascdigs=`echo $ascdigs | sed -e 's/0\([0-9]\)/\1/g'`
descdigs=`echo $descdigs | sed -e 's/0\([0-9]\)/\1/g'`
ascdigs=`echo $ascdigs | sed -e 's/ //g'`
descdigs=`echo $descdigs | sed -e 's/ //g'`
}
for i in `seq 1 12`; do
rearrange
decasc=`dec $ascdigs | cut -d. -f1`;
decdesc=`dec $descdigs | cut -d. -f1`;
if [[ $decasc -gt $decdesc ]]; then
 num=`dozdc " $ascdigs $descdigs - ="`;
else
 num=`dozdc " $descdigs $ascdigs - ="`;
fi
echo "$num"
done
exit


The below program is "rollcheck.sh," which is bash rather than simply POSIX shell so I can use the convenient random-number function. (Yes, I could get them from /dev/random; but whaa.) It simply produces a random number; makes sure that it's really only five digits (by piping it through "cut"), and feeds it to check.sh, writing the results therefore into a file called "results." At the end, it extracts all the duplicate entries, prints them to the screen, then writes them to a file called "commons."

CODE

#!/bin/bash
# +AMDG

rm results;
for i in `seq 1 144`; do
trialnum=$((RANDOM%248831+20735))
number=`doz $trialnum`
number=`echo $number | cut -c1-5`
./check.sh $number >> results;
done;
uniq -cd results;
uniq -cd results >> commons;


(I promise that on my computer this code is indented sensibly; the code environment on the board doesn't retain that.)
Top
wendy.krieger
Posted: Feb 22 2015, 02:57 AM


Dozens Demigod


Group: Members
Posts: 2,432
Member No.: 655
Joined: 11-July 12



Don's program was looking for a single value, rather than a loop. You could use an associative array to detect loops.

My program prints out 20 consecutive iterations of the process, and you can see in that the full iterations of either of the two loops. In fact, all of the data was cut from a command prompt, and edited to make it line.

But in any case, there really isn't a lot of numbers to check. The base forms are a, b, -b, -a, where a \ge b \ge 0. You then apply the carry ripple through it.

Top
dgoodmaniii
Posted: Feb 22 2015, 03:09 AM


Dozens Demigod


Group: Admin
Posts: 1,927
Member No.: 554
Joined: 21-May 09



I'm sorry, I don't understand what you're saying here.

Looking for a loop? It uses a loop to seek a single value; namely, the common result of this series of arithmetic operations. I'm not sure why I'd be looking for a loop, nor even what precisely that would mean in this context.

QUOTE

But in any case, there really isn't a lot of numbers to check.  The base forms are a, b, -b, -a,  where a \ge b \ge 0.  You then apply the carry ripple through it.


Aren't there, in fact, a lot of numbers to check? Namely, 10000--EEEEE? I'm not sure what you mean by "carry ripple", either.
Top
jim
Posted: Feb 22 2015, 05:06 AM


Regular


Group: Members
Posts: 165
Member No.: 641
Joined: 20-April 12



You guys are not looking at this as an ancient problem and it is a pyramid problem and it is about cubes.

In the ancient world to work out the side of a cube double that of 7 was not to use 1.25992 as it took too much calculation. 1.26 was used.

A cube twice the volume of 7 343 is 686 and the cube root is 8.81944 The ancients used 1.26 so the cube root = 8.82.

8.82 x 7 = 61.74

Then interestingly 7 squared 49 x 1.26 the approximate for the cube root of 2 = 61.74.

Jim

Top
wendy.krieger
Posted: Feb 22 2015, 06:21 AM


Dozens Demigod


Group: Members
Posts: 2,432
Member No.: 655
Joined: 11-July 12



There are not many numbers to check at all. For example, for four and five place dozenal numbers, there are just 78, and all fall under 100;.

Consider what happens when you try 7165. The process is to sort the digits and subtract the ascending from the descending, eg 7651 - 1567. But we can subtract 1551 from these to get 6100 - 0016. So the outcome of 7165 is the same as 0016, or 0061 etc.

So, the loops are then

CODE

for a = 0 to b-1 do
for b = 0 to a  do
  call try_this_number
end
end


suffices for all four- and five- place numbers, since the middle number disappears.

The ripple carry is in my code, which first finds 7 6 5 1 - 1 5 6 7 = 6 1 -1 -6. The next step is to do the carry: ie -6 = -1 6, carry the one to -2 1 -2 = 0 10 So this is 6 0 10 6, dozenal, or 6 0 8 4 decimal, etc.

I ran through the base 12 five place numbers, and 74 of the 78 end up at 83E74 (which corresponds to the next iteration as 0 0 0 1 1), but there are three irregulars, 00006, 00007 and 00056, which ends at 6EEE5 - 64E66, and the irregular 00000 which gives itself. The four-place numbers all end up in the loop aboves.

40 gives 24.07.31.16 after no more than 21 iterations, except for x.x.x.x which leads to 0.0.0.0. 8.24 is the smallest number to give this straight up.

10 gives 6174 after no more than 7 iterations, except for NNNN, 26 is the smallest number to give this straight up.

Top
Dan
Posted: Feb 22 2015, 08:34 AM


Dozens Disciple


Group: Members
Posts: 1,463
Member No.: 19
Joined: 8-August 05



QUOTE (dgoodmaniii @ Feb 21 2015, 10:09 PM)
Looking for a loop?  It uses a loop to seek a single value; namely, the common result of this series of arithmetic operations.  I'm not sure why I'd be looking for a loop, nor even what precisely that would mean in this context.

I think she means a repeating cycle of numbers. For example, in the middle-square PRNG method with 4 decimal digits, the sequence 0540 → 2916 → 5030 → 3009 → 0540 → 2916 → 5030 → 3009...
Top
wendy.krieger
Posted: Feb 22 2015, 08:42 AM


Dozens Demigod


Group: Members
Posts: 2,432
Member No.: 655
Joined: 11-July 12



No, Jim, we're not looking at any particular property of 6174, except that it is a set of digits with interesting properties. That is, we're not looking at the number 1.1.1.0 base 18 (ie 7*7*7*18), or any of the facinating relations between 63 and 50 and their cubes.

What we're looking at is the sort of thing that people who don't use other bases and have too much free time on their hand do. They somehow think that there is some sort of magic in the decimal expansion of pi, or tricks with digits.

Here, the number in question is derived from eg 6200 - 0026, or other numbers by adding symmetric numbers, like 1221 to both sides, eg 7421 - 1247.

Of course, people notice these tricks, and say, Oi! what about dozenal? What about a hundred. Doesn't Kaprekar's process give a single value anywhere?

So we do a bit of pan-base hacking. Don's code seems to be largely base 12, where as mine is set for any base, such as base 120. In fact, you set the base in the first param.

Top
Dan
Posted: Feb 22 2015, 08:45 AM


Dozens Disciple


Group: Members
Posts: 1,463
Member No.: 19
Joined: 8-August 05



What we're looking for is a fixed point of the function that maps one number in the Kaprekar sequence to the next.

For example, in decimal, 6174 maps to 7641 - 1467 = 6174 again.

Through a brute-force search, I've found that the only such fixed point with 4 dozenal digits is 0000.

But it does seem that many initial "seed" values lead into the loop 8374 → 5287 → 6196 → 7BB4 → 7375 → 4198 → 8374 → ...
Top
wendy.krieger
Posted: Feb 22 2015, 08:57 AM


Dozens Demigod


Group: Members
Posts: 2,432
Member No.: 655
Joined: 11-July 12



This list shows the kaprekar iterations of 0 0 1 2 and 0 0 0 3 in base 12. These settle down to loops, such as from 3: to 9: in the first example, and 4: to 7: in the second example. All 78 root values have been checked, and apart from 0000, they all end in one of these two loops.

CODE

[H:\USERS\Wendy]kaprekar 12 0 0 1 2
  1: 2 0 10 10
  2: 10 7 3 2
  3: 8 3 7 4
  4: 5 2 8 7
  5: 6 1 9 6
  6: 7 11 11 4
  7: 7 3 7 5
  8: 4 1 9 8
  9: 8 3 7 4
 10: 5 2 8 7
 11: 6 1 9 6
 12: 7 11 11 4

[H:\USERS\Wendy]kaprekar 12 0 0 0 3
  1: 2 11 11 9
  2: 9 1 9 3
  3: 8 5 5 4
  4: 3 11 11 8
  5: 8 2 8 4
  6: 6 3 7 6
  7: 3 11 11 8
  8: 8 2 8 4
  9: 6 3 7 6


There are 78 root values for the five-digit case, of which 74 settle down to a single value 83E74. One settles down to 00000, and three settle down to the second loop. These are 00006, 00007, and 00056.

All 78 values have been followed through.

CODE
[H:\USERS\Wendy]kaprekar 12 0 0 0 1 2
  1: 2 0 11 10 10
  2: 11 7 11 3 1
  3: 10 7 11 3 2
  4: 9 6 11 4 3
  5: 8 4 11 6 4
  6: 7 3 11 7 5
  7: 8 1 11 9 4
  8: 10 4 11 6 2
  9: 9 5 11 5 3
 10: 8 3 11 7 4
 11: 8 3 11 7 4
 12: 8 3 11 7 4
 13: 8 3 11 7 4
 14: 8 3 11 7 4

[H:\USERS\Wendy]kaprekar 12 0 0 0 0 6
  1: 5 11 11 11 6
  2: 6 4 11 6 6
  3: 6 11 11 11 5
  4: 6 4 11 6 6
  5: 6 11 11 11 5
  6: 6 4 11 6 6


Early tests on the six-place dozenal suggests one or more loops of ten (ie 2*5). Some have a leadin of 20 places, which means i will need to think differently here.

The 2-place version has a period of 6 (the six odd multiples of E), while the three-digit version ends at 5E6. The seven-digit version has a period of 9, or some multiple of it.

Likewise the 820 root values for base 40 have all been done, all give 24 7 31 16, with the exception of when all four digits are the same, these give 0 0 0 0. The longest lead is 20, meaning that the number appears only at the 21 iteration.

The reason why i was suggesting an associative array, is because the return to the start of the loop is immediately detected when one stores a value using the number.

For example, in the first four-digit 12 example above, the script would store the value (before the colon) in the label (after the colon), eg a."2 0 10 10" = 1, etc. But when it gets to line 9, it looks for a."8 3 7 4" but this already has 3 in it, so there are 2 leaders (ie 3-1), and a loop of 6 (ie 9-3).
Top
wendy.krieger
Posted: Feb 22 2015, 10:21 AM


Dozens Demigod


Group: Members
Posts: 2,432
Member No.: 655
Joined: 11-July 12



For 120, the following

2-digit: There is a period of 55, except for multiples of 11, which give 5.

3-digit: All settle down to 59.E9.60, but the leadins can be quite long.

4-digit: Tested loops settle down to one of the four-period places.

5-digit: These seem to head to 80.39.E9.79.40, but the experience with 12 tells us not to suppose all do this.

Top
jim
Posted: Feb 22 2015, 11:17 AM


Regular


Group: Members
Posts: 165
Member No.: 641
Joined: 20-April 12



Hi Wendy

What if we tried 2592? I think we would do it in 7?

Jim
Top
dgoodmaniii
Posted: Feb 23 2015, 02:12 AM


Dozens Demigod


Group: Admin
Posts: 1,927
Member No.: 554
Joined: 21-May 09



Yes, my scripts were entirely dozenal, by design. And yes, I wasn't really interested in finding cycles, but in locating a recurring value.

I still don't really understand what Wendy means by a "carry ripple," but yes, I found through brute force attack that the five-digit pattern isn't as clean as it had originally looked. It's really two patterns, one that ends at 83E74, and the other that loops at 6EEE5 - 64E66.

On the other hand, with three digits, I found that nearly all ended in 5E6 (this is a small enough number that I could run every one without growing old waiting for it to finish). Out of XEE possibilities, X5X ended in 5E6.

There doesn't seem to be any number of dozenal digits that works as cleanly as 6174 in decimal, though.
Top
wendy.krieger
Posted: Feb 23 2015, 03:45 AM


Dozens Demigod


Group: Members
Posts: 2,432
Member No.: 655
Joined: 11-July 12



Carry ripple, is simply that when you subtract, eg 6200 from 0026, you have to do several carries. The term 'ripple' is a hardware term, that if you have several addition gates, the final result isn't stable until the carry has 'rippled' through the units, tens, hundreds gates.

In the example above, subtracting 26 from 6200 causes a carry in the units, tens, and hundeds column, so the thing isn't final until that is done. After the uncarried subtraction is done of pairs of numbers, one is left with eg a, b, -b, -a, where b <= a. This is eaily achieved from a starting from eg "0 0 b a" directly. This is why i only looked at these numbers.

My rexx script (i upated the image in my first post), actually handles all bases, and any number of digits. The sort method is primitive, (it's a kind of insertion sort), but effective for very small numbers. On the other hand, the killer for larger values is that the leadin to the period can be quite long. For example, for three places of 120, it does settle down to 59.119.60, but this can take sixty iterations to get there.

From running the script on four-place dozenal (kaprekar 12 0 0 0 1) it came apparent that it settles down to a cycle of three or six places. When Don said that some of the five-place dozenal gave no result, i could from my runthroughs that these typically referred to the cycle-two cases, 00005, 00006 and 00056.

Top
Ged
Posted: May 25 2015, 11:02 PM


Casual Member


Group: Members
Posts: 83
Member No.: 16
Joined: 6-August 05



Dgoodmaniii I thought you had got it with the 5 digit 83E74. Then I saw that you found 6EEE5 - 64E66. sad.gif
So it looks like this phenomena only works for decimal. How nice it would have been if it worked for other bases with different number of digits e.g. half the base minus one. wink.gif
That would have been brilliant. Thanks for trying.
Top
« Next Oldest | General | Next Newest »
zIFBoards - Free Forum Hosting
Free Forums. Reliable service with over 8 years of experience.
Learn More · Register Now

Topic Options



Hosted for free by zIFBoards* (Terms of Use: Updated 2/10/2010) | Powered by Invision Power Board v1.3 Final © 2003 IPS, Inc.
Page creation time: 0.0284 seconds · Archive