$X = \{\{0,5\}, \{1,4\}, \{1,1,3\}, \{1,1,1,2\}, \{1,1,1,1,1\}, \{2,3\}, \{2,2,1\} \}$
$X$ is partition of 5 where only single digit numbers are allowed.
Observation:
Any number with digit sum 5 can be represented by permutation of one of the above sets stuffed with 0s.
Example:
$\begin{eqnarray*}
14 \rightarrow 10^040^0 \rightarrow 14:0,0\\
104 \rightarrow 10^{1}40^0 \rightarrow 14:1,0\\
10000000000004 \rightarrow 10^{12}40^0 \rightarrow 14:12,0\\
100040000000000000000 \rightarrow 10^{3}40^{16} \rightarrow 14:3,16
\end{eqnarray*}$
All these four numbers can be stored in a dictionary with 14 as key and list of number of zeros to stuff between each non-zero digits.
{
14: [
[0,0],
[1,0],
[12,0],
[3,16]
]
}
Space savings:
$log_{10}$ roughly computes length of a number in base 10. If you store a number N, as a string then $L \approx \log_{10}N$ bytes are required (assuming 1 byte per char).
But if we use representation of numbers given above then approximate number of bytes needed are $\approx \log_{10}L$. Reason for this is lots of zeros in the number.
$$space \ savings \approx 1 - \frac{log_{10} \ L}{L} = 1-\frac{log_{10}\ log_{10} \ N}{log_{10}\ N}$$
Python Code:
d = {}
def insert(n):
key, xs = '', []
for x in n:
if x is not '0':
key += x
xs += [0]
else:
xs[-1] += 1
if not key in d.keys():
d[key] = []
d[key] += [xs]