Cody

# Problem 44345. MATLAB Counter

Solution 1312519

Submitted on 24 Oct 2017 by Atnas
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   Pass
assessFunctionAbsence({'regexp','regexpi','regexprep','str2num'},'FileName','counter.m')

2   Pass
f = counter(0,1); assert(isequal(f(),0)) assert(isequal(f(),1)) assert(isequal(2,f())) assert(isequal(3,f()))

state = -1 state = 0 state2 = 0 state = 1 state2 = 1 state = 2 state2 = 2 state = 3 state2 = 3

3   Pass
f = counter(1,0); assert(isequal(f(),1)) assert(isequal(f(),1)) assert(isequal(1,f())) assert(isequal(1,f()))

state = 1 state = 1 state2 = 1 state = 1 state2 = 1 state = 1 state2 = 1 state = 1 state2 = 1

4   Pass
f = counter(10,2); assert(isequal(f(),10)) assert(isequal(f(),12)) assert(isequal(14,f())) assert(isequal(16,f()))

state = 8 state = 10 state2 = 10 state = 12 state2 = 12 state = 14 state2 = 14 state = 16 state2 = 16

5   Pass
f = counter(0,5); y_correct = [0, 5, 10, 15, 20, 55]; assert(isequal([f() f() f() f() f() f()+f()],y_correct))

state = -5 state = 0 state2 = 0 state = 5 state2 = 5 state = 10 state2 = 10 state = 15 state2 = 15 state = 20 state2 = 20 state = 25 state2 = 25 state = 30 state2 = 30

6   Pass
x0 = randi(10); b = randi(10); f = counter(x0,b); y_correct = x0 + (0:1000)*b; assert(isequal(arrayfun(@(n)f(),0:1000),y_correct))

