Cody

# Problem 44236. Mastermind I: Solve all 1296 cases

Solution 3112396

Submitted on 8 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
tic v=1111:6666; vL=length(v); m=zeros(vL,4); for i=1:vL vp=v(i); for k=4:-1:1 m(i,k)=mod(vp,10); vp=floor(vp/10); end end mdel=sum((m==0)+(m>6),2)>0; m(mdel,:)=[]; v=m*[1000;100;10;1]; mL=size(m,1); mpc=zeros(mL); % 0.030 for j=1:mL mpc(:,j)=sum(m==repmat(m(j,:),mL,1),2); end mch=zeros(mL,6); % 0.038 for i=1:mL for k=1:6 mch(i,k)=nnz(m(i,:)==k); end end mc=zeros(mL); % 0.06 for j=1:mL mc(:,j)=sum(min(mch,repmat(mch(j,:),mL,1)),2); end mc=mc-mpc; % remove mpc part mpc5c=5*mpc+mc; fprintf('Initialization %.3f\n',toc) % finished initilaiztion calculation in less than 0.2 sec ztic=tic; solved=1; pcase=0; Lmax=0; Ltot=0; for ptr=randperm(1296) % anti-hack randomization pcase=pcase+1; mguess=[];mpegs=[]; while solved % loop until solved ztoc=toc(ztic); if ztoc>45 solved=0; break; end % if [mguessn]=solve_mastermind(mguess,mpegs,m,mpc,mc,mpc5c,v); mguessptr=find(v==mguessn*[1000;100;10;1]); if isempty(mguessptr),continue;end % invalid input mguess(end+1,:)=mguessn; mpegs(end+1,1)=mpc(ptr,mguessptr); mpegs(end,2)=mc(ptr,mguessptr); if mpegs(end,1)==4 % break on solved to ptr loop Lsol=size(mguess,1); Ltot=Ltot+Lsol; if Lsol>Lmax, Lmax=Lsol;end break; end end % while if ~solved,break;end % terminate case processing end % for all 1296 cases if solved fprintf('Solved in %.2f\n',ztoc) fprintf('Lmax %i Ltot %i\n',Lmax,Ltot) assert(isequal(solved,1)) else fprintf('Solved %i of 1296 cases in %.2f\n',pcase-1,ztoc) fprintf('Lmax %i Ltot %i\n',Lmax,Ltot) assert(isequal(solved,1)) end

