I'm attempting to solve the Code Golf: Build Me an Arc problem. My solution's not bad, but I figure, there's a simpler way to do it. Does anybody know how to generate an nxn
matrix like this, given n
? I spent 57 characters getting it!
3 0 0 0 2 0 0 0 1
0 3 0 0 2 0 0 1 0
0 0 3 0 2 0 1 0 0
0 0 0 3 2 1 0 0 0
4 4 4 4 8 8 8 8 8
0 0 0 5 6 7 0 0 0
0 0 5 0 6 0 7 0 0
0 5 0 0 6 0 0 7 0
5 0 0 0 6 0 0 0 7
I would like to beat some of these matrices into shape.
Update:
This is how I get it now.
%%# Create the grid
[X Y]=meshgrid(-r:r);
%%# Compute the angles in degrees
T=atan2(-Y,X)/pi*180;
%%# Get all the angles
T=T+(T<=0)*360;
As you can see, I don't need most of the entries in T
.