## Can I Get Your Digits! (Except for one of them)

I follow the blog “Math Jokes 4 Mathy Folks“.  A recent post gave a game/riddle you can play with kids or even post a set of questions on some social media site and play with your friends.  The post is “Can I Get Your Digits“.

So, here are the questions you can ask:

[Step-1] Pick a number with more than four digits (keep it secret).
[Step-2] Add the digits of the number together (keep it secret).
[Step-3] Subtract this sum from the original number (keep it secret).
[Step-4] From [Step-3] give me all the digits except for one of them (keep that digit secret).
[Step-5] I will ‘magically’ guess the missing (secret) digit!

The ‘magic-guess’ is: Add up the digits given to you and then add what ever number it takes to get to the nearest multiple of nine and that number is the missing digit.

So for example: the number 87694. When the digits are added you get 34.  When you subtract 36 from 87694 you get 87660.  Below is a table for each of the possible missing digits from number 87660.

Missing the ‘0’ … 8+7+6+6 = 27 (The missing digit is ZERO)
Missing the ‘6’ … 8+7+6+0 = 21 (The missing digit is SIX)
Missing the ‘7’ … 8+6+6+0 = 20 (The missing digit is SEVEN)
Missing the ‘8’ … 7+6+6+0 = 19 (The missing digit is EIGHT)

Now here is an explanation of why this always works.

The way numbers are represented is in what is called a ‘Place Value System’.  In this system a number can be thought of as a sum of the digits of the number times a power of 10 (for a base 10 number).  The power of 10 depends on the ‘Place’ of the digit.  The ‘least-significant’ digit (the on on the right end of a number) can be thought of as that digit times $10^{0}$.  The next ‘Place’ is called the 10’s place and can be thought of as that digit times $10^{1}$, with the next ‘Place’ being the 100’s place or the digit times $10^{2}$ and so forth.

So for example:

$87694\quad =\quad 8\times {10}^{4}+7\times {10}^{3}+6\times {10}^{2}+9\times {10}^{1}+4\times {10}^{0}$

And this representation is equivalent to the following one when you replace the powers of 10 with the corresponding addition problem:

$8\left( 1+9999 \right) +7\left( 1+999 \right) +6\left( 1+99 \right) +9\left( 1+9 \right) +4$

It is now clear how this ‘magic guess’ works. When you distribute each digit over the corresponding sum you get the following:

$8+8\left( 9999 \right) +7+7\left( 999 \right) +6+6\left( 99 \right) +9+9\left( 9 \right) +4$

Regrouping you get the following very suggestive formula:

$(8+7+6+9+4)\quad +\quad 8\left( 9999 \right) +7\left( 999 \right) +6\left( 99 \right) +9\left( 9 \right)$

This is clearly the sum of the digits of the original number plus another number that is clearly a multiple of nine:

$\sum { digits\_ of(87694) } \quad +\quad 9\left[ 8\left( 1111 \right) +7\left( 111 \right) +6\left( 11 \right) +9\left( 1 \right) \right]$

The main thing to realize here is that when you subtract $\sum { digits\_ of(87694) }$ from the original number you are left with a number that (whatever its actual digits are) is a multiple of nine.

Finally it is the case that any number that is a multiple of nine also has the property that the number resulting from summing its digits is also a multiple of nine. This final fact is what you use to find the missing digit. Leaving out a single digit will ‘disturb’ the sum so it is no longer a multiple of nine and you only need sum up what you are given and find that number that causes the sum to be a multiple of nine to deduce the missing digit.

Notice: When the dropped digit is either a ‘0’ or a ‘9’ your magic ‘guess’ should be: “You left out either a 9 or a 0.”

Notice: This explanation can be extended to an arbitrary number of digits and thus it would be a proof.

Notice: That a multiple of nine also has the properties that the sum of its digits is also a multiple of nine can be explained in exactly the same way as the explanation above goes. So assume some number is a multiple of nine:

$X\quad =\quad 9x$

Now write X as a sum of its digits with each one times its corresponding power of ten:

$X\quad =\quad \sum _{ i=0 }^{ n }{ { a }_{ i } } { 10 }^{ i }$

Notice that we can write each term of the sum as a digit of the the original number times the quantity $\left( 1+9\cdots 9 \right)$ where the symbol “$9\cdots 9$” is 9 or 99 or 999 or 9999 and so forth.

$X\quad =\quad { a }_{ 0 }+\sum _{ i=1 }^{ n }{ { a }_{ i } } \left( 1+9\cdots 9 \right)$

This way of writing the number makes it clear what happens when each digit is distributed over the its corresponding sum and the the sum regrouped so that the sum of the digits of the original number are distinct from the rest of the number.

