###GolfScript, 50 characters###
GolfScript, 50 characters
{[[\].zip{1/~=},,\{$}/{1$?.)!!{)>0}*)},,\;1$-]}:M;
A similar solution to chron's answer written in GolfScript. Input must be provided as two strings on the stack, the result will be the array [A B]
.
"1254" "1342" M p # => [1 2]
"1234" "1111" M p # => [1 0]
"5441" "1234" M p # => [0 2]
"5441" "4531" M p # => [1 2]
"5441" "4441" M p # => [3 0]
"5441" "5441" M p # => [4 0]