Cody

# Problem 1164. Sum the Digits of a Number

Solution 1820913

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 = 49 s = 99 s = 150 s = 202 s = 255 s = 309 s = 364 s = 420 s = 477

Assertion failed.

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

s = 49 s = 100 s = 153 s = 208 s = 265

Assertion failed.

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

s = 49 s = 106 s = 163

Assertion failed.

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

s = 49 s = 106 s = 163 s = 220 s = 277 s = 334 s = 391 s = 448 s = 505 s = 562 s = 619 s = 676 s = 733 s = 790 s = 847 s = 904 s = 961 s = 1018 s = 1075 s = 1132 s = 1189 s = 1246 s = 1303

Assertion failed.

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

s = 49 s = 97 s = 148 s = 202 s = 256 s = 309 s = 361 s = 411 s = 464 s = 519 s = 574 s = 627 s = 682 s = 736 s = 785 s = 838 s = 889 s = 937 s = 986 s = 1035 s = 1089 s = 1141 s = 1195 s = 1245 s = 1293 s = 1346 s = 1396 s = 1453 s = 1510 s = 1561 s = 1609 s = 1663 s = 1719 s = 1776 s = 1824 s = 1876 s = 1929 s = 1983 s = 2038 s = 2092 s = 2147 s = 2198 s = 2251 s = 2300 s = 2348 s = 2405 s = 2455 s = 2508 s = 2565 s = 2614 s = 2663 s = 2714 s = 2771 s = 2822 s = 2872 s = 2921 s = 2972 s = 3023 s = 3072 s = 3124 s = 3172 s = 3226 s = 3274 s = 3327 s = 3382 s = 3432 s = 3484 s = 3537 s = 3585 s = 3637 s = 3691 s = 3741 s = 3797 s = 3854 s = 3910 s = 3963 s = 4013 s = 4068 s = 4118 s = 4175 s = 4229 s = 4283 s = 4332 s = 4380 s = 4430 s = 4486 s = 4543 s = 4597 s = 4652 s = 4702 s = 4755 s = 4811 s = 4863 s = 4920 s = 4968 s = 5019 s = 5072 s = 5120 s = 5175 s = 5228

Assertion failed.

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

s = 55 s = 107 s = 155 s = 205 s = 254 s = 304 s = 356 s = 409 s = 461 s = 517 s = 570 s = 627 s = 681 s = 738 s = 788 s = 842 s = 892 s = 946 s = 1000 s = 1048 s = 1098 s = 1148 s = 1202 s = 1258 s = 1309 s = 1364 s = 1418 s = 1466 s = 1520 s = 1571 s = 1628 s = 1676 s = 1728 s = 1780 s = 1832 s = 1887 s = 1938 s = 1993 s = 2045 s = 2093 s = 2142 s = 2197 s = 2249 s = 2298 s = 2349 s = 2403 s = 2452 s = 2507 s = 2557 s = 2614 s = 2664 s = 2719 s = 2768 s = 2818 s = 2866 s = 2919 s = 2973 s = 3026 s = 3078 s = 3132 s = 3186 s = 3240 s = 3294 s = 3351 s = 3401 s = 3456 s = 3506 s = 3555 s = 3609 s = 3661 s = 3713 s = 3767 s = 3822 s = 3873 s = 3927 s = 3979 s = 4035 s = 4091 s = 4141 s = 4195 s = 4248 s = 4301 s = 4357 s = 4407 s = 4458 s = 4507 s = 4564 s = 4618 s = 4670 s = 4724 s = 4777 s = 4831 s = 4884 s = 4939 s = 4992 s = 5049 s = 5099 s = 5148 s = 5197 s = 5245 s = 5297 s = 5349 s = 5400 s = 5455 s = 5509 s = 5564 s = 5621 s = 5678 s = 5727 s = 5776 s = 5830 s = 5878 s = 5931 s = 5984 s = 6040 s = 6092 s = 6143 s = 6197 s = 6252 s = 6305 s = 6356 s = 6405 s = 6458 s = 6508 s = 6556 s = 6611 s = 6661 s = 6713 s = 6767 s = 6818 s = 6873 s = 6924 s = 6978 s = 7033 s = 7085 s = 7133 s = 7184 s = 7236 s = 7286 s = 7335 s = 7391 s = 7443 s = 7499 s = 7550 s = 7605 s = 7656 s = 7712 s = 7767 s = 7818 s = 7868 s = 7923 s = 7980 s = 8031 s = 8085 s = 8137 s = 8193 s = 8248 s = 8297 s = 8353 s = 8410 s = 8463 s = 8519 s = 8572 s = 8621 s = 8670 s = 8722 s = 8777 s = 8833 s = 8888 s = 8939 s = 8992 s = 9040 s = 9089 s = 9138 s = 9192 s = 9244 s = 9293 s = 9345 s = 9394 s = 9442 s = 9498 s = 9551 s = 9608 s = 9662 s = 9715 s = 9771 s = 9827 s = 9884 s = 9932 s = 9988 s = 10042 s = 10099 s = 10152 s = 10204 s = 10260 s = 10310 s = 10362 s = 10419 s = 10472 s = 10528

