Skip to content

Instantly share code, notes, and snippets.

@zippeurfou
Last active August 29, 2015 14:16
Show Gist options
  • Save zippeurfou/ce0cc5c83c53e525a19d to your computer and use it in GitHub Desktop.
Save zippeurfou/ce0cc5c83c53e525a19d to your computer and use it in GitHub Desktop.
codehunter
%Marc Ferradou
%v0.0.1
%Licence: WTFPL
%Date: 3/16/14
%This code is an answer to the BNP codehunter challenge. It tooks me about 2 hours and I picked Matlab for its simplicity to do the job.
%As easy as this code looks, I was actually one of the 20 winners. As we say, KIS.
%Read more here: https://graduates.bnpparibas.com/codehunter/crack-the-challenge/
%Result: this is a 29x29 transformation of a london (I believe) landscape
%with 3 Easter eggs.
%Note: I choosed matlab because it was in my opinion the quickest (in term
%of time consuming) language to code a solution to this challenge.
%I believe the first goal of this challenge was to finish on time so I didn't focus
%on the complexity or the exatitude of the algorithm.
%Warning: I am assuming that the unscranbled image is in the current folder
%with the name 'CodeHunter-Scrambled-image.bmp'. I couldn't upload the
%folder with the image due to upload size limit. Code won't work without
%it.
%You have to have CodeHunter-Scrambled-image.bmp in the folder you are
%executing this code.
imgO=imread('CodeHunter-Scrambled-image.bmp');
%imgW is the imagine we will be working on.
imgW=imgO;
%nval is the number of transformation we want to apply.
nval=29;
sizeImg=size(imgO);
%This loop goes backward to undo the transformation.
for n=nval:-1:2
%width of a tile without decimal, note that width=height.
w=fix(sizeImg(1)/n);
%row and column are just for lisibility.
row=n;
column=row;
%Initial rotation
rot=90;
%We append the image row per row.
imgAppendRow=[];
for r=1:row
%This is the current row we are working on.
imgRow=[];
for c=1:column
%We select the good row and column and apply the rotation
tile=imrotate(imgW((r-1)*w+1:r*w,(c-1)*w+1:c*w,:),rot);
%Then we append it to the current row.
imgRow=[imgRow,tile];
rot=rot+90;
if rot>270
rot=90;
end
end
%At the end of the current row, we check if we don't have to add
%the missing pixel that were ommited by the removing of the decimal
if (n*w<sizeImg(1))
fixRow=imgO((r-1)*w+1:r*w,column*w+1:sizeImg(1),:);
imgRow=[imgRow,fixRow];
end
imgAppendRow=[imgAppendRow;imgRow];
end
%Once all row have been treated we check if there are extra pixel at
%the bottom to add.
if (n*w<sizeImg(1))
fixBottom=imgO((row)*w+1:sizeImg(1),1:sizeImg(1),:);
imgAppendRow=[imgAppendRow;fixBottom];
end
%We change the image we are working on with the one we just created
%with the transformation.
imgW=imgAppendRow;
end
imwrite(imgW,'CodeHunter-Unscrambled-image.bmp');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment