I have been trying to solve this problem, it worked slow. I know there is a efficiently way. How do I get it?
The following is my code:
f[{a_, b_, nth_}] := Nest[#~Join~IntegerDigits@Tr[#[[-2 ;;]]] &, {a, b}, nth - 2][[nth]];
f /@ {{1, 1, 2}, {1, 1, 8}, {1, 4, 8}, {1, 5, 10^5 - 1}, {1, 7, 10^5}}
additional
Integer a,b in range 0 to 9,combine them to a string ab
Make the last and penultimate number plus then appendto ab
repeat 2.,the string can any infinitely expanding. Now we need know what is the nth number.
For example:
1,1 ==> 11235813471123...
1,2 ==> 12358134711235...
1,5 ==> 156112358134711...
f(1,1,2)=1
f(1,1,8)=3
f(1,4,8)=9
update
I have got a way, but I feel it's not neat.
f[{a_, b_, n_}] :=
Module[{li, pos, left, repeat},
li = NestWhile[#~Join~IntegerDigits@Tr[#[[-2 ;;]]] &, {a, b},
FreeQ[Partition[#[[;; -2]], 2, 1], #[[-2 ;;]]] &];
pos = Position[Partition[li, 2, 1], li[[-2 ;;]], 1, 1][[1, 1]];
{left, repeat} = {#[[;; pos - 1]], #[[pos ;; -3]]} &@li;
If[n <= Length[left], left[[n]],
repeat[[Mod[n - Length[left], Length[repeat], 1]]]]
];
f /@ {{1, 1, 2}, {1, 1, 8}, {1, 4, 8}, {1, 5, 10^8 - 1}, {1, 7, 10^8}}