# Happy days alphametic

Every letter a decimal digit, different letters for different digits:

    HAPPY
HAPPY
HAPPY
+ DAYS
----------


Which digit does each letter represent?
(Please present the full analysis how these digits can be determined.)

Denote $C_i$ the carry over from the sum of the digits in column $i$ and $S_i$ be the sum of the digits in column $i$ plus $C_{i-1}$. $C_i$ is simply $S_i \div 10$ rounded down. Lastly, denot $D_i$ to be the ones digit of $S_i$. In other words, $D_i = S_i \mod 10$.

Since the sum of all the numbers is still a 5 digit number, we know that $H \in \{1,2,3\}$. If $H=3$, then $A=9$. But then in the 4th column you have 3 $A$s, which would mean $C_4 \ge 2$, making a six digit number. Therefore, $H \in \{1,2\}$.

This means, $A \ge 3$. Since $D \ne 0$, $A=3 \implies C_4=1$, which results in $A=4$. Thus, $A \ne 3$.

If $A=4$, then $C_4=1$ and $H=1$. Then $S_4=12+D+C_3$ and $D_4=H=1$. This can only happen if $D+C_3=9 \implies C_4=2$. Thus, $A \ne 4$.

If $A=6$, then $C_4=0$ and $H=2$, or $C_4=3$ and $H=1$. $S_4=18+D+C_3=H$. If $H=1$, then $D+C_3=13$, which only works if $C_3$ could be 4, but this is only possible when you are summing five or more numbers. Thus, $H=2$ and $C_4=0$. But $S_4 \gt 3 \times A = 18 \implies C_4 \gt 0$. Thus $A \ne 6$.

