Cody

# Problem 1164. Sum the Digits of a Number

Solution 1820904

Submitted on 21 May 2019
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
assessFunctionAbsence('regexp','FileName','digit_sum.m')

2   Fail
x = '123456789'; assert(isequal(digit_sum(x),9))

s = 4 5 6 7 8 0 1 2 3

Assertion failed.

3   Fail
x = '13579'; assert(isequal(digit_sum(x),7))

s = 4 6 8 1 3

Assertion failed.

4   Fail
x = '199'; assert(isequal(digit_sum(x),1))

s = 4 3 3

Assertion failed.

5   Fail
x = '19999999999999999999999'; assert(isequal(digit_sum(x),1))

s = 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

Assertion failed.

6   Fail
x = '1036654257757615301164620529930689045676735109259113932133140605724504628985272966102896725849035075'; assert(isequal(digit_sum(x),5))

s = Columns 1 through 29 4 3 6 0 0 8 7 5 8 1 1 8 1 0 4 8 6 3 4 4 0 7 0 5 3 8 5 3 3 Columns 30 through 58 6 3 0 2 3 3 7 8 0 1 0 1 6 8 4 3 3 5 8 3 4 4 6 3 6 5 4 6 6 Columns 59 through 87 4 7 3 0 3 8 1 5 7 8 3 7 0 5 2 3 2 8 5 1 5 3 0 0 4 3 5 2 3 Columns 88 through 100 0 1 5 8 2 7 3 3 6 8 3 1 8

Assertion failed.

7   Fail
x = '74021245485969262660226837606390444737401741361729271205654666692721644673648826558231964656575921104437679911605584367531520724637367403421848373873279364871895851147873501164141085965889086954824958'; assert(isequal(digit_sum(x),1))

s = Columns 1 through 29 1 7 3 5 4 5 7 8 7 2 8 3 0 3 5 0 5 0 0 3 5 5 0 2 6 1 0 3 0 Columns 30 through 58 6 3 3 7 7 7 1 6 1 7 3 4 1 7 4 6 0 4 1 5 3 5 1 4 5 3 8 0 8 Columns 59 through 87 7 0 0 0 0 3 5 1 5 4 0 7 7 0 1 6 0 7 2 2 5 0 8 8 2 5 6 4 3 Columns 88 through 116 0 7 0 8 0 8 1 8 3 5 4 4 3 7 7 6 1 0 1 3 3 4 4 0 3 8 8 2 7 Columns 117 through 145 6 0 1 8 6 4 8 5 3 1 5 7 0 6 1 6 0 1 7 3 6 7 5 4 2 7 2 6 1 Columns 146 through 174 6 2 1 6 5 1 3 6 0 7 2 1 4 2 3 8 2 8 4 4 7 1 2 1 6 8 3 4 4 Columns 175 through 200 0 7 4 7 4 3 2 8 3 0 8 2 2 3 3 2 0 3 8 7 2 5 7 3 8 2

Assertion failed.

8   Fail
x = '5851147873501164141085965889086954824958752606678975950184825606304112110625645414882256429011165097708998751310932346085834016381957924478113053129649177515212802040810341932020576007951832700665777265307367115487700079617116367572798033657320723526417122504117269467461912747320644603761100467516110111332287512097531691230649461317836258532443574410236994277771642081168571956087153534120969197542720767643838785694086392663104173875192923061073636098783655224289050890906758861210169349969736226546755550793938442137760897037722646218791104180057313259613054984813997639176837835953637446938790362276560342782718153854834909165636800962412231318093037756803017785098259784452756314377610539928858957504653988358962604698474998342789551842878266142728834686534787064418323355335697481001330501689595534408048368891285568524496673551564873437746977135402808065251650010486580915150789952155706519549648556325841434843312042241472703020112115992435204109497067652723884369953849057131345052221998713'; assert(isequal(digit_sum(x),3))

s = Columns 1 through 29 8 2 8 4 4 7 1 2 1 6 8 3 4 4 0 7 4 7 4 3 2 8 3 0 8 2 2 3 3 Columns 30 through 58 2 0 3 8 7 2 5 7 3 8 2 1 8 5 0 3 0 0 1 2 3 1 8 3 8 3 4 2 7 Columns 59 through 87 2 5 8 0 3 0 6 3 7 4 4 5 4 4 3 0 5 8 0 7 8 7 4 7 2 2 5 5 8 Columns 88 through 116 0 7 5 3 3 4 4 4 0 8 3 3 1 1 3 2 3 3 2 1 8 4 6 4 3 3 6 5 6 Columns 117 through 145 7 0 3 2 8 2 6 7 3 4 0 6 2 4 3 8 1 3 5 7 7 1 2 4 4 6 3 8 6 Columns 146 through 174 4 5 3 0 7 3 4 1 1 8 4 8 5 4 5 2 3 5 3 7 3 2 4 3 6 7 4 3 6 Columns 175 through 203 5 3 5 3 8 1 0 3 3 1 3 8 4 2 6 5 1 3 3 0 0 8 1 1 1 5 0 8 6 Columns 204 through 232 3 1 6 0 1 4 4 8 7 2 1 1 3 3 3 1 3 0 4 1 4 4 0 6 0 1 8 1 5 Columns 233 through 261 1 3 2 3 6 6 0 8 1 6 5 3 1 5 6 8 5 0 7 4 1 4 5 5 8 3 7 4 4 Columns 262 through 290 1 5 0 3 7 0 1 7 0 4 3 4 5 1 7 1 6 5 3 0 7 7 0 3 6 1 0 4 4 Columns 291 through 319 3 3 7 0 1 8 4 0 4 4 3 4 4 4 6 6 5 5 2 1 8 4 5 3 3 1 8 6 4 Columns 320 through 348 0 3 4 5 6 3 0 7 3 7 0 4 6 4 1 2 6 0 5 8 2 8 6 5 7 7 6 8 1 Columns 349 through 377 7 7 4 3 5 6 0 3 3 7 5 1 1 1 1 4 0 7 5 3 2 4 4 0 2 8 1 4 3 Columns 378 through 406 8 0 3 2 1 4 8 6 8 6 7 4 5 3 3 0 3 4 3 1 8 7 5 1 5 3 1 0 1 Columns 407 through 435 0 7 6 2 6 2 1 2 8 0 3 7 3 2 0 6 3 5 0 0 6 4 3 7 4 1 6 2 1 Columns 436 through 464 8 4 3 5 3 5 6 3 0 4 3 1 6 0 6 0 3 3 2 1 2 6 0 8 8 5 5 7 5 Columns 465 through 493 2 3 3 8 3 2 3 3 3 3 0 1 8 2 2 0 4 5 4 3 4 0 3 6 7 3 3 0 3 Columns 494 through 522 1 6 0 5 5 0 8 7 0 1 8 8 8 8 3 1 3 6 3 6 2 7 7 5 4 6 1 1 0 Columns 523 through 551 3 2 3 1 3 6 1 1 5 5 0 7 0 5 4 2 1 3 4 4 3 7 4 2 3 3 8 1 6 Columns 552 through 580 4 6 5 8 3 0 4 6 3 8 7 3 2 7 2 4 6 3 3 1 0 6 3 4 1 0 2 6 1 Columns 581 through 609 2 6 8 3 8 6 0 6 1 7 7 0 3 6 2 1 3 3 6 0 5 5 1 0 8 0 3 6 7 Columns 610 through 638 5 1 2 5 1 4 2 4 8 6 2 8 7 2 6 7 3 3 3 4 0 8 0 6 0 2 3 3 3 Columns 639 through 667 0 5 7 4 5 5 6 4 6 4 2 3 3 6 3 6 1 1 8 0 2 3 6 3 4 1 1 2 8 Columns 668 through 696 3 3 2 5 8 3 1 2 7 7 8 5 1 8 0 6 4 7 6 1 1 0 4 3 8 6 3 3 5 Columns 697 through 725 2 2 8 2 3 8 1 8 3 7 0 8 6 3 2 2 6 8 2 3 0 5 0 3 7 0 3 2 7 Columns 726 through 754 1 7 3 3 2 6 7 5 1 2 3 8 8 4 2 7 5 2 1 2 5 0 0 4 7 5 1 5 2 Columns 755 through 783 2 6 7 0 2 0 8 6 7 1 2 1 3 0 7 7 4 2 6 5 6 6 8 8 6 6 8 0 3 Columns 784 through 812 1 7 2 4 3 3 4 6 6 3 8 3 4 0 2 3 8 3 8 8 6 7 7 3 2 3 7 2 6 Columns 813 through 841 0 2 2 3 4 5 2 8 8 0 2 8 5 7 7 3 0 0 1 6 8 8 4 8 0 7 2 1 6 Columns 842 through 870 7 6 1 1 7 0 3 1 1 4 6 8 7 3 5 2 3 2 3 0 8 5 8 4 0 8 3 3 4 Columns 871 through 899 3 7 2 0 8 2 3 3 4 8 4 8 3 1 2 3 3 8 5 4 8 8 1 3 0 8 4 3 8 Columns 900 through 928 7 3 0 7 2 8 8 0 6 5 8 2 7 4 7 6 7 2 7 6 6 4 5 3 7 5 5 7 4 Columns 929 through 957 7 1 5 1 3 6 3 5 3 4 4 5 4 4 8 3 3 5 7 6 8 5 3 7 4 3 3 7 3 Columns 958 through 986 1 3 0 1 0 8 5 1 5 6 2 2 7 6 0 3 3 8 6 2 7 3 3 8 1 4 6 4 6 Columns 987 through 1000 7 8 3 8 5 5 5 4 3 3 2 1 4 6