Initialization 0.166 a = 1 b = 8 a = 2 b = 8 a = 3 b = 8 a = 4 b = 8 a = 5 b = 8 a = 6 b = 8 a = 7 b = 8 a = 8 b = 8 a = 9 b = 8 a = 10 b = 8 a = 11 b = 8 a = 12 b = 8 a = 13 b = 8 a = 14 b = 8 a = 15 b = 8 a = 16 b = 8 a = 17 b = 8 a = 18 b = 8 a = 19 b = 8 a = 20 b = 8 a = 21 b = 8 a = 22 b = 8 a = 23 b = 8 a = 24 b = 8 a = 25 b = 8 a = 26 b = 8 a = 27 b = 8 a = 28 b = 8 a = 29 b = 8 a = 30 b = 8 a = 31 b = 8 a = 32 b = 8 a = 33 b = 8 a = 34 b = 8 a = 35 b = 8 a = 36 b = 8 a = 37 b = 8 a = 38 b = 8 a = 39 b = 8 a = 40 b = 8 a = 41 b = 8 a = 42 b = 8 a = 43 b = 8 a = 44 b = 8 a = 45 b = 8 a = 46 b = 8 a = 47 b = 8 a = 48 b = 8 a = 49 b = 8 a = 50 b = 8 a = 51 b = 8 a = 52 b = 8 a = 53 b = 8 a = 54 b = 8 a = 55 b = 8 a = 56 b = 8 a = 57 b = 8 a = 58 b = 8 a = 59 b = 8 a = 60 b = 8 a = 61 b = 8 a = 62 b = 8 a = 63 b = 8 a = 64 b = 8 a = 65 b = 8 a = 66 b = 8 a = 67 b = 8 a = 68 b = 8 a = 69 b = 8 a = 70 b = 8 a = 71 b = 8 a = 72 b = 8 a = 73 b = 8 a = 74 b = 8 a = 75 b = 8 a = 76 b = 8 a = 77 b = 8 a = 78 b = 8 a = 79 b = 8 a = 80 b = 8 a = 81 b = 8 a = 82 b = 8 a = 83 b = 8 a = 84 b = 8 a = 85 b = 8 a = 86 b = 8 a = 87 b = 8 a = 88 b = 8 a = 89 b = 8 a = 90 b = 8 a = 91 b = 8 a = 92 b = 8 a = 93 b = 8 a = 94 b = 8 a = 95 b = 8 a = 96 b = 8 a = 97 b = 8 a = 98 b = 8 a = 99 b = 8 a = 100 b = 8 a = 101 b = 8 a = 102 b = 8 a = 103 b = 8 a = 104 b = 8 a = 105 b = 8 a = 106 b = 8 a = 107 b = 8 a = 108 b = 8 a = 109 b = 8 a = 110 b = 8 a = 111 b = 8 a = 112 b = 8 a = 113 b = 8 a = 114 b = 8 a = 115 b = 8 a = 116 b = 8 a = 117 b = 8 a = 118 b = 8 a = 119 b = 8 a = 120 b = 8 a = 121 b = 8 a = 122 b = 8 a = 123 b = 8 a = 124 b = 8 a = 125 b = 8 a = 126 b = 8 a = 127 b = 8 a = 128 b = 8 a = 129 b = 8 a = 130 b = 8 a = 131 b = 8 a = 132 b = 8 a = 133 b = 8 a = 134 b = 8 a = 135 b = 8 a = 136 b = 8 a = 137 b = 8 a = 138 b = 8 a = 139 b = 8 a = 140 b = 8 a = 141 b = 8 a = 142 b = 8 a = 143 b = 8 a = 144 b = 8 a = 145 b = 8 a = 146 b = 8 a = 147 b = 8 a = 148 b = 8 a = 149 b = 8 a = 150 b = 8 a = 151 b = 8 a = 152 b = 8 a = 153 b = 8 a = 154 b = 8 a = 155 b = 8 a = 156 b = 8 a = 157 b = 8 a = 158 b = 8 a = 159 b = 8 a = 160 b = 8 a = 161 b = 8 a = 162 b = 8 a = 163 b = 8 a = 164 b = 8 a = 165 b = 8 a = 166 b = 8 a = 167 b = 8 a = 168 b = 8 a = 169 b = 8 a = 170 b = 8 a = 171 b = 8 a = 172 b = 8 a = 173 b = 8 a = 174 b = 8 a = 175 b = 8 a = 176 b = 8 a = 177 b = 8 a = 178 b = 8 a = 179 b = 8 a = 180 b = 8 a = 181 b = 8 a = 182 b = 8 a = 183 b = 8 a = 184 b = 8 a = 185 b = 8 a = 186 b = 8 a = 187 b = 8 a = 188 b = 8 a = 189 b = 8 a = 190 b = 8 a = 191 b = 8 a = 192 b = 8 a = 193 b = 8 a = 194 b = 8 a = 195 b = 8 a = 196 b = 8 a = 197 b = 8 a = 198 b = 8 a = 199 b = 8 a = 200 b = 8 a = 201 b = 8 a = 202 b = 8 a = 203 b = 8 a = 204 b = 8 a = 205 b = 8 a = 206 b = 8 a = 207 b = 8 a = 208 b = 8 a = 209 b = 8 a = 210 b = 8 a = 211 b = 8 a = 212 b = 8 a = 213 b = 8 a = 214 b = 8 a = 215 b = 8 a = 216 b = 8 a = 217 b = 8 a = 218 b = 8 a = 219 b = 8 a = 220 b = 8 a = 221 b = 8 a = 222 b = 8 a = 223 b = 8 a = 224 b = 8 a = 225 b = 8 a = 226 b = 8 a = 227 b = 8 a = 228 b = 8 a = 229 b = 8 a = 230 b = 8 a = 231 b = 8 a = 232 b = 8 a = 233 b = 8 a = 234 b = 8 a = 235 b = 8 a = 236 b = 8 a = 237 b = 8 a = 238 b = 8 a = 239 b = 8 a = 240 b = 8 a = 241 b = 8 a = 242 b = 8 a = 243 b = 8 a = 244 b = 8 a = 245 b = 8 a = 246 b = 8 a = 247 b = 8 a = 248 b = 8 a = 249 b = 8 a = 250 b = 8 a = 251 b = 8 a = 252 b = 8 a = 253 b = 8 a = 254 b = 8 a = 255 b = 8 a = 256 b = 8 a = 257 b = 8 a = 258 b = 8 a = 259 b = 8 a = 260 b = 8 a = 261 b = 8 a = 262 b = 8 a = 263 b = 8 a = 264 b = 8 a = 265 b = 8 a = 266 b = 8 a = 267 b = 8 a = 268 b = 8 a = 269 b = 8 a = 270 b = 8 a = 271 b = 8 a = 272 b = 8 a = 273 b = 8 a = 274 b = 8 a = 275 b = 8 a = 276 b = 8 a = 277 b = 8 a = 278 b = 8 a = 279 b = 8 a = 280 b = 8 a = 281 b = 8 a = 282 b = 8 a = 283 b = 8 a = 284 b = 8 a = 285 b = 8 a = 286 b = 8 a = 287 b = 8 a = 288 b = 8 a = 289 b = 8 a = 290 b = 8 a = 291 b = 8 a = 292 b = 8 a = 293 b = 8 a = 294 b = 8 a = 295 b = 8 a = 296 b = 8 a = 297 b = 8 a = 298 b = 8 a = 299 b = 8 a = 300 b = 8 a = 301 b = 8 a = 302 b = 8 a = 303 b = 8 a = 304 b = 8 a = 305 b = 8 a = 306 b = 8 a = 307 b = 8 a = 308 b = 8 a = 309 b = 8 a = 310 b = 8 a = 311 b = 8 a = 312 b = 8 a = 313 b = 8 a = 314 b = 8 a = 315 b = 8 a = 316 b = 8 a = 317 b = 8 a = 318 b = 8 a = 319 b = 8 a = 320 b = 8 a = 321 b = 8 a = 322 b = 8 a = 323 b = 8 a = 324 b = 8 a = 325 b = 8 a = 326 b = 8 a = 327 b = 8 a = 328 b = 8 a = 329 b = 8 a = 330 b = 8 a = 331 b = 8 a = 332 b = 8 a = 333 b = 8 a = 334 b = 8 a = 335 b = 8 a = 336 b = 8 a = 337 b = 8 a = 338 b = 8 a = 339 b = 8 a = 340 b = 8 a = 341 b = 8 a = 342 b = 8 a = 343 b = 8 a = 344 b = 8 a = 345 b = 8 a = 346 b = 8 a = 347 b = 8 a = 348 b = 8 a = 349 b = 8 a = 350 b = 8 a = 351 b = 8 a = 352 b = 8 a = 353 b = 8 a = 354 b = 8 a = 355 b = 8 a = 356 b = 8 a = 35...

Assertion failed.

### Community Treasure Hunt

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

Start Hunting!