If $A=7$, then $C_4=1$ and $H=2$, or $C_4=4$ and $H=1$. Since $S_4=3\times 7+D+C_3=21+D+C_3$, we know that $C_4$ can only be 4 when $D+C_3 \ge 19$ (which can't happen), and is at least $2$. Thus, $C_4=1$ and $H=2$. But $S_4\ge3\times7=21 \implies C_4\ge2$. Thus $A \ne 7$.

If $A=8$, then $C_4=2$ and $H=2$. $S_4=3 \times 8 + D + C_3=24 + D +C_3$. We know that $D_4=H=2$ only works when $D+C_3=8 \implies C_4=3$. Thus, $A \ne 8$.

After all this, we know that $A \in \{5, 9\}$ and $H \in \{1, 2\}$.

### Assume $A=5$, so $H=1$

If $A=5$, $S_4=15+D+C_3$ and $D_4=H=1$. Thus, $D+C_3=6$ and $C_4=2$.

If $C_3=0$, then $P=1$, which is already taken by $H$. If $C_3 = 1$, then $S_4=3 \times 5 + D + C_3 = 15 + D + 1 = 16 + D$. We know that $D_4=H=1$ only works if $D=5$, which is already taken by $A$. We know that $C_3 \ne 4$ because the highest $S_3$ can be is when $P=9$ and $C_1=3$, which makes $S_3=35$.

Thus $C_3 \in \{2,3\}$ and $D \in \{4,3\}$.

Lets look at $S_3=3 \times P + 5 + C_2$ and $S_2=3 \times P + Y + C_1$.

If $P \in \{2,3,4\}$, then $C_3=1$. Thus, $P \ge 6$.

If $P=6$, then $S_2=18+Y+C_1$ and $D_2=5$. So $Y+C_1=7 \implies C_2=2$. Thus, $S_3=12+5+2=19 \implies E=9$ and $C_3=1$.

If $P=7$, then $S_2=21+Y+C_1$ and $D_2=5$. So $Y+C_1=4$. Thus, $Y \in \{2,3\}$. If $Y=2$, then $S_1=6+S$ and $D_1=D$. If $D=4$ then $S=7$ which is a contradiction. Thus, $S=6$ and $D=3$ and $C_3=3$. $S_3=21+5+C_2=26+C_2 \implies C_2=4$. This is impossible when $P=7$, so $Y=3$. Then $C_1=1$ and $S_1=9+S$ and $D_1=D \in \{3,4\}$. If $D=4$ then $S=3$.

If $P=8$, then $S_3=24+5+C_2=29+C_2$ and $C_3=3$ and $D=3$. From $S_2=24+Y+C_1$ and $D_2=5$, we know that $Y+C_1 \in \{1,11\}$. If $Y=0$, then $C_1=0$, and $Y \ne 1$ since that is already taken by $H$. Thus, $Y+C_1=11 \implies Y=9$ and $C_1=2$. But $S_1=27+S$ and $D_1=D=3 \implies S=6$ and $C_1=3$

If $P=9$, then $S_3=27+5+C_2=32+C_2$ and $C_3=3$ and $D=3$. From $S_2=27+Y+C_1$ and $D_2=5$, we know that $Y+C_1=8$. If $C_1=1$, then $Y=7$ and $C_1=2$. Thus, $C_1=2$ and $Y=6$. This makes $S=5$ which is already taken by $A$.

## Thus $A=9$ and $H=2$

$S_4=27+D+C_3 \implies D+C_3=5$ and $C_4=3$. Since $D \ne 2$, $C_3 \ne 3$. Any value of $P$ will result in $C_3 \ge 1$, so $C_3 \in \{1,2\}$ and $D \in \{4,3\}$.

If $P=8$, then $S_3=32+C_2 \implies C_3=3$.

If $P=7$, then $C_2 \ge 2 \implies S_3=29+C_2\ge31 \implies C_3=3$

If $P=1$, then $S_3=12+C_2 \implies C_3=1 \implies D=4$. $S_2=3+Y+C_1$ and $D_2=A=9 \implies Y+C_1=6$ and $C_2=0$. Thus $S_3=12$ so $D_3=E=2$ which is already taken.

If $P=3$, then $S_3=18+C_2$. If $C_2\ge2$, then $C_3=2$ and $D=3$, which is already taken by $P$. If $C_2=1$ then $D_3=E=9$ which is already taken. If $C_2=0$, then $S_2=9+Y+C1 \implies Y+C_1=0$. Thus, $Y=0$ and $S=D$, which is not allowed.

If $P=4$, then $S_3=21+C_2 \implies C_3=2 \implies D=3$. $S_2=12+Y+C_1 \implies Y+C_1=7$ so that $D_2=A=9$. But then $C_2=1$ and $D_3=2$, which is already taken by $H$.

If $P=5$, then $S_3=24+C_2 \implies C_3=2 \implies D=3$. $S_2=15+Y+C_1 \implies Y+C_1=4$ so that $D_2=A=9$. But then $C_2=1$ and $D_3=5$ which is already taken by $P$.

## Therefore $P=6$

From $S_2=18+Y+C_1$ and $D_2=A=9$, we know that $Y+C_1 \in \{1,11\}$. If $Y+C_1=11$, then $Y=8$ and $C_1=3$. But then $S_1=24+S$. No value of $S$ can make $C_1=3$ and $D\in \{4,3\}$. Therefore, $Y+C_1=1$, and $S_2=19$, so $C_2=1$. If $Y=0$, then $C_1=0$ as well, which is a contradiction, so $Y=1$.

This means that $S_3=18+9+C_2=28$, so $D_3=E=8$ and $C_3=2$. Thus, $D=3$.

Lastly, $S_1=3+S=D=3 \implies S=0$.

Full solution:

$$H=2$$ $$A=9$$ $$P=6$$ $$Y=1$$ $$E=8$$ $$D=3$$ $$S=0$$

The corresponding numbers are:

A = 9
D = 3
E = 8
H = 2
P = 6
S = 0
Y = 1

The summation then becomes:

29661
29661
29661
+ 3910
------
92893