主要内容

Results for


Salam,
While I was playing with Cody, I found one interesting question that asked to write MATLAB function to create times-table (can be found here: http://bit.ly/1cWZGGM ). The question itself was easy, but I had problems to figure out how could someone solve this problem with compact code of size 10 !!
After I've checked the leading answer, it seems to be written in Chinese not in MATLAB :)
Here is the answer:
function m = timestables(n)
regexp '' '(?@A=repmat([1:n]'',1,n);m=A.*A'';)'
end
Could anyone translate this to me so that I can use it in my future attempts ? :P
Regards.
In a previous Q & A, Jan Simon pointed to Cody: Sum 1:2^n. The current leading solution to that problem has node-count (or more simply, "length") 10. Apparently, 10 is the minimal length (per the official length-function on File Exchange) of any function taking input & generating output:
function y = test_cody_solution(x)
y = x;
end
Per Cody instruction examples, additional computation within a function definition increases the solution length. For example, both of the following functions have length 12:
function y = test_cody_solution(x)
y = [x];
end
function y = test_cody_solution(x)
y = x+1;
end
My question is: what kinds of ninja-style coding idioms even exist in MATLAB which actually perform definite computation but at the same time do not increase the node-count above 10? I'm not able to imagine what could be going on in order for someone to solve a given non-trivial Cody puzzle in length 10 or 11? IOW, without respect to any particular Cody problem, could someone please give an example of a non-trivial function which somehow comes in at or just above the absolute lower bound? Any explanation of the magic would be appreciated as well.
Thanks, Brad
function b = most_change(a)
a(:,1)=a(:,1)*0.25;
a(:,2)=a(:,2)*0.1;
a(:,3)=a(:,3)*0.05;
a(:,4)=a(:,4)*0.01;
d=sum(a,2);
c=max(d);
for i=1:length(d)
if d(i)==c
b=i;
end
end
i got wa please explain idont understand
Given a tic tac toe board:
1 represents X
0 represents empty.
-1 represents O
It is X's move. If there is an immediate win possibility, choose a square for an immediate win. Otherwise return 0.
Return absolute index of the square of choice. If multiple square are valid, return them in order.
Example:
Input a = [ 1 0 1
-1 1 0
0 -1 -1]
Output wins is [4 8]
Can anyone explain it in detail?
I'm confused with the sentence I marked ans bold style.
Thanks a lot~~~
I've written a valid answer to the last Cody problem, but it is not even close to the best answer. I have no idea how they made this short answer. To unlock it I need to solve another Cody question, but there are none left... :(
Anybody know how to unlock the last question?
Hi,
i'm "solving" number 30 cody's problem.
I think to solve that whit sortrows function.
If I have a z vector:
j = sqrt(-1);
z = [-4 6 3+4*j 1+j 0];
my funtion is:
function z = complexSort(z)
z(2,:)=sqrt(real(z).^2+imag(z).^2);
z=sortrows(z',-2);
z=z(:,1);
end
End it return the result
z =
6.0000 6.0000
3.0000 - 4.0000i 5.0000
-4.0000 4.0000
1.0000 - 1.0000i 1.4142
0 0
The question is: why imagine part in input is positive e sortrows trasform it in negative?
best regards
Marco