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: Select all

```
/* 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.