Cody

Solution 575990

Submitted on 7 Feb 2015 by Pritesh Shah
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

This solution is outdated. To rescore this solution, sign in.

Test Suite

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', player.vote); % % 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); 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.'); end % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %

v = 31 Congratulations! You have voted for "Problem 31. " created by .

Suggested Problems

More from this Author41