# Add new comment

### Kaprekar operation 4 digit numbers with bases 2-40

Hi there Philip!

I made some brute force computing for test of four digit numbers with different bases up to 40. The principle for presentation is extrapolation of the method used to present HEX code: A = 10, B = 11 ….. F = 15, G = 16 … Z = 35, [ = 36, … ^ = 39, _ = 40.

I found that only bases 5, 10 and 40 terminate to one value: 3032 (=dec 392), 6174 and O7VG (= dec 1548456) respectively with max number of loops 4, 7 and 21 respectively.

When it comes to base = 20, loop terminates to C3F8 (= dec 97508) for many start values with max number of loops = 10
Base 15, 30, 35 do not terminate to one value.

Below a sample of loops for different bases. “…” means that loop is unterminated and will continue for ever. “…” is printed after a value in the last position N when it has been detected earlier in the loop in position N-2 or earlier. E.g. the loop
0045 5311 4132 3043 3552 3133 1554 4042 4132 ...
will continue for ever like
0045 5311 4132 3043 3552 3133 1554 4042 4132 3043 3552 3133 1554 4042 4132 3043 3552 3133 1554 4042 4132 etc

All bases are not included in this comment, but are produced in the program. I’m thinking of extending the number of digits to be variable too…
All bases have been given a random start value within the definition area, and 10 loops are printed. All loops are not presented in this comment.

Kaprekar's constant for BASE = *
***********************************************************
Base = 2:
1001 1001
1010 1001
1011 0111
1100 1001
1101 0111
1110 0111
0001 0111
0010 0111
***********************************************************
Base = 3:
0010 0222 1221 1012 1221 ...
0011 1012 1221 1012 ...
0012 2011 1221 1012 1221 ...
0020 1221 1012 1221 ...
***********************************************************
Base = 4:
3321 2022 1332 2022 ...
3322 1023 3021
3323 0333 2331 2022 1332 2022 ...
3330 2331 2022 1332 2022 ...
3331 1332 2022 1332 ...
3332 0333 2331 2022 1332 2022 ...
***********************************************************
Base = 5:
0140 4031 4121 3032
0141 3441 3032
0142 4031 4121 3032
0143 4121 3032
0144 4211 3032
0200 1443 3032
0201 2033 3032
0202 2123 1443 3032
0203 3122 1443 3032
0204 4121 3032
***********************************************************
Base = 6:
0051 5041 5221 3552 3133 1554 4042 4132 3043 3552 ...
0052 5131 4132 3043 3552 3133 1554 4042 4132 ...
***********************************************************
Base = 10:
0860 8532 6174
0861 8442 5994 5355 1998 8082 8532 6174
0862 8352 6174
0863 8262 6354 3087 8352 6174
0864 8172 7443 3996 6264 4176 6174
0865 8082 8532 6174
0866 7992 7173 6354 3087 8352 6174
0867 8082 8532 6174
0868 8172 7443 3996 6264 4176 6174
0869 9171 8532 6174
***********************************************************
Base = 15:
0796 90D6 D2B2 B854 72B8 90D6 ...
0797 8EE6 8587 30DC D852 B2B4 9676 30DC ...
0798 90D6 D2B2 B854 72B8 90D6 ...
***********************************************************
Base = 16:
0C09 C864 81D8 BFF4 B3B5 8598 3FFC C2C4 A776 3FFC ...
0C0A C954 83B8 7FF8 8688 1FFE E0E2 EB32 C774 7FF8 ...
0C0B CA44 8598 3FFC C2C4 A776 3FFC ...
***********************************************************
Base = 20:
0566 60IE I7B2 G3F4 DA87 61HE G7B4 C3F8
0567 70ID I5D2 G7B4 C3F8
0568 80IC I3F2 GB74 C3F8
0569 90IB I1H2 HE43 E996 7JJC C6C8 63FE C7B8 52GF E996 ...
056A A0IA HJJ2 H1H3 GD54 C7B8 52GF E996 7JJC C6C8 63FE C7B8 ...
056B B0I9 I1H2 HE43 E996 7JJC C6C8 63FE C7B8 52GF E996 ...
056C C0I8 I3F2 GB74 C3F8
056D D0I7 I5D2 G7B4 C3F8
056E E0I6 I7B2 G3F4 DA87 61HE G7B4 C3F8
056F F0I5 I992 FJJ4 F3F5 C998 3JJG G2G4 EB76 83FC C3F8
***********************************************************
Base = 39:
0VZZ Z3Y4 WT87 PKHE B2ZS XGL6 R4XC TENA J8TK L0\I \2Z2 ZW54 VQB8 NENG 96VU PKHE ...
0VZ[ [3Y3 XU76 RMFC F6VO P8TE LARI H2ZM X4X6 TQBA JENK 90\U \KH2 Z2Z4 XU76 ...
***********************************************************
Base = 40:
0I4A I5XM S3ZC WFN8 O7VG
0I4B I6WM Q3ZE WBR8 OFNG 96WV QLHE C3ZS WFN8 O7VG
0I4C I7VM O3ZG W7V8 PMGF A5XU SJJC F^^O OEOG A7VU OJJG 7^^W W6W8 QNFE C7VS OFNG 96WV QLHE C3ZS WFN8 O7VG
0I4D I8UM M3ZI W3Z8 WNF8 O7VG
0I4E I9TM K3ZK V^^8 V7V9 OLHG 83ZW WNF8 O7VG
0I4F IASM I3ZM W3Z8 WNF8 O7VG
0I4G IBRM G3ZO W7V8 PMGF A5XU SJJC F^^O OEOG A7VU OJJG 7^^W W6W8 QNFE C7VS OFNG 96WV QLHE C3ZS WFN8 O7VG
0I4H ICQM E3ZQ WBR8 OFNG 96WV QLHE C3ZS WFN8 O7VG
0I4I IDPM C3ZS WFN8 O7VG
0I4J JDPL C1\S [FN4 W7V8 PMGF A5XU SJJC F^^O OEOG A7VU OJJG 7^^W W6W8 QNFE C7VS OFNG 96WV QLHE C3ZS WFN8 O7VG