Cody

Solution 1957962

Submitted on 3 Oct 2019 by Earnest
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()))

out = 0 numInvoked = 1 out = 1 numInvoked = 2 out = 2 numInvoked = 3 out = 3 numInvoked = 4

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

out = 1 numInvoked = 1 out = 1 numInvoked = 2 out = 1 numInvoked = 3 out = 1 numInvoked = 4

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

out = 10 numInvoked = 1 out = 12 numInvoked = 2 out = 14 numInvoked = 3 out = 16 numInvoked = 4

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))

out = 0 numInvoked = 1 out = 5 numInvoked = 2 out = 10 numInvoked = 3 out = 15 numInvoked = 4 out = 20 numInvoked = 5 out = 25 numInvoked = 6 out = 30 numInvoked = 7

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))

out = 2 numInvoked = 1 out = 3 numInvoked = 2 out = 4 numInvoked = 3 out = 5 numInvoked = 4 out = 6 numInvoked = 5 out = 7 numInvoked = 6 out = 8 numInvoked = 7 out = 9 numInvoked = 8 out = 10 numInvoked = 9 out = 11 numInvoked = 10 out = 12 numInvoked = 11 out = 13 numInvoked = 12 out = 14 numInvoked = 13 out = 15 numInvoked = 14 out = 16 numInvoked = 15 out = 17 numInvoked = 16 out = 18 numInvoked = 17 out = 19 numInvoked = 18 out = 20 numInvoked = 19 out = 21 numInvoked = 20 out = 22 numInvoked = 21 out = 23 numInvoked = 22 out = 24 numInvoked = 23 out = 25 numInvoked = 24 out = 26 numInvoked = 25 out = 27 numInvoked = 26 out = 28 numInvoked = 27 out = 29 numInvoked = 28 out = 30 numInvoked = 29 out = 31 numInvoked = 30 out = 32 numInvoked = 31 out = 33 numInvoked = 32 out = 34 numInvoked = 33 out = 35 numInvoked = 34 out = 36 numInvoked = 35 out = 37 numInvoked = 36 out = 38 numInvoked = 37 out = 39 numInvoked = 38 out = 40 numInvoked = 39 out = 41 numInvoked = 40 out = 42 numInvoked = 41 out = 43 numInvoked = 42 out = 44 numInvoked = 43 out = 45 numInvoked = 44 out = 46 numInvoked = 45 out = 47 numInvoked = 46 out = 48 numInvoked = 47 out = 49 numInvoked = 48 out = 50 numInvoked = 49 out = 51 numInvoked = 50 out = 52 numInvoked = 51 out = 53 numInvoked = 52 out = 54 numInvoked = 53 out = 55 numInvoked = 54 out = 56 numInvoked = 55 out = 57 numInvoked = 56 out = 58 numInvoked = 57 out = 59 numInvoked = 58 out = 60 numInvoked = 59 out = 61 numInvoked = 60 out = 62 numInvoked = 61 out = 63 numInvoked = 62 out = 64 numInvoked = 63 out = 65 numInvoked = 64 out = 66 numInvoked = 65 out = 67 numInvoked = 66 out = 68 numInvoked = 67 out = 69 numInvoked = 68 out = 70 numInvoked = 69 out = 71 numInvoked = 70 out = 72 numInvoked = 71 out = 73 numInvoked = 72 out = 74 numInvoked = 73 out = 75 numInvoked = 74 out = 76 numInvoked = 75 out = 77 numInvoked = 76 out = 78 numInvoked = 77 out = 79 numInvoked = 78 out = 80 numInvoked = 79 out = 81 numInvoked = 80 out = 82 numInvoked = 81 out = 83 numInvoked = 82 out = 84 numInvoked = 83 out = 85 numInvoked = 84 out = 86 numInvoked = 85 out = 87 numInvoked = 86 out = 88 numInvoked = 87 out = 89 numInvoked = 88 out = 90 numInvoked = 89 out = 91 numInvoked = 90 out = 92 numInvoked = 91 out = 93 numInvoked = 92 out = 94 numInvoked = 93 out = 95 numInvoked = 94 out = 96 numInvoked = 95 out = 97 numInvoked = 96 out = 98 numInvoked = 97 out = 99 numInvoked = 98 out = 100 numInvoked = 99 out = 101 numInvoked = 100 out = 102 numInvoked = 101 out = 103 numInvoked = 102 out = 104 numInvoked = 103 out = 105 numInvoked = 104 out = 106 numInvoked = 105 out = 107 numInvoked = 106 out = 108 numInvoked = 107 out = 109 numInvoked = 108 out = 110 numInvoked = 109 out = 111 numInvoked = 110 out = 112 numInvoked = 111 out = 113 numInvoked = 112 out = 114 numInvoked = 113 out = 115 numInvoked = 114 out = 116 numInvoked = 115 out = 117 numInvoked = 116 out = 118 numInvoked = 117 out = 119 numInvoked = 118 out = 120 numInvoked = 119 out = 121 numInvoked = 120 out = 122 numInvoked = 121 out = 123 numInvoked = 122 out = 124 numInvoked = 123 out = 125 numInvoked = 124 out = 126 numInvoked = 125 out = 127 numInvoked = 126 out = 128 numInvoked = 127 out = 129 numInvoked = 128 out = 130 numInvoked = 129 out = 131 numInvoked = 130 out = 132 numInvoked = 131 out = 133 numInvoked = 132 out = 134 numInvoked = 133 out = 135 numInvoked = 134 out = 136 numInvoked = 135 out = 137 numInvoked = 136 out = 138 numInvoked = 137 out = 139 numInvoked = 138 out = 140 numInvoked = 139 out = 141 numInvoked = 140 out = 142 numInvoked = 141 out = 143 numInvoked = 142 out = 144 numInvoked = 143 out = 145 numInvoked = 144 out = 146 numInvoked = 145 out = 147 numInvoked = 146 out = 148 numInvoked = 147 out = 149 numInvoked = 148 out = 150 numInvoked = 149 out = 151 numInvoked = 150 out = 152 numInvoked = 151 out = 153 numInvoked = 152 out = 154 numInvoked = 153 out = 155 numInvoked = 154 out = 156 numInvoked = 155 out = 157 numInvoked = 156 out = 158 numInvoked = 157 out = 159 numInvoked = 158 out = 160 numInvoked = 159 out = 161 numInvoked = 160 out = 162 numInvoked = 161 out = 163 numInvoked = 162 out = 164 numInvoked = 163 out = 165 numInvoked = 164 out = 166 numInvoked = 165 out = 167 numInvoked = 166 out = 168 numInvoked = 167 out = 169 numInvoked = 168 out = 170 numInvoked = 169 out = 171 numInvoked = 170 out = 172 numInvoked = 171 out = 173 numInvoked = 172 out = 174 numInvoked = 173 out = 175 numInvoked = 174 out = 176 numInvoked = 175 out = 177 numInvoked = 176 out = 178 numInvoked = 177 out = 179 numInvoked = 178 out = 180 numInvoked = 179 out = 181 numInvoked = 180 out = 182 numInvoked = 181 out = 183 numInvoked = 182 out = 184 numInvoked = 183 out = 185 numInvoked = 184 out = 186 numInvoked = 185 out = 187 numInvoked = 186 out = 188 numInvoked = 187 out = 189 numInvoked = 188 out = 190 numInvoked = 189 out = 191 numInvoked = 190 out = 192 numInvoked = 191 out = 193 numInvoked = 192 out = 194 numInvoked = 193 out = 195 numInvoked = 194 out = 196 numInvoked = 195 out = 197 numInvoked = 196 out = 198 numInvoked = 197 out = 199 numInvoked = 198 out = 200 numInvoked = 199 out = 201 numInvoked = 200 out = 202 numInvoked = 201 out = 203 numInvoked = 202 out = 204 numInvoked = 203 out = 205 numInvoked = 204 out = 206 numInvoked = 205 out = 207 numInvoked = 206 out = 208 numInvoked = 207 out = 209 numInvoked = 208 out = 210 numInvoked = 209 out = 211 numInvoked = 210 out = 212 numInvoked = 211 out = 213 numInvoked = 212 out = 214 numInvoked = 213 out = 215 numInvoked = 214 out = 216 numInvoked = 215 out = 217 numInvoked = 216 out = 218 numInvoked = 217 out = 219 numInvoked = 218 out = 220 numInvoked = 219 out = 221 numInvoked = 220 out = 222 numInvoked = 221 out = 223 numInvoked = 222 out = 224 numInvoked = 223 out = 225 numInvoked = 224 out = 226 numInvoked = 225 out = 227 numInvoked = 226 out = 228 numInvoked = 227 out = 229 numInvoked = 228 out = 230 numInvoked = 229 out = 231 numInvoked = 230 out = 232 numInvoked = 231 out = 233 numInvoked = 232 out = 234 numInvoked = 233 out = 235 numInvoked = 234 out = 236 numInvoked = 235 out = 237 numInvoked = 236 out = 238 numInvoked = 237 out = 239 numInvoked = 238 out = 240 numInvoked = 239 out = 241 numInvoked = 240 out = 242 numInvoked = 241 out = 243 numInvoked = 242 out = 244 numInvoked = 243 out = 245 numInvoked = 244 out = 246 numInvoked = 245 out = 247 numInvoked = 246 out = 248 numInvoked = 247 out = 249 numInvoked = 248 out = 250 numInvoked = 249 out = 251 numInvoked = 250 out = 252 numInvoked = 251 out = 253 numInvoked = 252 out = 254 numInvoked = 253 out = 255 numInvoked = 254 out = 256 numInvoked = 255 out = 257 numInvoked = 256 out = 258 ...