Hi Team,
I am getting error after submitting as,
"We're sorry, but something went wrong. We've been notified about this issue and we'll take a look at it shortly"
But completion bar has been incremented.
Thanks and Have a Good DaY
function A = right_triangle_sides(p)
k=1;
for i=1:round(p/2)
for j=1:p-i
if sqrt(i^2+j^2)==p-i-j
c(k,:)=[i,j,p-i-j];
k=k+1;
end
end
end
c(size(c,1)/2+1:size(c,1),:)=[];
for i = 1:size(c,1)
A{1,i}=c(i,:);
end
end
Well I don't know why I can't pass the test
could anyone help
function c = right_triangle_sides(p)
c = {};
k=1;
for i=1:ceil(p/3)
for j=i:ceil((p-i)/2)
if i^2+j^2==(p-i-j)^2
c(k)=mat2cell([i j p-i-i],1);
k=k+1;
end
end
end
end
function c = right_triangle_sides(p)
i=0;
for a1 = 1:p-2
for a2 = a1:(p-a1-1)
for a3 = a2:(p-a2-1)
if((a1^2+a2^2==a3^2)&&(a1<=a2)&&(a2<=a3)&&(a1+a2+a3==p))
i=i+1;
b(i,:) = [a1,a2,a3];
end
end
end
end
for i = 1:size(b,1)
c{1,i}=b(i,:);
end
end
function c = right_triangle_sides(p)
N = round(p/2);
A = 1:N;
A = A.^2;
B = sqrt(A + A');
C = arrayfun(@(t) t/floor(t) == 1,B);
[i j] = find(triu(C));
k = p - i - j;
x = (i.^2 + j.^2 - k.^2 == 0);
R = [i(x) j(x) k(x)];
R = sortrows(R);
R = R';
[~,col] = size(R);
c = mat2cell(R(:)',1,3*ones(1,col));
end
I think, the statement of the problem is not complete. The reference problem is not available. I know very well about right angle triangles but I do not have the idea on how to find the solutions. Please help me out.
Hi Castillo,
it is just iteration of 3 sides using perimeter and summing up the three iteration variable for perimeter check then for right angle triangle check (Pythagoras)...
Hope this helped you...(:
c=[];
for A=1:p
B=0;
while B < 1000
B = B+1;
C = sqrt((A^2) + (B^2));
perimeter = A+B+C;
if perimeter==p
c(end+1,:) = [A,B,C];
end
end
end
c=unique(sort(c,2),'rows');
x=cell(1,size(c,1));
for i=1:size(c,1)
[x{1,i}]= deal(c(i,:))
end
c=x
Thank you :)
Works, but is horribly inefficient especially for higher p...
solution using a Neural Network Toolbox function ;)
Find relatively common elements in matrix rows
865 Solvers
Sum all integers from 1 to 2^n
8423 Solvers
Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock.
761 Solvers
390 Solvers
266 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!