Balanced number (source code)

= Balanced number

A <balanced number> is a <positive integer> whose first $\lceil k/2\rceil$ <decimal digits> have the same <digit sum> as its last $\lceil k/2\rceil$ <decimal digits>, where $k$ is the number of <numerical digits>. For odd $k$, the middle <numerical digit> appears on both sides and cancels, so only the equally long outer halves need to be compared.

For example, $123006$ is balanced because $1+2+3=0+0+6$. It is not a <palindromic number>: equality of two <digit sums> does not require reversed digits. At odd length, $12321$ is balanced because the outer pairs $12$ and $21$ both sum to three; its middle digit is irrelevant to the equality.

<Digit dynamic programming> can tabulate counts and value sums of fixed-length halves indexed by <digit sum>, then match equal indices. The first half must begin with a nonzero <numerical digit>, while the last half may contain initial zeros, as in $123006$. Preserving the half length is essential when assembling the positional value.