Cody

Solution 2013625

Submitted on 11 Nov 2019 at 9:38 by cokakola
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
v = 10 * (1:6) + (1:6)'; v = 10 * v(:)' + (1:6)'; v = reshape(10*v(:)' + (1:6)', [], 1); m = dec2base(v, 10) - 48; mpc = sum(permute(m, [1 3 2]) == permute(m, [3 1 2]), 3); mc = histc(m, 1:6, 2); mc = sum(min(permute(mc, [1 3 2]), permute(mc, [3 1 2])), 3) - mpc; mpc5c = 5 * mpc + mc; L = zeros(1296, 1); P = [1:1296 randi(1296, 1, 6000)]; t = accumarray(P', 1); for p = P(randperm(end)) mguess = []; mpegs = []; while 1 mguessn = solve_mastermind(mguess, mpegs, m, mpc, mc, mpc5c, v); k = v == polyval(mguessn, 10); assert(any(k), 'invalid guess.') mguess(end+1, :) = mguessn; mpegs(end+1, :) = [mpc(p, k) mc(p, k)]; if mpegs(end, 1) == 4, L(p) = L(p) + size(mguess, 1); break, end end end L = sum(L ./ t); fid = fopen('score.p', 'Wb'); fwrite(fid, uint8(sscanf([... '7630312E30307630302E3030000D201C07E23FB1000000340000015B000001C36FCD46'... '4336A6F9BD2918A670F86BF0AC534F616971CE31A66833ECF344BF30BF9F163C19F925'... '0AC8280807727BFFC8E8FF46AA63FA75C2890672D48C5599920C846EB7E0E230FDC14E'... '1EA1768A5F84951A22717883064D6B9AD895493F53F6443E63783C5BFDD36A65EE33DB'... 'DF0C38A4238848AF99B21B91FC5F8E0E31A8D33533721B36C2AB371D7B4D59A1036FBF'... 'E2A4A0233812C46AA22FE134B0DE0FCFDCDCD4A49106161DDD64A97EC0B1F14A8E1FB4'... '81CE94D11A50006D5AA9536055488421EC1682EF9945B98FB175A9CE96624DE8C575C2'... 'B442A7EAD282A0A90E89D3F25C7B22AF0D1FA61A2F76ED95E8C6EF78A197B13C3B570E'... 'D2F8EA301AAA8795CB4B2DEF21140589C0FC80A0B75F896CCEB1B560C07273FC4BCBD5'... '5D98ED8516915D9A344A91D913E1E106F8CB3C87EBDBB7C0501AE307F5B1807555F8D2'... '65EE53842038231C5E6C0BFDC5EB1A33CA999C68E612C9DC17050B9606'], '%2X'))); fclose(fid); fprintf('Average number of guesses: %.2f', L / 1296) score(floor((L / 1296 - 4) * 100))

Average number of guesses: 13.36