Cody

Problem 1164. Sum the Digits of a Number

Solution 469033

Submitted on 10 Jul 2014 by Abdullah Caliskan
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

This solution is outdated. To rescore this solution, sign in.

Test Suite

Test Status Code Input and Output
1   Pass
%% x = '123456789'; y_correct = 9; assert(isequal(digit_sum(x),y_correct))

p = 123456789 r = 45 k = 45 p = 45 r = 9 k = 9

2   Pass
%% x = '13579'; y_correct = 7; assert(isequal(digit_sum(x),y_correct))

p = 13579 r = 25 k = 25 p = 25 r = 7 k = 7

3   Pass
%% x = '1036654257757615301164620529930689045676735109259113932133140605724504628985272966102896725849035075'; y_correct = 5; assert(isequal(digit_sum(x),y_correct))

p = 1036654257757615301164620529930689045676735109259113932133140605724504628985272966102896725849035075 r = 428 k = 428 p = 428 r = 14 k = 14 p = 14 r = 5 k = 5

4   Pass
%% x = '5851147873501164141085965889086954824958752606678975950184825606304112110625645414882256429011165097708998751310932346085834016381957924478113053129649177515212802040810341932020576007951832700665777265307367115487700079617116367572798033657320723526417122504117269467461912747320644603761100467516110111332287512097531691230649461317836258532443574410236994277771642081168571956087153534120969197542720767643838785694086392663104173875192923061073636098783655224289050890906758861210169349969736226546755550793938442137760897037722646218791104180057313259613054984813997639176837835953637446938790362276560342782718153854834909165636800962412231318093037756803017785098259784452756314377610539928858957504653988358962604698474998342789551842878266142728834686534787064418323355335697481001330501689595534408048368891285568524496673551564873437746977135402808065251650010486580915150789952155706519549648556325841434843312042241472703020112115992435204109497067652723884369953849057131345052221998713'; y_correct = 3; assert(isequal(digit_sum(x),y_correct))

p = 5851147873501164141085965889086954824958752606678975950184825606304112110625645414882256429011165097708998751310932346085834016381957924478113053129649177515212802040810341932020576007951832700665777265307367115487700079617116367572798033657320723526417122504117269467461912747320644603761100467516110111332287512097531691230649461317836258532443574410236994277771642081168571956087153534120969197542720767643838785694086392663104173875192923061073636098783655224289050890906758861210169349969736226546755550793938442137760897037722646218791104180057313259613054984813997639176837835953637446938790362276560342782718153854834909165636800962412231318093037756803017785098259784452756314377610539928858957504653988358962604698474998342789551842878266142728834686534787064418323355335697481001330501689595534408048368891285568524496673551564873437746977135402808065251650010486580915150789952155706519549648556325841434843312042241472703020112115992435204109497067652723884369953849057131345052221998713 r = 4458 k = 4458 p = 4458 r = 21 k = 21 p = 21 r = 3 k = 3

Suggested Problems

More from this Author3

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!