Cody

# Problem 1164. Sum the Digits of a Number

Solution 184638

Submitted on 2 Jan 2013 by Robert Turner
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
%% x = '123456789'; y_correct = 9; assert(isequal(digit_sum(x),y_correct))

ans = 1 2 3 4 5 6 7 8 9

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

ans = 1 3 5 7 9

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

ans = Columns 1 through 16 1 0 3 6 6 5 4 2 5 7 7 5 7 6 1 5 Columns 17 through 32 3 0 1 1 6 4 6 2 0 5 2 9 9 3 0 6 Columns 33 through 48 8 9 0 4 5 6 7 6 7 3 5 1 0 9 2 5 Columns 49 through 64 9 1 1 3 9 3 2 1 3 3 1 4 0 6 0 5 Columns 65 through 80 7 2 4 5 0 4 6 2 8 9 8 5 2 7 2 9 Columns 81 through 96 6 6 1 0 2 8 9 6 7 2 5 8 4 9 0 3 Columns 97 through 100 5 0 7 5

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

ans = Columns 1 through 16 5 8 5 1 1 4 7 8 7 3 5 0 1 1 6 4 Columns 17 through 32 1 4 1 0 8 5 9 6 5 8 8 9 0 8 6 9 Columns 33 through 48 5 4 8 2 4 9 5 8 7 5 2 6 0 6 6 7 Columns 49 through 64 8 9 7 5 9 5 0 1 8 4 8 2 5 6 0 6 Columns 65 through 80 3 0 4 1 1 2 1 1 0 6 2 5 6 4 5 4 Columns 81 through 96 1 4 8 8 2 2 5 6 4 2 9 0 1 1 1 6 Columns 97 through 112 5 0 9 7 7 0 8 9 9 8 7 5 1 3 1 0 Columns 113 through 128 9 3 2 3 4 6 0 8 5 8 3 4 0 1 6 3 Columns 129 through 144 8 1 9 5 7 9 2 4 4 7 8 1 1 3 0 5 Columns 145 through 160 3 1 2 9 6 4 9 1 7 7 5 1 5 2 1 2 Columns 161 through 176 8 0 2 0 4 0 8 1 0 3 4 1 9 3 2 0 Columns 177 through 192 2 0 5 7 6 0 0 7 9 5 1 8 3 2 7 0 Columns 193 through 208 0 6 6 5 7 7 7 2 6 5 3 0 7 3 6 7 Columns 209 through 224 1 1 5 4 8 7 7 0 0 0 7 9 6 1 7 1 Columns 225 through 240 1 6 3 6 7 5 7 2 7 9 8 0 3 3 6 5 Columns 241 through 256 7 3 2 0 7 2 3 5 2 6 4 1 7 1 2 2 Columns 257 through 272 5 0 4 1 1 7 2 6 9 4 6 7 4 6 1 9 Columns 273 through 288 1 2 7 4 7 3 2 0 6 4 4 6 0 3 7 6 Columns 289 through 304 1 1 0 0 4 6 7 5 1 6 1 1 0 1 1 1 Columns 305 through 320 3 3 2 2 8 7 5 1 2 0 9 7 5 3 1 6 Columns 321 through 336 9 1 2 3 0 6 4 9 4 6 1 3 1 7 8 3 Columns 337 through 352 6 2 5 8 5 3 2 4 4 3 5 7 4 4 1 0 Columns 353 through 368 2 3 6 9 9 4 2 7 7 7 7 1 6 4 2 0 Columns 369 through 384 8 1 1 6 8 5 7 1 9 5 6 0 8 7 1 5 Columns 385 through 400 3 5 3 4 1 2 0 9 6 9 1 9 7 5 4 2 Columns 401 through 416 7 2 0 7 6 7 6 4 3 8 3 8 7 8 5 6 Columns 417 through 432 9 4 0 8 6 3 9 2 6 6 3 1 0 4 1 7 Columns 433 through 448 3 8 7 5 1 9 2 9 2 3 0 6 1 0 7 3 Columns 449 through 464 6 3 6 0 9 8 7 8 3 6 5 5 2 2 4 2 Columns 465 through 480 8 9 0 5 0 8 9 0 9 0 6 7 5 8 8 6 Columns 481 through 496 1 2 1 0 1 6 9 3 4 9 9 6 9 7 3 6 Columns 497 through 512 2 2 6 5 4 6 7 5 5 5 5 0 7 9 3 9 Columns 513 through 528 3 8 4 4 2 1 3 7 7 6 0 8 9 7 0 3 Columns 529 through 544 7 7 2 2 6 4 6 2 1 8 7 9 1 1 0 4 Columns 545 through 560 1 8 0 0 5 7 3 1 3 2 5 9 6 1 3 0 Columns 561 through 576 5 4 9 8 4 8 1 3 9 9 7 6 3 9 1 7 Columns 577 through 592 6 8 3 7 8 3 5 9 5 3 6 3 7 4 4 6 Columns 593 through 608 9 3 8 7 9 0 3 6 2 2 7 6 5 6 0 3 Columns 609 through 624 4 2 7 8 2 7 1 8 1 5 3 8 5 4 8 3 Columns 625 through 640 4 9 0 9 1 6 5 6 3 6 8 0 0 9 6 2 Columns 641 through 656 4 1 2 2 3 1 3 1 8 0 9 3 0 3 7 7 Columns 657 through 672 5 6 8 0 3 0 1 7 7 8 5 0 9 8 2 5 Columns 673 through 688 9 7 8 4 4 5 2 7 5 6 3 1 4 3 7 7 Columns 689 through 704 6 1 0 5 3 9 9 2 8 8 5 8 9 5 7 5 Columns 705 through 720 0 4 6 5 3 9 8 8 3 5 8 9 6 2 6 0 Columns 721 through 736 4 6 9 8 4 7 4 9 9 8 3 4 2 7 8 9 Columns 737 through 752 5 5 1 8 4 2 8 7 8 2 6 6 1 4 2 7 Columns 753 through 768 2 8 8 3 4 6 8 6 5 3 4 7 8 7 0 6 Columns 769 through 784 4 4 1 8 3 2 3 3 5 5 3 3 5 6 9 7 Columns 785 through 800 4 8 1 0 0 1 3 3 0 5 0 1 6 8 9 5 Columns 801 through 816 9 5 5 3 4 4 0 8 0 4 8 3 6 8 8 9 Columns 817 through 832 1 2 8 5 5 6 8 5 2 4 4 9 6 6 7 3 Columns 833 through 848 5 5 1 5 6 4 8 7 3 4 3 7 7 4 6 9 Columns 849 through 864 7 7 1 3 5 4 0 2 8 0 8 0 6 5 2 5 Columns 865 through 880 1 6 5 0 0 1 0 4 8 6 5 8 0 9 1 5 Columns 881 through 896 1 5 0 7 8 9 9 5 2 1 5 5 7 0 6 5 Columns 897 through 912 1 9 5 4 9 6 4 8 5 5 6 3 2 5 8 4 Columns 913 through 928 1 4 3 4 8 4 3 3 1 2 0 4 2 2 4 1 Columns 929 through 944 4 7 2 7 0 3 0 2 0 1 1 2 1 1 5 9 Columns 945 through 960 9 2 4 3 5 2 0 4 1 0 9 4 9 7 0 6 Columns 961 through 976 7 6 5 2 7 2 3 8 8 4 3 6 9 9 5 3 Columns 977 through 992 8 4 9 0 5 7 1 3 1 3 4 5 0 5 2 2 Columns 993 through 1000 2 1 9 9 8 7 1 3