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
Sanchises
- 9.5k
- 1
- 37
- 63