MATL, 14 bytes
1&)"V@VX&nv@]x
Thanks @LuisMendo for saving a byte. Explanation:
1&) % Implicitly take input.% 'Pop' the first item from the input and push it on the stack.
" ] % Main 'for' loop, to loop over the rest of the input.
V % Stringify previous (or first) iten from the input.
@V % Push current number, convert to string
X& % Intersect with stringified number already on the stack.
nnv % Count the size of the intersection, and add it to the existing list of sizes.
@ % Push the current number again for the intersection in the next loop.
x % Remove the number pushed by the last loop.
% Else the program would end with the result on the second instead of the first position in the stack
MATL, 14 bytes
1&)"V@VX&nv@]x
Thanks @LuisMendo for saving a byte. Explanation:
1&) % Implicitly take input. 'Pop' the first item from the input on the stack.
" ] % Main 'for' loop, to loop over the rest of the input.
V % Stringify previous (or first) iten from the input.
@V % Push current number, convert to string
X& % Intersect with stringified number already on the stack.
n % Count the size of the intersection
@ % Push the current number again for the intersection in the next loop.
MATL, 14 bytes
1&)"V@VX&nv@]x
Thanks @LuisMendo for saving a byte. Explanation:
1&) % 'Pop' the first item from the input and push it on the stack.
" ] % Main 'for' loop, to loop over the rest of the input.
V % Stringify previous (or first) iten from the input.
@V % Push current number, convert to string
X& % Intersect with stringified number already on the stack.
nv % Count the size of the intersection, and add it to the existing list of sizes.
@ % Push the current number again for the intersection in the next loop.
x % Remove the number pushed by the last loop.
% Else the program would end with the result on the second instead of the first position in the stack
MATL, 1514 bytes
11&)VG"@VX&nv@V]x"V@VX&nv@]x
I've added a simple 'if/else' statement in the TIO link,Thanks @LuisMendo for those who don't believe thatsaving a single 0 makes an array falsey in MATLbyte.
Explanation:
1&) G" % Implicitly ]take %input. Main'Pop' 'for'the loop,first toitem loopfrom overthe input G
on the stack.
@V " ] % PushMain current'for' numberloop, convert to stringloop over the rest of the input.
V X& % IntersectStringify withprevious stringified(or numberfirst) alreadyiten onfrom the stackinput.
@V n % CountPush thecurrent sizenumber, ofconvert theto intersection
string
X& v@ % PushIntersect thewith stringified number for the intersectionalready inon the next loopstack.
1)V n % ForCount the firstsize iteration,of the first element ofintersection
the input is stringified
@ % Push the current number again %for (guaranteedthe notintersection toin havethe annext emptyloop. intersection)
MATL, 15 bytes
1)VG"@VX&nv@V]x
I've added a simple 'if/else' statement in the TIO link, for those who don't believe that a single 0 makes an array falsey in MATL.
Explanation:
G" ] % Main 'for' loop, to loop over input G
@V % Push current number, convert to string
X& % Intersect with stringified number already on the stack.
n % Count the size of the intersection
v@ % Push the stringified number for the intersection in the next loop.
1)V % For the first iteration, the first element of the input is stringified
% (guaranteed not to have an empty intersection)
MATL, 14 bytes
1&)"V@VX&nv@]x
Thanks @LuisMendo for saving a byte. Explanation:
1&) % Implicitly take input. 'Pop' the first item from the input on the stack.
" ] % Main 'for' loop, to loop over the rest of the input.
V % Stringify previous (or first) iten from the input.
@V % Push current number, convert to string
X& % Intersect with stringified number already on the stack.
n % Count the size of the intersection
@ % Push the current number again for the intersection in the next loop.
MATL, 15 bytes
1)VG"@VX&nv@V]x
I've added a simple 'if/else' statement in the TIO link, for those who don't believe that a single 0 makes an array falsey in MATL.
Explanation:
G" ] % Main 'for' loop, to loop over input G
@V % Push current number, convert to string
X& % Intersect with stringified number already on the stack.
n % Count the size of the intersection
v@ % Push the stringified number for the intersection in the next loop.
1)V % For the first iteration, the first element of the input is stringified
% (guaranteed not to have an empty intersection)