Cody

Problem 47. Extract leading non-zero digit

Solution 3263018

Submitted on 18 Oct 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Fail
x = [100 23 -34 0.005 -0.466664 -0.555 1 134534]; y_correct = [1 2 3 5 4 5 1 1]; assert(isequal(leadingDigit(x),y_correct))

Error using ^ (line 51) Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'. Error in leadingDigit (line 2) y = floor(10^(-(log10(x))).*x) Error in Test1 (line 3) assert(isequal(leadingDigit(x),y_correct))

2   Fail
x = [57 -0.2 8913 -63 0.838127]; y_correct = [5 2 8 6 8]; assert(isequal(leadingDigit(x),y_correct))

Error using ^ (line 51) Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'. Error in leadingDigit (line 2) y = floor(10^(-(log10(x))).*x) Error in Test2 (line 3) assert(isequal(leadingDigit(x),y_correct))

3   Fail
x = [-0.4336 0.3426 3.5784 2.7694 -1.3499]; y_correct = [4 3 3 2 1]; assert(isequal(leadingDigit(x),y_correct))

Error using ^ (line 51) Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'. Error in leadingDigit (line 2) y = floor(10^(-(log10(x))).*x) Error in Test3 (line 3) assert(isequal(leadingDigit(x),y_correct))

4   Fail
x = [0.3000 -0.1 -0.00000002 0.5 0.002]; y_correct = [3 1 2 5 2]; assert(isequal(leadingDigit(x),y_correct))

Error using ^ (line 51) Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'. Error in leadingDigit (line 2) y = floor(10^(-(log10(x))).*x) Error in Test4 (line 3) assert(isequal(leadingDigit(x),y_correct))

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!