state = -2 state = 8 state2 = 8 state = 18 state2 = 18 state = 28 state2 = 28 state = 38 state2 = 38 state = 48 state2 = 48 state = 58 state2 = 58 state = 68 state2 = 68 state = 78 state2 = 78 state = 88 state2 = 88 state = 98 state2 = 98 state = 108 state2 = 108 state = 118 state2 = 118 state = 128 state2 = 128 state = 138 state2 = 138 state = 148 state2 = 148 state = 158 state2 = 158 state = 168 state2 = 168 state = 178 state2 = 178 state = 188 state2 = 188 state = 198 state2 = 198 state = 208 state2 = 208 state = 218 state2 = 218 state = 228 state2 = 228 state = 238 state2 = 238 state = 248 state2 = 248 state = 258 state2 = 258 state = 268 state2 = 268 state = 278 state2 = 278 state = 288 state2 = 288 state = 298 state2 = 298 state = 308 state2 = 308 state = 318 state2 = 318 state = 328 state2 = 328 state = 338 state2 = 338 state = 348 state2 = 348 state = 358 state2 = 358 state = 368 state2 = 368 state = 378 state2 = 378 state = 388 state2 = 388 state = 398 state2 = 398 state = 408 state2 = 408 state = 418 state2 = 418 state = 428 state2 = 428 state = 438 state2 = 438 state = 448 state2 = 448 state = 458 state2 = 458 state = 468 state2 = 468 state = 478 state2 = 478 state = 488 state2 = 488 state = 498 state2 = 498 state = 508 state2 = 508 state = 518 state2 = 518 state = 528 state2 = 528 state = 538 state2 = 538 state = 548 state2 = 548 state = 558 state2 = 558 state = 568 state2 = 568 state = 578 state2 = 578 state = 588 state2 = 588 state = 598 state2 = 598 state = 608 state2 = 608 state = 618 state2 = 618 state = 628 state2 = 628 state = 638 state2 = 638 state = 648 state2 = 648 state = 658 state2 = 658 state = 668 state2 = 668 state = 678 state2 = 678 state = 688 state2 = 688 state = 698 state2 = 698 state = 708 state2 = 708 state = 718 state2 = 718 state = 728 state2 = 728 state = 738 state2 = 738 state = 748 state2 = 748 state = 758 state2 = 758 state = 768 state2 = 768 state = 778 state2 = 778 state = 788 state2 = 788 state = 798 state2 = 798 state = 808 state2 = 808 state = 818 state2 = 818 state = 828 state2 = 828 state = 838 state2 = 838 state = 848 state2 = 848 state = 858 state2 = 858 state = 868 state2 = 868 state = 878 state2 = 878 state = 888 state2 = 888 state = 898 state2 = 898 state = 908 state2 = 908 state = 918 state2 = 918 state = 928 state2 = 928 state = 938 state2 = 938 state = 948 state2 = 948 state = 958 state2 = 958 state = 968 state2 = 968 state = 978 state2 = 978 state = 988 state2 = 988 state = 998 state2 = 998 state = 1008 state2 = 1008 state = 1018 state2 = 1018 state = 1028 state2 = 1028 state = 1038 state2 = 1038 state = 1048 state2 = 1048 state = 1058 state2 = 1058 state = 1068 state2 = 1068 state = 1078 state2 = 1078 state = 1088 state2 = 1088 state = 1098 state2 = 1098 state = 1108 state2 = 1108 state = 1118 state2 = 1118 state = 1128 state2 = 1128 state = 1138 state2 = 1138 state = 1148 state2 = 1148 state = 1158 state2 = 1158 state = 1168 state2 = 1168 state = 1178 state2 = 1178 state = 1188 state2 = 1188 state = 1198 state2 = 1198 state = 1208 state2 = 1208 state = 1218 state2 = 1218 state = 1228 state2 = 1228 state = 1238 state2 = 1238 state = 1248 state2 = 1248 state = 1258 state2 = 1258 state = 1268 state2 = 1268 state = 1278 state2 = 1278 state = 1288 state2 = 1288 state = 1298 state2 = 1298 state = 1308 state2 = 1308 state = 1318 state2 = 1318 state = 1328 state2 = 1328 state = 1338 state2 = 1338 state = 1348 state2 = 1348 state = 1358 state2 = 1358 state = 1368 state2 = 1368 state = 1378 state2 = 1378 state = 1388 state2 = 1388 state = 1398 state2 = 1398 state = 1408 state2 = 1408 state = 1418 state2 = 1418 state = 1428 state2 = 1428 state = 1438 state2 = 1438 state = 1448 state2 = 1448 state = 1458 state2 = 1458 state = 1468 state2 = 1468 state = 1478 state2 = 1478 state = 1488 state2 = 1488 state = 1498 state2 = 1498 state = 1508 state2 = 1508 state = 1518 state2 = 1518 state = 1528 state2 = 1528 state = 1538 state2 = 1538 state = 1548 state2 = 1548 state = 1558 state2 = 1558 state = 1568 state2 = 1568 state = 1578 state2 = 1578 state = 1588 state2 = 1588 state = 1598 state2 = 1598 state = 1608 state2 = 1608 state = 1618 state2 = 1618 state = 1628 state2 = 1628 state = 1638 state2 = 1638 state = 1648 state2 = 1648 state = 1658 state2 = 1658 state = 1668 state2 = 1668 state = 1678 state2 = 1678 state = 1688 state2 = 1688 state = 1698 state2 = 1698 state = 1708 state2 = 1708 state = 1718 state2 = 1718 state = 1728 state2 = 1728 state = 1738 state2 = 1738 state = 1748 state2 = 1748 state = 1758 state2 = 1758 state = 1768 state2 = 1768 state = 1778 state2 = 1778 state = 1788 state2 = 1788 state = 1798 state2 = 1798 state = 1808 state2 = 1808 state = 1818 state2 = 1818 state = 1828 state2 = 1828 state = 1838 state2 = 1838 state = 1848 state2 = 1848 state = 1858 state2 = 1858 state = 1868 state2 = 1868 state = 1878 state2 = 1878 state = 1888 state2 = 1888 state = 1898 state2 = 1898 state = 1908 state2 = 1908 state = 1918 state2 = 1918 state = 1928 state2 = 1928 state = 1938 state2 = 1938 state = 1948 state2 = 1948 state = 1958 state2 = 1958 state = 1968 state2 = 1968 state = 1978 state2 = 1978 state = 1988 state2 = 1988 state = 1998 state2 = 1998 state = 2008 state2 = 2008 state = 2018 state2 = 2018 state = 2028 state2 = 2028 state = 2038 state2 = 2038 state = 2048 state2 = 2048 state = 2058 state2 = 2058 state = 2068 state2 = 2068 state = 2078 state2 = 2078 state = 2088 state2 = 2088 state = 2098 state2 = 2098 state = 2108 state2 = 2108 state = 2118 state2 = 2118 state = 2128 state2 = 2128 state = 2138 state2 = 2138 state = 2148 state2 = 2148 state = 2158 state2 = 2158 state = 2168 state2 = 2168 state = 2178 state2 = 2178 state = 2188 state2 = 2188 state = 2198 state2 = 2198 state = 2208 state2 = 2208 state = 2218 state2 = 2218 state = 2228 state2 = 2228 state = 2238 state2 = 2238 state = 2248 state2 = 2248 state = 2258 state2 = 2258 state = 2268 state2 = 2268 state = 2278 state2 = 2278 state = ...