Something weird is happening
When I submit the size of my code is -1 and it fails the test suite when it seems to work fine in MATLAB desktop.
would you please let me know why
sum(x) creates error?
Good problem helps understand how to use binary better
concepts matter
challenging!
easy
Interesting problem
ASCII
Can someone check this code?
function y = one(x)
split1= num2cell(x)
sum=0;
for i=1:length(split1)
if split1(i)=='1'
sum=sum+1
else
sum=0
i=i+1
y = sum;
end
What's wrong with this problem!!
used y=y+str2double(x(i)) instead of y=y+str2double(x(i)) and it worked just fine
function y = one(x)
y1=[];
for a=x(1:end)
y1 = [y1,str2num(a)];
end
y=sum(y1);
end
y=0;
for index=1:length(x)
y = y + str2num(x(index));
end
y = sum(x=='1');
Well, well! Here he/she is as well, great job continuing your copy and paste of the cheap and meaningless trick you prick!
In case you didn't know how to do it and wanted to know how -which somehow I doubt it for some reason!, but anyhow, here is one of MANY ways to do it:
function x=one(x),x=count(x,'1');end
y = length(find(x=='1'));
Why doesn't this solution work? Works just fine in my desktop program...
Because you compare a char Array to a double. Try (x=='1').
Find the longest sequence of 1's in a binary sequence.
3933 Solvers
Remove the polynomials that have positive real elements of their roots.
784 Solvers
How long is the longest prime diagonal?
355 Solvers
The Answer to Life, the Universe, and Everything
404 Solvers
560 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!