# Counting Cards – I

Standard

You would have seen the bad consequences of “counting cards” in blackjack game in casinos in movies like Rain Man and 21. This method allows the player to play a perfect game so that the odds are in the player’s favour to win.

In this post, let’s first understand what is blackjack. Most parts have been shamelessly copied from http://www.bicyclecards.com/how-to-play/blackjack/ . You can consider this post to be a tl;dr. If not happy, consider SMMRY.

In the casino version, the house is the dealer. The dealer remains standing and the players are seated. The dealer is in charge of running all aspects of the game, from shuffling and dealing the cards to handling all bets. Between one and eight standard 52-card decks are shuffled together and the cards are dealt from a shoe (a box that allows the dealer to remove cards one at a time, face down, without actually holding one or more packs).  Each card has some value assigned to it. It is up to each individual player if an ace is worth 1 or 11. Face cards are 10 and any other card is its pip value.   A hand’s value is the sum of the card values. Each participant attempts to beat the dealer by getting a count as close to 21 as possible, without going over 21.

When all the players have placed their bets, the dealer gives one card face up to each player in rotation clockwise, and then one card face up to himself. Another round of cards is then dealt face up to each player, but the dealer takes his second card face down. Thus, each player except the dealer receives two cards face up, and the dealer receives one card face up and one card face down. If a player’s first two cards are an ace and a “ten-card” (a picture card or 10), giving him a count of 21 in two cards, this is a natural or “blackjack.”  If the dealer’s face-up card is a ten-card or an ace, he/she looks at his face-down card to see if the two cards make a natural. If the face-up card is not a ten-card or an ace, he/she does not look at the face-down card until it is the dealer’s turn to play.

The player to the left of the dealer goes first and must decide whether to “stand” (not ask for another card) or “hit” (ask for another card in an attempt to get closer to a count of 21, or even hit 21 exactly). Thus, a player may stand on the two cards originally dealt him, or he/she may ask the dealer for additional cards, one at a time until he/she either decides to stand on the total (if it is 21 or under) or goes “bust” (if it is over 21).  The dealer then turns to the next player to his left and serves him in the same manner.

When the dealer has served every player, his face-down card is turned up. If the total is 17 or more, he/she must stand. If the total is 16 or under, he/she must take a card. He/she must continue to take cards until the total is 17 or more, at which point the dealer must stand. If the dealer has an ace, and counting it as 11 would bring his total to 17 or more (but not over 21), he/she must count the ace as 11 and stand.

There are three special moves called splitting pairs, doubling down and insurance.

• Splitting pairs is possible if a player’s first two cards are of the same denomination, such as two jacks or two sixes. The player may choose to treat them as two separate hands when his/her turn comes around. The amount of his/her original bet then goes on one of the cards, and an equal amount must be placed as a bet on the other card.
• Doubling down is possible when the original two cards dealt total 9, 10, or 11. When the player’s turn comes, he/she places a bet equal to the original bet, i.e. doubling his/her bet, and the dealer gives him/her just one card, which is placed face down and is not turned up until the bets are settled at the end of the hand.
• Insurance is possible when the dealer’s face-up card is an ace.  Any of the players may make a side bet of up to half the original bet that the dealer’s face-down card is a ten-card, and thus a blackjack for the house.  Insurance is invariably not a good proposition for the player unless he/she is quite sure that there are an unusually high number of ten-cards still left undealt.

# Happy Birthday Ramanujam

Standard

Today is the 130th birthday of Srinivasa Ramanujam Iyengar.

I will discuss the easiest-to-follow work of Ramanujam, from G. H. Hardy’s Ramanujan: Twelve lectures on subjects suggested by his life and work.

A partition of $n$ is a division of $n$ into any number of positive integral parts. Thus, the sum of digits of 130 = 1+3+0=4 has 5 partitions:

$\displaystyle{4 = 3+1 = 2+2 = 2+1+1 = 1+1+1+1}$

The order in which the partitions are arranged is irrelevant, so we may think of them, as arranged in descending order. We denote the number of partitons of $n$ by $p(n)$; thus $p(4) = 5$. Also, by convention, we define $p(0) = 1$.

