Bytewise look-and-say sequence code-golf
The look-and-say sequence is a sequence which begins with 1, 11, 21, 1211, 111221, 312211
.
To get a term of the sequence from the previous, read the previous out literally:
312211 => one three, one one, two twos,two ones => 13112221
So the next term is 13112221
.
Given this javascript code (Node.js), which outputs the look-and-say sequence indefinitely (assuming it doesn't crash), delimited by newlines:
function nextTerm(x){
return x.replace(/(.)\1*/g,z=>z.length+z[0])
}
function printUpTo(x){
var str = '1';
for(var i = 0; i < x; i++){
console.log(str);str = nextTerm(str);
}
}
printUpTo(Infinity)
It will output a string that begins 1\n11\n21\n1211\n111221
etcetera. Your job is to write a function that takes a number as input and outputs that byte of the output string.
Rules
You may output a different character for newline instead of \n, e.g. # or something.
Scoring
Your program should be able to handle 100 million.
The first answer to handle 1e+18 correctly will receive a 100-rep bounty. This cannot be hard-coded.
Standard loopholes apply.
Test cases:
1 => \n
5 => 2
10 => 1
20 => 3
50 => 3
100 => 1
1000 => 1
100000 => 3
10000000 => 1
This is code-golf, so shortest bytes wins.