there is a problem with the test.
it does not accept the following code:
s1=[]
s2=[]
l=length(s)
if mod(l,2)~= 0
for i = 1:ceil(length(s)/2)-1
s1 = [s1,str2double(s(i))]
end
for i = ceil(length(s)/2)+1:l
s2=[s2,str2double(s(i))]
end
else
for i = 1:ceil(length(s)/2)
s1 = [s1,str2double(s(i))]
end
for i = ceil(length(s)/2)+1:l
s2=[s2,str2double(s(i))]
end
end
if sum(s1)==sum(s2)
tf = 1
else
tf = 0
end
Simple code:
clc
clear all
close all
x=input('Enter the number');
Y=[];
c=0;
m=x;
while (m>0)
b=rem(m,10);
Y=[b Y];
c=c+1;
m=(m-b)/10;
end
r=c/2;
qw=floor(r);
if(qw==r)
t=0;
l=0;
for i=1:qw
t=t+Y(i);
end
for i=(qw+1):c
l=l+Y(i);
end
if(t==l)
disp('Yes');
else
disp('No');
end
else
t=0;
l=0;
for i=1:qw
t=t+Y(i);
end
for i=(qw+2):c
l=l+Y(i);
end
if(t==l)
disp('Yes');
else
disp('No');
end
end
All test cases of CODY , will be passed :-)
could be better
I just wanted to see if this would be accepted. I can't find a way to remove it...
can you please explain what is going on inside dot function and why the str input?
in this code,it seems that end/2 is not alwayss an integer,so we need modify it,l wonder your code works or the workspace report a warning
That is cheating :P
nicely done..
Excellent way to use the dot product. Wish I would have thought of it!
Extract leading non-zero digit
1213 Solvers
First non-zero element in each column
601 Solvers
Solve the set of simultaneous linear equations
278 Solvers
Getting the row and column location from a matrix
244 Solvers
391 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!