Assertion failed.

9   Fail
x = '908345908234987234589734591724598712345987345273472134987134589764359712459087124587213458149576345917461982455851147873501164141085965889086954824958752606678975950184825606304112110625645414882256429011165097708998751310932346085834016381957924478113053129649177515212802040810341932020576007951832700665777265307367115487700079617116367572798033657320723526417122504117269467461912747320644603761100467516110111332287512097531691230649461317836258532443574410236994277771642081168571956087153534120969197542720767643838785694086392663104173875192923061073636098783655224289050890906758861210169349969736226546755550793938442137760897037722646218791104180057313259613054984813997639176837835953637446938790362276560342782718153854834909165636800962412231318093037756803017785098259784452756314377610539928858957504653988358962604698474998342789551842878266142728834686534787064418323355335697481001330501689595534408048368891285568524496673551564873437746977135402808065251650010486580915150789952155706519549648556325841434843312042241472703020112115992435204109497067652723884369953849057131345059345982439827345092847145091842350981273459871458321098243593498348934598234098145091245845745091240912345931475871452221993493498324734583402901234912925903469023609823768684168426843682436846824645654268462546242684234365243284325436590349324982345923459832145097614359071642509832457234591249314598734590872134590871645098132450921347509237602389760914651346592451257153'; assert(isequal(digit_sum(x),6))