Assertion failed.

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

s = 53 s = 109 s = 162 s = 211 s = 260 s = 312 s = 367 s = 423 s = 478 s = 529 s = 582 s = 630 s = 679 s = 728 s = 782 s = 834 s = 883 s = 935 s = 984 s = 1032 s = 1088 s = 1141 s = 1198 s = 1252 s = 1305 s = 1361 s = 1417 s = 1474 s = 1522 s = 1578 s = 1632 s = 1689 s = 1742 s = 1794 s = 1850 s = 1900 s = 1952 s = 2009 s = 2062 s = 2118 s = 2173 s = 2226 s = 2276 s = 2330 s = 2378 s = 2432 s = 2486 s = 2541 s = 2597 s = 2654 s = 2709 s = 2762 s = 2819 s = 2872 s = 2920 s = 2969 s = 3025 s = 3077 s = 3133 s = 3183 s = 3236 s = 3290 s = 3338 s = 3392 s = 3443 s = 3491 s = 3543 s = 3592 s = 3641 s = 3691 s = 3740 s = 3789 s = 3837 s = 3891 s = 3941 s = 3994 s = 4048 s = 4100 s = 4153 s = 4205 s = 4254 s = 4306 s = 4362 s = 4418 s = 4468 s = 4518 s = 4571 s = 4625 s = 4677 s = 4727 s = 4784 s = 4832 s = 4881 s = 4930 s = 4979 s = 5033 s = 5086 s = 5134 s = 5191 s = 5246 s = 5301 s = 5349 s = 5405 s = 5462 s = 5519 s = 5575 s = 5630 s = 5683 s = 5732 s = 5783 s = 5832 s = 5880 s = 5937 s = 5988 s = 6038 s = 6089 s = 6141 s = 6195 s = 6243 s = 6299 s = 6352 s = 6408 s = 6459 s = 6511 s = 6559 s = 6608 s = 6662 s = 6713 s = 6769 s = 6818 s = 6875 s = 6928 s = 6983 s = 7040 s = 7090 s = 7142 s = 7194 s = 7249 s = 7305 s = 7354 s = 7403 s = 7454 s = 7502 s = 7555 s = 7606 s = 7655 s = 7705 s = 7762 s = 7816 s = 7868 s = 7925 s = 7974 s = 8029 s = 8084 s = 8137 s = 8186 s = 8239 s = 8289 s = 8338 s = 8388 s = 8444 s = 8492 s = 8542 s = 8590 s = 8642 s = 8690 s = 8746 s = 8795 s = 8843 s = 8894 s = 8946 s = 8995 s = 9052 s = 9103 s = 9153 s = 9201 s = 9251 s = 9299 s = 9352 s = 9407 s = 9461 s = 9509 s = 9557 s = 9612 s = 9669 s = 9722 s = 9771 s = 9827 s = 9878 s = 9928 s = 9983 s = 10031 s = 10079 s = 10133 s = 10187 s = 10240 s = 10295 s = 10350 s = 10405 s = 10455 s = 10509 s = 10562 s = 10613 s = 10661 s = 10716 s = 10767 s = 10821 s = 10876 s = 10925 s = 10974 s = 11027 s = 11079 s = 11135 s = 11190 s = 11245 s = 11293 s = 11341 s = 11389 s = 11444 s = 11501 s = 11555 s = 11604 s = 11659 s = 11708 s = 11757 s = 11811 s = 11862 s = 11916 s = 11971 s = 12024 s = 12079 s = 12129 s = 12184 s = 12241 s = 12297 s = 12345 s = 12396 s = 12447 s = 12501 s = 12554 s = 12609 s = 12660 s = 12710 s = 12758 s = 12813 s = 12863 s = 12914 s = 12967 s = 13017 s = 13071 s = 13123 s = 13172 s = 13227 s = 13276 s = 13326 s = 13376 s = 13429 s = 13477 s = 13529 s = 13578 s = 13627 s = 13682 s = 13732 s = 13786 s = 13843 s = 13895 s = 13949 s = 14004 s = 14056 s = 14110 s = 14159 s = 14216 s = 14265 s = 14315 s = 14370 s = 14422 s = 14477 s = 14528 s = 14578 s = 14626 s = 14680 s = 14732 s = 14784 s = 14838 s = 14886 s = 14937 s = 14992 s = 15046 s = 15095 s = 15144 s = 15192 s = 15240 s = 15292 s = 15346 s = 15401 s = 15454 s = 15503 s = 15557 s = 15606 s = 15655 s = 15703 s = 15752 s = 15801 s = 15850 s = 15901 s = 15952 s = 16002 s = 16052 s = 16108 s = 16163 s = 16216 s = 16265 s = 16315 s = 16363 s = 16420 s = 16475 s = 16528 s = 16579 s = 16628 s = 16682 s = 16739 s = 16788 s = 16838 s = 16889 s = 16937 s = 16991 s = 17043 s = 17100 s = 17152 s = 17206 s = 17255 s = 17306 s = 17355 s = 17410 s = 17466 s = 17517 s = 17571 s = 17621 s = 17674 s = 17730 s = 17783 s = 17834 s = 17884 s = 17936 s = 17988 s = 18039 s = 18092 s = 18147 s = 18199 s = 18251 s = 18300 s = 18348 s = 18398 s = 18449 s = 18503 s = 18560 s = 18617 s = 18669 s = 18719 s = 18774 s = 18829 s = 18884 s = 18939 s = 18988 s = 19042 s = 19094 s = 19144 s = 19192 s = 19248 s = 19297 s = 19346 s = 19400 s = 19456 s = 19509 s = 19564 s = 19613 s = 19670 s = 19723 s = 19777 s = 19825 s = 19881 s = 19936 s = 19985 s = 20038 s = 20089 s = 20142 s = 20193 s = 20245 s = 20294 s = 20344 s = 20392 s = 20449 s = 20503 s = 20560 s = 20609 s = 20666 s = 20721 s = 20774 s = 20826 s = 20876 s = 20931 s = 20981 s = 21029 s = 21084 s = 21138 s = 21193 s = 21247 s = 21299 s = 21350 s = 21406 s = 21457 s = 21513 s = 21568 s = 21624 s = 21677 s = 21731 s = 21788 s = 21840 s = 21888 s = 21944 s = 21998 s = 22049 s = 22106 s = 22156 s = 22210 s = 22264 s = 22315 s = 22364 s = 22412 s = 22464 s = 22513 s = 22568 s = 22619 s = 22675 s = 22730 s = 22783 s = 22832 s = 22889 s = 22939 s = 22996 s = 23046 s = 23097 s = 23145 s = 23199 s = 23248 s = 23296 s = 23351 s = 23402 s = 23456 s = 23507 s = 23561 s = 23609 s = 23666 s = 23722 s = 23777 s = 23833 s = 23884 s = 23938 s = 23991 s = 24044 s = 24094 s = 24144 s = 24196 s = 24246 s = 24302 s = 24359 s = 24407 s = 24460 s = 24508 s = 24564 s = 24621 s = 24669 s = 24726 s = 24774 s = 24828 s = 24883 s = 24936 s = 24992 s = 25048 s = 25102 s = 25151 s = 25201 s = 25250 s = 25298 s = 25347 s = 25401 s = 25458 s = 25509 s = 25561 s = 25618 s = 25675 s = 25729 s = 25786 s = 25841 s = 25892 s = 25946 s = 25996 s = 26046 s = 26100 s = 26153 s = 26205 s = 26259 s = 26314 s = 26367 s = 26420 s = 26...

