Normal numbers in base 10 are those for which, in the base 10 decimal expansion, you can find every natural number. Champernowne's number is a very simple example of this where it is simply written as:
0.12345678910111213...etc.
I thought that it might be interesting to see if one could write a much shorter Normal Number but using a similar procedure to Champernowne. I haven't seen this done anywhere.
For example, in the above expression, you don't need to include the 12 explicitly as it's already there at the beginning. You could write
0.12345678910113 which now includes 11, 12 and 13.
I wanted to write some Mathematica code which generated such a Normal Number in as short a way as possible. This is what I've come up with, but I wonder if there may be a better way.
isitthere[seq_, n_] := SequencePosition[seq, IntegerDigits[n]]
addtoseq[seq_, n_] := Module[{},
id = IntegerDigits[n];
len = Length[id];
For[i = 1, i < len, i++,
If[seq[[i - len ;;]] == id[[;; -i - 1]],
Return[ Join[seq, id[[-i ;;]]]]]
];
Return[ Join[seq, id]]
]
start = {1};
For[m = 1, m <= 200, m++,
If[isitthere[start, m] === {}, start = addtoseq[start, m]]
]
N[FromDigits[start]/10^Length[start], Length[start]]
It gives the right answer:
0.12345678910113141516171819202122425262728293032335363738394043446474\
8495054557585960656686970767798087889099100102103104105106107108109110
but it feels a little clunky. Is there a purely functional way to do this?