Very little was known about the arithmetical properties of $p(n)$; when Ramanujam started his investigations. Though we still don’t know when $p(n)$ is even or odd, there has been a lot of progress in this domain of research. For an overview, see the first section of Ken Ono’s “Distribution of the partition function modulo m” (it’s 17-year-old paper…)

Ramanujam was the first, and up to his death, the only, mathematician to discover the arithmetical properties of $p(n)$. His theorems were discovered by observing Percy MacMahon‘s table of $p(n)$ for the first 200 values of $n$. Ramanujan observed that the table indicated certain simple congruence properties of $p(n)$. In particular, the numbers of the partitions of numbers $5m+4, 7m+5$ and $11m+6$ are divisible by 5, 7 and 11 respectively, i.e.

• $p(5m+4) \equiv 0 \pmod{5}$
• $p(7m+5) \equiv 0 \pmod{7}$
• $p(11m+6) \equiv 0 \pmod{11}$

Hence, for example, for $n=130+1$ (Chinese way of calculating age) $p(131) \equiv 0 \pmod{7}$. And we can verify this using SageMath:

Now, to check its divisibility by 7, take the last digit of the number you’re testing and double it. Then, subtract this number from the rest of the remaining digits. If this new number is either 0 or if it’s a number that’s divisible by 7, then the original number is divisible by seven. [Derive it yourself!]

This process is lengthy but it converts the process of division by a simpler operation of subtraction.

Here, we have:

$5964539504 \rightarrow 596453942\rightarrow 59645390\rightarrow 5964539\rightarrow 596435\rightarrow 59633\rightarrow 5957\rightarrow 581\rightarrow 56 = 7\times 8$.

If you know how SageMath calculates the number of partitions, please let me know in the comments below.

# Childhood Maths – II

Standard

I found two documents that I was very proud of as a child. Both were the result of trying to understand the kind of things Ramanujan did in free time, a result of the little AMTI books I read as a child. I will share the second document in this post and the other one was in the previous post.

Following document was created in MS Word on my old Windows XP desktop. The calculations were done using some Microsoft advanced calculator:

I was not happy with the result though since the pattern didn’t continue which was supposed to continue according to Ramanujan.

# Childhood Maths – I

Standard

I found two documents that I was very proud of as a child. Both were the result of trying to understand the kind of things Ramanujan did in free time, a result of the little AMTI books I read as a child. I will share one document in this post and another one in the next since both are not related to each other in substance.

Following is a calculation table generated using some spreadsheet software:

As you can see, it was motivated by the famous Taxicab number story.

# A complex log inequality

Standard

Let $z$ be a complex number. The power series expansion of $\text{log}(1+z)$ about $z_0=0$ is given by

$\displaystyle{\text{log}(1+z) = \sum_{n=1}^\infty (-1)^{n-1}\frac{z^n}{n} = z-\frac{z^2}{2} + \ldots}$

which has radius of convergence 1. If $|z|<1$ then

$\displaystyle{\left|1-\frac{\log(1+z)}{z}\right|\leq \frac{|z|}{2(1-|z|)}}$

If we further assume $|z|<1/2$ then

$\displaystyle{\left|1-\frac{\log(1+z)}{z}\right|\leq \frac{1}{2}}$

This gives,

$\displaystyle{\frac{|z|}{2}\leq |\log(1+z)|\leq \frac{3|z|}{2}, \quad |z|<\frac{1}{2}}$

I just wanted to see how this inequality will appear graphically, so here are the plots made using SageMath 7.5.1 (by fixing the real part of z to zero and varying the imaginary part till 1/2)

i = CDF.0; p1 = plot(lambda t: abs(log(1+t*i)), 0, 0.5, rgbcolor=(0.8,0,0),legend_label=’ $|log(1+z)|$’, thickness=2); p2 = plot(lambda t: abs((t*i)/2), 0, 0.5, rgbcolor=(0,0.8,0), legend_label=’$|z|/2$’, thickness=2); p3 = plot(lambda t: abs(3*(t*i)/2), 0, 0.5, rgbcolor=(0,0,0.8), legend_label=’ $3|z|/2$’, thickness=2); p1+p2+p3

I tried to get a graph where this inequlaity fails (i.e. the plots intersect), but failed to do so.