This solution is outdated. To rescore this solution, sign in.
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
% read player id and voted problem number
lines = textread('vote.m', '%s');
player.id = str2num(regexp(lines{end}, '\d+', 'match', 'once'));
player.vote = uint16(vote());
assignin('caller', 'score', -1);
%
% get web pages data
% 1 - voted problem,
% 2 - this problem player correct solutions,
% 3 - voted problem solutions - problemexists
url = 'http://www.mathworks.com/matlabcentral/cody/problems/';
url1 = sprintf('%s%d', url, player.vote);
url2 = sprintf( ...
'%s%d/solutions?sort=&term=player_id:%d+status:Correct', ...
url, 2954, player.id);
url3 = sprintf('%s%d/solutions', url, player.vote);
[html1, ~] = urlread(url1);
[html2, ~] = urlread(url2);
[~,status] = urlread(url3);
%
% get voted problem creator id, name and problem description
creator.id = str2num(regexp(html1, ...
'(?<=Created by.*?players/)\d*', ...
'match', 'once'));
creator.name = regexp(html1, ...
'(?<=Created by <.*?>)[^<]*', ...
'match', 'once');
creator.description = regexp(html1, ...
'(?<=Problem \d+\. )[^<>]*', ...
'match', 'once');
%
% get some player previous votes data
player.countVotes = numel(regexpi(html2, 'solution \d+'));
player.prevDateStr = regexp(html2, ...
'(?<=Submitted on )\d+ ... \d{4}', ...
'match', 'once');
if isempty(player.prevDateStr)
player.prevDateNum = 0;
else
player.prevDateNum = datenum(player.prevDateStr);
end
player.thisDateNum = floor(now);
player.nextDateStr = regexprep(datestr(player.prevDateNum+7, ...
'dd mmmm yyyy'), ...
'^0', '');
%
% check if vote is valid and manage errors
if status
if ~isequal(creator.id,player.id)
if player.countVotes < 10 || player.thisDateNum >= ...
player.prevDateNum + 7
fprintf(['Congratulations! You have voted for ' ...
'"Problem %d. %s" created by %s.\n'], ...
player.vote, creator.description, creator.name);
assignin('caller', 'score', player.vote);
else
error(['You voted %d times already. \n' ...
'You can submit next vote on %s or later.'], ...
player.countVotes, player.nextDateStr);
end
else
error(['You cannot vote for problems created' ...
' by yourself. Sorry.']);
end
elseif player.vote
error('There is no "Problem %d." on Cody yet.', player.vote);
else
disp('Got what you want, size 0, but one vote is gone.');
assignin('caller', 'score', 0);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
ans =
582
Congratulations! You have voted for "Problem 582. Function composition - harder" created by David Hruska.
|
Find the sum of all the numbers of the input vector
25588 Solvers
378 Solvers
322 Solvers
682 Solvers
Back to basics - mean of corner elements of a matrix
235 Solvers