The Rite of Sling

Duels are interesting things. Flashman made his name in one and earnt an impressive scar in another. Maupassant explored their psychology and so did his imitator Maugham. Game theory might be a good guide on how to fight one, but I’d like to look at something simpler: the concept of duelling numbers.

How would two numbers fight? One way is to use digit-sums. Find the digit-sum of each number, then take it away from the other number. Repeat until one or both numbers <= 0, like this:

function duel(n1,n2){
print(n1," <-> ",n2);
do{
s1=digitsum(n1);
s2=digitsum(n2);
n1 -= s2;
n2 -= s1;
print(” -> ",n1," <-> ",n2);
}while(n1>0 && n2>0);
}

Suppose n1 = 23 and n2 = 22. At the first step, s1 = digitsum(23) = 5 and s2 = digitsum(22) = 4. So n1 = 23 – 4 = 19 and n2 = 22 – 5 = 17. And what happens in the end?

23 ↔ 22 ➔ 19 ↔ 17 ➔ 11 ↔ 7 ➔ 4 ↔ 5 ➔ -1 ↔ 1

So 23 loses the duel with 22. Now try 23 vs 24:

23 ↔ 24 ➔ 17 ↔ 19 ➔ 7 ↔ 11 ➔ 5 ↔ 4 ➔ 1 ↔ -1

23 wins the duel with 24. The gap can be bigger. For example, 85 and 100 are what might be called David and Goliath numbers, because the David of 85 beats the Goliath of 100:

85 ↔ 100 ➔ 84 ↔ 87 ➔ 69 ↔ 75 ➔ 57 ↔ 60 ➔ 51 ↔ 48 ➔ 39 ↔ 42 ➔ 33 ↔ 30 ➔ 30 ↔ 24 ➔ 24 ↔ 21 ➔ 21 ↔ 15 ➔ 15 ↔ 12 ➔ 12 ↔ 6 ➔ 6 ↔ 3 ➔ 3 ↔ -3

999 and 1130 are also David and Goliath numbers:

999 ↔ 1130 ➔ 994 ↔ 1103 ➔ 989 ↔ 1081 ➔ 979 ↔ 1055 ➔ 968 ↔ 1030 ➔ 964 ↔ 1007 ➔ 956 ↔ 988 ➔ 931 ↔ 968 ➔ 908 ↔ 955 ➔ 889 ↔ 938 ➔ 869 ↔ 913 ➔ 856 ↔ 890 ➔ 839 ↔ 871 ➔ 823 ↔ 851 ➔ 809 ↔ 838 ➔ 790 ↔ 821 ➔ 779 ↔ 805 ➔ 766 ↔ 782 ➔ 749 ↔ 763 ➔ 733 ↔ 743 ➔ 719 ↔ 730 ➔ 709 ↔ 713 ➔ 698 ↔ 697 ➔ 676 ↔ 674 ➔ 659 ↔ 655 ➔ 643 ↔ 635 ➔ 629 ↔ 622 ➔ 619 ↔ 605 ➔ 608 ↔ 589 ➔ 586 ↔ 575 ➔ 569 ↔ 556 ➔ 553 ↔ 536 ➔ 539 ↔ 523 ➔ 529 ↔ 506 ➔ 518 ↔ 490 ➔ 505 ↔ 476 ➔ 488 ↔ 466 ➔ 472 ↔ 446 ➔ 458 ↔ 433 ➔ 448 ↔ 416 ➔ 437 ↔ 400 ➔ 433 ↔ 386 ➔ 416 ↔ 376 ➔ 400 ↔ 365 ➔ 386 ↔ 361 ➔ 376 ↔ 344 ➔ 365 ↔ 328 ➔ 352 ↔ 314 ➔ 344 ↔ 304 ➔ 337 ↔ 293 ➔ 323 ↔ 280 ➔ 313 ↔ 272 ➔ 302 ↔ 265 ➔ 289 ↔ 260 ➔ 281 ↔ 241 ➔ 274 ↔ 230 ➔ 269 ↔ 217 ➔ 259 ↔ 200 ➔ 257 ↔ 184 ➔ 244 ↔ 170 ➔ 236 ↔ 160 ➔ 229 ↔ 149 ➔ 215 ↔ 136 ➔ 205 ↔ 128 ➔ 194 ↔ 121 ➔ 190 ↔ 107 ➔ 182 ↔ 97 ➔ 166 ↔ 86 ➔ 152 ↔ 73 ➔ 142 ↔ 65 ➔ 131 ↔ 58 ➔ 118 ↔ 53 ➔ 110 ↔ 43 ➔ 103 ↔ 41 ➔ 98 ↔ 37 ➔ 88 ↔ 20 ➔ 86 ↔ 4 ➔ 82 ↔ -10

You can look in the other direction and find bully numbers, or numbers that beat all numbers smaller than themselves. In base 10, the numbers 2 to 9 obviously do. So do these:

35, 36, 37, 38, 39, 47, 48, 49, 58, 59, 64, 65, 66, 67, 68, 69, 76, 77, 78, 79, 189

In other bases, bullies are sometimes common, sometimes rare. Sometimes they don’t exist at all for n > b. Here are bully numbers for bases 2 to 30:

base=2: 3, 5, 7, 13, 15, 21, 27, 29, 31, 37, 43, 45, 47, 54, 59
b=3: 4, 5, 7, 8, 14
b=4: 5, 6, 7, 9, 10, 11, 14, 15, 27, 63
b=5: 12, 13, 14, 18, 19, 23, 24
b=6: 15, 16, 17, 22, 23, 26, 27, 28, 29, 32, 33, 34, 35, 65, 71, 101
b=7: 17, 18, 19, 20, 24, 25, 26, 27, 32, 33, 34, 40, 41, 45, 46, 47, 48, 76
b=8: 37, 38, 39, 46, 47, 59, 60, 61, 62, 63, 95, 103, 111, 119
b=9: 42, 43, 44, 52, 53, 61, 62
b=10: 35, 36, 37, 38, 39, 47, 48, 49, 58, 59, 64, 65, 66, 67, 68, 69, 76, 77, 78, 79, 189
b=11: 38, 39, 40, 41, 42, 43, 49, 50, 51, 52, 53, 54, 62, 63, 64, 65, 73, 74, 75, 76, 85, 86, 87
b=12: 57, 58, 59
b=13: 58, 59, 60, 61, 62, 63, 64, 74, 75, 76, 77, 87, 88, 89, 90, 101, 102, 103, 115, 116, 127, 128, 129
b=14: none (except 2 to 13)
b=15: 116, 117, 118, 119, 130, 131, 132, 133, 134, 147, 148, 149
b=16: 122, 123, 124, 125, 126, 127, 140, 141, 142, 143, 156, 157, 158, 159, 173, 174, 175, 190, 191, 222, 223
b=17: 151, 152, 168, 169, 185, 186
b=18: 85, 86, 87, 88, 89, 191, 192, 193, 194, 195, 196, 197, 212, 213, 214, 215
b=19: 242, 243, 244, 245, 246
b=20: none
b=21: 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 162, 163, 164, 165, 166, 167, 183, 184, 185, 186, 187, 188, 206, 207, 208, 209, 227, 228, 229, 230, 248, 249, 250, 251, 270, 271, 272
b=22: 477, 478, 479, 480, 481, 482, 483
b=23: none
b=24: none
b=25: 271, 272, 273, 274, 296, 297, 298, 299, 322, 323, 324, 348, 349, 372, 373, 374
b=26: none
b=27: none
b=28: none
b=29: 431, 432, 433, 434, 459, 460, 461, 462, 463, 490, 491, 492, 546, 547, 548, 549, 550
b=30: none

Summus

I’m interested in digit-sums and in palindromic numbers. Looking at one, I found the other. It started like this: 9^2 = 81 and 9 = 8 + 1, so digitsum(9^1) = digitsum(9^2). I wondered how long such a sequence of powers could be (excluding powers of 10). I quickly found that the digit-sum of 468 is equal to the digit-sum of its square and cube:

digsum(468) = digsum(219024) = digsum(102503232)

But I couldn’t find any longer sequence, although plenty of other numbers are similar to 468:

digsum(585) = digsum(342225) = digsum(200201625)
digsum(4680) = digsum(21902400) = digsum(102503232000)
digsum(5850) = digsum(34222500) = digsum(200201625000)
digsum(5851) = digsum(34234201) = digsum(200304310051)
digsum(5868) = digsum(34433424) = digsum(202055332032)
digsum(28845) = digsum(832034025) = digsum(24000021451125) […]
digsum(589680) = digsum(347722502400) = digsum(205045005215232000)

What about other bases? First came this sequence:

digsum(2) = digsum(11) (base = 3) (highest power = 2)

Then these:

digsum(4) = digsum(22) = digsum(121) (b=7) (highest power = 3)
digsum(8) = digsum(44) = digsum(242) = digsum(1331) (b=15) (hp=4)
digsum([16]) = digsum(88) = digsum(484) = digsum(2662) = digsum(14641) (b=31) (hp=5)

The pattern continues (a number between square brackets represents a single digit in the base):

digsum([32]) = digsum([16][16]) = digsum(8[16]8) = digsum(4[12][12]4) = digsum(28[12]82) = digsum(15[10][10]51) (b=63) (hp=6)
digsum([64]) = digsum([32][32]) = digsum([16][32][16]) = digsum(8[24][24]8) = digsum(4[16][24][16]4) = digsum(2[10][20][20][10]2) = digsum(16[15][20][15]61) (b=127) (hp=7)
digsum([128]) = digsum([64][64]) = digsum([32][64][32]) = digsum([16][48][48][16]) = digsum(8[32][48][32]8) = digsum(4[20][40][40][20]4) = digsum(2[12][30][40][30][12]2) = digsum(17[21][35][35][21]71) (b=255) (hp=8)
digsum([256]) = digsum([128][128]) = digsum([64][128][64]) = digsum([32][96][96][32]) = digsum([16][64][96][64][16]) = digsum(8[40][80][80][40]8) = digsum(4[24][60][80][60][24]4) = digsum(2[14][42][70][70][42][14]2) = digsum(18[28][56][70][56][28]81) (b=511) (hp=9)

After this, I looked at sequences in which n(i) = n(i-1) + digitsum(n(i-1)). How long could digitsum(n(i)) be greater than or equal to digitsum(n(i-1))? In base 10, I found these sequences:

1 (digitsum=1) → 2 → 4 → 8 → 16 (sum=7) (count=4) (base=10)
9 → 18 (sum=9) → 27 (s=9) → 36 (s=9) → 45 (s=9) → 54 (s=9) → 63 (s=9) → 72 (s=9) → 81 (s=9) → 90 (s=9) → 99 (s=18) → 117 (s=9) (c=11) (b=10)
801 (s=9) → 810 (s=9) → 819 (s=18) → 837 (s=18) → 855 (s=18) → 873 (s=18) → 891 (s=18) → 909 (s=18) → 927 (s=18) → 945 (s=18) → 963 (s=18) → 981 (s=18) → 999 (s=27) → 1026 (s=9) (c=13)

Base 2 does better:

1 → 10 (s=1) → 11 (s=2) → 101 (s=2) → 111 (s=3) → 1010 (s=2) (c=5) (b=2)
16 = 10000 (s=1) → 10001 (s=2) → 10011 (s=3) → 10110 (s=3) → 11001 (s=3) → 11100 (s=3) → 11111 (s=5) → 100100 (s=2) (c=7) (b=2)
962 = 1111000010 (s=5) → 1111000111 (s=7) → 1111001110 (s=7) → 1111010101 (s=7) → 1111011100 (s=7) → 1111100011 (s=7) → 1111101010 (s=7) → 1111110001 (s=7) → 1111111000 (s=7) → 1111111111 (s=10) → 10000001001 (s=3) (c=10) (b=2)
524047 = 1111111111100001111 (s=15) → 1111111111100011110 (s=15) → 1111111111100101101 (s=15) → 1111111111100111100 (s=15) → 1111111111101001011 (s=15) → 1111111111101011010 (s=15) → 1111111111101101001(s=15) → 1111111111101111000 (s=15) → 1111111111110000111 (s=15) → 1111111111110010110 (s=15) → 1111111111110100101 (s=15) → 1111111111110110100 (s=15) → 1111111111111000011 (s=15) → 1111111111111010010 (s=15) → 1111111111111100001 (s=15) → 1111111111111110000 (s=15) → 1111111111111111111 (s=19) → 10000000000000010010 (s=3) (c=17) (b=2)

The best sequence I found in base 3 is shorter than in base 10, but there are more sequences:

1 → 2 → 11 (s=2) → 20 (s=2) → 22 (s=4) → 110 (s=2) (c=5) (b=3)
31 = 1011 (s=3) → 1021 (s=4) → 1102 (s=4) → 1120 (s=4) → 1201 (s=4) → 1212 (s=6) → 2002 (s=4) (c=6) (b=3)
54 = 2000 (s=2) → 2002 (s=4) → 2020 (s=4) → 2101 (s=4) → 2112 (s=6) → 2202 (s=6) → 2222 (s=8) → 10021(s=4) (c=7) (b=3)
432 = 121000 (s=4) → 121011 (s=6) → 121101 (s=6) → 121121 (s=8) → 121220 (s=8) → 122012 (s=8) → 122111 (s=8) → 122210 (s=8) → 200002 (s=4) (c=8) (b=3)
648 = 220000 (s=4) → 220011 (s=6) → 220101 (s=6) → 220121 (s=8) → 220220 (s=8) → 221012 (s=8) → 221111 (s=8) → 221210 (s=8) → 222002 (s=8) → 222101 (s=8) → 222200 (s=8) → 222222 (s=12) → 1000102 (s=4) (c=12) (b=3)

And what about sequences in which digitsum(n(i)) is always greater than digitsum(n(i-1))? Base 10 is disappointing:

1 → 2 → 4 → 8 → 16 (sum=7) (count=4) (base=10)
50 (s=5) → 55 (s=10) → 65 (s=11) → 76 (s=13) → 89 (s=17) → 106 (s=7) (c=5) (b=10)

Some other bases do better:

2 = 10 (s=1) → 11 (s=2) → 101 (s=2) (c=2) (b=2)
4 = 100 (s=1) → 101 (s=2) → 111 (s=3) → 1010 (s=2) (c=3) (b=2)
240 = 11110000 (s=4) → 11110100 (s=5) → 11111001 (s=6) → 11111111 (s=8) → 100000111 (s=4) (c=4) (b=2)

1 → 2 → 11 (s=2) (c=2) (b=3)
19 = 201 (s=3) → 211 (s=4) → 222 (s=6) → 1012 (s=4) (c=3) (b=3)
58999 = 2222221011 (s=15) → 2222221201 (s=16) → 2222222022 (s=18) → 2222222222 (s=20) → 10000000201 (s=4) (c=4) (b=3)

1 → 2 → 10 (s=1) (c=2) (b=4)
4 = 10 (s=1) → 11 (s=2) → 13 (s=4) → 23 (s=5) → 100 (s=1) (c=4) (b=4)
977 = 33101 (s=8) → 33121 (s=10) → 33203 (s=11) → 33232 (s=13) → 33323 (s=14) → 100021 (s=4) (c=5) (b=4)

1 → 2 → 4 → 13 (s=4) (c=3) (b=5)
105 = 410 (s=5) → 420 (s=6) → 431 (s=8) → 444 (s=12) → 1021 (s=4) (c=4) (b=5)

1 → 2 → 4 → 12 (s=3) (c=3) (b=6)
13 = 21 (s=3) → 24 (s=6) → 34 (s=7) → 45 (s=9) → 102 (s=3) (c=4) (b=6)
396 = 1500 (s=6) → 1510 (s=7) → 1521 (s=9) → 1534 (s=13) → 1555 (s=16) → 2023 (s=7) (c=5) (b=6)

1 → 2 → 4 → 11 (s=2) (c=3) (b=7)
121 = 232 (s=7) → 242 (s=8) → 253 (s=10) → 266 (s=14) → 316 (s=10) (c=4) (b=7)
205 = 412 (s=7) → 422 (s=8) → 433 (s=10) → 446 (s=14) → 466 (s=16) → 521 (s=8) (c=5) (b=7)

1 → 2 → 4 → 10 (s=1) (c=3) (b=8)
8 = 10 (s=1) → 11 (s=2) → 13 (s=4) → 17 (s=8) → 27 (s=9) → 40 (s=4) (c=5) (b=8)
323 = 503 (s=8) → 513 (s=9) → 524 (s=11) → 537 (s=15) → 556 (s=16) → 576 (s=18) → 620 (s=8) (c=6) (b=8)

1 → 2 → 4 → 8 → 17 (s=8) (c=4) (b=9)
6481 = 8801 (s=17) → 8820 (s=18) → 8840 (s=20) → 8862 (s=24) → 8888 (s=32) → 10034 (s=8) (c=5) (b=9)

1 → 2 → 4 → 8 → 16 (s=7) (c=4) (b=10)
50 (s=5) → 55 (s=10) → 65 (s=11) → 76 (s=13) → 89 (s=17) → 106 (s=7) (c=5) (b=10)

1 → 2 → 4 → 8 → 15 (s=6) (c=4) (b=11)
1013 = 841 (s=13) → 853 (s=16) → 868 (s=22) → 888 (s=24) → 8[10][10] (s=28) → 925 (s=16) (c=5) (b=11)

1 → 2 → 4 → 8 → 14 (s=5) (c=4) (b=12)
25 = 21 (s=3) → 24 (s=6) → 2[10] (s=12) → 3[10] (s=13) → 4[11] (s=15) → 62 (s=8) (c=5) (b=12)
1191 = 833 (s=14) → 845 (s=17) → 85[10] (s=23) → 879 (s=24) → 899 (s=26) → 8[11][11] (s=30) → 925 (s=16) (c=6) (b=12)

1 → 2 → 4 → 8 → 13 (s=4) (c=4) (b=13)
781 = 481 (s=13) → 491 (s=14) → 4[10]2 (s=16) → 4[11]5 (s=20) → 4[12][12] (s=28) → 521 (s=8) (c=5) (b=13)
19621 = 8[12]14 (s=25) → 8[12]33 (s=26) → 8[12]53 (s=28) → 8[12]75 (s=32) → 8[12]9[11] (s=40) → 8[12][12][12] (s=44) → 9034 (s=16) (c=6) (b=13)

1 → 2 → 4 → 8 → 12 (s=3) (c=4) (b=14)
72 = 52 (s=7) → 59 (s=14) → 69 (s=15) → 7[10] (s=17) → 8[13] (s=21) → [10]6 (s=16) (c=5) (b=14)
1275 = 671 (s=14) → 681 (s=15) → 692 (s=17) → 6[10]5 (s=21) → 6[11][12] (s=29) → 6[13][13] (s=32) → 723 (s=12) (c=6) (b=14)
19026 = 6[13]10 (s=20) → 6[13]26 (s=27) → 6[13]45 (s=28) → 6[13]65 (s=30) → 6[13]87 (s=34) → 6[13][10][13] (s=42) → 6[13][13][13] (s=45) → 7032 (s=12) (c=7) (b=14)

1 → 2 → 4 → 8 → 11 (s=2) (c=4) (b=15)
603 = 2[10]3 (s=15) → 2[11]3 (s=16) → 2[12]4 (s=18) → 2[13]7 (s=22) → 2[14][14] (s=30) → 31[14] (s=18) (c=5) (b=15)
1023 = 483 (s=15) → 493 (s=16) → 4[10]4 (s=18) → 4[11]7 (s=22) → 4[12][14] (s=30) → 4[14][14] (s=32) → 521 (s=8) (c=6) (b=15)
1891 = 861 (s=15) → 871 (s=16) → 882 (s=18) → 895 (s=22) → 8[10][12] (s=30) → 8[12][12] (s=32) → 8[14][14] (s=36) → 925 (s=16) (c=7) (b=15)

1 → 2 → 4 → 8 → 10 (s=1) (c=4) (b=16)
16 = 10 (s=1) → 11 (s=2) → 13 (s=4) → 17 (s=8) → 1[15] (s=16) → 2[15] (s=17) → 40 (s=4) (c=6) (b=16)
1396 = 574 (s=16) → 584 (s=17) → 595 (s=19) → 5[10]8 (s=23) → 5[11][15] (s=31) → 5[13][14] (s=32) → 5[15][14] (s=34) → 620 (s=8) (c=7) (b=16)
2131 = 853 (s=16) → 863 (s=17) → 874 (s=19) → 887 (s=23) → 89[14] (s=31) → 8[11][13] (s=32) → 8[13][13] (s=34) → 8[15][15] (s=38) → 925 (s=16) (c=8) (b=16)

1 → 2 → 4 → 8 → [16] (s=16) → 1[15] (s=16) (c=5) (b=17)

1 → 2 → 4 → 8 → [16] (s=16) → 1[14] (s=15) (c=5) (b=18)
5330 = [16]82 (s=26) → [16]9[10] (s=35) → [16][11]9 (s=36) → [16][13]9 (s=38) → [16][15][11] (s=42) → [16][17][17] (s=50) → [17]2[13] (s=32) (c=6) (b=18)

1 → 2 → 4 → 8 → [16] (s=16) → 1[13] (s=14) (c=5) (b=19)
116339 = [16][18]52 (s=41) → [16][18]75 (s=46) → [16][18]9[13] (s=56) → [16][18][12][12] (s=58) → [16][18][15][13] (s=62) → [16][18][18][18] (s=70) → [17]03[12] (s=32) (c=6) (b=19)

1 → 2 → 4 → 8 → [16] (s=16) → 1[12] (s=13) (c=5) (b=20)
100 = 50 (s=5) → 55 (s=10) → 5[15] (s=20) → 6[15] (s=21) → 7[16] (s=23) → 8[19] (s=27) → [10]6 (s=16) (c=6) (b=20)
135665 = [16][19]35 (s=43) → [16][19]58 (s=48) → [16][19]7[16] (s=58) → [16][19][10][14] (s=59) → [16][19][13][13] (s=61) → [16][19][16][14] (s=65) → [16][19][19][19] (s=73) → [17]03[12] (s=32) (c=7) (b=20)