Cody

# Problem 44637. Still more miles to go before I sleep

Solution 1529547

Submitted on 15 May 2018
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
r=12341;b=4; assert(isequal(miles2(r,b),659))

Error using str2num (line 35) Input must be a character vector or string scalar. Error in miles2 (line 16) str2num(dec2base(base2dec(r(1:ans-1),b)+1,b))*10^(length(r)-ans+1)-str2num(r); Error in Test1 (line 2) assert(isequal(miles2(r,b),659))

2   Fail
r=12341;b=2; assert(isequal(miles2(r,b),87659))

Error using str2num (line 35) Input must be a character vector or string scalar. Error in miles2 (line 16) str2num(dec2base(base2dec(r(1:ans-1),b)+1,b))*10^(length(r)-ans+1)-str2num(r); Error in Test2 (line 2) assert(isequal(miles2(r,b),87659))

3   Fail
r=12331;b=4; assert(isequal(miles2(r,b),0))

Error using str2num (line 35) Input must be a character vector or string scalar. Error in miles2 (line 16) str2num(dec2base(base2dec(r(1:ans-1),b)+1,b))*10^(length(r)-ans+1)-str2num(r); Error in Test3 (line 2) assert(isequal(miles2(r,b),0))

4   Fail
r=455555;b=5; assert(isequal(miles2(r,b),544445))

Error using str2num (line 35) Input must be a character vector or string scalar. Error in miles2 (line 16) str2num(dec2base(base2dec(r(1:ans-1),b)+1,b))*10^(length(r)-ans+1)-str2num(r); Error in Test4 (line 2) assert(isequal(miles2(r,b),544445))

5   Fail
r=23907515;b=5; assert(isequal(miles2(r,b),92485))

Error using str2num (line 35) Input must be a character vector or string scalar. Error in miles2 (line 16) str2num(dec2base(base2dec(r(1:ans-1),b)+1,b))*10^(length(r)-ans+1)-str2num(r); Error in Test5 (line 2) assert(isequal(miles2(r,b),92485))

6   Fail
r=23807515;b=8; assert(isequal(miles2(r,b),192485))

Error using str2num (line 35) Input must be a character vector or string scalar. Error in miles2 (line 16) str2num(dec2base(base2dec(r(1:ans-1),b)+1,b))*10^(length(r)-ans+1)-str2num(r); Error in Test6 (line 2) assert(isequal(miles2(r,b),192485))

7   Fail
s=zeros(1,10); for b=2:10 s(b)=miles2(123456789,b); end assert(isequal(sum(s),960219488))

Error using str2num (line 35) Input must be a character vector or string scalar. Error in miles2 (line 16) str2num(dec2base(base2dec(r(1:ans-1),b)+1,b))*10^(length(r)-ans+1)-str2num(r); Error in Test7 (line 3) s(b)=miles2(123456789,b);

8   Fail
s=zeros(200,10); for b=2:10 for r=1:200 s(r,b)=miles2(r,b); end end assert(isequal(sum(s(:)),96940))

Error using str2num (line 35) Input must be a character vector or string scalar. Error in miles2 (line 16) str2num(dec2base(base2dec(r(1:ans-1),b)+1,b))*10^(length(r)-ans+1)-str2num(r); Error in Test8 (line 4) s(r,b)=miles2(r,b);