2 deleted 122 characters in body
source | link

MATLAB, 100100 89 bytes

A different approach (using implicit expansion to create a subtraction matrix) reduces 11 bytes:

function f(a,b);c = mod(a-b+5,10)-5;a,mod(a-cumsum(repelem(eye(3).*sign(c),abs(c),1)),10)

[Original 100 byte solution]

function f(a,b);c=mod(a-b+5,10)-5;a,for n=1:3;for r=1:abs(c(n));a(n)=mod(a(n)-sign(c(n)),10),end;end

Commented:

function f(a,b)
    c = mod(a-b+5,10)-5; % Get the number of required turns, and direction
    a                    % Display initial a
    for n = 1:3          % Loop over digits
        for r = 1:abs(c(n))   % Loop over required turns for this digit
            a(n) = mod(a(n)-sign(c(n)),10) % Update digit and display a
        end
    end

CalledBoth called by passing the inputs as 3-element arrays, e.g. f([9 1 1], [2 3 2])

MATLAB, 100 bytes

function f(a,b);c=mod(a-b+5,10)-5;a,for n=1:3;for r=1:abs(c(n));a(n)=mod(a(n)-sign(c(n)),10),end;end

Commented:

function f(a,b)
    c = mod(a-b+5,10)-5; % Get the number of required turns, and direction
    a                    % Display initial a
    for n = 1:3          % Loop over digits
        for r = 1:abs(c(n))   % Loop over required turns for this digit
            a(n) = mod(a(n)-sign(c(n)),10) % Update digit and display a
        end
    end

Called by passing the inputs as 3-element arrays, e.g. f([9 1 1], [2 3 2])

MATLAB, 100 89 bytes

A different approach (using implicit expansion to create a subtraction matrix) reduces 11 bytes:

function f(a,b);c = mod(a-b+5,10)-5;a,mod(a-cumsum(repelem(eye(3).*sign(c),abs(c),1)),10)

[Original 100 byte solution]

function f(a,b);c=mod(a-b+5,10)-5;a,for n=1:3;for r=1:abs(c(n));a(n)=mod(a(n)-sign(c(n)),10),end;end

Both called by passing the inputs as 3-element arrays, e.g. f([9 1 1], [2 3 2])

1
source | link

MATLAB, 100 bytes

function f(a,b);c=mod(a-b+5,10)-5;a,for n=1:3;for r=1:abs(c(n));a(n)=mod(a(n)-sign(c(n)),10),end;end

Commented:

function f(a,b)
    c = mod(a-b+5,10)-5; % Get the number of required turns, and direction
    a                    % Display initial a
    for n = 1:3          % Loop over digits
        for r = 1:abs(c(n))   % Loop over required turns for this digit
            a(n) = mod(a(n)-sign(c(n)),10) % Update digit and display a
        end
    end

Called by passing the inputs as 3-element arrays, e.g. f([9 1 1], [2 3 2])