s = Columns 1 through 29 3 3 2 6 7 8 3 3 2 5 6 7 3 2 1 5 6 7 8 2 3 1 6 7 8 3 4 1 5 Columns 30 through 58 7 8 3 2 1 4 5 6 7 8 3 2 1 6 7 8 5 1 6 7 1 5 4 6 7 3 2 1 4 Columns 59 through 87 6 7 8 2 3 1 0 7 6 8 3 1 4 5 7 8 3 3 2 1 4 5 7 8 2 1 5 4 6 Columns 88 through 116 7 8 2 4 7 3 8 1 0 6 7 8 3 4 1 7 0 4 3 2 5 7 8 8 2 8 4 4 7 Columns 117 through 145 1 2 1 6 8 3 4 4 0 7 4 7 4 3 2 8 3 0 8 2 2 3 3 2 0 3 8 7 2 Columns 146 through 174 5 7 3 8 2 1 8 5 0 3 0 0 1 2 3 1 8 3 8 3 4 2 7 2 5 8 0 3 0 Columns 175 through 203 6 3 7 4 4 5 4 4 3 0 5 8 0 7 8 7 4 7 2 2 5 5 8 0 7 5 3 3 4 Columns 204 through 232 4 4 0 8 3 3 1 1 3 2 3 3 2 1 8 4 6 4 3 3 6 5 6 7 0 3 2 8 2 Columns 233 through 261 6 7 3 4 0 6 2 4 3 8 1 3 5 7 7 1 2 4 4 6 3 8 6 4 5 3 0 7 3 Columns 262 through 290 4 1 1 8 4 8 5 4 5 2 3 5 3 7 3 2 4 3 6 7 4 3 6 5 3 5 3 8 1 Columns 291 through 319 0 3 3 1 3 8 4 2 6 5 1 3 3 0 0 8 1 1 1 5 0 8 6 3 1 6 0 1 4 Columns 320 through 348 4 8 7 2 1 1 3 3 3 1 3 0 4 1 4 4 0 6 0 1 8 1 5 1 3 2 3 6 6 Columns 349 through 377 0 8 1 6 5 3 1 5 6 8 5 0 7 4 1 4 5 5 8 3 7 4 4 1 5 0 3 7 0 Columns 378 through 406 1 7 0 4 3 4 5 1 7 1 6 5 3 0 7 7 0 3 6 1 0 4 4 3 3 7 0 1 8 Columns 407 through 435 4 0 4 4 3 4 4 4 6 6 5 5 2 1 8 4 5 3 3 1 8 6 4 0 3 4 5 6 3 Columns 436 through 464 0 7 3 7 0 4 6 4 1 2 6 0 5 8 2 8 6 5 7 7 6 8 1 7 7 4 3 5 6 Columns 465 through 493 0 3 3 7 5 1 1 1 1 4 0 7 5 3 2 4 4 0 2 8 1 4 3 8 0 3 2 1 4 Columns 494 through 522 8 6 8 6 7 4 5 3 3 0 3 4 3 1 8 7 5 1 5 3 1 0 1 0 7 6 2 6 2 Columns 523 through 551 1 2 8 0 3 7 3 2 0 6 3 5 0 0 6 4 3 7 4 1 6 2 1 8 4 3 5 3 5 Columns 552 through 580 6 3 0 4 3 1 6 0 6 0 3 3 2 1 2 6 0 8 8 5 5 7 5 2 3 3 8 3 2 Columns 581 through 609 3 3 3 3 0 1 8 2 2 0 4 5 4 3 4 0 3 6 7 3 3 0 3 1 6 0 5 5 0 Columns 610 through 638 8 7 0 1 8 8 8 8 3 1 3 6 3 6 2 7 7 5 4 6 1 1 0 3 2 3 1 3 6 Columns 639 through 667 1 1 5 5 0 7 0 5 4 2 1 3 4 4 3 7 4 2 3 3 8 1 6 4 6 5 8 3 0 Columns 668 through 696 4 6 3 8 7 3 2 7 2 4 6 3 3 1 0 6 3 4 1 0 2 6 1 2 6 8 3 8 6 Columns 697 through 725 0 6 1 7 7 0 3 6 2 1 3 3 6 0 5 5 1 0 8 0 3 6 7 5 1 2 5 1 4 Columns 726 through 754 2 4 8 6 2 8 7 2 6 7 3 3 3 4 0 8 0 6 0 2 3 3 3 0 5 7 4 5 5 Columns 755 through 783 6 4 6 4 2 3 3 6 3 6 1 1 8 0 2 3 6 3 4 1 1 2 8 3 3 2 5 8 3 Columns 784 through 812 1 2 7 7 8 5 1 8 0 6 4 7 6 1 1 0 4 3 8 6 3 3 5 2 2 8 2 3 8 Columns 813 through 841 1 8 3 7 0 8 6 3 2 2 6 8 2 3 0 5 0 3 7 0 3 2 7 1 7 3 3 2 6 Columns 842 through 870 7 5 1 2 3 8 8 4 2 7 5 2 1 2 5 0 0 4 7 5 1 5 2 2 6 7 0 2 0 Columns 871 through 899 8 6 7 1 2 1 3 0 7 7 4 2 6 5 6 6 8 8 6 6 8 0 3 1 7 2 4 3 3 Columns 900 through 928 4 6 6 3 8 3 4 0 2 3 8 3 8 8 6 7 7 3 2 3 7 2 6 0 2 2 3 4 5 Columns 929 through 957 2 8 8 0 2 8 5 7 7 3 0 0 1 6 8 8 4 8 0 7 2 1 6 7 6 1 1 7 0 Columns 958 through 986 3 1 1 4 6 8 7 3 5 2 3 2 3 0 8 5 8 4 0 8 3 3 4 3 7 2 0 8 2 Columns 987 through 1015 3 3 4 8 4 8 3 1 2 3 3 8 5 4 8 8 1 3 0 8 4 3 8 7 3 0 7 2 8 Columns 1016 through 1044 8 0 6 5 8 2 7 4 7 6 7 2 7 6 6 4 5 3 7 5 5 7 4 7 1 5 1 3 6 Columns 1045 through 1073 3 5 3 4 4 5 4 4 8 3 3 5 7 6 8 5 3 7 4 3 3 7 3 1 3 0 1 0 8 Columns 1074 through 1102 5 1 5 6 2 2 7 6 0 3 3 8 6 2 7 3 3 8 1 4 6 4 6 7 8 3 8 3 6 Columns 1103 through 1131 7 8 3 2 5 7 6 3 2 5 1 6 7 8 3 3 5 2 7 1 4 7 8 3 3 4 2 7 5 Columns 1132 through 1160 6 8 3 3 2 4 5 1 6 7 8 3 2 1 4 7 8 2 6 5 4 3 3 2 5 7 6 8 3 Columns 1161 through 1189 6 7 3 2 6 7 2 3 6 7 8 3 2 5 6 7 3 3 2 4 7 8 3 3 4 5 7 8 2 Columns 1190 through 1218 7 8 1 7 8 3 3 4 5 7 3 3 4 5 6 7 8 3 6 4 7 1 8 2 1 4 7 8 5 Columns 1219 through 1247 5 5 4 3 3 6 7 3 6 7 3 2 6 5 7 1 6 7 8 2 6 7 3 5 3 3 4 5 6 Columns 1248 through 1276 7 3 4 5 3 5 8 3 3 6 7 0 3 3 5 6 0 3 3 2 5 6 1 0 2 0 2 7 4 Columns 1277 through 1305 0 2 7 5 0 2 7 6 0 2 5 7 6 0 2 7 0 2 5 7 0 7 8 0 8 7 5 0 2 Columns 1306 through 1334 7 0 5 8 7 0 5 7 5 0 2 7 5 6 7 6 0 8 5 7 6 5 2 7 6 5 8 7 6 Columns 1335 through 1363 0 8 3 3 6 7 3 6 5 7 3 2 5 6 7 8 3 5 6 7 8 3 2 6 5 4 7 8 3 Columns 1364 through 1392 3 1 0 4 7 6 8 3 3 1 4 0 7 5 8 3 3 2 6 5 7 8 1 5 6 7 8 3 4 Columns 1393 through 1421 5 7 3 6 4 7 8 3 2 1 6 7 8 3 3 2 1 5 4 6 7 8 3 3 2 1 4 0 7 Columns 1422 through 1450...

Assertion failed.