Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 184833

Submitted on 3 Jan 2013 by Khaled Hamed

Correct

24Size
Leading solution size is 10.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
x = '123456789';
y_correct = 9;
assert(isequal(digit_sum(x),y_correct))
ans =
     9
2
Pass
 
%%
x = '13579';
y_correct = 7;
assert(isequal(digit_sum(x),y_correct))
ans =
     7
3
Pass
 
%%
x = '1036654257757615301164620529930689045676735109259113932133140605724504628985272966102896725849035075';
y_correct = 5;
assert(isequal(digit_sum(x),y_correct))
ans =
     5
4
Pass
 
%%
x = '5851147873501164141085965889086954824958752606678975950184825606304112110625645414882256429011165097708998751310932346085834016381957924478113053129649177515212802040810341932020576007951832700665777265307367115487700079617116367572798033657320723526417122504117269467461912747320644603761100467516110111332287512097531691230649461317836258532443574410236994277771642081168571956087153534120969197542720767643838785694086392663104173875192923061073636098783655224289050890906758861210169349969736226546755550793938442137760897037722646218791104180057313259613054984813997639176837835953637446938790362276560342782718153854834909165636800962412231318093037756803017785098259784452756314377610539928858957504653988358962604698474998342789551842878266142728834686534787064418323355335697481001330501689595534408048368891285568524496673551564873437746977135402808065251650010486580915150789952155706519549648556325841434843312042241472703020112115992435204109497067652723884369953849057131345052221998713';
y_correct = 3;
assert(isequal(digit_sum(x),y_correct))
ans =
     3