Come now, and take my hand

I want to dance with cand-

or and rigor,

so much splendor.

We'll spin the night away

For joy is here to stay

Let the stars inspire us

Light the fire within

Now spin, spin, step, and spin

Let all of your troubles sweat away

And let your hands find their

way onto my shoulders and then my hips

Then let your face make its way to my lips.

I can feel your trepidation --- your heart is

beating through your shirt. But if you fall

There's nothing to miss. We'll wake up again

and the sun will shine again.

# Tag: fun

## Six in Line

Hey man, fuck you, too

I have six in line to screw

That’s more than you do

The Learn Fun Facts blog posted an interesting fun fact about strings. Law’s fun fact is that 8+9+1+89+91=198. Why is this a fun fact? Because the left side of that equation takes every sequence of digits from 891 (except the whole thing) and adds them together to get the digits in reverse order. Contrary to Law’s statement, though, this is not the only three digit number that does this. At the end of the post, he challenges us to figure out if this happens for any five digit combinations. He suggests using a computer to do it, but I wanted to see if basic algebra and a little cleverness could do it. So first I set out on the 3-digit problem to see how the process works.

## The 3-Digit Problem

So, what do we know to start with? We’re working with three digits. Let’s call them x, y, and z. So for 891, x=8, y=9, and z=1. To make them match up with 891, we note that 100x+10y+z=891. To reverse the digits, just reverse the coefficients: x+10y+100z=198.

Now, to figure out that it’s 8, 9, and 1, we can’t assume that from the start. But we are working on making the “substrings” (the sequences of digits within the number) equal x+10y+100z. How do we express the sum of substrings? x+y+z+10x+y+10y+z. If we clean that up a bit, we have 11x+12y+2z. Thus we are trying to find out when this is true:

x+10y+100z=11x+12y+2z

Well, if you just have three variables and one equation, you’re going to get a lot of possible solution. But wait, x, y, and z all have to be single digits. So we know that 0≤x9, 0≤y≤9, and 0≤z≤9. And since we want a three digit number, 1≤x. Since we want to be able to flip it into another three digit number, 1≤z. And since they’re digits, we know that they’re all whole numbers. Okay, now we have some stuff to work with.

If we take our equation from before and subtract all the stuff on the right from both sides we get:

10x+2y-98z=0

Then divide everything by 2:

5x+y-49z=0

We want to isolate one variable to work with, and that z is being subtracted right now, so let’s try moving it back to the right:

5x+y=49z

Well that’s quite the disparity in coefficients! And here’s where the magic is. Since 1≤z, the smallest thing 49z can be is 49. Since we know 1≤x≤9, we also know 5≤x≤45. And since y≤9, the biggest thing 5x+y can be is 54. But since 5x+y=49z, that means the biggest thing 49z can be is 54. And since z is a whole number, we can see that 49*2=98 which is too big. So z must be 1.

If we plug z=1 into our equation, we have:

5x+y=49

Now we’re down to two variables. If we subtract y from both sides we’ll be able to get some nice bounds on 5x, so let’s do that:

5x=49-y

Since 1≤y≤9, 40≤49-y≤48. And since 5x=49-y, 40≤5x≤48. But we know x has to be a whole number. So the only options for x are 8 and 9. So if we plug in either option:

(5*8 or 5*9)=49-y

Which is to say

(40 or 45)=49-y

So if we subtract the two options from each side:

0=(4 or 9)-y

Add y to each side:

y=4 or 9

And notice that the y=4 goes with x=9, and y=9 goes with x=8. So now all three variables are solved for. Either x=8, y=9, and z=1, or x=9, y=4, and z=1. These correspond to 891 and 941.

So remember that the fun thing about 891 is that 8+9+1+89+91=198. So now let’s look at 941. We can see 9+4+1+94+41=149. Neat! So there are in fact two three-digit numbers with this property.

## Can it be done without the reversal?

On the Learn Fun Facts post, Jack Shalom asks in a comment whether there are any three-digit numbers whose substrings add up to the number itself. The answer is no, and here is the proof.

We start again with 1≤x≤9, 0≤y9, and 0≤z≤9. (We’re not reversing it, so z being 0 would be fine.) Now the equation we want to figure out what makes true is:

100x+10y+z=x+y+z+10x+y+10y+z

Which simplifies to:

100x+10y+z=11z+12y+2z

If we shuffle the ys and zs to the right and xs to the left we get:

89x=2y+z

Since 1≤x, 89≤89x. But since y≤9 and z≤9, the biggest thing 2y+z can be is 2*9+9=27. So this system has no solution.

## The 5-Digit Problem

The 5-digit version is obviously trickier. Because it’s so cumbersome to write and read the process of defining everything again, I’ll skip to the equation. This time I use a through e as digits for the number abcde since they’re easier to tell apart than some of the later letters.:

1111a+1222b+233c+34d+4e=a+10b+100c+1000d+10000e

Which can be rewritten as:

1110a+1212b+133c-966d-9996e=0

Solving this would not be super interesting. First you would isolate e, find out it has to be 1 or 2, and continue from there in much the same way was with the 3-digit problem. So I won’t spend more time on that. However, the general case could be fun. Where did 1111, 1222, 233, 34, and 4 come from? Well, each digit gets a 1 from the single digit strings. Then the first four get a ten from the double digit strings and the last four get a one. Then the first three get a 100 from the triple digit strings, the second through fourth get a ten, and the last three get a one. Finally, the first two get a 1000 for the four digit strings, the second and third get a 100, the third and fourth get a 10, and the last two get a 1. So a got one of each, b got to double up on everything except hundreds, c was excluded from getting a thousand but got two hundreds, three tens, and three ones, and so on.

This pattern could rather easily be adapted to any length of number. I hypothesize that with such generated numbers there’s some way to generate the solutions with single digits, but that will take more work.