R, 7575 68 bytes
- -7 bytes by rewriting
if
and digit extraction (pajonk)
\f=\(b){if`if`(b>1&all((K=b%%10^K=b%/%10^(X=1X=0:nchar(b))%/%10^(X-1)%%10)<2))b=f,f(sum(2^X/2*K2^X*K));b},b)
Attempt This Online!Attempt This Online!
A recursive function: the first if
-condition is checking whether the input is not 1 or 0; the second condition checks whether there are only the digits 0 or 1 in the generated on the fly K
vector. Then the function is called again, with the b
converted to its decimal form as the input. Outside ofOutside of if In the ifelse
b-clause b
is output (outputted ?).