{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":42412,"title":"Divisible by 10","description":"Pursuant to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 first problem\u003e in this series, this one involves checking for divisibility by 10.\r\n\r\nWrite a function to determine if a number is divisible by 10. This can be done by checking if the last digit is zero.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42411-divisible-by-9 divisible by 9\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42413-divisible-by-11 divisible by 11\u003e.\r\n","description_html":"\u003cp\u003ePursuant to the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003efirst problem\u003c/a\u003e in this series, this one involves checking for divisibility by 10.\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 10. This can be done by checking if the last digit is zero.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42411-divisible-by-9\"\u003edivisible by 9\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42413-divisible-by-11\"\u003edivisible by 11\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_10(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_10.m');\r\nassert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_10(n_str),0))\r\n\r\n%%\r\nn_str = '10';\r\nassert(isequal(divisible_by_10(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_10(n_str),0))\r\n\r\n%%\r\nn_str = '234';\r\nassert(isequal(divisible_by_10(n_str),0))\r\n\r\n%%\r\nn_str = '220';\r\nassert(isequal(divisible_by_10(n_str),1))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_10(n_str),0))\r\n\r\n%%\r\nn_str = '12361230';\r\nassert(isequal(divisible_by_10(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_10(n_str),1))\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904';\r\nassert(isequal(divisible_by_10(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_10(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_10(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_10(n_str),0))\r\n\r\n%%\r\nn_str = '31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632788659361533818279682303019520353018529689957736225994138912497217752834791315155748572424541506959508295331168617278558890750983817546374649393192550604009277016711390098488240128583616035637076601047101819429555961989467678374494482553797747268471040475346462080466842590694912933136770289891521047521620569660240580381501935112533824300355876402474964732639141992726042699227960';\r\nassert(isequal(divisible_by_10(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_10(n_str),0))\r\n\r\n%%\r\nn_str = '10100101010110101010010110101001011010100101001011010100110101001010010110';\r\nassert(isequal(divisible_by_10(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_10(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904';\r\n\t\tassert(isequal(divisible_by_10(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_10(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '220';\r\n\t\tassert(isequal(divisible_by_10(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_10(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '10100101010110101010010110101001011010100101001011010100110101001010010110';\r\n\t\tassert(isequal(divisible_by_10(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_10(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_10(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '13';\r\n\t\tassert(isequal(divisible_by_10(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_10(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_10(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_10(n_str),1))\r\nend\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":376,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T03:34:57.000Z","updated_at":"2026-03-24T13:02:48.000Z","published_at":"2015-06-25T03:34:57.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 10.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 10. This can be done by checking if the last digit is zero.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42411-divisible-by-9\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 9\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42413-divisible-by-11\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 11\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42407,"title":"Divisible by 5","description":"Pursuant to the first problem in this series, this one involves checking for divisibility by 5.\r\nWrite a function to determine if a number is divisible by 5. This can be checked by the following method:\r\nCheck if the last digits is 0 or 5.\r\nPrevious problem: divisible by 4. Next problem: divisible by 6.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 122.433px; display: block; min-width: 0px; padding-block-start: 0px; padding-inline-start: 2px; padding-left: 2px; padding-top: 0px; perspective-origin: 408px 61.2167px; transform-origin: 408px 61.2167px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 47.45px 7.79167px; transform-origin: 47.45px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ePursuant to the\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 1.94167px 7.79167px; transform-origin: 1.94167px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003e\u003cspan style=\"border-block-end-color: rgb(0, 91, 130); border-block-start-color: rgb(0, 91, 130); border-bottom-color: rgb(0, 91, 130); border-inline-end-color: rgb(0, 91, 130); border-inline-start-color: rgb(0, 91, 130); border-left-color: rgb(0, 91, 130); border-right-color: rgb(0, 91, 130); border-top-color: rgb(0, 91, 130); caret-color: rgb(0, 91, 130); color: rgb(0, 91, 130); column-rule-color: rgb(0, 91, 130); outline-color: rgb(0, 91, 130); text-decoration-color: rgb(0, 91, 130); text-emphasis-color: rgb(0, 91, 130); \"\u003e\u003cspan style=\"\"\u003efirst problem\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 184.767px 7.79167px; transform-origin: 184.767px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e in this series, this one involves checking for divisibility by 5.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 320.775px 7.79167px; transform-origin: 320.775px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to determine if a number is divisible by 5. This can be checked by the following method:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 20.4333px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: decimal; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 391px 10.2167px; transform-origin: 391px 10.2167px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 96.8417px 7.79167px; transform-origin: 96.8417px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eCheck if the last digits is 0 or 5.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 56.4083px 7.79167px; transform-origin: 56.4083px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ePrevious problem:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 1.94167px 7.79167px; transform-origin: 1.94167px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"http://www.mathworks.com/matlabcentral/cody/problems/42406-divisible-by-4\"\u003e\u003cspan style=\"border-block-end-color: rgb(0, 91, 130); border-block-start-color: rgb(0, 91, 130); border-bottom-color: rgb(0, 91, 130); border-inline-end-color: rgb(0, 91, 130); border-inline-start-color: rgb(0, 91, 130); border-left-color: rgb(0, 91, 130); border-right-color: rgb(0, 91, 130); border-top-color: rgb(0, 91, 130); caret-color: rgb(0, 91, 130); color: rgb(0, 91, 130); column-rule-color: rgb(0, 91, 130); outline-color: rgb(0, 91, 130); text-decoration-color: rgb(0, 91, 130); text-emphasis-color: rgb(0, 91, 130); \"\u003e\u003cspan style=\"\"\u003edivisible by 4\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 47.45px 7.79167px; transform-origin: 47.45px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. Next problem:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 1.94167px 7.79167px; transform-origin: 1.94167px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"http://www.mathworks.com/matlabcentral/cody/problems/42408-divisible-by-6\"\u003e\u003cspan style=\"border-block-end-color: rgb(0, 91, 130); border-block-start-color: rgb(0, 91, 130); border-bottom-color: rgb(0, 91, 130); border-inline-end-color: rgb(0, 91, 130); border-inline-start-color: rgb(0, 91, 130); border-left-color: rgb(0, 91, 130); border-right-color: rgb(0, 91, 130); border-top-color: rgb(0, 91, 130); caret-color: rgb(0, 91, 130); color: rgb(0, 91, 130); column-rule-color: rgb(0, 91, 130); outline-color: rgb(0, 91, 130); text-decoration-color: rgb(0, 91, 130); text-emphasis-color: rgb(0, 91, 130); \"\u003e\u003cspan style=\"\"\u003edivisible by 6\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 1.94167px 7.79167px; transform-origin: 1.94167px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [tf] = divisible_by_5(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_5.m');\r\nassert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\nassert(isempty(strfind(filetext, 'regexp ''')),'regexp hacks forbidden')\r\n%Last assert added by Dyuman Joshi on 02/01/2026\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_5(n_str),0))\r\n\r\n%%\r\nn_str = '13';\r\nassert(isequal(divisible_by_5(n_str),0))\r\n\r\n%%\r\nn_str = '225';\r\nassert(isequal(divisible_by_5(n_str),1))\r\n\r\n%%\r\nn_str = '232';\r\nassert(isequal(divisible_by_5(n_str),0))\r\n\r\n%%\r\nn_str = '223';\r\nassert(isequal(divisible_by_5(n_str),0))\r\n\r\n%%\r\nn_str = '1236125';\r\nassert(isequal(divisible_by_5(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_5(n_str),1))\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\nassert(isequal(divisible_by_5(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_5(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_5(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_5(n_str),0))\r\n\r\n%%\r\nn_str = '10100101010110101010010110101001011010100101001011010100110101001010';\r\nassert(isequal(divisible_by_5(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_5(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\n\t\tassert(isequal(divisible_by_5(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_5(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '225';\r\n\t\tassert(isequal(divisible_by_5(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '10100101010110101010010110101001011010100101001011010100110101001010';\r\n\t\tassert(isequal(divisible_by_5(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_5(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_5(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_5(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '13';\r\n\t\tassert(isequal(divisible_by_5(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_5(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_5(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_5(n_str),1))\r\nend","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":26769,"edited_by":223089,"edited_at":"2026-01-02T16:52:49.000Z","deleted_by":null,"deleted_at":null,"solvers_count":495,"test_suite_updated_at":"2026-01-02T16:52:49.000Z","rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T02:41:14.000Z","updated_at":"2026-03-24T09:37:28.000Z","published_at":"2015-06-25T02:41:14.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 5.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 5. This can be checked by the following method:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCheck if the last digits is 0 or 5.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42406-divisible-by-4\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 4\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42408-divisible-by-6\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 6\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":42404,"title":"Divisible by 2","description":"This is the first problem in a set of \"divisible by x\" problems. You will be provided a number as a string and the function you write must return whether or not that number is divisible by x.\r\n\r\nRather than allowing you to use an easy way out, such as the modulus function, division and checking the result against its rounded value, Java functions, etc., you get to learn and apply integer divisibility rules. For reference, some divisibility conditions for integers are listed \u003chttp://en.wikipedia.org/wiki/Divisibility_rule here\u003e. Other such references are also available elsewhere on the internet.\r\n\r\nThere are two benefits to approaching divisibility in this manner: first, you learn neat divisibility tricks that you can use in your head or on paper for large numbers and, second, you program a routine capable of determining divisibility for arbitrarily large numbers, for which existing precision fails. *_So, to begin..._*\r\n\r\nWrite a function to determine if a number is divisible by 2. This will be the case if its last digit is even.\r\n\r\n(This problem blocks a range of functions in the first test case so that you must use one of the supplied methods; some of these restrictions will be lifted for later problems in the series.)\r\n\r\nNext problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3 divisible by 3\u003e.","description_html":"\u003cp\u003eThis is the first problem in a set of \"divisible by x\" problems. You will be provided a number as a string and the function you write must return whether or not that number is divisible by x.\u003c/p\u003e\u003cp\u003eRather than allowing you to use an easy way out, such as the modulus function, division and checking the result against its rounded value, Java functions, etc., you get to learn and apply integer divisibility rules. For reference, some divisibility conditions for integers are listed \u003ca href = \"http://en.wikipedia.org/wiki/Divisibility_rule\"\u003ehere\u003c/a\u003e. Other such references are also available elsewhere on the internet.\u003c/p\u003e\u003cp\u003eThere are two benefits to approaching divisibility in this manner: first, you learn neat divisibility tricks that you can use in your head or on paper for large numbers and, second, you program a routine capable of determining divisibility for arbitrarily large numbers, for which existing precision fails. \u003cb\u003e\u003ci\u003eSo, to begin...\u003c/i\u003e\u003c/b\u003e\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 2. This will be the case if its last digit is even.\u003c/p\u003e\u003cp\u003e(This problem blocks a range of functions in the first test case so that you must use one of the supplied methods; some of these restrictions will be lifted for later problems in the series.)\u003c/p\u003e\u003cp\u003eNext problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\"\u003edivisible by 3\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_2(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_2.m');\r\nassert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'factor')),'factor() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_2(n_str),1))\r\n\r\n%%\r\nn_str = '13';\r\nassert(isequal(divisible_by_2(n_str),0))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_2(n_str),1))\r\n\r\n%%\r\nn_str = '232';\r\nassert(isequal(divisible_by_2(n_str),1))\r\n\r\n%%\r\nn_str = '223';\r\nassert(isequal(divisible_by_2(n_str),0))\r\n\r\n%%\r\nn_str = '1236127';\r\nassert(isequal(divisible_by_2(n_str),0))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_2(n_str),1))\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\nassert(isequal(divisible_by_2(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_2(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_2(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_2(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_2(n_str),0))\r\n\r\n%% anti-cheating test\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '222';\r\n\t\tassert(isequal(divisible_by_2(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\n\t\tassert(isequal(divisible_by_2(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '1236127';\r\n\t\tassert(isequal(divisible_by_2(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_2(n_str),1))\r\nend\r\n\r\n%% anti-cheating test\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_2(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_2(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_2(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '223';\r\n\t\tassert(isequal(divisible_by_2(n_str),0))\r\nend\r\n\r\n%% anti-cheating test\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '1236127';\r\n\t\tassert(isequal(divisible_by_2(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_2(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '222';\r\n\t\tassert(isequal(divisible_by_2(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\n\t\tassert(isequal(divisible_by_2(n_str),1))\r\nend","published":true,"deleted":false,"likes_count":10,"comments_count":8,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":616,"test_suite_updated_at":"2017-04-19T17:42:44.000Z","rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T02:14:54.000Z","updated_at":"2026-03-24T09:42:10.000Z","published_at":"2015-06-25T02:14:54.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is the first problem in a set of \\\"divisible by x\\\" problems. You will be provided a number as a string and the function you write must return whether or not that number is divisible by x.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRather than allowing you to use an easy way out, such as the modulus function, division and checking the result against its rounded value, Java functions, etc., you get to learn and apply integer divisibility rules. For reference, some divisibility conditions for integers are listed\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Divisibility_rule\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehere\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Other such references are also available elsewhere on the internet.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are two benefits to approaching divisibility in this manner: first, you learn neat divisibility tricks that you can use in your head or on paper for large numbers and, second, you program a routine capable of determining divisibility for arbitrarily large numbers, for which existing precision fails.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSo, to begin...\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 2. This will be the case if its last digit is even.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(This problem blocks a range of functions in the first test case so that you must use one of the supplied methods; some of these restrictions will be lifted for later problems in the series.)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNext problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42411,"title":"Divisible by 9","description":"Pursuant to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 first problem\u003e in this series, this one involves checking for divisibility by 9.\r\n\r\nWrite a function to determine if a number is divisible by 9. This can be done by the following method:\r\n\r\n# Sum the digits of the number. As with methods for other numbers, this summing step can be applied recursively until a single-digit number results. If the resulting number is divisible by nine, then so is the original number.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42410-divisible-by-8 divisible by 8\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42412-divisible-by-10 divisible by 10\u003e.","description_html":"\u003cp\u003ePursuant to the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003efirst problem\u003c/a\u003e in this series, this one involves checking for divisibility by 9.\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 9. This can be done by the following method:\u003c/p\u003e\u003col\u003e\u003cli\u003eSum the digits of the number. As with methods for other numbers, this summing step can be applied recursively until a single-digit number results. If the resulting number is divisible by nine, then so is the original number.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42410-divisible-by-8\"\u003edivisible by 8\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42412-divisible-by-10\"\u003edivisible by 10\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_9(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_9.m');\r\nassert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_9(n_str),0))\r\n\r\n%%\r\nn_str = '18';\r\nassert(isequal(divisible_by_9(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_9(n_str),0))\r\n\r\n%%\r\nn_str = '234';\r\nassert(isequal(divisible_by_9(n_str),1))\r\n\r\n%%\r\nn_str = '225';\r\nassert(isequal(divisible_by_9(n_str),1))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_9(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_9(n_str),1))\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904';\r\nassert(isequal(divisible_by_9(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_9(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_9(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_9(n_str),0))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_9(n_str),0))\r\n\r\n%%\r\nn_str = '10100101010110101010010110101001011010100101001011010100110101001010010110';\r\nassert(isequal(divisible_by_9(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_9(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904';\r\n\t\tassert(isequal(divisible_by_9(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_9(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '234';\r\n\t\tassert(isequal(divisible_by_9(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_9(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '10100101010110101010010110101001011010100101001011010100110101001010010110';\r\n\t\tassert(isequal(divisible_by_9(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_9(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_9(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '13';\r\n\t\tassert(isequal(divisible_by_9(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_9(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_9(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_9(n_str),1))\r\nend\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":277,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T03:31:29.000Z","updated_at":"2026-03-27T11:38:56.000Z","published_at":"2015-06-25T03:31:29.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 9.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 9. This can be done by the following method:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSum the digits of the number. As with methods for other numbers, this summing step can be applied recursively until a single-digit number results. If the resulting number is divisible by nine, then so is the original number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42410-divisible-by-8\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42412-divisible-by-10\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 10\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42408,"title":"Divisible by 6","description":"Pursuant to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 first problem\u003e in this series, this one involves checking for divisibility by 6.\r\n\r\nWrite a function to determine if a number is divisible by 6. This can be done by checking for \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 divisibility by 2\u003e and \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3 divisibility by 3\u003e. If the number passes both tests, it is also divisible by 6.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5 divisible by 5\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7 divisible by 7\u003e.","description_html":"\u003cp\u003ePursuant to the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003efirst problem\u003c/a\u003e in this series, this one involves checking for divisibility by 6.\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 6. This can be done by checking for \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003edivisibility by 2\u003c/a\u003e and \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\"\u003edivisibility by 3\u003c/a\u003e. If the number passes both tests, it is also divisible by 6.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5\"\u003edivisible by 5\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7\"\u003edivisible by 7\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_6(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_6.m');\r\nassert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_6(n_str),1))\r\n\r\n%%\r\nn_str = '13';\r\nassert(isequal(divisible_by_6(n_str),0))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_6(n_str),1))\r\n\r\n%%\r\nn_str = '232';\r\nassert(isequal(divisible_by_6(n_str),0))\r\n\r\n%%\r\nn_str = '223';\r\nassert(isequal(divisible_by_6(n_str),0))\r\n\r\n%%\r\nn_str = '1236126';\r\nassert(isequal(divisible_by_6(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_6(n_str),1))%\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\nassert(isequal(divisible_by_6(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_6(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_6(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_6(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_6(n_str),0))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_6(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\n\t\tassert(isequal(divisible_by_6(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_6(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '223';\r\n\t\tassert(isequal(divisible_by_6(n_str),0))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_6(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_6(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_6(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_6(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '13';\r\n\t\tassert(isequal(divisible_by_6(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_6(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_6(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_6(n_str),1))\r\nend","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":332,"test_suite_updated_at":"2015-06-25T03:14:53.000Z","rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T02:46:24.000Z","updated_at":"2026-03-24T12:51:01.000Z","published_at":"2015-06-25T02:46:24.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 6.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 6. This can be done by checking for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisibility by 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisibility by 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. If the number passes both tests, it is also divisible by 6.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 7\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42417,"title":"Divisible by 15","description":"Write a function to determine if a number is divisible by 15. If a number is \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3 divisible by 3\u003e and \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5 divisible by 5\u003e, then it is divisible by 15.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42416-divisible-by-14 divisible by 14\u003e. Next problem \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42418-divisible-by-16 divisible by 16\u003e.\r\n","description_html":"\u003cp\u003eWrite a function to determine if a number is divisible by 15. If a number is \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\"\u003edivisible by 3\u003c/a\u003e and \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5\"\u003edivisible by 5\u003c/a\u003e, then it is divisible by 15.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42416-divisible-by-14\"\u003edivisible by 14\u003c/a\u003e. Next problem \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42418-divisible-by-16\"\u003edivisible by 16\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_15(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_15.m');\r\n% assert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_15(n_str),0))\r\n\r\n%%\r\nn_str = '15';\r\nassert(isequal(divisible_by_15(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_15(n_str),0))\r\n\r\n%%\r\nn_str = '225';\r\nassert(isequal(divisible_by_15(n_str),1))\r\n\r\n%%\r\nn_str = '211';\r\nassert(isequal(divisible_by_15(n_str),0))\r\n\r\n%%\r\nn_str = '210';\r\nassert(isequal(divisible_by_15(n_str),1))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_15(n_str),0))\r\n\r\n%%\r\nn_str = '1236120';\r\nassert(isequal(divisible_by_15(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_15(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\nassert(isequal(divisible_by_15(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_15(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\nassert(isequal(divisible_by_15(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_15(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922790';\r\nassert(isequal(divisible_by_15(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_15(n_str),0))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100110';\r\nassert(isequal(divisible_by_15(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_15(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\n\t\tassert(isequal(divisible_by_15(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_15(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '210';\r\n\t\tassert(isequal(divisible_by_15(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_15(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '1010010101011010101001011010100101101010010100101101010011010100110';\r\n\t\tassert(isequal(divisible_by_15(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\n\t\tassert(isequal(divisible_by_15(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_15(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '222';\r\n\t\tassert(isequal(divisible_by_15(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_15(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\n\t\tassert(isequal(divisible_by_15(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_15(n_str),1))\r\nend\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":221,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-26T01:58:40.000Z","updated_at":"2026-03-27T16:43:11.000Z","published_at":"2015-06-26T01:58:40.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 15. If a number is\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, then it is divisible by 15.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42416-divisible-by-14\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 14\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42418-divisible-by-16\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 16\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42406,"title":"Divisible by 4","description":"Pursuant to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 first problem\u003e in this series, this one involves checking for divisibility by 4.\r\n\r\nWrite a function to determine if a number is divisible by 4. This can be checked by a few slightly different methods:\r\n\r\n# Check the last two digits for divisibility by four.\r\n# From the \u003chttps://en.wikipedia.org/wiki/Divisibility_rule wikipedia reference page\u003e: \"If the tens digit is even, the ones digit must be 0, 4, or 8.\r\nIf the tens digit is odd, the ones digit must be 2 or 6.\"\r\n# Check the following sum for divisibility by four: twice the tens digit plus the ones digit.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3 divisible by 3\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5 divisible by 5\u003e.","description_html":"\u003cp\u003ePursuant to the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003efirst problem\u003c/a\u003e in this series, this one involves checking for divisibility by 4.\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 4. This can be checked by a few slightly different methods:\u003c/p\u003e\u003col\u003e\u003cli\u003eCheck the last two digits for divisibility by four.\u003c/li\u003e\u003cli\u003eFrom the \u003ca href = \"https://en.wikipedia.org/wiki/Divisibility_rule\"\u003ewikipedia reference page\u003c/a\u003e: \"If the tens digit is even, the ones digit must be 0, 4, or 8.\r\nIf the tens digit is odd, the ones digit must be 2 or 6.\"\u003c/li\u003e\u003cli\u003eCheck the following sum for divisibility by four: twice the tens digit plus the ones digit.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\"\u003edivisible by 3\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5\"\u003edivisible by 5\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_4(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_4.m');\r\nassert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_4(n_str),1))\r\n\r\n%%\r\nn_str = '13';\r\nassert(isequal(divisible_by_4(n_str),0))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_4(n_str),0))\r\n\r\n%%\r\nn_str = '232';\r\nassert(isequal(divisible_by_4(n_str),1))\r\n\r\n%%\r\nn_str = '223';\r\nassert(isequal(divisible_by_4(n_str),0))\r\n\r\n%%\r\nn_str = '1236127';\r\nassert(isequal(divisible_by_4(n_str),0))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_4(n_str),0))\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\nassert(isequal(divisible_by_4(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_4(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_4(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_4(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_4(n_str),0))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_4(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\n\t\tassert(isequal(divisible_by_4(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_4(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '232';\r\n\t\tassert(isequal(divisible_by_4(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\n\t\tassert(isequal(divisible_by_4(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_4(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_4(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_4(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '13';\r\n\t\tassert(isequal(divisible_by_4(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_4(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_4(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_4(n_str),0))\r\nend","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":373,"test_suite_updated_at":"2015-06-25T03:13:44.000Z","rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T02:35:16.000Z","updated_at":"2026-03-24T10:06:27.000Z","published_at":"2015-06-25T02:35:16.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 4.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 4. This can be checked by a few slightly different methods:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCheck the last two digits for divisibility by four.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFrom the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Divisibility_rule\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ewikipedia reference page\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e: \\\"If the tens digit is even, the ones digit must be 0, 4, or 8.If the tens digit is odd, the ones digit must be 2 or 6.\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCheck the following sum for divisibility by four: twice the tens digit plus the ones digit.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42509,"title":"Divisible by n, Truncated-number Divisors","description":"Some divisors only require a few numbers at the end of the number in question to determine divisibility, no matter how long. Examples include 25, 32, 50, 64, 75, 100, 125, 128, 256, and 512. Notice that this list includes some prime-power divisors (e.g, 25 = 5^2, 32 = 2^5, 125 = 5^3, etc.). Write a function to determine if a given number, provided as a string (n_str), is divisible by the provided divisor. See the test suite for examples and rules for these simple divisors below:\r\n\r\n* 25: The last two digits must be divisible by 25.\r\n* 32: The last five digits must be divisible by 32.\r\n* 50: The last two digits must be 00 or 50.\r\n* 64: The last six digits must be divisible by 64.\r\n* 75: The number must be divisible by 3 (can be done by a \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3 simple sum\u003e) and end in 00, 25, 50, or 75 (last two digits divisible by 25). \r\n* 100: The last two digits must be 00.\r\n* 125: The last three digits must be divisible by 125.\r\n* 128: The last seven digits must be divisible by 128.\r\n* 256: The last eight digits must be divisible by 256.\r\n* 512: The last nine digits must be divisible by 512.\r\n\r\nThe only restriction that remains is Java.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42508-divisible-by-n-prime-divisors-from-20-to-200 Divisible by n, prime divisors from 20 to 200\u003e. Next problem \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42510-divisible-by-n-composite-divisors Divisible by n, Composite Divisors\u003e.","description_html":"\u003cp\u003eSome divisors only require a few numbers at the end of the number in question to determine divisibility, no matter how long. Examples include 25, 32, 50, 64, 75, 100, 125, 128, 256, and 512. Notice that this list includes some prime-power divisors (e.g, 25 = 5^2, 32 = 2^5, 125 = 5^3, etc.). Write a function to determine if a given number, provided as a string (n_str), is divisible by the provided divisor. See the test suite for examples and rules for these simple divisors below:\u003c/p\u003e\u003cul\u003e\u003cli\u003e25: The last two digits must be divisible by 25.\u003c/li\u003e\u003cli\u003e32: The last five digits must be divisible by 32.\u003c/li\u003e\u003cli\u003e50: The last two digits must be 00 or 50.\u003c/li\u003e\u003cli\u003e64: The last six digits must be divisible by 64.\u003c/li\u003e\u003cli\u003e75: The number must be divisible by 3 (can be done by a \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\"\u003esimple sum\u003c/a\u003e) and end in 00, 25, 50, or 75 (last two digits divisible by 25).\u003c/li\u003e\u003cli\u003e100: The last two digits must be 00.\u003c/li\u003e\u003cli\u003e125: The last three digits must be divisible by 125.\u003c/li\u003e\u003cli\u003e128: The last seven digits must be divisible by 128.\u003c/li\u003e\u003cli\u003e256: The last eight digits must be divisible by 256.\u003c/li\u003e\u003cli\u003e512: The last nine digits must be divisible by 512.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe only restriction that remains is Java.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42508-divisible-by-n-prime-divisors-from-20-to-200\"\u003eDivisible by n, prime divisors from 20 to 200\u003c/a\u003e. Next problem \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42510-divisible-by-n-composite-divisors\"\u003eDivisible by n, Composite Divisors\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = truncated_number_divisors(n,n_str)\r\n\r\ntf = 1;\r\n\r\nend","test_suite":"%%\r\nfiletext = fileread('truncated_number_divisors.m');\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn = 25;\r\nn_str = '123456789025';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 25;\r\nn_str = '1234567890250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 25;\r\nn_str = '1234567890250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 32;\r\nn_str = '213546116579874651316984601654958847098406516051320150408460840649084790870510201378465465046760406541654604601561065140637860373703970644065166540616510650165409684098049804165016510320540540645106056501650165709804650860466840650156106165028224';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 32;\r\nn_str = '213546116579874651316984601654958847098406516051320150408460840649084790870510201378465465046760406541654604601561065140637860373703970644065166540616510650165409684098049804165016510320540540645106056501650165709804650860466840650156106165028227';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 50;\r\nn_str = '15668045014654987098045406540500';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 50;\r\nn_str = '50440984098480149540561065106510516501615001';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 50;\r\nn_str = '50440984098480149540561065106510516501615001897241387234587503198417059813645097867234985672307485679813709582304957234897659832746098514949188412929894824924949334949777378994191995216173718811313515141418186186382171646871681436817897678350';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 64;\r\nn_str = '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890404992';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 64;\r\nn_str = '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890404996';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 64;\r\nn_str = '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111489216';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 64;\r\nn_str = '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111489217';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 75;\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789040499175';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 75;\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789040499275';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 100;\r\nn_str = '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890404992750';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 100;\r\nn_str = '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890404992700';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 100;\r\nn_str = '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890404992';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 100;\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789040499200';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 125;\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789040499200125';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 125;\r\nn_str = '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111489216';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 125;\r\nn_str = '111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111114892375';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 128;\r\nn_str = '1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111148923751048576';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 128;\r\nn_str = '1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111148923751048578';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 256;\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904049917516777216';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 256;\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904049917516777210';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 512;\r\nn_str = '10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000134217728';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 512;\r\nn_str = '10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000536870912';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 512;\r\nn_str = '10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000536870914';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":79,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-08-17T21:32:54.000Z","updated_at":"2026-01-11T10:42:54.000Z","published_at":"2015-08-17T21:32:54.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSome divisors only require a few numbers at the end of the number in question to determine divisibility, no matter how long. Examples include 25, 32, 50, 64, 75, 100, 125, 128, 256, and 512. Notice that this list includes some prime-power divisors (e.g, 25 = 5^2, 32 = 2^5, 125 = 5^3, etc.). Write a function to determine if a given number, provided as a string (n_str), is divisible by the provided divisor. See the test suite for examples and rules for these simple divisors below:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e25: The last two digits must be divisible by 25.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e32: The last five digits must be divisible by 32.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e50: The last two digits must be 00 or 50.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e64: The last six digits must be divisible by 64.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e75: The number must be divisible by 3 (can be done by a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esimple sum\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e) and end in 00, 25, 50, or 75 (last two digits divisible by 25).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e100: The last two digits must be 00.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e125: The last three digits must be divisible by 125.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e128: The last seven digits must be divisible by 128.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e256: The last eight digits must be divisible by 256.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e512: The last nine digits must be divisible by 512.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe only restriction that remains is Java.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42508-divisible-by-n-prime-divisors-from-20-to-200\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, prime divisors from 20 to 200\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42510-divisible-by-n-composite-divisors\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, Composite Divisors\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42414,"title":"Divisible by 12","description":"Write a function to determine if a number is divisible by 12. Similar to the number six, this can be done by checking for divisibility of two numbers, in this case, \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3 divisibility by 3\u003e and \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42406-divisible-by-4 divisibility by 4\u003e. If the number passes both tests, it is also divisible by 12.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42413-divisible-by-11 divisible by 11\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42415-divisible-by-13 divisible by 13\u003e.\r\n","description_html":"\u003cp\u003eWrite a function to determine if a number is divisible by 12. Similar to the number six, this can be done by checking for divisibility of two numbers, in this case, \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\"\u003edivisibility by 3\u003c/a\u003e and \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42406-divisible-by-4\"\u003edivisibility by 4\u003c/a\u003e. If the number passes both tests, it is also divisible by 12.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42413-divisible-by-11\"\u003edivisible by 11\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42415-divisible-by-13\"\u003edivisible by 13\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_12(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_12.m');\r\nassert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_12(n_str),1))\r\n\r\n%%\r\nn_str = '11';\r\nassert(isequal(divisible_by_12(n_str),0))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_12(n_str),0))\r\n\r\n%%\r\nn_str = '228';\r\nassert(isequal(divisible_by_12(n_str),1))\r\n\r\n%%\r\nn_str = '242';\r\nassert(isequal(divisible_by_12(n_str),0))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_12(n_str),0))\r\n\r\n%%\r\nn_str = '1236120';\r\nassert(isequal(divisible_by_12(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_12(n_str),0))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\nassert(isequal(divisible_by_12(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_12(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_12(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_12(n_str),1))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922790';\r\nassert(isequal(divisible_by_12(n_str),0))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_12(n_str),0))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_12(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\n\t\tassert(isequal(divisible_by_12(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_12(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '222';\r\n\t\tassert(isequal(divisible_by_12(n_str),0))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_12(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\n\t\tassert(isequal(divisible_by_12(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_12(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_12(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '228';\r\n\t\tassert(isequal(divisible_by_12(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_12(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_12(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_12(n_str),0))\r\nend\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":210,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T03:54:07.000Z","updated_at":"2026-03-27T16:47:41.000Z","published_at":"2015-06-25T03:54:07.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 12. Similar to the number six, this can be done by checking for divisibility of two numbers, in this case,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisibility by 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42406-divisible-by-4\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisibility by 4\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. If the number passes both tests, it is also divisible by 12.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42413-divisible-by-11\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 11\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42415-divisible-by-13\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 13\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42410,"title":"Divisible by 8","description":"Pursuant to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 first problem\u003e in this series, this one involves checking for divisibility by 8.\r\n\r\nWrite a function to determine if a number is divisible by 8. This can be done by the following method:\r\n\r\n# Check the last three digits for divisibility by eight. If that portion of the number is divisible by eight, then so is the original number. That three-digit number can be further reduced by summing four times the hundreds digit, two times the tens digit, and the ones digit. As with methods for other numbers, this factor/sum step can be applied recursively until a single-digit number results.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7 divisible by 7\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42411-divisible-by-9 divisible by 9\u003e.","description_html":"\u003cp\u003ePursuant to the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003efirst problem\u003c/a\u003e in this series, this one involves checking for divisibility by 8.\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 8. This can be done by the following method:\u003c/p\u003e\u003col\u003e\u003cli\u003eCheck the last three digits for divisibility by eight. If that portion of the number is divisible by eight, then so is the original number. That three-digit number can be further reduced by summing four times the hundreds digit, two times the tens digit, and the ones digit. As with methods for other numbers, this factor/sum step can be applied recursively until a single-digit number results.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7\"\u003edivisible by 7\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42411-divisible-by-9\"\u003edivisible by 9\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_8(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_8.m');\r\n%assert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_8(n_str),0))\r\n\r\n%%\r\nn_str = '16';\r\nassert(isequal(divisible_by_8(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_8(n_str),0))\r\n\r\n%%\r\nn_str = '232';\r\nassert(isequal(divisible_by_8(n_str),1))\r\n\r\n%%\r\nn_str = '224';\r\nassert(isequal(divisible_by_8(n_str),1))\r\n\r\n%%\r\nn_str = '1236128';\r\nassert(isequal(divisible_by_8(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_8(n_str),0))%\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904';\r\nassert(isequal(divisible_by_8(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_8(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_8(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_8(n_str),0))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_8(n_str),0))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_8(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904';\r\n\t\tassert(isequal(divisible_by_8(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_8(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '232';\r\n\t\tassert(isequal(divisible_by_8(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_8(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '16';\r\n\t\tassert(isequal(divisible_by_8(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_8(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_8(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '13';\r\n\t\tassert(isequal(divisible_by_8(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_8(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_8(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904';\r\n\t\tassert(isequal(divisible_by_8(n_str),1))\r\nend\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":243,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T03:23:41.000Z","updated_at":"2026-03-27T11:43:47.000Z","published_at":"2015-06-25T03:23:41.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 8.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 8. This can be done by the following method:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCheck the last three digits for divisibility by eight. If that portion of the number is divisible by eight, then so is the original number. That three-digit number can be further reduced by summing four times the hundreds digit, two times the tens digit, and the ones digit. As with methods for other numbers, this factor/sum step can be applied recursively until a single-digit number results.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 7\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42411-divisible-by-9\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 9\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42454,"title":"Divisible by n, prime divisors (including powers)","description":"For this problem, you will be provided an array of numbers (not necessarily in order). Return the array of numbers with only prime divisors (including prime powers) remaining in the array. For example:\r\n\r\n  n = 1:10;\r\n  n_p = [2 3 4 5 7 8 9];\r\n\r\nSince the prime numbers in the 1:10 range are 2, 3, 5, and 7, while the prime powers in this range are 4 (2^2), 8 (2^3), and 9 (3^2). (Ignore one, as it is a trivial case since all integers are divisible by one.) Therefore, you should return the array including both sets joined together and sorted, as shown in the example above.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors Divisible by n, prime vs. composite divisors\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42455-divisible-by-n-prime-divisors-11-13-17-19 Divisible by n, prime divisors - 11, 13, 17, \u0026 19\u003e.","description_html":"\u003cp\u003eFor this problem, you will be provided an array of numbers (not necessarily in order). Return the array of numbers with only prime divisors (including prime powers) remaining in the array. For example:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003en = 1:10;\r\nn_p = [2 3 4 5 7 8 9];\r\n\u003c/pre\u003e\u003cp\u003eSince the prime numbers in the 1:10 range are 2, 3, 5, and 7, while the prime powers in this range are 4 (2^2), 8 (2^3), and 9 (3^2). (Ignore one, as it is a trivial case since all integers are divisible by one.) Therefore, you should return the array including both sets joined together and sorted, as shown in the example above.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors\"\u003eDivisible by n, prime vs. composite divisors\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42455-divisible-by-n-prime-divisors-11-13-17-19\"\u003eDivisible by n, prime divisors - 11, 13, 17, \u0026 19\u003c/a\u003e.\u003c/p\u003e","function_template":"function [n_p] = prime_divisors_incl_powers(n)\r\n\r\nn_p = 1;\r\n\r\nend","test_suite":"%%\r\nn = 1:10;\r\nn_p = [2 3 4 5 7 8 9]; %prime factors (including powers)\r\nassert(isequal(n_p,prime_divisors_incl_powers(n)))\r\n\r\n%%\r\nn = [2:7 12:17 10 42:55 11 19:29];\r\nn_p = [2 3 4 5 7 11 13 16 17 19 23 25 27 29 43 47 49 53]; %prime factors (including powers)\r\nassert(isequal(n_p,prime_divisors_incl_powers(n)))\r\n\r\n%%\r\nn = 1:100;\r\nn_p = [2 3 4 5 7 8 9 11 13 16 17 19 23 25 27 29 31 32 37 41 43 47 49 53 59 61 64 67 71 73 79 81 83 89 97]; %prime factors (including powers)\r\nassert(isequal(n_p,prime_divisors_incl_powers(n)))\r\n\r\n%%\r\nn = 41:59;\r\nn_p = [41 43 47 49 53 59]; %prime factors (including powers)\r\nassert(isequal(n_p,prime_divisors_incl_powers(n)))\r\n\r\n%%\r\nn = 100:200;\r\nn_p = [101 103 107 109 113 121 125 127 128 131 137 139 149 151 157 163 167 169 173 179 181 191 193 197 199]; %prime factors (including powers)\r\nassert(isequal(n_p,prime_divisors_incl_powers(n)))\r\n\r\n%%\r\nn = 1000:1111;\r\nn_p = [1009 1013 1019 1021 1024 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109]; %prime factors (including powers)\r\nassert(isequal(n_p,prime_divisors_incl_powers(n)))\r\n\r\n%% anti-cheating test case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn = 1:10;\r\n\t\tn_p = [2 3 4 5 7 8 9]; %prime factors (including powers)\r\n\tcase 2\r\n\t\tn = 41:59;\r\n\t\tn_p = [41 43 47 49 53 59]; %prime factors (including powers)\r\n\tcase 3\r\n\t\tn = 1:100;\r\n\t\tn_p = [2 3 4 5 7 8 9 11 13 16 17 19 23 25 27 29 31 32 37 41 43 47 49 53 59 61 64 67 71 73 79 81 83 89 97]; %prime factors (including powers)\r\n\tcase 4\r\n\t\tn = [2:7 12:17 10 42:55 11 19:29];\r\n\t\tn_p = [2 3 4 5 7 11 13 16 17 19 23 25 27 29 43 47 49 53];\r\nend\r\nassert(isequal(n_p,prime_divisors_incl_powers(n)))\r\n\r\n%% anti-cheating test case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn = 1:100;\r\n\t\tn_p = [2 3 4 5 7 8 9 11 13 16 17 19 23 25 27 29 31 32 37 41 43 47 49 53 59 61 64 67 71 73 79 81 83 89 97]; %prime factors (including powers)\r\n\tcase 2\r\n\t\tn = [2:7 12:17 10 42:55 11 19:29];\r\n\t\tn_p = [2 3 4 5 7 11 13 16 17 19 23 25 27 29 43 47 49 53];\r\n\tcase 3\r\n\t\tn = 41:59;\r\n\t\tn_p = [41 43 47 49 53 59]; %prime factors (including powers)\r\n\tcase 4\r\n\t\tn = 1000:1111;\r\n\t\tn_p = [1009 1013 1019 1021 1024 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109]; %prime factors (including powers)\r\nend\r\nassert(isequal(n_p,prime_divisors_incl_powers(n)))\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":95,"test_suite_updated_at":"2017-03-20T19:03:08.000Z","rescore_all_solutions":false,"group_id":22,"created_at":"2015-07-09T01:55:28.000Z","updated_at":"2026-01-11T12:28:45.000Z","published_at":"2015-07-09T01:55:28.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor this problem, you will be provided an array of numbers (not necessarily in order). Return the array of numbers with only prime divisors (including prime powers) remaining in the array. For example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[n = 1:10;\\nn_p = [2 3 4 5 7 8 9];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSince the prime numbers in the 1:10 range are 2, 3, 5, and 7, while the prime powers in this range are 4 (2^2), 8 (2^3), and 9 (3^2). (Ignore one, as it is a trivial case since all integers are divisible by one.) Therefore, you should return the array including both sets joined together and sorted, as shown in the example above.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, prime vs. composite divisors\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42455-divisible-by-n-prime-divisors-11-13-17-19\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, prime divisors - 11, 13, 17, \u0026amp; 19\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42413,"title":"Divisible by 11","description":"Pursuant to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 first problem\u003e in this series, this one involves checking for divisibility by 11.\r\n\r\nWrite a function to determine if a number is divisible by 11. Like the number seven, this can be done by a variety of methods. Some are:\r\n\r\n# Form the alternating sum of the digits (e.g., positive even digits and negative odd digits). Apply recursively until a two-digit number results. If that result is divisible by 11, then so is the original number.\r\n# Add the digits of the number in blocks of two from right to left. Apply recursively, as needed, and check for divisibility as stated in the previous method.\r\n# Subtract the last digit from the remaining number (e.g., 649: 64 - 9 = 55). Apply recursion, as needed.\r\n# Add ten times the last digit to the remaining number. Apply recursion, as needed. For example: 737: 73 + 70 = 143: 14 + 30 = 44.\r\n# Etc.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42412-divisible-by-10 divisible by 10\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42414-divisible-by-12 divisible by 12\u003e.\r\n","description_html":"\u003cp\u003ePursuant to the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003efirst problem\u003c/a\u003e in this series, this one involves checking for divisibility by 11.\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 11. Like the number seven, this can be done by a variety of methods. Some are:\u003c/p\u003e\u003col\u003e\u003cli\u003eForm the alternating sum of the digits (e.g., positive even digits and negative odd digits). Apply recursively until a two-digit number results. If that result is divisible by 11, then so is the original number.\u003c/li\u003e\u003cli\u003eAdd the digits of the number in blocks of two from right to left. Apply recursively, as needed, and check for divisibility as stated in the previous method.\u003c/li\u003e\u003cli\u003eSubtract the last digit from the remaining number (e.g., 649: 64 - 9 = 55). Apply recursion, as needed.\u003c/li\u003e\u003cli\u003eAdd ten times the last digit to the remaining number. Apply recursion, as needed. For example: 737: 73 + 70 = 143: 14 + 30 = 44.\u003c/li\u003e\u003cli\u003eEtc.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42412-divisible-by-10\"\u003edivisible by 10\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42414-divisible-by-12\"\u003edivisible by 12\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_11(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_11.m');\r\n%assert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\n%assert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_11(n_str),0))\r\n\r\n%%\r\nn_str = '11';\r\nassert(isequal(divisible_by_11(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_11(n_str),0))\r\n\r\n%%\r\nn_str = '231';\r\nassert(isequal(divisible_by_11(n_str),1))\r\n\r\n%%\r\nn_str = '242';\r\nassert(isequal(divisible_by_11(n_str),1))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_11(n_str),0))\r\n\r\n%%\r\nn_str = '1236125';\r\nassert(isequal(divisible_by_11(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_11(n_str),0))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567881';\r\nassert(isequal(divisible_by_11(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_11(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007';\r\nassert(isequal(divisible_by_11(n_str),1))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_11(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922789';\r\nassert(isequal(divisible_by_11(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_11(n_str),0))\r\n\r\n%%\r\nn_str = '10100101010110101010010110101001011010100101001011010100110101001010010110';\r\nassert(isequal(divisible_by_11(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_11(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567881';\r\n\t\tassert(isequal(divisible_by_11(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_11(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '231';\r\n\t\tassert(isequal(divisible_by_11(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_11(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '10100101010110101010010110101001011010100101001011010100110101001010010110';\r\n\t\tassert(isequal(divisible_by_11(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007';\r\n\t\tassert(isequal(divisible_by_11(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_11(n_str),0))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '242';\r\n\t\tassert(isequal(divisible_by_11(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_11(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007';\r\n\t\tassert(isequal(divisible_by_11(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_11(n_str),0))\r\nend\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":3,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":175,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T03:49:05.000Z","updated_at":"2025-12-29T20:09:06.000Z","published_at":"2015-06-25T03:49:05.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 11.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 11. Like the number seven, this can be done by a variety of methods. Some are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eForm the alternating sum of the digits (e.g., positive even digits and negative odd digits). Apply recursively until a two-digit number results. If that result is divisible by 11, then so is the original number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAdd the digits of the number in blocks of two from right to left. Apply recursively, as needed, and check for divisibility as stated in the previous method.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSubtract the last digit from the remaining number (e.g., 649: 64 - 9 = 55). Apply recursion, as needed.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAdd ten times the last digit to the remaining number. Apply recursion, as needed. For example: 737: 73 + 70 = 143: 14 + 30 = 44.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEtc.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42412-divisible-by-10\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 10\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42414-divisible-by-12\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 12\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42416,"title":"Divisible by 14","description":"Write a function to determine if a number is divisible by 14. If a number is \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 divisible by 2\u003e and \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7 divisible by 7\u003e, then it is divisible by 14.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42415-divisible-by-13 divisible by 13\u003e. Next problem \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42417-divisible-by-15 divisible by 15\u003e.","description_html":"\u003cp\u003eWrite a function to determine if a number is divisible by 14. If a number is \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003edivisible by 2\u003c/a\u003e and \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7\"\u003edivisible by 7\u003c/a\u003e, then it is divisible by 14.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42415-divisible-by-13\"\u003edivisible by 13\u003c/a\u003e. Next problem \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42417-divisible-by-15\"\u003edivisible by 15\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_14(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_14.m');\r\n% assert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_14(n_str),0))\r\n\r\n%%\r\nn_str = '14';\r\nassert(isequal(divisible_by_14(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_14(n_str),0))\r\n\r\n%%\r\nn_str = '224';\r\nassert(isequal(divisible_by_14(n_str),1))\r\n\r\n%%\r\nn_str = '210';\r\nassert(isequal(divisible_by_14(n_str),1))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_14(n_str),0))\r\n\r\n%%\r\nn_str = '1236130';\r\nassert(isequal(divisible_by_14(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_14(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\nassert(isequal(divisible_by_14(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_14(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\nassert(isequal(divisible_by_14(n_str),1))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_14(n_str),1))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922799';\r\nassert(isequal(divisible_by_14(n_str),0))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_14(n_str),0))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100110';\r\nassert(isequal(divisible_by_14(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_14(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\n\t\tassert(isequal(divisible_by_14(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_14(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '210';\r\n\t\tassert(isequal(divisible_by_14(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_14(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '1010010101011010101001011010100101101010010100101101010011010100110';\r\n\t\tassert(isequal(divisible_by_14(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\n\t\tassert(isequal(divisible_by_14(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_14(n_str),0))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '222';\r\n\t\tassert(isequal(divisible_by_14(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_14(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\n\t\tassert(isequal(divisible_by_14(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_14(n_str),1))\r\nend\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":153,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-26T01:47:26.000Z","updated_at":"2026-03-27T16:40:51.000Z","published_at":"2015-06-26T01:47:26.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 14. If a number is\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 7\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, then it is divisible by 14.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42415-divisible-by-13\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 13\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42417-divisible-by-15\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 15\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42418,"title":"Divisible by 16","description":"Write a function to determine if a number is divisible by 16. This can be done by a few different methods. Here are two:\r\n\r\n# If a number has four or more digits, take the last three digits. Add eight to it if the thousands digit in the original number is odd (zero if even). If this three-digit number is divisible by 16, so is the original number. The resulting number can also be reduced by the following method.\r\n# Take the last two digits and add them to four times the remaining number. Apply this method recursively until a two-digit number remains. As usual, if the resulting number is divisible by 16, then so is the original number.\r\n\r\nA few of the function restrictions have been lifted.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42417-divisible-by-15 divisible by 15\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors divisible by n, prime vs. composite divisors\u003e.","description_html":"\u003cp\u003eWrite a function to determine if a number is divisible by 16. This can be done by a few different methods. Here are two:\u003c/p\u003e\u003col\u003e\u003cli\u003eIf a number has four or more digits, take the last three digits. Add eight to it if the thousands digit in the original number is odd (zero if even). If this three-digit number is divisible by 16, so is the original number. The resulting number can also be reduced by the following method.\u003c/li\u003e\u003cli\u003eTake the last two digits and add them to four times the remaining number. Apply this method recursively until a two-digit number remains. As usual, if the resulting number is divisible by 16, then so is the original number.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eA few of the function restrictions have been lifted.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42417-divisible-by-15\"\u003edivisible by 15\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors\"\u003edivisible by n, prime vs. composite divisors\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_16(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_16.m');\r\n% assert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\n% assert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\n% assert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\n% assert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\n% assert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_16(n_str),0))\r\n\r\n%%\r\nn_str = '16';\r\nassert(isequal(divisible_by_16(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_16(n_str),0))\r\n\r\n%%\r\nn_str = '224';\r\nassert(isequal(divisible_by_16(n_str),1))\r\n\r\n%%\r\nn_str = '208';\r\nassert(isequal(divisible_by_16(n_str),1))\r\n\r\n%%\r\nn_str = '210';\r\nassert(isequal(divisible_by_16(n_str),0))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_16(n_str),0))\r\n\r\n%%\r\nn_str = '1236128';\r\nassert(isequal(divisible_by_16(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_16(n_str),0))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567888';\r\nassert(isequal(divisible_by_16(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_16(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\nassert(isequal(divisible_by_16(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_16(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922784';\r\nassert(isequal(divisible_by_16(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_16(n_str),0))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100112';\r\nassert(isequal(divisible_by_16(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_16(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567888';\r\n\t\tassert(isequal(divisible_by_16(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_16(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '208';\r\n\t\tassert(isequal(divisible_by_16(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_16(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '1010010101011010101001011010100101101010010100101101010011010100112';\r\n\t\tassert(isequal(divisible_by_16(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\n\t\tassert(isequal(divisible_by_16(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_16(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '1236123';\r\n\t\tassert(isequal(divisible_by_16(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_16(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\n\t\tassert(isequal(divisible_by_16(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567888';\r\n\t\tassert(isequal(divisible_by_16(n_str),1))\r\nend\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":178,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-26T02:08:33.000Z","updated_at":"2026-03-31T13:28:32.000Z","published_at":"2015-06-26T02:08:33.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 16. This can be done by a few different methods. Here are two:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf a number has four or more digits, take the last three digits. Add eight to it if the thousands digit in the original number is odd (zero if even). If this three-digit number is divisible by 16, so is the original number. The resulting number can also be reduced by the following method.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTake the last two digits and add them to four times the remaining number. Apply this method recursively until a two-digit number remains. As usual, if the resulting number is divisible by 16, then so is the original number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA few of the function restrictions have been lifted.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42417-divisible-by-15\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 15\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by n, prime vs. composite divisors\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42405,"title":"Divisible by 3","description":"Pursuant to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 first problem\u003e in this series, this one involves checking for divisibility by 3.\r\n\r\nWrite a function to determine if a number is divisible by 3. This can be checked by at least two different methods:\r\n\r\n# Sum the digits in the number. If the resulting sum is divisible by 3, then so is the original number. This routine can be applied recursively until the resulting sum is a single digit.\r\n# From the \u003chttps://en.wikipedia.org/wiki/Divisibility_rule wikipedia reference page\u003e: \"Subtract the quantity of the digits 2, 5, and 8 in the number from the quantity of the digits 1, 4, and 7 in the number.\" If the resulting sum (absolute value) is a multiple of 3, then so is the original number.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 divisible by 2\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42406-divisible-by-4 divisible by 4\u003e.","description_html":"\u003cp\u003ePursuant to the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003efirst problem\u003c/a\u003e in this series, this one involves checking for divisibility by 3.\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 3. This can be checked by at least two different methods:\u003c/p\u003e\u003col\u003e\u003cli\u003eSum the digits in the number. If the resulting sum is divisible by 3, then so is the original number. This routine can be applied recursively until the resulting sum is a single digit.\u003c/li\u003e\u003cli\u003eFrom the \u003ca href = \"https://en.wikipedia.org/wiki/Divisibility_rule\"\u003ewikipedia reference page\u003c/a\u003e: \"Subtract the quantity of the digits 2, 5, and 8 in the number from the quantity of the digits 1, 4, and 7 in the number.\" If the resulting sum (absolute value) is a multiple of 3, then so is the original number.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003edivisible by 2\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42406-divisible-by-4\"\u003edivisible by 4\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_3(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_3.m');\r\nassert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_3(n_str),1))\r\n\r\n%%\r\nn_str = '13';\r\nassert(isequal(divisible_by_3(n_str),0))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_3(n_str),1))\r\n\r\n%%\r\nn_str = '232';\r\nassert(isequal(divisible_by_3(n_str),0))\r\n\r\n%%\r\nn_str = '223';\r\nassert(isequal(divisible_by_3(n_str),0))\r\n\r\n%%\r\nn_str = '1236127';\r\nassert(isequal(divisible_by_3(n_str),0))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_3(n_str),1))\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\nassert(isequal(divisible_by_3(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_3(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_3(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_3(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_3(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_3(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\n\t\tassert(isequal(divisible_by_3(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_3(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '1236127';\r\n\t\tassert(isequal(divisible_by_3(n_str),0))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\n\t\tassert(isequal(divisible_by_3(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_3(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_3(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '13';\r\n\t\tassert(isequal(divisible_by_3(n_str),0))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '13';\r\n\t\tassert(isequal(divisible_by_3(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_3(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_3(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_3(n_str),1))\r\nend","published":true,"deleted":false,"likes_count":12,"comments_count":7,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":429,"test_suite_updated_at":"2015-06-25T03:11:34.000Z","rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T02:27:10.000Z","updated_at":"2026-03-24T12:40:53.000Z","published_at":"2015-06-25T02:27:10.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 3.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 3. This can be checked by at least two different methods:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSum the digits in the number. If the resulting sum is divisible by 3, then so is the original number. This routine can be applied recursively until the resulting sum is a single digit.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFrom the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Divisibility_rule\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ewikipedia reference page\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e: \\\"Subtract the quantity of the digits 2, 5, and 8 in the number from the quantity of the digits 1, 4, and 7 in the number.\\\" If the resulting sum (absolute value) is a multiple of 3, then so is the original number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42406-divisible-by-4\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 4\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42510,"title":"Divisible by n, Composite Divisors","description":"Pursuant to \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors Divisible by n, prime vs. composite divisors\u003e, this problem requires you to write a function that determines divisibility for a large number (n_str) when the divisor is a composite. As was required in that problem, you will need to formulate the highest-power factorization of the divisor. Divisibility of n_str can then be determined by testing against each highest-power factor. For simplicity, this problem is restricted to numbers that contain the following as highest-power factors: 2, 3, 4, 5, 8, 9, and 10, as these divisibility tests are trivial. Their rules are included briefly below, for reference.\r\n\r\nAs an example, a number is divisible by 30 if it is divisible by 2, 3, and 5, as those are the highest-power factors for 30. Likewise, a number is divisible by 36 if it is divisible by 4 and 9 (not 3), as those are its highest-power factors.\r\n\r\nThe only restriction that remains is Java.\r\n\r\n* Divisible by 2: if the last digit is divisible by 2.\r\n* Divisible by 3: if the sum of the number's digits (n_str) is divisible by 3. Apply iteratively, as necessary, to arrive at a single-digit number.\r\n* Divisible by 4: if the last two digits are divisible by 4.\r\n* Divisible by 5: if the last digit is a 0 or 5.\r\n* Divisible by 8: if the last three digits are divisible by 8.\r\n* Divisible by 9: if the sum of the number's digits (n_str) is divisible by 9. Apply iteratively, as necessary, to arrive at a single-digit number.\r\n* Divisible by 10: if the last digit is zero.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42509-divisible-by-n-truncated-number-divisors Divisible by n, Truncated-number Divisors\u003e.","description_html":"\u003cp\u003ePursuant to \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors\"\u003eDivisible by n, prime vs. composite divisors\u003c/a\u003e, this problem requires you to write a function that determines divisibility for a large number (n_str) when the divisor is a composite. As was required in that problem, you will need to formulate the highest-power factorization of the divisor. Divisibility of n_str can then be determined by testing against each highest-power factor. For simplicity, this problem is restricted to numbers that contain the following as highest-power factors: 2, 3, 4, 5, 8, 9, and 10, as these divisibility tests are trivial. Their rules are included briefly below, for reference.\u003c/p\u003e\u003cp\u003eAs an example, a number is divisible by 30 if it is divisible by 2, 3, and 5, as those are the highest-power factors for 30. Likewise, a number is divisible by 36 if it is divisible by 4 and 9 (not 3), as those are its highest-power factors.\u003c/p\u003e\u003cp\u003eThe only restriction that remains is Java.\u003c/p\u003e\u003cul\u003e\u003cli\u003eDivisible by 2: if the last digit is divisible by 2.\u003c/li\u003e\u003cli\u003eDivisible by 3: if the sum of the number's digits (n_str) is divisible by 3. Apply iteratively, as necessary, to arrive at a single-digit number.\u003c/li\u003e\u003cli\u003eDivisible by 4: if the last two digits are divisible by 4.\u003c/li\u003e\u003cli\u003eDivisible by 5: if the last digit is a 0 or 5.\u003c/li\u003e\u003cli\u003eDivisible by 8: if the last three digits are divisible by 8.\u003c/li\u003e\u003cli\u003eDivisible by 9: if the sum of the number's digits (n_str) is divisible by 9. Apply iteratively, as necessary, to arrive at a single-digit number.\u003c/li\u003e\u003cli\u003eDivisible by 10: if the last digit is zero.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42509-divisible-by-n-truncated-number-divisors\"\u003eDivisible by n, Truncated-number Divisors\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = composite_divisors(n,n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('composite_divisors.m');\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn = 18;\r\nn_str = '612220032';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 18;\r\nn_str = '612220031';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 18;\r\nn_str = '64268410079232';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 18;\r\nn_str = '192805230237696';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 18;\r\nn_str = '64268410079230';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 18;\r\nn_str = '192805230237696000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 18;\r\nn_str = '192805230237696000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 30;\r\nn_str = '64268410079230';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 30;\r\nn_str = '64268410079220';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 90;\r\nn_str = '47829690000000';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 90;\r\nn_str = '47829690000001';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 36;\r\nn_str = '101559956668416';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 36;\r\nn_str = '101559956668417';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 36;\r\nn_str = '3046798700052480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 36;\r\nn_str = '3046798700052480000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 40;\r\nn_str = '262144000000000';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 40;\r\nn_str = '262144000000008';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 40;\r\nn_str = '52428800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 40;\r\nn_str = '52428800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 24;\r\nn_str = '4586471424';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 24;\r\nn_str = '45864714247';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 24;\r\nn_str = '26418075402240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 24;\r\nn_str = '26418075402240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":76,"test_suite_updated_at":"2015-08-18T17:06:20.000Z","rescore_all_solutions":false,"group_id":22,"created_at":"2015-08-18T01:06:51.000Z","updated_at":"2026-01-11T11:13:47.000Z","published_at":"2015-08-18T01:06:51.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, prime vs. composite divisors\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, this problem requires you to write a function that determines divisibility for a large number (n_str) when the divisor is a composite. As was required in that problem, you will need to formulate the highest-power factorization of the divisor. Divisibility of n_str can then be determined by testing against each highest-power factor. For simplicity, this problem is restricted to numbers that contain the following as highest-power factors: 2, 3, 4, 5, 8, 9, and 10, as these divisibility tests are trivial. Their rules are included briefly below, for reference.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs an example, a number is divisible by 30 if it is divisible by 2, 3, and 5, as those are the highest-power factors for 30. Likewise, a number is divisible by 36 if it is divisible by 4 and 9 (not 3), as those are its highest-power factors.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe only restriction that remains is Java.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by 2: if the last digit is divisible by 2.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by 3: if the sum of the number's digits (n_str) is divisible by 3. Apply iteratively, as necessary, to arrive at a single-digit number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by 4: if the last two digits are divisible by 4.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by 5: if the last digit is a 0 or 5.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by 8: if the last three digits are divisible by 8.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by 9: if the sum of the number's digits (n_str) is divisible by 9. Apply iteratively, as necessary, to arrive at a single-digit number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by 10: if the last digit is zero.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42509-divisible-by-n-truncated-number-divisors\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, Truncated-number Divisors\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42453,"title":"Divisible by n, prime vs. composite divisors","description":"In general, there are two types of divisibility checks; the first involves composite divisors and the second prime divisors, including powers of prime numbers (technically composite divisors, though they often function similar to prime numbers for the sake of divisibility). We'll get into the specifics of the two divisibility check types in subsequent problems. For now, we'll segregate numbers into three groups, based on type (n_type) while also returning the number's highest-power factorization (hpf). Write a function to return these two variables for a given number; see the following examples for reference:\r\n\r\n  n = 11  |  n_type = 1 (prime)        |  hpf = [11]\r\n  n = 31  |  n_type = 1 (prime)        |  hpf = [31]\r\n  n = 9   |  n_type = 2 (prime power)  |  hpf = [9] (3^2)\r\n  n = 32  |  n_type = 2 (prime power)  |  hpf = [32] (2^5)\r\n  n = 49  |  n_type = 2 (prime power)  |  hpf = [49] (7^2)\r\n  n = 21  |  n_type = 3 (composite)    |  hpf = [3,7]\r\n  n = 39  |  n_type = 3 (composite)    |  hpf = [3,13]\r\n  n = 42  |  n_type = 3 (composite)    |  hpf = [2,3,7]\r\n  n = 63  |  n_type = 3 (composite)    |  hpf = [9,7] ([3^2,7])\r\n  n = 90  |  n_type = 3 (composite)    |  hpf = [2,9,5] ([2,3^2,5])\r\n\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42418-divisible-by-16 divisible by 16\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42454-divisible-by-n-prime-divisors-including-powers Divisible by n, prime divisors (including powers)\u003e.","description_html":"\u003cp\u003eIn general, there are two types of divisibility checks; the first involves composite divisors and the second prime divisors, including powers of prime numbers (technically composite divisors, though they often function similar to prime numbers for the sake of divisibility). We'll get into the specifics of the two divisibility check types in subsequent problems. For now, we'll segregate numbers into three groups, based on type (n_type) while also returning the number's highest-power factorization (hpf). Write a function to return these two variables for a given number; see the following examples for reference:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003en = 11  |  n_type = 1 (prime)        |  hpf = [11]\r\nn = 31  |  n_type = 1 (prime)        |  hpf = [31]\r\nn = 9   |  n_type = 2 (prime power)  |  hpf = [9] (3^2)\r\nn = 32  |  n_type = 2 (prime power)  |  hpf = [32] (2^5)\r\nn = 49  |  n_type = 2 (prime power)  |  hpf = [49] (7^2)\r\nn = 21  |  n_type = 3 (composite)    |  hpf = [3,7]\r\nn = 39  |  n_type = 3 (composite)    |  hpf = [3,13]\r\nn = 42  |  n_type = 3 (composite)    |  hpf = [2,3,7]\r\nn = 63  |  n_type = 3 (composite)    |  hpf = [9,7] ([3^2,7])\r\nn = 90  |  n_type = 3 (composite)    |  hpf = [2,9,5] ([2,3^2,5])\r\n\u003c/pre\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42418-divisible-by-16\"\u003edivisible by 16\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42454-divisible-by-n-prime-divisors-including-powers\"\u003eDivisible by n, prime divisors (including powers)\u003c/a\u003e.\u003c/p\u003e","function_template":"function [n_type,hpf] = composite_vs_prime_divisor(n)\r\n\r\nn_type = 1;\r\nhpf = [1];\r\n\r\nend\r\n","test_suite":"%%\r\nn = 5;\r\ntf_corr = 1; %prime factor\r\nhpf_corr = 5;\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 7;\r\ntf_corr = 1; %prime factor\r\nhpf_corr = 7;\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 15;\r\ntf_corr = 3; %composite factor\r\nhpf_corr = [3,5];\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 25;\r\ntf_corr = 2; %composite factor, prime power (5^2)\r\nhpf_corr = 25;\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 125;\r\ntf_corr = 2; %composite factor, prime power (5^3)\r\nhpf_corr = 125;\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 20;\r\ntf_corr = 3; %composite factor\r\nhpf_corr = [4,5];\r\n[tf,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(tf,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 42;\r\ntf_corr = 3; %composite factor\r\nhpf_corr = [2,3,7];\r\n[tf,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(tf,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 18;\r\ntf_corr = 3; %composite factor\r\nhpf_corr = [2,9];\r\n[tf,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(tf,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 29;\r\ntf_corr = 1; %prime factor\r\nhpf_corr = 29;\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 39;\r\ntf_corr = 3; %composite factor\r\nhpf_corr = [3,13];\r\n[tf,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(tf,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 64;\r\ntf_corr = 2; %composite factor, prime power (2^6)\r\nhpf_corr = 64;\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 27;\r\ntf_corr = 2; %composite factor, prime power (3^3)\r\nhpf_corr = 27;\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%% anti-cheating test case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn = 29;\r\n\t\ttf_corr = 1; %prime factor\r\n\t\thpf_corr = 29;\r\n\tcase 2\r\n\t\tn = 42;\r\n\t\ttf_corr = 3; %composite factor\r\n\t\thpf_corr = [2,3,7];\r\n\tcase 3\r\n\t\tn = 18;\r\n\t\ttf_corr = 3; %composite factor\r\n\t\thpf_corr = [2,9];\r\n\tcase 4\r\n\t\tn = 42;\r\n\t\ttf_corr = 3; %composite factor\r\n\t\thpf_corr = [2,3,7];\r\nend\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%% anti-cheating test case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn = 64;\r\n\t\ttf_corr = 2; %composite factor, prime power (2^6)\r\n\t\thpf_corr = 64;\r\n\tcase 2\r\n\t\tn = 27;\r\n\t\ttf_corr = 2; %composite factor, prime power (3^3)\r\n\t\thpf_corr = 27;\r\n\tcase 3\r\n\t\tn = 42;\r\n\t\ttf_corr = 3; %composite factor\r\n\t\thpf_corr = [2,3,7];\r\n\tcase 4\r\n\t\tn = 18;\r\n\t\ttf_corr = 3; %composite factor\r\n\t\thpf_corr = [2,9];\r\nend\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%% anti-cheating test case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn = 39;\r\n\t\ttf_corr = 3; %composite factor\r\n\t\thpf_corr = [3,13];\r\n\tcase 2\r\n\t\tn = 5;\r\n\t\ttf_corr = 1; %prime factor\r\n\t\thpf_corr = 5;\r\n\tcase 3\r\n\t\tn = 18;\r\n\t\ttf_corr = 3; %composite factor\r\n\t\thpf_corr = [2,9];\r\n\tcase 4\r\n\t\tn = 27;\r\n\t\ttf_corr = 2; %composite factor, prime power (3^3)\r\n\t\thpf_corr = 27;\r\nend\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":113,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-07-09T01:29:13.000Z","updated_at":"2026-01-11T11:07:59.000Z","published_at":"2015-07-09T01:29:13.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn general, there are two types of divisibility checks; the first involves composite divisors and the second prime divisors, including powers of prime numbers (technically composite divisors, though they often function similar to prime numbers for the sake of divisibility). We'll get into the specifics of the two divisibility check types in subsequent problems. For now, we'll segregate numbers into three groups, based on type (n_type) while also returning the number's highest-power factorization (hpf). Write a function to return these two variables for a given number; see the following examples for reference:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[n = 11  |  n_type = 1 (prime)        |  hpf = [11]\\nn = 31  |  n_type = 1 (prime)        |  hpf = [31]\\nn = 9   |  n_type = 2 (prime power)  |  hpf = [9] (3^2)\\nn = 32  |  n_type = 2 (prime power)  |  hpf = [32] (2^5)\\nn = 49  |  n_type = 2 (prime power)  |  hpf = [49] (7^2)\\nn = 21  |  n_type = 3 (composite)    |  hpf = [3,7]\\nn = 39  |  n_type = 3 (composite)    |  hpf = [3,13]\\nn = 42  |  n_type = 3 (composite)    |  hpf = [2,3,7]\\nn = 63  |  n_type = 3 (composite)    |  hpf = [9,7] ([3^2,7])\\nn = 90  |  n_type = 3 (composite)    |  hpf = [2,9,5] ([2,3^2,5])]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42418-divisible-by-16\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 16\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42454-divisible-by-n-prime-divisors-including-powers\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, prime divisors (including powers)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42415,"title":"Divisible by 13","description":"Write a function to determine if a number is divisible by 13. Similar to the number seven, this can be done by a few different methods:\r\n\r\n# Form the alternating sum of blocks of three (separated at the comma locations). Apply this recursively until a three-digit number remains. If this number is divisible by 13, then so is the original number. This three-digit number can also be further reduced using one of the other methods below.\r\n# Add four times the last digit to the remaining number. Apply recursively until a two-digit number remains. As before, if this number is divisible by 13, then so is the original number.\r\n# Similar to the previous method, multiply the last digit by nine and subtract it from the remaining number. Apply recursion, etc.\r\n\r\nSome of the function restrictions have been lifted.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42414-divisible-by-12 divisible by 12\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42416-divisible-by-14 divisible by 14\u003e.","description_html":"\u003cp\u003eWrite a function to determine if a number is divisible by 13. Similar to the number seven, this can be done by a few different methods:\u003c/p\u003e\u003col\u003e\u003cli\u003eForm the alternating sum of blocks of three (separated at the comma locations). Apply this recursively until a three-digit number remains. If this number is divisible by 13, then so is the original number. This three-digit number can also be further reduced using one of the other methods below.\u003c/li\u003e\u003cli\u003eAdd four times the last digit to the remaining number. Apply recursively until a two-digit number remains. As before, if this number is divisible by 13, then so is the original number.\u003c/li\u003e\u003cli\u003eSimilar to the previous method, multiply the last digit by nine and subtract it from the remaining number. Apply recursion, etc.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eSome of the function restrictions have been lifted.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42414-divisible-by-12\"\u003edivisible by 12\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42416-divisible-by-14\"\u003edivisible by 14\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_13(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_13.m');\r\n% assert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\n% assert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\n% assert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_13(n_str),0))\r\n\r\n%%\r\nn_str = '13';\r\nassert(isequal(divisible_by_13(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_13(n_str),0))\r\n\r\n%%\r\nn_str = '228';\r\nassert(isequal(divisible_by_13(n_str),0))\r\n\r\n%%\r\nn_str = '221';\r\nassert(isequal(divisible_by_13(n_str),1))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_13(n_str),0))\r\n\r\n%%\r\nn_str = '1236131';\r\nassert(isequal(divisible_by_13(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_13(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\nassert(isequal(divisible_by_13(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_13(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006';\r\nassert(isequal(divisible_by_13(n_str),1))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_13(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922799';\r\nassert(isequal(divisible_by_13(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_13(n_str),0))\r\n\r\n%%\r\nn_str = '10100101010110101010010110101001011010100101001011010100110101001007';\r\nassert(isequal(divisible_by_13(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_13(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\n\t\tassert(isequal(divisible_by_13(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_13(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '221';\r\n\t\tassert(isequal(divisible_by_13(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_13(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '10100101010110101010010110101001011010100101001011010100110101001007';\r\n\t\tassert(isequal(divisible_by_13(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006';\r\n\t\tassert(isequal(divisible_by_13(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_13(n_str),0))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '228';\r\n\t\tassert(isequal(divisible_by_13(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_13(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006';\r\n\t\tassert(isequal(divisible_by_13(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_13(n_str),1))\r\nend\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":157,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-26T01:40:22.000Z","updated_at":"2025-12-24T20:24:26.000Z","published_at":"2015-06-26T01:40:22.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 13. Similar to the number seven, this can be done by a few different methods:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eForm the alternating sum of blocks of three (separated at the comma locations). Apply this recursively until a three-digit number remains. If this number is divisible by 13, then so is the original number. This three-digit number can also be further reduced using one of the other methods below.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAdd four times the last digit to the remaining number. Apply recursively until a two-digit number remains. As before, if this number is divisible by 13, then so is the original number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSimilar to the previous method, multiply the last digit by nine and subtract it from the remaining number. Apply recursion, etc.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSome of the function restrictions have been lifted.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42414-divisible-by-12\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 12\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42416-divisible-by-14\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 14\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42409,"title":"Divisible by 7","description":"Pursuant to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 first problem\u003e in this series, this one involves checking for divisibility by 7.\r\n\r\nWrite a function to determine if a number is divisible by 7. This can be done by a variety of methods. Some are:\r\n\r\n# Multiply each digit in the candidate number (from right to left) by the digit in the corresponding position in this pattern: 1, 3, 2, -1, -3, -2 (1 applies to the ones digit, 3 to the tens digit, etc.). This pattern should be repeated beyond the hundred-thousands digit. The resulting sum will be a smaller number. This method can be applied recursively to the absolute values of the resulting sum until a single digit results. Then, check that number for divisibility by seven.\r\n# The previous method can also be used applying a slightly different pattern: 1, 3, 2, 6, 4, 5 (1 applies to the ones digit again, etc.). The absolute value of the resulting sum is not necessary as none of the factors are negative.\r\n# Multiply the last (ones) digit by two and subtract the result from the remaining number. Apply recursively, as noted in methods above.\r\n# Similar to the previous method, multiply the last digit by five and add to the remaining number. Apply recursively, as noted in methods above.\r\n# Double the last digit and subtract it from the remaining number (original number except for the ones digit). Apply this recursively until a single digit results. If that number is divisible by seven, then so is the original number.\r\n# Similar to the previous method, multiply the ones digit by five and add it to the remaining number. Apply this recursively until a single digit results. If that number is divisible by seven, then so is the original number.\r\n# Along similar lines, take the last three digits of the number and subtract that number from the remaining number. Once you reach a number less than 1000, another method can be applied to further reduce the number to check for divisibility by seven.\r\n# Etc. (there are others)\r\n\r\nThe restriction for multiplication has been lifted for this specific problem.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42408-divisible-by-6 divisible by 6\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42410-divisible-by-8 divisible by 8\u003e.","description_html":"\u003cp\u003ePursuant to the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003efirst problem\u003c/a\u003e in this series, this one involves checking for divisibility by 7.\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 7. This can be done by a variety of methods. Some are:\u003c/p\u003e\u003col\u003e\u003cli\u003eMultiply each digit in the candidate number (from right to left) by the digit in the corresponding position in this pattern: 1, 3, 2, -1, -3, -2 (1 applies to the ones digit, 3 to the tens digit, etc.). This pattern should be repeated beyond the hundred-thousands digit. The resulting sum will be a smaller number. This method can be applied recursively to the absolute values of the resulting sum until a single digit results. Then, check that number for divisibility by seven.\u003c/li\u003e\u003cli\u003eThe previous method can also be used applying a slightly different pattern: 1, 3, 2, 6, 4, 5 (1 applies to the ones digit again, etc.). The absolute value of the resulting sum is not necessary as none of the factors are negative.\u003c/li\u003e\u003cli\u003eMultiply the last (ones) digit by two and subtract the result from the remaining number. Apply recursively, as noted in methods above.\u003c/li\u003e\u003cli\u003eSimilar to the previous method, multiply the last digit by five and add to the remaining number. Apply recursively, as noted in methods above.\u003c/li\u003e\u003cli\u003eDouble the last digit and subtract it from the remaining number (original number except for the ones digit). Apply this recursively until a single digit results. If that number is divisible by seven, then so is the original number.\u003c/li\u003e\u003cli\u003eSimilar to the previous method, multiply the ones digit by five and add it to the remaining number. Apply this recursively until a single digit results. If that number is divisible by seven, then so is the original number.\u003c/li\u003e\u003cli\u003eAlong similar lines, take the last three digits of the number and subtract that number from the remaining number. Once you reach a number less than 1000, another method can be applied to further reduce the number to check for divisibility by seven.\u003c/li\u003e\u003cli\u003eEtc. (there are others)\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eThe restriction for multiplication has been lifted for this specific problem.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42408-divisible-by-6\"\u003edivisible by 6\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42410-divisible-by-8\"\u003edivisible by 8\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_7(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_7.m');\r\n%assert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_7(n_str),0))\r\n\r\n%%\r\nn_str = '14';\r\nassert(isequal(divisible_by_7(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_7(n_str),0))\r\n\r\n%%\r\nn_str = '231';\r\nassert(isequal(divisible_by_7(n_str),1))\r\n\r\n%%\r\nn_str = '224';\r\nassert(isequal(divisible_by_7(n_str),1))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_7(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_7(n_str),1))\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\nassert(isequal(divisible_by_7(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_7(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_7(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_7(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_7(n_str),0))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '14';\r\n\t\tassert(isequal(divisible_by_7(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\n\t\tassert(isequal(divisible_by_7(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_7(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '231';\r\n\t\tassert(isequal(divisible_by_7(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_7(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '224';\r\n\t\tassert(isequal(divisible_by_7(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_7(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_7(n_str),0))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '1236123';\r\n\t\tassert(isequal(divisible_by_7(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_7(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_7(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_7(n_str),1))\r\nend","published":true,"deleted":false,"likes_count":2,"comments_count":5,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":183,"test_suite_updated_at":"2015-06-25T03:15:21.000Z","rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T03:07:11.000Z","updated_at":"2025-12-29T13:23:25.000Z","published_at":"2015-06-25T03:07:11.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 7.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 7. This can be done by a variety of methods. Some are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMultiply each digit in the candidate number (from right to left) by the digit in the corresponding position in this pattern: 1, 3, 2, -1, -3, -2 (1 applies to the ones digit, 3 to the tens digit, etc.). This pattern should be repeated beyond the hundred-thousands digit. The resulting sum will be a smaller number. This method can be applied recursively to the absolute values of the resulting sum until a single digit results. Then, check that number for divisibility by seven.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe previous method can also be used applying a slightly different pattern: 1, 3, 2, 6, 4, 5 (1 applies to the ones digit again, etc.). The absolute value of the resulting sum is not necessary as none of the factors are negative.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMultiply the last (ones) digit by two and subtract the result from the remaining number. Apply recursively, as noted in methods above.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSimilar to the previous method, multiply the last digit by five and add to the remaining number. Apply recursively, as noted in methods above.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDouble the last digit and subtract it from the remaining number (original number except for the ones digit). Apply this recursively until a single digit results. If that number is divisible by seven, then so is the original number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSimilar to the previous method, multiply the ones digit by five and add it to the remaining number. Apply this recursively until a single digit results. If that number is divisible by seven, then so is the original number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAlong similar lines, take the last three digits of the number and subtract that number from the remaining number. Once you reach a number less than 1000, another method can be applied to further reduce the number to check for divisibility by seven.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEtc. (there are others)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe restriction for multiplication has been lifted for this specific problem.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42408-divisible-by-6\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 6\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42410-divisible-by-8\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42508,"title":"Divisible by n, prime divisors from 20 to 200","description":"Pursuant to the previous problem (linked below), this problem requires a function that checks for divisibility of large numbers for any prime number from 20 to 200. Similar to the previous problem, these can all be checked using the same routine: add or subtract x times the last digit to or from the remaining number after removing that last digit. For example, for 127, the last-digit factor is -38:\r\n\r\n* 2048379: 204837 + -38*9 = 204495: 20449 + -38*5 = 20259: 2025 + -38*9 = 1683: 168 + -38*3 = 54 -\u003e 2048379 is not divisible by 127 since 54 is not divisible by 127.\r\n\r\n* 4853940: 485394 + -38*0 = 485394: 48539 + -38*4 = 48387: 4838 + -38*7 = 4572: 457 + -38*2 = 381: 38 + -38*1 = 0 -\u003e 4853940 is divisible by 127.\r\n\r\nYour function will be provided with the prime number, n, and the number to check for divisibility as a string, n_str. Write a function that returns true or false for each prime number and candidate number pair. See the test suite for more examples. The template function will include arrays of all possible prime number in the given range in addition to a paired array with the associated factors.\r\n\r\nRestrictions on Java, mod, ceil, round, and floor are still in effect.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42455-divisible-by-n-prime-divisors-11-13-17-19 Divisible by n, prime divisors - 11, 13, 17, \u0026 19\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42509-divisible-by-n-truncated-number-divisors Divisible by n, Truncated-number Divisors\u003e.","description_html":"\u003cp\u003ePursuant to the previous problem (linked below), this problem requires a function that checks for divisibility of large numbers for any prime number from 20 to 200. Similar to the previous problem, these can all be checked using the same routine: add or subtract x times the last digit to or from the remaining number after removing that last digit. For example, for 127, the last-digit factor is -38:\u003c/p\u003e\u003cul\u003e\u003cli\u003e2048379: 204837 + -38*9 = 204495: 20449 + -38*5 = 20259: 2025 + -38*9 = 1683: 168 + -38*3 = 54 -\u0026gt; 2048379 is not divisible by 127 since 54 is not divisible by 127.\u003c/li\u003e\u003c/ul\u003e\u003cul\u003e\u003cli\u003e4853940: 485394 + -38*0 = 485394: 48539 + -38*4 = 48387: 4838 + -38*7 = 4572: 457 + -38*2 = 381: 38 + -38*1 = 0 -\u0026gt; 4853940 is divisible by 127.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eYour function will be provided with the prime number, n, and the number to check for divisibility as a string, n_str. Write a function that returns true or false for each prime number and candidate number pair. See the test suite for more examples. The template function will include arrays of all possible prime number in the given range in addition to a paired array with the associated factors.\u003c/p\u003e\u003cp\u003eRestrictions on Java, mod, ceil, round, and floor are still in effect.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42455-divisible-by-n-prime-divisors-11-13-17-19\"\u003eDivisible by n, prime divisors - 11, 13, 17, \u0026 19\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42509-divisible-by-n-truncated-number-divisors\"\u003eDivisible by n, Truncated-number Divisors\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = prime_divisors_20_to_200(n,n_str)\r\n\r\np_digits =      [23 29  31 37  41 43  47 53 59 61 67  71 73 79 83 89 97  101 103 107 109 113 127 131 137 139  149  151 157 163  167 173  179  181 191 193  197 199];\r\nlast_dig_mult = [7  3  -3 -11 -4  13 -14 16 6 -6 -20 -7 -51 8  25 9 -29 -10 -72 -32 -98 -79 -38 -13 -41 -125 -134 -15 -47 -114 -50 -121 -161 -18 -19 -135 -59 -179];\r\n\r\ntf = 1;\r\n\r\nend","test_suite":"%%\r\nfiletext = fileread('prime_divisors_20_to_200.m');\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn = 23;\r\nn_str = '943';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 23;\r\nn_str = '9430000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 23;\r\nn_str = '9430000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 29;\r\nn_str = '22649';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 31;\r\nn_str = '992';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 31;\r\nn_str = '9920000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 31;\r\nn_str = '9920000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 37;\r\nn_str = '4107';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 41;\r\nn_str = '33292';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 43;\r\nn_str = '85140';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 43;\r\nn_str = '851400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 43;\r\nn_str = '851400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 47;\r\nn_str = '232603';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 53;\r\nn_str = '148877';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 59;\r\nn_str = '12698688';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 61;\r\nn_str = '61965813';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 61;\r\nn_str = '619658130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 61;\r\nn_str = '619658130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 67;\r\nn_str = '22319844';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 71;\r\nn_str = '25411681';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 73;\r\nn_str = '328500';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 73;\r\nn_str = '32850000000000000000000000000000000000000000000000000000000000001000000000000';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 79;\r\nn_str = '41977440';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 83;\r\nn_str = '342873';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 89;\r\nn_str = '8900000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 97;\r\nn_str = '88529281';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 101;\r\nn_str = '104060401';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 101;\r\nn_str = '1040604010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 101;\r\nn_str = '1040604010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 103;\r\nn_str = '112550881';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 107;\r\nn_str = '515205';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 109;\r\nn_str = '141158161';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 113;\r\nn_str = '2151294';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 113;\r\nn_str = '2151294000000000000000000000000113000000000000000000000000113000000000000000000000000113000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 113;\r\nn_str = '2151294000000000000000000000000113000000000000000000000000113000000000000000000000000113000000000000000000000112';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 127;\r\nn_str = '4853940';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 131;\r\nn_str = '294499921';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 137;\r\nn_str = '249421241';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 139;\r\nn_str = '2685619';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 139;\r\nn_str = '268561900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013900000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 139;\r\nn_str = '268561900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013900000000000000000000000000000000000000000000000000000000000000000000000013';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 149;\r\nn_str = '512977200';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 151;\r\nn_str = '141160991';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 157;\r\nn_str = '607573201';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 163;\r\nn_str = '705911761';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 167;\r\nn_str = '777796321';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 173;\r\nn_str = '154963892093';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 179;\r\nn_str = '98682340334763';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 181;\r\nn_str = '35161828327081';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 191;\r\nn_str = '884089868985578';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 193;\r\nn_str = '1387488001';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 197;\r\nn_str = '27000544548887';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 199;\r\nn_str = '328039798800';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 199;\r\nn_str = '32803979880000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 199;\r\nn_str = '32803979880000000000000000000000000000000000000000000000000000000000000001990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001990000000000000000000000000000000000199000000000000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 199;\r\nn_str = '32803979880000000000000000000000000000000000000000000000000000000000000001991000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001990000000000000000000000000000000000199000000000000';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":68,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-08-17T19:05:44.000Z","updated_at":"2025-12-27T11:58:28.000Z","published_at":"2015-08-17T19:05:44.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the previous problem (linked below), this problem requires a function that checks for divisibility of large numbers for any prime number from 20 to 200. Similar to the previous problem, these can all be checked using the same routine: add or subtract x times the last digit to or from the remaining number after removing that last digit. For example, for 127, the last-digit factor is -38:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2048379: 204837 + -38*9 = 204495: 20449 + -38*5 = 20259: 2025 + -38*9 = 1683: 168 + -38*3 = 54 -\u0026gt; 2048379 is not divisible by 127 since 54 is not divisible by 127.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4853940: 485394 + -38*0 = 485394: 48539 + -38*4 = 48387: 4838 + -38*7 = 4572: 457 + -38*2 = 381: 38 + -38*1 = 0 -\u0026gt; 4853940 is divisible by 127.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour function will be provided with the prime number, n, and the number to check for divisibility as a string, n_str. Write a function that returns true or false for each prime number and candidate number pair. See the test suite for more examples. The template function will include arrays of all possible prime number in the given range in addition to a paired array with the associated factors.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRestrictions on Java, mod, ceil, round, and floor are still in effect.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42455-divisible-by-n-prime-divisors-11-13-17-19\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, prime divisors - 11, 13, 17, \u0026amp; 19\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42509-divisible-by-n-truncated-number-divisors\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, Truncated-number Divisors\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":3079,"title":"Big numbers, repeated least significant digits","description":"This problem builds off of Problem 3077\r\nGiven an integer x which contains d digits, find the value of (minimum) n (n \u003e 1) such that the last d digits of x^n is equal to x. If the last d digits will never equal x, return inf.\r\nExample 1:\r\nx = 2; (therefore d = 1)\r\n2^2 = 4, 2^3 = 8, 2^4 = 16, 2^5 = 32\r\nn = 5;\r\nExample 2:\r\nx = 10; (therefore d = 2)\r\n10^2 = 100, 10^3 = 1000, etc\r\nn = inf;","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 285.6px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 142.8px; transform-origin: 407px 142.8px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 79.5px 8px; transform-origin: 79.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis problem builds off of\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 3077\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"perspective-origin: 186.5px 8px; transform-origin: 186.5px 8px; \"\u003eGiven an integer x which contains d digits, find the value of \u003c/span\u003e\u003cspan style=\"border-block-end-style: solid; border-block-end-width: 1px; border-bottom-style: solid; border-bottom-width: 1px; perspective-origin: 2.5px 8.5px; transform-origin: 2.5px 8.5px; \"\u003e(\u003c/span\u003e\u003cspan style=\"perspective-origin: 27.5px 8px; transform-origin: 27.5px 8px; \"\u003eminimum\u003c/span\u003e\u003cspan style=\"border-block-end-style: solid; border-block-end-width: 1px; border-bottom-style: solid; border-bottom-width: 1px; perspective-origin: 2.5px 8.5px; transform-origin: 2.5px 8.5px; \"\u003e)\u003c/span\u003e\u003cspan style=\"perspective-origin: 165px 8px; transform-origin: 165px 8px; \"\u003e n (n \u0026gt; 1) such that the last d digits of x^n is equal to x. If the last d digits will never equal x, return inf.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 34.5px 8px; transform-origin: 34.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample 1:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 61.3px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 30.65px; transform-origin: 391px 30.65px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 71px 8px; transform-origin: 71px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ex = 2; (therefore d = 1)\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 110px 8px; transform-origin: 110px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e2^2 = 4, 2^3 = 8, 2^4 = 16, 2^5 = 32\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 18px 8px; transform-origin: 18px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en = 5;\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 34.5px 8px; transform-origin: 34.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample 2:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 61.3px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 30.65px; transform-origin: 391px 30.65px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 75px 8px; transform-origin: 75px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ex = 10; (therefore d = 2)\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 90.5px 8px; transform-origin: 90.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e10^2 = 100, 10^3 = 1000, etc\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 21.5px 8px; transform-origin: 21.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en = inf;\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function n = bigNumRepeat(x)\r\n  n = x;\r\nend","test_suite":"%%\r\nx = 2;\r\nn_correct = 5;\r\nassert(isequal(bigNumRepeat(x),n_correct))\r\n\r\n%%\r\nx = 10;\r\nn_correct = inf;\r\nassert(isequal(bigNumRepeat(x),n_correct))\r\n\r\n%%\r\nx = [3 7 33 51 67 192 329 678 680 4731 10016 10081 35197 35199 51783 517839 517842];\r\nn_correct = [5 5 21 3 21 101 51 inf inf 501 626 626 5001 251 2501 12501 inf];\r\nfor ii = 1:numel(x)\r\n   assert(isequal(bigNumRepeat(x(ii)),n_correct(ii)))\r\nend","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":3096,"edited_by":223089,"edited_at":"2022-07-27T07:11:05.000Z","deleted_by":null,"deleted_at":null,"solvers_count":86,"test_suite_updated_at":"2015-03-16T15:16:23.000Z","rescore_all_solutions":false,"group_id":45,"created_at":"2015-03-13T18:49:43.000Z","updated_at":"2026-02-15T15:42:06.000Z","published_at":"2015-03-13T18:49:43.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis problem builds off of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3077\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an integer x which contains d digits, find the value of (minimum) n (n \u0026gt; 1) such that the last d digits of x^n is equal to x. If the last d digits will never equal x, return inf.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 1:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex = 2; (therefore d = 1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2^2 = 4, 2^3 = 8, 2^4 = 16, 2^5 = 32\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en = 5;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 2:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex = 10; (therefore d = 2)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e10^2 = 100, 10^3 = 1000, etc\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en = inf;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":42455,"title":"Divisible by n, prime divisors - 11, 13, 17, \u0026 19","description":"Divisibility checks against prime numbers can all be accomplished with the same routine, applied recursively, consisting of add or subtract x times the last digit to or from the remaining number. For example, for 13, add four times the last digit to the rest:\r\n\r\n* 2392: 239 + 4*2 = 247: 24 + 4*7 = 52: 5 + 4*2 = 13 -\u003e 2392 is divisible by 13.\r\n\r\nFor 17, subtract five times the last digit from the rest:\r\n\r\n* 3281: 328 - 5*1 = 323: 32 - 5*3 = 17 -\u003e 3281 is divisible by 17.\r\n\r\nFor 19, add two times the last digit to the rest:\r\n\r\n* 16863: 1686 + 2*3 = 1692: 169 + 2*2 = 173: 17 + 2*3 = 23: 2 + 2*3 = 8 -\u003e 16863 is not divisible by 19.\r\n\r\nAnd, for 11, subtract the last digit from the rest:\r\n\r\n* 269830: 26983 - 0 = 26983: 2698 - 3 = 2695: 269 - 5 = 264: 26 - 4 = 22: 2 - 2 = 0 -\u003e 269830 is divisible by 11.\r\n\r\nWrite a function to return a true-false vector for the prime numbers in the 11:20 range ([11 13 17 19]) based on a number supplied as a string.\r\n\r\nRestrictions on Java, mod, ceil, round, and floor are still in effect.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42454-divisible-by-n-prime-divisors-including-powers Divisible by n, prime divisors (including powers)\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42508-divisible-by-n-prime-divisors-from-20-to-200 Divisible by n, prime divisors from 20 to 200\u003e.","description_html":"\u003cp\u003eDivisibility checks against prime numbers can all be accomplished with the same routine, applied recursively, consisting of add or subtract x times the last digit to or from the remaining number. For example, for 13, add four times the last digit to the rest:\u003c/p\u003e\u003cul\u003e\u003cli\u003e2392: 239 + 4*2 = 247: 24 + 4*7 = 52: 5 + 4*2 = 13 -\u0026gt; 2392 is divisible by 13.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eFor 17, subtract five times the last digit from the rest:\u003c/p\u003e\u003cul\u003e\u003cli\u003e3281: 328 - 5*1 = 323: 32 - 5*3 = 17 -\u0026gt; 3281 is divisible by 17.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eFor 19, add two times the last digit to the rest:\u003c/p\u003e\u003cul\u003e\u003cli\u003e16863: 1686 + 2*3 = 1692: 169 + 2*2 = 173: 17 + 2*3 = 23: 2 + 2*3 = 8 -\u0026gt; 16863 is not divisible by 19.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eAnd, for 11, subtract the last digit from the rest:\u003c/p\u003e\u003cul\u003e\u003cli\u003e269830: 26983 - 0 = 26983: 2698 - 3 = 2695: 269 - 5 = 264: 26 - 4 = 22: 2 - 2 = 0 -\u0026gt; 269830 is divisible by 11.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eWrite a function to return a true-false vector for the prime numbers in the 11:20 range ([11 13 17 19]) based on a number supplied as a string.\u003c/p\u003e\u003cp\u003eRestrictions on Java, mod, ceil, round, and floor are still in effect.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42454-divisible-by-n-prime-divisors-including-powers\"\u003eDivisible by n, prime divisors (including powers)\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42508-divisible-by-n-prime-divisors-from-20-to-200\"\u003eDivisible by n, prime divisors from 20 to 200\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = prime_divisors_11_to_20(n)\r\n\r\np_digits = [11 13 17 19];\r\ntf = zeros(1,4); %[11 13 17 19]\r\n\t\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('prime_divisors_11_to_20.m');\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn = '143';\r\ntf = [1 1 0 0]; %[11 13 17 19]\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '187';\r\ntf = [1 0 1 0];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '221';\r\ntf = [0 1 1 0];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '247';\r\ntf = [0 1 0 1];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '46189';\r\ntf = [1 1 1 1];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '2133423721';\r\ntf = [1 1 1 1];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '233296158667';\r\ntf = [1 1 1 1];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '1011001000101010101010110101001010101001010101001001011010101000101010101010101010010101010010101010100101010101001100101010010101';\r\ntf = [0 0 0 0];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '1011001000101010101010110101001010101001010101001001011010101000101010101010101010010101010010101010100101010101001100101010010103';\r\ntf = [0 1 0 0];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '1011001000101010101010110101001010101001010101001001011010101000101010101010101010010101010010101010100101010101001100101010010107';\r\ntf = [0 0 0 1];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%\r\nn = '14300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = [1 1 0 0];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '14300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\ntf = [0 0 0 0];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '22100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = [0 1 1 0];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%% anti-cheating test\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn = '221';\r\n\t\ttf = [0 1 1 0];\r\n\tcase 2\r\n\t\tn = '233296158667';\r\n\t\ttf = [1 1 1 1];\r\n\tcase 3\r\n\t\tn = '46189';\r\n\t\ttf = [1 1 1 1];\r\n\tcase 4\r\n\t\tn = '247';\r\n\t\ttf = [0 1 0 1];\r\nend\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%% anti-cheating test\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn = '187';\r\n\t\ttf = [1 0 1 0];\r\n\tcase 2\r\n\t\tn = '143';\r\n\t\ttf = [1 1 0 0];\r\n\tcase 3\r\n\t\tn = '221';\r\n\t\ttf = [0 1 1 0];\r\n\tcase 4\r\n\t\tn = '233296158667';\r\n\t\ttf = [1 1 1 1];\r\nend\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%% anti-cheating test\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn = '2133423721';\r\n\t\ttf = [1 1 1 1];\r\n\tcase 2\r\n\t\tn = '46189';\r\n\t\ttf = [1 1 1 1];\r\n\tcase 3\r\n\t\tn = '187';\r\n\t\ttf = [1 0 1 0];\r\n\tcase 4\r\n\t\tn = '247';\r\n\t\ttf = [0 1 0 1];\r\nend\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":73,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-07-09T04:18:06.000Z","updated_at":"2025-12-28T20:47:42.000Z","published_at":"2015-07-09T04:18:06.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDivisibility checks against prime numbers can all be accomplished with the same routine, applied recursively, consisting of add or subtract x times the last digit to or from the remaining number. For example, for 13, add four times the last digit to the rest:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2392: 239 + 4*2 = 247: 24 + 4*7 = 52: 5 + 4*2 = 13 -\u0026gt; 2392 is divisible by 13.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor 17, subtract five times the last digit from the rest:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e3281: 328 - 5*1 = 323: 32 - 5*3 = 17 -\u0026gt; 3281 is divisible by 17.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor 19, add two times the last digit to the rest:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e16863: 1686 + 2*3 = 1692: 169 + 2*2 = 173: 17 + 2*3 = 23: 2 + 2*3 = 8 -\u0026gt; 16863 is not divisible by 19.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAnd, for 11, subtract the last digit from the rest:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e269830: 26983 - 0 = 26983: 2698 - 3 = 2695: 269 - 5 = 264: 26 - 4 = 22: 2 - 2 = 0 -\u0026gt; 269830 is divisible by 11.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to return a true-false vector for the prime numbers in the 11:20 range ([11 13 17 19]) based on a number supplied as a string.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRestrictions on Java, mod, ceil, round, and floor are still in effect.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42454-divisible-by-n-prime-divisors-including-powers\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, prime divisors (including powers)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42508-divisible-by-n-prime-divisors-from-20-to-200\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, prime divisors from 20 to 200\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":42412,"title":"Divisible by 10","description":"Pursuant to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 first problem\u003e in this series, this one involves checking for divisibility by 10.\r\n\r\nWrite a function to determine if a number is divisible by 10. This can be done by checking if the last digit is zero.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42411-divisible-by-9 divisible by 9\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42413-divisible-by-11 divisible by 11\u003e.\r\n","description_html":"\u003cp\u003ePursuant to the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003efirst problem\u003c/a\u003e in this series, this one involves checking for divisibility by 10.\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 10. This can be done by checking if the last digit is zero.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42411-divisible-by-9\"\u003edivisible by 9\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42413-divisible-by-11\"\u003edivisible by 11\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_10(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_10.m');\r\nassert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_10(n_str),0))\r\n\r\n%%\r\nn_str = '10';\r\nassert(isequal(divisible_by_10(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_10(n_str),0))\r\n\r\n%%\r\nn_str = '234';\r\nassert(isequal(divisible_by_10(n_str),0))\r\n\r\n%%\r\nn_str = '220';\r\nassert(isequal(divisible_by_10(n_str),1))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_10(n_str),0))\r\n\r\n%%\r\nn_str = '12361230';\r\nassert(isequal(divisible_by_10(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_10(n_str),1))\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904';\r\nassert(isequal(divisible_by_10(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_10(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_10(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_10(n_str),0))\r\n\r\n%%\r\nn_str = '31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632788659361533818279682303019520353018529689957736225994138912497217752834791315155748572424541506959508295331168617278558890750983817546374649393192550604009277016711390098488240128583616035637076601047101819429555961989467678374494482553797747268471040475346462080466842590694912933136770289891521047521620569660240580381501935112533824300355876402474964732639141992726042699227960';\r\nassert(isequal(divisible_by_10(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_10(n_str),0))\r\n\r\n%%\r\nn_str = '10100101010110101010010110101001011010100101001011010100110101001010010110';\r\nassert(isequal(divisible_by_10(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_10(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904';\r\n\t\tassert(isequal(divisible_by_10(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_10(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '220';\r\n\t\tassert(isequal(divisible_by_10(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_10(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '10100101010110101010010110101001011010100101001011010100110101001010010110';\r\n\t\tassert(isequal(divisible_by_10(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_10(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_10(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '13';\r\n\t\tassert(isequal(divisible_by_10(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_10(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_10(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_10(n_str),1))\r\nend\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":376,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T03:34:57.000Z","updated_at":"2026-03-24T13:02:48.000Z","published_at":"2015-06-25T03:34:57.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 10.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 10. This can be done by checking if the last digit is zero.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42411-divisible-by-9\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 9\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42413-divisible-by-11\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 11\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42407,"title":"Divisible by 5","description":"Pursuant to the first problem in this series, this one involves checking for divisibility by 5.\r\nWrite a function to determine if a number is divisible by 5. This can be checked by the following method:\r\nCheck if the last digits is 0 or 5.\r\nPrevious problem: divisible by 4. Next problem: divisible by 6.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 122.433px; display: block; min-width: 0px; padding-block-start: 0px; padding-inline-start: 2px; padding-left: 2px; padding-top: 0px; perspective-origin: 408px 61.2167px; transform-origin: 408px 61.2167px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 47.45px 7.79167px; transform-origin: 47.45px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ePursuant to the\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 1.94167px 7.79167px; transform-origin: 1.94167px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003e\u003cspan style=\"border-block-end-color: rgb(0, 91, 130); border-block-start-color: rgb(0, 91, 130); border-bottom-color: rgb(0, 91, 130); border-inline-end-color: rgb(0, 91, 130); border-inline-start-color: rgb(0, 91, 130); border-left-color: rgb(0, 91, 130); border-right-color: rgb(0, 91, 130); border-top-color: rgb(0, 91, 130); caret-color: rgb(0, 91, 130); color: rgb(0, 91, 130); column-rule-color: rgb(0, 91, 130); outline-color: rgb(0, 91, 130); text-decoration-color: rgb(0, 91, 130); text-emphasis-color: rgb(0, 91, 130); \"\u003e\u003cspan style=\"\"\u003efirst problem\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 184.767px 7.79167px; transform-origin: 184.767px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e in this series, this one involves checking for divisibility by 5.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 320.775px 7.79167px; transform-origin: 320.775px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to determine if a number is divisible by 5. This can be checked by the following method:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 20.4333px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: decimal; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 391px 10.2167px; transform-origin: 391px 10.2167px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 96.8417px 7.79167px; transform-origin: 96.8417px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eCheck if the last digits is 0 or 5.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 56.4083px 7.79167px; transform-origin: 56.4083px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ePrevious problem:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 1.94167px 7.79167px; transform-origin: 1.94167px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"http://www.mathworks.com/matlabcentral/cody/problems/42406-divisible-by-4\"\u003e\u003cspan style=\"border-block-end-color: rgb(0, 91, 130); border-block-start-color: rgb(0, 91, 130); border-bottom-color: rgb(0, 91, 130); border-inline-end-color: rgb(0, 91, 130); border-inline-start-color: rgb(0, 91, 130); border-left-color: rgb(0, 91, 130); border-right-color: rgb(0, 91, 130); border-top-color: rgb(0, 91, 130); caret-color: rgb(0, 91, 130); color: rgb(0, 91, 130); column-rule-color: rgb(0, 91, 130); outline-color: rgb(0, 91, 130); text-decoration-color: rgb(0, 91, 130); text-emphasis-color: rgb(0, 91, 130); \"\u003e\u003cspan style=\"\"\u003edivisible by 4\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 47.45px 7.79167px; transform-origin: 47.45px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. Next problem:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 1.94167px 7.79167px; transform-origin: 1.94167px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"http://www.mathworks.com/matlabcentral/cody/problems/42408-divisible-by-6\"\u003e\u003cspan style=\"border-block-end-color: rgb(0, 91, 130); border-block-start-color: rgb(0, 91, 130); border-bottom-color: rgb(0, 91, 130); border-inline-end-color: rgb(0, 91, 130); border-inline-start-color: rgb(0, 91, 130); border-left-color: rgb(0, 91, 130); border-right-color: rgb(0, 91, 130); border-top-color: rgb(0, 91, 130); caret-color: rgb(0, 91, 130); color: rgb(0, 91, 130); column-rule-color: rgb(0, 91, 130); outline-color: rgb(0, 91, 130); text-decoration-color: rgb(0, 91, 130); text-emphasis-color: rgb(0, 91, 130); \"\u003e\u003cspan style=\"\"\u003edivisible by 6\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 1.94167px 7.79167px; transform-origin: 1.94167px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [tf] = divisible_by_5(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_5.m');\r\nassert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\nassert(isempty(strfind(filetext, 'regexp ''')),'regexp hacks forbidden')\r\n%Last assert added by Dyuman Joshi on 02/01/2026\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_5(n_str),0))\r\n\r\n%%\r\nn_str = '13';\r\nassert(isequal(divisible_by_5(n_str),0))\r\n\r\n%%\r\nn_str = '225';\r\nassert(isequal(divisible_by_5(n_str),1))\r\n\r\n%%\r\nn_str = '232';\r\nassert(isequal(divisible_by_5(n_str),0))\r\n\r\n%%\r\nn_str = '223';\r\nassert(isequal(divisible_by_5(n_str),0))\r\n\r\n%%\r\nn_str = '1236125';\r\nassert(isequal(divisible_by_5(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_5(n_str),1))\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\nassert(isequal(divisible_by_5(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_5(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_5(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_5(n_str),0))\r\n\r\n%%\r\nn_str = '10100101010110101010010110101001011010100101001011010100110101001010';\r\nassert(isequal(divisible_by_5(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_5(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\n\t\tassert(isequal(divisible_by_5(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_5(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '225';\r\n\t\tassert(isequal(divisible_by_5(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '10100101010110101010010110101001011010100101001011010100110101001010';\r\n\t\tassert(isequal(divisible_by_5(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_5(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_5(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_5(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '13';\r\n\t\tassert(isequal(divisible_by_5(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_5(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_5(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_5(n_str),1))\r\nend","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":26769,"edited_by":223089,"edited_at":"2026-01-02T16:52:49.000Z","deleted_by":null,"deleted_at":null,"solvers_count":495,"test_suite_updated_at":"2026-01-02T16:52:49.000Z","rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T02:41:14.000Z","updated_at":"2026-03-24T09:37:28.000Z","published_at":"2015-06-25T02:41:14.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 5.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 5. This can be checked by the following method:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCheck if the last digits is 0 or 5.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42406-divisible-by-4\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 4\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42408-divisible-by-6\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 6\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":42404,"title":"Divisible by 2","description":"This is the first problem in a set of \"divisible by x\" problems. You will be provided a number as a string and the function you write must return whether or not that number is divisible by x.\r\n\r\nRather than allowing you to use an easy way out, such as the modulus function, division and checking the result against its rounded value, Java functions, etc., you get to learn and apply integer divisibility rules. For reference, some divisibility conditions for integers are listed \u003chttp://en.wikipedia.org/wiki/Divisibility_rule here\u003e. Other such references are also available elsewhere on the internet.\r\n\r\nThere are two benefits to approaching divisibility in this manner: first, you learn neat divisibility tricks that you can use in your head or on paper for large numbers and, second, you program a routine capable of determining divisibility for arbitrarily large numbers, for which existing precision fails. *_So, to begin..._*\r\n\r\nWrite a function to determine if a number is divisible by 2. This will be the case if its last digit is even.\r\n\r\n(This problem blocks a range of functions in the first test case so that you must use one of the supplied methods; some of these restrictions will be lifted for later problems in the series.)\r\n\r\nNext problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3 divisible by 3\u003e.","description_html":"\u003cp\u003eThis is the first problem in a set of \"divisible by x\" problems. You will be provided a number as a string and the function you write must return whether or not that number is divisible by x.\u003c/p\u003e\u003cp\u003eRather than allowing you to use an easy way out, such as the modulus function, division and checking the result against its rounded value, Java functions, etc., you get to learn and apply integer divisibility rules. For reference, some divisibility conditions for integers are listed \u003ca href = \"http://en.wikipedia.org/wiki/Divisibility_rule\"\u003ehere\u003c/a\u003e. Other such references are also available elsewhere on the internet.\u003c/p\u003e\u003cp\u003eThere are two benefits to approaching divisibility in this manner: first, you learn neat divisibility tricks that you can use in your head or on paper for large numbers and, second, you program a routine capable of determining divisibility for arbitrarily large numbers, for which existing precision fails. \u003cb\u003e\u003ci\u003eSo, to begin...\u003c/i\u003e\u003c/b\u003e\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 2. This will be the case if its last digit is even.\u003c/p\u003e\u003cp\u003e(This problem blocks a range of functions in the first test case so that you must use one of the supplied methods; some of these restrictions will be lifted for later problems in the series.)\u003c/p\u003e\u003cp\u003eNext problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\"\u003edivisible by 3\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_2(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_2.m');\r\nassert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'factor')),'factor() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_2(n_str),1))\r\n\r\n%%\r\nn_str = '13';\r\nassert(isequal(divisible_by_2(n_str),0))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_2(n_str),1))\r\n\r\n%%\r\nn_str = '232';\r\nassert(isequal(divisible_by_2(n_str),1))\r\n\r\n%%\r\nn_str = '223';\r\nassert(isequal(divisible_by_2(n_str),0))\r\n\r\n%%\r\nn_str = '1236127';\r\nassert(isequal(divisible_by_2(n_str),0))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_2(n_str),1))\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\nassert(isequal(divisible_by_2(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_2(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_2(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_2(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_2(n_str),0))\r\n\r\n%% anti-cheating test\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '222';\r\n\t\tassert(isequal(divisible_by_2(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\n\t\tassert(isequal(divisible_by_2(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '1236127';\r\n\t\tassert(isequal(divisible_by_2(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_2(n_str),1))\r\nend\r\n\r\n%% anti-cheating test\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_2(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_2(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_2(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '223';\r\n\t\tassert(isequal(divisible_by_2(n_str),0))\r\nend\r\n\r\n%% anti-cheating test\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '1236127';\r\n\t\tassert(isequal(divisible_by_2(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_2(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '222';\r\n\t\tassert(isequal(divisible_by_2(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\n\t\tassert(isequal(divisible_by_2(n_str),1))\r\nend","published":true,"deleted":false,"likes_count":10,"comments_count":8,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":616,"test_suite_updated_at":"2017-04-19T17:42:44.000Z","rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T02:14:54.000Z","updated_at":"2026-03-24T09:42:10.000Z","published_at":"2015-06-25T02:14:54.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is the first problem in a set of \\\"divisible by x\\\" problems. You will be provided a number as a string and the function you write must return whether or not that number is divisible by x.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRather than allowing you to use an easy way out, such as the modulus function, division and checking the result against its rounded value, Java functions, etc., you get to learn and apply integer divisibility rules. For reference, some divisibility conditions for integers are listed\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Divisibility_rule\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehere\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Other such references are also available elsewhere on the internet.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are two benefits to approaching divisibility in this manner: first, you learn neat divisibility tricks that you can use in your head or on paper for large numbers and, second, you program a routine capable of determining divisibility for arbitrarily large numbers, for which existing precision fails.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSo, to begin...\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 2. This will be the case if its last digit is even.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(This problem blocks a range of functions in the first test case so that you must use one of the supplied methods; some of these restrictions will be lifted for later problems in the series.)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNext problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42411,"title":"Divisible by 9","description":"Pursuant to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 first problem\u003e in this series, this one involves checking for divisibility by 9.\r\n\r\nWrite a function to determine if a number is divisible by 9. This can be done by the following method:\r\n\r\n# Sum the digits of the number. As with methods for other numbers, this summing step can be applied recursively until a single-digit number results. If the resulting number is divisible by nine, then so is the original number.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42410-divisible-by-8 divisible by 8\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42412-divisible-by-10 divisible by 10\u003e.","description_html":"\u003cp\u003ePursuant to the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003efirst problem\u003c/a\u003e in this series, this one involves checking for divisibility by 9.\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 9. This can be done by the following method:\u003c/p\u003e\u003col\u003e\u003cli\u003eSum the digits of the number. As with methods for other numbers, this summing step can be applied recursively until a single-digit number results. If the resulting number is divisible by nine, then so is the original number.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42410-divisible-by-8\"\u003edivisible by 8\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42412-divisible-by-10\"\u003edivisible by 10\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_9(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_9.m');\r\nassert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_9(n_str),0))\r\n\r\n%%\r\nn_str = '18';\r\nassert(isequal(divisible_by_9(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_9(n_str),0))\r\n\r\n%%\r\nn_str = '234';\r\nassert(isequal(divisible_by_9(n_str),1))\r\n\r\n%%\r\nn_str = '225';\r\nassert(isequal(divisible_by_9(n_str),1))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_9(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_9(n_str),1))\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904';\r\nassert(isequal(divisible_by_9(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_9(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_9(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_9(n_str),0))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_9(n_str),0))\r\n\r\n%%\r\nn_str = '10100101010110101010010110101001011010100101001011010100110101001010010110';\r\nassert(isequal(divisible_by_9(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_9(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904';\r\n\t\tassert(isequal(divisible_by_9(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_9(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '234';\r\n\t\tassert(isequal(divisible_by_9(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_9(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '10100101010110101010010110101001011010100101001011010100110101001010010110';\r\n\t\tassert(isequal(divisible_by_9(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_9(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_9(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '13';\r\n\t\tassert(isequal(divisible_by_9(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_9(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_9(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_9(n_str),1))\r\nend\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":277,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T03:31:29.000Z","updated_at":"2026-03-27T11:38:56.000Z","published_at":"2015-06-25T03:31:29.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 9.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 9. This can be done by the following method:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSum the digits of the number. As with methods for other numbers, this summing step can be applied recursively until a single-digit number results. If the resulting number is divisible by nine, then so is the original number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42410-divisible-by-8\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42412-divisible-by-10\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 10\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42408,"title":"Divisible by 6","description":"Pursuant to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 first problem\u003e in this series, this one involves checking for divisibility by 6.\r\n\r\nWrite a function to determine if a number is divisible by 6. This can be done by checking for \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 divisibility by 2\u003e and \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3 divisibility by 3\u003e. If the number passes both tests, it is also divisible by 6.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5 divisible by 5\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7 divisible by 7\u003e.","description_html":"\u003cp\u003ePursuant to the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003efirst problem\u003c/a\u003e in this series, this one involves checking for divisibility by 6.\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 6. This can be done by checking for \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003edivisibility by 2\u003c/a\u003e and \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\"\u003edivisibility by 3\u003c/a\u003e. If the number passes both tests, it is also divisible by 6.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5\"\u003edivisible by 5\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7\"\u003edivisible by 7\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_6(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_6.m');\r\nassert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_6(n_str),1))\r\n\r\n%%\r\nn_str = '13';\r\nassert(isequal(divisible_by_6(n_str),0))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_6(n_str),1))\r\n\r\n%%\r\nn_str = '232';\r\nassert(isequal(divisible_by_6(n_str),0))\r\n\r\n%%\r\nn_str = '223';\r\nassert(isequal(divisible_by_6(n_str),0))\r\n\r\n%%\r\nn_str = '1236126';\r\nassert(isequal(divisible_by_6(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_6(n_str),1))%\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\nassert(isequal(divisible_by_6(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_6(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_6(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_6(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_6(n_str),0))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_6(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\n\t\tassert(isequal(divisible_by_6(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_6(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '223';\r\n\t\tassert(isequal(divisible_by_6(n_str),0))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_6(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_6(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_6(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_6(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '13';\r\n\t\tassert(isequal(divisible_by_6(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_6(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_6(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_6(n_str),1))\r\nend","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":332,"test_suite_updated_at":"2015-06-25T03:14:53.000Z","rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T02:46:24.000Z","updated_at":"2026-03-24T12:51:01.000Z","published_at":"2015-06-25T02:46:24.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 6.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 6. This can be done by checking for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisibility by 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisibility by 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. If the number passes both tests, it is also divisible by 6.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 7\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42417,"title":"Divisible by 15","description":"Write a function to determine if a number is divisible by 15. If a number is \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3 divisible by 3\u003e and \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5 divisible by 5\u003e, then it is divisible by 15.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42416-divisible-by-14 divisible by 14\u003e. Next problem \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42418-divisible-by-16 divisible by 16\u003e.\r\n","description_html":"\u003cp\u003eWrite a function to determine if a number is divisible by 15. If a number is \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\"\u003edivisible by 3\u003c/a\u003e and \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5\"\u003edivisible by 5\u003c/a\u003e, then it is divisible by 15.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42416-divisible-by-14\"\u003edivisible by 14\u003c/a\u003e. Next problem \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42418-divisible-by-16\"\u003edivisible by 16\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_15(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_15.m');\r\n% assert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_15(n_str),0))\r\n\r\n%%\r\nn_str = '15';\r\nassert(isequal(divisible_by_15(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_15(n_str),0))\r\n\r\n%%\r\nn_str = '225';\r\nassert(isequal(divisible_by_15(n_str),1))\r\n\r\n%%\r\nn_str = '211';\r\nassert(isequal(divisible_by_15(n_str),0))\r\n\r\n%%\r\nn_str = '210';\r\nassert(isequal(divisible_by_15(n_str),1))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_15(n_str),0))\r\n\r\n%%\r\nn_str = '1236120';\r\nassert(isequal(divisible_by_15(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_15(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\nassert(isequal(divisible_by_15(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_15(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\nassert(isequal(divisible_by_15(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_15(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922790';\r\nassert(isequal(divisible_by_15(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_15(n_str),0))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100110';\r\nassert(isequal(divisible_by_15(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_15(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\n\t\tassert(isequal(divisible_by_15(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_15(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '210';\r\n\t\tassert(isequal(divisible_by_15(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_15(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '1010010101011010101001011010100101101010010100101101010011010100110';\r\n\t\tassert(isequal(divisible_by_15(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\n\t\tassert(isequal(divisible_by_15(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_15(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '222';\r\n\t\tassert(isequal(divisible_by_15(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_15(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\n\t\tassert(isequal(divisible_by_15(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_15(n_str),1))\r\nend\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":221,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-26T01:58:40.000Z","updated_at":"2026-03-27T16:43:11.000Z","published_at":"2015-06-26T01:58:40.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 15. If a number is\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, then it is divisible by 15.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42416-divisible-by-14\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 14\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42418-divisible-by-16\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 16\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42406,"title":"Divisible by 4","description":"Pursuant to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 first problem\u003e in this series, this one involves checking for divisibility by 4.\r\n\r\nWrite a function to determine if a number is divisible by 4. This can be checked by a few slightly different methods:\r\n\r\n# Check the last two digits for divisibility by four.\r\n# From the \u003chttps://en.wikipedia.org/wiki/Divisibility_rule wikipedia reference page\u003e: \"If the tens digit is even, the ones digit must be 0, 4, or 8.\r\nIf the tens digit is odd, the ones digit must be 2 or 6.\"\r\n# Check the following sum for divisibility by four: twice the tens digit plus the ones digit.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3 divisible by 3\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5 divisible by 5\u003e.","description_html":"\u003cp\u003ePursuant to the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003efirst problem\u003c/a\u003e in this series, this one involves checking for divisibility by 4.\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 4. This can be checked by a few slightly different methods:\u003c/p\u003e\u003col\u003e\u003cli\u003eCheck the last two digits for divisibility by four.\u003c/li\u003e\u003cli\u003eFrom the \u003ca href = \"https://en.wikipedia.org/wiki/Divisibility_rule\"\u003ewikipedia reference page\u003c/a\u003e: \"If the tens digit is even, the ones digit must be 0, 4, or 8.\r\nIf the tens digit is odd, the ones digit must be 2 or 6.\"\u003c/li\u003e\u003cli\u003eCheck the following sum for divisibility by four: twice the tens digit plus the ones digit.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\"\u003edivisible by 3\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5\"\u003edivisible by 5\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_4(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_4.m');\r\nassert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_4(n_str),1))\r\n\r\n%%\r\nn_str = '13';\r\nassert(isequal(divisible_by_4(n_str),0))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_4(n_str),0))\r\n\r\n%%\r\nn_str = '232';\r\nassert(isequal(divisible_by_4(n_str),1))\r\n\r\n%%\r\nn_str = '223';\r\nassert(isequal(divisible_by_4(n_str),0))\r\n\r\n%%\r\nn_str = '1236127';\r\nassert(isequal(divisible_by_4(n_str),0))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_4(n_str),0))\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\nassert(isequal(divisible_by_4(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_4(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_4(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_4(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_4(n_str),0))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_4(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\n\t\tassert(isequal(divisible_by_4(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_4(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '232';\r\n\t\tassert(isequal(divisible_by_4(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\n\t\tassert(isequal(divisible_by_4(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_4(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_4(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_4(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '13';\r\n\t\tassert(isequal(divisible_by_4(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_4(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_4(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_4(n_str),0))\r\nend","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":373,"test_suite_updated_at":"2015-06-25T03:13:44.000Z","rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T02:35:16.000Z","updated_at":"2026-03-24T10:06:27.000Z","published_at":"2015-06-25T02:35:16.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 4.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 4. This can be checked by a few slightly different methods:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCheck the last two digits for divisibility by four.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFrom the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Divisibility_rule\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ewikipedia reference page\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e: \\\"If the tens digit is even, the ones digit must be 0, 4, or 8.If the tens digit is odd, the ones digit must be 2 or 6.\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCheck the following sum for divisibility by four: twice the tens digit plus the ones digit.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42407-divisible-by-5\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42509,"title":"Divisible by n, Truncated-number Divisors","description":"Some divisors only require a few numbers at the end of the number in question to determine divisibility, no matter how long. Examples include 25, 32, 50, 64, 75, 100, 125, 128, 256, and 512. Notice that this list includes some prime-power divisors (e.g, 25 = 5^2, 32 = 2^5, 125 = 5^3, etc.). Write a function to determine if a given number, provided as a string (n_str), is divisible by the provided divisor. See the test suite for examples and rules for these simple divisors below:\r\n\r\n* 25: The last two digits must be divisible by 25.\r\n* 32: The last five digits must be divisible by 32.\r\n* 50: The last two digits must be 00 or 50.\r\n* 64: The last six digits must be divisible by 64.\r\n* 75: The number must be divisible by 3 (can be done by a \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3 simple sum\u003e) and end in 00, 25, 50, or 75 (last two digits divisible by 25). \r\n* 100: The last two digits must be 00.\r\n* 125: The last three digits must be divisible by 125.\r\n* 128: The last seven digits must be divisible by 128.\r\n* 256: The last eight digits must be divisible by 256.\r\n* 512: The last nine digits must be divisible by 512.\r\n\r\nThe only restriction that remains is Java.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42508-divisible-by-n-prime-divisors-from-20-to-200 Divisible by n, prime divisors from 20 to 200\u003e. Next problem \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42510-divisible-by-n-composite-divisors Divisible by n, Composite Divisors\u003e.","description_html":"\u003cp\u003eSome divisors only require a few numbers at the end of the number in question to determine divisibility, no matter how long. Examples include 25, 32, 50, 64, 75, 100, 125, 128, 256, and 512. Notice that this list includes some prime-power divisors (e.g, 25 = 5^2, 32 = 2^5, 125 = 5^3, etc.). Write a function to determine if a given number, provided as a string (n_str), is divisible by the provided divisor. See the test suite for examples and rules for these simple divisors below:\u003c/p\u003e\u003cul\u003e\u003cli\u003e25: The last two digits must be divisible by 25.\u003c/li\u003e\u003cli\u003e32: The last five digits must be divisible by 32.\u003c/li\u003e\u003cli\u003e50: The last two digits must be 00 or 50.\u003c/li\u003e\u003cli\u003e64: The last six digits must be divisible by 64.\u003c/li\u003e\u003cli\u003e75: The number must be divisible by 3 (can be done by a \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\"\u003esimple sum\u003c/a\u003e) and end in 00, 25, 50, or 75 (last two digits divisible by 25).\u003c/li\u003e\u003cli\u003e100: The last two digits must be 00.\u003c/li\u003e\u003cli\u003e125: The last three digits must be divisible by 125.\u003c/li\u003e\u003cli\u003e128: The last seven digits must be divisible by 128.\u003c/li\u003e\u003cli\u003e256: The last eight digits must be divisible by 256.\u003c/li\u003e\u003cli\u003e512: The last nine digits must be divisible by 512.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe only restriction that remains is Java.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42508-divisible-by-n-prime-divisors-from-20-to-200\"\u003eDivisible by n, prime divisors from 20 to 200\u003c/a\u003e. Next problem \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42510-divisible-by-n-composite-divisors\"\u003eDivisible by n, Composite Divisors\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = truncated_number_divisors(n,n_str)\r\n\r\ntf = 1;\r\n\r\nend","test_suite":"%%\r\nfiletext = fileread('truncated_number_divisors.m');\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn = 25;\r\nn_str = '123456789025';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 25;\r\nn_str = '1234567890250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 25;\r\nn_str = '1234567890250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 32;\r\nn_str = '213546116579874651316984601654958847098406516051320150408460840649084790870510201378465465046760406541654604601561065140637860373703970644065166540616510650165409684098049804165016510320540540645106056501650165709804650860466840650156106165028224';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 32;\r\nn_str = '213546116579874651316984601654958847098406516051320150408460840649084790870510201378465465046760406541654604601561065140637860373703970644065166540616510650165409684098049804165016510320540540645106056501650165709804650860466840650156106165028227';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 50;\r\nn_str = '15668045014654987098045406540500';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 50;\r\nn_str = '50440984098480149540561065106510516501615001';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 50;\r\nn_str = '50440984098480149540561065106510516501615001897241387234587503198417059813645097867234985672307485679813709582304957234897659832746098514949188412929894824924949334949777378994191995216173718811313515141418186186382171646871681436817897678350';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 64;\r\nn_str = '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890404992';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 64;\r\nn_str = '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890404996';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 64;\r\nn_str = '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111489216';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 64;\r\nn_str = '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111489217';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 75;\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789040499175';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 75;\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789040499275';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 100;\r\nn_str = '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890404992750';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 100;\r\nn_str = '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890404992700';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 100;\r\nn_str = '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890404992';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 100;\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789040499200';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 125;\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789040499200125';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 125;\r\nn_str = '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111489216';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 125;\r\nn_str = '111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111114892375';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 128;\r\nn_str = '1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111148923751048576';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 128;\r\nn_str = '1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111148923751048578';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 256;\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904049917516777216';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 256;\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904049917516777210';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 512;\r\nn_str = '10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000134217728';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 512;\r\nn_str = '10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000536870912';\r\ntf = 1;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 512;\r\nn_str = '10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000536870914';\r\ntf = 0;\r\nassert(isequal(truncated_number_divisors(n,n_str),tf))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":79,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-08-17T21:32:54.000Z","updated_at":"2026-01-11T10:42:54.000Z","published_at":"2015-08-17T21:32:54.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSome divisors only require a few numbers at the end of the number in question to determine divisibility, no matter how long. Examples include 25, 32, 50, 64, 75, 100, 125, 128, 256, and 512. Notice that this list includes some prime-power divisors (e.g, 25 = 5^2, 32 = 2^5, 125 = 5^3, etc.). Write a function to determine if a given number, provided as a string (n_str), is divisible by the provided divisor. See the test suite for examples and rules for these simple divisors below:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e25: The last two digits must be divisible by 25.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e32: The last five digits must be divisible by 32.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e50: The last two digits must be 00 or 50.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e64: The last six digits must be divisible by 64.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e75: The number must be divisible by 3 (can be done by a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esimple sum\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e) and end in 00, 25, 50, or 75 (last two digits divisible by 25).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e100: The last two digits must be 00.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e125: The last three digits must be divisible by 125.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e128: The last seven digits must be divisible by 128.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e256: The last eight digits must be divisible by 256.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e512: The last nine digits must be divisible by 512.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe only restriction that remains is Java.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42508-divisible-by-n-prime-divisors-from-20-to-200\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, prime divisors from 20 to 200\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42510-divisible-by-n-composite-divisors\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, Composite Divisors\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42414,"title":"Divisible by 12","description":"Write a function to determine if a number is divisible by 12. Similar to the number six, this can be done by checking for divisibility of two numbers, in this case, \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3 divisibility by 3\u003e and \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42406-divisible-by-4 divisibility by 4\u003e. If the number passes both tests, it is also divisible by 12.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42413-divisible-by-11 divisible by 11\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42415-divisible-by-13 divisible by 13\u003e.\r\n","description_html":"\u003cp\u003eWrite a function to determine if a number is divisible by 12. Similar to the number six, this can be done by checking for divisibility of two numbers, in this case, \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\"\u003edivisibility by 3\u003c/a\u003e and \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42406-divisible-by-4\"\u003edivisibility by 4\u003c/a\u003e. If the number passes both tests, it is also divisible by 12.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42413-divisible-by-11\"\u003edivisible by 11\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42415-divisible-by-13\"\u003edivisible by 13\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_12(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_12.m');\r\nassert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_12(n_str),1))\r\n\r\n%%\r\nn_str = '11';\r\nassert(isequal(divisible_by_12(n_str),0))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_12(n_str),0))\r\n\r\n%%\r\nn_str = '228';\r\nassert(isequal(divisible_by_12(n_str),1))\r\n\r\n%%\r\nn_str = '242';\r\nassert(isequal(divisible_by_12(n_str),0))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_12(n_str),0))\r\n\r\n%%\r\nn_str = '1236120';\r\nassert(isequal(divisible_by_12(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_12(n_str),0))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\nassert(isequal(divisible_by_12(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_12(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_12(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_12(n_str),1))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922790';\r\nassert(isequal(divisible_by_12(n_str),0))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_12(n_str),0))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_12(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\n\t\tassert(isequal(divisible_by_12(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_12(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '222';\r\n\t\tassert(isequal(divisible_by_12(n_str),0))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_12(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\n\t\tassert(isequal(divisible_by_12(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_12(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_12(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '228';\r\n\t\tassert(isequal(divisible_by_12(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_12(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_12(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_12(n_str),0))\r\nend\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":210,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T03:54:07.000Z","updated_at":"2026-03-27T16:47:41.000Z","published_at":"2015-06-25T03:54:07.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 12. Similar to the number six, this can be done by checking for divisibility of two numbers, in this case,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42405-divisible-by-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisibility by 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42406-divisible-by-4\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisibility by 4\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. If the number passes both tests, it is also divisible by 12.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42413-divisible-by-11\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 11\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42415-divisible-by-13\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 13\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42410,"title":"Divisible by 8","description":"Pursuant to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 first problem\u003e in this series, this one involves checking for divisibility by 8.\r\n\r\nWrite a function to determine if a number is divisible by 8. This can be done by the following method:\r\n\r\n# Check the last three digits for divisibility by eight. If that portion of the number is divisible by eight, then so is the original number. That three-digit number can be further reduced by summing four times the hundreds digit, two times the tens digit, and the ones digit. As with methods for other numbers, this factor/sum step can be applied recursively until a single-digit number results.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7 divisible by 7\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42411-divisible-by-9 divisible by 9\u003e.","description_html":"\u003cp\u003ePursuant to the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003efirst problem\u003c/a\u003e in this series, this one involves checking for divisibility by 8.\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 8. This can be done by the following method:\u003c/p\u003e\u003col\u003e\u003cli\u003eCheck the last three digits for divisibility by eight. If that portion of the number is divisible by eight, then so is the original number. That three-digit number can be further reduced by summing four times the hundreds digit, two times the tens digit, and the ones digit. As with methods for other numbers, this factor/sum step can be applied recursively until a single-digit number results.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7\"\u003edivisible by 7\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42411-divisible-by-9\"\u003edivisible by 9\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_8(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_8.m');\r\n%assert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_8(n_str),0))\r\n\r\n%%\r\nn_str = '16';\r\nassert(isequal(divisible_by_8(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_8(n_str),0))\r\n\r\n%%\r\nn_str = '232';\r\nassert(isequal(divisible_by_8(n_str),1))\r\n\r\n%%\r\nn_str = '224';\r\nassert(isequal(divisible_by_8(n_str),1))\r\n\r\n%%\r\nn_str = '1236128';\r\nassert(isequal(divisible_by_8(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_8(n_str),0))%\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904';\r\nassert(isequal(divisible_by_8(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_8(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_8(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_8(n_str),0))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_8(n_str),0))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_8(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904';\r\n\t\tassert(isequal(divisible_by_8(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_8(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '232';\r\n\t\tassert(isequal(divisible_by_8(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_8(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '16';\r\n\t\tassert(isequal(divisible_by_8(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_8(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_8(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '13';\r\n\t\tassert(isequal(divisible_by_8(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_8(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_8(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678904';\r\n\t\tassert(isequal(divisible_by_8(n_str),1))\r\nend\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":243,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T03:23:41.000Z","updated_at":"2026-03-27T11:43:47.000Z","published_at":"2015-06-25T03:23:41.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 8.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 8. This can be done by the following method:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCheck the last three digits for divisibility by eight. If that portion of the number is divisible by eight, then so is the original number. That three-digit number can be further reduced by summing four times the hundreds digit, two times the tens digit, and the ones digit. As with methods for other numbers, this factor/sum step can be applied recursively until a single-digit number results.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 7\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42411-divisible-by-9\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 9\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42454,"title":"Divisible by n, prime divisors (including powers)","description":"For this problem, you will be provided an array of numbers (not necessarily in order). Return the array of numbers with only prime divisors (including prime powers) remaining in the array. For example:\r\n\r\n  n = 1:10;\r\n  n_p = [2 3 4 5 7 8 9];\r\n\r\nSince the prime numbers in the 1:10 range are 2, 3, 5, and 7, while the prime powers in this range are 4 (2^2), 8 (2^3), and 9 (3^2). (Ignore one, as it is a trivial case since all integers are divisible by one.) Therefore, you should return the array including both sets joined together and sorted, as shown in the example above.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors Divisible by n, prime vs. composite divisors\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42455-divisible-by-n-prime-divisors-11-13-17-19 Divisible by n, prime divisors - 11, 13, 17, \u0026 19\u003e.","description_html":"\u003cp\u003eFor this problem, you will be provided an array of numbers (not necessarily in order). Return the array of numbers with only prime divisors (including prime powers) remaining in the array. For example:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003en = 1:10;\r\nn_p = [2 3 4 5 7 8 9];\r\n\u003c/pre\u003e\u003cp\u003eSince the prime numbers in the 1:10 range are 2, 3, 5, and 7, while the prime powers in this range are 4 (2^2), 8 (2^3), and 9 (3^2). (Ignore one, as it is a trivial case since all integers are divisible by one.) Therefore, you should return the array including both sets joined together and sorted, as shown in the example above.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors\"\u003eDivisible by n, prime vs. composite divisors\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42455-divisible-by-n-prime-divisors-11-13-17-19\"\u003eDivisible by n, prime divisors - 11, 13, 17, \u0026 19\u003c/a\u003e.\u003c/p\u003e","function_template":"function [n_p] = prime_divisors_incl_powers(n)\r\n\r\nn_p = 1;\r\n\r\nend","test_suite":"%%\r\nn = 1:10;\r\nn_p = [2 3 4 5 7 8 9]; %prime factors (including powers)\r\nassert(isequal(n_p,prime_divisors_incl_powers(n)))\r\n\r\n%%\r\nn = [2:7 12:17 10 42:55 11 19:29];\r\nn_p = [2 3 4 5 7 11 13 16 17 19 23 25 27 29 43 47 49 53]; %prime factors (including powers)\r\nassert(isequal(n_p,prime_divisors_incl_powers(n)))\r\n\r\n%%\r\nn = 1:100;\r\nn_p = [2 3 4 5 7 8 9 11 13 16 17 19 23 25 27 29 31 32 37 41 43 47 49 53 59 61 64 67 71 73 79 81 83 89 97]; %prime factors (including powers)\r\nassert(isequal(n_p,prime_divisors_incl_powers(n)))\r\n\r\n%%\r\nn = 41:59;\r\nn_p = [41 43 47 49 53 59]; %prime factors (including powers)\r\nassert(isequal(n_p,prime_divisors_incl_powers(n)))\r\n\r\n%%\r\nn = 100:200;\r\nn_p = [101 103 107 109 113 121 125 127 128 131 137 139 149 151 157 163 167 169 173 179 181 191 193 197 199]; %prime factors (including powers)\r\nassert(isequal(n_p,prime_divisors_incl_powers(n)))\r\n\r\n%%\r\nn = 1000:1111;\r\nn_p = [1009 1013 1019 1021 1024 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109]; %prime factors (including powers)\r\nassert(isequal(n_p,prime_divisors_incl_powers(n)))\r\n\r\n%% anti-cheating test case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn = 1:10;\r\n\t\tn_p = [2 3 4 5 7 8 9]; %prime factors (including powers)\r\n\tcase 2\r\n\t\tn = 41:59;\r\n\t\tn_p = [41 43 47 49 53 59]; %prime factors (including powers)\r\n\tcase 3\r\n\t\tn = 1:100;\r\n\t\tn_p = [2 3 4 5 7 8 9 11 13 16 17 19 23 25 27 29 31 32 37 41 43 47 49 53 59 61 64 67 71 73 79 81 83 89 97]; %prime factors (including powers)\r\n\tcase 4\r\n\t\tn = [2:7 12:17 10 42:55 11 19:29];\r\n\t\tn_p = [2 3 4 5 7 11 13 16 17 19 23 25 27 29 43 47 49 53];\r\nend\r\nassert(isequal(n_p,prime_divisors_incl_powers(n)))\r\n\r\n%% anti-cheating test case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn = 1:100;\r\n\t\tn_p = [2 3 4 5 7 8 9 11 13 16 17 19 23 25 27 29 31 32 37 41 43 47 49 53 59 61 64 67 71 73 79 81 83 89 97]; %prime factors (including powers)\r\n\tcase 2\r\n\t\tn = [2:7 12:17 10 42:55 11 19:29];\r\n\t\tn_p = [2 3 4 5 7 11 13 16 17 19 23 25 27 29 43 47 49 53];\r\n\tcase 3\r\n\t\tn = 41:59;\r\n\t\tn_p = [41 43 47 49 53 59]; %prime factors (including powers)\r\n\tcase 4\r\n\t\tn = 1000:1111;\r\n\t\tn_p = [1009 1013 1019 1021 1024 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109]; %prime factors (including powers)\r\nend\r\nassert(isequal(n_p,prime_divisors_incl_powers(n)))\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":95,"test_suite_updated_at":"2017-03-20T19:03:08.000Z","rescore_all_solutions":false,"group_id":22,"created_at":"2015-07-09T01:55:28.000Z","updated_at":"2026-01-11T12:28:45.000Z","published_at":"2015-07-09T01:55:28.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor this problem, you will be provided an array of numbers (not necessarily in order). Return the array of numbers with only prime divisors (including prime powers) remaining in the array. For example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[n = 1:10;\\nn_p = [2 3 4 5 7 8 9];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSince the prime numbers in the 1:10 range are 2, 3, 5, and 7, while the prime powers in this range are 4 (2^2), 8 (2^3), and 9 (3^2). (Ignore one, as it is a trivial case since all integers are divisible by one.) Therefore, you should return the array including both sets joined together and sorted, as shown in the example above.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, prime vs. composite divisors\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42455-divisible-by-n-prime-divisors-11-13-17-19\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, prime divisors - 11, 13, 17, \u0026amp; 19\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42413,"title":"Divisible by 11","description":"Pursuant to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 first problem\u003e in this series, this one involves checking for divisibility by 11.\r\n\r\nWrite a function to determine if a number is divisible by 11. Like the number seven, this can be done by a variety of methods. Some are:\r\n\r\n# Form the alternating sum of the digits (e.g., positive even digits and negative odd digits). Apply recursively until a two-digit number results. If that result is divisible by 11, then so is the original number.\r\n# Add the digits of the number in blocks of two from right to left. Apply recursively, as needed, and check for divisibility as stated in the previous method.\r\n# Subtract the last digit from the remaining number (e.g., 649: 64 - 9 = 55). Apply recursion, as needed.\r\n# Add ten times the last digit to the remaining number. Apply recursion, as needed. For example: 737: 73 + 70 = 143: 14 + 30 = 44.\r\n# Etc.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42412-divisible-by-10 divisible by 10\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42414-divisible-by-12 divisible by 12\u003e.\r\n","description_html":"\u003cp\u003ePursuant to the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003efirst problem\u003c/a\u003e in this series, this one involves checking for divisibility by 11.\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 11. Like the number seven, this can be done by a variety of methods. Some are:\u003c/p\u003e\u003col\u003e\u003cli\u003eForm the alternating sum of the digits (e.g., positive even digits and negative odd digits). Apply recursively until a two-digit number results. If that result is divisible by 11, then so is the original number.\u003c/li\u003e\u003cli\u003eAdd the digits of the number in blocks of two from right to left. Apply recursively, as needed, and check for divisibility as stated in the previous method.\u003c/li\u003e\u003cli\u003eSubtract the last digit from the remaining number (e.g., 649: 64 - 9 = 55). Apply recursion, as needed.\u003c/li\u003e\u003cli\u003eAdd ten times the last digit to the remaining number. Apply recursion, as needed. For example: 737: 73 + 70 = 143: 14 + 30 = 44.\u003c/li\u003e\u003cli\u003eEtc.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42412-divisible-by-10\"\u003edivisible by 10\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42414-divisible-by-12\"\u003edivisible by 12\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_11(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_11.m');\r\n%assert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\n%assert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_11(n_str),0))\r\n\r\n%%\r\nn_str = '11';\r\nassert(isequal(divisible_by_11(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_11(n_str),0))\r\n\r\n%%\r\nn_str = '231';\r\nassert(isequal(divisible_by_11(n_str),1))\r\n\r\n%%\r\nn_str = '242';\r\nassert(isequal(divisible_by_11(n_str),1))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_11(n_str),0))\r\n\r\n%%\r\nn_str = '1236125';\r\nassert(isequal(divisible_by_11(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_11(n_str),0))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567881';\r\nassert(isequal(divisible_by_11(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_11(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007';\r\nassert(isequal(divisible_by_11(n_str),1))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_11(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922789';\r\nassert(isequal(divisible_by_11(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_11(n_str),0))\r\n\r\n%%\r\nn_str = '10100101010110101010010110101001011010100101001011010100110101001010010110';\r\nassert(isequal(divisible_by_11(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_11(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567881';\r\n\t\tassert(isequal(divisible_by_11(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_11(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '231';\r\n\t\tassert(isequal(divisible_by_11(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_11(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '10100101010110101010010110101001011010100101001011010100110101001010010110';\r\n\t\tassert(isequal(divisible_by_11(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007';\r\n\t\tassert(isequal(divisible_by_11(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_11(n_str),0))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '242';\r\n\t\tassert(isequal(divisible_by_11(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_11(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007';\r\n\t\tassert(isequal(divisible_by_11(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_11(n_str),0))\r\nend\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":3,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":175,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T03:49:05.000Z","updated_at":"2025-12-29T20:09:06.000Z","published_at":"2015-06-25T03:49:05.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 11.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 11. Like the number seven, this can be done by a variety of methods. Some are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eForm the alternating sum of the digits (e.g., positive even digits and negative odd digits). Apply recursively until a two-digit number results. If that result is divisible by 11, then so is the original number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAdd the digits of the number in blocks of two from right to left. Apply recursively, as needed, and check for divisibility as stated in the previous method.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSubtract the last digit from the remaining number (e.g., 649: 64 - 9 = 55). Apply recursion, as needed.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAdd ten times the last digit to the remaining number. Apply recursion, as needed. For example: 737: 73 + 70 = 143: 14 + 30 = 44.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEtc.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42412-divisible-by-10\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 10\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42414-divisible-by-12\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 12\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42416,"title":"Divisible by 14","description":"Write a function to determine if a number is divisible by 14. If a number is \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 divisible by 2\u003e and \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7 divisible by 7\u003e, then it is divisible by 14.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42415-divisible-by-13 divisible by 13\u003e. Next problem \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42417-divisible-by-15 divisible by 15\u003e.","description_html":"\u003cp\u003eWrite a function to determine if a number is divisible by 14. If a number is \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003edivisible by 2\u003c/a\u003e and \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7\"\u003edivisible by 7\u003c/a\u003e, then it is divisible by 14.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42415-divisible-by-13\"\u003edivisible by 13\u003c/a\u003e. Next problem \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42417-divisible-by-15\"\u003edivisible by 15\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_14(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_14.m');\r\n% assert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_14(n_str),0))\r\n\r\n%%\r\nn_str = '14';\r\nassert(isequal(divisible_by_14(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_14(n_str),0))\r\n\r\n%%\r\nn_str = '224';\r\nassert(isequal(divisible_by_14(n_str),1))\r\n\r\n%%\r\nn_str = '210';\r\nassert(isequal(divisible_by_14(n_str),1))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_14(n_str),0))\r\n\r\n%%\r\nn_str = '1236130';\r\nassert(isequal(divisible_by_14(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_14(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\nassert(isequal(divisible_by_14(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_14(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\nassert(isequal(divisible_by_14(n_str),1))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_14(n_str),1))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922799';\r\nassert(isequal(divisible_by_14(n_str),0))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_14(n_str),0))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100110';\r\nassert(isequal(divisible_by_14(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_14(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\n\t\tassert(isequal(divisible_by_14(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_14(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '210';\r\n\t\tassert(isequal(divisible_by_14(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_14(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '1010010101011010101001011010100101101010010100101101010011010100110';\r\n\t\tassert(isequal(divisible_by_14(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\n\t\tassert(isequal(divisible_by_14(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_14(n_str),0))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '222';\r\n\t\tassert(isequal(divisible_by_14(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_14(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\n\t\tassert(isequal(divisible_by_14(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_14(n_str),1))\r\nend\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":153,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-26T01:47:26.000Z","updated_at":"2026-03-27T16:40:51.000Z","published_at":"2015-06-26T01:47:26.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 14. If a number is\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42409-divisible-by-7\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 7\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, then it is divisible by 14.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42415-divisible-by-13\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 13\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42417-divisible-by-15\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 15\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42418,"title":"Divisible by 16","description":"Write a function to determine if a number is divisible by 16. This can be done by a few different methods. Here are two:\r\n\r\n# If a number has four or more digits, take the last three digits. Add eight to it if the thousands digit in the original number is odd (zero if even). If this three-digit number is divisible by 16, so is the original number. The resulting number can also be reduced by the following method.\r\n# Take the last two digits and add them to four times the remaining number. Apply this method recursively until a two-digit number remains. As usual, if the resulting number is divisible by 16, then so is the original number.\r\n\r\nA few of the function restrictions have been lifted.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42417-divisible-by-15 divisible by 15\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors divisible by n, prime vs. composite divisors\u003e.","description_html":"\u003cp\u003eWrite a function to determine if a number is divisible by 16. This can be done by a few different methods. Here are two:\u003c/p\u003e\u003col\u003e\u003cli\u003eIf a number has four or more digits, take the last three digits. Add eight to it if the thousands digit in the original number is odd (zero if even). If this three-digit number is divisible by 16, so is the original number. The resulting number can also be reduced by the following method.\u003c/li\u003e\u003cli\u003eTake the last two digits and add them to four times the remaining number. Apply this method recursively until a two-digit number remains. As usual, if the resulting number is divisible by 16, then so is the original number.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eA few of the function restrictions have been lifted.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42417-divisible-by-15\"\u003edivisible by 15\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors\"\u003edivisible by n, prime vs. composite divisors\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_16(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_16.m');\r\n% assert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\n% assert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\n% assert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\n% assert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\n% assert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_16(n_str),0))\r\n\r\n%%\r\nn_str = '16';\r\nassert(isequal(divisible_by_16(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_16(n_str),0))\r\n\r\n%%\r\nn_str = '224';\r\nassert(isequal(divisible_by_16(n_str),1))\r\n\r\n%%\r\nn_str = '208';\r\nassert(isequal(divisible_by_16(n_str),1))\r\n\r\n%%\r\nn_str = '210';\r\nassert(isequal(divisible_by_16(n_str),0))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_16(n_str),0))\r\n\r\n%%\r\nn_str = '1236128';\r\nassert(isequal(divisible_by_16(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_16(n_str),0))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567888';\r\nassert(isequal(divisible_by_16(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_16(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\nassert(isequal(divisible_by_16(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_16(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922784';\r\nassert(isequal(divisible_by_16(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_16(n_str),0))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100112';\r\nassert(isequal(divisible_by_16(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_16(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567888';\r\n\t\tassert(isequal(divisible_by_16(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_16(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '208';\r\n\t\tassert(isequal(divisible_by_16(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_16(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '1010010101011010101001011010100101101010010100101101010011010100112';\r\n\t\tassert(isequal(divisible_by_16(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\n\t\tassert(isequal(divisible_by_16(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_16(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '1236123';\r\n\t\tassert(isequal(divisible_by_16(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_16(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012';\r\n\t\tassert(isequal(divisible_by_16(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567888';\r\n\t\tassert(isequal(divisible_by_16(n_str),1))\r\nend\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":178,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-26T02:08:33.000Z","updated_at":"2026-03-31T13:28:32.000Z","published_at":"2015-06-26T02:08:33.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 16. This can be done by a few different methods. Here are two:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf a number has four or more digits, take the last three digits. Add eight to it if the thousands digit in the original number is odd (zero if even). If this three-digit number is divisible by 16, so is the original number. The resulting number can also be reduced by the following method.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTake the last two digits and add them to four times the remaining number. Apply this method recursively until a two-digit number remains. As usual, if the resulting number is divisible by 16, then so is the original number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA few of the function restrictions have been lifted.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42417-divisible-by-15\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 15\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by n, prime vs. composite divisors\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42405,"title":"Divisible by 3","description":"Pursuant to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 first problem\u003e in this series, this one involves checking for divisibility by 3.\r\n\r\nWrite a function to determine if a number is divisible by 3. This can be checked by at least two different methods:\r\n\r\n# Sum the digits in the number. If the resulting sum is divisible by 3, then so is the original number. This routine can be applied recursively until the resulting sum is a single digit.\r\n# From the \u003chttps://en.wikipedia.org/wiki/Divisibility_rule wikipedia reference page\u003e: \"Subtract the quantity of the digits 2, 5, and 8 in the number from the quantity of the digits 1, 4, and 7 in the number.\" If the resulting sum (absolute value) is a multiple of 3, then so is the original number.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 divisible by 2\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42406-divisible-by-4 divisible by 4\u003e.","description_html":"\u003cp\u003ePursuant to the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003efirst problem\u003c/a\u003e in this series, this one involves checking for divisibility by 3.\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 3. This can be checked by at least two different methods:\u003c/p\u003e\u003col\u003e\u003cli\u003eSum the digits in the number. If the resulting sum is divisible by 3, then so is the original number. This routine can be applied recursively until the resulting sum is a single digit.\u003c/li\u003e\u003cli\u003eFrom the \u003ca href = \"https://en.wikipedia.org/wiki/Divisibility_rule\"\u003ewikipedia reference page\u003c/a\u003e: \"Subtract the quantity of the digits 2, 5, and 8 in the number from the quantity of the digits 1, 4, and 7 in the number.\" If the resulting sum (absolute value) is a multiple of 3, then so is the original number.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003edivisible by 2\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42406-divisible-by-4\"\u003edivisible by 4\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_3(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_3.m');\r\nassert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_3(n_str),1))\r\n\r\n%%\r\nn_str = '13';\r\nassert(isequal(divisible_by_3(n_str),0))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_3(n_str),1))\r\n\r\n%%\r\nn_str = '232';\r\nassert(isequal(divisible_by_3(n_str),0))\r\n\r\n%%\r\nn_str = '223';\r\nassert(isequal(divisible_by_3(n_str),0))\r\n\r\n%%\r\nn_str = '1236127';\r\nassert(isequal(divisible_by_3(n_str),0))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_3(n_str),1))\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\nassert(isequal(divisible_by_3(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_3(n_str),1))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_3(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_3(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_3(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_3(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\n\t\tassert(isequal(divisible_by_3(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_3(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '1236127';\r\n\t\tassert(isequal(divisible_by_3(n_str),0))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\n\t\tassert(isequal(divisible_by_3(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_3(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_3(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '13';\r\n\t\tassert(isequal(divisible_by_3(n_str),0))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '13';\r\n\t\tassert(isequal(divisible_by_3(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_3(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_3(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_3(n_str),1))\r\nend","published":true,"deleted":false,"likes_count":12,"comments_count":7,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":429,"test_suite_updated_at":"2015-06-25T03:11:34.000Z","rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T02:27:10.000Z","updated_at":"2026-03-24T12:40:53.000Z","published_at":"2015-06-25T02:27:10.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 3.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 3. This can be checked by at least two different methods:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSum the digits in the number. If the resulting sum is divisible by 3, then so is the original number. This routine can be applied recursively until the resulting sum is a single digit.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFrom the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Divisibility_rule\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ewikipedia reference page\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e: \\\"Subtract the quantity of the digits 2, 5, and 8 in the number from the quantity of the digits 1, 4, and 7 in the number.\\\" If the resulting sum (absolute value) is a multiple of 3, then so is the original number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42406-divisible-by-4\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 4\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42510,"title":"Divisible by n, Composite Divisors","description":"Pursuant to \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors Divisible by n, prime vs. composite divisors\u003e, this problem requires you to write a function that determines divisibility for a large number (n_str) when the divisor is a composite. As was required in that problem, you will need to formulate the highest-power factorization of the divisor. Divisibility of n_str can then be determined by testing against each highest-power factor. For simplicity, this problem is restricted to numbers that contain the following as highest-power factors: 2, 3, 4, 5, 8, 9, and 10, as these divisibility tests are trivial. Their rules are included briefly below, for reference.\r\n\r\nAs an example, a number is divisible by 30 if it is divisible by 2, 3, and 5, as those are the highest-power factors for 30. Likewise, a number is divisible by 36 if it is divisible by 4 and 9 (not 3), as those are its highest-power factors.\r\n\r\nThe only restriction that remains is Java.\r\n\r\n* Divisible by 2: if the last digit is divisible by 2.\r\n* Divisible by 3: if the sum of the number's digits (n_str) is divisible by 3. Apply iteratively, as necessary, to arrive at a single-digit number.\r\n* Divisible by 4: if the last two digits are divisible by 4.\r\n* Divisible by 5: if the last digit is a 0 or 5.\r\n* Divisible by 8: if the last three digits are divisible by 8.\r\n* Divisible by 9: if the sum of the number's digits (n_str) is divisible by 9. Apply iteratively, as necessary, to arrive at a single-digit number.\r\n* Divisible by 10: if the last digit is zero.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42509-divisible-by-n-truncated-number-divisors Divisible by n, Truncated-number Divisors\u003e.","description_html":"\u003cp\u003ePursuant to \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors\"\u003eDivisible by n, prime vs. composite divisors\u003c/a\u003e, this problem requires you to write a function that determines divisibility for a large number (n_str) when the divisor is a composite. As was required in that problem, you will need to formulate the highest-power factorization of the divisor. Divisibility of n_str can then be determined by testing against each highest-power factor. For simplicity, this problem is restricted to numbers that contain the following as highest-power factors: 2, 3, 4, 5, 8, 9, and 10, as these divisibility tests are trivial. Their rules are included briefly below, for reference.\u003c/p\u003e\u003cp\u003eAs an example, a number is divisible by 30 if it is divisible by 2, 3, and 5, as those are the highest-power factors for 30. Likewise, a number is divisible by 36 if it is divisible by 4 and 9 (not 3), as those are its highest-power factors.\u003c/p\u003e\u003cp\u003eThe only restriction that remains is Java.\u003c/p\u003e\u003cul\u003e\u003cli\u003eDivisible by 2: if the last digit is divisible by 2.\u003c/li\u003e\u003cli\u003eDivisible by 3: if the sum of the number's digits (n_str) is divisible by 3. Apply iteratively, as necessary, to arrive at a single-digit number.\u003c/li\u003e\u003cli\u003eDivisible by 4: if the last two digits are divisible by 4.\u003c/li\u003e\u003cli\u003eDivisible by 5: if the last digit is a 0 or 5.\u003c/li\u003e\u003cli\u003eDivisible by 8: if the last three digits are divisible by 8.\u003c/li\u003e\u003cli\u003eDivisible by 9: if the sum of the number's digits (n_str) is divisible by 9. Apply iteratively, as necessary, to arrive at a single-digit number.\u003c/li\u003e\u003cli\u003eDivisible by 10: if the last digit is zero.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42509-divisible-by-n-truncated-number-divisors\"\u003eDivisible by n, Truncated-number Divisors\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = composite_divisors(n,n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('composite_divisors.m');\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn = 18;\r\nn_str = '612220032';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 18;\r\nn_str = '612220031';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 18;\r\nn_str = '64268410079232';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 18;\r\nn_str = '192805230237696';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 18;\r\nn_str = '64268410079230';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 18;\r\nn_str = '192805230237696000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 18;\r\nn_str = '192805230237696000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 30;\r\nn_str = '64268410079230';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 30;\r\nn_str = '64268410079220';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 90;\r\nn_str = '47829690000000';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 90;\r\nn_str = '47829690000001';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 36;\r\nn_str = '101559956668416';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 36;\r\nn_str = '101559956668417';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 36;\r\nn_str = '3046798700052480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 36;\r\nn_str = '3046798700052480000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 40;\r\nn_str = '262144000000000';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 40;\r\nn_str = '262144000000008';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 40;\r\nn_str = '52428800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 40;\r\nn_str = '52428800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 24;\r\nn_str = '4586471424';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 24;\r\nn_str = '45864714247';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 24;\r\nn_str = '26418075402240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020';\r\ntf = 0;\r\nassert(isequal(composite_divisors(n,n_str),tf))\r\n\r\n%%\r\nn = 24;\r\nn_str = '26418075402240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(composite_divisors(n,n_str),tf))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":76,"test_suite_updated_at":"2015-08-18T17:06:20.000Z","rescore_all_solutions":false,"group_id":22,"created_at":"2015-08-18T01:06:51.000Z","updated_at":"2026-01-11T11:13:47.000Z","published_at":"2015-08-18T01:06:51.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42453-divisible-by-n-prime-vs-composite-divisors\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, prime vs. composite divisors\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, this problem requires you to write a function that determines divisibility for a large number (n_str) when the divisor is a composite. As was required in that problem, you will need to formulate the highest-power factorization of the divisor. Divisibility of n_str can then be determined by testing against each highest-power factor. For simplicity, this problem is restricted to numbers that contain the following as highest-power factors: 2, 3, 4, 5, 8, 9, and 10, as these divisibility tests are trivial. Their rules are included briefly below, for reference.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs an example, a number is divisible by 30 if it is divisible by 2, 3, and 5, as those are the highest-power factors for 30. Likewise, a number is divisible by 36 if it is divisible by 4 and 9 (not 3), as those are its highest-power factors.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe only restriction that remains is Java.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by 2: if the last digit is divisible by 2.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by 3: if the sum of the number's digits (n_str) is divisible by 3. Apply iteratively, as necessary, to arrive at a single-digit number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by 4: if the last two digits are divisible by 4.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by 5: if the last digit is a 0 or 5.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by 8: if the last three digits are divisible by 8.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by 9: if the sum of the number's digits (n_str) is divisible by 9. Apply iteratively, as necessary, to arrive at a single-digit number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by 10: if the last digit is zero.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42509-divisible-by-n-truncated-number-divisors\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, Truncated-number Divisors\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42453,"title":"Divisible by n, prime vs. composite divisors","description":"In general, there are two types of divisibility checks; the first involves composite divisors and the second prime divisors, including powers of prime numbers (technically composite divisors, though they often function similar to prime numbers for the sake of divisibility). We'll get into the specifics of the two divisibility check types in subsequent problems. For now, we'll segregate numbers into three groups, based on type (n_type) while also returning the number's highest-power factorization (hpf). Write a function to return these two variables for a given number; see the following examples for reference:\r\n\r\n  n = 11  |  n_type = 1 (prime)        |  hpf = [11]\r\n  n = 31  |  n_type = 1 (prime)        |  hpf = [31]\r\n  n = 9   |  n_type = 2 (prime power)  |  hpf = [9] (3^2)\r\n  n = 32  |  n_type = 2 (prime power)  |  hpf = [32] (2^5)\r\n  n = 49  |  n_type = 2 (prime power)  |  hpf = [49] (7^2)\r\n  n = 21  |  n_type = 3 (composite)    |  hpf = [3,7]\r\n  n = 39  |  n_type = 3 (composite)    |  hpf = [3,13]\r\n  n = 42  |  n_type = 3 (composite)    |  hpf = [2,3,7]\r\n  n = 63  |  n_type = 3 (composite)    |  hpf = [9,7] ([3^2,7])\r\n  n = 90  |  n_type = 3 (composite)    |  hpf = [2,9,5] ([2,3^2,5])\r\n\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42418-divisible-by-16 divisible by 16\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42454-divisible-by-n-prime-divisors-including-powers Divisible by n, prime divisors (including powers)\u003e.","description_html":"\u003cp\u003eIn general, there are two types of divisibility checks; the first involves composite divisors and the second prime divisors, including powers of prime numbers (technically composite divisors, though they often function similar to prime numbers for the sake of divisibility). We'll get into the specifics of the two divisibility check types in subsequent problems. For now, we'll segregate numbers into three groups, based on type (n_type) while also returning the number's highest-power factorization (hpf). Write a function to return these two variables for a given number; see the following examples for reference:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003en = 11  |  n_type = 1 (prime)        |  hpf = [11]\r\nn = 31  |  n_type = 1 (prime)        |  hpf = [31]\r\nn = 9   |  n_type = 2 (prime power)  |  hpf = [9] (3^2)\r\nn = 32  |  n_type = 2 (prime power)  |  hpf = [32] (2^5)\r\nn = 49  |  n_type = 2 (prime power)  |  hpf = [49] (7^2)\r\nn = 21  |  n_type = 3 (composite)    |  hpf = [3,7]\r\nn = 39  |  n_type = 3 (composite)    |  hpf = [3,13]\r\nn = 42  |  n_type = 3 (composite)    |  hpf = [2,3,7]\r\nn = 63  |  n_type = 3 (composite)    |  hpf = [9,7] ([3^2,7])\r\nn = 90  |  n_type = 3 (composite)    |  hpf = [2,9,5] ([2,3^2,5])\r\n\u003c/pre\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42418-divisible-by-16\"\u003edivisible by 16\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42454-divisible-by-n-prime-divisors-including-powers\"\u003eDivisible by n, prime divisors (including powers)\u003c/a\u003e.\u003c/p\u003e","function_template":"function [n_type,hpf] = composite_vs_prime_divisor(n)\r\n\r\nn_type = 1;\r\nhpf = [1];\r\n\r\nend\r\n","test_suite":"%%\r\nn = 5;\r\ntf_corr = 1; %prime factor\r\nhpf_corr = 5;\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 7;\r\ntf_corr = 1; %prime factor\r\nhpf_corr = 7;\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 15;\r\ntf_corr = 3; %composite factor\r\nhpf_corr = [3,5];\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 25;\r\ntf_corr = 2; %composite factor, prime power (5^2)\r\nhpf_corr = 25;\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 125;\r\ntf_corr = 2; %composite factor, prime power (5^3)\r\nhpf_corr = 125;\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 20;\r\ntf_corr = 3; %composite factor\r\nhpf_corr = [4,5];\r\n[tf,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(tf,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 42;\r\ntf_corr = 3; %composite factor\r\nhpf_corr = [2,3,7];\r\n[tf,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(tf,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 18;\r\ntf_corr = 3; %composite factor\r\nhpf_corr = [2,9];\r\n[tf,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(tf,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 29;\r\ntf_corr = 1; %prime factor\r\nhpf_corr = 29;\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 39;\r\ntf_corr = 3; %composite factor\r\nhpf_corr = [3,13];\r\n[tf,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(tf,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 64;\r\ntf_corr = 2; %composite factor, prime power (2^6)\r\nhpf_corr = 64;\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%%\r\nn = 27;\r\ntf_corr = 2; %composite factor, prime power (3^3)\r\nhpf_corr = 27;\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%% anti-cheating test case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn = 29;\r\n\t\ttf_corr = 1; %prime factor\r\n\t\thpf_corr = 29;\r\n\tcase 2\r\n\t\tn = 42;\r\n\t\ttf_corr = 3; %composite factor\r\n\t\thpf_corr = [2,3,7];\r\n\tcase 3\r\n\t\tn = 18;\r\n\t\ttf_corr = 3; %composite factor\r\n\t\thpf_corr = [2,9];\r\n\tcase 4\r\n\t\tn = 42;\r\n\t\ttf_corr = 3; %composite factor\r\n\t\thpf_corr = [2,3,7];\r\nend\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%% anti-cheating test case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn = 64;\r\n\t\ttf_corr = 2; %composite factor, prime power (2^6)\r\n\t\thpf_corr = 64;\r\n\tcase 2\r\n\t\tn = 27;\r\n\t\ttf_corr = 2; %composite factor, prime power (3^3)\r\n\t\thpf_corr = 27;\r\n\tcase 3\r\n\t\tn = 42;\r\n\t\ttf_corr = 3; %composite factor\r\n\t\thpf_corr = [2,3,7];\r\n\tcase 4\r\n\t\tn = 18;\r\n\t\ttf_corr = 3; %composite factor\r\n\t\thpf_corr = [2,9];\r\nend\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n\r\n%% anti-cheating test case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn = 39;\r\n\t\ttf_corr = 3; %composite factor\r\n\t\thpf_corr = [3,13];\r\n\tcase 2\r\n\t\tn = 5;\r\n\t\ttf_corr = 1; %prime factor\r\n\t\thpf_corr = 5;\r\n\tcase 3\r\n\t\tn = 18;\r\n\t\ttf_corr = 3; %composite factor\r\n\t\thpf_corr = [2,9];\r\n\tcase 4\r\n\t\tn = 27;\r\n\t\ttf_corr = 2; %composite factor, prime power (3^3)\r\n\t\thpf_corr = 27;\r\nend\r\n[n_type,hpf] = composite_vs_prime_divisor(n);\r\nassert(isequal(n_type,tf_corr))\r\nassert(isequal(hpf,hpf_corr))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":113,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-07-09T01:29:13.000Z","updated_at":"2026-01-11T11:07:59.000Z","published_at":"2015-07-09T01:29:13.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn general, there are two types of divisibility checks; the first involves composite divisors and the second prime divisors, including powers of prime numbers (technically composite divisors, though they often function similar to prime numbers for the sake of divisibility). We'll get into the specifics of the two divisibility check types in subsequent problems. For now, we'll segregate numbers into three groups, based on type (n_type) while also returning the number's highest-power factorization (hpf). Write a function to return these two variables for a given number; see the following examples for reference:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[n = 11  |  n_type = 1 (prime)        |  hpf = [11]\\nn = 31  |  n_type = 1 (prime)        |  hpf = [31]\\nn = 9   |  n_type = 2 (prime power)  |  hpf = [9] (3^2)\\nn = 32  |  n_type = 2 (prime power)  |  hpf = [32] (2^5)\\nn = 49  |  n_type = 2 (prime power)  |  hpf = [49] (7^2)\\nn = 21  |  n_type = 3 (composite)    |  hpf = [3,7]\\nn = 39  |  n_type = 3 (composite)    |  hpf = [3,13]\\nn = 42  |  n_type = 3 (composite)    |  hpf = [2,3,7]\\nn = 63  |  n_type = 3 (composite)    |  hpf = [9,7] ([3^2,7])\\nn = 90  |  n_type = 3 (composite)    |  hpf = [2,9,5] ([2,3^2,5])]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42418-divisible-by-16\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 16\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42454-divisible-by-n-prime-divisors-including-powers\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, prime divisors (including powers)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42415,"title":"Divisible by 13","description":"Write a function to determine if a number is divisible by 13. Similar to the number seven, this can be done by a few different methods:\r\n\r\n# Form the alternating sum of blocks of three (separated at the comma locations). Apply this recursively until a three-digit number remains. If this number is divisible by 13, then so is the original number. This three-digit number can also be further reduced using one of the other methods below.\r\n# Add four times the last digit to the remaining number. Apply recursively until a two-digit number remains. As before, if this number is divisible by 13, then so is the original number.\r\n# Similar to the previous method, multiply the last digit by nine and subtract it from the remaining number. Apply recursion, etc.\r\n\r\nSome of the function restrictions have been lifted.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42414-divisible-by-12 divisible by 12\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42416-divisible-by-14 divisible by 14\u003e.","description_html":"\u003cp\u003eWrite a function to determine if a number is divisible by 13. Similar to the number seven, this can be done by a few different methods:\u003c/p\u003e\u003col\u003e\u003cli\u003eForm the alternating sum of blocks of three (separated at the comma locations). Apply this recursively until a three-digit number remains. If this number is divisible by 13, then so is the original number. This three-digit number can also be further reduced using one of the other methods below.\u003c/li\u003e\u003cli\u003eAdd four times the last digit to the remaining number. Apply recursively until a two-digit number remains. As before, if this number is divisible by 13, then so is the original number.\u003c/li\u003e\u003cli\u003eSimilar to the previous method, multiply the last digit by nine and subtract it from the remaining number. Apply recursion, etc.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eSome of the function restrictions have been lifted.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42414-divisible-by-12\"\u003edivisible by 12\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42416-divisible-by-14\"\u003edivisible by 14\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_13(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_13.m');\r\n% assert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\n% assert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\n% assert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_13(n_str),0))\r\n\r\n%%\r\nn_str = '13';\r\nassert(isequal(divisible_by_13(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_13(n_str),0))\r\n\r\n%%\r\nn_str = '228';\r\nassert(isequal(divisible_by_13(n_str),0))\r\n\r\n%%\r\nn_str = '221';\r\nassert(isequal(divisible_by_13(n_str),1))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_13(n_str),0))\r\n\r\n%%\r\nn_str = '1236131';\r\nassert(isequal(divisible_by_13(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_13(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\nassert(isequal(divisible_by_13(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_13(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006';\r\nassert(isequal(divisible_by_13(n_str),1))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_13(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922799';\r\nassert(isequal(divisible_by_13(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_13(n_str),0))\r\n\r\n%%\r\nn_str = '10100101010110101010010110101001011010100101001011010100110101001007';\r\nassert(isequal(divisible_by_13(n_str),1))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '12';\r\n\t\tassert(isequal(divisible_by_13(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567896';\r\n\t\tassert(isequal(divisible_by_13(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_13(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '221';\r\n\t\tassert(isequal(divisible_by_13(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_13(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '10100101010110101010010110101001011010100101001011010100110101001007';\r\n\t\tassert(isequal(divisible_by_13(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006';\r\n\t\tassert(isequal(divisible_by_13(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_13(n_str),0))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '228';\r\n\t\tassert(isequal(divisible_by_13(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_13(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006';\r\n\t\tassert(isequal(divisible_by_13(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_13(n_str),1))\r\nend\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":157,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-26T01:40:22.000Z","updated_at":"2025-12-24T20:24:26.000Z","published_at":"2015-06-26T01:40:22.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 13. Similar to the number seven, this can be done by a few different methods:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eForm the alternating sum of blocks of three (separated at the comma locations). Apply this recursively until a three-digit number remains. If this number is divisible by 13, then so is the original number. This three-digit number can also be further reduced using one of the other methods below.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAdd four times the last digit to the remaining number. Apply recursively until a two-digit number remains. As before, if this number is divisible by 13, then so is the original number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSimilar to the previous method, multiply the last digit by nine and subtract it from the remaining number. Apply recursion, etc.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSome of the function restrictions have been lifted.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42414-divisible-by-12\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 12\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42416-divisible-by-14\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 14\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42409,"title":"Divisible by 7","description":"Pursuant to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2 first problem\u003e in this series, this one involves checking for divisibility by 7.\r\n\r\nWrite a function to determine if a number is divisible by 7. This can be done by a variety of methods. Some are:\r\n\r\n# Multiply each digit in the candidate number (from right to left) by the digit in the corresponding position in this pattern: 1, 3, 2, -1, -3, -2 (1 applies to the ones digit, 3 to the tens digit, etc.). This pattern should be repeated beyond the hundred-thousands digit. The resulting sum will be a smaller number. This method can be applied recursively to the absolute values of the resulting sum until a single digit results. Then, check that number for divisibility by seven.\r\n# The previous method can also be used applying a slightly different pattern: 1, 3, 2, 6, 4, 5 (1 applies to the ones digit again, etc.). The absolute value of the resulting sum is not necessary as none of the factors are negative.\r\n# Multiply the last (ones) digit by two and subtract the result from the remaining number. Apply recursively, as noted in methods above.\r\n# Similar to the previous method, multiply the last digit by five and add to the remaining number. Apply recursively, as noted in methods above.\r\n# Double the last digit and subtract it from the remaining number (original number except for the ones digit). Apply this recursively until a single digit results. If that number is divisible by seven, then so is the original number.\r\n# Similar to the previous method, multiply the ones digit by five and add it to the remaining number. Apply this recursively until a single digit results. If that number is divisible by seven, then so is the original number.\r\n# Along similar lines, take the last three digits of the number and subtract that number from the remaining number. Once you reach a number less than 1000, another method can be applied to further reduce the number to check for divisibility by seven.\r\n# Etc. (there are others)\r\n\r\nThe restriction for multiplication has been lifted for this specific problem.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42408-divisible-by-6 divisible by 6\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42410-divisible-by-8 divisible by 8\u003e.","description_html":"\u003cp\u003ePursuant to the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\"\u003efirst problem\u003c/a\u003e in this series, this one involves checking for divisibility by 7.\u003c/p\u003e\u003cp\u003eWrite a function to determine if a number is divisible by 7. This can be done by a variety of methods. Some are:\u003c/p\u003e\u003col\u003e\u003cli\u003eMultiply each digit in the candidate number (from right to left) by the digit in the corresponding position in this pattern: 1, 3, 2, -1, -3, -2 (1 applies to the ones digit, 3 to the tens digit, etc.). This pattern should be repeated beyond the hundred-thousands digit. The resulting sum will be a smaller number. This method can be applied recursively to the absolute values of the resulting sum until a single digit results. Then, check that number for divisibility by seven.\u003c/li\u003e\u003cli\u003eThe previous method can also be used applying a slightly different pattern: 1, 3, 2, 6, 4, 5 (1 applies to the ones digit again, etc.). The absolute value of the resulting sum is not necessary as none of the factors are negative.\u003c/li\u003e\u003cli\u003eMultiply the last (ones) digit by two and subtract the result from the remaining number. Apply recursively, as noted in methods above.\u003c/li\u003e\u003cli\u003eSimilar to the previous method, multiply the last digit by five and add to the remaining number. Apply recursively, as noted in methods above.\u003c/li\u003e\u003cli\u003eDouble the last digit and subtract it from the remaining number (original number except for the ones digit). Apply this recursively until a single digit results. If that number is divisible by seven, then so is the original number.\u003c/li\u003e\u003cli\u003eSimilar to the previous method, multiply the ones digit by five and add it to the remaining number. Apply this recursively until a single digit results. If that number is divisible by seven, then so is the original number.\u003c/li\u003e\u003cli\u003eAlong similar lines, take the last three digits of the number and subtract that number from the remaining number. Once you reach a number less than 1000, another method can be applied to further reduce the number to check for divisibility by seven.\u003c/li\u003e\u003cli\u003eEtc. (there are others)\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eThe restriction for multiplication has been lifted for this specific problem.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42408-divisible-by-6\"\u003edivisible by 6\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42410-divisible-by-8\"\u003edivisible by 8\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = divisible_by_7(n_str)\r\n\r\ntf = 1;\r\n\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('divisible_by_7.m');\r\n%assert(isempty(strfind(filetext, '*')),'* forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross() forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod() forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')\r\nassert(isempty(strfind(filetext, 'times')),'times() forbidden')\r\nassert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')\r\nassert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')),'\\ forbidden')\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')),'dot() forbidden')\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn_str = '12';\r\nassert(isequal(divisible_by_7(n_str),0))\r\n\r\n%%\r\nn_str = '14';\r\nassert(isequal(divisible_by_7(n_str),1))\r\n\r\n%%\r\nn_str = '222';\r\nassert(isequal(divisible_by_7(n_str),0))\r\n\r\n%%\r\nn_str = '231';\r\nassert(isequal(divisible_by_7(n_str),1))\r\n\r\n%%\r\nn_str = '224';\r\nassert(isequal(divisible_by_7(n_str),1))\r\n\r\n%%\r\nn_str = '1236123';\r\nassert(isequal(divisible_by_7(n_str),1))\r\n\r\n%%\r\nn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\nassert(isequal(divisible_by_7(n_str),1))\r\n\r\n%%\r\nn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\nassert(isequal(divisible_by_7(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\nassert(isequal(divisible_by_7(n_str),0))\r\n\r\n%%\r\nn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\nassert(isequal(divisible_by_7(n_str),0))\r\n\r\n%%\r\nn_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';\r\nassert(isequal(divisible_by_7(n_str),1))\r\n\r\n%%\r\nn_str = '1010010101011010101001011010100101101010010100101101010011010100101';\r\nassert(isequal(divisible_by_7(n_str),0))\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '14';\r\n\t\tassert(isequal(divisible_by_7(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';\r\n\t\tassert(isequal(divisible_by_7(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_7(n_str),1))\r\n\tcase 4\r\n\t\tn_str = '231';\r\n\t\tassert(isequal(divisible_by_7(n_str),1))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '101001010101101010100101101010010110101001010010110101001101010010101';\r\n\t\tassert(isequal(divisible_by_7(n_str),0))\r\n\tcase 2\r\n\t\tn_str = '224';\r\n\t\tassert(isequal(divisible_by_7(n_str),1))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_7(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_7(n_str),0))\r\nend\r\n\r\n%% anti-cheating case\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn_str = '1236123';\r\n\t\tassert(isequal(divisible_by_7(n_str),1))\r\n\tcase 2\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\n\t\tassert(isequal(divisible_by_7(n_str),0))\r\n\tcase 3\r\n\t\tn_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\n\t\tassert(isequal(divisible_by_7(n_str),0))\r\n\tcase 4\r\n\t\tn_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';\r\n\t\tassert(isequal(divisible_by_7(n_str),1))\r\nend","published":true,"deleted":false,"likes_count":2,"comments_count":5,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":183,"test_suite_updated_at":"2015-06-25T03:15:21.000Z","rescore_all_solutions":false,"group_id":22,"created_at":"2015-06-25T03:07:11.000Z","updated_at":"2025-12-29T13:23:25.000Z","published_at":"2015-06-25T03:07:11.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42404-divisible-by-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efirst problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in this series, this one involves checking for divisibility by 7.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine if a number is divisible by 7. This can be done by a variety of methods. Some are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMultiply each digit in the candidate number (from right to left) by the digit in the corresponding position in this pattern: 1, 3, 2, -1, -3, -2 (1 applies to the ones digit, 3 to the tens digit, etc.). This pattern should be repeated beyond the hundred-thousands digit. The resulting sum will be a smaller number. This method can be applied recursively to the absolute values of the resulting sum until a single digit results. Then, check that number for divisibility by seven.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe previous method can also be used applying a slightly different pattern: 1, 3, 2, 6, 4, 5 (1 applies to the ones digit again, etc.). The absolute value of the resulting sum is not necessary as none of the factors are negative.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMultiply the last (ones) digit by two and subtract the result from the remaining number. Apply recursively, as noted in methods above.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSimilar to the previous method, multiply the last digit by five and add to the remaining number. Apply recursively, as noted in methods above.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDouble the last digit and subtract it from the remaining number (original number except for the ones digit). Apply this recursively until a single digit results. If that number is divisible by seven, then so is the original number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSimilar to the previous method, multiply the ones digit by five and add it to the remaining number. Apply this recursively until a single digit results. If that number is divisible by seven, then so is the original number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAlong similar lines, take the last three digits of the number and subtract that number from the remaining number. Once you reach a number less than 1000, another method can be applied to further reduce the number to check for divisibility by seven.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEtc. (there are others)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe restriction for multiplication has been lifted for this specific problem.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42408-divisible-by-6\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 6\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42410-divisible-by-8\\\"\u003e\u003cw:r\u003e\u003cw:t\u003edivisible by 8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42508,"title":"Divisible by n, prime divisors from 20 to 200","description":"Pursuant to the previous problem (linked below), this problem requires a function that checks for divisibility of large numbers for any prime number from 20 to 200. Similar to the previous problem, these can all be checked using the same routine: add or subtract x times the last digit to or from the remaining number after removing that last digit. For example, for 127, the last-digit factor is -38:\r\n\r\n* 2048379: 204837 + -38*9 = 204495: 20449 + -38*5 = 20259: 2025 + -38*9 = 1683: 168 + -38*3 = 54 -\u003e 2048379 is not divisible by 127 since 54 is not divisible by 127.\r\n\r\n* 4853940: 485394 + -38*0 = 485394: 48539 + -38*4 = 48387: 4838 + -38*7 = 4572: 457 + -38*2 = 381: 38 + -38*1 = 0 -\u003e 4853940 is divisible by 127.\r\n\r\nYour function will be provided with the prime number, n, and the number to check for divisibility as a string, n_str. Write a function that returns true or false for each prime number and candidate number pair. See the test suite for more examples. The template function will include arrays of all possible prime number in the given range in addition to a paired array with the associated factors.\r\n\r\nRestrictions on Java, mod, ceil, round, and floor are still in effect.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42455-divisible-by-n-prime-divisors-11-13-17-19 Divisible by n, prime divisors - 11, 13, 17, \u0026 19\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42509-divisible-by-n-truncated-number-divisors Divisible by n, Truncated-number Divisors\u003e.","description_html":"\u003cp\u003ePursuant to the previous problem (linked below), this problem requires a function that checks for divisibility of large numbers for any prime number from 20 to 200. Similar to the previous problem, these can all be checked using the same routine: add or subtract x times the last digit to or from the remaining number after removing that last digit. For example, for 127, the last-digit factor is -38:\u003c/p\u003e\u003cul\u003e\u003cli\u003e2048379: 204837 + -38*9 = 204495: 20449 + -38*5 = 20259: 2025 + -38*9 = 1683: 168 + -38*3 = 54 -\u0026gt; 2048379 is not divisible by 127 since 54 is not divisible by 127.\u003c/li\u003e\u003c/ul\u003e\u003cul\u003e\u003cli\u003e4853940: 485394 + -38*0 = 485394: 48539 + -38*4 = 48387: 4838 + -38*7 = 4572: 457 + -38*2 = 381: 38 + -38*1 = 0 -\u0026gt; 4853940 is divisible by 127.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eYour function will be provided with the prime number, n, and the number to check for divisibility as a string, n_str. Write a function that returns true or false for each prime number and candidate number pair. See the test suite for more examples. The template function will include arrays of all possible prime number in the given range in addition to a paired array with the associated factors.\u003c/p\u003e\u003cp\u003eRestrictions on Java, mod, ceil, round, and floor are still in effect.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42455-divisible-by-n-prime-divisors-11-13-17-19\"\u003eDivisible by n, prime divisors - 11, 13, 17, \u0026 19\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42509-divisible-by-n-truncated-number-divisors\"\u003eDivisible by n, Truncated-number Divisors\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = prime_divisors_20_to_200(n,n_str)\r\n\r\np_digits =      [23 29  31 37  41 43  47 53 59 61 67  71 73 79 83 89 97  101 103 107 109 113 127 131 137 139  149  151 157 163  167 173  179  181 191 193  197 199];\r\nlast_dig_mult = [7  3  -3 -11 -4  13 -14 16 6 -6 -20 -7 -51 8  25 9 -29 -10 -72 -32 -98 -79 -38 -13 -41 -125 -134 -15 -47 -114 -50 -121 -161 -18 -19 -135 -59 -179];\r\n\r\ntf = 1;\r\n\r\nend","test_suite":"%%\r\nfiletext = fileread('prime_divisors_20_to_200.m');\r\nassert(isempty(strfind(filetext, 'rem')),'rem() forbidden')\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn = 23;\r\nn_str = '943';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 23;\r\nn_str = '9430000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 23;\r\nn_str = '9430000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 29;\r\nn_str = '22649';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 31;\r\nn_str = '992';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 31;\r\nn_str = '9920000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 31;\r\nn_str = '9920000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 37;\r\nn_str = '4107';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 41;\r\nn_str = '33292';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 43;\r\nn_str = '85140';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 43;\r\nn_str = '851400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 43;\r\nn_str = '851400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 47;\r\nn_str = '232603';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 53;\r\nn_str = '148877';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 59;\r\nn_str = '12698688';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 61;\r\nn_str = '61965813';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 61;\r\nn_str = '619658130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 61;\r\nn_str = '619658130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 67;\r\nn_str = '22319844';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 71;\r\nn_str = '25411681';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 73;\r\nn_str = '328500';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 73;\r\nn_str = '32850000000000000000000000000000000000000000000000000000000000001000000000000';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 79;\r\nn_str = '41977440';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 83;\r\nn_str = '342873';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 89;\r\nn_str = '8900000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 97;\r\nn_str = '88529281';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 101;\r\nn_str = '104060401';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 101;\r\nn_str = '1040604010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 101;\r\nn_str = '1040604010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 103;\r\nn_str = '112550881';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 107;\r\nn_str = '515205';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 109;\r\nn_str = '141158161';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 113;\r\nn_str = '2151294';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 113;\r\nn_str = '2151294000000000000000000000000113000000000000000000000000113000000000000000000000000113000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 113;\r\nn_str = '2151294000000000000000000000000113000000000000000000000000113000000000000000000000000113000000000000000000000112';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 127;\r\nn_str = '4853940';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 131;\r\nn_str = '294499921';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 137;\r\nn_str = '249421241';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 139;\r\nn_str = '2685619';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 139;\r\nn_str = '268561900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013900000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 139;\r\nn_str = '268561900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013900000000000000000000000000000000000000000000000000000000000000000000000013';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 149;\r\nn_str = '512977200';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 151;\r\nn_str = '141160991';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 157;\r\nn_str = '607573201';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 163;\r\nn_str = '705911761';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 167;\r\nn_str = '777796321';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 173;\r\nn_str = '154963892093';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 179;\r\nn_str = '98682340334763';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 181;\r\nn_str = '35161828327081';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 191;\r\nn_str = '884089868985578';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 193;\r\nn_str = '1387488001';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 197;\r\nn_str = '27000544548887';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 199;\r\nn_str = '328039798800';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 199;\r\nn_str = '32803979880000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 199;\r\nn_str = '32803979880000000000000000000000000000000000000000000000000000000000000001990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001990000000000000000000000000000000000199000000000000';\r\ntf = 1;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n\r\n%%\r\nn = 199;\r\nn_str = '32803979880000000000000000000000000000000000000000000000000000000000000001991000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001990000000000000000000000000000000000199000000000000';\r\ntf = 0;\r\nassert(isequal(prime_divisors_20_to_200(n,n_str),tf))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":68,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-08-17T19:05:44.000Z","updated_at":"2025-12-27T11:58:28.000Z","published_at":"2015-08-17T19:05:44.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePursuant to the previous problem (linked below), this problem requires a function that checks for divisibility of large numbers for any prime number from 20 to 200. Similar to the previous problem, these can all be checked using the same routine: add or subtract x times the last digit to or from the remaining number after removing that last digit. For example, for 127, the last-digit factor is -38:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2048379: 204837 + -38*9 = 204495: 20449 + -38*5 = 20259: 2025 + -38*9 = 1683: 168 + -38*3 = 54 -\u0026gt; 2048379 is not divisible by 127 since 54 is not divisible by 127.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4853940: 485394 + -38*0 = 485394: 48539 + -38*4 = 48387: 4838 + -38*7 = 4572: 457 + -38*2 = 381: 38 + -38*1 = 0 -\u0026gt; 4853940 is divisible by 127.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour function will be provided with the prime number, n, and the number to check for divisibility as a string, n_str. Write a function that returns true or false for each prime number and candidate number pair. See the test suite for more examples. The template function will include arrays of all possible prime number in the given range in addition to a paired array with the associated factors.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRestrictions on Java, mod, ceil, round, and floor are still in effect.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42455-divisible-by-n-prime-divisors-11-13-17-19\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, prime divisors - 11, 13, 17, \u0026amp; 19\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42509-divisible-by-n-truncated-number-divisors\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, Truncated-number Divisors\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":3079,"title":"Big numbers, repeated least significant digits","description":"This problem builds off of Problem 3077\r\nGiven an integer x which contains d digits, find the value of (minimum) n (n \u003e 1) such that the last d digits of x^n is equal to x. If the last d digits will never equal x, return inf.\r\nExample 1:\r\nx = 2; (therefore d = 1)\r\n2^2 = 4, 2^3 = 8, 2^4 = 16, 2^5 = 32\r\nn = 5;\r\nExample 2:\r\nx = 10; (therefore d = 2)\r\n10^2 = 100, 10^3 = 1000, etc\r\nn = inf;","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 285.6px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 142.8px; transform-origin: 407px 142.8px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 79.5px 8px; transform-origin: 79.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis problem builds off of\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 3077\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"perspective-origin: 186.5px 8px; transform-origin: 186.5px 8px; \"\u003eGiven an integer x which contains d digits, find the value of \u003c/span\u003e\u003cspan style=\"border-block-end-style: solid; border-block-end-width: 1px; border-bottom-style: solid; border-bottom-width: 1px; perspective-origin: 2.5px 8.5px; transform-origin: 2.5px 8.5px; \"\u003e(\u003c/span\u003e\u003cspan style=\"perspective-origin: 27.5px 8px; transform-origin: 27.5px 8px; \"\u003eminimum\u003c/span\u003e\u003cspan style=\"border-block-end-style: solid; border-block-end-width: 1px; border-bottom-style: solid; border-bottom-width: 1px; perspective-origin: 2.5px 8.5px; transform-origin: 2.5px 8.5px; \"\u003e)\u003c/span\u003e\u003cspan style=\"perspective-origin: 165px 8px; transform-origin: 165px 8px; \"\u003e n (n \u0026gt; 1) such that the last d digits of x^n is equal to x. If the last d digits will never equal x, return inf.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 34.5px 8px; transform-origin: 34.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample 1:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 61.3px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 30.65px; transform-origin: 391px 30.65px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 71px 8px; transform-origin: 71px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ex = 2; (therefore d = 1)\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 110px 8px; transform-origin: 110px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e2^2 = 4, 2^3 = 8, 2^4 = 16, 2^5 = 32\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 18px 8px; transform-origin: 18px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en = 5;\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 34.5px 8px; transform-origin: 34.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample 2:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 61.3px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 30.65px; transform-origin: 391px 30.65px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 75px 8px; transform-origin: 75px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ex = 10; (therefore d = 2)\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 90.5px 8px; transform-origin: 90.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e10^2 = 100, 10^3 = 1000, etc\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 21.5px 8px; transform-origin: 21.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003en = inf;\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function n = bigNumRepeat(x)\r\n  n = x;\r\nend","test_suite":"%%\r\nx = 2;\r\nn_correct = 5;\r\nassert(isequal(bigNumRepeat(x),n_correct))\r\n\r\n%%\r\nx = 10;\r\nn_correct = inf;\r\nassert(isequal(bigNumRepeat(x),n_correct))\r\n\r\n%%\r\nx = [3 7 33 51 67 192 329 678 680 4731 10016 10081 35197 35199 51783 517839 517842];\r\nn_correct = [5 5 21 3 21 101 51 inf inf 501 626 626 5001 251 2501 12501 inf];\r\nfor ii = 1:numel(x)\r\n   assert(isequal(bigNumRepeat(x(ii)),n_correct(ii)))\r\nend","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":3096,"edited_by":223089,"edited_at":"2022-07-27T07:11:05.000Z","deleted_by":null,"deleted_at":null,"solvers_count":86,"test_suite_updated_at":"2015-03-16T15:16:23.000Z","rescore_all_solutions":false,"group_id":45,"created_at":"2015-03-13T18:49:43.000Z","updated_at":"2026-02-15T15:42:06.000Z","published_at":"2015-03-13T18:49:43.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis problem builds off of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3077\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an integer x which contains d digits, find the value of (minimum) n (n \u0026gt; 1) such that the last d digits of x^n is equal to x. If the last d digits will never equal x, return inf.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 1:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex = 2; (therefore d = 1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2^2 = 4, 2^3 = 8, 2^4 = 16, 2^5 = 32\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en = 5;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 2:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex = 10; (therefore d = 2)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e10^2 = 100, 10^3 = 1000, etc\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en = inf;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":42455,"title":"Divisible by n, prime divisors - 11, 13, 17, \u0026 19","description":"Divisibility checks against prime numbers can all be accomplished with the same routine, applied recursively, consisting of add or subtract x times the last digit to or from the remaining number. For example, for 13, add four times the last digit to the rest:\r\n\r\n* 2392: 239 + 4*2 = 247: 24 + 4*7 = 52: 5 + 4*2 = 13 -\u003e 2392 is divisible by 13.\r\n\r\nFor 17, subtract five times the last digit from the rest:\r\n\r\n* 3281: 328 - 5*1 = 323: 32 - 5*3 = 17 -\u003e 3281 is divisible by 17.\r\n\r\nFor 19, add two times the last digit to the rest:\r\n\r\n* 16863: 1686 + 2*3 = 1692: 169 + 2*2 = 173: 17 + 2*3 = 23: 2 + 2*3 = 8 -\u003e 16863 is not divisible by 19.\r\n\r\nAnd, for 11, subtract the last digit from the rest:\r\n\r\n* 269830: 26983 - 0 = 26983: 2698 - 3 = 2695: 269 - 5 = 264: 26 - 4 = 22: 2 - 2 = 0 -\u003e 269830 is divisible by 11.\r\n\r\nWrite a function to return a true-false vector for the prime numbers in the 11:20 range ([11 13 17 19]) based on a number supplied as a string.\r\n\r\nRestrictions on Java, mod, ceil, round, and floor are still in effect.\r\n\r\nPrevious problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42454-divisible-by-n-prime-divisors-including-powers Divisible by n, prime divisors (including powers)\u003e. Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42508-divisible-by-n-prime-divisors-from-20-to-200 Divisible by n, prime divisors from 20 to 200\u003e.","description_html":"\u003cp\u003eDivisibility checks against prime numbers can all be accomplished with the same routine, applied recursively, consisting of add or subtract x times the last digit to or from the remaining number. For example, for 13, add four times the last digit to the rest:\u003c/p\u003e\u003cul\u003e\u003cli\u003e2392: 239 + 4*2 = 247: 24 + 4*7 = 52: 5 + 4*2 = 13 -\u0026gt; 2392 is divisible by 13.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eFor 17, subtract five times the last digit from the rest:\u003c/p\u003e\u003cul\u003e\u003cli\u003e3281: 328 - 5*1 = 323: 32 - 5*3 = 17 -\u0026gt; 3281 is divisible by 17.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eFor 19, add two times the last digit to the rest:\u003c/p\u003e\u003cul\u003e\u003cli\u003e16863: 1686 + 2*3 = 1692: 169 + 2*2 = 173: 17 + 2*3 = 23: 2 + 2*3 = 8 -\u0026gt; 16863 is not divisible by 19.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eAnd, for 11, subtract the last digit from the rest:\u003c/p\u003e\u003cul\u003e\u003cli\u003e269830: 26983 - 0 = 26983: 2698 - 3 = 2695: 269 - 5 = 264: 26 - 4 = 22: 2 - 2 = 0 -\u0026gt; 269830 is divisible by 11.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eWrite a function to return a true-false vector for the prime numbers in the 11:20 range ([11 13 17 19]) based on a number supplied as a string.\u003c/p\u003e\u003cp\u003eRestrictions on Java, mod, ceil, round, and floor are still in effect.\u003c/p\u003e\u003cp\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42454-divisible-by-n-prime-divisors-including-powers\"\u003eDivisible by n, prime divisors (including powers)\u003c/a\u003e. Next problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42508-divisible-by-n-prime-divisors-from-20-to-200\"\u003eDivisible by n, prime divisors from 20 to 200\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = prime_divisors_11_to_20(n)\r\n\r\np_digits = [11 13 17 19];\r\ntf = zeros(1,4); %[11 13 17 19]\r\n\t\r\nend\r\n","test_suite":"%%\r\nfiletext = fileread('prime_divisors_11_to_20.m');\r\nassert(isempty(strfind(filetext, 'mod')),'mod() forbidden')\r\nassert(isempty(strfind(filetext, 'round')),'round() forbidden')\r\nassert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')\r\nassert(isempty(strfind(filetext, 'floor')),'floor() forbidden')\r\nassert(isempty(strfind(filetext, 'java')),'java forbidden')\r\n\r\n%%\r\nn = '143';\r\ntf = [1 1 0 0]; %[11 13 17 19]\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '187';\r\ntf = [1 0 1 0];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '221';\r\ntf = [0 1 1 0];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '247';\r\ntf = [0 1 0 1];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '46189';\r\ntf = [1 1 1 1];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '2133423721';\r\ntf = [1 1 1 1];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '233296158667';\r\ntf = [1 1 1 1];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '1011001000101010101010110101001010101001010101001001011010101000101010101010101010010101010010101010100101010101001100101010010101';\r\ntf = [0 0 0 0];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '1011001000101010101010110101001010101001010101001001011010101000101010101010101010010101010010101010100101010101001100101010010103';\r\ntf = [0 1 0 0];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '1011001000101010101010110101001010101001010101001001011010101000101010101010101010010101010010101010100101010101001100101010010107';\r\ntf = [0 0 0 1];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%\r\nn = '14300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = [1 1 0 0];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '14300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';\r\ntf = [0 0 0 0];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%%\r\nn = '22100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\r\ntf = [0 1 1 0];\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%% anti-cheating test\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn = '221';\r\n\t\ttf = [0 1 1 0];\r\n\tcase 2\r\n\t\tn = '233296158667';\r\n\t\ttf = [1 1 1 1];\r\n\tcase 3\r\n\t\tn = '46189';\r\n\t\ttf = [1 1 1 1];\r\n\tcase 4\r\n\t\tn = '247';\r\n\t\ttf = [0 1 0 1];\r\nend\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%% anti-cheating test\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn = '187';\r\n\t\ttf = [1 0 1 0];\r\n\tcase 2\r\n\t\tn = '143';\r\n\t\ttf = [1 1 0 0];\r\n\tcase 3\r\n\t\tn = '221';\r\n\t\ttf = [0 1 1 0];\r\n\tcase 4\r\n\t\tn = '233296158667';\r\n\t\ttf = [1 1 1 1];\r\nend\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n\r\n%% anti-cheating test\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tn = '2133423721';\r\n\t\ttf = [1 1 1 1];\r\n\tcase 2\r\n\t\tn = '46189';\r\n\t\ttf = [1 1 1 1];\r\n\tcase 3\r\n\t\tn = '187';\r\n\t\ttf = [1 0 1 0];\r\n\tcase 4\r\n\t\tn = '247';\r\n\t\ttf = [0 1 0 1];\r\nend\r\nassert(isequal(prime_divisors_11_to_20(n),tf))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":73,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":22,"created_at":"2015-07-09T04:18:06.000Z","updated_at":"2025-12-28T20:47:42.000Z","published_at":"2015-07-09T04:18:06.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDivisibility checks against prime numbers can all be accomplished with the same routine, applied recursively, consisting of add or subtract x times the last digit to or from the remaining number. For example, for 13, add four times the last digit to the rest:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2392: 239 + 4*2 = 247: 24 + 4*7 = 52: 5 + 4*2 = 13 -\u0026gt; 2392 is divisible by 13.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor 17, subtract five times the last digit from the rest:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e3281: 328 - 5*1 = 323: 32 - 5*3 = 17 -\u0026gt; 3281 is divisible by 17.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor 19, add two times the last digit to the rest:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e16863: 1686 + 2*3 = 1692: 169 + 2*2 = 173: 17 + 2*3 = 23: 2 + 2*3 = 8 -\u0026gt; 16863 is not divisible by 19.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAnd, for 11, subtract the last digit from the rest:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e269830: 26983 - 0 = 26983: 2698 - 3 = 2695: 269 - 5 = 264: 26 - 4 = 22: 2 - 2 = 0 -\u0026gt; 269830 is divisible by 11.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to return a true-false vector for the prime numbers in the 11:20 range ([11 13 17 19]) based on a number supplied as a string.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRestrictions on Java, mod, ceil, round, and floor are still in effect.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42454-divisible-by-n-prime-divisors-including-powers\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, prime divisors (including powers)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Next problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42508-divisible-by-n-prime-divisors-from-20-to-200\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDivisible by n, prime divisors from 20 to 200\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"tag:\"overflow\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"overflow\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"overflow\"","","\"","overflow","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f19493dcbd8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f19493dcb38\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f19493db7d8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f19493dce58\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f19493dcdb8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f19493dcd18\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f19493dcc78\u003e":"tag:\"overflow\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f19493dcc78\u003e":"tag:\"overflow\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"overflow\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"overflow\"","","\"","overflow","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f19493dcbd8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f19493dcb38\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f19493db7d8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f19493dce58\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f19493dcdb8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f19493dcd18\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f19493dcc78\u003e":"tag:\"overflow\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f19493dcc78\u003e":"tag:\"overflow\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":42412,"difficulty_rating":"easy"},{"id":42407,"difficulty_rating":"easy-medium"},{"id":42404,"difficulty_rating":"easy-medium"},{"id":42411,"difficulty_rating":"easy-medium"},{"id":42408,"difficulty_rating":"easy-medium"},{"id":42417,"difficulty_rating":"easy-medium"},{"id":42406,"difficulty_rating":"easy-medium"},{"id":42509,"difficulty_rating":"easy-medium"},{"id":42414,"difficulty_rating":"easy-medium"},{"id":42410,"difficulty_rating":"easy-medium"},{"id":42454,"difficulty_rating":"easy-medium"},{"id":42413,"difficulty_rating":"easy-medium"},{"id":42416,"difficulty_rating":"easy-medium"},{"id":42418,"difficulty_rating":"easy-medium"},{"id":42405,"difficulty_rating":"easy-medium"},{"id":42510,"difficulty_rating":"easy-medium"},{"id":42453,"difficulty_rating":"easy-medium"},{"id":42415,"difficulty_rating":"medium"},{"id":42409,"difficulty_rating":"medium"},{"id":42508,"difficulty_rating":"medium"},{"id":3079,"difficulty_rating":"medium"},{"id":42455,"difficulty_rating":"medium"}]}}