Finish 2010-05-05 12:00:00 UTC

Local Average -- Square with filter ?

by Chethan C U

Status: Passed
Results: 1175119592 (cyc: 5, node: 371)
CPU Time: 70.046
Score: 2350250.0
Submitted at: 2010-04-29 18:01:14 UTC
Scored at: 2010-04-29 18:04:16 UTC

Current Rank: 4229th (Highest: 445th )

Comments
Alan Chalker
10 May 2010
This entry was submitted during the Twilight phase
Alan Chalker
11 May 2010
This entry gets a result of 2011052256 on the test suite (835932664 more than the contest suite). It has a ranking of 4213 compared to all other entries run against the test suite according to the data set provided by Jan Keller.
Please login or create a profile.
Code
function Aest = solver(imageSize, queryLimit)
    

    Aest = zeros(imageSize);
    %Mask = logical(false*zeros(imageSize));
    Num=ceil((imageSize*imageSize)/queryLimit); % Can be floor/ceil
    [m,n]=FindMN(Num);
    %m =floor(sqrt(Num));
    %n =ceil(Num/m);
    for ii=1:ceil(imageSize/m)
        for jj=1:ceil(imageSize/n)
        Mask=false(imageSize);
        Mask((ii-1)*m+1:m*ii,(jj-1)*n+1:n*jj)= true(m,n);
        Mask=Mask(1:imageSize,1:imageSize);
        LocalSum=queryImage(logical(Mask));
        LocalAvg= round(LocalSum/m);
        Aest((ii-1)*m+1:m*ii,(jj-1)*n+1:n*jj)=LocalAvg;
        Aest=Aest(1:imageSize,1:imageSize);
        end
      
    end
    Aest1=Aest';
    prev=Aest1(1,1);
    nxt=Aest1(3);
    for jj=2:imageSize*imageSize-1
        Aest(jj)=(prev+nxt+Aest1(jj))/3;
        prev=Aest1(jj-1);
        nxt=Aest1(jj+1);
    end
    Aest2=Aest;
    prev=Aest2(1,1);
    nxt=Aest2(3);
    for jj=2:imageSize*imageSize-1
        Aest(jj)=(prev+nxt+Aest2(jj))/3;
        prev=Aest2(jj-1);
        nxt=Aest2(jj+1);
    end
    Aest=(Aest1+Aest2)/2;
end

function [m,n]=FindMN(Num)
%can be sqrt algo.
% m =floor(sqrt(Num));
% n =ceil(Num/m);
 if (isprime(Num))
     Num=Num+1;              % Can be Num-1
 end
     L=factor(Num);
     len=length(L);
     m=prod(L(1:floor(len/2)));
     n=prod(L(floor(len/2)+1:end));
 if Num<1
     m=1;
     n=1;
 end
 if Num==3 % actual no. is 2.
     m=2;
     n=1;
 end
end