Given a positive integer find whether it is a balanced number. For a balanced number the sum of first half of digits is equal to the second half.
Examples:
Input n = 13722 Output tf is true
because 1 + 3 = 2 + 2.
Input n = 23567414 Output tf = true
All palindrome numbers are balanced.
This is partly from Project Euler, Problem 217.
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
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!
Return elements unique to either input
442 Solvers
Create a vector whose elements depend on the previous element
267 Solvers
find the maximum element of the matrix
236 Solvers
214 Solvers
739 Solvers