$X\quad =\quad { a }_{ 0 }+\sum _{ i=1 }^{ n }{ { a }_{ i } } +\sum _{ i=1 }^{ n }{ { a }_{ i } } \left( 9\cdots 9 \right)$

Now it is clear that each term of the rightmost sum can be factored by the number nine giving the formula below. The symbol “$1\cdots 1$” is 1 or 11 or 111 or 1111 and so forth.

$X\quad =\quad { a }_{ 0 }+\sum _{ i=1 }^{ n }{ { a }_{ i } } +\quad 9\sum _{ i=1 }^{ n }{ { a }_{ i } } \left( 1\cdots 1 \right)$

Recalling that the original number is a multiple of nine we get the following:

$9x\quad =\quad { a }_{ 0 }+\sum _{ i=1 }^{ n }{ { a }_{ i } } +\quad 9\sum _{ i=1 }^{ n }{ { a }_{ i } } \left( 1\cdots 1 \right)$

Finally subtracting the rightmost sum from both sides of the formula and factoring out the number nine we get the following which does show that the sum of the digits of the original number is a multiple of nine.

$9\left[ x-\sum _{ i=1 }^{ n }{ { a }_{ i } } \left( 1\cdots 1 \right) \right] ={ a }_{ 0 }+\sum _{ i=1 }^{ n }{ { a }_{ i } } \quad$

## Fizz Buzz (Beep?)

I subscribe to a blog called Quora.  You can set filters on what sort of questions are presented. I’ve set them to show math, physics, and computer science posts.

Today I saw a post that asked if someone with an advanced degree in computer science could fail the “Fizz Buzz Test“.

I had no idea what this test was so I did a Google Search on the words “fizzbuzz test” and came up with a wikipedia page dedicated to the game which also mentions the test (here is the page).

After reading the article section named “Other Uses” and messing around with a python script today I can safely say I do fall into the category of someone who has used this game as a “Software Kata

Here is what I’ve done so far.  And, in my defense, I did start out with a VERY SIMPLE version of this game and it sort of “grew-like-topsy” to what you see below.

I’ve used the WordPress tags to embed the code below.  So this blog post not only talks about the Fizz Buzz Test but also gives a demonstration of how source code embedding works on WordPress.

# Fizz Buzz (beep) Script
import os

def sayIt( anIndex, aCount, phrase):
indexString = "The "+str(aCount)
if aCount >= 11 and aCount <= 20:
indexString += 'th'
elif aCount % 10 == 1:
indexString += 'st'
elif aCount % 10 == 2:
indexString += 'nd'
elif aCount % 10 == 3:
indexString += 'rd'
else:
indexString += 'th'
indexString += ' element is '+str(anIndex)+' and we say '+phrase
os.system("say " +indexString)

def findPhrase( index, fizzNumber, buzzNumber, beepNumber ):
newNumber = index
thePhrase = ''
if fizzNumber != 0:
while newNumber % fizzNumber == 0:
thePhrase += 'FIZZ '
newNumber = newNumber / fizzNumber
if buzzNumber != 0:
while newNumber % buzzNumber == 0:
thePhrase += 'BUZZ '
newNumber = newNumber / buzzNumber
if beepNumber != 0:
while newNumber % beepNumber == 0:
thePhrase += 'BEEP '
newNumber = newNumber / beepNumber
return thePhrase

def fizzBuzzBeep(maxCount, fizzNumber, buzzNumber, beepNumber):
count = 0
index = 1
while (count<maxCount):
aPhrase = findPhrase( index, fizzNumber, buzzNumber, beepNumber )
if len(aPhrase) != 0:
count +=1
print("{0:3d} - {1:3d} {2}".format(count, index, aPhrase))
sayIt( index, count, aPhrase)
index +=1

if __name__ == '__main__':
fizzBuzzBeep(100, 3, 5, 7)



## The Volume of A Pizza

We ordered ‘Mellow Mushroom‘ pizzas for supper last night and we still have about one pie left over in the frig, just waiting to be finished off.

Now: What is pizza? one way to say it is to assume the thickness of the pie is the value $'a'$ and the radius of the pie is the value $'z'$ then to say, “What is Pizza?” could be to ask, “What is the volume of a pizza?”

Thinking of a pizza as a very thin cylinder of height $'h'$ and radius $'r'$ we get.

[1] $V = \pi r^{2}h$

Substituting $'a'$ for the height $'h'$ and $'z'$ for the radius $'r'$ we get:

[2] $V = \pi z^{2}a$

Next  recall that the greek letter $\pi$ can be written in English as $Pi$ we get:

[3] $V = Pi z^{2}a$

Finally expanding the $z{2}$ to be $z z$ we get:

[4] $V = Pi z z a$

## Another Lottery Ticket

As you can see in the graphic below the numbers that were picked by the computer when I purchased the ticket did not match the numbers that were selected that evening.