Assertion failed.

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

s = 57 s = 105 s = 161 s = 212 s = 264 s = 317 s = 374 s = 422 s = 478 s = 528 s = 579 s = 631 s = 688 s = 744 s = 799 s = 849 s = 900 s = 952 s = 1005 s = 1061 s = 1118 s = 1173 s = 1224 s = 1276 s = 1329 s = 1386 s = 1435 s = 1490 s = 1540 s = 1592 s = 1645 s = 1702 s = 1758 s = 1813 s = 1862 s = 1912 s = 1963 s = 2015 s = 2068 s = 2125 s = 2181 s = 2236 s = 2287 s = 2339 s = 2392 s = 2442 s = 2497 s = 2548 s = 2600 s = 2655 s = 2705 s = 2754 s = 2805 s = 2857 s = 2914 s = 2970 s = 3025 s = 3074 s = 3125 s = 3177 s = 3230 s = 3286 s = 3343 s = 3398 s = 3452 s = 3504 s = 3555 s = 3608 s = 3665 s = 3720 s = 3769 s = 3819 s = 3871 s = 3924 s = 3981 s = 4029 s = 4085 s = 4140 s = 4189 s = 4239 s = 4291 s = 4344 s = 4400 s = 4455 s = 4505 s = 4554 s = 4605 s = 4657 s = 4710 s = 4766 s = 4815 s = 4867 s = 4924 s = 4977 s = 5032 s = 5086 s = 5137 s = 5189 s = 5242 s = 5299 s = 5348 s = 5403 s = 5455 s = 5509 s = 5558 s = 5615 s = 5671 s = 5721 s = 5773 s = 5826 s = 5879 s = 5935 s = 5988 s = 6037 s = 6086 s = 6138 s = 6193 s = 6249 s = 6304 s = 6355 s = 6408 s = 6456 s = 6505 s = 6554 s = 6608 s = 6660 s = 6709 s = 6761 s = 6810 s = 6858 s = 6914 s = 6967 s = 7024 s = 7078 s = 7131 s = 7187 s = 7243 s = 7300 s = 7348 s = 7404 s = 7458 s = 7515 s = 7568 s = 7620 s = 7676 s = 7726 s = 7778 s = 7835 s = 7888 s = 7944 s = 7999 s = 8052 s = 8102 s = 8156 s = 8204 s = 8258 s = 8312 s = 8367 s = 8423 s = 8480 s = 8535 s = 8588 s = 8645 s = 8698 s = 8746 s = 8795 s = 8851 s = 8903 s = 8959 s = 9009 s = 9062 s = 9116 s = 9164 s = 9218 s = 9269 s = 9317 s = 9369 s = 9418 s = 9467 s = 9517 s = 9566 s = 9615 s = 9663 s = 9717 s = 9767 s = 9820 s = 9874 s = 9926 s = 9979 s = 10031 s = 10080 s = 10132 s = 10188 s = 10244 s = 10294 s = 10344 s = 10397 s = 10451 s = 10503 s = 10553 s = 10610 s = 10658 s = 10707 s = 10756 s = 10805 s = 10859 s = 10912 s = 10960 s = 11017 s = 11072 s = 11127 s = 11175 s = 11231 s = 11288 s = 11345 s = 11401 s = 11456 s = 11509 s = 11558 s = 11609 s = 11658 s = 11706 s = 11763 s = 11814 s = 11864 s = 11915 s = 11967 s = 12021 s = 12069 s = 12125 s = 12178 s = 12234 s = 12285 s = 12337 s = 12385 s = 12434 s = 12488 s = 12539 s = 12595 s = 12644 s = 12701 s = 12754 s = 12809 s = 12866 s = 12916 s = 12968 s = 13020 s = 13075 s = 13131 s = 13180 s = 13229 s = 13280 s = 13328 s = 13381 s = 13432 s = 13481 s = 13531 s = 13588 s = 13642 s = 13694 s = 13751 s = 13800 s = 13855 s = 13910 s = 13963 s = 14012 s = 14065 s = 14115 s = 14164 s = 14214 s = 14270 s = 14318 s = 14368 s = 14416 s = 14468 s = 14516 s = 14572 s = 14621 s = 14669 s = 14720 s = 14772 s = 14821 s = 14878 s = 14929 s = 14979 s = 15027 s = 15077 s = 15125 s = 15178 s = 15233 s = 15287 s = 15335 s = 15383 s = 15438 s = 15495 s = 15548 s = 15597 s = 15653 s = 15704 s = 15754 s = 15809 s = 15857 s = 15905 s = 15959 s = 16013 s = 16066 s = 16121 s = 16176 s = 16231 s = 16281 s = 16335 s = 16388 s = 16439 s = 16487 s = 16542 s = 16593 s = 16647 s = 16702 s = 16751 s = 16800 s = 16853 s = 16905 s = 16961 s = 17016 s = 17071 s = 17119 s = 17167 s = 17215 s = 17270 s = 17327 s = 17381 s = 17430 s = 17485 s = 17534 s = 17583 s = 17637 s = 17688 s = 17742 s = 17797 s = 17850 s = 17905 s = 17955 s = 18010 s = 18067 s = 18123 s = 18171 s = 18222 s = 18273 s = 18327 s = 18380 s = 18435 s = 18486 s = 18536 s = 18584 s = 18639 s = 18689 s = 18740 s = 18793 s = 18843 s = 18897 s = 18949 s = 18998 s = 19053 s = 19102 s = 19152 s = 19202 s = 19255 s = 19303 s = 19355 s = 19404 s = 19453 s = 19508 s = 19558 s = 19612 s = 19669 s = 19721 s = 19775 s = 19830 s = 19882 s = 19936 s = 19985 s = 20042 s = 20091 s = 20141 s = 20196 s = 20248 s = 20303 s = 20354 s = 20404 s = 20452 s = 20506 s = 20558 s = 20610 s = 20664 s = 20712 s = 20763 s = 20818 s = 20872 s = 20921 s = 20970 s = 21018 s = 21066 s = 21118 s = 21172 s = 21227 s = 21280 s = 21329 s = 21383 s = 21432 s = 21481 s = 21529 s = 21578 s = 21627 s = 21676 s = 21727 s = 21778 s = 21828 s = 21878 s = 21934 s = 21989 s = 22042 s = 22091 s = 22141 s = 22189 s = 22246 s = 22301 s = 22354 s = 22405 s = 22454 s = 22508 s = 22565 s = 22614 s = 22664 s = 22715 s = 22763 s = 22817 s = 22869 s = 22926 s = 22978 s = 23032 s = 23081 s = 23132 s = 23181 s = 23236 s = 23292 s = 23343 s = 23397 s = 23447 s = 23500 s = 23556 s = 23609 s = 23660 s = 23710 s = 23762 s = 23814 s = 23865 s = 23918 s = 23973 s = 24025 s = 24077 s = 24126 s = 24174 s = 24224 s = 24275 s = 24329 s = 24386 s = 24443 s = 24495 s = 24545 s = 24600 s = 24655 s = 24710 s = 24765 s = 24814 s = 24868 s = 24920 s = 24970 s = 25018 s = 25074 s = 25123 s = 25172 s = 25226 s = 25282 s = 25335 s = 25390 s = 25439 s = 25496 s = 25549 s = 25603 s = 25651 s = 25707 s = 25762 s = 25811 s = 25864 s = 25915 s = 25968 s = 26019 s = 26071 s = 26120 s = 26170 s = 26218 s = 26275 s = 26329 s = 26386 s = 26435 s = ...

Assertion failed.