Back in second year of my undergraduate degree, we were asked in our MATLAB algorithms design class to write the smallest piece of code to produce the following:
After several attempts my final solution was to encode the face patterns in integers of a matrix. The command spy will plot a logical matrix. This is what I came up with.
function Dice(k) hold rectangle('Po', [0 0 4 4], 'F', 'k', 'Cu', .2) spy(bitget([56 0 62 32 21 32 62 0 56], k), 'w', 99) axis off
In this "competition", only non-whitespace characters were counted. There were a few things like the function definition, hol and axis which were compulsory. I didn't beat the lecturer's solution but I did come up with a solution which I was very happy with.
Last night I was kind of bored and wanted something to do. I decided I'd try and make a random Voronoi diagram which fits in a Tweet.
I'm not quite as happy with this code compared to my Dice code, but I am still going to share it :)
v=rand(15,3) x y]=meshgrid(0:5e-3:1) [hold scatter(x(:),y(:),2,v(dsearchn(v(:,1:2),[x(:) y(:)]),:)) plot(v(:,1),v(:,2),'k.')
Pretty short! And the output is pretty!