So a question that occurred to me was: “How close did I get?” And one way to think about distances between two numbers is to subtract their values and take the absolute value of the result. So the distance between the number $2$ and the number $7$ would be $5$. Here is the formula:

$\lvert 2-7 \rvert = \sqrt{(2-7)^2} = \sqrt{(-5)^2} = \sqrt{25} = 5$

This is very easy to extend into higher dimensions. For example, if you go to two dimensions this becomes the pythagorean theorem as applied to two points in the plane. Here is the formula using the example of the points $(a,b) and (c,d)$

$dist( (a,b), (c,d) ) = \sqrt{(a-c)^2 + (b-d)^2}$

In the case of the lottery tickets we can think of a lottery ticket as a point in a six dimensional space, since the ticket has six numbers. This means that the distance between the ticket I purchased and the winning ticket is:

${\sqrt{(10-6)^2 + (13-8)^2 + (14-31)^2 + (22-46)^2 + (52-52)^2 + (11-29)^2 }}$

This expression simplifies to be $\sqrt{1230}$ which is about $35.1$, this means that I was pretty close when you consider the maximum distance between two sets of numbers in the lottery is ($125$). The maximum distance is computed by considering the distance between the two points $(1,2,3,4,5,1)$ and $(55,56,57,58,59,35)$ This type of distance is called the Euclidean Distance between two points..

## E to the ‘i’ Pie

I’ve seen the following before but it is so cool I have to write it down:

The derivation of the formula below is really cool but this post is not about the derivation but an application of the formula:

[1]  $e^{ix} =$ $\cos x + i\sin x$

If we let $x = \pi$ we get

[2] $e^{i\pi} =$ $\cos \pi + i\sin \pi$

Simplify this by recalling that $\cos \pi = -1$ and $\sin \pi = 0$ we get:

[3] $e^{i\pi} = -1$

This is all really straight forward.  Here is the cool part.  What if we let $x = \pi/2$ then we get:

[4]  $e^{i\pi/2} =$ $\cos \pi/2 + i\sin \pi/2$

Since $\cos \pi/2 = 0$ and $\sin \pi/2 = i$ then this simplifies to be

[5]  $e^{i\pi/2} = i$

Finally if we raise both sides of the equation to the $i$ power we get:

[6] ${(e^{i\pi/2}})^i = i^i$

Combining the exponents on the left and noting that $(i)(i) =$ $i^2$ and $i^2 = -1$ we get

[7] $e^{-\pi/2} = i^i$

or

[8] $\dfrac{1}{e^{\pi/2}} = i^i$

or

[9] $\dfrac{1}{\sqrt{e^\pi}} = i^i$

Since the left hand side no longer has $i = \sqrt{-1}$ then if $e^{\pi}$ is a real number then $i^i$ is also a real number!   And, it is a real number see, for example, the articles “http://en.wikipedia.org/wiki/Gelfond%27s_constant” and “http://en.wikipedia.org/wiki/Gelfond%E2%80%93Schneider_theorem

If you go to WolframAlpha.COM and enter the sting “evaluate $i^i$” it actually gives you a  number, marked as transcendental and it’s value is:

[10] $i^i =$ $0.207879576350761908546955 ...$

Finally I wrote this post after reading today “Saturday Morning Breakfast Cereal” cartoon.  WARNING: This day’s cartoon is most definitely N.S.F. (Not suitable for work!)

## A Mathematicians Lottery

I follow the Spiked Math Blog and I especially liked the ‘Mathematicians Lottery‘ post which relies on the divergence of the harmonic series for the payout of the prize to insure that the payout can be managed.

The Wikipedia page on the harmonic series is very well done and the demonstation that this series diverges using an improper integral reminded me of the proof that I first saw when I was taking third semester calculs back in 1972 (forty years ago). Here is how the payout goes and the proof that you can award an arbitrary large sum of money as prizes in the lottery and get away with it even if you suppose that every ticket is a winner. Here is how all that goes:

[1] $\sum_{n=1}^{\infty}\frac{1}{n}$

The idea is that payout works like this: You get $1.00 the first week then (1/2)($1.00) the second week then (1/3)($1.00) the third week and because this series is divergent its partial sum is eventually greater than any finite number (even$750,000,000,000,000 “750 trillion dollars”).

The key is that the harmonic series diverges very, very slowly. To see that the series diverges at all it is enough to notice that it is bounded (from below) by something else that you can show ‘goes-to-infinity’. The choice is the following integral:

[2] ${\int^{\infty}_1\frac{1}{n}\,dn}$

To see why the integral bounds the series from below this picture is a great help:

Since the area under the curve from 1 to infinity is strictly less than the sum of the areas of the rectangles then if we can show that the integral diverges then that will show that the series diverges. This is because each of the rectangles has base equal to 1 and height equal to 1/n and thus area equal to 1/n and the sum of them all is exactly the value of the infinite series.

When you actually perform the integration in [2] you get:

[3] ${\int^x_1\frac{1}{n}\,dn = ln(x)-ln(1)}$

To see why this integrates to ln(x) you think about the inverse function theorem and the fact that the derivative of exponential is itself and the inverse of the exponential is the lograthim.

[4] ${\frac{d}{dx}\left(e^x\right) = e^x}$

and

[5] if ${f(x) = e^x}$ then ${f^{-1}(x) = ln(x)}$

This also explains why $ln(x)$ is an increasing function and why it is a very, very slowly increasing function (since its inverse is a very very quickly increasing function). And all this says that:

[6] $\sum_{n=1}^{\infty}\frac{1}{n} > {\lim_{x\to\infty}\int^x_1\frac{1}{n}\,dn = \lim_{x\to\infty}ln(x) = \infty}$

So this settles it, the harmonic series is divergent and you can always exceed an arbitrary large by just picking a greater and greater partial sum. The question then comes up just how many years do you need to wait to collect 750 trillion dollars. This comes out to be:
[7] $ln(n) = \frac{(7.5)(10^{14})}{52}$ because there are 52 weeks in a year.

Now we just solve for n getting:

[8] $n = e^{\frac{(7.5)(10^{14})}{52}}$

I did visit Wolfram Alpha web site and entered the exponential and, of course, it is way beyond computation, but interestingly Wolfram Alpha displayed the following:

[9] $e^{\frac{(7.5)(10^{14})}{52}} = 10^{10^{10^{1.119224798480347}}}$

And this totally settles the matter as to whether or not it is OK award 750 trillion dollars to each ticket holder.

Original strip http://spikedmath.com/477.html

The “Shoes and Socks Rule” is all about ‘un-doing’ things. If you want to ‘un-do’ putting on your socks and shoes then you have to do things backward, first take your shoes off then take your socks off, which is just the opposite of how you got them on. Well this much is all clear.

The question is what does this have to do with the following formula:

[1]  (XY)-1 = Y-1 X-1

What it is trying to say is when you do that “Minus-One-Exponent-Thingy” you have to reverse the order.  And the “Minus-One-Exponent-Thingy”, well that really means “INVERSE FUNCTION”. In other words the function that ‘un-does’ the original one (it’s inverse).

The normal way to write this is to do it this way:

[2]  (f o g)-1(x) = (g-1 o f-1)(x)

Another way to write (f o g)(x) is to say f(g(x)) so the above becomes:

[3]  f(g(x))-1 = g-1(f-1(x))

And the proof is really cool see:

The basis of the proof is that you only need to show that one function undoes a second function and that second function undoes the first function to prove that the two functions are inverses of each other.  The rest of the proof relies on the fact that function composition is associative (you can re-group it) and that a function composed with its own inverse gives the ‘identity-function’ (i.e. the do-nothing function) and the identity function composed with anything just gives back that anything since it does nothing.

So here is how that would work: the original function is:

[4]  (f o g)(x)

And, the inverse function of that — we want it to turn out to be:

[5]  (g-1 o f-1)(x)

So, to prove this then we think what does a function do?  It takes elements from a set (let’s call it set X) to another set (let’s call it set Y).  The inverse of the function will take elements of the set Y back to the original set X.  Also if you take a function and then apply its inverse the inverse function will UN-DO what the function does. Another way to say this is to say that it leaves things alone.

Or you could say if the combination of a function and another function LEAVES the input set ALONE and the combination of the second function with the first function also leaves the the input set ALONE then the two functions are INVERSES of each other. In symbolic notation this is:

if
[6]  (p o q)(x) = x
and
[7]  (q o p)(x) = x
then
[8]  p(x) and q(x) are inverse functions of each other.

For the proof we are working on we have to show the following two things (here we know f(x)1 and f(x) are already inverses of each other and that g1(x) and g(x) are inverses of each other:

[9]    ((f o g) o (g-1 o f-1))(x) = x
[10]  ((g-1 o f-1) o (f o g))(x) = x

Here is where the fact that function composition being associative comes in.  Notice that if we re-group the parenthesis in [9] the middle two functions turn in to the ‘do-nothing’ function call it “I” for “identity” so we get:

[10]    (f o I o f-1)(x) = x

And if we notice that composing a function with the “I” or “identity” function just gives us the same function then that “I” in the middle just drops out giving us:

[11]    (f o  f-1)(x) = x

And for sure statement [11] is true because that is just the definition of the action of a function and it’s inverse.

Since you can do the same thing to statement [10] this shows that both statement [9] and statement [10] are true so it is the case that statement [2] is true.

Showing that function composition is associative would be the final thing to show.  (Well that and showing that a function composed with the “identity” function is the same as just the function itself.)