{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-04-16T00:12:35.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":"2026-04-16T00: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":369,"title":"Basic electricity in a dry situation","description":"\u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \r\n\r\nThis is a very hypothetical situation between two individuals in a very dry atmosphere. \r\n\r\nHe came running in rubber boots when she was combing her hair. \r\n\r\nAround N number of electrons moved from one person to the other upon contact. \r\n\r\nWhat was the voltage between them before the contact? \r\n\r\nAssume it is a simple RC type electrical circuit with equivalent capacitance of about 16 pico farads. \r\n\r\nPlease assume that every electron carries about 160 zepto coulombs.\r\n\r\nFor more info on capacitors: \u003chttps://en.wikipedia.org/wiki/Capacitor\u003e","description_html":"\u003cp\u003e\u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889\u003c/p\u003e\u003cp\u003eThis is a very hypothetical situation between two individuals in a very dry atmosphere.\u003c/p\u003e\u003cp\u003eHe came running in rubber boots when she was combing her hair.\u003c/p\u003e\u003cp\u003eAround N number of electrons moved from one person to the other upon contact.\u003c/p\u003e\u003cp\u003eWhat was the voltage between them before the contact?\u003c/p\u003e\u003cp\u003eAssume it is a simple RC type electrical circuit with equivalent capacitance of about 16 pico farads.\u003c/p\u003e\u003cp\u003ePlease assume that every electron carries about 160 zepto coulombs.\u003c/p\u003e\u003cp\u003eFor more info on capacitors: \u003ca href = \"https://en.wikipedia.org/wiki/Capacitor\"\u003ehttps://en.wikipedia.org/wiki/Capacitor\u003c/a\u003e\u003c/p\u003e","function_template":"function V = volts(N)\r\n  V = 10000;\r\nend","test_suite":"%%\r\nN = 10^10;\r\nV = 150;\r\nassert(volts(N)\u003eV/pi)\r\n%%\r\nN = 10^11;\r\nV = 700;\r\nassert(volts(N)\u003cV*pi)\r\n%%\r\nN = 10^12;\r\nV = 10000;\r\nassert(volts(N)\u003eV/sqrt(pi))\r\n","published":true,"deleted":false,"likes_count":8,"comments_count":4,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":596,"test_suite_updated_at":"2012-02-20T20:05:18.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2012-02-20T20:05:18.000Z","updated_at":"2026-04-07T19:14:18.000Z","published_at":"2017-10-16T01:45: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\u003e\u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889\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\u003eThis is a very hypothetical situation between two individuals in a very dry atmosphere.\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\u003eHe came running in rubber boots when she was combing her hair.\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\u003eAround N number of electrons moved from one person to the other upon contact.\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\u003eWhat was the voltage between them before the contact?\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\u003eAssume it is a simple RC type electrical circuit with equivalent capacitance of about 16 pico farads.\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\u003ePlease assume that every electron carries about 160 zepto coulombs.\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 more info on capacitors:\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/Capacitor\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://en.wikipedia.org/wiki/Capacitor\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\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":361,"title":"Energy of a photon","description":"\u0026#9883 \u0026#9762 \u0026#9883 \u0026#9762 \u0026#9883 \u0026#9762 \u0026#9883\r\nGiven the frequency F of a photon in giga hertz.\r\nFind energy E of this photon in giga electron volts.\r\nAssume h, Planck's constant is about 4 femto electron-volt-second.\r\nTo maximize benefits, it may help not looking at the Test Suite before trying any solution!\r\nFor more info: \u003chttps://en.wikipedia.org/wiki/Planck_constant\u003e","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: 171px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 85.5px; transform-origin: 407px 85.5px; 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: 187px 8px; transform-origin: 187px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003e\u0026amp;#9883 \u0026amp;#9762 \u0026amp;#9883 \u0026amp;#9762 \u0026amp;#9883 \u0026amp;#9762 \u0026amp;#9883\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: 151px 8px; transform-origin: 151px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven the frequency F of a photon in giga hertz.\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: 158.5px 8px; transform-origin: 158.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFind energy E of this photon in giga electron volts.\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: 211px 8px; transform-origin: 211px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAssume h, Planck's constant is about 4 femto electron-volt-second.\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: 276.5px 8px; transform-origin: 276.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eTo maximize benefits, it may help not looking at the Test Suite before trying any solution!\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: 44.5px 8px; transform-origin: 44.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor more info:\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 = \"https://en.wikipedia.org/wiki/Planck_constant\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u0026lt;https://en.wikipedia.org/wiki/Planck_constant\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: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u0026gt;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function E = photon_energy(F)\r\n  E=100/F;\r\nend","test_suite":"%%\r\nF = 1;\r\nE_correct = 3/10^15;\r\nassert(photon_energy(F)\u003eE_correct)\r\n%%\r\nF = 100;\r\nE_correct = 500/10^15;\r\nassert(photon_energy(F)\u003cE_correct)\r\n%%\r\nF = 500;\r\nE_correct = 2100/10^15;\r\nassert(photon_energy(F)\u003cE_correct)\r\n%%\r\nF = 420;\r\nE_correct = 1680/10^15;\r\nassert(isequal(photon_energy(F),E_correct))\r\n%%\r\nF = 0.25;\r\nE_correct = 1e-15;\r\nassert(isequal(photon_energy(F),E_correct))","published":true,"deleted":false,"likes_count":15,"comments_count":11,"created_by":166,"edited_by":223089,"edited_at":"2022-12-24T15:16:49.000Z","deleted_by":null,"deleted_at":null,"solvers_count":1465,"test_suite_updated_at":"2022-12-24T15:16:49.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2012-02-19T23:13:56.000Z","updated_at":"2026-04-01T13:59:42.000Z","published_at":"2017-10-16T01:45:05.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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u0026amp;#9883 \u0026amp;#9762 \u0026amp;#9883 \u0026amp;#9762 \u0026amp;#9883 \u0026amp;#9762 \u0026amp;#9883\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\u003eGiven the frequency F of a photon in giga hertz.\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\u003eFind energy E of this photon in giga electron volts.\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\u003eAssume h, Planck's constant is about 4 femto electron-volt-second.\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\u003eTo maximize benefits, it may help not looking at the Test Suite before trying any solution!\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\u003eFor more info:\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/Planck_constant\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://en.wikipedia.org/wiki/Planck_constant\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\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":44315,"title":"Predicting life and death of a memory-less light bulb","description":"*\u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161* \r\n\r\nYou have a light bulb that can fail any moment according to the exponential probability distribution. \r\n\r\nAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant. \r\n\r\nNotice that this probability is very small if N is very large. \r\n\r\nNow suppose, the bulb has already survived N hours. \r\n\r\nPlease calculate the probability of its surviving M more hours.\r\n","description_html":"\u003cp\u003e\u003cb\u003e\u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161\u003c/b\u003e\u003c/p\u003e\u003cp\u003eYou have a light bulb that can fail any moment according to the exponential probability distribution.\u003c/p\u003e\u003cp\u003eAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant.\u003c/p\u003e\u003cp\u003eNotice that this probability is very small if N is very large.\u003c/p\u003e\u003cp\u003eNow suppose, the bulb has already survived N hours.\u003c/p\u003e\u003cp\u003ePlease calculate the probability of its surviving M more hours.\u003c/p\u003e","function_template":"function hope = fate(N,P,M)\r\n  hope=exp(-(N+M)*P);\r\nend","test_suite":"%%\r\nN = 1;\r\nP=1;\r\nM=0;\r\nhope_correct = 1;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN = 1;\r\nP=0;\r\nM=1;\r\nhope_correct = 1;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=1;\r\nP=1;\r\nM=1;\r\nhope_correct = 0.3679;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=2;\r\nP=1;\r\nM=1;\r\nhope_correct = 0.3679;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=2;\r\nP=1;\r\nM=2;\r\nhope_correct = 0.1353;\r\nassert(fate(N,P,M)\u003chope_correct*1.1)\r\n%%\r\nN=2;\r\nP=2;\r\nM=2;\r\nhope_correct = 0.0183;\r\nassert(fate(N,P,M)\u003chope_correct*1.1)\r\n%%","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":336,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-12T02:53:45.000Z","updated_at":"2026-03-25T02:55:11.000Z","published_at":"2017-10-16T01:45: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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161\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\u003eYou have a light bulb that can fail any moment according to the exponential probability distribution.\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\u003eAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant.\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\u003eNotice that this probability is very small if N is very large.\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\u003eNow suppose, the bulb has already survived N hours.\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\u003ePlease calculate the probability of its surviving M more hours.\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":2736,"title":"Pernicious Anniversary Problem","description":"Since Cody is 5 years old, it's pernicious. A \u003chttp://rosettacode.org/wiki/Pernicious_numbers Pernicious number\u003e is an integer whose population count is a prime. Check if the given number is pernicious.","description_html":"\u003cp\u003eSince Cody is 5 years old, it's pernicious. A \u003ca href = \"http://rosettacode.org/wiki/Pernicious_numbers\"\u003ePernicious number\u003c/a\u003e is an integer whose population count is a prime. Check if the given number is pernicious.\u003c/p\u003e","function_template":"function y = isPernicious(x)\r\n  y = false;\r\nend","test_suite":"%%\r\nx = 5;\r\ny_correct = true;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 1;\r\ny_correct = false;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 2^randi(16);\r\ny_correct = false;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 17;\r\ny_correct = true;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 18;\r\ny_correct = true;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 61;\r\ny_correct = true;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 6;\r\ny_correct = true;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 2115;\r\ny_correct = false;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 2114;\r\ny_correct = true;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 2017;\r\ny_correct = true;\r\nassert(isequal(isPernicious(x),y_correct))\r\n\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":13,"comments_count":1,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":838,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2014-12-08T08:48:45.000Z","updated_at":"2026-04-10T14:31:08.000Z","published_at":"2017-10-16T01:45:06.000Z","restored_at":"2017-10-25T14:37:50.000Z","restored_by":null,"spam":false,"simulink":false,"admin_reviewed":true,"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\u003eSince Cody is 5 years old, it's pernicious. 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://rosettacode.org/wiki/Pernicious_numbers\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePernicious number\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is an integer whose population count is a prime. Check if the given number is pernicious.\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":44370,"title":"Octoberfest festival","description":"A group of students decided to visit Octoberfest festival. First they ordered one beer, then after half-hour they taken one more, after one more half-hour they ordered two more beers like sum of previous two times. Then after having spend a good time and anoter half an hour they ordered three beers. The situation went on. Task: calculate how many beers they ordered after n half-hours for given n - number of half-hours.\r\n\r\nExample:\r\n\r\nn=1 result will be 2;\r\n\r\nn=2 result will be 4.","description_html":"\u003cp\u003eA group of students decided to visit Octoberfest festival. First they ordered one beer, then after half-hour they taken one more, after one more half-hour they ordered two more beers like sum of previous two times. Then after having spend a good time and anoter half an hour they ordered three beers. The situation went on. Task: calculate how many beers they ordered after n half-hours for given n - number of half-hours.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003en=1 result will be 2;\u003c/p\u003e\u003cp\u003en=2 result will be 4.\u003c/p\u003e","function_template":"function totalNumberOfOrderedBeers = OctoberfestFestival(n)  \r\n  totalNumberOfOrderedBeers=n\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 2;\r\nassert(isequal(OctoberfestFestival(x),y_correct))\r\n%%\r\nx = 5;\r\ny_correct = 20;\r\nassert(isequal(OctoberfestFestival(x),y_correct))\r\n%%\r\nx = 10;\r\ny_correct = 232;\r\nassert(isequal(OctoberfestFestival(x),y_correct))","published":true,"deleted":false,"likes_count":4,"comments_count":11,"created_by":90467,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":498,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-10T19:33:58.000Z","updated_at":"2026-03-18T12:47:33.000Z","published_at":"2017-10-16T01:45: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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eA group of students decided to visit Octoberfest festival. First they ordered one beer, then after half-hour they taken one more, after one more half-hour they ordered two more beers like sum of previous two times. Then after having spend a good time and anoter half an hour they ordered three beers. The situation went on. Task: calculate how many beers they ordered after n half-hours for given n - number of half-hours.\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:\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\u003en=1 result will be 2;\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\u003en=2 result will be 4.\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":44314,"title":"A Simple Tide Gauge with MATLAB","description":"*\u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767* \r\n\r\nYou are standing in a few inches of sea water on a beach.\r\n\r\nYou are wondering whether the high tide is coming soon or it has just passed. \r\n\r\nTherefore, you will write a code in MATLAB to analyze following data. \r\n\r\nYou followed the sequence of water lines left by several swash of waves. \r\n\r\nThe data array A contains the distances the water traveled past your feet during each upward swash of waves. \r\n\r\nYour code will return 1 if the high tide is coming soon. \r\n\r\nYour code will return 0 if the high tide has just passed.    \r\n","description_html":"\u003cp\u003e\u003cb\u003e\u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767\u003c/b\u003e\u003c/p\u003e\u003cp\u003eYou are standing in a few inches of sea water on a beach.\u003c/p\u003e\u003cp\u003eYou are wondering whether the high tide is coming soon or it has just passed.\u003c/p\u003e\u003cp\u003eTherefore, you will write a code in MATLAB to analyze following data.\u003c/p\u003e\u003cp\u003eYou followed the sequence of water lines left by several swash of waves.\u003c/p\u003e\u003cp\u003eThe data array A contains the distances the water traveled past your feet during each upward swash of waves.\u003c/p\u003e\u003cp\u003eYour code will return 1 if the high tide is coming soon.\u003c/p\u003e\u003cp\u003eYour code will return 0 if the high tide has just passed.\u003c/p\u003e","function_template":"function tide = gauge(A)\r\n  tide=max(A)-min(A);\r\n  tide=tide*0;\r\nend","test_suite":"%%\r\nA = [5 8 10 12 8 13 14 10 10 15];\r\ntide_correct = 1;\r\nassert(isequal(gauge(A),tide_correct))\r\n%%\r\nA = [15 16 11 9 10 15 7 12 6 11 5 6];\r\ntide_correct = 0;\r\nassert(isequal(gauge(A),tide_correct))\r\n%%\r\nA = [9 15 3 9 5 18 4 17 18 19 8 13 12 21 17 24];\r\ntide_correct = 1;\r\nassert(isequal(gauge(A),tide_correct))\r\n%%\r\nA = [22 12 22 12 9 14 17 16 15 8 13 6 10 7 13 3];\r\ntide_correct = 0;\r\nassert(isequal(gauge(A),tide_correct))\r\n%%\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":3,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":394,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-12T00:26:53.000Z","updated_at":"2026-03-25T04:12:58.000Z","published_at":"2017-10-16T01:45: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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u0026amp;#8767 \u0026amp;#8767 \u0026amp;#8767 \u0026amp;#8767 \u0026amp;#8767 \u0026amp;#8767 \u0026amp;#8767 \u0026amp;#8767\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\u003eYou are standing in a few inches of sea water on a beach.\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\u003eYou are wondering whether the high tide is coming soon or it has just passed.\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\u003eTherefore, you will write a code in MATLAB to analyze following data.\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\u003eYou followed the sequence of water lines left by several swash of waves.\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 data array A contains the distances the water traveled past your feet during each upward swash of waves.\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 code will return 1 if the high tide is coming soon.\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 code will return 0 if the high tide has just passed.\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":564,"title":"How to subtract?","description":"*\u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn* \r\n\r\n* Imagine you need to subtract one number from another using MATLAB.\r\n* You will not be using eval for this task.\r\n* Given two ASCII strings representing two integers X and Y.\r\n* Each of them has only 12 or less ASCII characters.\r\n* Each of them represents signed integers, such as '+2345'\r\n* Please output the result of (X-Y) in a similar style.","description_html":"\u003cp\u003e\u003cb\u003e\u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn\u003c/b\u003e\u003c/p\u003e\u003cul\u003e\u003cli\u003eImagine you need to subtract one number from another using MATLAB.\u003c/li\u003e\u003cli\u003eYou will not be using eval for this task.\u003c/li\u003e\u003cli\u003eGiven two ASCII strings representing two integers X and Y.\u003c/li\u003e\u003cli\u003eEach of them has only 12 or less ASCII characters.\u003c/li\u003e\u003cli\u003eEach of them represents signed integers, such as '+2345'\u003c/li\u003e\u003cli\u003ePlease output the result of (X-Y) in a similar style.\u003c/li\u003e\u003c/ul\u003e","function_template":"function Z = mysub(X,Y)\r\n   Z = 0;\r\nend\r\n","test_suite":"%%\r\nX='+68768686834554';\r\nY='+76574535435398';\r\nZ_correct='-7805848600844';\r\nassert(isequal(mysub(X,Y),Z_correct))\r\n\r\n%%\r\nX='+1';\r\nY='+2';\r\nZ_correct ='-1';\r\nassert(isequal(mysub(X,Y),Z_correct))\r\n\r\n%%\r\nX='+100';\r\nY='+20';\r\nZ_correct ='+80';\r\nassert(isequal(mysub(X,Y),Z_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":11,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1536,"test_suite_updated_at":"2017-10-16T20:04:25.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2012-04-08T02:27:39.000Z","updated_at":"2026-04-13T22:37:20.000Z","published_at":"2017-10-16T01:45: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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn\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\u003eImagine you need to subtract one number from another using MATLAB.\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\u003eYou will not be using eval for this task.\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\u003eGiven two ASCII strings representing two integers X and Y.\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\u003eEach of them has only 12 or less ASCII characters.\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\u003eEach of them represents signed integers, such as '+2345'\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\u003ePlease output the result of (X-Y) in a similar style.\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":44369,"title":"Circle/Pentagon Overlap","description":"Your function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The function should return the number of pentagon vertices that lie within or on the circle. The tolerance for lying on the circle is 0.02.","description_html":"\u003cp\u003eYour function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The function should return the number of pentagon vertices that lie within or on the circle. The tolerance for lying on the circle is 0.02.\u003c/p\u003e","function_template":"function y = circle_pentagon_overlap(p,cp,r)\r\n y = 0;\r\nend","test_suite":"%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 5;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0];\r\nr = 4;\r\ny_correct = 0;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0];\r\nr = 15;\r\ny_correct = 5;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [2,0];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [2,0.75];\r\nr = 5;\r\ny_correct = 3;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [7.5,0];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,-5];\r\nr = 9;\r\ny_correct = 4;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 5;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [19,8];\r\nr = 5;\r\ny_correct = 3;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [19.5,10];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [19.5,10];\r\nr = 6.6;\r\ny_correct = 4;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [19.5,10];\r\nr = 7;\r\ny_correct = 5;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 5;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [26.97,28.45];\r\nr = 8;\r\ny_correct = 0;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":328,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-10T18:44:43.000Z","updated_at":"2026-04-07T14:02:38.000Z","published_at":"2017-10-16T01:45:09.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eYour function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The function should return the number of pentagon vertices that lie within or on the circle. The tolerance for lying on the circle is 0.02.\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":44358,"title":"I Plead the Fifth","description":"Write a function to provide a yes or no answer to the input string. However, it must plead the 5th amendment (return an empty string) if the number five or any variation thereof (e.g., fifth, fifty, fifteen, 5) is within the input string.","description_html":"\u003cp\u003eWrite a function to provide a yes or no answer to the input string. However, it must plead the 5th amendment (return an empty string) if the number five or any variation thereof (e.g., fifth, fifty, fifteen, 5) is within the input string.\u003c/p\u003e","function_template":"function answer = I_plead_the_fifth(question)\r\n str = 'yes/no';\r\nend","test_suite":"%%\r\nquestion = 'Are you the fifth child?';\r\nassert(isempty(I_plead_the_fifth(question)))\r\n\r\n%%\r\nquestion = 'Were you at home on the night of 24 Oct 1974?';\r\nassert(strcmpi(I_plead_the_fifth(question),'yes') || ...\r\n    strcmpi(I_plead_the_fifth(question),'no'))\r\n\r\n%%\r\nquestion = 'Did you go to work on 15 Oct 1955?';\r\nassert(isempty(I_plead_the_fifth(question)))\r\n\r\n%%\r\nquestion = 'Did you go to the bowling alley last week?';\r\nassert(strcmpi(I_plead_the_fifth(question),'yes') || ...\r\n    strcmpi(I_plead_the_fifth(question),'no'))\r\n\r\n%%\r\nquestion = 'Do you like bread?';\r\nassert(strcmpi(I_plead_the_fifth(question),'yes') || ...\r\n    strcmpi(I_plead_the_fifth(question),'no'))\r\n\r\n%%\r\nquestion = 'Are there five fingers on your right hand?';\r\nassert(isempty(I_plead_the_fifth(question)))\r\n\r\n%%\r\nquestion = 'Do you like pumpkins?';\r\nassert(strcmpi(I_plead_the_fifth(question),'yes') || ...\r\n    strcmpi(I_plead_the_fifth(question),'no'))\r\n\r\n%%\r\nquestion = 'Do you have fifteen siblings?';\r\nassert(isempty(I_plead_the_fifth(question)))\r\n\r\n%%\r\nquestion = 'Do two quarters equal fifty cents?';\r\nassert(isempty(I_plead_the_fifth(question)))\r\n\r\n%%\r\nquestion = 'Do you own five dogs?';\r\nassert(isempty(I_plead_the_fifth(question)))\r\n\r\n%%\r\nquestion = 'Is my name Harry?';\r\nassert(strcmpi(I_plead_the_fifth(question),'yes') || ...\r\n    strcmpi(I_plead_the_fifth(question),'no'))","published":true,"deleted":false,"likes_count":6,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":427,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-03T17:12:42.000Z","updated_at":"2026-03-22T03:30:09.000Z","published_at":"2017-10-16T01:45:09.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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 provide a yes or no answer to the input string. However, it must plead the 5th amendment (return an empty string) if the number five or any variation thereof (e.g., fifth, fifty, fifteen, 5) is within the input string.\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":44363,"title":"Is this is a Tic Tac Toe X Win?","description":"For the game of Tic Tac Toe we will be storing the state of the game in a matrix M.\r\nFor this game:\r\n\r\nWe would store the state as this:\r\n-1  1  1 \r\n 1 -1 -1\r\n 1 -1 -1\r\nIf there were any blanks squares, they would be 0;\r\nFor this challenge, given a game state, does X (1) have a three in a row on any row, column or major diagonal?","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: 243.3px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 121.65px; transform-origin: 407px 121.65px; 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: 50.5px 8px; transform-origin: 50.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor the game 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 = \"https://en.wikipedia.org/wiki/Tic-tac-toe\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eTic Tac Toe\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: 167.5px 8px; transform-origin: 167.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e we will be storing the state of the game in a matrix M.\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: 45.5px 8px; transform-origin: 45.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor this game:\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: 0px 8px; transform-origin: 0px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\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: 102.5px 8px; transform-origin: 102.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWe would store the state as this:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 30.65px; transform-origin: 404px 30.65px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 36px 8.5px; tab-size: 4; transform-origin: 36px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e-1  1  1 \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 32px 8.5px; tab-size: 4; transform-origin: 32px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e 1 -1 -1\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 32px 8.5px; tab-size: 4; transform-origin: 32px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e 1 -1 -1\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; 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: 158px 8px; transform-origin: 158px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf there were any blanks squares, they would be 0;\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: 349px 8px; transform-origin: 349px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor this challenge, given a game state, does X (1) have a three in a row on any row, column or major diagonal?\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function flagWin = your_fcn_name(M)\r\n  flagWin = false\r\nend","test_suite":"%%\r\nx = [1 1 1\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 0 0\r\n     0 1 0\r\n     0 0 1];\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 0 0\r\n     0 -1 0\r\n     1 0 1];\r\ny_correct = 0;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 0 0\r\n     1 0 0\r\n     1 0 0];\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 0 0\r\n     1 -1 0\r\n     1 0 0];\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [0 0 1\r\n     0 1 0\r\n     1 0 0];\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1  0 0\r\n     0 -1 0\r\n     0  0 1];\r\ny_correct = 0;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 0 0\r\n     0 1 0\r\n     0 0 1];\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [-1 0 0\r\n     0 -1 0\r\n     0 0 -1];\r\ny_correct = 0;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":240,"edited_by":223089,"edited_at":"2022-07-28T15:36:47.000Z","deleted_by":null,"deleted_at":null,"solvers_count":534,"test_suite_updated_at":"2022-07-28T15:36:47.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-09T23:11:43.000Z","updated_at":"2026-04-07T14:05:08.000Z","published_at":"2017-10-16T01:45:09.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\u003eFor the game 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=\\\"https://en.wikipedia.org/wiki/Tic-tac-toe\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eTic Tac Toe\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e we will be storing the state of the game in a matrix M.\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\u003eFor this game:\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\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWe would store the state as this:\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[-1  1  1 \\n 1 -1 -1\\n 1 -1 -1]]\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf there were any blanks squares, they would be 0;\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\u003eFor this challenge, given a game state, does X (1) have a three in a row on any row, column or major diagonal?\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":44384,"title":"Find the nearest prime number","description":"Happy 5th birthday, Cody! Since 5 is a prime number, let's have some fun looking for other prime numbers.\r\n\r\nGiven a positive integer x, find the nearest prime number. Keep in mind that the nearest prime may be less than x.\r\n\r\n*Examples*\r\n\r\n  nearestprime(5) = 5\r\n  nearestprime(36) = 37\r\n  nearestprime(200) = 199\r\n\r\nNOTE: You may ignore cases in which two prime numbers are equally close to x. (e.g., x=12 --\u003e 11 and 13 are both primes). ","description_html":"\u003cp\u003eHappy 5th birthday, Cody! Since 5 is a prime number, let's have some fun looking for other prime numbers.\u003c/p\u003e\u003cp\u003eGiven a positive integer x, find the nearest prime number. Keep in mind that the nearest prime may be less than x.\u003c/p\u003e\u003cp\u003e\u003cb\u003eExamples\u003c/b\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003enearestprime(5) = 5\r\nnearestprime(36) = 37\r\nnearestprime(200) = 199\r\n\u003c/pre\u003e\u003cp\u003eNOTE: You may ignore cases in which two prime numbers are equally close to x. (e.g., x=12 --\u0026gt; 11 and 13 are both primes).\u003c/p\u003e","function_template":"function y = nearestprime(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 0;\r\ny_correct = 2;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = 5;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 100;\r\ny_correct = 101;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 500;\r\ny_correct = 499;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 911;\r\ny_correct = 911;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 2500;\r\ny_correct = 2503;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 8000;\r\ny_correct = 7993;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 100000;\r\ny_correct = 100003;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 1300000;\r\ny_correct = 1299989;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 179424710;\r\ny_correct = 179424719;\r\nassert(isequal(nearestprime(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":9,"comments_count":1,"created_by":4793,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":664,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-13T19:42:15.000Z","updated_at":"2026-04-07T15:16:58.000Z","published_at":"2017-10-16T01:45: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\u003eHappy 5th birthday, Cody! Since 5 is a prime number, let's have some fun looking for other prime numbers.\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\u003eGiven a positive integer x, find the nearest prime number. Keep in mind that the nearest prime may be less than 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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExamples\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[nearestprime(5) = 5\\nnearestprime(36) = 37\\nnearestprime(200) = 199]]\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\u003eNOTE: You may ignore cases in which two prime numbers are equally close to x. (e.g., x=12 --\u0026gt; 11 and 13 are both primes).\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":44385,"title":"Extra safe primes","description":"Did you know that the number 5 is the first safe prime? A safe prime is a prime number that can be expressed as 2p+1, where p is also a prime.\r\n\r\nTo celebrate Cody's Five-Year Anniversary, write a function to determine if a positive integer n is a safe prime in which the prime p (such that n=2p+1) is *also a safe prime*.\r\n\r\n*Examples*\r\n\r\n  isextrasafe(5) = false % because 5=2*2+1 and 2 is not a safe prime\r\n  isextrasafe(23) = true % because 23=2*11+1 and 11 is also a safe prime (11=2*5+1)\r\n","description_html":"\u003cp\u003eDid you know that the number 5 is the first safe prime? A safe prime is a prime number that can be expressed as 2p+1, where p is also a prime.\u003c/p\u003e\u003cp\u003eTo celebrate Cody's Five-Year Anniversary, write a function to determine if a positive integer n is a safe prime in which the prime p (such that n=2p+1) is \u003cb\u003ealso a safe prime\u003c/b\u003e.\u003c/p\u003e\u003cp\u003e\u003cb\u003eExamples\u003c/b\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eisextrasafe(5) = false % because 5=2*2+1 and 2 is not a safe prime\r\nisextrasafe(23) = true % because 23=2*11+1 and 11 is also a safe prime (11=2*5+1)\r\n\u003c/pre\u003e","function_template":"function tf = isextrasafe(x)\r\n    tf = false;\r\nend","test_suite":"%%\r\nx = 0;\r\nassert(isequal(isextrasafe(x),false))\r\n\r\n%%\r\nx = 5;\r\nassert(isequal(isextrasafe(x),false))\r\n\r\n%%\r\nx = 7;\r\nassert(isequal(isextrasafe(x),false))\r\n\r\n%%\r\nx = 11;\r\nassert(isequal(isextrasafe(x),true))\r\n\r\n%%\r\nx = 15;\r\nassert(isequal(isextrasafe(x),false))\r\n\r\n%%\r\nx = 23;\r\nassert(isequal(isextrasafe(x),true))\r\n\r\n%%\r\nx = 71;\r\nassert(isequal(isextrasafe(x),false))\r\n\r\n%%\r\nx = 719;\r\nassert(isequal(isextrasafe(x),true))\r\n\r\n%%\r\nx = 2039;\r\nassert(isequal(isextrasafe(x),true))\r\n\r\n%%\r\nx = 2040;\r\nassert(isequal(isextrasafe(x),false))\r\n\r\n%%\r\nx = 5807;\r\nassert(isequal(isextrasafe(x),true))","published":true,"deleted":false,"likes_count":13,"comments_count":4,"created_by":4793,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":757,"test_suite_updated_at":"2017-10-19T17:09:19.000Z","rescore_all_solutions":true,"group_id":34,"created_at":"2017-10-13T20:02:13.000Z","updated_at":"2026-04-10T14:37:08.000Z","published_at":"2017-10-16T01:45: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\u003eDid you know that the number 5 is the first safe prime? A safe prime is a prime number that can be expressed as 2p+1, where p is also a prime.\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\u003eTo celebrate Cody's Five-Year Anniversary, write a function to determine if a positive integer n is a safe prime in which the prime p (such that n=2p+1) is\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\u003ealso a safe prime\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExamples\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[isextrasafe(5) = false % because 5=2*2+1 and 2 is not a safe prime\\nisextrasafe(23) = true % because 23=2*11+1 and 11 is also a safe prime (11=2*5+1)]]\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":44319,"title":"Write c^3 as sum of two squares a^2+b^2","description":"write c^3 as sum of two squares a^2+b^2. a and b must be integer and greater than zero.\r\n\r\nFor example \r\n\r\n 5^3 = 2^2 + 11^2\r\n 5^3 = 5^2 + 10^2\r\n 10^3 = 10^2 + 30^2\r\n 10^3 = 18^2 + 26^2\r\n\r\nsort output matrix so that each row and first column is in ascending order.","description_html":"\u003cp\u003ewrite c^3 as sum of two squares a^2+b^2. a and b must be integer and greater than zero.\u003c/p\u003e\u003cp\u003eFor example\u003c/p\u003e\u003cpre\u003e 5^3 = 2^2 + 11^2\r\n 5^3 = 5^2 + 10^2\r\n 10^3 = 10^2 + 30^2\r\n 10^3 = 18^2 + 26^2\u003c/pre\u003e\u003cp\u003esort output matrix so that each row and first column is in ascending order.\u003c/p\u003e","function_template":"function y = sumoftwosquares(c)\r\n\r\nend","test_suite":"%%\r\nc = 1;\r\ny_correct = [];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 5;\r\ny_correct = [2 11; 5 10];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 6;\r\ny_correct = [];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 10;\r\ny_correct = [10 30; 18 26];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 20;\r\ny_correct = [16 88; 40 80];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 24;\r\ny_correct = [];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 40;\r\ny_correct = [80 240; 144 208];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 65;\r\ny_correct = [7 524; 65 520; 140 505; 191 488; 208 481; 260 455; 320 415; 364 377];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 100;\r\ny_correct = [280 960; 352 936; 600 800];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 123;\r\ny_correct = [];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 340;\r\ny_correct = [408 6256;1360 6120; 1680 6040; 2280 5840; 2584 5712; 3304 5328; 3824 4968; 4080 4760];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 500;\r\ny_correct = [1160 11120; 2000 11000; 5000 10000; 5744 9592; 7600 8200];\r\nassert(isequal(sumoftwosquares(c),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":329,"test_suite_updated_at":"2017-10-16T17:19:22.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-12T19:54:46.000Z","updated_at":"2026-04-01T13:09:32.000Z","published_at":"2017-10-16T01:45: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 c^3 as sum of two squares a^2+b^2. a and b must be integer and greater than 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\u003eFor 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[ 5^3 = 2^2 + 11^2\\n 5^3 = 5^2 + 10^2\\n 10^3 = 10^2 + 30^2\\n 10^3 = 18^2 + 26^2]]\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\u003esort output matrix so that each row and first column is in ascending order.\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":44342,"title":"Spot the First Occurrence of 5","description":"This problem series invites you to solve two simple problems related to the integer NUMBER FIVE, in order to celebrate \u003chttps://www.mathworks.com/matlabcentral/cody/contests/1?s_tid=Cody5YA_cody_home Cody's 5th birthday\u003e. \r\n\r\nIn this problem, let's determine the position (index) of the first occurrence of 5 along the first non-singleton dimension of an input array. \r\n\r\nE.g., \r\n\r\n* If the input is a vector, return the index of the first occurrence of 5. \r\n\r\n  x = [1 2 5 3 5];\r\n  y = 3;\r\n\r\n* If the input is a matrix, return the index of the first occurrence of 5 in each column. If 5 is not found, simply return 0; \r\n\r\n  % Input x is a matrix\r\n  x = [1 2 5\r\n       5 9 1\r\n       5 6 5];\r\n\r\n  % Output y\r\n  y = [2 0 1];\r\n\r\nNext problem in this series: \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44352-the-top-5-primes The Top 5 Primes\u003e","description_html":"\u003cp\u003eThis problem series invites you to solve two simple problems related to the integer NUMBER FIVE, in order to celebrate \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/contests/1?s_tid=Cody5YA_cody_home\"\u003eCody's 5th birthday\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eIn this problem, let's determine the position (index) of the first occurrence of 5 along the first non-singleton dimension of an input array.\u003c/p\u003e\u003cp\u003eE.g.,\u003c/p\u003e\u003cul\u003e\u003cli\u003eIf the input is a vector, return the index of the first occurrence of 5.\u003c/li\u003e\u003c/ul\u003e\u003cpre class=\"language-matlab\"\u003ex = [1 2 5 3 5];\r\ny = 3;\r\n\u003c/pre\u003e\u003cul\u003e\u003cli\u003eIf the input is a matrix, return the index of the first occurrence of 5 in each column. If 5 is not found, simply return 0;\u003c/li\u003e\u003c/ul\u003e\u003cpre class=\"language-matlab\"\u003e% Input x is a matrix\r\nx = [1 2 5\r\n     5 9 1\r\n     5 6 5];\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003e% Output y\r\ny = [2 0 1];\r\n\u003c/pre\u003e\u003cp\u003eNext problem in this series: \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44352-the-top-5-primes\"\u003eThe Top 5 Primes\u003c/a\u003e\u003c/p\u003e","function_template":"function y = locOf5(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nassessFunctionAbsence({'regexp','regexpi','regexprep','str2num'},'FileName','locOf5.m')\r\n\r\n%%\r\nx = 2:2:20;\r\ny_correct = 0;\r\nassert(isequal(locOf5(x),y_correct))\r\n\r\n%%\r\nx = rot90(1:10);\r\ny_correct = 6;\r\nassert(isequal(locOf5(x),y_correct))\r\n\r\n%%\r\nx = [1 2 5\r\n     5 9 1\r\n     5 6 5];\r\ny_correct = [2 0 1];\r\nassert(isequal(locOf5(x),y_correct))\r\n\r\n%%\r\nx = magic(5);\r\ny_correct = [0 2 0 0 0];\r\nassert(isequal(locOf5(x),y_correct))\r\n\r\n%%\r\nx = [1 2 3 4 5;\r\n     5 4 3 2 1\r\n     2 3 5 2 1\r\n     1 5 2 6 8\r\n     3 5 2 2 5];\r\ny_correct = [2 4 3 0 1];\r\nassert(isequal(locOf5(x),y_correct))\r\n\r\n% %%\r\n% x = randi([-10,10],20,1e6); \r\n% x(x==5) = 0;\r\n% p = sort(randi([0 size(x,1)],5,size(x,2)));\r\n% y_correct = p(1,:);\r\n% p(2:end,~y_correct) = 0;\r\n% [~,col,v] = find(p);\r\n% x((col-1)*size(x,1)+v) = 5;\r\n% assert(isequal(locOf5(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":434,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-20T14:43:55.000Z","updated_at":"2026-03-18T13:43:25.000Z","published_at":"2017-10-16T01:45:08.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 problem series invites you to solve two simple problems related to the integer NUMBER FIVE, in order to celebrate\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://www.mathworks.com/matlabcentral/cody/contests/1?s_tid=Cody5YA_cody_home\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody's 5th birthday\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\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn this problem, let's determine the position (index) of the first occurrence of 5 along the first non-singleton dimension of an input array.\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\u003eE.g.,\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\u003eIf the input is a vector, return the index of the first occurrence of 5.\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[x = [1 2 5 3 5];\\ny = 3;]]\u003e\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\u003eIf the input is a matrix, return the index of the first occurrence of 5 in each column. If 5 is not found, simply return 0;\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[% Input x is a matrix\\nx = [1 2 5\\n     5 9 1\\n     5 6 5];\\n\\n% Output y\\ny = [2 0 1];]]\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\u003eNext problem in this series:\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://www.mathworks.com/matlabcentral/cody/problems/44352-the-top-5-primes\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eThe Top 5 Primes\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":44349,"title":"Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock.","description":"Submit your answer to this problem a multiple of 5 seconds after the hour.  Your answer is irrelevant; the only thing that matters is *when* you submit it.  It can be 5 seconds after, 555 seconds, or 3300 seconds after the hour.  So long as the number of seconds is a multiple of five, you are good to go.","description_html":"\u003cp\u003eSubmit your answer to this problem a multiple of 5 seconds after the hour.  Your answer is irrelevant; the only thing that matters is \u003cb\u003ewhen\u003c/b\u003e you submit it.  It can be 5 seconds after, 555 seconds, or 3300 seconds after the hour.  So long as the number of seconds is a multiple of five, you are good to go.\u003c/p\u003e","function_template":"function y = time_for_five(x)\r\n  y = 555555;\r\nend","test_suite":"%%\r\nfiletext = fileread('time_for_five.m');\r\nassert(isempty(strfind(filetext, 'fopen')));\r\nassert(isempty(strfind(filetext, 'assert')));\r\n%%\r\ny = time_for_five(5);\r\n\r\na=clock;\r\n\r\nif mod(floor(a(6)),5)==0\r\n    y_correct= y\r\nelse\r\n    y_correct = NaN;\r\nend\r\n\r\nassert(isequal(y,y_correct))","published":true,"deleted":false,"likes_count":14,"comments_count":13,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":957,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-26T17:42:30.000Z","updated_at":"2026-03-18T13:20:10.000Z","published_at":"2017-10-16T01:45:08.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\u003eSubmit your answer to this problem a multiple of 5 seconds after the hour. Your answer is irrelevant; the only thing that matters is\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\u003ewhen\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e you submit it. It can be 5 seconds after, 555 seconds, or 3300 seconds after the hour. So long as the number of seconds is a multiple of five, you are good to go.\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":44360,"title":"Pentagonal Numbers","description":"Your function will receive a lower and upper bound. It should return all pentagonal numbers within that inclusive range in ascending order. Additionally, it should return an array that indicates those numbers that are divisible by 5. For example,\r\n\r\n [p,d] = pentagonal_numbers(10,40)\r\n\r\nshould return\r\n\r\n p = [12,22,35]\r\n d = [ 0, 0, 1]","description_html":"\u003cp\u003eYour function will receive a lower and upper bound. It should return all pentagonal numbers within that inclusive range in ascending order. Additionally, it should return an array that indicates those numbers that are divisible by 5. For example,\u003c/p\u003e\u003cpre\u003e [p,d] = pentagonal_numbers(10,40)\u003c/pre\u003e\u003cp\u003eshould return\u003c/p\u003e\u003cpre\u003e p = [12,22,35]\r\n d = [ 0, 0, 1]\u003c/pre\u003e","function_template":"function [p,d] = pentagonal_numbers(10,40)\r\n p = [5];\r\n d = [1];\r\nend","test_suite":"%%\r\nx1 = 1; x2 = 25;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[1,5,12,22]))\r\nassert(isequal(d,[0,1,0,0]))\r\n\r\n%%\r\nx1 = 1; x2 = 4;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,1))\r\nassert(isequal(d,0))\r\n\r\n%%\r\nx1 = 10; x2 = 40;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[12,22,35]))\r\nassert(isequal(d,[0,0,1]))\r\n\r\n%%\r\nx1 = 10; x2 = 99;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[12,22,35,51,70,92]))\r\nassert(isequal(d,[0,0,1,0,1,0]))\r\n\r\n%%\r\nx1 = 100; x2 = 999;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[117,145,176,210,247,287,330,376,425,477,532,590,651,715,782,852,925]))\r\nassert(isequal(d,[0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1]))\r\n\r\n%%\r\nx1 = 40; x2 = 50;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isempty(p))\r\nassert(isempty(d))\r\n\r\n%%\r\nx1 = 1000; x2 = 1500;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[1001,1080,1162,1247,1335,1426]))\r\nassert(isequal(d,[0,1,0,0,1,0]))\r\n\r\n%%\r\nx1 = 1500; x2 = 3000;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[1520,1617,1717,1820,1926,2035,2147,2262,2380,2501,2625,2752,2882]))\r\nassert(isequal(d,[1,0,0,1,0,1,0,0,1,0,1,0,0]))\r\n\r\n%%\r\nx1 = 1; x2 = 3000;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[1,5,12,22,35,51,70,92,117,145,176,210,247,287,330,376,425,477,532,590,651,715,782,852,925,1001,1080,1162,1247,1335,1426,1520,1617,1717,1820,1926,2035,2147,2262,2380,2501,2625,2752,2882]))\r\nassert(isequal(d,[0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0]))\r\n\r\n%%\r\nx1 = 10000; x2 = 12000;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[10045,10292,10542,10795,11051,11310,11572,11837]))\r\nassert(isequal(d,[1,0,0,1,0,1,0,0]))\r\n\r\n%%\r\nx1 = 100000; x2 = 110000;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[100492,101270,102051,102835,103622,104412,105205,106001,106800,107602,108407,109215]))\r\nassert(isequal(d,[0,1,0,1,0,0,1,0,1,0,0,1]))\r\n\r\n%%\r\nx1 = 1000000; x2 = 1010101;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[1000825,1003277,1005732,1008190]))\r\nassert(isequal(d,[1,0,0,1]))","published":true,"deleted":false,"likes_count":12,"comments_count":3,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":679,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-05T17:43:36.000Z","updated_at":"2026-04-07T13:59:33.000Z","published_at":"2017-10-16T01:45:09.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\u003eYour function will receive a lower and upper bound. It should return all pentagonal numbers within that inclusive range in ascending order. Additionally, it should return an array that indicates those numbers that are divisible by 5. 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[ [p,d] = pentagonal_numbers(10,40)]]\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\u003eshould return\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[ p = [12,22,35]\\n d = [ 0, 0, 1]]]\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":44368,"title":"Inscribed Pentagon?","description":"Your function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon will be centered about the circle. The function should return one of the following values:\r\n\r\n  0: the pentagon is completely enclosed within the circle but is not inscribed\r\n  1: the pentagon is inscribed in the circle (within ±0.02)\r\n  2: the vertices of the pentagon extend beyond the circle\r\n\r\nPoints will be rounded to the nearest hundredth. See the test cases for examples.","description_html":"\u003cp\u003eYour function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon will be centered about the circle. The function should return one of the following values:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e0: the pentagon is completely enclosed within the circle but is not inscribed\r\n1: the pentagon is inscribed in the circle (within ±0.02)\r\n2: the vertices of the pentagon extend beyond the circle\r\n\u003c/pre\u003e\u003cp\u003ePoints will be rounded to the nearest hundredth. See the test cases for examples.\u003c/p\u003e","function_template":"function y = inscribed_pentagon(p,cp,r)\r\n y = 0;\r\nend","test_suite":"%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,6.58; 6.42,1.92; 3.97,-5.63; -3.97,-5.63; -6.42,1.92];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,4.55; 4.28,1.44; 2.65,-3.59; -2.65,-3.59; -4.28,1.44];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,6.58; 6.42,1.92; 3.97,-5.63; -3.97,-5.63; -6.42,1.92] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,4.55; 4.28,1.44; 2.65,-3.59; -2.65,-3.59; -4.28,1.44] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [25.01,12.47; 25.98,4.58; 18.78,1.23; 13.37,7.03; 17.22,13.97];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.27,11.12; 23.92,5.87; 19.12,3.63; 15.52,7.50; 18.08,12.13];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [32.54,38.78; 38.84,26.41; 29.02,16.59; 16.65,22.89; 18.83,36.61];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.49,35.54; 34.69,27.29; 28.14,20.74; 19.89,24.95; 21.34,34.09];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))","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":307,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-10T16:31:01.000Z","updated_at":"2026-04-07T14:00:57.000Z","published_at":"2017-10-16T01:45:09.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\u003eYour function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon will be centered about the circle. The function should return one of the following values:\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[0: the pentagon is completely enclosed within the circle but is not inscribed\\n1: the pentagon is inscribed in the circle (within ±0.02)\\n2: the vertices of the pentagon extend beyond the circle]]\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\u003ePoints will be rounded to the nearest hundredth. See the test cases for examples.\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":44338,"title":"Recaman Sequence - I","description":"Recaman Sequence (A005132 - \u003chttp://oeis.org/A005132 - OEIS Link\u003e) is defined as follow;\r\n\r\n  seq(0) = 0; \r\n  for n \u003e 0, seq(n) = seq(n-1) - n if positive and not already in the sequence, \r\n  otherwise seq(n) = seq(n-1) + n. \r\n\r\n  seq = 0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9 ...\r\nindex = 1, 2, 3 ,...\r\n\r\nTo avoid zero index, start indexing from 1.\r\nreturn the first n elements in Recaman Sequence\r\n\r\n*Related Challenges :*\r\n\r\n# Recaman Sequence - I\r\n# \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44339 Recaman Sequence - II\u003e\r\n# \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44340 Recaman Sequence - III\u003e\r\n","description_html":"\u003cp\u003eRecaman Sequence (A005132 - \u003ca href = \"http://oeis.org/A005132\"\u003e- OEIS Link\u003c/a\u003e) is defined as follow;\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eseq(0) = 0; \r\nfor n \u0026gt; 0, seq(n) = seq(n-1) - n if positive and not already in the sequence, \r\notherwise seq(n) = seq(n-1) + n. \r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eseq = 0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9 ...\r\nindex = 1, 2, 3 ,...\r\n\u003c/pre\u003e\u003cp\u003eTo avoid zero index, start indexing from 1.\r\nreturn the first n elements in Recaman Sequence\u003c/p\u003e\u003cp\u003e\u003cb\u003eRelated Challenges :\u003c/b\u003e\u003c/p\u003e\u003col\u003e\u003cli\u003eRecaman Sequence - I\u003c/li\u003e\u003cli\u003e\u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44339\"\u003eRecaman Sequence - II\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44340\"\u003eRecaman Sequence - III\u003c/a\u003e\u003c/li\u003e\u003c/ol\u003e","function_template":"function y = Recaman(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 0;\r\nassert(isequal(Recaman(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = [0 1 3 6 2];\r\nassert(isequal(Recaman(x),y_correct))\r\n\r\n%%\r\nx = 8;\r\ny_correct = [0 1 3 6 2 7 13 20];\r\nassert(isequal(Recaman(x),y_correct))\r\n\r\n%%\r\nx = 10;\r\ny_correct = [0 1 3 6 2 7 13 20 12 21];\r\nassert(isequal(Recaman(x),y_correct))\r\n\r\n%%\r\nx = 5e4;\r\ny = Recaman(x);\r\nassert(isequal(length(Recaman(x)),x))\r\nassert(isequal(y(954),739))\r\nassert(isequal(y(7589),17654))\r\nassert(isequal(y(12345),18554))\r\n\r\n%%\r\nx = 1e5;\r\ny = Recaman(x);\r\nassert(isequal(length(Recaman(x)),x))\r\nassert(isequal(y(1e4),8658))\r\nassert(isequal(y(2e4),34358))\r\nassert(isequal(y(3e4),92474))\r\nassert(isequal(y(4e4),102344))","published":true,"deleted":false,"likes_count":3,"comments_count":8,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":321,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-19T06:55:43.000Z","updated_at":"2026-03-22T11:16:16.000Z","published_at":"2017-10-16T01:45: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\u003eRecaman Sequence (A005132 -\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://oeis.org/A005132\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e- OEIS Link\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e) is defined as follow;\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[seq(0) = 0; \\nfor n \u003e 0, seq(n) = seq(n-1) - n if positive and not already in the sequence, \\notherwise seq(n) = seq(n-1) + n. \\n\\nseq = 0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9 ...\\nindex = 1, 2, 3 ,...]]\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\u003eTo avoid zero index, start indexing from 1. return the first n elements in Recaman Sequence\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRelated Challenges :\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\u003eRecaman Sequence - I\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:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44339\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - II\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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44340\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - III\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":44334,"title":"Sums of Multiple Pairs of Triangular Numbers","description":"This is a follow-up to \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44289 Problem 44289\u003e - Find two triangular numbers whose sum is input.\r\n\r\nThere are some numbers that are the sum of multiple pairs of triangular numbers.  For example, 81 = 36+45 = 15+66 = 3+78.  Given a number X, find all of the possible pairs of triangular numbers that add up to X.  Your answer should be in a 2-by-X matrix.  Each column of the matrix should sum to X, and each pair of triangular numbers should only appear once.  The top row sorted from low to high.  The output for 81 would be:\r\n\r\n [ 3   15  36 \r\n  78   66  45]\r\n\r\nGood luck!","description_html":"\u003cp\u003eThis is a follow-up to \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44289\"\u003eProblem 44289\u003c/a\u003e - Find two triangular numbers whose sum is input.\u003c/p\u003e\u003cp\u003eThere are some numbers that are the sum of multiple pairs of triangular numbers.  For example, 81 = 36+45 = 15+66 = 3+78.  Given a number X, find all of the possible pairs of triangular numbers that add up to X.  Your answer should be in a 2-by-X matrix.  Each column of the matrix should sum to X, and each pair of triangular numbers should only appear once.  The top row sorted from low to high.  The output for 81 would be:\u003c/p\u003e\u003cpre\u003e [ 3   15  36 \r\n  78   66  45]\u003c/pre\u003e\u003cp\u003eGood luck!\u003c/p\u003e","function_template":"function y = multi_triangular(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 21;\r\ny_correct = [6;15];\r\nassert(isequal(multi_triangular(x),y_correct))\r\n%%\r\nx=81;\r\ny_correct=[ 3   15  36 ;  78   66  45];\r\nassert(isequal(multi_triangular(x),y_correct))\r\n%%\r\nx=20;\r\ny_correct=[ 10 10];\r\nassert(isequal(multi_triangular(x),y_correct'))\r\n%%\r\nx=17956;\r\ny_correct=[ 1 190 378 1485 2556  4095 4753 6328 8911;\r\n 17955 17766 17578 16471 15400 13861 13203 11628 9045];\r\nassert(isequal(multi_triangular(x),y_correct))\r\n%%\r\nx=70;\r\ny_correct=[15 55];\r\nassert(isequal(multi_triangular(x),y_correct'));\r\n%%\r\nx=37052031;\r\ny_correct=[7503 16110 93528 119316 136503 393828 496506 778128 1033203 1194285 1675365 1876953 2503203 2627778 3214380 3436131 3983253 4226778 4943940 5112003 5279625 6063903 6417153 7055646 7771653 8456328 8855736 9801378 10015050 11221953 11580078 12834711 13846953 14084778 15149760 15387378 15531951 17096628 17567628 18395145;\r\n37044528 37035921 36958503 36932715 36915528 36658203 36555525 36273903 36018828 35857746 35376666 35175078 34548828 34424253 33837651 33615900 33068778 32825253 32108091 31940028 31772406 30988128 30634878 29996385 29280378 28595703 28196295 27250653 27036981 25830078 25471953 24217320 23205078 22967253 21902271 21664653 21520080 19955403 19484403 18656886];\r\nassert(isequal(multi_triangular(x),y_correct));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":247,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-15T19:37:34.000Z","updated_at":"2026-03-22T12:09:49.000Z","published_at":"2017-10-16T01:45: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\u003eThis is a follow-up 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=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44289\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44289\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e - Find two triangular numbers whose sum is input.\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 some numbers that are the sum of multiple pairs of triangular numbers. For example, 81 = 36+45 = 15+66 = 3+78. Given a number X, find all of the possible pairs of triangular numbers that add up to X. Your answer should be in a 2-by-X matrix. Each column of the matrix should sum to X, and each pair of triangular numbers should only appear once. The top row sorted from low to high. The output for 81 would be:\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[ [ 3   15  36 \\n  78   66  45]]]\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\u003eGood luck!\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":44381,"title":"Cache me Outside","description":"The test suite includes a simple recursive Fibonacci sequence generator, but it's terribly inefficient. One simple method for improving its performance is using a technique called memoization. Write a function that takes a function_handle that we wish to memoize and returns a function_handle to a memoized version of the initial handle.","description_html":"\u003cp\u003eThe test suite includes a simple recursive Fibonacci sequence generator, but it's terribly inefficient. One simple method for improving its performance is using a technique called memoization. Write a function that takes a function_handle that we wish to memoize and returns a function_handle to a memoized version of the initial handle.\u003c/p\u003e","function_template":"function memfcn = memoize_this(fcn)\r\n    memfcn = fcn;\r\nend","test_suite":"%%\r\nmemfib = memoize_this(@fib);\r\n\r\n[seq, n1] = fib(1, memfib);\r\nassert(n1 == 1);\r\n\r\n[seq, n2] = fib(20, memfib);\r\nassert(n2 - n1 == 19);\r\n\r\n[seq, n3] = fib(100, memfib);\r\nassert(n3 - n2 == 81);\r\n\r\n\r\nfunction [seq, n] = fib(n, memfib)\r\n    persistent num\r\n    if isempty(num)\r\n        num = 1;\r\n    else\r\n        num = num + 1;\r\n    end\r\n    \r\n    if n \u003c 3\r\n        seq = ones(1, n);\r\n    else\r\n        seq = memfib(n-1, memfib);\r\n        seq = [seq, seq(end-1) + seq(end)];\r\n    end\r\n    \r\n    n = num;\r\nend","published":true,"deleted":false,"likes_count":5,"comments_count":6,"created_by":134,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":102,"test_suite_updated_at":"2017-10-17T21:30:35.000Z","rescore_all_solutions":true,"group_id":35,"created_at":"2017-10-12T20:12:52.000Z","updated_at":"2026-04-01T04:17:42.000Z","published_at":"2017-10-16T01:51:02.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eThe test suite includes a simple recursive Fibonacci sequence generator, but it's terribly inefficient. One simple method for improving its performance is using a technique called memoization. Write a function that takes a function_handle that we wish to memoize and returns a function_handle to a memoized version of the initial handle.\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":44321,"title":"Van Eck's Sequence's nth member","description":"Return the Van Eck's Sequence's nth member.\r\n\r\nFor detailed info : \u003chttp://oeis.org/A181391 OEIS link\u003e and \u003chttps://www.theguardian.com/science/alexs-adventures-in-numberland/2014/oct/07/neil-sloane-the-man-who-loved-only-integer-sequences here\u003e\r\n\r\n seq = 0, 0, 1, 0, 2, 0, 2, 2, 1, 6, 0, 5...\r\n\r\nFirst member is 0;\r\n\r\nSecond member is 0;\r\n\r\nthird member is 1 etc\r\n","description_html":"\u003cp\u003eReturn the Van Eck's Sequence's nth member.\u003c/p\u003e\u003cp\u003eFor detailed info : \u003ca href = \"http://oeis.org/A181391\"\u003eOEIS link\u003c/a\u003e and \u003ca href = \"https://www.theguardian.com/science/alexs-adventures-in-numberland/2014/oct/07/neil-sloane-the-man-who-loved-only-integer-sequences\"\u003ehere\u003c/a\u003e\u003c/p\u003e\u003cpre\u003e seq = 0, 0, 1, 0, 2, 0, 2, 2, 1, 6, 0, 5...\u003c/pre\u003e\u003cp\u003eFirst member is 0;\u003c/p\u003e\u003cp\u003eSecond member is 0;\u003c/p\u003e\u003cp\u003ethird member is 1 etc\u003c/p\u003e","function_template":"function result = VanEcksSequence(n)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 0;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n\r\n%%\r\nx = 2;\r\ny_correct = 0;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n\r\n%%\r\nx = 4;\r\ny_correct = 0;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n\r\n%%\r\nx = 6;\r\ny_correct = 0;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n\r\n%%\r\nx = 11;\r\ny_correct = 0;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n\r\n%%\r\nx = 50;\r\ny_correct = 3;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n\r\n%%\r\nx = 500;\r\ny_correct = 4;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n\r\n\r\n%%\r\nx = 5000;\r\ny_correct = 402;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n\r\n%%\r\nx = 50000;\r\ny_correct = 114;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":12,"comments_count":1,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":331,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-13T08:14:57.000Z","updated_at":"2026-03-24T14:52:41.000Z","published_at":"2017-10-16T01:45:07.000Z","restored_at":"2017-09-28T06:15:18.000Z","restored_by":null,"spam":false,"simulink":false,"admin_reviewed":true,"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\u003eReturn the Van Eck's Sequence's nth member.\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 detailed info :\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://oeis.org/A181391\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eOEIS link\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=\\\"https://www.theguardian.com/science/alexs-adventures-in-numberland/2014/oct/07/neil-sloane-the-man-who-loved-only-integer-sequences\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehere\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=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ seq = 0, 0, 1, 0, 2, 0, 2, 2, 1, 6, 0, 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\u003eFirst member is 0;\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\u003eSecond member is 0;\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\u003ethird member is 1 etc\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":44307,"title":"The glass half full","description":"Identical glasses are placed in a triangular tower structure, such that the top level (L = 1) comprises one glass, the next level down (L = 2) comprises three glasses, the next level down (L = 3) comprises six glasses, and so on.\r\n\r\nFollow the \u003chttps://imgur.com/a/j9ZZa link\u003e to see a diagram shows the first three levels. The glasses in each levels are represented by the blue circles, while the yellow circles represent the positions of the glasses in the next higher level.\r\n\r\nWater is poured into the top glass at a constant volumetric flow rate. When the glass is filled, the water starts spilling over and into the glasses below. Note that *water only spills outward* , meaning that at some point, some glasses will remain empty.\r\n\r\nGiven the volume of a glass in liters, v, the volumetric flow rate in liters per second, u, and an integer, L, representing a level in the glass structure, return the total number of glasses in that level, g, the number of glasses in that level that will be filled with water, f, and the time, in seconds, it would take to fill all \"fillable\" glasses in that level, t, starting with no water in any of the levels.\r\n\r\nExample:\r\n\r\nInput: v = 0.25, u = 0.1, L = 2\r\n\r\nOutput: g = 3, f = 3, t = 10","description_html":"\u003cp\u003eIdentical glasses are placed in a triangular tower structure, such that the top level (L = 1) comprises one glass, the next level down (L = 2) comprises three glasses, the next level down (L = 3) comprises six glasses, and so on.\u003c/p\u003e\u003cp\u003eFollow the \u003ca href = \"https://imgur.com/a/j9ZZa\"\u003elink\u003c/a\u003e to see a diagram shows the first three levels. The glasses in each levels are represented by the blue circles, while the yellow circles represent the positions of the glasses in the next higher level.\u003c/p\u003e\u003cp\u003eWater is poured into the top glass at a constant volumetric flow rate. When the glass is filled, the water starts spilling over and into the glasses below. Note that \u003cb\u003ewater only spills outward\u003c/b\u003e , meaning that at some point, some glasses will remain empty.\u003c/p\u003e\u003cp\u003eGiven the volume of a glass in liters, v, the volumetric flow rate in liters per second, u, and an integer, L, representing a level in the glass structure, return the total number of glasses in that level, g, the number of glasses in that level that will be filled with water, f, and the time, in seconds, it would take to fill all \"fillable\" glasses in that level, t, starting with no water in any of the levels.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003eInput: v = 0.25, u = 0.1, L = 2\u003c/p\u003e\u003cp\u003eOutput: g = 3, f = 3, t = 10\u003c/p\u003e","function_template":"function [g, f, t] = filltime(v, u, L)\r\n    [g, f, t] = [v, u, L];\r\nend","test_suite":"%%\r\n[g f t] = filltime(0.25, 0.1, 2);\r\nassert(isequal([g f t],[3 3 10]))\r\n\r\n%%\r\n[g f t] = filltime(0.45, 0.3, 6);\r\nassert(isequal([g f t],[21 15 69]))\r\n\r\n%%\r\n[g f t] = filltime(3, 0.8, 7);\r\nassert(isequal([g f t],[28 18 240]))\r\n\r\n\r\n%%\r\n[g f t] = filltime(2, 8, 47);\r\nassert(isequal([g f t],[1128 138 811]))","published":true,"deleted":false,"likes_count":8,"comments_count":1,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":260,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-09T07:06:17.000Z","updated_at":"2026-04-07T08:44:37.000Z","published_at":"2017-10-16T01:45: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\u003eIdentical glasses are placed in a triangular tower structure, such that the top level (L = 1) comprises one glass, the next level down (L = 2) comprises three glasses, the next level down (L = 3) comprises six glasses, and so on.\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\u003eFollow 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://imgur.com/a/j9ZZa\\\"\u003e\u003cw:r\u003e\u003cw:t\u003elink\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e to see a diagram shows the first three levels. The glasses in each levels are represented by the blue circles, while the yellow circles represent the positions of the glasses in the next higher level.\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\u003eWater is poured into the top glass at a constant volumetric flow rate. When the glass is filled, the water starts spilling over and into the glasses below. Note that\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\u003ewater only spills outward\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e , meaning that at some point, some glasses will remain empty.\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\u003eGiven the volume of a glass in liters, v, the volumetric flow rate in liters per second, u, and an integer, L, representing a level in the glass structure, return the total number of glasses in that level, g, the number of glasses in that level that will be filled with water, f, and the time, in seconds, it would take to fill all \\\"fillable\\\" glasses in that level, t, starting with no water in any of the levels.\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\u003eExample:\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\u003eInput: v = 0.25, u = 0.1, L = 2\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\u003eOutput: g = 3, f = 3, t = 10\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":44305,"title":"5 Prime Numbers","description":"Your function will be given lower and upper integer bounds. Your task is to return a vector containing the first five prime numbers in that range that contain the number five. But, if you can't find at least five such numbers, the function should give up and return -1.\r\n\r\nFor example, for n_min = 60 and n_max = 1000, the set of prime numbers is:\r\n\r\n p = [61,67,71,73,79, ... 149,151,157,163, ... 241,251,257,263, ... 349,353,359,367, ... 983,991,997]\r\n\r\nThis set contains at least five numbers that contain a five; the first five are:\r\n\r\n p5 = [151,157,251,257,353]\r\n\r\nwhich is the set that your function should return in this case. If, however, n_max were set at 300, five such numbers do not exist and the function should then give up (return -1).","description_html":"\u003cdiv style = \"text-align: start; line-height: 20px; 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: normal; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"display: block; min-width: 0px; padding-top: 0px; transform-origin: 420.4375px 118px; vertical-align: baseline; perspective-origin: 420.4375px 118px; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; transform-origin: 309px 31.5px; white-space: pre-wrap; perspective-origin: 309px 31.5px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eYour function will be given lower and upper integer bounds. Your task is to return a vector containing the first five prime numbers in that range that contain the number five. But, if you can't find at least five such numbers, the function should give up and return -1.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; transform-origin: 309px 10.5px; white-space: pre-wrap; perspective-origin: 309px 10.5px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eFor example, for n_min = 60 and n_max = 1000, the set of prime numbers is:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-bottom: 10px; margin-left: 3px; margin-right: 3px; margin-top: 10px; transform-origin: 417.4375px 10px; perspective-origin: 417.4375px 10px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: 18px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-right: 45px; min-height: 0px; padding-left: 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; perspective-origin: 0px 0px; margin-right: 45px; \"\u003e\u003cspan style=\"margin-right: 0px; \"\u003e p = [61,67,71,73,79, \u003c/span\u003e\u003cspan style=\"border-bottom-color: rgb(255, 0, 0); border-left-color: rgb(255, 0, 0); border-right-color: rgb(255, 0, 0); border-top-color: rgb(255, 0, 0); caret-color: rgb(255, 0, 0); color: rgb(255, 0, 0); margin-right: 0px; outline-color: rgb(255, 0, 0); text-decoration-color: rgb(255, 0, 0); column-rule-color: rgb(255, 0, 0); \"\u003e… \u003c/span\u003e\u003cspan style=\"margin-right: 0px; \"\u003e149,151,157,163, \u003c/span\u003e\u003cspan style=\"border-bottom-color: rgb(255, 0, 0); border-left-color: rgb(255, 0, 0); border-right-color: rgb(255, 0, 0); border-top-color: rgb(255, 0, 0); caret-color: rgb(255, 0, 0); color: rgb(255, 0, 0); margin-right: 0px; outline-color: rgb(255, 0, 0); text-decoration-color: rgb(255, 0, 0); column-rule-color: rgb(255, 0, 0); \"\u003e… \u003c/span\u003e\u003cspan style=\"margin-right: 0px; \"\u003e241,251,257,263, \u003c/span\u003e\u003cspan style=\"border-bottom-color: rgb(255, 0, 0); border-left-color: rgb(255, 0, 0); border-right-color: rgb(255, 0, 0); border-top-color: rgb(255, 0, 0); caret-color: rgb(255, 0, 0); color: rgb(255, 0, 0); margin-right: 0px; outline-color: rgb(255, 0, 0); text-decoration-color: rgb(255, 0, 0); column-rule-color: rgb(255, 0, 0); \"\u003e… \u003c/span\u003e\u003cspan style=\"margin-right: 0px; \"\u003e349,353,359,367, \u003c/span\u003e\u003cspan style=\"border-bottom-color: rgb(255, 0, 0); border-left-color: rgb(255, 0, 0); border-right-color: rgb(255, 0, 0); border-top-color: rgb(255, 0, 0); caret-color: rgb(255, 0, 0); color: rgb(255, 0, 0); margin-right: 0px; outline-color: rgb(255, 0, 0); text-decoration-color: rgb(255, 0, 0); column-rule-color: rgb(255, 0, 0); \"\u003e… \u003c/span\u003e\u003cspan style=\"margin-right: 0px; \"\u003e983,991,997]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 10px; text-align: left; transform-origin: 309px 10.5px; white-space: pre-wrap; perspective-origin: 309px 10.5px; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThis set contains at least five numbers that contain a five; the first five are:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-bottom: 10px; margin-left: 3px; margin-right: 3px; margin-top: 10px; transform-origin: 417.4375px 10px; perspective-origin: 417.4375px 10px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: 18px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-right: 45px; min-height: 0px; padding-left: 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; perspective-origin: 0px 0px; margin-right: 45px; \"\u003e\u003cspan style=\"margin-right: 0px; \"\u003e p5 = [151,157,251,257,353]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 10px; text-align: left; transform-origin: 309px 21px; white-space: pre-wrap; perspective-origin: 309px 21px; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003ewhich is the set that your function should return in this case. If, however, n_max were set at 300, five such numbers do not exist and the function should then give up (return -1).\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = five_primes(n_min,n_max)\r\n  y = [];\r\nend","test_suite":"%%\r\nn_min = 60;\r\nn_max = 1000;\r\ny_correct = [151,157,251,257,353];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 60;\r\nn_max = 300;\r\ny_correct = -1;\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 1;\r\nn_max = 200;\r\ny_correct = [5,53,59,151,157];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 1;\r\nn_max = 100;\r\ny_correct = -1;\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 500;\r\nn_max = 600;\r\ny_correct = [503,509,521,523,541];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 500;\r\nn_max = 555;\r\ny_correct = [503,509,521,523,541];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 500;\r\nn_max = 500000000;\r\ny_correct = [503,509,521,523,541];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 5000;\r\nn_max = 5020;\r\ny_correct = -1;\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 5000;\r\nn_max = 5200;\r\ny_correct = [5003,5009,5011,5021,5023];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 5000;\r\nn_max = 55555555;\r\ny_correct = [5003,5009,5011,5021,5023];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 55555;\r\nn_max = 56789;\r\ny_correct = [55579,55589,55603,55609,55619];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 987654321;\r\nn_max = 988777666;\r\ny_correct = [987654323,987654337,987654347,987654359,987654361];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))","published":true,"deleted":false,"likes_count":7,"comments_count":2,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":453,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-08T18:33:05.000Z","updated_at":"2026-04-06T09:57:52.000Z","published_at":"2017-10-16T01:45:06.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\u003eYour function will be given lower and upper integer bounds. Your task is to return a vector containing the first five prime numbers in that range that contain the number five. But, if you can't find at least five such numbers, the function should give up and return -1.\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\u003eFor example, for n_min = 60 and n_max = 1000, the set of prime numbers is:\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[ p = [61,67,71,73,79, … 149,151,157,163, … 241,251,257,263, … 349,353,359,367, … 983,991,997]]]\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis set contains at least five numbers that contain a five; the first five are:\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[ p5 = [151,157,251,257,353]]]\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ewhich is the set that your function should return in this case. If, however, n_max were set at 300, five such numbers do not exist and the function should then give up (return -1).\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":44339,"title":"Recaman Sequence - II","description":"Take an arbitrary starting point as input and create Recaman Sequence. Then find the 1, return its index.\r\n\r\nFor example: if n = 0 (default Recaman sequence)\r\n  \r\n  seq = [0 1 3 6 2];\r\n\r\n1 is in the second place. \r\n\r\nif n = 10;\r\n\r\n  seq = [10 9 7 4 8 3 9 2 10 1 11 22 34 21];\r\n\r\n1 is in the 10th place\r\n\r\n*Related Challenges :*\r\n\r\n# \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44338 Recaman Sequence - I\u003e\r\n# Recaman Sequence - II\r\n# \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44340 Recaman Sequence - III\u003e","description_html":"\u003cp\u003eTake an arbitrary starting point as input and create Recaman Sequence. Then find the 1, return its index.\u003c/p\u003e\u003cp\u003eFor example: if n = 0 (default Recaman sequence)\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eseq = [0 1 3 6 2];\r\n\u003c/pre\u003e\u003cp\u003e1 is in the second place.\u003c/p\u003e\u003cp\u003eif n = 10;\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eseq = [10 9 7 4 8 3 9 2 10 1 11 22 34 21];\r\n\u003c/pre\u003e\u003cp\u003e1 is in the 10th place\u003c/p\u003e\u003cp\u003e\u003cb\u003eRelated Challenges :\u003c/b\u003e\u003c/p\u003e\u003col\u003e\u003cli\u003e\u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44338\"\u003eRecaman Sequence - I\u003c/a\u003e\u003c/li\u003e\u003cli\u003eRecaman Sequence - II\u003c/li\u003e\u003cli\u003e\u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44340\"\u003eRecaman Sequence - III\u003c/a\u003e\u003c/li\u003e\u003c/ol\u003e","function_template":"function y = RecamanII(startPoint)\r\n\r\nend","test_suite":"%%\r\nx = 0;\r\ny_correct = 2;\r\nassert(isequal(RecamanII(x),y_correct))\r\n\r\n%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(RecamanII(x),y_correct))\r\n\r\n%%\r\nx = 3;\r\ny_correct = 4;\r\nassert(isequal(RecamanII(x),y_correct))\r\n\r\n%%\r\nx = 90;\r\ny_correct = 35;\r\nassert(isequal(RecamanII(x),y_correct))\r\n\r\n%%\r\nx = 123456;\r\ny_correct = 895;\r\nassert(isequal(RecamanII(x),y_correct))\r\n\r\n%%\r\nx = 123456789;\r\ny_correct = 46633;\r\nassert(isequal(RecamanII(x),y_correct))\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":281,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-19T07:08:59.000Z","updated_at":"2026-04-07T13:57:31.000Z","published_at":"2017-10-16T01:45: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\u003eTake an arbitrary starting point as input and create Recaman Sequence. Then find the 1, return its index.\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 example: if n = 0 (default Recaman sequence)\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[seq = [0 1 3 6 2];]]\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\u003e1 is in the second place.\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\u003eif n = 10;\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[seq = [10 9 7 4 8 3 9 2 10 1 11 22 34 21];]]\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\u003e1 is in the 10th place\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRelated Challenges :\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:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44338\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - I\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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - II\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:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44340\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - III\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":44375,"title":"Missing five","description":"Convert decimal numbers to a base-9 notation missing the digit *5*\r\n\r\n\u003c\u003chttp://www.alfnie.com/software/missing5.jpg\u003e\u003e\r\n\r\nToo many five-themed problems? Wondering whether everything would be simpler if we just got rid of the digit 5? Let's try!\r\n\r\nIn a world without 5's, positive integers may be represented using a base-9 notation that uses only the digits 0, 1, 2, 3, 4, 6, 7, 8, and 9. We'll call this the \"missing-5\" notation. The following list shows the first 100 positive numbers (i.e. 1 through 100) using \"missing-5\" notation:\r\n\r\n    '1'      '2'      '3'      '4'      '6'      '7'      '8'      '9'      '10'     '11' \r\n    '12'     '13'     '14'     '16'     '17'     '18'     '19'     '20'     '21'     '22' \r\n    '23'     '24'     '26'     '27'     '28'     '29'     '30'     '31'     '32'     '33' \r\n    '34'     '36'     '37'     '38'     '39'     '40'     '41'     '42'     '43'     '44' \r\n    '46'     '47'     '48'     '49'     '60'     '61'     '62'     '63'     '64'     '66' \r\n    '67'     '68'     '69'     '70'     '71'     '72'     '73'     '74'     '76'     '77' \r\n    '78'     '79'     '80'     '81'     '82'     '83'     '84'     '86'     '87'     '88' \r\n    '89'     '90'     '91'     '92'     '93'     '94'     '96'     '97'     '98'     '99' \r\n    '100'    '101'    '102'    '103'    '104'    '106'    '107'    '108'    '109'    '110'\r\n    '111'    '112'    '113'    '114'    '116'    '117'    '118'    '119'    '120'    '121'\r\n\r\nYou may notice that this is simply the sorted list of positive numbers which do not contain the digit 5 in their decimal representation. \r\n\r\nYour function should convert a positive decimal number N into its \"missing-5\" notation. For example\r\n\r\n dec2missing5(20)\r\n\r\nshould return _'22'_ (the 20th positive number in missing-5 notation), and\r\n\r\n dec2missing5(100)\r\n\r\nshould return _'121'_ (the 100th positive number in missing-5 notation)\r\n\r\nGood luck!\r\n\r\n_Small print_: Your function may output a number, a char array, or a string; whatever you find simpler (e.g. in the example above, valid outputs are 121, '121', or \"121\"). Input numbers in testsuite are always relatively low valued positive integers (\u003c10,000)","description_html":"\u003cp\u003eConvert decimal numbers to a base-9 notation missing the digit \u003cb\u003e5\u003c/b\u003e\u003c/p\u003e\u003cimg src = \"http://www.alfnie.com/software/missing5.jpg\"\u003e\u003cp\u003eToo many five-themed problems? Wondering whether everything would be simpler if we just got rid of the digit 5? Let's try!\u003c/p\u003e\u003cp\u003eIn a world without 5's, positive integers may be represented using a base-9 notation that uses only the digits 0, 1, 2, 3, 4, 6, 7, 8, and 9. We'll call this the \"missing-5\" notation. The following list shows the first 100 positive numbers (i.e. 1 through 100) using \"missing-5\" notation:\u003c/p\u003e\u003cpre\u003e    '1'      '2'      '3'      '4'      '6'      '7'      '8'      '9'      '10'     '11' \r\n    '12'     '13'     '14'     '16'     '17'     '18'     '19'     '20'     '21'     '22' \r\n    '23'     '24'     '26'     '27'     '28'     '29'     '30'     '31'     '32'     '33' \r\n    '34'     '36'     '37'     '38'     '39'     '40'     '41'     '42'     '43'     '44' \r\n    '46'     '47'     '48'     '49'     '60'     '61'     '62'     '63'     '64'     '66' \r\n    '67'     '68'     '69'     '70'     '71'     '72'     '73'     '74'     '76'     '77' \r\n    '78'     '79'     '80'     '81'     '82'     '83'     '84'     '86'     '87'     '88' \r\n    '89'     '90'     '91'     '92'     '93'     '94'     '96'     '97'     '98'     '99' \r\n    '100'    '101'    '102'    '103'    '104'    '106'    '107'    '108'    '109'    '110'\r\n    '111'    '112'    '113'    '114'    '116'    '117'    '118'    '119'    '120'    '121'\u003c/pre\u003e\u003cp\u003eYou may notice that this is simply the sorted list of positive numbers which do not contain the digit 5 in their decimal representation.\u003c/p\u003e\u003cp\u003eYour function should convert a positive decimal number N into its \"missing-5\" notation. For example\u003c/p\u003e\u003cpre\u003e dec2missing5(20)\u003c/pre\u003e\u003cp\u003eshould return \u003ci\u003e'22'\u003c/i\u003e (the 20th positive number in missing-5 notation), and\u003c/p\u003e\u003cpre\u003e dec2missing5(100)\u003c/pre\u003e\u003cp\u003eshould return \u003ci\u003e'121'\u003c/i\u003e (the 100th positive number in missing-5 notation)\u003c/p\u003e\u003cp\u003eGood luck!\u003c/p\u003e\u003cp\u003e\u003ci\u003eSmall print\u003c/i\u003e: Your function may output a number, a char array, or a string; whatever you find simpler (e.g. in the example above, valid outputs are 121, '121', or \"121\"). Input numbers in testsuite are always relatively low valued positive integers (\u0026lt;10,000)\u003c/p\u003e","function_template":"function y = dec2missing5(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nassert(isequal(regexprep(char(string(dec2missing5(3))),'^0*',''),'3'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(14))),'^0*',''),'16'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(19))),'^0*',''),'21'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(80))),'^0*',''),'99'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(91))),'^0*',''),'111'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(313))),'^0*',''),'388'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(732))),'^0*',''),'1003'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(748))),'^0*',''),'1021'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(1249))),'^0*',''),'1738'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(1873))),'^0*',''),'2611'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(2790))),'^0*',''),'3840'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(3035))),'^0*',''),'4142'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(3391))),'^0*',''),'4688'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(3547))),'^0*',''),'4881'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(3724))),'^0*',''),'6098'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4057))),'^0*',''),'6608'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4221))),'^0*',''),'6810'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4389))),'^0*',''),'7017'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4444))),'^0*',''),'7088'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4489))),'^0*',''),'7138'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4530))),'^0*',''),'7193'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4533))),'^0*',''),'7197'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4569))),'^0*',''),'7237'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4585))),'^0*',''),'7264'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4651))),'^0*',''),'7338'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4680))),'^0*',''),'7380'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(5455))),'^0*',''),'8431'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(5711))),'^0*',''),'8846'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(5949))),'^0*',''),'9140'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(5999))),'^0*',''),'9206'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(6075))),'^0*',''),'9300'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(6526))),'^0*',''),'9961'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(6601))),'^0*',''),'10044'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(6634))),'^0*',''),'10091'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(6728))),'^0*',''),'10206'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(6787))),'^0*',''),'10281'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(6902))),'^0*',''),'10419'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(7037))),'^0*',''),'10689'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(7212))),'^0*',''),'10903'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(7493))),'^0*',''),'11246'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(7962))),'^0*',''),'11927'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(7996))),'^0*',''),'11974'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(8062))),'^0*',''),'12048'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(8109))),'^0*',''),'12110'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(8248))),'^0*',''),'12284'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(8427))),'^0*',''),'12603'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(8538))),'^0*',''),'12737'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(8620))),'^0*',''),'12838'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(8959))),'^0*',''),'13264'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(9190))),'^0*',''),'13641'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(9289))),'^0*',''),'13771'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(9436))),'^0*',''),'13944'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(9480))),'^0*',''),'14003'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(9533))),'^0*',''),'14072'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(9541))),'^0*',''),'14081'))\r\n%%\r\nfor n=1:100, assert(all(char(string(dec2missing5(randi(10000))))~='5')); end\r\n%%\r\nx='1000'; for n=1:7, x=char(string(dec2missing5(str2double(x)))); end; assert(isequal(regexprep(x,'^0*',''),'11027'));\r\n%%\r\nx='234'; for n=1:10, x=char(string(dec2missing5(str2double(x)))); end; assert(isequal(regexprep(x,'^0*',''),'4240'));\r\n%%\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13944,14003,14072,14081]),regexp(fileread('dec2missing5.m'),'((\\s*[\\+\\-\\*\\/]\\s*)?[\\d\\.])+','match'))),'please do not use look-up table solutions');\r\n\r\n","published":true,"deleted":false,"likes_count":9,"comments_count":7,"created_by":43,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":381,"test_suite_updated_at":"2017-10-31T17:07:46.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-11T00:58:23.000Z","updated_at":"2026-04-07T15:19:53.000Z","published_at":"2017-10-16T01:45: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\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/media/image1.JPEG\"}],\"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\u003eConvert decimal numbers to a base-9 notation missing the digit\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\u003e5\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:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"relationshipId\\\" w:val=\\\"rId1\\\"/\u003e\u003c/w:customXmlPr\u003e\u003c/w:customXml\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\u003eToo many five-themed problems? Wondering whether everything would be simpler if we just got rid of the digit 5? Let's try!\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\u003eIn a world without 5's, positive integers may be represented using a base-9 notation that uses only the digits 0, 1, 2, 3, 4, 6, 7, 8, and 9. We'll call this the \\\"missing-5\\\" notation. The following list shows the first 100 positive numbers (i.e. 1 through 100) using \\\"missing-5\\\" notation:\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[    '1'      '2'      '3'      '4'      '6'      '7'      '8'      '9'      '10'     '11' \\n    '12'     '13'     '14'     '16'     '17'     '18'     '19'     '20'     '21'     '22' \\n    '23'     '24'     '26'     '27'     '28'     '29'     '30'     '31'     '32'     '33' \\n    '34'     '36'     '37'     '38'     '39'     '40'     '41'     '42'     '43'     '44' \\n    '46'     '47'     '48'     '49'     '60'     '61'     '62'     '63'     '64'     '66' \\n    '67'     '68'     '69'     '70'     '71'     '72'     '73'     '74'     '76'     '77' \\n    '78'     '79'     '80'     '81'     '82'     '83'     '84'     '86'     '87'     '88' \\n    '89'     '90'     '91'     '92'     '93'     '94'     '96'     '97'     '98'     '99' \\n    '100'    '101'    '102'    '103'    '104'    '106'    '107'    '108'    '109'    '110'\\n    '111'    '112'    '113'    '114'    '116'    '117'    '118'    '119'    '120'    '121']]\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\u003eYou may notice that this is simply the sorted list of positive numbers which do not contain the digit 5 in their decimal representation.\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 should convert a positive decimal number N into its \\\"missing-5\\\" notation. 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[ dec2missing5(20)]]\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\u003eshould return\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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e'22'\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (the 20th positive number in missing-5 notation), and\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[ dec2missing5(100)]]\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\u003eshould return\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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e'121'\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (the 100th positive number in missing-5 notation)\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\u003eGood luck!\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:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSmall print\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: Your function may output a number, a char array, or a string; whatever you find simpler (e.g. in the example above, valid outputs are 121, '121', or \\\"121\\\"). Input numbers in testsuite are always relatively low valued positive integers (\u0026lt;10,000)\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\"},{\"partUri\":\"/media/image1.JPEG\",\"contentType\":\"image/JPEG\",\"content\":\"data:image/JPEG;base64,/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCADqASMDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD3+iiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAoopCwA5IAoAKK5fXPH2g6GXjmuxLcp/wAsIRubPoew/EivP9U+MGpTsV02yht0/vSkux/AYA/WsKmIpw3Z6eEyfGYrWnDTu9D2fcB1IH41G08SDLSIB7kV8333jHxFqP8Ax8avc4z0jbyx/wCO4rGlmlnk3zSPI/Tc7EmuZ4+P2Ue5S4Rq2vVqJfj/AJH1C2r6epwb2AH0Mg/xpyanZSn5LqFvo4NfLFFT9ff8pv8A6ow/5/fh/wAE+sBIh6Mp/GnDB6V8sWup6hZEfZb65gHYRysv8jXR6f8AEnxNYYBvVuUH8M6A/qMH9auOPg/iVjkrcJ4mKvSmpfgfQlFeX6R8YbOXbHqllJAe8kR3r+XUfrXf6XrenazbibT7uOdD3U8j6jqPxrqhWhP4WeDisuxOFf76DX5GlRRRWpxBRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAJRSH1Nee+OPiLFoofTtLZJr88O/VYfr6t7fn6GJ1IwV5HThcJVxVRU6SuzpPEfi3S/DNuHvJsytny4U+Z3/DsPc8V434i+Imta6zxRymytCeIoW5I/2m6n8MCuYuLi51G8aaeSSe5lblmO5mPpXoPhT4V3N+q3etl7aA4K26n52/3j/D9Ov0rzZVquIfLDRH2lLLsBlFNVcW+af9bI8/srC61G4W3sreSeZuixrk13Wj/CTV75RJqM8dip/gx5jY/A4/WvXtL0TTtGtxBp9pHAg67Ryfqep/GtGt6eBitZ6nmYzinEVPdw65V+JwVh8J/D9oo+0ie7YdTJIRn8FxXQ23g/w9a4MOkWgI6MYVJ/PGa3KOldUaUI7I8Crj8TWf7ybfzKS6Rp8YwlnAB7IBUc2haXcD97p9tJ/vRKf6Vo0VXKuxh7ap/MzmLz4feGbxCH0qGPPeIbD/47iuX1P4O2Eu59Ov5rds5CSDzFH8j+pr0+is5UKct0ddDNMZQd4VGfOus/D/xBoqtLJafaIB/y0t/n/MdR+VYFlf3WnXK3FlcSQTDo0bYNfVBAYYIBrlPEfgDRvEAaRovs12ek8XBz7joa5KmBtrTZ9HhOKOdezxsLp9V/kcf4Y+LLhhbeIFBHAW5jX/0JR/T8q9VtrqG9t0nt5VkicZVkOQRXzr4l8Har4ZlP2mLzbUnCXEY+U/X+6frS+FvGGoeFrnMDebaMcyW7HAb3Hofepp4qVN8lU1xuQ4fF0/rGXtenT/gH0hRWRoPiGw8RWC3VjLuHG5DwyH0IrX5r0k01dHxdSnKnJwmrNC0UUUyAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAEo6UVyXjrxYnhnRz5RBvpwVgQ9vVj7D/CplJQXMzbD0J16ipU1dsw/iN47GlxvpGly/wCnOP3sin/Uj/4o/p+VeP2dndanfR2trE89xK2FUckn1/8Ar01VudQvcKHnuZ5M4HLOxP8AMmvevA3guHwzp/mzhZNQmUebJj7o/ur7fzx9K8tKWKqXex93UnQyHCKMdakv6+4h8GfD+z8PQpd3SrcakRkyEcR57L/j1rt8YHFFFenCEYKyPhcTiauJqOpVd2xaKKKswCiiigAooooAKKKKACiikJAGTQBBd2tveWzwXMSSwuMMrrkEe9fOnjLT9J0zxDNa6ROZIU++vURv3UHvj9Old58QviEYPN0XRpv3vK3Fyh+56qp/vep7fXp5PFFJPMkMMbSSOQqooyWJ6ACvLxlWMnyRV2fdcNYCvQi8TVlyxfTv5s0/D3iG98Oaml5aOdvSSMn5XX3FfQ3h/XbPxDpUV9aOCrcMvdG7g+9eF6/4F1Tw9o9tqFyA6yDEyoM+SSeAT39PrxzTPBfiqbwxrCuWLWUxCzx57f3h7ipw9WVGXJU2N82wFDNKLxOFacl26+R9GUVDb3EV1bxzwuHjdQyspyCD3qavWPz9pp2YtFFFAgooooAKKKKACiiigAooooAKKKKACiiigAooooAguriO0tpLiZwkcalmY9AAOtfNvinX5vEeuz30hPlZ2wL/AHUHT8e59zXqHxa182WkRaTA+Jbw5kweRGOv5nA/OvLvCuhv4h8Q21gAfLJ3zEdkHX/D6kV5uMqOc1Sifa8OYWGGoTx9b5eh6J8K/CQjhGv3kf7xwRaqw+6vQt9T0Ht9a9VFRW8EdrbxwRKEjRQqqBwAKlrupU1Tgoo+Wx+MnjK8q0+v5C0UUVocYUUUUAFFfI/xQ8Yay/xJ1xLLWL63tobjyFiguXRV2KFPAPqprkP+Es8R/wDQwar/AOBsn+NAH3PRXwx/wlniP/oYNV/8DZP8aP8AhLPEf/Qwar/4Gyf40Afc9FfDH/CWeJP+hg1X/wADJP8A4qvT/gRr2r6h8QZYb7Vb65hFjI2ye4d1zuTnBNAH0sSAMk15X8RPiCbdpdF0eUrN924uFP3P9lT6+p7fXpL8QfiCLMSaRpEubn7s0yn/AFfsPf8AlXkKJLcTqkatJLI2AByWJrz8Vibe5Dc+wyLIlK2KxS91bJ/mxIopJ5UiijZ5HIVUUZJJ7CvcfAPgKPQIV1DUEV9TccDqIQew9/U/gOOrPAPgBNEjXUdSQPqDj5VPIhHoPf3r0GqwuG5ffnuY59nnt39Xw79xbvv/AMAr3tpDfWkttcRrJFIpVlYZBBr5x8WeHpfDWuzWTAmFvngc/wASE/zHSvpauM+I/hsa54eeaGMNd2gMkRA5I7r+IH8q0xVH2kLrdHFkGZPB4lRk/clo/wDM574T+J2lifQ7uTLxjfbEn+Huv4dfx9q9U618s6VqM2k6pb30BxJC4b6juK+nNOvYdR0+3vIG3RTRh1PsRmowdXnhyvdG/EuAWHxHtYfDP8y3RRRXafNhRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABTScAn0paztcvhpuiXt6ekMLP+QpN2VyoRc5KK6ngnj3VjrHjC9kViYoW8iMegXg/+PZr0D4Q6MINJuNWkUb7l9kZ/wBheP8A0LP5V44S80ufmeR2+pYmvp3QdNTSNDs7BORDEq59Tjk/jXm4Re0quoz7fiCawmAp4SHX9DTooor0z4YKKKKACmSyJDE8sjBURSzE9gKfXMfETUf7J+Hev3YbawspEQ+jONin82FAHxlqV6+pareX8md9zM8zZ9WYn+tfR3w++EXhDVPAWj6hrOj/AGi/uYfOkl+0zJuDMSvCuB90r2r5qiieeaOKNSzyMFVfUnpX3dpNiul6NY6emNtrbxwLj0VQv9KAOM/4Ul8PP+he/wDJ24/+OUf8KS+Hn/Qvf+Ttx/8AHK9ApCcDJoA8/PwU+HgHPh//AMnbj/45XDeIIvCfgnUJoPB2ni21No2hnuluZZPLQ4JUbmIzwOe1dT8QfiCLMSaRpEn+kn5ZplP+r9h7/wAq8hRJbiZUjVpJZGwAOSxNefisVb3Ibn1+RZFz2xWKVorZf5+QIktxMsaK0ksjYAHJYmvbfAPgFNEjTUtRRX1Bx8q9RCPQe/vR4A8Apoka6jqSK+oOPlU8iEe3v716DTwuF5ffnuRnue+3vh8O7QW77/8AAFooorvPkwprqHQqehGKdRQB81eMdHGh+KL2zVdsO/zIhjA2NzgfQ5H4V6d8I9YN5oM+nSMC1nJ8o/2G5H65rK+MumhTp2pKACS0LnHJ7r/JvzrB+FWoG08XraliEu4mTGeMj5gf0b868uH7rE26M+8xD/tDJFUfxR/Tf8D3qiiivUPgwooooAKKKKACiiigAooooAKKKKACiiigBK434oXX2fwRdoDhpWRB/wB9DP6A12Vec/GKQp4atEBxvulBHqNrH+grKu7U5HflcFPG00+6PKvC9p9u8UaZb9muEJHqAcn9BX00owoHtXzz8N4/M8eab6JvY/8AfDD+tfQ9cuAX7tvzPb4tnfFxh2QtFFFd58qFFFFABXlX7QGo/Y/hqbUNg3t5FER6hcyfzQV6rXz9+0rqOZNA0xW6CW4df++VX+T0AeVfDnTf7V+I2gWm3cpvI5GHqqHe36Ka+tvEHjXw34VX/ic6vb20mMiEtukI/wBxct+OK+NvD+vXvhnVP7S01lS8WN44pWGTHuUqWHvgnFFlpeueJ7+VrOzvtTunO+V0RpWJPdm/qaAPo+f9obwbFLsit9XuB/eit0A/8ecGqfiD4vQ6xo4j0GC7tmmyGluFVWVf9kAnr614nZ+FLnT7101WERSxHmHcGIPvg8fSt4lUUkkAAdT0Arz8Vire5Dc+wyLIlO2JxS91bIkVZJpQqq0kjtgADJYn+Zr27wD4BTRYk1LUUV9QcfKp5EI9B7+9fOJ8ZXuk6zb3mjyLHJbPuV2QMGPQ5B7YJr6Z+G/xDsvHujGQKtvqduALq2ByB6Ov+yf06e5eFw3L789yM+zz218Nh37q3ff/AIB29FFFd58kFFFFABRRRQBxfxQtPtPgi7cAFoWRx/30Af0JrxfwtdNZ+KtLnUkYuUBI9Cdp/Q17542QSeDdWB7Wzn8lJr5zs5PKvreQcFJVbp6GvLxnu1YyPueG37XAVqL8/wAUfVanKg+1LTIjmJPoKfXqHw73CiiigQUUUUAFFFFABRRRQAUUUUAFFFFABXmvxkH/ABTlkfS7X/0B69Jrhfixbed4MeX/AJ4zI/67f/Zqxrr92z0cply42k/NHmvwzfb48sAf4g4/8cJ/pX0JXzZ4JuRa+M9KlP8Az22cf7QK/wBa+kgcgGufAP8AdteZ7HFkbYyMu8f1Y6iiiu4+WCiiigAr58+M3gXxh4q8bC90zRpLmwgtY4I5Fmj55Zj8pbPViOnavoOgnAoA+X/AnwO1fVNVMvim2m07TYCC0ZI8yc/3RjoPU/l6j0bxd4t0/wAL6f8A8I14VhhtTGNsjQKAsPqB6v6n+tW/iD8QhYiTSNIkzdn5Zp1P+q9h/tfy+tePKsk0oRVaSR2wABksT/M15+KxVvchufXZFkXtLYrFK0Vsu/m/IFWSaUKoaSR2wABksT/M17B4U+Flj/ZEjeIrVbia6jKmAniJT6EH73uOnb3t+APACaNGmp6nGG1Bh8iHkQA/+zep/Ae/olPC4Xl9+e5Oe577ZvD4Z2it33/4B8ffFD4eTeAdcRYnefS7sFrWZ/vDHVG/2hxz3B+oGN4G8UzeDvF1jq8TN5KPsuUX/lpCfvL/AFHuBX098Y9Fi1n4ZaruUGWzQXcTf3SnX/x3cPxr49rvPkz77ikSaJJY2DRuoZWHQg9DUlcd8LNRbU/hhoFw5yy23k5/65sY/wD2WuxoAKKKKACiiigDB8ZMF8HauT/z6SD81NfN9shkuYUXG5nUD86+gviNci28Dai3d1WMD/eYL/WvCNDgNzr+nQhS2+5jBAGeNwzXmY3WpGJ9zwwuTBVqr/qyPqCL/VJ9BT6anCKPanV6aPh3uFFFFAgooooAKKKKACiiigAooooAKKKKAErC8Y2Laj4S1K2QFnaFioA6kcj9QK3abIoaNlPcYqZK6aNKNR06kZrdO58qW072t1DcR43xOHX6g5FfUtjcx3ljBcRNujkRWUjuCOK+aPEOnNpPiC/sWUKIpmCgf3Tyv6EV7P8AC7VxqPhOO2ZgZbMmJh7dV/Tj8K87BS5Jygz7Tiekq+GpYqG3+Z3NFFFemfDhRRQTgUAMd1RSzEBQOSa8v8dfEm3jtvsHh+7jnklX57uFwyop/ukcE+/b69JPiF8QVsVl0fSZAbogrPOp/wBUPQf7X8vr08aJCKSSAAO/QCvPxWKt7kNz6/IsiVRLFYpWitl3/wCASKsk0oVQ0kjtgADJYn+Zr2vwB4ATRo01TU0Daiw+ROogB/8AZvU/gPfjfgrd6FquvX6SANqdsoe33nhk6Myj1Bxn2I9692p4XDcvvz3Iz7PHWbw2Hdord9/+AL0ooorvPkzmviDMkHw58SO5wDps6fiyFR+pr4lr6g/aA8URaZ4OTQo3H2vU3G5QeViRgxP4sFHv83pXzFHG8sqRRqWkchVUDJJPagD67+CSMnwk0Xd/EZ2A9vOevQaxPCOjHw94R0nSWA8y1tUSTHTfj5v/AB7NbdABRRRQAUUUHgUAeZ/GLUDDo1nYq2DcTbmHqqj/ABK/lXC/Day+2eOLLIykIaVsj0GB+pFTfE7Vxqfi+WFH3Q2iiFcHI3dWP1ycf8Brp/g5pPyX2qyL94iGM49OW/mPyry3+9xXofdwX1HInfef6/8AAPWR0ooor1D4QKKKKACiiigAooooAKKKKACiiigAooooAKKKKAPHfjBohjurXWIk+WQeTMR69VP5ZH4CsL4aa+NG8TJbyvttb3Ebegf+E/nkfjXtXiDSIdd0S60+f7sqYBx90jkH8Dg1803lnPp19NaXKGOeFyrD0Iry8SnSqqqj7rJKsMwwE8DU3W3p0+4+qgQRmiuQ+H/ikeItDVZm/wBNtsRzZ43ccN+P8811+RjJr0oSU48yPi8RQnh6rpTWqAkAZNeY/EL4gixEmkaRJm7PyzTqf9V7D/a/l9aPiD8QRYiTSNIk/wBLPyzTqf8AVew/2v5fWvHlWSaUKqtJI7YAAyWJ/ma4cVire5Dc+oyLIlUtisUrRWy7+b8gVZJpQqhpJHbAAGSxP8zV3x/4D8QaD4TtdWcbrd2xdxRjJgz90se49T0Bx1zXr3gDwAmjRpqepxhtQYfIh5EAP/s3qfwHv388EVzA8E8SSQyKUeN1yrKRggjuKeFwvL789xZ5nzrN4fDO0Fu+/wDwD4U0rVb3RdTg1LTrh7e7t33xyL2P9R6jvX0X4S/aB0TULWKDxLHJpt6Bhp40LwufXjLL9MEe9Zfjb9nxbieS+8JXCQ7iWawuGIUf7j9vo35143q3gbxTocjLqGgX8QXq4hLp/wB9rlf1rvPkj6yX4m+CHi8weJ9N2+hmwfyPNcf4p+PvhrSrd49DD6te9FIVo4VPqWIyfwHPqK+YhaXBfYIJS2cY2HNbmk+BPFWtyrHp/h+/kDcCRoSiD6u2FH50AUvEHiDUvFGtT6rqtwZrqY8noqr2VR2Ar1H4G/DqbVtXh8U6lCV06zfdaq6/6+UdGH+yp5z/AHsehre8E/s+LBLFfeLp0k2kMLC3bKn/AH37/Rfzr3W3t4bS3jt7eJIoI1CRxou1VUcAADoKAJqKKKACiiigBKxPFeuR6B4eur5iN6piNT/E54A/Pr7ZraJABPpXhHxM8UDW9YFhbOWs7NiMg8O/c/h0/P1rDEVVThfqeplGXyxuJUOi1focVma7uSfmkmlf6lmJ/wAa+k/CujLoPhyz08HLRpl29WPJP5k15L8LfDn9qa4dTnXNtYkFQRw0h6fl1+uK90HAxXPgadk6j6nscUY5TqRwsNo7+otFFFd58mFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFACV5d8U/CRuYf7dso8zRDFwij7yf3vqP5fSvUeaZJGsqFHGVIwQazq01Ui4s68DjJ4SvGtDofMvh3Xbrw7rEV/bc7flkjzw6nqP8+lejeLvifDJpMdtocjfaLiMGSXGDCD2/3v5VzvxB8Ev4fvDf2UZOmzN0X/AJYse30PY/h6Z4avIdSrQvTP0OGEwOauGM3a3X+foPVXmkCqGkkdsADksTXtXw/8AJo8aapqkYbUHGUQ8iAf1b1Pbp65pfC7wpp4s01yWWK5um4jVTkQe3+9/L+fqQrrwuGt+8lufP8AEGdubeEoaRWj8/L0F7cUUUV6B8iFFFFABRRRQAUUUUAFFFFACUUdB1rg/HPj+DQInsbBkm1FhgjORDx1Pv6ConNQXNI6MNhauJqKlSV2yt8SfGo0m0bSdPl/06ZcO6n/AFK/4nt+dePaXplzrGpQWFom6aVto9AO5PsBzURNzqF7n95cXM7+7M7E/qTXu3gDwWnhuwNzdKrajOP3hznYOyj+vv8AQV5iUsVUu/hR9xOVHIcHyR1qS/r7kdB4e0W30DRrfT7cfLGvzMRy7dyfxrVoor1UklZHwM5yqSc5O7YtFFFMkKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigCvd2kN7bSW1xEskUilWRhkEV4b42+H1z4elkvbBXn00/Me7Q+x9R7/n6n3mmSRpKhR1DKRgg1jWoRqxsz0stzOtgKnNB6dV3PmbQfEWo+HL0XNhNtz9+NuUkHoRXtvhfx/pXiNFiZha3p48iRhlv90965vxb8K4pvMvdBxFJyWtSfkb/dP8P06fSvKLuzutPuWt7uCS3nTqjqQfTP/wBevPUquGdnqj66dHL88hz03y1Px+fc+qc56UtfP+gfEnXNGKxzyfbrYY+SY/MB7N1/PNelaP8AE/w/qaYuJzYy5xtuPlB+jdMV208VTn1PmMbkWMwru48y7rU7alqtb3ttdxLLbzxyIejI4IP41YyD3roTPHaadmLRRRTEJRSFgOpH4msrU/Euj6OM32oQQnGQpYbjj0HU0m0tWXCnObtFXZrVBdXlvZQPPczJFEgyzu2AB715rrfxgtYkeLRrVp5OgmmG1B746n9K8y1nxFqniCfzdRu3lAOVjHCL9FHFclXGQhpHVnv4DhvFYh81VckfPf7j0Dxd8VTKJLLQMqudrXbDqP8AZB/mfy715nDBdalerFCklxdTvwBlmcnkn/69bHh3wdq3iWUfZIdlsDhriQYQfT1PsPxxXt3hjwZpnhi3HkR+ZdMMSXDj5m+noPYfrXNGnVxL5p6I9ytjcDktN0sOuaf9bv8AQxvA3w/h0CNb+/VZdSYcd1hHoPU+p/L372iivShCMFyxPicTiquKqOrVd2xaKKKs5wooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooASsvWPD+l67b+TqFnHMB0JGGX6Ecj8K1KKTSasyoTlCXNB2Z47rnwguYWMujXQmX/njPwR9GHB/IVwOpaDqujsVv7CeDH8TLlf++hx+tfUFNeNXGGUH6iuOpgqctVofR4TifF0Vy1Eprz3PlSC6uLV99vPLC3rG5U/pW3beOPE1pxFrFx/wPD/APoQNe53/gvw9qRZrnSrdnY5Louxj+Iwawrj4TeHJv8AVJcQf7kxP881j9UrR+GR6i4iy6uv39HX0TPN1+JniteuoqfrCn+FMl+I/iuUn/ialR6LCn/xNd8fg3pHbUL7/vpP/iafH8HdFQ5e8vn9i6D+S0ewxP8AMH9qZGtVS/8AJUeUXXiXXL0n7Rq14wPUCUgfkOKzVV5pNqhnkc9ByWNe/Wvwx8L2xDNYtKw/56SsR+WcV0NjommaauLKwt4Bjny4wufyoWCqS+OQpcTYSirYal+SPBtJ+HviLV9rLZG2iP8Ay0uTs/Tr+lekeH/hVpOnbJtSJv7gc7XGIwf93v8AjXoGABwKWumnhKcNdzw8bxBjMUuW/KuyI44khQJGgVVGAAMYFS0UV1Hht33CiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//2Q==\"}]}"},{"id":44364,"title":"Is this a valid Tic Tac Toe State?","description":"For the game of \u003chttps://en.wikipedia.org/wiki/Tic-tac-toe Tic Tac Toe\u003e we will be storing the state of the game in a matrix M.\r\n\r\nFor this game: \r\n\r\n\u003c\u003chttps://upload.wikimedia.org/wikipedia/commons/3/32/Tic_tac_toe.svg\u003e\u003e\r\n\r\nWe would store the state as this:\r\n\r\n  -1  1  1 \r\n   1 -1 -1\r\n   1 -1 -1\r\n\r\nIf there were any blanks squares, they would be 0;\r\n\r\nFor this challenge, X goes first. Neither side is compelled to take a win if possible. The game stops when either player wins.\r\n\r\nFor this challenge, is the the given board state\r\n 0: legal \r\n 1: this state can not occur in a game\r\n\r\nThe example in the image would return 0 because if X goes first there can never be more O than X. The state matrix will only hold [-1 0 1], so we are only checking for logic of the game.","description_html":"\u003cp\u003eFor the game of \u003ca href = \"https://en.wikipedia.org/wiki/Tic-tac-toe\"\u003eTic Tac Toe\u003c/a\u003e we will be storing the state of the game in a matrix M.\u003c/p\u003e\u003cp\u003eFor this game:\u003c/p\u003e\u003cimg src = \"https://upload.wikimedia.org/wikipedia/commons/3/32/Tic_tac_toe.svg\"\u003e\u003cp\u003eWe would store the state as this:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e-1  1  1 \r\n 1 -1 -1\r\n 1 -1 -1\r\n\u003c/pre\u003e\u003cp\u003eIf there were any blanks squares, they would be 0;\u003c/p\u003e\u003cp\u003eFor this challenge, X goes first. Neither side is compelled to take a win if possible. The game stops when either player wins.\u003c/p\u003e\u003cp\u003eFor this challenge, is the the given board state\r\n 0: legal \r\n 1: this state can not occur in a game\u003c/p\u003e\u003cp\u003eThe example in the image would return 0 because if X goes first there can never be more O than X. The state matrix will only hold [-1 0 1], so we are only checking for logic of the game.\u003c/p\u003e","function_template":"function y = isLegalTicTacToeState(M)\r\n  y = round(rand);\r\nend","test_suite":"%%\r\nx = [1 1 0\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [0 0 0\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 1;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [  -1  1  1 \r\n        1 -1 -1\r\n        1 -1 -1];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [ 0 -1 1\r\n     -1  1 0\r\n      1  0 0];\r\ny_correct = 1;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [ 1  1  1\r\n     -1 -1 -1\r\n      0  0  0];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [-1 1 1\r\n     0 -1 1\r\n     1 0 -1];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [-1 1 0\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 1;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [-1 0 0\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [-1 1 0\r\n     0 1 0\r\n     0 1 0];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [1  1  1\r\n     -1 1 -1\r\n     -1 1 -1];\r\ny_correct = 1;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":6,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":123,"test_suite_updated_at":"2017-10-20T22:46:06.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-09T23:21:35.000Z","updated_at":"2026-02-03T09:11:08.000Z","published_at":"2017-10-20T22:46: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\u003eFor the game 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=\\\"https://en.wikipedia.org/wiki/Tic-tac-toe\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eTic Tac Toe\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e we will be storing the state of the game in a matrix M.\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 this game:\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\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\u003eWe would store the state as this:\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[-1  1  1 \\n 1 -1 -1\\n 1 -1 -1]]\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\u003eIf there were any blanks squares, they would be 0;\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 this challenge, X goes first. Neither side is compelled to take a win if possible. The game stops when either player wins.\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 this challenge, is the the given board state 0: legal 1: this state can not occur in a game\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 example in the image would return 0 because if X goes first there can never be more O than X. The state matrix will only hold [-1 0 1], so we are only checking for logic of the game.\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":44365,"title":"An asteroid and a spacecraft","description":"\r\n\u0026#128640 Imagine a non-relativistic simple situation. \r\n\r\nAssume positions p0, p1, p2, and p3 are three dimensional Cartesian coordinates.\r\n\r\nYour spacecraft started from the position p0 at time t0. \r\n\r\nYour spacecraft is moving with a constant velocity.\r\n\r\nYour spacecraft is expected to reach a star at the location p1 at time t1.\r\n\r\nYou just heard over the radio that an asteroid has been identified at the location p2 at time t0.\r\n\r\nThe asteroid is moving with a constant velocity.\r\n\r\nThe asteroid is expected to reach another star at the location p3 at time t1. \r\n\r\nYou need to write a code 'safetrip' in MATLAB to return true if the minimum distance between your spacecraft and the asteroid will be more than the distance d during the time interval between t0 and t1, otherwise return false.","description_html":"\u003cp\u003e\u0026#128640 Imagine a non-relativistic simple situation.\u003c/p\u003e\u003cp\u003eAssume positions p0, p1, p2, and p3 are three dimensional Cartesian coordinates.\u003c/p\u003e\u003cp\u003eYour spacecraft started from the position p0 at time t0.\u003c/p\u003e\u003cp\u003eYour spacecraft is moving with a constant velocity.\u003c/p\u003e\u003cp\u003eYour spacecraft is expected to reach a star at the location p1 at time t1.\u003c/p\u003e\u003cp\u003eYou just heard over the radio that an asteroid has been identified at the location p2 at time t0.\u003c/p\u003e\u003cp\u003eThe asteroid is moving with a constant velocity.\u003c/p\u003e\u003cp\u003eThe asteroid is expected to reach another star at the location p3 at time t1.\u003c/p\u003e\u003cp\u003eYou need to write a code 'safetrip' in MATLAB to return true if the minimum distance between your spacecraft and the asteroid will be more than the distance d during the time interval between t0 and t1, otherwise return false.\u003c/p\u003e","function_template":"function ok = safetrip(d, t0, t1, p0, p1, p2, p3)\r\n    if d\u003e1000000000\r\n        ok = true;\r\n    end\r\nend","test_suite":"%%\r\np0 = [0 0 0];\r\np1 = [1 1 1];\r\np2 = [2 2 2];\r\np3 = [3 3 3];\r\nt0 = 0; \r\nt1 = 1;\r\nd = 1;\r\nok = true;\r\nassert(isequal(safetrip(d, t0, t1, p0, p1, p2, p3), ok))\r\n\r\n%%\r\np0 = [3 3 3];\r\np1 = [2 2 2];\r\np2 = [2 2 2];\r\np3 = [3 3 3];\r\nt0 = 0; \r\nt1 = 1;\r\nd = 1;\r\nok = false;\r\nassert(isequal(safetrip(d, t0, t1, p0, p1, p2, p3), ok))\r\n\r\n%%\r\np0 = [1 2 3];\r\np1 = [4 5 6];\r\np2 = [3 2 1];\r\np3 = [6 5 4];\r\nt0 = 10; \r\nt1 = 20;\r\nd = 2;\r\nok = true;\r\nassert(isequal(safetrip(d, t0, t1, p0, p1, p2, p3), ok))\r\n\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":8,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":168,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-10T02:30:44.000Z","updated_at":"2026-03-26T15:11:20.000Z","published_at":"2017-10-16T01:51:00.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003e\u0026amp;#128640 Imagine a non-relativistic simple situation.\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\u003eAssume positions p0, p1, p2, and p3 are three dimensional Cartesian coordinates.\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\u003eYour spacecraft started from the position p0 at time t0.\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\u003eYour spacecraft is moving with a constant velocity.\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\u003eYour spacecraft is expected to reach a star at the location p1 at time t1.\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\u003eYou just heard over the radio that an asteroid has been identified at the location p2 at time t0.\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\u003eThe asteroid is moving with a constant velocity.\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\u003eThe asteroid is expected to reach another star at the location p3 at time t1.\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\u003eYou need to write a code 'safetrip' in MATLAB to return true if the minimum distance between your spacecraft and the asteroid will be more than the distance d during the time interval between t0 and t1, otherwise return false.\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":44311,"title":"Number of Even Elements in Fibonacci Sequence","description":"Find how many even Fibonacci numbers are available in the first d numbers.\r\n\r\nConsider the following first 14 numbers\r\n\r\n  1 1 2 3 5 8 13 21 34 55 89 144 233 377 ...\r\n\r\n4 of them are even. ","description_html":"\u003cp\u003eFind how many even Fibonacci numbers are available in the first d numbers.\u003c/p\u003e\u003cp\u003eConsider the following first 14 numbers\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e1 1 2 3 5 8 13 21 34 55 89 144 233 377 ...\r\n\u003c/pre\u003e\u003cp\u003e4 of them are even.\u003c/p\u003e","function_template":"function y = evenFibo(d)\r\n  y = x;\r\nend","test_suite":"%%\r\nd = 14;\r\ny_correct = 4;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 20;\r\ny_correct = 6;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 50;\r\ny_correct = 16;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 100;\r\ny_correct = 33;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 150;\r\ny_correct = 50;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 200;\r\ny_correct = 66;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 500;\r\ny_correct = 166;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 1000;\r\ny_correct = 333;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 1e4;\r\ny_correct = 3333;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 2e4;\r\ny_correct = 6666;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 3e5;\r\ny_correct = 1e5;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 6e6;\r\ny_correct = 2e6;\r\nassert(isequal(evenFibo(d),y_correct))\r\n% \r\n% %%\r\n% d = 9223372036854775807;\r\n% y_correct = 3074457345618258432;\r\n% assert(isequal(evenFibo(d),y_correct))\r\n","published":true,"deleted":false,"likes_count":21,"comments_count":9,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1641,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-11T12:36:15.000Z","updated_at":"2026-04-08T12:45:53.000Z","published_at":"2017-10-16T01:50:58.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\u003eFind how many even Fibonacci numbers are available in the first d numbers.\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\u003eConsider the following first 14 numbers\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[1 1 2 3 5 8 13 21 34 55 89 144 233 377 ...]]\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\u003e4 of them are even.\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":281,"title":"Acid and water","description":"\u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878;\r\n\r\nAssume that there is a 100 liter tank. \r\n\r\nIt is initially filled with just distilled water. \r\n\r\nIt is continuously drained at R liters per minute. \r\n\r\nThis tank is always maintained full and homogeneous by continuously adding and stirring R liters per minute of an unknown acid (or some fancy oil if it helps you solving this problem). \r\n\r\nHow many liters W of water will be in the tank after M minutes?\r\n\r\nNeglect any expansion or contraction when the acid is mixed with water. ","description_html":"\u003cp\u003e\u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878;\u003c/p\u003e\u003cp\u003eAssume that there is a 100 liter tank.\u003c/p\u003e\u003cp\u003eIt is initially filled with just distilled water.\u003c/p\u003e\u003cp\u003eIt is continuously drained at R liters per minute.\u003c/p\u003e\u003cp\u003eThis tank is always maintained full and homogeneous by continuously adding and stirring R liters per minute of an unknown acid (or some fancy oil if it helps you solving this problem).\u003c/p\u003e\u003cp\u003eHow many liters W of water will be in the tank after M minutes?\u003c/p\u003e\u003cp\u003eNeglect any expansion or contraction when the acid is mixed with water.\u003c/p\u003e","function_template":"function W = tank(R,M)\r\n  W = 100 * R * M;\r\nend","test_suite":"%%\r\nR=1; \r\nM=1;\r\nW=99;\r\nassert(tank(R,M)\u003eW)\r\n%%\r\nR=2; \r\nM=2;\r\nW=96;\r\nassert(tank(R,M)\u003eW)\r\n%%\r\nR=10; \r\nM=10;\r\nW=36;\r\nassert(tank(R,M)\u003eW)\r\n%%\r\nR=15; \r\nM=20;\r\nW=5;\r\nassert(tank(R,M)\u003cW)\r\n%%\r\nR=7; \r\nM=8;\r\nW=58;\r\nassert(tank(R,M)\u003cW)\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":13,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":261,"test_suite_updated_at":"2012-02-07T16:08:37.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2012-02-07T16:08:37.000Z","updated_at":"2026-03-26T15:49:26.000Z","published_at":"2017-10-16T01:50:58.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003e\u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878;\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\u003eAssume that there is a 100 liter tank.\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\u003eIt is initially filled with just distilled water.\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\u003eIt is continuously drained at R liters per minute.\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\u003eThis tank is always maintained full and homogeneous by continuously adding and stirring R liters per minute of an unknown acid (or some fancy oil if it helps you solving this 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHow many liters W of water will be in the tank after M minutes?\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\u003eNeglect any expansion or contraction when the acid is mixed with water.\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":44372,"title":"Polarisation","description":"You have n polarising filters stacked one on top of another, and you know each axis angle. How much light gets passed through the filter bank? For more information, see \u003chttps://en.wikipedia.org/wiki/Polarizer Polarizer (Wikipedia)\u003e.\r\n\r\n    \u003e\u003e n = [0, 90];\r\n    \u003e\u003e polarised([0, 90])\r\n\r\n    ans = 0","description_html":"\u003cp\u003eYou have n polarising filters stacked one on top of another, and you know each axis angle. How much light gets passed through the filter bank? For more information, see \u003ca href = \"https://en.wikipedia.org/wiki/Polarizer\"\u003ePolarizer (Wikipedia)\u003c/a\u003e.\u003c/p\u003e\u003cpre\u003e    \u0026gt;\u0026gt; n = [0, 90];\r\n    \u0026gt;\u0026gt; polarised([0, 90])\u003c/pre\u003e\u003cpre\u003e    ans = 0\u003c/pre\u003e","function_template":"function y = polarised(x)\r\n  y = max(x);\r\nend","test_suite":"%%\r\nx = 5;\r\ny_correct = 0.5;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\nx = 180;\r\ny_correct = 0.5;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\nx = 365;\r\ny_correct = 0.5;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\nx = [91, 1];\r\ny_correct = 0;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\na = randi([-360, 360]);\r\nb = 90*(1+2*randi([-3, 3]));\r\nx = [a, a+b];\r\ny_correct = 0;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\na = randi([-360, 360]);\r\nb = 90*(1+2*randi([-3, 3]));\r\nx = [a, a+b];\r\ny_correct = 0;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\nx = [0, 22.5];\r\ny_correct = 0.85355339059/2;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\nx = [0, -45];\r\ny_correct = 0.25;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\nx = [5, 140];\r\ny_correct = 0.25;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\nx = 5 + (1:5)*22.5;\r\ny_correct = 0.53079004294/2;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":10,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":270,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-10T21:58:52.000Z","updated_at":"2026-04-07T15:12:18.000Z","published_at":"2017-10-16T01:45: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\u003eYou have n polarising filters stacked one on top of another, and you know each axis angle. How much light gets passed through the filter bank? For more information, see\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/Polarizer\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePolarizer (Wikipedia)\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\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    \u003e\u003e n = [0, 90];\\n    \u003e\u003e polarised([0, 90])\\n\\n    ans = 0]]\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":44310,"title":"Digit concentration in Champernowne's constant","description":"Consider the first 50 digits of Champernowne's constant\r\n \r\n    0.12345678910111213141516171819202122232425262728293...\r\n  \r\nThere are two zeros (do not count the left side of \".\" (integer part) ) in this series. So the digit concentration for 0 for the first 50 digits is = 2 / 50 = 0.04.\r\n\r\nAlso the number of '2' (x) digit is counted as 13. So the digit concentration of number '2' for the first 50 (d) digit is = 13/50 = 0.26\r\n\r\nCalculate the digit concentration of number x for the first d digit of constant.\r\n","description_html":"\u003cp\u003eConsider the first 50 digits of Champernowne's constant\u003c/p\u003e\u003cpre\u003e    0.12345678910111213141516171819202122232425262728293...\u003c/pre\u003e\u003cp\u003eThere are two zeros (do not count the left side of \".\" (integer part) ) in this series. So the digit concentration for 0 for the first 50 digits is = 2 / 50 = 0.04.\u003c/p\u003e\u003cp\u003eAlso the number of '2' (x) digit is counted as 13. So the digit concentration of number '2' for the first 50 (d) digit is = 13/50 = 0.26\u003c/p\u003e\u003cp\u003eCalculate the digit concentration of number x for the first d digit of constant.\u003c/p\u003e","function_template":"function concentration = digitCon(d,x)\r\n  y = x;\r\nend","test_suite":"%%\r\nd = 1;\r\nx = 1;\r\ny_correct = 1;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 10;\r\nx = 5;\r\ny_correct = 0.1000;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 10;\r\nx = 1;\r\ny_correct = 0.2000;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 20;\r\nx = 9;\r\ny_correct = 0.0500;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n\r\n%%\r\nd = 50;\r\nx = 0;\r\ny_correct = 0.0400;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 50;\r\nx = 2;\r\ny_correct = 0.2600;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1000;\r\nx = 9;\r\ny_correct = 0.0670;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1e4;\r\nx = 8;\r\ny_correct = 0.0747;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1e5;\r\nx = 7;\r\ny_correct = 0.0864;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1e6;\r\nx = 6;\r\ny_correct = 0.0935;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1e6;\r\nx = 5;\r\ny_correct = 0.0937;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 2e6;\r\nx = 4;\r\ny_correct = 0.0903;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 2000124;\r\nx = 3;\r\ny_correct = 0.1162;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)","published":true,"deleted":false,"likes_count":5,"comments_count":1,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":125,"test_suite_updated_at":"2017-10-25T07:12:47.000Z","rescore_all_solutions":true,"group_id":35,"created_at":"2017-09-11T10:35:46.000Z","updated_at":"2026-02-03T09:31:30.000Z","published_at":"2017-10-16T01:50:58.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\u003eConsider the first 50 digits of Champernowne's constant\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[    0.12345678910111213141516171819202122232425262728293...]]\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\u003eThere are two zeros (do not count the left side of \\\".\\\" (integer part) ) in this series. So the digit concentration for 0 for the first 50 digits is = 2 / 50 = 0.04.\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\u003eAlso the number of '2' (x) digit is counted as 13. So the digit concentration of number '2' for the first 50 (d) digit is = 13/50 = 0.26\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\u003eCalculate the digit concentration of number x for the first d digit of constant.\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":44344,"title":"The 5th Root","description":"Write a function to find the 5th root of a number.\r\n\r\nIt sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method to solve the problem.","description_html":"\u003cp\u003eWrite a function to find the 5th root of a number.\u003c/p\u003e\u003cp\u003eIt sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method to solve the problem.\u003c/p\u003e","function_template":"function f = fifth_root(n)\r\n f = n^(1/5)\r\nend","test_suite":"%%\r\nfiletext = fileread('fifth_root.m');\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'power')),'power() forbidden')\r\nassert(isempty(strfind(filetext, 'mpower')),'mpower() forbidden')\r\nassert(isempty(strfind(filetext, 'realpow')),'realpow() forbidden')\r\nassert(isempty(strfind(filetext, 'nthroot')),'nthroot() forbidden')\r\nassert(isempty(strfind(filetext, 'roots')),'roots() forbidden')\r\n\r\n%%\r\nn = 1/9765625;\r\nassert(abs(fifth_root(n)-1/25)\u003c1e-5)\r\n\r\n%%\r\nn = 1/5555;\r\nassert(abs(fifth_root(n)-0.178263811215444)\u003c1e-5)\r\n\r\n%%\r\nn = 1/3125;\r\nassert(abs(fifth_root(n)-1/5)\u003c1e-5)\r\n\r\n%%\r\nn = 1/125;\r\nassert(abs(fifth_root(n)-0.380730787743176)\u003c1e-5)\r\n\r\n%%\r\nn = 1/5;\r\nassert(abs(fifth_root(n)-0.724779663677696)\u003c1e-5)\r\n\r\n%%\r\nn = 1;\r\nassert(abs(fifth_root(n)-1)\u003c1e-5)\r\n\r\n%%\r\nn = 5;\r\nassert(abs(fifth_root(n)-1.37972966146121)\u003c1e-5)\r\n\r\n%%\r\nn = 25;\r\nassert(abs(fifth_root(n)-1.90365393871588)\u003c1e-5)\r\n\r\n%%\r\nn = 50;\r\nassert(abs(fifth_root(n)-2.18672414788656)\u003c1e-5)\r\n\r\n%%\r\nn = 500;\r\nassert(abs(fifth_root(n)-3.46572421577573)\u003c1e-5)\r\n\r\n%%\r\nn = 3125;\r\nassert(abs(fifth_root(n)-5)\u003c1e-5)\r\n\r\n%%\r\nn = 759375;\r\nassert(abs(fifth_root(n)-15)\u003c1e-5)\r\n\r\n%%\r\nn = 9765625;\r\nassert(abs(fifth_root(n)-25)\u003c1e-5)\r\n\r\n%%\r\nn = 312500000;\r\nassert(abs(fifth_root(n)-50)\u003c1e-5)\r\n\r\n%%\r\nn = 75937500000;\r\nassert(abs(fifth_root(n)-150)\u003c1e-5)\r\n\r\n%%\r\nn = 31250000000000;\r\nassert(abs(fifth_root(n)-500)\u003c1e-5)\r\n\r\n%%\r\nn = 52658067346875;\r\nassert(abs(fifth_root(n)-555)\u003c1e-5)","published":true,"deleted":false,"likes_count":13,"comments_count":3,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":559,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-22T16:03:40.000Z","updated_at":"2026-02-03T09:23:18.000Z","published_at":"2017-10-16T01:50:59.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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 find the 5th root of a 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIt sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method to solve the problem.\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":44337,"title":"Sums of Distinct Powers","description":"You will be given three numbers: base, nstart, and nend.  Write a MATLAB script that will compute the sum of a sequence of both the distinct powers of base as well as sums of distinct powers of base.  Your sequence should start with the 'nstart'th term and end with the 'nend'th term.  For example:\r\n\r\n* base=4\r\n* nstart=2\r\n* nend=6\r\n\r\nThe first several sums of the distinct powers of 4 are:\r\n\r\n* 1 (4^0)\r\n* 4 (4^1)\r\n* 5 (4^1 + 4^0)\r\n* 16 (4^2)\r\n* 17 (4^2 + 4^0)\r\n* 20 (4^2 + 4^1)\r\n* 21 (4^2 + 4^1 + 4^0)\r\n* 64 (4^3)\r\n* 65 (4^3 + 4^0)\r\n\r\nSince nstart=2 and nend=6 in this example, you take the second through the sixth terms of this sequence.  The correct output would be 4+5+16+17+20, or 62.  Notice that the number 8 does not occur in this pattern.  While 8 is a multiple of 4, 8=4^1+4^1.  Because there are two 4^1 terms in the sum, 8 does not qualify as a sum of *distinct* powers of 4.  You can assume that all three will be integers, base\u003e1, and that nstart\u003cnend.  Good luck!","description_html":"\u003cp\u003eYou will be given three numbers: base, nstart, and nend.  Write a MATLAB script that will compute the sum of a sequence of both the distinct powers of base as well as sums of distinct powers of base.  Your sequence should start with the 'nstart'th term and end with the 'nend'th term.  For example:\u003c/p\u003e\u003cul\u003e\u003cli\u003ebase=4\u003c/li\u003e\u003cli\u003enstart=2\u003c/li\u003e\u003cli\u003enend=6\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe first several sums of the distinct powers of 4 are:\u003c/p\u003e\u003cul\u003e\u003cli\u003e1 (4^0)\u003c/li\u003e\u003cli\u003e4 (4^1)\u003c/li\u003e\u003cli\u003e5 (4^1 + 4^0)\u003c/li\u003e\u003cli\u003e16 (4^2)\u003c/li\u003e\u003cli\u003e17 (4^2 + 4^0)\u003c/li\u003e\u003cli\u003e20 (4^2 + 4^1)\u003c/li\u003e\u003cli\u003e21 (4^2 + 4^1 + 4^0)\u003c/li\u003e\u003cli\u003e64 (4^3)\u003c/li\u003e\u003cli\u003e65 (4^3 + 4^0)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eSince nstart=2 and nend=6 in this example, you take the second through the sixth terms of this sequence.  The correct output would be 4+5+16+17+20, or 62.  Notice that the number 8 does not occur in this pattern.  While 8 is a multiple of 4, 8=4^1+4^1.  Because there are two 4^1 terms in the sum, 8 does not qualify as a sum of \u003cb\u003edistinct\u003c/b\u003e powers of 4.  You can assume that all three will be integers, base\u0026gt;1, and that nstart\u0026lt;nend.  Good luck!\u003c/p\u003e","function_template":"function y = sum_distinct_powers(base,nstart,nend)\r\n  y = base*nstart*nend;\r\nend","test_suite":"%%\r\nbase=4;nstart=2;nend=6;y_correct=62;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=5;nstart=1;nend=1000;y_correct=1193853250;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=3;nstart=1;nend=1000;y_correct=14438162;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=3;nstart=100;nend=1000;y_correct=14397354;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=2;nstart=1;nend=2017;y_correct=2035153;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=7;nstart=1234;nend=2345;y_correct=843569026324;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=7;nstart=1;nend=10;y_correct=1265;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nnstart=1;nend=50;\r\njunk=arrayfun(@(base) sum_distinct_powers(base,nstart,nend),2:10);\r\ny_correct=[1275 7120 26365 75000 178591 374560 714465 1266280 2116675];\r\nassert(isequal(junk,y_correct))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":9,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":156,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-18T16:30:15.000Z","updated_at":"2026-02-03T09:26:51.000Z","published_at":"2017-10-16T01:50:59.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\u003eYou will be given three numbers: base, nstart, and nend. Write a MATLAB script that will compute the sum of a sequence of both the distinct powers of base as well as sums of distinct powers of base. Your sequence should start with the 'nstart'th term and end with the 'nend'th term. For example:\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\u003ebase=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\u003enstart=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\u003enend=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\u003eThe first several sums of the distinct powers of 4 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=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1 (4^0)\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\u003e4 (4^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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e5 (4^1 + 4^0)\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\u003e16 (4^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\u003e17 (4^2 + 4^0)\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\u003e20 (4^2 + 4^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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e21 (4^2 + 4^1 + 4^0)\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 (4^3)\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\u003e65 (4^3 + 4^0)\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 nstart=2 and nend=6 in this example, you take the second through the sixth terms of this sequence. The correct output would be 4+5+16+17+20, or 62. Notice that the number 8 does not occur in this pattern. While 8 is a multiple of 4, 8=4^1+4^1. Because there are two 4^1 terms in the sum, 8 does not qualify as a sum of\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\u003edistinct\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e powers of 4. You can assume that all three will be integers, base\u0026gt;1, and that nstart\u0026lt;nend. Good luck!\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":44367,"title":"Inscribed Pentagon? 2","description":"Your function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon may or may not be centered on the circle. The function should return one of the following values:\r\n\r\n -1: the pentagon is not centered on the circle (within 5% of r)^\r\n  0: the pentagon is completely enclosed within the circle but is not inscribed\r\n  1: the pentagon is inscribed in the circle (within ±0.02)\r\n  2: the vertices of the pentagon extend beyond the circle\r\n\r\nPoints will be rounded to the nearest hundredth. See the test cases for examples. (There will not be a case where some vertices are within the circle and others without.)\r\n\r\n^ Due to the asymmetric nature of the pentagon, its centroid does not coincide with center of its inscribing circle, hence the ±5% tolerance window. ","description_html":"\u003cp\u003eYour function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon may or may not be centered on the circle. The function should return one of the following values:\u003c/p\u003e\u003cpre\u003e -1: the pentagon is not centered on the circle (within 5% of r)^\r\n  0: the pentagon is completely enclosed within the circle but is not inscribed\r\n  1: the pentagon is inscribed in the circle (within ±0.02)\r\n  2: the vertices of the pentagon extend beyond the circle\u003c/pre\u003e\u003cp\u003ePoints will be rounded to the nearest hundredth. See the test cases for examples. (There will not be a case where some vertices are within the circle and others without.)\u003c/p\u003e\u003cp\u003e^ Due to the asymmetric nature of the pentagon, its centroid does not coincide with center of its inscribing circle, hence the ±5% tolerance window.\u003c/p\u003e","function_template":"function y = inscribed_pentagon2(p,cp,r)\r\n y = -1;\r\nend","test_suite":"%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,6.58; 6.42,1.92; 3.97,-5.63; -3.97,-5.63; -6.42,1.92];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,4.55; 4.28,1.44; 2.65,-3.59; -2.65,-3.59; -4.28,1.44];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0.5];\r\nr = 8.75;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [1.98,-0.47];\r\nr = 8.75;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,6.58; 6.42,1.92; 3.97,-5.63; -3.97,-5.63; -6.42,1.92] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,4.55; 4.28,1.44; 2.65,-3.59; -2.65,-3.59; -4.28,1.44] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp_temp = [20,8];\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55] + repmat(cp_temp,[5,1]);\r\ncp = [19.5,9.08];\r\nr = 2.5;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp_temp = [20,8];\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55] + repmat(cp_temp,[5,1]);\r\ncp = [19.86,7.19];\r\nr = 7.5;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [25.01,12.47; 25.98,4.58; 18.78,1.23; 13.37,7.03; 17.22,13.97];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.27,11.12; 23.92,5.87; 19.12,3.63; 15.52,7.50; 18.08,12.13];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [32.54,38.78; 38.84,26.41; 29.02,16.59; 16.65,22.89; 18.83,36.61];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.49,35.54; 34.69,27.29; 28.14,20.74; 19.89,24.95; 21.34,34.09];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [26.41,29.04];\r\nr = 6.13;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [27.07,27.66];\r\nr = 9.63;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))","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":88,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-10T15:28:54.000Z","updated_at":"2026-04-02T01:39:53.000Z","published_at":"2017-10-16T01:51:00.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\u003eYour function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon may or may not be centered on the circle. The function should return one of the following values:\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[ -1: the pentagon is not centered on the circle (within 5% of r)^\\n  0: the pentagon is completely enclosed within the circle but is not inscribed\\n  1: the pentagon is inscribed in the circle (within ±0.02)\\n  2: the vertices of the pentagon extend beyond the circle]]\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\u003ePoints will be rounded to the nearest hundredth. See the test cases for examples. (There will not be a case where some vertices are within the circle and others without.)\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^ Due to the asymmetric nature of the pentagon, its centroid does not coincide with center of its inscribing circle, hence the ±5% tolerance window.\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":44340,"title":"Recaman Sequence - III","description":"I want to create a Recaman sequence where there is a \"1\" in the n-th position. So from which integer should I start the Recaman sequence? If there are more than one starting integer that generates a sequence with a 1 in the n-th position, return the lowest one.\r\nFor example if I want to place the digit 1 in the 7th place in the sequence then I should start the sequence from six as follow;\r\nseq = [6 5 3 6 2 7 1 8 16]\r\nYou can also start the sequence with 12 and obtain a series where there is a 1 in 7th position;\r\nseq = [12 11 9 6 2 7 1]\r\nRelated Challenges :\r\nRecaman Sequence - I\r\nRecaman Sequence - II\r\nRecaman Sequence - III","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: 308.167px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 154.083px; transform-origin: 407px 154.083px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; 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 31.5px; text-align: left; transform-origin: 384px 31.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: 371.5px 8px; transform-origin: 371.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eI want to create a Recaman sequence where there is a \"1\" in the n-th position. So from which integer should I start the Recaman sequence? If there are more than one starting integer that generates a sequence with a 1 in the n-th position, return the lowest one.\u003c/span\u003e\u003c/span\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: 368.5px 8px; transform-origin: 368.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example if I want to place the digit 1 in the 7th place in the sequence then I should start the sequence from six as follow;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 104px 8.5px; tab-size: 4; transform-origin: 104px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eseq = [6 5 3 6 2 7 1 8 16]\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; 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: 294.5px 8px; transform-origin: 294.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou can also start the sequence with 12 and obtain a series where there is a 1 in 7th position;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 92px 8.5px; tab-size: 4; transform-origin: 92px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eseq = [12 11 9 6 2 7 1]\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; 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: 72.5px 8px; transform-origin: 72.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eRelated Challenges :\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 61.3px; 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; 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\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/44338\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eRecaman Sequence - I\u003c/span\u003e\u003c/span\u003e\u003c/a\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\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/44339\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eRecaman Sequence - II\u003c/span\u003e\u003c/span\u003e\u003c/a\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: 75px 8px; transform-origin: 75px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eRecaman Sequence - III\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function startPoint = RecamanIII(onesplace)\r\n\r\nend","test_suite":"%%\r\nfiletext = fileread('RecamanIII.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'str2num'); \r\nassert(~illegal)\r\n\r\n%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 2;\r\ny_correct = 0;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 3;\r\ny_correct = 4;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 9;\r\ny_correct = 13;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 13;\r\ny_correct = 15;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 15;\r\ny_correct = 26;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 26;\r\ny_correct = 54;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 54;\r\ny_correct = 208;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 208;\r\ny_correct = 2485;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":12,"created_by":8703,"edited_by":223089,"edited_at":"2022-10-11T07:22:46.000Z","deleted_by":null,"deleted_at":null,"solvers_count":89,"test_suite_updated_at":"2022-10-11T07:22:46.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-19T07:36:19.000Z","updated_at":"2026-03-22T11:36:50.000Z","published_at":"2017-10-16T01:50:59.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\u003eI want to create a Recaman sequence where there is a \\\"1\\\" in the n-th position. So from which integer should I start the Recaman sequence? If there are more than one starting integer that generates a sequence with a 1 in the n-th position, return the lowest one.\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\u003eFor example if I want to place the digit 1 in the 7th place in the sequence then I should start the sequence from six as follow;\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[seq = [6 5 3 6 2 7 1 8 16]]]\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou can also start the sequence with 12 and obtain a series where there is a 1 in 7th position;\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[seq = [12 11 9 6 2 7 1]]]\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRelated Challenges :\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:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44338\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - I\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=\\\"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:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44339\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - II\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=\\\"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\u003eRecaman Sequence - III\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":44359,"title":"5th Time's a Charm","description":"Write a function that will return the input value. However, your function must fail the first four times, only functioning properly every fifth time. Furthermore, the first four times the function is called, successively closer, but not correct, values must be supplied by the function.\r\n\r\nFor example, if x = 10, you may return any number not equal to 10 the first function call. Here, we will return 27. Then, the second function call must return a value between 27 and 10, but not equal to either, and so on, until 10 is returned the fifth time.","description_html":"\u003cp\u003eWrite a function that will return the input value. However, your function must fail the first four times, only functioning properly every fifth time. Furthermore, the first four times the function is called, successively closer, but not correct, values must be supplied by the function.\u003c/p\u003e\u003cp\u003eFor example, if x = 10, you may return any number not equal to 10 the first function call. Here, we will return 27. Then, the second function call must return a value between 27 and 10, but not equal to either, and so on, until 10 is returned the fifth time.\u003c/p\u003e","function_template":"function y = fifth_times_a_charm(x)\r\n y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny1 = fifth_times_a_charm(x);\r\nassert(~isequal(y1,x))\r\n\r\ny2 = fifth_times_a_charm(x);\r\nassert(~isequal(y2,x))\r\nassert(abs(x-y2)\u003cabs(x-y1))\r\n\r\ny3 = fifth_times_a_charm(x);\r\nassert(~isequal(y3,x))\r\nassert(abs(x-y3)\u003cabs(x-y2))\r\n\r\ny4 = fifth_times_a_charm(x);\r\nassert(~isequal(y4,x))\r\nassert(abs(x-y4)\u003cabs(x-y3))\r\n\r\ny5 = fifth_times_a_charm(x);\r\nassert(isequal(y5,x))\r\n\r\n%%\r\nx = -1;\r\ny1 = fifth_times_a_charm(x);\r\nassert(~isequal(y1,x))\r\n\r\ny2 = fifth_times_a_charm(x);\r\nassert(~isequal(y2,x))\r\nassert(abs(x-y2)\u003cabs(x-y1))\r\n\r\ny3 = fifth_times_a_charm(x);\r\nassert(~isequal(y3,x))\r\nassert(abs(x-y3)\u003cabs(x-y2))\r\n\r\ny4 = fifth_times_a_charm(x);\r\nassert(~isequal(y4,x))\r\nassert(abs(x-y4)\u003cabs(x-y3))\r\n\r\ny5 = fifth_times_a_charm(x);\r\nassert(isequal(y5,x))\r\n\r\n%%\r\nx = 42;\r\ny1 = fifth_times_a_charm(x);\r\nassert(~isequal(y1,x))\r\n\r\ny2 = fifth_times_a_charm(x);\r\nassert(~isequal(y2,x))\r\nassert(abs(x-y2)\u003cabs(x-y1))\r\n\r\ny3 = fifth_times_a_charm(x);\r\nassert(~isequal(y3,x))\r\nassert(abs(x-y3)\u003cabs(x-y2))\r\n\r\ny4 = fifth_times_a_charm(x);\r\nassert(~isequal(y4,x))\r\nassert(abs(x-y4)\u003cabs(x-y3))\r\n\r\ny5 = fifth_times_a_charm(x);\r\nassert(isequal(y5,x))\r\n\r\n%%\r\nx = i;\r\ny1 = fifth_times_a_charm(x);\r\nassert(~isequal(y1,x))\r\n\r\ny2 = fifth_times_a_charm(x);\r\nassert(~isequal(y2,x))\r\nassert(abs(x-y2)\u003cabs(x-y1))\r\n\r\ny3 = fifth_times_a_charm(x);\r\nassert(~isequal(y3,x))\r\nassert(abs(x-y3)\u003cabs(x-y2))\r\n\r\ny4 = fifth_times_a_charm(x);\r\nassert(~isequal(y4,x))\r\nassert(abs(x-y4)\u003cabs(x-y3))\r\n\r\ny5 = fifth_times_a_charm(x);\r\nassert(isequal(y5,x))","published":true,"deleted":false,"likes_count":7,"comments_count":5,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":193,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-03T17:35:55.000Z","updated_at":"2026-03-13T03:06:49.000Z","published_at":"2017-10-16T01:51:00.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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 that will return the input value. However, your function must fail the first four times, only functioning properly every fifth time. Furthermore, the first four times the function is called, successively closer, but not correct, values must be supplied by the function.\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\u003eFor example, if x = 10, you may return any number not equal to 10 the first function call. Here, we will return 27. Then, the second function call must return a value between 27 and 10, but not equal to either, and so on, until 10 is returned the fifth time.\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":44350,"title":"Breaking Out of the Matrix","description":"Do you want to take the Red Pill, or the Blue Pill?\r\n\r\nIf you take the Blue Pill, you will simply pass along to the next problem, not knowing what Cody has in store for you.\r\n\r\nIf you take the Red Pill, you will be asked to write a MATLAB function that will Break a Matrix. The inputs to the function will be a matrix M, along with a number of rows (R) and columns (C). You goal is to break the larger 2-D matrix up into a 3-D matrix comprised of enough RxC matrices so that you can recreate the 2-D matrix. When creating your 3-D matrix, go down the columns first, and then across the rows.  Increment only one column (or one row) at a time.  Do not go C columns down at each step.\r\n\r\nFor example, R=2 and C=3, and M is as follows:\r\n\r\n M=[1 4 7 10\r\n    2 5 8 11\r\n    3 6 9 12]\r\n\r\nThis means that your output should be a 2x3x4 matrix:\r\n\r\n X(:,:,1) =\r\n     1     4     7\r\n     2     5     8\r\n X(:,:,2) =\r\n     2     5     8\r\n     3     6     9\r\n X(:,:,3) =\r\n     4     7    10\r\n     5     8    11\r\n X(:,:,4) =\r\n     5     8    11\r\n     6     9    12\r\n\r\nYou can assume that R and C will always be less than or equal to the appropriate dimension of the original matrix. Good luck!\r\n","description_html":"\u003cp\u003eDo you want to take the Red Pill, or the Blue Pill?\u003c/p\u003e\u003cp\u003eIf you take the Blue Pill, you will simply pass along to the next problem, not knowing what Cody has in store for you.\u003c/p\u003e\u003cp\u003eIf you take the Red Pill, you will be asked to write a MATLAB function that will Break a Matrix. The inputs to the function will be a matrix M, along with a number of rows (R) and columns (C). You goal is to break the larger 2-D matrix up into a 3-D matrix comprised of enough RxC matrices so that you can recreate the 2-D matrix. When creating your 3-D matrix, go down the columns first, and then across the rows.  Increment only one column (or one row) at a time.  Do not go C columns down at each step.\u003c/p\u003e\u003cp\u003eFor example, R=2 and C=3, and M is as follows:\u003c/p\u003e\u003cpre\u003e M=[1 4 7 10\r\n    2 5 8 11\r\n    3 6 9 12]\u003c/pre\u003e\u003cp\u003eThis means that your output should be a 2x3x4 matrix:\u003c/p\u003e\u003cpre\u003e X(:,:,1) =\r\n     1     4     7\r\n     2     5     8\r\n X(:,:,2) =\r\n     2     5     8\r\n     3     6     9\r\n X(:,:,3) =\r\n     4     7    10\r\n     5     8    11\r\n X(:,:,4) =\r\n     5     8    11\r\n     6     9    12\u003c/pre\u003e\u003cp\u003eYou can assume that R and C will always be less than or equal to the appropriate dimension of the original matrix. Good luck!\u003c/p\u003e","function_template":"function y = BreakTheMatrix(M,R,C)\r\n  y = x;\r\nend","test_suite":"%%\r\nM=[1 4 7 10;\r\n2 5 8 11;\r\n3 6 9 12];\r\nR=2;C=3;\r\nX(:,:,1) =[1 4 7 ; 2 5 8];\r\nX(:,:,2) =[2 5 8 ; 3 6 9];\r\nX(:,:,3) =[4 7 10 ; 5 8 11];\r\nX(:,:,4) =[5 8 11 ; 6 9 12];\r\nassert(isequal(BreakTheMatrix(M,R,C),X))\r\n%%\r\nx=1:ceil(35+25*rand());r=1;c=1;\r\nM=BreakTheMatrix(x,r,c);\r\nassert(all(arrayfun(@(y) (M(:,:,y)==y),1:numel(x))))\r\n%%\r\nx=eye(7);r=2;c=2;\r\nM=BreakTheMatrix(x,r,c);\r\nids=[1 8 15 22 29 36];\r\nurs=ids(1:5)+1;\r\nlls=urs+5;\r\nz=setxor(1:size(M,3),[ids urs lls]);\r\na1=arrayfun(@(a) isequal(M(:,:,a),eye(2)),ids);\r\na2=arrayfun(@(a) isequal(M(:,:,a),[0 1 ; 0 0]),urs);\r\na3=arrayfun(@(a) isequal(M(:,:,a),[0 0 ; 1 0]),lls);\r\na4=arrayfun(@(a) isequal(M(:,:,a),zeros(2)),z);\r\nassert(all([a1 a2 a3 a4]))\r\n%%\r\nu=ceil(10*rand())+4;\r\nx=magic(u);r=u;c=u;\r\nM=BreakTheMatrix(x,r,c);\r\nassert(isequal(M,x))\r\n%%\r\ntemp=ceil(8*rand)+3;\r\nx=ones(temp);r=2;c=2;\r\nM=BreakTheMatrix(x,r,c);\r\nassert(size(M,3)==(temp-1)^2);\r\nassert(all(arrayfun(@(a) isequal(M(:,:,a),ones(2)),1:size(M,3))))\r\n%%\r\nx=eye(7);r=7;c=7;\r\nassert(isequal(x,BreakTheMatrix(x,r,c)))","published":true,"deleted":false,"likes_count":9,"comments_count":14,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":379,"test_suite_updated_at":"2017-10-31T19:02:59.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-28T14:36:19.000Z","updated_at":"2026-03-31T15:14:35.000Z","published_at":"2017-10-16T01:45:08.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\u003eDo you want to take the Red Pill, or the Blue Pill?\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\u003eIf you take the Blue Pill, you will simply pass along to the next problem, not knowing what Cody has in store for you.\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\u003eIf you take the Red Pill, you will be asked to write a MATLAB function that will Break a Matrix. The inputs to the function will be a matrix M, along with a number of rows (R) and columns (C). You goal is to break the larger 2-D matrix up into a 3-D matrix comprised of enough RxC matrices so that you can recreate the 2-D matrix. When creating your 3-D matrix, go down the columns first, and then across the rows. Increment only one column (or one row) at a time. Do not go C columns down at each step.\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 example, R=2 and C=3, and M is as follows:\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[ M=[1 4 7 10\\n    2 5 8 11\\n    3 6 9 12]]]\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\u003eThis means that your output should be a 2x3x4 matrix:\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[ X(:,:,1) =\\n     1     4     7\\n     2     5     8\\n X(:,:,2) =\\n     2     5     8\\n     3     6     9\\n X(:,:,3) =\\n     4     7    10\\n     5     8    11\\n X(:,:,4) =\\n     5     8    11\\n     6     9    12]]\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\u003eYou can assume that R and C will always be less than or equal to the appropriate dimension of the original matrix. Good luck!\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":44352,"title":"The Top 5 Primes","description":"This problem series invites you to solve two simple problems related to the integer NUMBER FIVE, in order to celebrate \u003chttps://www.mathworks.com/matlabcentral/cody/contests/1?s_tid=Cody5YA_cody_home Cody's 5th birthday\u003e. \r\n\r\nIn this problem, let's find the top 5 greatest prime numbers along the first non-singleton dimension of an input array. \r\n\r\nExample \r\n\r\n* If the input is a vector, the output is a length-5 vector containing the top 5 prime numbers of the input sorted in descending order. Append NaNs as needed in the output if the number of primes is less than 5. \r\n\r\n  x = 1:10;\r\n  y = [7 5 3 2 NaN];\r\n\r\n* If the input is a m-by-n (m \u003e= 5) matrix, the output is a 5-by-n matrix containing the column-wise top 5 prime numbers of the input matrix sorted in descending order. Whenever there are less than 5 primes found in a specific column of the input, simply append NaNs as needed in the same column of the output. \r\n\r\n  % Input x is a matrix\r\n  x = [17     6     3\r\n       13     8    17\r\n        1     2     5\r\n        5     3     7\r\n        7    11     2\r\n       31     7     6];\r\n\r\n  % Output y\r\n  y = [31    11    17\r\n       17     7     7\r\n       13     3     5\r\n        7     2     3\r\n        5   NaN     2];\r\n\r\nPrevious problem in this series: \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44342-spot-the-first-occurrence-of-5 Spot the First Occurrence of 5\u003e","description_html":"\u003cp\u003eThis problem series invites you to solve two simple problems related to the integer NUMBER FIVE, in order to celebrate \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/contests/1?s_tid=Cody5YA_cody_home\"\u003eCody's 5th birthday\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eIn this problem, let's find the top 5 greatest prime numbers along the first non-singleton dimension of an input array.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cul\u003e\u003cli\u003eIf the input is a vector, the output is a length-5 vector containing the top 5 prime numbers of the input sorted in descending order. Append NaNs as needed in the output if the number of primes is less than 5.\u003c/li\u003e\u003c/ul\u003e\u003cpre class=\"language-matlab\"\u003ex = 1:10;\r\ny = [7 5 3 2 NaN];\r\n\u003c/pre\u003e\u003cul\u003e\u003cli\u003eIf the input is a m-by-n (m \u0026gt;= 5) matrix, the output is a 5-by-n matrix containing the column-wise top 5 prime numbers of the input matrix sorted in descending order. Whenever there are less than 5 primes found in a specific column of the input, simply append NaNs as needed in the same column of the output.\u003c/li\u003e\u003c/ul\u003e\u003cpre class=\"language-matlab\"\u003e% Input x is a matrix\r\nx = [17     6     3\r\n     13     8    17\r\n      1     2     5\r\n      5     3     7\r\n      7    11     2\r\n     31     7     6];\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003e% Output y\r\ny = [31    11    17\r\n     17     7     7\r\n     13     3     5\r\n      7     2     3\r\n      5   NaN     2];\r\n\u003c/pre\u003e\u003cp\u003ePrevious problem in this series: \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44342-spot-the-first-occurrence-of-5\"\u003eSpot the First Occurrence of 5\u003c/a\u003e\u003c/p\u003e","function_template":"function y = top5primes(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nassessFunctionAbsence({'regexp','regexpi','regexprep','str2num'},'FileName','top5primes.m')\r\n\r\n%%\r\nx = 1:10;\r\ny_correct = [7 5 3 2 NaN];\r\nassert(isequaln(top5primes(x),y_correct))\r\n\r\n%%\r\nx = (1:2:100).';\r\ny_correct = [97 89 83 79 73].';\r\nassert(isequaln(top5primes(x),y_correct))\r\n\r\n%%\r\nx = [17     6     3\r\n     13     8    17\r\n      1     2     5\r\n      5     3     7\r\n      7    11     2\r\n     31     7     6];\r\ny_correct = [31    11    17\r\n             17     7     7\r\n             13     3     5\r\n              7     2     3\r\n              5   NaN     2];\r\nassert(isequaln(top5primes(x),y_correct))\r\n\r\n%%\r\nx = interp1(magic(30).',1:5).';\r\ny_correct = [877   733   863   719   881\r\n             829   701   751   173   769\r\n             797   139    59   157    29\r\n              89   107    43   109    13\r\n              73   NaN    11    61   NaN];\r\nassert(isequaln(top5primes(x),y_correct))\r\n\r\n%%\r\nrng(0);\r\nx = reshape(randperm(200,180),36,5);\r\ny_correct = [163   181   173   197   193\r\n              71   179   149   191   157\r\n              23   167   113   139   151\r\n              19   131   101    83   137\r\n             NaN   109    67    73   127];\r\nassert(isequaln(top5primes(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":342,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-01T01:52:48.000Z","updated_at":"2026-04-07T13:51:21.000Z","published_at":"2017-10-16T01:45:08.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 problem series invites you to solve two simple problems related to the integer NUMBER FIVE, in order to celebrate\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://www.mathworks.com/matlabcentral/cody/contests/1?s_tid=Cody5YA_cody_home\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody's 5th birthday\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\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn this problem, let's find the top 5 greatest prime numbers along the first non-singleton dimension of an input array.\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\u003eExample\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\u003eIf the input is a vector, the output is a length-5 vector containing the top 5 prime numbers of the input sorted in descending order. Append NaNs as needed in the output if the number of primes is less than 5.\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[x = 1:10;\\ny = [7 5 3 2 NaN];]]\u003e\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\u003eIf the input is a m-by-n (m \u0026gt;= 5) matrix, the output is a 5-by-n matrix containing the column-wise top 5 prime numbers of the input matrix sorted in descending order. Whenever there are less than 5 primes found in a specific column of the input, simply append NaNs as needed in the same column of the output.\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[% Input x is a matrix\\nx = [17     6     3\\n     13     8    17\\n      1     2     5\\n      5     3     7\\n      7    11     2\\n     31     7     6];\\n\\n% Output y\\ny = [31    11    17\\n     17     7     7\\n     13     3     5\\n      7     2     3\\n      5   NaN     2];]]\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 in this series:\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://www.mathworks.com/matlabcentral/cody/problems/44342-spot-the-first-occurrence-of-5\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSpot the First Occurrence of 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":44386,"title":"Circumscribed Pentagon?","description":"Building off of \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44368 Problem 44368\u003e, your function will be provided with the five vertices of a regular pentagon (p) as well as the center point (cp) and radius (r) of a circle. The function should return one of the following values:\r\n\r\n  0: the pentagon is completely enclosed within the circle but is not inscribed\r\n  1: the pentagon is inscribed in the circle (within ±0.02)\r\n  2: the vertices of the pentagon extend beyond the circle, but its edges still cross back into the circle\r\n  3: the pentagon circumscribes the circle (within ±0.02)\r\n  4: the pentagon completely encloses, and does not touch, the circle\r\n\r\nPoints will be rounded to the nearest hundredth. See the test cases for examples.","description_html":"\u003cp\u003eBuilding off of \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44368\"\u003eProblem 44368\u003c/a\u003e, your function will be provided with the five vertices of a regular pentagon (p) as well as the center point (cp) and radius (r) of a circle. The function should return one of the following values:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e0: the pentagon is completely enclosed within the circle but is not inscribed\r\n1: the pentagon is inscribed in the circle (within ±0.02)\r\n2: the vertices of the pentagon extend beyond the circle, but its edges still cross back into the circle\r\n3: the pentagon circumscribes the circle (within ±0.02)\r\n4: the pentagon completely encloses, and does not touch, the circle\r\n\u003c/pre\u003e\u003cp\u003ePoints will be rounded to the nearest hundredth. See the test cases for examples.\u003c/p\u003e","function_template":"function y = circumscribed_pentagon(p,cp,r)\r\n  y = 0;\r\nend","test_suite":"%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5.61; 5.40,1.69; 3.34,-4.66; -3.34,-4.66; -5.40,1.69];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,6.18; 5.88,1.91; 3.63,-5.00; -3.63,-5.00; -5.88,1.91];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 3;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,4.55; 4.28,1.44; 2.65,-3.59; -2.65,-3.59; -4.28,1.44];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [20,13.61; 25.40,9.69; 23.34,3.34; 16.66,3.34; 14.60,9.69];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [20,14.18; 25.88,9.91; 23.63,3.00; 16.37,3.00; 14.12,9.91];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 3;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,6.58; 6.42,1.92; 3.97,-5.63; -3.97,-5.63; -6.42,1.92] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 4;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,4.55; 4.28,1.44; 2.65,-3.59; -2.65,-3.59; -4.28,1.44] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [25.01,12.47; 25.98,4.58; 18.78,1.23; 13.37,7.03; 17.22,13.97];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 4;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.27,11.12; 23.92,5.87; 19.12,3.63; 15.52,7.50; 18.08,12.13];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 1;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [32.54,38.78; 38.84,26.41; 29.02,16.59; 16.65,22.89; 18.83,36.61];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 4;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.49,35.54; 34.69,27.29; 28.14,20.74; 19.89,24.95; 21.34,34.09];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 0;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [26.97,34.06; 32.37,30.14; 30.31,23.79; 23.63,23.79; 21.57,30.14];\r\ncp = [26.97,28.45];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [31.35,32.83; 32.49,25.64; 26.00,22.34; 20.85,27.48; 24.16,33.97];\r\ncp = [26.97,28.45];\r\nr = 5.01;\r\ny_correct = 3;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":64,"test_suite_updated_at":"2017-12-08T15:45:11.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-13T20:03:45.000Z","updated_at":"2025-11-04T13:12:51.000Z","published_at":"2017-10-16T01:51:02.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\u003eBuilding 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=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44368\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44368\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, your function will be provided with the five vertices of a regular pentagon (p) as well as the center point (cp) and radius (r) of a circle. The function should return one of the following values:\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[0: the pentagon is completely enclosed within the circle but is not inscribed\\n1: the pentagon is inscribed in the circle (within ±0.02)\\n2: the vertices of the pentagon extend beyond the circle, but its edges still cross back into the circle\\n3: the pentagon circumscribes the circle (within ±0.02)\\n4: the pentagon completely encloses, and does not touch, the circle]]\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\u003ePoints will be rounded to the nearest hundredth. See the test cases for examples.\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":44306,"title":"Is it really a 5?","description":"A number containing at least one five will be passed to your function, which must return true or false depending upon whether the English spelling of the number may contain \"five\" anywhere. For example:\r\n\r\n n = 5; return true since it is spelled \"five\"\r\n n = 15; return false since it is spelled \"fifteen\" and does not contain the four-letter string \"five\"\r\n\r\nThis criterion applies to any common spelling of the number. For example, 1500 can be written fifteen hundred. But, it can also be written one thousand five hundred. So, 1500 would be considered to contain a \"five\" for this problem.\r\n\r\nSee the test suite for more examples.","description_html":"\u003cp\u003eA number containing at least one five will be passed to your function, which must return true or false depending upon whether the English spelling of the number may contain \"five\" anywhere. For example:\u003c/p\u003e\u003cpre\u003e n = 5; return true since it is spelled \"five\"\r\n n = 15; return false since it is spelled \"fifteen\" and does not contain the four-letter string \"five\"\u003c/pre\u003e\u003cp\u003eThis criterion applies to any common spelling of the number. For example, 1500 can be written fifteen hundred. But, it can also be written one thousand five hundred. So, 1500 would be considered to contain a \"five\" for this problem.\u003c/p\u003e\u003cp\u003eSee the test suite for more examples.\u003c/p\u003e","function_template":"function tf = is_it_really_a_5(n)\r\n tf = 0;\r\nend","test_suite":"%%\r\nn = 5;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 15;\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 25;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 35;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 50;\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 52;\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 55;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 59;\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 85;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 105;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 115;\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 125;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 250;\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 500;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 555;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 5000; %5,000\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 15000; %15,000\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 55555; %55,555\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 50000; %50,000\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 55000; %55,000\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 50500; %50,500\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 50050; %50,050\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 50005; %50,005\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 500000; %500,000\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 5000000; %5,000,000\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 15000000; %15,000,000\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 50000000; %50,000,000\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 105000000; %105,000,000\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 50050050; %50,050,050\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 50000005; %50,000,005\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 50000015; %50,000,015\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 500000000; %500,000,000\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 5000000000; %5,000,000,000\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 50000000000; %50,000,000,000\r\nassert(isequal(is_it_really_a_5(n),0))","published":true,"deleted":false,"likes_count":7,"comments_count":1,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":317,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-08T22:07:48.000Z","updated_at":"2026-04-15T11:02:38.000Z","published_at":"2017-10-16T01:45: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\u003eA number containing at least one five will be passed to your function, which must return true or false depending upon whether the English spelling of the number may contain \\\"five\\\" anywhere. 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 = 5; return true since it is spelled \\\"five\\\"\\n n = 15; return false since it is spelled \\\"fifteen\\\" and does not contain the four-letter string \\\"five\\\"]]\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\u003eThis criterion applies to any common spelling of the number. For example, 1500 can be written fifteen hundred. But, it can also be written one thousand five hundred. So, 1500 would be considered to contain a \\\"five\\\" for this 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\u003eSee the test suite for more examples.\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":44341,"title":"Hexagonal numbers on a spiral matrix","description":"Put hexagonal numbers in a ( m x m ) spiral matrix and return the sum of its diagonal elements.\r\n\r\nFormula of hexagonal numbers h(n) = 2n^2 - n\r\n\r\nIf m = 5;\r\n\r\n  spiral(5) =   \r\n    21    22    23    24    25\r\n    20     7     8     9    10\r\n    19     6     1     2    11\r\n    18     5     4     3    12\r\n    17    16    15    14    13\r\n\r\nFirst 5x5=25 hexagonal numbers are;\r\n\r\n  h = [1 6 15 28 45 66 91 120 153 190 231 276 325 378 435 496 561 630 703 780 861 946 1035 1128 1225]\r\n\r\nWe put them in a spiral format;\r\n\r\n   spiralHex = [\r\n861\t946\t1035\t1128\t1225\r\n780\t91\t120\t153\t190\r\n703\t66\t1\t6\t231\r\n630\t45\t28\t15\t276\r\n561\t496\t435\t378\t325\r\n\r\nAnd sum its diag = 861 + 91 + 1 + 15 + 325 = 1293.\r\n\r\nReturn the output as char.","description_html":"\u003cp\u003ePut hexagonal numbers in a ( m x m ) spiral matrix and return the sum of its diagonal elements.\u003c/p\u003e\u003cp\u003eFormula of hexagonal numbers h(n) = 2n^2 - n\u003c/p\u003e\u003cp\u003eIf m = 5;\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003espiral(5) =   \r\n  21    22    23    24    25\r\n  20     7     8     9    10\r\n  19     6     1     2    11\r\n  18     5     4     3    12\r\n  17    16    15    14    13\r\n\u003c/pre\u003e\u003cp\u003eFirst 5x5=25 hexagonal numbers are;\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eh = [1 6 15 28 45 66 91 120 153 190 231 276 325 378 435 496 561 630 703 780 861 946 1035 1128 1225]\r\n\u003c/pre\u003e\u003cp\u003eWe put them in a spiral format;\u003c/p\u003e\u003cpre\u003e   spiralHex = [\r\n861\t946\t1035\t1128\t1225\r\n780\t91\t120\t153\t190\r\n703\t66\t1\t6\t231\r\n630\t45\t28\t15\t276\r\n561\t496\t435\t378\t325\u003c/pre\u003e\u003cp\u003eAnd sum its diag = 861 + 91 + 1 + 15 + 325 = 1293.\u003c/p\u003e\u003cp\u003eReturn the output as char.\u003c/p\u003e","function_template":"function y = hexagonalSpiral(m)\r\n  \r\nend","test_suite":"%%\r\nm = 1;\r\ny_correct = '1';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 2;\r\ny_correct = '16';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 5;\r\ny_correct = '1293';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 16;\r\ny_correct = '420800';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 100;\r\ny_correct = '4000333360';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 1295;\r\ny_correct = '1456830580539887';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 2500;\r\ny_correct = '39062505208334000';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 5000;\r\ny_correct = '1250000041666668000';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 8000;\r\ny_correct = '13107200170666668800';\r\nassert(isequal(hexagonalSpiral(m),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":164,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-19T08:06:36.000Z","updated_at":"2025-12-26T10:11:44.000Z","published_at":"2017-10-16T01:50:59.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\u003ePut hexagonal numbers in a ( m x m ) spiral matrix and return the sum of its diagonal elements.\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\u003eFormula of hexagonal numbers h(n) = 2n^2 - n\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\u003eIf m = 5;\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[spiral(5) =   \\n  21    22    23    24    25\\n  20     7     8     9    10\\n  19     6     1     2    11\\n  18     5     4     3    12\\n  17    16    15    14    13]]\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\u003eFirst 5x5=25 hexagonal numbers are;\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[h = [1 6 15 28 45 66 91 120 153 190 231 276 325 378 435 496 561 630 703 780 861 946 1035 1128 1225]]]\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\u003eWe put them in a spiral format;\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[   spiralHex = [\\n861  946  1035  1128  1225\\n780  91  120  153  190\\n703  66  1  6  231\\n630  45  28  15  276\\n561  496  435  378  325]]\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\u003eAnd sum its diag = 861 + 91 + 1 + 15 + 325 = 1293.\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\u003eReturn the output as char.\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":44353,"title":"Group-wise Euclidean distance","description":"*Input*:\r\n \r\n* *x* —— An array of size *n-by-d*, where each row vector denotes a point in a d-dimensional space;\r\n* *g* —— A grouping (index) vector g of size *n-by-1*, which divides the points in x into groups. Specifically, the rows in x corresponding to the same group index in g belong to the same group. \r\n\r\n*Output*: \r\n\r\n* *y* —— The group-wise Euclidean distance matrix associated with the points in x. Suppose that m = max(g), then y will be an *m-by-m* matrix, where each element y(i,j) is the Euclidean distance between group i and group j, which is defined as the minimum of the Euclidean distances between any points in group i and any other points in group j. \r\n\r\n*Example*:\r\n\r\nExample 1: n = 6, d = 1\r\n\r\n  g = [2   1   3  2  1].';\r\n  x = [3  10  15  8  5].';\r\n  y = [0   2   5            % y(1,2) = y(2,1) = min(10-3,5-3,10-8,8-5) = 2\r\n       2   0   7            % y(1,3) = y(3,1) = min(15-10,15-5) = 5\r\n       5   7   0];          % y(2,3) = y(3,2) = min(15-3,15-8) = 7\r\n\r\nExample 2: n = 3, d = 2\r\n\r\n  g = [1 2 2].';\r\n  x = [0   0\r\n       5  12\r\n       3   4];\r\n  y = [0  5;\r\n       5  0];    % y(1,2) = y(2,1) = min(sqrt(5^2+12^2),sqrt(3^2+4^2)) = 5\r\n  \r\n*Testing*:\r\n\r\nThe test suite will focus mainly on the large-scale problem dimensions (e.g., large n and/or d). The purpose is to direct attention towards efficient runtime speed of execution. Note that your solution may run into a time-out error if it is not sufficiently efficient (which is why this problem falls into the \u003chttps://www.mathworks.com/matlabcentral/cody/groups/35 Cody5:Hard\u003e category).\r\n\r\n*Scoring*:\r\n\r\nWe have modified Cody's default size-based scoring function into a performance-based scoring system (implemented by our fellow Cody player \u003chttps://www.mathworks.com/matlabcentral/cody/players/3021298-ly-cao LY Cao\u003e), in which the score of your submission equals 5 times the execution time of your solution (which reprents a score resolution of 0.2 seconds and allows for more room for performance improvement). Please ignore the code size and focus only on improving the code performance, as our test suite will reject any submissions running longer than 20 seconds (in contrast to Cody's default 40 seconds timeout limit).  \r\n\r\nPlease be advised that an amazingly fast solution would earn a score \u003c 5, meaning that it completes execution of all test cases within a second!\r\n\r\n*Update* (11/21/2017):\r\nAdditional test cases are added to ban cheater solutions (e.g., hard-coded submissions 1351541, 1351007, 1350563, 1349442, all came from \u003chttps://www.mathworks.com/matlabcentral/cody/players/3931805-marco-tullio Marco Tullio\u003e).\r\n","description_html":"\u003cp\u003e\u003cb\u003eInput\u003c/b\u003e:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003cb\u003ex\u003c/b\u003e —— An array of size \u003cb\u003en-by-d\u003c/b\u003e, where each row vector denotes a point in a d-dimensional space;\u003c/li\u003e\u003cli\u003e\u003cb\u003eg\u003c/b\u003e —— A grouping (index) vector g of size \u003cb\u003en-by-1\u003c/b\u003e, which divides the points in x into groups. Specifically, the rows in x corresponding to the same group index in g belong to the same group.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003e\u003cb\u003eOutput\u003c/b\u003e:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003cb\u003ey\u003c/b\u003e —— The group-wise Euclidean distance matrix associated with the points in x. Suppose that m = max(g), then y will be an \u003cb\u003em-by-m\u003c/b\u003e matrix, where each element y(i,j) is the Euclidean distance between group i and group j, which is defined as the minimum of the Euclidean distances between any points in group i and any other points in group j.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003e\u003cb\u003eExample\u003c/b\u003e:\u003c/p\u003e\u003cp\u003eExample 1: n = 6, d = 1\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eg = [2   1   3  2  1].';\r\nx = [3  10  15  8  5].';\r\ny = [0   2   5            % y(1,2) = y(2,1) = min(10-3,5-3,10-8,8-5) = 2\r\n     2   0   7            % y(1,3) = y(3,1) = min(15-10,15-5) = 5\r\n     5   7   0];          % y(2,3) = y(3,2) = min(15-3,15-8) = 7\r\n\u003c/pre\u003e\u003cp\u003eExample 2: n = 3, d = 2\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eg = [1 2 2].';\r\nx = [0   0\r\n     5  12\r\n     3   4];\r\ny = [0  5;\r\n     5  0];    % y(1,2) = y(2,1) = min(sqrt(5^2+12^2),sqrt(3^2+4^2)) = 5\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eTesting\u003c/b\u003e:\u003c/p\u003e\u003cp\u003eThe test suite will focus mainly on the large-scale problem dimensions (e.g., large n and/or d). The purpose is to direct attention towards efficient runtime speed of execution. Note that your solution may run into a time-out error if it is not sufficiently efficient (which is why this problem falls into the \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/groups/35\"\u003eCody5:Hard\u003c/a\u003e category).\u003c/p\u003e\u003cp\u003e\u003cb\u003eScoring\u003c/b\u003e:\u003c/p\u003e\u003cp\u003eWe have modified Cody's default size-based scoring function into a performance-based scoring system (implemented by our fellow Cody player \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/players/3021298-ly-cao\"\u003eLY Cao\u003c/a\u003e), in which the score of your submission equals 5 times the execution time of your solution (which reprents a score resolution of 0.2 seconds and allows for more room for performance improvement). Please ignore the code size and focus only on improving the code performance, as our test suite will reject any submissions running longer than 20 seconds (in contrast to Cody's default 40 seconds timeout limit).\u003c/p\u003e\u003cp\u003ePlease be advised that an amazingly fast solution would earn a score \u0026lt; 5, meaning that it completes execution of all test cases within a second!\u003c/p\u003e\u003cp\u003e\u003cb\u003eUpdate\u003c/b\u003e (11/21/2017):\r\nAdditional test cases are added to ban cheater solutions (e.g., hard-coded submissions 1351541, 1351007, 1350563, 1349442, all came from \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/players/3931805-marco-tullio\"\u003eMarco Tullio\u003c/a\u003e).\u003c/p\u003e","function_template":"function y = groupDist(x,g)\r\n  y = x;\r\nend","test_suite":"%%\r\nassessFunctionAbsence({'regexp','regexpi','regexprep','str2num','tic','toc','persistent','global','rng','assert','!','system','unix','noCheater'},'FileName','groupDist.m')\r\n\r\n%%\r\nfid = fopen('noCheater.p','Wb');\r\nfwrite(fid, hex2dec(reshape([\r\n    '7630312E30307630302E30300007701CAB777FB100000015000000740000007E3D5C20F'...'\r\n    '5319EEB8B0D3D9C9C87C18B91C13D7310D9D8E837C95E62D49A3FE08B071790DBC222B5'...\r\n    '839E9A19EA6AA7CF3785A7E7CEC1CFE46E0E9A5DB7C82D69A4FAB7BF308D0871C342A5F'...\r\n    'EF9AF61623F1D97F80207388D54ABA3CB3D551617DA33AA3F5040CD425FC9B29E2A4233'...\r\n    'AE7C5ADEF399'],2,[]).')); rehash path; \r\nfclose(fid); \r\nassert(noCheater(),'Cheater detected!')\r\n\r\n%%\r\ng = [2   1   3  2  1].';\r\nx = [3  10  15  8  5].';\r\ny_correct = [0   2   5            \r\n             2   0   7      \r\n             5   7   0]; \r\nassert(isequaln(y_correct,groupDist(x,g)))\r\n\r\n%%\r\ng = [1 2 2].';\r\nx = [0   0\r\n     5  12\r\n     3   4];\r\ny_correct = [0  5;\r\n             5  0];    \r\nassert(isequal(y_correct,groupDist(x,g)))\r\n\r\n%%\r\ng = [2 2 3 3 3 1].';\r\nx = [-5   12\r\n      3    4\r\n     -7  -24\r\n     25    4\r\n      9   40\r\n      0    0];\r\ny_correct = [0    5   25;\r\n             5    0   22\r\n             25  22    0];  \r\nassert(isequal(y_correct,groupDist(x,g)))\r\n\r\n%% Randomized case to disallow hard-coded solution\r\ng = randperm(10).';\r\nx = rand(10,1);\r\na = sortrows([g,x]);\r\ny_correct = abs(a(:,2)-a(:,2).');\r\nassert(isequal(round(y_correct,10),round(groupDist(x,g),10))) \r\n\r\n%% Additional test case to disallow hard-coded solution\r\ng = [1,2,3].';\r\nx = [2,5,10].';\r\ny_correct = [0   3   8            \r\n             3   0   5      \r\n             8   5   0]; \r\nassert(isequaln(y_correct,groupDist(x,g)))\r\n\r\n%%\r\nglobal t\r\nt = zeros(1,3); \r\nrng(923,'twister');\r\nn = 5e3; d = 3; m = 5;\r\nx = rand(n,d);\r\ng = randi(m,n,1); \r\ny_correct = [0,0.00653919638188362,0.00319052186150122,0.00858841434457234,0.00359654235965771\r\n             0.00653919638188362,0,0.00855286615862212,0.00589790293838067,0.00484910151004134\r\n             0.00319052186150122,0.00855286615862212,0,0.00591041083080696,0.00483607360689871\r\n             0.00858841434457234,0.00589790293838067,0.00591041083080696,0,0.00695738487959094\r\n             0.00359654235965771,0.00484910151004134,0.00483607360689871,0.00695738487959094,0];\r\ntic, y = groupDist(x,g); t(1) = toc;\r\nassert(isequal(round(y_correct,10),round(y,10))) \r\n\r\n%%\r\nglobal t\r\nrng(123) \r\nrng(max('cody5'),'combRecursive');\r\nn = 5e3; d = 3; m = 100;\r\nx = 10*rand(n,d);\r\ng = randi(m,n,1); \r\ntic, y = groupDist(x,g); t(2) = toc;\r\nassert(norm(y-y.') \u003c 1e-11 \u0026\u0026 all(~diag(y)) \u0026\u0026 all(size(y)==m) \u0026\u0026 abs(det(y)-0.030846735888559)\u003c1e-8 \u0026\u0026...\r\n    abs(cond(y)-1.606720826682107e+04) \u003c 1e-6 \u0026\u0026 abs(max(nonzeros(y))-1.058563379304832)\u003c1e-10 \u0026\u0026...\r\n    abs(mean(nonzeros(y))-0.419901913602729)\u003c1e-8)\r\n\r\n%%\r\nglobal t \r\nrng(sum('Cody5, Oct. 16, 2017'),'multFibonacci') \r\nn = 5e3; d = 1e2;  m = 100;\r\nx = 5*randn(n,d) + 20;\r\ng = randi(m,n,1); \r\ntic, y = groupDist(x,g); t(3) = toc;\r\nassert(norm(y-y.') \u003c 1e-11 \u0026\u0026 all(~diag(y)) \u0026\u0026 all(size(y)==m) \u0026\u0026 ...\r\n    abs(cond(y)-2.024633860688276e+02) \u003c 1e-8 \u0026\u0026 abs(max(nonzeros(y))-57.768463869822135)\u003c1e-10 \u0026\u0026...\r\n    abs(mean(nonzeros(y))-53.852605466762945)\u003c1e-8) \r\n \r\n%%\r\nglobal t\r\nfid = fopen('score.p','Wb');\r\nfwrite(fid,uint8(sscanf([...\r\n     '7630312E30307630302E3030000B901C454EFFB100000031000001330000018D483A60'...\r\n     '366BC9545F84AE26323B67424D4E8A7A2E5B7D8ACAA45A1C3C5C8B33E245C95243E3CB'...\r\n     'AF5D0D993BDA70B7AB5DA365A83E8CA87FFC45265E23EF80943784C5F48E6E53D5DA34'...\r\n     'F1F2ECD34683EABE3B7461DC9E8004CC50B2A79D73495F6F625B5365602B2E6C6093D2'...\r\n     '997D371DA457CE82327E686AF512A507B2CB62A375BFD1B283DDD2C01EDEF2771EDAA3'...\r\n     '6ABB4852BA4061E20149688E812EB41A9AF8627EF35755492D2830EB8718BCFE88027E'...\r\n     '6EA960B63A3B3E26E0451B1DCF14F3C20E70D9D93B08E7FF4AE8D82E7CC38042FD38F7'...\r\n     'A14D312EF5652823FEB7E8B52AF5C69F5E7D16B116B5F979EDA77459D6BB61B7971A51'...\r\n     '041227DD601319D667DF62E8DA5E381FDD07A2806FE835BD2569E5315CDFC19C6B6A2B'...\r\n     '4F0FF6BA803F1759ACAB133CCFAB6D5A5D002FC2C5F381F0'],'%2X')));\r\nfclose(fid);\r\nscore(round(5*sum(t)))\r\nfprintf('The execution time of test case %d is %.5f seconds \\n',[5:7;t])\r\nfprintf('The total execution time is %.5f seconds \\n',sum(t))\r\nassert(sum(t)\u003c20, 'Sorry, your solution is too slow. The execution time must not exceed 20 seconds.')\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":4,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":75,"test_suite_updated_at":"2017-11-21T22:49:00.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-01T04:33:43.000Z","updated_at":"2026-02-03T09:16:35.000Z","published_at":"2017-10-16T01:51:00.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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e:\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e —— An array of size\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\u003en-by-d\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, where each row vector denotes a point in a d-dimensional space;\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eg\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e —— A grouping (index) vector g of size\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\u003en-by-1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, which divides the points in x into groups. Specifically, the rows in x corresponding to the same group index in g belong to the same group.\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e:\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e —— The group-wise Euclidean distance matrix associated with the points in x. Suppose that m = max(g), then y will be an\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\u003em-by-m\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix, where each element y(i,j) is the Euclidean distance between group i and group j, which is defined as the minimum of the Euclidean distances between any points in group i and any other points in group j.\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\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\u003eExample 1: n = 6, d = 1\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[g = [2   1   3  2  1].';\\nx = [3  10  15  8  5].';\\ny = [0   2   5            % y(1,2) = y(2,1) = min(10-3,5-3,10-8,8-5) = 2\\n     2   0   7            % y(1,3) = y(3,1) = min(15-10,15-5) = 5\\n     5   7   0];          % y(2,3) = y(3,2) = min(15-3,15-8) = 7]]\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\u003eExample 2: n = 3, d = 2\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[g = [1 2 2].';\\nx = [0   0\\n     5  12\\n     3   4];\\ny = [0  5;\\n     5  0];    % y(1,2) = y(2,1) = min(sqrt(5^2+12^2),sqrt(3^2+4^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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTesting\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\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\u003eThe test suite will focus mainly on the large-scale problem dimensions (e.g., large n and/or d). The purpose is to direct attention towards efficient runtime speed of execution. Note that your solution may run into a time-out error if it is not sufficiently efficient (which is why this problem falls into 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://www.mathworks.com/matlabcentral/cody/groups/35\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody5:Hard\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e category).\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eScoring\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\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\u003eWe have modified Cody's default size-based scoring function into a performance-based scoring system (implemented by our fellow Cody player\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://www.mathworks.com/matlabcentral/cody/players/3021298-ly-cao\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eLY Cao\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e), in which the score of your submission equals 5 times the execution time of your solution (which reprents a score resolution of 0.2 seconds and allows for more room for performance improvement). Please ignore the code size and focus only on improving the code performance, as our test suite will reject any submissions running longer than 20 seconds (in contrast to Cody's default 40 seconds timeout limit).\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\u003ePlease be advised that an amazingly fast solution would earn a score \u0026lt; 5, meaning that it completes execution of all test cases within a second!\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eUpdate\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (11/21/2017): Additional test cases are added to ban cheater solutions (e.g., hard-coded submissions 1351541, 1351007, 1350563, 1349442, all came from\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://www.mathworks.com/matlabcentral/cody/players/3931805-marco-tullio\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eMarco Tullio\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":44309,"title":"Pi Digit Probability","description":"Assume that the next digit of pi constant is determined by the historical digit distribution. What is the probability of next digit (N) being (n). \r\n\r\nFor example if we consider the first 100 digits of pi, we will see that the digit '3' is occured 12 times. So the probability of the being '3' the 101th digit will be 12/100 = 0.12.\r\n\r\nRound the results to four decimals.","description_html":"\u003cp\u003eAssume that the next digit of pi constant is determined by the historical digit distribution. What is the probability of next digit (N) being (n).\u003c/p\u003e\u003cp\u003eFor example if we consider the first 100 digits of pi, we will see that the digit '3' is occured 12 times. So the probability of the being '3' the 101th digit will be 12/100 = 0.12.\u003c/p\u003e\u003cp\u003eRound the results to four decimals.\u003c/p\u003e","function_template":"function y = pidigit(N,n)\r\n  y = x;\r\nend","test_suite":"%%\r\nN = 101;\r\nn = 3;\r\ny_correct = 0.1200;\r\nassert(abs(pidigit(N,n)-y_correct)\u003c0.0001)\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[101,201,202,203,1001]),regexp(fileread('pidigit.m'),'[\\d\\.\\+\\-\\*\\/]+','match')))) % modified from the comment of Alfonso on https://www.mathworks.com/matlabcentral/cody/problems/44343\r\n\r\n%%\r\nN = 201;\r\nn = 6;\r\ny_correct = 0.0750;\r\nassert(abs(pidigit(N,n)-y_correct)\u003c0.0001)\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[101,201,202,203,1001]),regexp(fileread('pidigit.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nN = 202;\r\nn = 6;\r\ny_correct = 0.0796;\r\nassert(abs(pidigit(N,n)-y_correct)\u003c0.0001)\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[101,201,202,203,1001]),regexp(fileread('pidigit.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nN = 203;\r\nn = 6;\r\ny_correct = 0.0792;\r\nassert(abs(pidigit(N,n)-y_correct)\u003c0.0001)\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[101,201,202,203,1001]),regexp(fileread('pidigit.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nN = 1001;\r\nn = 9;\r\ny_correct = 0.1050;\r\nassert(abs(pidigit(N,n)-y_correct)\u003c0.0001)\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[101,201,202,203,1001]),regexp(fileread('pidigit.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n","published":true,"deleted":false,"likes_count":18,"comments_count":27,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":853,"test_suite_updated_at":"2017-10-21T07:59:48.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-11T06:41:07.000Z","updated_at":"2026-04-17T02:20:31.000Z","published_at":"2017-10-16T01:45: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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eAssume that the next digit of pi constant is determined by the historical digit distribution. What is the probability of next digit (N) being (n).\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\u003eFor example if we consider the first 100 digits of pi, we will see that the digit '3' is occured 12 times. So the probability of the being '3' the 101th digit will be 12/100 = 0.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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRound the results to four decimals.\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":44380,"title":"ASCII Birthday Cake","description":"Given an age and a name, give draw an ASCII birthday cake. For example, given the name \"CODY\" and the age 5, return a string with the following (no trailing spaces)\r\n\r\n   6 6 6 6 6\r\n   | | | | |\r\n __|_|_|_|_|__\r\n{             }\r\n{             }\r\n{    CODY     }\r\n{             }\r\n{_____________}\r\n\r\nThis uses the \u003chttps://www.mathworks.com/help/matlab/ref/string.html string datatype\u003e, not a char array.","description_html":"\u003cp\u003eGiven an age and a name, give draw an ASCII birthday cake. For example, given the name \"CODY\" and the age 5, return a string with the following (no trailing spaces)\u003c/p\u003e\u003cpre\u003e   6 6 6 6 6\r\n   | | | | |\r\n __|_|_|_|_|__\r\n{             }\r\n{             }\r\n{    CODY     }\r\n{             }\r\n{_____________}\u003c/pre\u003e\u003cp\u003eThis uses the \u003ca href = \"https://www.mathworks.com/help/matlab/ref/string.html\"\u003estring datatype\u003c/a\u003e, not a char array.\u003c/p\u003e","function_template":"function s = birthday_cake(name, n)\r\n    s = \"\";\r\n    s = s + \"name\";\r\nend","test_suite":"%%\r\ncake = string(char([32 32 32 54 32 54 32 54 32 54 32 54 10 32 32 32 124 32 124 32 124 32 124 32 124 10 32 95 95 124 95 124 95 124 95 124 95 124 95 95 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 67 79 68 89 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 95 95 95 95 95 95 95 95 95 95 95 95 95 125 10]));\r\nfprintf('%s\\n', cake);\r\nassert(isequal(birthday_cake(\"CODY\", 5), cake));\r\n\r\n%%\r\ncake = string(char([32 32 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 10 32 32 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 10 32 95 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 95 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 64 98 109 116 114 97 110 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 125 10]));\r\nfprintf('%s\\n', cake);\r\nassert(isequal(birthday_cake(\"@bmtran\", 29), cake));\r\n\r\n%%\r\ncake = string(char([32 32 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 10 32 32 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 10 32 95 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 95 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 77 65 84 76 65 66 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 125 10]));\r\nfprintf('%s\\n', cake);\r\nassert(isequal(birthday_cake(\"MATLAB\", 33), cake));\r\n\r\n%%\r\ncake = string(char([32 32 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 10 32 32 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 10 32 95 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 95 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 67 108 101 118 101 32 77 111 108 101 114 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 125 10]));\r\nfprintf('%s\\n', cake);\r\nassert(isequal(birthday_cake(\"Cleve Moler\", 78), cake));\r\n\r\n%%\r\ncake = string(char([32 32 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 10 32 32 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 10 32 95 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 95 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 65 108 97 110 32 84 117 114 105 110 103 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 125 10]));\r\nfprintf('%s\\n', cake);\r\nassert(isequal(birthday_cake(\"Alan Turing\", 105), cake));\r\n\r\n%%\r\ncake = string(char([32 32 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 10 32 32 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 10 32 95 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 95 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 83 105 114 32 73 115 97 97 99 32 78 101 119 116 111 110 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 125 10]));\r\nfprintf('%s\\n', cake);\r\nassert(isequal(birthday_cake(\"Sir Isaac Newton\", 375), cake));","published":true,"deleted":false,"likes_count":10,"comments_count":4,"created_by":134,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":228,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-12T19:48:13.000Z","updated_at":"2026-04-07T09:25:44.000Z","published_at":"2017-10-16T01:45: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\u003eGiven an age and a name, give draw an ASCII birthday cake. For example, given the name \\\"CODY\\\" and the age 5, return a string with the following (no trailing spaces)\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[   6 6 6 6 6\\n   | | | | |\\n __|_|_|_|_|__\\n{             }\\n{             }\\n{    CODY     }\\n{             }\\n{_____________}]]\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\u003eThis uses 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://www.mathworks.com/help/matlab/ref/string.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003estring datatype\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, not a char array.\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":44316,"title":"Pandigital Multiples of 11 (based on Project Euler 491)","description":"A \"Pandigital number of order X\" is one that contains all of the numbers from 0 to X, but with no leading zeroes. If X\u003e9, the cycle 0-9 repeats itself. For example, 2310 is a Pandigital number of order 3 (0-3), while 120345678901 is a Pandigital number of order 11, with the \"01\" at the end of the number representing 10 and 11, respectively (10 and 11 mod 10, essentially). 0321 is not a Pandigital number, as it has a leading zero.\r\n\r\nGiven a number X, determine how many pandigital numbers of that order are divisible by 11.  You do not need to return the numbers themselves, just how many of them there are.","description_html":"\u003cp\u003eA \"Pandigital number of order X\" is one that contains all of the numbers from 0 to X, but with no leading zeroes. If X\u0026gt;9, the cycle 0-9 repeats itself. For example, 2310 is a Pandigital number of order 3 (0-3), while 120345678901 is a Pandigital number of order 11, with the \"01\" at the end of the number representing 10 and 11, respectively (10 and 11 mod 10, essentially). 0321 is not a Pandigital number, as it has a leading zero.\u003c/p\u003e\u003cp\u003eGiven a number X, determine how many pandigital numbers of that order are divisible by 11.  You do not need to return the numbers themselves, just how many of them there are.\u003c/p\u003e","function_template":"function y = pandigitalby11(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 2;y_correct = 0;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\nx = 3;y_correct = 6;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\nx = 7;y_correct = 4032;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\np6=pandigitalby11(6);\r\np8=pandigitalby11(8);\r\np9=pandigitalby11(9);\r\n\r\nassert(p8\u003ep6);\r\nassert(p9\u003ep8);\r\n\r\nf6=factor(p6);\r\nf8=factor(p8);\r\nf9=factor(p9);\r\nf9e1=f9(end-1);\r\n\r\nassert(p6\u003e256);\r\nassert(max(f9)\u003cmax(f8));\r\nassert(f9e1\u003emax(f6));\r\nassert(numel(f9)\u003enumel(f8));\r\n%%\r\nx = 11;y_correct = 9072000;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\nx = 14;y_correct = 3216477600;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\nassert(isequal(pandigitalby11(16),222911740800))","published":true,"deleted":false,"likes_count":5,"comments_count":15,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":53,"test_suite_updated_at":"2017-10-23T01:32:05.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-12T15:26:05.000Z","updated_at":"2026-02-03T09:29:47.000Z","published_at":"2017-10-16T01:50:58.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eA \\\"Pandigital number of order X\\\" is one that contains all of the numbers from 0 to X, but with no leading zeroes. If X\u0026gt;9, the cycle 0-9 repeats itself. For example, 2310 is a Pandigital number of order 3 (0-3), while 120345678901 is a Pandigital number of order 11, with the \\\"01\\\" at the end of the number representing 10 and 11, respectively (10 and 11 mod 10, essentially). 0321 is not a Pandigital number, as it has a leading 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a number X, determine how many pandigital numbers of that order are divisible by 11. You do not need to return the numbers themselves, just how many of them there are.\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":44345,"title":"MATLAB Counter","description":"Write a function f = counter(x0,b) to construct a counter handle f that counts with an initial value x0 and a step size b. \r\n\r\nE.g.,\r\n\r\n  \u003e\u003e f = counter(0,1)  % Initialize a counter f() with initial_count = 0 and step_size = 1\r\n  \u003e\u003e f()\r\n  ans =\r\n       0\r\n  \u003e\u003e f()\r\n  ans =\r\n       1\r\n  \u003e\u003e f()\r\n  ans =\r\n       2\r\n\r\n\r\n","description_html":"\u003cp\u003eWrite a function f = counter(x0,b) to construct a counter handle f that counts with an initial value x0 and a step size b.\u003c/p\u003e\u003cp\u003eE.g.,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e\u0026gt;\u0026gt; f = counter(0,1)  % Initialize a counter f() with initial_count = 0 and step_size = 1\r\n\u0026gt;\u0026gt; f()\r\nans =\r\n     0\r\n\u0026gt;\u0026gt; f()\r\nans =\r\n     1\r\n\u0026gt;\u0026gt; f()\r\nans =\r\n     2\r\n\u003c/pre\u003e","function_template":"function y = counter(x,b)\r\n  y = x;\r\nend","test_suite":"%%\r\nassessFunctionAbsence({'regexp','regexpi','regexprep','str2num'},'FileName','counter.m')\r\n\r\n%%\r\nf = counter(0,1);\r\nassert(isequal(f(),0))\r\nassert(isequal(f(),1))\r\nassert(isequal(2,f()))\r\nassert(isequal(3,f()))\r\n\r\n%%\r\nf = counter(1,0);\r\nassert(isequal(f(),1))\r\nassert(isequal(f(),1))\r\nassert(isequal(1,f()))\r\nassert(isequal(1,f()))\r\n\r\n%%\r\nf = counter(10,2);\r\nassert(isequal(f(),10))\r\nassert(isequal(f(),12))\r\nassert(isequal(14,f()))\r\nassert(isequal(16,f()))\r\n\r\n%%\r\nf = counter(0,5);\r\ny_correct = [0, 5, 10, 15, 20, 55];\r\nassert(isequal([f() f() f() f() f() f()+f()],y_correct))\r\n\r\n%%\r\nx0 = randi(10);\r\nb = randi(10);\r\nf = counter(x0,b);\r\ny_correct = x0 + (0:1000)*b;\r\nassert(isequal(arrayfun(@(n)f(),0:1000),y_correct))","published":true,"deleted":false,"likes_count":23,"comments_count":9,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":301,"test_suite_updated_at":"2017-10-17T00:19:49.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-24T01:58:21.000Z","updated_at":"2026-04-13T19:23:03.000Z","published_at":"2017-10-16T01:45:08.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 f = counter(x0,b) to construct a counter handle f that counts with an initial value x0 and a step size b.\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\u003eE.g.,\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[\u003e\u003e f = counter(0,1)  % Initialize a counter f() with initial_count = 0 and step_size = 1\\n\u003e\u003e f()\\nans =\\n     0\\n\u003e\u003e f()\\nans =\\n     1\\n\u003e\u003e f()\\nans =\\n     2]]\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":44374,"title":"Tautology","description":"Check if the given expression is always true. For example, the sentence\r\n\r\n  '~(A \u0026 B) == (~A | ~B)'\r\n\r\nis always true.\r\n\r\nCharacters in the input sequences may include *~ \u0026 | == ( )*, whitespace, 0 for false, 1 for true and letters for variables.","description_html":"\u003cp\u003eCheck if the given expression is always true. For example, the sentence\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e'~(A \u0026 B) == (~A | ~B)'\r\n\u003c/pre\u003e\u003cp\u003eis always true.\u003c/p\u003e\u003cp\u003eCharacters in the input sequences may include \u003cb\u003e~ \u0026 | == ( )\u003c/b\u003e, whitespace, 0 for false, 1 for true and letters for variables.\u003c/p\u003e","function_template":"function y = tautology(x)\r\n  y = true;\r\nend","test_suite":"%%\r\nx = '0';\r\ny_correct = false;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = '1';\r\ny_correct = true;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = 'A';\r\ny_correct = false;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = '~A';\r\ny_correct = false;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = 'A|1';\r\ny_correct = true;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = '1\u0026A';\r\ny_correct = false;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = 'A|B';\r\ny_correct = false;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = 'A\u0026B';\r\ny_correct = false;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = 'A|A';\r\ny_correct = false;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = 'A|~A';\r\ny_correct = true;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = '0==0';\r\ny_correct = true;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = '~0';\r\ny_correct = true;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = '~(A \u0026 B) == (~A | ~B)';\r\ny_correct = true;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = '~(Z \u0026 Y) == (~Y | ~Z)';\r\ny_correct = true;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = 'A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|X|V|W|Y|Z';\r\ny_correct = false;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = 'A|B|C|D|E|F|G|H|I|J|K|L|M|~A|O|P|Q|R|S|T|U|X|V|W|Y|Z';\r\ny_correct = true;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nassert(isequal(tautology('(A|B)|C'),false));\r\n%%\r\nassert(isequal(tautology('(A|B)|(C == C)'),true));\r\n%%\r\nassert(isequal(tautology('(A == B)|(B == C)|(C == A)'),true));\r\n%%\r\nassert(isequal(tautology('~(~(~(~(~(~(0))))))'),false)); \r\n%%\r\nassert(isequal(tautology('~(~(~(~(~(~(~0))))))'),true));\r\n% provided by Alfonso:\r\nassert(isequal(tautology('((0\u00261)|~B)\u0026~B'),false)); \r\n%%\r\nassert(isequal(tautology('((0\u0026~B)\u0026~B)'),false)); \r\n%%\r\nassert(isequal(tautology('((0|A)\u0026~A)'),false)); \r\n%%\r\nassert(isequal(tautology('((0|A)|1)'),true)); \r\n%%\r\nassert(isequal(tautology('((0|~B)|1)'),true)); \r\n%%\r\nassert(isequal(tautology('((1\u00260)|B)'),false)); \r\n%%\r\nassert(isequal(tautology('((1\u00261)\u0026A)'),false)); \r\n%%\r\nassert(isequal(tautology('((1|0)|A)'),true)); \r\n%%\r\nassert(isequal(tautology('((1|A)|0)'),true)); \r\n%%\r\nassert(isequal(tautology('((1|~A)\u0026B)'),false)); \r\n%%\r\nassert(isequal(tautology('((A\u00261)|~A)|A'),true)); \r\n%%\r\nassert(isequal(tautology('((A\u0026~A)\u0026~B)|~A'),false)); \r\n%%\r\nassert(isequal(tautology('((A\u0026~B)\u00261)|B'),false)); \r\n%%\r\nassert(isequal(tautology('((A|0)\u00261)\u0026~B'),false)); \r\n%%\r\nassert(isequal(tautology('((A|A)\u0026A)|~A'),true)); \r\n%%\r\nassert(isequal(tautology('((B|0)\u0026B)'),false)); \r\n%%\r\nassert(isequal(tautology('((B|1)\u0026B)\u0026A'),false)); \r\n%%\r\nassert(isequal(tautology('((B|A)|~A)'),true)); \r\n%%\r\nassert(isequal(tautology('((~A\u0026~A)\u00260)\u0026B'),false)); \r\n%%\r\nassert(isequal(tautology('((~A\u0026~A)|0)'),false)); \r\n%%\r\nassert(isequal(tautology('((~A\u0026~A)|~A)|1'),true)); \r\n%%\r\nassert(isequal(tautology('((~A|A)|~B)\u00261'),true)); \r\n%%\r\nassert(isequal(tautology('((~A|B)|A)'),true)); \r\n%%\r\nassert(isequal(tautology('((~A|~A)|1)'),true)); \r\n%%\r\nassert(isequal(tautology('((~A|~B)\u00260)'),false)); \r\n%%\r\nassert(isequal(tautology('((~B\u00260)\u0026A)'),false)); \r\n%%\r\nassert(isequal(tautology('(0\u00261)|1\u00261'),true)); \r\n%%\r\nassert(isequal(tautology('(0|~A\u0026B)'),false)); \r\n%%\r\nassert(isequal(tautology('(1|A\u00260)'),true)); \r\n%%\r\nassert(isequal(tautology('(A\u0026A\u0026~B)'),false)); \r\n%%\r\nassert(isequal(tautology('(A\u0026~A|1)'),true)); \r\n%%\r\nassert(isequal(tautology('(A|1)|B'),true)); \r\n%%\r\nassert(isequal(tautology('(A|A)|A|1'),true)); \r\n%%\r\nassert(isequal(tautology('(B\u00261)|~B'),true)); \r\n%%\r\nassert(isequal(tautology('(B\u0026~B)\u0026~B\u00260'),false)); \r\n%%\r\nassert(isequal(tautology('(B|~B)|B'),true)); \r\n%%\r\nassert(isequal(tautology('(~A\u0026B\u00260)'),false)); \r\n%%\r\nassert(isequal(tautology('(~A|0)|~B\u0026~A'),false)); \r\n%%\r\nassert(isequal(tautology('(~A|1)|1'),true)); \r\n%%\r\nassert(isequal(tautology('(~A|B\u0026B)'),false)); \r\n%%\r\nassert(isequal(tautology('(~A|B)|~B'),true)); \r\n%%\r\nassert(isequal(tautology('(~A|~A)|0'),false)); \r\n%%\r\nassert(isequal(tautology('(~B\u00260)\u00261|1'),true)); \r\n%%\r\nassert(isequal(tautology('1\u0026B|~B|0'),true)); \r\n%%\r\nassert(isequal(tautology('B\u00261\u0026A\u00261'),false)); \r\n%%\r\nassert(isequal(tautology('~A\u00260\u00261|1'),true)); \r\n%%\r\nassert(isequal(tautology('~B\u00260\u0026~A|B'),false)); \r\n%%\r\nassert(isequal(tautology('~B|1|1|~B'),true)); \r\n%%\r\nassert(isequal(tautology('~B|~B\u00261|1'),true));\r\n%%\r\nassert(isequal(tautology('A==~A'),false));\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":30,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":44,"test_suite_updated_at":"2017-10-31T07:45:16.000Z","rescore_all_solutions":true,"group_id":35,"created_at":"2017-10-10T23:20:08.000Z","updated_at":"2026-02-03T08:59:32.000Z","published_at":"2017-10-16T01:51:01.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\u003eCheck if the given expression is always true. For example, the sentence\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['~(A \u0026 B) == (~A | ~B)']]\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\u003eis always true.\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\u003eCharacters in the input sequences may include\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~ \u0026amp; | == ( )\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, whitespace, 0 for false, 1 for true and letters for variables.\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":44382,"title":"Parse me a Lisp","description":"*Description*\r\n\r\nIn Lisp and its variants, function calls are done using parenthesis where the first item in the parenthesis is the function being called and the following items are arguments to the function. Given a mathematical ( |+ - * /| ) expression using this notation, return the result. Note: In Lisp, functions that normally take only two arguments can be called with many arguments, with the function being applied to all elements from left to right.\r\n\r\n*Simple example*\r\n\r\n  (+ 1 1 1 1 1)\r\n\r\nwould give 5.\r\n\r\n*Complicated example*\r\n\r\n  (* (* 10 (+ 1 4)) (+ 10 (/ 12 2 3) 1) 0.1)\r\n\r\nwould give 65.","description_html":"\u003cp\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/p\u003e\u003cp\u003eIn Lisp and its variants, function calls are done using parenthesis where the first item in the parenthesis is the function being called and the following items are arguments to the function. Given a mathematical ( \u003ctt\u003e+ - * /\u003c/tt\u003e ) expression using this notation, return the result. Note: In Lisp, functions that normally take only two arguments can be called with many arguments, with the function being applied to all elements from left to right.\u003c/p\u003e\u003cp\u003e\u003cb\u003eSimple example\u003c/b\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e(+ 1 1 1 1 1)\r\n\u003c/pre\u003e\u003cp\u003ewould give 5.\u003c/p\u003e\u003cp\u003e\u003cb\u003eComplicated example\u003c/b\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e(* (* 10 (+ 1 4)) (+ 10 (/ 12 2 3) 1) 0.1)\r\n\u003c/pre\u003e\u003cp\u003ewould give 65.\u003c/p\u003e","function_template":"function x = eval_lisp(s)\r\n    x = s\r\nend","test_suite":"%%\r\nexpr = \"(+ 1 1 1 1 1)\";\r\nassert(isequal(eval_lisp(expr), 5));\r\n\r\n%%\r\nexpr = \"(+ 1 5)\";\r\nassert(isequal(eval_lisp(expr), 6));\r\n\r\n%%\r\nexpr = \"(+ 1 1 1 1 1 1 1 1 1 1 1 1 1)\";\r\nassert(isequal(eval_lisp(expr), 13));\r\n\r\n%%\r\nexpr = \"(+ 1 2 3 4 5 6 7 8 9 10)\";\r\nassert(isequal(eval_lisp(expr), 55));\r\n\r\n%%\r\nexpr = \"(* 1 2 3 4 5 6 7 8 9 10)\";\r\nassert(isequal(eval_lisp(expr), 3628800));\r\n\r\n%%\r\nexpr = \"(* (* 10 (+ 1 4)) (+ 10 (/ 12 2 3) 1) 0.1)\";\r\nassert(isequal(eval_lisp(expr), 65));\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":4,"created_by":134,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":89,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-12T20:43:01.000Z","updated_at":"2026-02-03T07:40:05.000Z","published_at":"2017-10-16T01:51:02.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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eDescription\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\u003eIn Lisp and its variants, function calls are done using parenthesis where the first item in the parenthesis is the function being called and the following items are arguments to the function. Given a mathematical (\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e+ - * /\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ) expression using this notation, return the result. Note: In Lisp, functions that normally take only two arguments can be called with many arguments, with the function being applied to all elements from left to right.\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSimple 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[(+ 1 1 1 1 1)]]\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\u003ewould give 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eComplicated 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[(* (* 10 (+ 1 4)) (+ 10 (/ 12 2 3) 1) 0.1)]]\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\u003ewould give 65.\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":44347,"title":"Ned's queens","description":"A tribute to Cody's five-year anniversary should also celebrate the people behind Cody, and in this particular case, our illustrious Quizmaster, Ned Gulley.\r\n\r\nThe N-Queens problem (N stands for Ned, of course) is a well known computing challenge. If you are unfamiliar with this problem, refer to \u003chttps://www.mathworks.com/matlabcentral/cody/problems/113-n-queens-checker Problem 113\u003e, incidentally written by... You guessed it.\r\n\r\nThis problem is the real deal. Given a positive integer, n, representing the number of queens and the size of the board, return the number of possible solutions, s, and a list of the solutions, q.\r\n\r\nq shall be an array with s rows and n columns, such that each row represents one solution. The column indeces of q shall represent the column indeces of the positions of the queens in the respective solution, while the values of the array elements shall represent the row indeces of the positions of the queens in the respective solution. q does not have to be sorted.\r\n\r\nNote: All symmetries/rotations count as individual solutions.\r\n\r\nExample:\r\n\r\n Input: n = 4\r\n\r\n Output: s = 2, q = [2 4 1 3;3 1 4 2]","description_html":"\u003cp\u003eA tribute to Cody's five-year anniversary should also celebrate the people behind Cody, and in this particular case, our illustrious Quizmaster, Ned Gulley.\u003c/p\u003e\u003cp\u003eThe N-Queens problem (N stands for Ned, of course) is a well known computing challenge. If you are unfamiliar with this problem, refer to \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/113-n-queens-checker\"\u003eProblem 113\u003c/a\u003e, incidentally written by... You guessed it.\u003c/p\u003e\u003cp\u003eThis problem is the real deal. Given a positive integer, n, representing the number of queens and the size of the board, return the number of possible solutions, s, and a list of the solutions, q.\u003c/p\u003e\u003cp\u003eq shall be an array with s rows and n columns, such that each row represents one solution. The column indeces of q shall represent the column indeces of the positions of the queens in the respective solution, while the values of the array elements shall represent the row indeces of the positions of the queens in the respective solution. q does not have to be sorted.\u003c/p\u003e\u003cp\u003eNote: All symmetries/rotations count as individual solutions.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e Input: n = 4\u003c/pre\u003e\u003cpre\u003e Output: s = 2, q = [2 4 1 3;3 1 4 2]\u003c/pre\u003e","function_template":"function [s, q] = nqueens(n)\r\n    s = n;\r\n    q = 1:n;\r\nend","test_suite":"%%\r\nn = 1;\r\ns_correct = 1;\r\nq_correct = 1;\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isequal(sortrows(q),sortrows(q_correct)))\r\n\r\n%%\r\nn = 2;\r\ns_correct = 0;\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isempty(q))\r\n\r\n%%\r\nn = 3;\r\ns_correct = 0;\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isempty(q))\r\n\r\n%%\r\nn = 4;\r\ns_correct = 2;\r\nq_correct = [3  1  4  2;2  4  1  3]\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isequal(sortrows(q),sortrows(q_correct)))\r\n\r\n%%\r\nn = 5;\r\ns_correct = 10;\r\nq_correct = [5  3  1  4  2;5  2  4  1  3;4  2  5  3  1;4  1  3  5  2;3  5  2  4  1;3  1  4  2  5;2  4  1  3  5;2  5  3  1  4;1  4  2  5  3;1  3  5  2  4];\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isequal(sortrows(q),sortrows(q_correct)))\r\n\r\n%%\r\nn = 6;\r\ns_correct = 4;\r\nq_correct = [5  3  1  6  4  2;4  1  5  2  6  3;3  6  2  5  1  4;2  4  6  1  3  5];\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isequal(sortrows(q),sortrows(q_correct)))\r\n\r\n%%\r\nn = 7;\r\ns_correct = 40;\r\nq_correct = [7  5  3  1  6  4  2;7  4  1  5  2  6  3;7  3  6  2  5  1  4;7  2  4  6  1  3  5;6  4  7  1  3  5  2;6  4  2  7  5  3  1;6  3  5  7  1  4  2;6  3  7  4  1  5  2;6  3  1  4  7  5  2;6  2  5  1  4  7  3;6  1  3  5  7  2  4;5  7  2  4  6  1  3;5  7  2  6  3  1  4;5  3  1  6  4  2  7;5  2  6  3  7  4  1;5  1  4  7  3  6  2;5  1  6  4  2  7  3;4  6  1  3  5  7  2;4  7  5  2  6  1  3;4  7  3  6  2  5  1;4  2  7  5  3  1  6;4  1  5  2  6  3  7;4  1  3  6  2  7  5;3  6  2  5  1  4  7;3  5  7  2  4  6  1;3  7  4  1  5  2  6;3  7  2  4  6  1  5;3  1  6  4  2  7  5;3  1  6  2  5  7  4;2  6  3  7  4  1  5;2  5  3  1  7  4  6;2  5  7  4  1  3  6;2  5  1  4  7  3  6;2  4  6  1  3  5  7;2  4  1  7  5  3  6;2  7  5  3  1  6  4;1  6  4  2  7  5  3;1  5  2  6  3  7  4;1  4  7  3  6  2  5;1  3  5  7  2  4  6];\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isequal(sortrows(q),sortrows(q_correct)))\r\n\r\n%%\r\nn = 8;\r\ns_correct = 92;\r\nq_correct = [8  4  1  3  6  2  7  5\r\n8  3  1  6  2  5  7  4;8  2  5  3  1  7  4  6;8  2  4  1  7  5  3  6;7  5  3  1  6  8  2  4;7  4  2  5  8  1  3  6;7  4  2  8  6  1  3  5;7  3  8  2  5  1  6  4;7  3  1  6  8  5  2  4;7  2  6  3  1  4  8  5;7  2  4  1  8  5  3  6;7  1  3  8  6  4  2  5;6  8  2  4  1  7  5  3;6  4  7  1  8  2  5  3;6  4  7  1  3  5  2  8;6  4  2  8  5  7  1  3;6  4  1  5  8  2  7  3;6  3  5  8  1  4  2  7;6  3  5  7  1  4  2  8;6  3  7  4  1  8  2  5;6  3  7  2  4  8  1  5;6  3  7  2  8  5  1  4;6  3  1  7  5  8  2  4;6  3  1  8  4  2  7  5;6  3  1  8  5  2  4  7;6  2  7  1  4  8  5  3;6  2  7  1  3  5  8  4;6  1  5  2  8  3  7  4;5  7  4  1  3  8  6  2;5  7  2  4  8  1  3  6;5  7  2  6  3  1  8  4;5  7  2  6  3  1  4  8;5  7  1  4  2  8  6  3;5  7  1  3  8  6  4  2;5  8  4  1  3  6  2  7;5  8  4  1  7  2  6  3;5  3  8  4  7  1  6  2;5  3  1  7  2  8  6  4;5  3  1  6  8  2  4  7;5  2  6  1  7  4  8  3;5  2  8  1  4  7  3  6;5  2  4  6  8  3  1  7;5  2  4  7  3  8  6  1;5  1  8  6  3  7  2  4;5  1  8  4  2  7  3  6;5  1  4  6  8  2  7  3;4  7  5  3  1  6  8  2;4  7  5  2  6  1  3  8;4  7  3  8  2  5  1  6;4  7  1  8  5  2  6  3;4  6  8  3  1  7  5  2;4  6  8  2  7  1  3  5;4  6  1  5  2  8  3  7;4  8  5  3  1  7  2  6;4  8  1  5  7  2  6  3;4  8  1  3  6  2  7  5;4  2  5  8  6  1  3  7;4  2  8  5  7  1  3  6;4  2  8  6  1  3  5  7;4  2  7  5  1  8  6  3;4  2  7  3  6  8  5  1;4  2  7  3  6  8  1  5;4  1  5  8  6  3  7  2;4  1  5  8  2  7  3  6;3  7  2  8  5  1  4  6;3  7  2  8  6  4  1  5;3  6  4  2  8  5  7  1;3  6  4  1  8  5  7  2;3  6  8  2  4  1  7  5;3  6  8  1  4  7  5  2;3  6  8  1  5  7  2  4;3  6  2  5  8  1  7  4;3  6  2  7  5  1  8  4;3  6  2  7  1  4  8  5;3  5  7  1  4  2  8  6;3  5  8  4  1  7  2  6;3  5  2  8  6  4  7  1;3  5  2  8  1  7  4  6;3  8  4  7  1  6  2  5;3  1  7  5  8  2  4  6;2  7  5  8  1  4  6  3;2  7  3  6  8  5  1  4;2  6  8  3  1  4  7  5;2  6  1  7  4  8  3  5;2  5  7  4  1  8  6  3;2  5  7  1  3  8  6  4;2  4  6  8  3  1  7  5;2  8  6  1  3  5  7  4;1  7  5  8  2  4  6  3;1  7  4  6  8  2  5  3;1  6  8  3  7  4  2  5;1  5  8  6  3  7  2  4];\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isequal(sortrows(q),sortrows(q_correct)))\r\n\r\n%%\r\nn = 9;\r\ns_correct = 352;\r\nq_correct = [9  7  4  2  8  6  1  3  5;9  7  3  8  2  5  1  6  4;9  7  2  4  1  8  5  3  6;9  6  8  2  4  1  7  5  3;9  6  4  7  1  8  2  5  3;9  6  4  2  8  5  7  1  3;9  6  3  7  2  8  5  1  4;9  6  3  1  8  5  2  4  7;9  6  2  7  1  3  5  8  4;9  5  8  4  1  7  2  6  3;9  5  3  8  4  7  1  6  2;9  5  3  1  7  2  8  6  4;9  5  3  1  6  8  2  4  7;9  5  1  8  4  2  7  3  6;9  5  1  4  6  8  2  7  3;9  4  6  8  3  1  7  5  2;9  4  6  8  2  7  1  3  5;9  4  8  1  3  6  2  7  5;9  4  2  5  8  6  1  3  7;9  4  2  7  3  6  8  1  5;9  4  1  5  8  2  7  3  6;9  3  6  4  1  8  5  7  2;9  3  6  2  7  5  1  8  4;9  3  6  2  7  1  4  8  5;9  3  5  2  8  1  7  4  6;9  2  6  8  3  1  4  7  5;9  2  5  7  4  1  8  6  3;9  2  5  7  1  3  8  6  4;8  6  9  3  1  4  7  5  2;8  6  3  9  7  1  4  2  5;8  6  2  7  1  4  9  5  3;8  6  1  3  5  7  9  4  2;8  6  1  3  7  9  4  2  5;8  5  3  6  9  7  1  4  2;8  5  3  9  7  2  4  6  1;8  5  3  1  7  4  6  9  2;8  5  3  1  6  2  9  7  4;8  5  2  9  7  4  1  3  6;8  5  2  9  1  4  7  3  6;8  5  2  4  1  7  9  6  3;8  5  2  4  1  7  9  3  6;8  5  1  6  9  2  4  7  3;8  4  7  9  2  6  1  3  5;8  4  9  7  3  1  6  2  5;8  4  9  3  5  7  1  6  2;8  4  9  3  6  2  7  5  1;8  4  9  1  5  2  6  3  7;8  4  1  7  5  2  6  9  3;8  3  5  9  1  6  4  2  7;8  3  5  2  9  6  4  7  1;8  3  1  4  7  9  6  2  5;8  2  5  7  1  4  6  9  3;8  2  4  1  7  9  6  3  5;8  2  9  6  3  1  4  7  5;8  1  5  7  2  6  3  9  4;8  1  4  6  3  9  7  5  2;8  1  4  7  5  2  9  6  3;8  1  4  7  3  6  9  2  5;7  9  6  3  1  8  5  2  4;7  9  4  2  5  8  6  1  3;7  9  3  5  2  8  6  4  1;7  9  3  8  2  4  6  1  5;7  9  2  6  1  3  5  8  4;7  9  1  3  5  8  2  4  6;7  5  8  2  9  3  6  4  1;7  5  8  2  9  6  3  1  4;7  5  3  9  6  8  2  4  1;7  5  2  8  1  4  9  3  6;7  5  2  8  1  3  9  6  4;7  5  1  6  9  3  8  4  2;7  5  1  8  6  3  9  2  4;7  4  8  3  9  6  2  5  1;7  4  8  1  5  9  2  6  3;7  4  2  5  8  1  3  6  9;7  4  2  5  9  1  3  8  6;7  4  2  8  6  1  3  5  9;7  4  2  9  5  1  8  6  3;7  4  2  9  6  3  5  8  1;7  4  1  5  2  9  6  8  3;7  4  1  8  5  3  6  9  2;7  4  1  8  2  9  6  3  5;7  4  1  3  8  6  2  9  5;7  4  1  3  6  9  2  8  5;7  4  1  3  9  6  8  5  2;7  4  1  9  2  6  8  3  5;7  3  6  8  1  4  9  5  2;7  3  6  8  1  5  9  2  4;7  3  6  2  5  1  9  4  8;7  3  8  6  2  9  5  1  4;7  3  8  2  5  1  9  4  6;7  3  8  2  4  6  9  5  1;7  3  1  6  8  5  2  4  9;7  3  1  9  5  8  2  4  6;7  2  6  3  1  8  5  9  4;7  2  4  6  1  9  5  3  8;7  2  4  9  1  8  5  3  6;7  2  4  1  8  5  9  6  3;7  2  8  6  1  3  5  9  4;7  1  6  9  2  4  8  3  5;7  1  6  2  5  8  4  9  3;7  1  6  8  2  4  9  3  5;7  1  4  6  9  3  5  8  2;7  1  4  2  8  6  9  3  5;7  1  4  8  5  3  9  6  2;7  1  8  5  2  9  3  6  4;6  8  5  2  9  7  4  1  3;6  8  3  7  9  2  5  1  4;6  8  3  1  9  2  5  7  4;6  8  3  1  9  5  2  4  7;6  8  2  7  1  3  5  9  4;6  8  1  5  9  2  4  7  3;6  8  1  7  4  2  9  5  3;6  9  7  4  1  8  2  5  3;6  9  5  8  1  3  7  2  4;6  9  5  2  8  3  7  4  1;6  9  5  1  8  4  2  7  3;6  9  3  1  8  4  2  7  5;6  9  1  4  7  3  8  2  5;6  4  7  1  8  5  2  9  3;6  4  7  1  8  2  5  3  9;6  4  7  1  3  9  2  8  5;6  4  9  5  8  2  7  3  1;6  4  9  1  5  2  8  3  7;6  4  9  1  3  7  2  8  5;6  4  2  8  5  9  1  3  7;6  4  2  8  5  3  1  9  7;6  4  2  8  3  9  7  5  1;6  4  2  7  9  3  5  8  1;6  4  1  7  9  2  8  5  3;6  3  7  4  1  9  2  5  8;6  3  7  2  4  8  1  5  9;6  3  7  2  4  9  1  8  5;6  3  7  2  8  5  1  4  9;6  3  9  7  1  4  2  5  8;6  3  9  4  1  8  2  5  7;6  3  9  2  5  8  1  7  4;6  3  5  8  1  4  2  7  9;6  3  5  8  1  9  4  2  7;6  3  5  8  1  9  7  2  4;6  3  1  4  7  9  2  5  8;6  3  1  8  5  2  9  7  4;6  3  1  8  4  9  7  5  2;6  2  9  5  3  8  4  7  1;6  2  5  7  9  4  8  1  3;6  2  5  7  9  3  8  4  1;6  1  7  4  8  3  5  9  2;6  1  5  7  9  4  2  8  3;6  1  5  7  9  3  8  2  4;6  1  5  2  9  7  4  8  3;5  8  6  9  3  1  7  4  2;5  8  6  1  3  7  9  4  2;5  8  4  9  7  3  1  6  2;5  8  4  1  7  2  6  3  9;5  8  4  1  3  6  9  7  2;5  8  2  9  6  3  1  4  7;5  8  2  9  3  1  7  4  6;5  8  2  7  3  6  9  1  4;5  8  2  7  3  1  9  4  6;5  8  1  9  4  2  7  3  6;5  8  1  4  7  3  6  9  2;5  7  9  4  8  1  3  6  2;5  7  9  4  2  8  6  3  1;5  7  9  3  8  2  4  6  1;5  7  4  1  8  2  9  6  3;5  7  4  1  3  8  6  2  9;5  7  4  1  3  9  6  8  2;5  7  4  1  3  6  9  2  8;5  7  2  6  3  1  8  4  9;5  7  2  6  8  1  4  9  3;5  7  2  4  8  1  3  9  6;5  7  2  4  8  1  9  6  3;5  7  1  6  8  2  4  9  3;5  7  1  4  2  8  6  9  3;5  9  4  6  8  2  7  1  3;5  9  2  6  8  3  1  4  7;5  9  2  4  7  3  8  6  1;5  3  6  9  7  4  1  8  2;5  3  6  9  7  2  4  8  1;5  3  6  9  7  1  4  2  8;5  3  6  9  2  8  1  4  7;5  3  9  6  8  2  4  1  7;5  3  9  4  2  8  6  1  7;5  3  8  6  2  9  7  1  4;5  3  8  6  2  9  1  4  7;5  3  8  4  7  9  2  6  1;5  3  8  4  2  9  6  1  7;5  3  1  6  8  2  4  7  9;5  3  1  6  2  9  7  4  8;5  3  1  7  2  8  6  4  9;5  2  6  9  7  4  1  3  8;5  2  6  9  3  8  4  7  1;5  2  6  1  3  7  9  4  8;5  2  9  6  3  7  4  1  8;5  2  9  1  6  8  3  7  4;5  2  4  9  7  3  1  6  8;5  2  4  1  7  9  3  6  8;5  2  8  3  7  4  1  9  6;5  2  8  3  7  9  1  6  4;5  2  8  1  4  7  9  6  3;5  2  8  1  7  9  3  6  4;5  1  6  4  2  8  3  9  7;5  1  8  6  3  7  2  4  9;5  1  8  4  2  7  9  6  3;4  8  5  3  1  6  2  9  7;4  8  5  3  1  7  2  6  9;4  8  1  5  7  2  6  3  9;4  7  5  2  9  6  8  3  1;4  7  5  2  9  1  3  8  6;4  7  5  2  9  1  6  8  3;4  7  9  6  3  1  8  5  2;4  7  9  2  5  8  1  3  6;4  7  9  2  6  1  3  5  8;4  7  3  6  9  1  8  5  2;4  7  3  8  6  2  9  5  1;4  7  3  8  6  1  9  2  5;4  7  3  8  2  5  9  6  1;4  7  1  6  9  2  8  5  3;4  7  1  3  9  6  8  5  2;4  7  1  8  5  2  9  3  6;4  6  8  3  1  7  5  2  9;4  6  8  2  5  7  9  1  3;4  6  8  2  5  1  9  7  3;4  6  8  2  7  1  3  5  9;4  6  9  3  1  8  2  5  7;4  6  3  9  7  1  8  2  5;4  6  3  9  2  8  5  7  1;4  6  3  9  2  5  8  1  7;4  6  1  5  2  8  3  7  9;4  6  1  9  5  8  2  7  3;4  6  1  9  7  3  8  2  5;4  9  5  8  1  3  6  2  7;4  9  5  3  1  6  8  2  7;4  9  5  3  1  7  2  8  6;4  9  3  6  2  7  5  1  8;4  2  7  9  1  8  5  3  6;4  2  7  9  1  5  8  6  3;4  2  7  3  1  8  5  9  6;4  2  5  8  1  3  6  9  7;4  2  9  5  1  8  6  3  7;4  2  9  3  6  8  1  5  7;4  2  8  3  9  7  5  1  6;4  1  7  9  2  6  8  3  5;4  1  5  9  2  6  8  3  7;4  1  5  2  9  7  3  8  6;4  1  5  8  2  7  3  6  9;4  1  9  6  3  7  2  8  5;4  1  3  6  9  2  8  5  7;3  8  6  4  9  1  5  7  2;3  8  6  9  2  5  1  4  7;3  8  6  1  9  2  5  7  4;3  8  4  7  9  2  5  1  6;3  8  2  4  9  7  5  1  6;3  7  4  8  5  9  1  6  2;3  7  4  2  9  5  1  8  6;3  7  4  2  9  6  1  5  8;3  7  9  4  2  5  8  6  1;3  7  9  1  5  2  8  6  4;3  7  2  4  8  1  5  9  6;3  7  2  8  5  9  1  6  4;3  7  2  8  6  4  1  5  9;3  6  8  5  2  9  7  4  1;3  6  8  5  1  9  7  2  4;3  6  8  2  4  9  7  5  1;3  6  8  1  5  9  2  4  7;3  6  8  1  4  7  5  2  9;3  6  9  5  8  1  4  2  7;3  6  9  7  4  1  8  2  5;3  6  9  7  2  4  8  1  5;3  6  9  7  1  4  2  5  8;3  6  9  2  5  7  4  1  8;3  6  9  2  8  1  4  7  5;3  6  9  1  8  4  2  7  5;3  6  2  9  5  1  8  4  7;3  6  2  7  1  4  8  5  9;3  5  7  1  4  2  8  6  9;3  5  8  2  9  7  1  4  6;3  5  8  2  9  6  1  7  4;3  5  9  4  1  7  2  6  8;3  5  9  2  4  7  1  8  6;3  5  2  8  1  4  7  9  6;3  5  2  8  1  7  4  6  9;3  9  6  4  1  7  5  2  8;3  9  6  8  2  4  1  7  5;3  9  6  2  5  7  1  4  8;3  9  4  8  5  2  6  1  7;3  9  4  2  8  6  1  7  5;3  9  4  1  8  6  2  7  5;3  9  2  5  8  1  7  4  6;3  1  7  5  8  2  4  6  9;3  1  7  2  8  6  4  9  5;3  1  6  8  5  2  4  9  7;3  1  4  7  9  2  5  8  6;3  1  9  7  5  2  8  6  4;3  1  8  4  9  7  5  2  6;2  8  6  9  3  1  4  7  5;2  8  5  3  9  6  4  1  7;2  8  1  4  7  9  6  3  5;2  7  5  8  1  4  6  3  9;2  7  5  1  9  4  6  8  3;2  7  9  6  3  1  4  8  5;2  6  3  1  8  4  9  7  5;2  6  9  3  5  8  4  1  7;2  6  1  3  7  9  4  8  5;2  6  1  9  5  8  4  7  3;2  6  1  7  5  3  9  4  8;2  6  1  7  4  8  3  5  9;2  5  7  4  1  3  9  6  8;2  5  7  9  4  8  1  3  6;2  5  7  9  3  6  4  1  8;2  5  7  1  3  8  6  4  9;2  5  8  6  9  3  1  7  4;2  5  8  6  9  3  1  4  7;2  5  8  1  3  6  9  7  4;2  5  8  1  9  6  3  7  4;2  5  9  4  1  8  6  3  7;2  4  7  1  3  9  6  8  5;2  4  8  3  9  6  1  5  7;2  4  9  7  5  3  1  6  8;2  4  9  7  3  1  6  8  5;2  4  1  7  9  6  3  5  8;2  9  6  4  7  1  3  5  8;2  9  6  3  5  8  1  4  7;2  9  6  3  7  4  1  8  5;2  9  5  3  8  4  7  1  6;1  8  5  3  6  9  2  4  7;1  8  5  3  9  7  2  4  6;1  8  4  2  7  9  6  3  5;1  7  5  8  2  9  3  6  4;1  7  4  6  9  2  5  3  8;1  7  4  8  3  5  9  2  6;1  7  4  8  3  9  6  2  5;1  6  8  5  2  4  9  7  3;1  6  8  3  7  4  2  9  5;1  6  4  2  7  9  3  5  8;1  6  4  2  8  3  9  7  5;1  6  2  9  7  4  8  3  5;1  6  9  5  2  8  3  7  4;1  5  7  2  6  3  9  4  8;1  5  7  9  4  2  8  6  3;1  5  7  9  3  8  2  4  6;1  5  2  6  9  3  8  4  7;1  5  9  6  4  2  8  3  7;1  5  9  2  6  8  3  7  4;1  4  7  3  8  2  5  9  6;1  4  7  9  2  5  8  6  3;1  4  6  8  2  5  3  9  7;1  4  6  3  9  2  8  5  7;1  4  8  3  9  7  5  2  6;1  4  2  8  6  9  3  5  7;1  3  7  2  8  5  9  4  6;1  3  6  8  2  4  9  7  5;1  3  8  6  9  2  5  7  4];\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isequal(sortrows(q),sortrows(q_correct)))","published":true,"deleted":false,"likes_count":6,"comments_count":1,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":92,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-24T19:13:26.000Z","updated_at":"2026-02-03T09:18:46.000Z","published_at":"2017-10-16T01:51:00.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\u003eA tribute to Cody's five-year anniversary should also celebrate the people behind Cody, and in this particular case, our illustrious Quizmaster, Ned Gulley.\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 N-Queens problem (N stands for Ned, of course) is a well known computing challenge. If you are unfamiliar with this problem, refer 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=\\\"https://www.mathworks.com/matlabcentral/cody/problems/113-n-queens-checker\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 113\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, incidentally written by... You guessed it.\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\u003eThis problem is the real deal. Given a positive integer, n, representing the number of queens and the size of the board, return the number of possible solutions, s, and a list of the solutions, q.\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\u003eq shall be an array with s rows and n columns, such that each row represents one solution. The column indeces of q shall represent the column indeces of the positions of the queens in the respective solution, while the values of the array elements shall represent the row indeces of the positions of the queens in the respective solution. q does not have to be sorted.\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\u003eNote: All symmetries/rotations count as individual solutions.\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\u003eExample:\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[ Input: n = 4\\n\\n Output: s = 2, q = [2 4 1 3;3 1 4 2]]]\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":44343,"title":"Pair Primes","description":"Let's define pair primes as follow;\r\nFor 2 digits numbers: 11 and 17 are pair primes because both of them are 2 digits prime numbers and last digit of the first prime equals to the first digit of second prime number. 11 and 11 are not pair primes because a = b.\r\nFor 3 digit numbers: 389 and 967 are pair primes because both of them are 3 digits prime numbers and last digit of the first prime equals to the first digit of the second prime number (797 and 797 are not pair primes because a = b). 467 and 673 are pair primes too because the last two digits of the first prime number (67) equals to the first two digit (67) of the second prime number. 211 and 113 are pair primes too but they satisfy two conditions: last digit of the first prime equals to the first digit of the second prime also last two digits of the first prime equals to the first two digits of the first prime.\r\nFor 4 digit numbers:\r\n1-) 1637 and 7549 are pair primes. First ends with 7 and second starts with 7.\r\n2-) 6221 and 2113 are pair primes. First ends with 21 and second starts with 21.\r\n3-) 1429 and 4297 are pair primes. First ends with 429 and second starts with 429. You should be careful. 2111 and 1117 are also four digit pair primes. It satisfies three conditions. First ends with 1 and second starts with 1. First ends with 11 and second starts with 11. First ends with 111 and second starts with 111. [2111 1117] pair should be counted for once.\r\nGiven the digit counts, can you determine how many unique pair primes are there (a~=b)","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: 387.9px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 193.95px; transform-origin: 407px 193.95px; 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: 104.5px 8px; transform-origin: 104.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eLet's define pair primes as follow;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 183.9px; 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 91.95px; transform-origin: 391px 91.95px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 40.8667px; 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 20.4333px; text-align: left; transform-origin: 363px 20.4333px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 74.5px 8px; transform-origin: 74.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eFor 2 digits numbers:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 283.5px 8px; transform-origin: 283.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e 11 and 17 are pair primes because both of them are 2 digits prime numbers and last digit of the first prime equals to the first digit of second prime number. 11 and 11 are not pair primes because a = b.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 122.6px; 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 61.3px; text-align: left; transform-origin: 363px 61.3px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 70.5px 8px; transform-origin: 70.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eFor 3 digit numbers:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 292px 8px; transform-origin: 292px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e 389 and 967 are pair primes because both of them are 3 digits prime numbers and last digit of the first prime equals to the first digit of the second prime number (797 and 797 are not pair primes because a = b). 467 and 673 are pair primes too because the last two digits of the first prime number (67) equals to the first two digit (67) of the second prime number. 211 and 113 are pair primes too but they satisfy two conditions: last digit of the first prime equals to the first digit of the second prime also last two digits of the first prime equals to the first two digits of the first prime.\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: 70.5px 8px; transform-origin: 70.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eFor 4 digit numbers:\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: 244.5px 8px; transform-origin: 244.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1-) 1637 and 7549 are pair primes. First ends with 7 and second starts with 7.\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: 252px 8px; transform-origin: 252px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e2-) 6221 and 2113 are pair primes. First ends with 21 and second starts with 21.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 63px; 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 31.5px; text-align: left; transform-origin: 384px 31.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: 383px 8px; transform-origin: 383px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e3-) 1429 and 4297 are pair primes. First ends with 429 and second starts with 429. You should be careful. 2111 and 1117 are also four digit pair primes. It satisfies three conditions. First ends with 1 and second starts with 1. First ends with 11 and second starts with 11. First ends with 111 and second starts with 111. [2111 1117] pair should be counted for once.\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: 279px 8px; transform-origin: 279px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven the digit counts, can you determine how many unique pair primes are there (a~=b)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = pairPrimes(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nfiletext = fileread('pairPrimes.m');\r\nillegal = contains(filetext, 'regexp') || contains(filetext, 'interp1') || ...\r\n          contains(filetext, 'elseif') || contains(filetext, 'str2num'); \r\nassert(~illegal)\r\n\r\n%%\r\nx = 2;\r\ny_correct = 51;\r\nassert(isequal(pairPrimes(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[51,2485,136162,8578934]),regexp(fileread('pairPrimes.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 3;\r\ny_correct = 2485;\r\nassert(isequal(pairPrimes(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[51,2485,136162,8578934]),regexp(fileread('pairPrimes.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 4;\r\ny_correct = 136162;\r\nassert(isequal(pairPrimes(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[51,2485,136162,8578934]),regexp(fileread('pairPrimes.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 5;\r\ny_correct = 8578934;\r\nassert(isequal(pairPrimes(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[51,2485,136162,8578934]),regexp(fileread('pairPrimes.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n","published":true,"deleted":false,"likes_count":9,"comments_count":5,"created_by":8703,"edited_by":223089,"edited_at":"2022-10-11T06:50:24.000Z","deleted_by":null,"deleted_at":null,"solvers_count":105,"test_suite_updated_at":"2022-10-11T06:50:24.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-22T08:07:44.000Z","updated_at":"2026-02-03T07:36:30.000Z","published_at":"2017-10-16T01:50:59.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\u003eLet's define pair primes as follow;\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eFor 2 digits numbers:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 11 and 17 are pair primes because both of them are 2 digits prime numbers and last digit of the first prime equals to the first digit of second prime number. 11 and 11 are not pair primes because a = b.\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eFor 3 digit numbers:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 389 and 967 are pair primes because both of them are 3 digits prime numbers and last digit of the first prime equals to the first digit of the second prime number (797 and 797 are not pair primes because a = b). 467 and 673 are pair primes too because the last two digits of the first prime number (67) equals to the first two digit (67) of the second prime number. 211 and 113 are pair primes too but they satisfy two conditions: last digit of the first prime equals to the first digit of the second prime also last two digits of the first prime equals to the first two digits of the first prime.\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eFor 4 digit numbers:\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\u003e1-) 1637 and 7549 are pair primes. First ends with 7 and second starts with 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2-) 6221 and 2113 are pair primes. First ends with 21 and second starts with 21.\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\u003e3-) 1429 and 4297 are pair primes. First ends with 429 and second starts with 429. You should be careful. 2111 and 1117 are also four digit pair primes. It satisfies three conditions. First ends with 1 and second starts with 1. First ends with 11 and second starts with 11. First ends with 111 and second starts with 111. [2111 1117] pair should be counted for once.\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\u003eGiven the digit counts, can you determine how many unique pair primes are there (a~=b)\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\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":369,"title":"Basic electricity in a dry situation","description":"\u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \r\n\r\nThis is a very hypothetical situation between two individuals in a very dry atmosphere. \r\n\r\nHe came running in rubber boots when she was combing her hair. \r\n\r\nAround N number of electrons moved from one person to the other upon contact. \r\n\r\nWhat was the voltage between them before the contact? \r\n\r\nAssume it is a simple RC type electrical circuit with equivalent capacitance of about 16 pico farads. \r\n\r\nPlease assume that every electron carries about 160 zepto coulombs.\r\n\r\nFor more info on capacitors: \u003chttps://en.wikipedia.org/wiki/Capacitor\u003e","description_html":"\u003cp\u003e\u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889 \u0026#9889\u003c/p\u003e\u003cp\u003eThis is a very hypothetical situation between two individuals in a very dry atmosphere.\u003c/p\u003e\u003cp\u003eHe came running in rubber boots when she was combing her hair.\u003c/p\u003e\u003cp\u003eAround N number of electrons moved from one person to the other upon contact.\u003c/p\u003e\u003cp\u003eWhat was the voltage between them before the contact?\u003c/p\u003e\u003cp\u003eAssume it is a simple RC type electrical circuit with equivalent capacitance of about 16 pico farads.\u003c/p\u003e\u003cp\u003ePlease assume that every electron carries about 160 zepto coulombs.\u003c/p\u003e\u003cp\u003eFor more info on capacitors: \u003ca href = \"https://en.wikipedia.org/wiki/Capacitor\"\u003ehttps://en.wikipedia.org/wiki/Capacitor\u003c/a\u003e\u003c/p\u003e","function_template":"function V = volts(N)\r\n  V = 10000;\r\nend","test_suite":"%%\r\nN = 10^10;\r\nV = 150;\r\nassert(volts(N)\u003eV/pi)\r\n%%\r\nN = 10^11;\r\nV = 700;\r\nassert(volts(N)\u003cV*pi)\r\n%%\r\nN = 10^12;\r\nV = 10000;\r\nassert(volts(N)\u003eV/sqrt(pi))\r\n","published":true,"deleted":false,"likes_count":8,"comments_count":4,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":596,"test_suite_updated_at":"2012-02-20T20:05:18.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2012-02-20T20:05:18.000Z","updated_at":"2026-04-07T19:14:18.000Z","published_at":"2017-10-16T01:45: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\u003e\u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889 \u0026amp;#9889\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\u003eThis is a very hypothetical situation between two individuals in a very dry atmosphere.\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\u003eHe came running in rubber boots when she was combing her hair.\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\u003eAround N number of electrons moved from one person to the other upon contact.\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\u003eWhat was the voltage between them before the contact?\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\u003eAssume it is a simple RC type electrical circuit with equivalent capacitance of about 16 pico farads.\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\u003ePlease assume that every electron carries about 160 zepto coulombs.\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 more info on capacitors:\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/Capacitor\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://en.wikipedia.org/wiki/Capacitor\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\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":361,"title":"Energy of a photon","description":"\u0026#9883 \u0026#9762 \u0026#9883 \u0026#9762 \u0026#9883 \u0026#9762 \u0026#9883\r\nGiven the frequency F of a photon in giga hertz.\r\nFind energy E of this photon in giga electron volts.\r\nAssume h, Planck's constant is about 4 femto electron-volt-second.\r\nTo maximize benefits, it may help not looking at the Test Suite before trying any solution!\r\nFor more info: \u003chttps://en.wikipedia.org/wiki/Planck_constant\u003e","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: 171px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 85.5px; transform-origin: 407px 85.5px; 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: 187px 8px; transform-origin: 187px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003e\u0026amp;#9883 \u0026amp;#9762 \u0026amp;#9883 \u0026amp;#9762 \u0026amp;#9883 \u0026amp;#9762 \u0026amp;#9883\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: 151px 8px; transform-origin: 151px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven the frequency F of a photon in giga hertz.\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: 158.5px 8px; transform-origin: 158.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFind energy E of this photon in giga electron volts.\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: 211px 8px; transform-origin: 211px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAssume h, Planck's constant is about 4 femto electron-volt-second.\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: 276.5px 8px; transform-origin: 276.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eTo maximize benefits, it may help not looking at the Test Suite before trying any solution!\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: 44.5px 8px; transform-origin: 44.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor more info:\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 = \"https://en.wikipedia.org/wiki/Planck_constant\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u0026lt;https://en.wikipedia.org/wiki/Planck_constant\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: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u0026gt;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function E = photon_energy(F)\r\n  E=100/F;\r\nend","test_suite":"%%\r\nF = 1;\r\nE_correct = 3/10^15;\r\nassert(photon_energy(F)\u003eE_correct)\r\n%%\r\nF = 100;\r\nE_correct = 500/10^15;\r\nassert(photon_energy(F)\u003cE_correct)\r\n%%\r\nF = 500;\r\nE_correct = 2100/10^15;\r\nassert(photon_energy(F)\u003cE_correct)\r\n%%\r\nF = 420;\r\nE_correct = 1680/10^15;\r\nassert(isequal(photon_energy(F),E_correct))\r\n%%\r\nF = 0.25;\r\nE_correct = 1e-15;\r\nassert(isequal(photon_energy(F),E_correct))","published":true,"deleted":false,"likes_count":15,"comments_count":11,"created_by":166,"edited_by":223089,"edited_at":"2022-12-24T15:16:49.000Z","deleted_by":null,"deleted_at":null,"solvers_count":1465,"test_suite_updated_at":"2022-12-24T15:16:49.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2012-02-19T23:13:56.000Z","updated_at":"2026-04-01T13:59:42.000Z","published_at":"2017-10-16T01:45:05.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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u0026amp;#9883 \u0026amp;#9762 \u0026amp;#9883 \u0026amp;#9762 \u0026amp;#9883 \u0026amp;#9762 \u0026amp;#9883\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\u003eGiven the frequency F of a photon in giga hertz.\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\u003eFind energy E of this photon in giga electron volts.\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\u003eAssume h, Planck's constant is about 4 femto electron-volt-second.\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\u003eTo maximize benefits, it may help not looking at the Test Suite before trying any solution!\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\u003eFor more info:\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/Planck_constant\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://en.wikipedia.org/wiki/Planck_constant\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\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":44315,"title":"Predicting life and death of a memory-less light bulb","description":"*\u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161* \r\n\r\nYou have a light bulb that can fail any moment according to the exponential probability distribution. \r\n\r\nAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant. \r\n\r\nNotice that this probability is very small if N is very large. \r\n\r\nNow suppose, the bulb has already survived N hours. \r\n\r\nPlease calculate the probability of its surviving M more hours.\r\n","description_html":"\u003cp\u003e\u003cb\u003e\u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161\u003c/b\u003e\u003c/p\u003e\u003cp\u003eYou have a light bulb that can fail any moment according to the exponential probability distribution.\u003c/p\u003e\u003cp\u003eAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant.\u003c/p\u003e\u003cp\u003eNotice that this probability is very small if N is very large.\u003c/p\u003e\u003cp\u003eNow suppose, the bulb has already survived N hours.\u003c/p\u003e\u003cp\u003ePlease calculate the probability of its surviving M more hours.\u003c/p\u003e","function_template":"function hope = fate(N,P,M)\r\n  hope=exp(-(N+M)*P);\r\nend","test_suite":"%%\r\nN = 1;\r\nP=1;\r\nM=0;\r\nhope_correct = 1;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN = 1;\r\nP=0;\r\nM=1;\r\nhope_correct = 1;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=1;\r\nP=1;\r\nM=1;\r\nhope_correct = 0.3679;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=2;\r\nP=1;\r\nM=1;\r\nhope_correct = 0.3679;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=2;\r\nP=1;\r\nM=2;\r\nhope_correct = 0.1353;\r\nassert(fate(N,P,M)\u003chope_correct*1.1)\r\n%%\r\nN=2;\r\nP=2;\r\nM=2;\r\nhope_correct = 0.0183;\r\nassert(fate(N,P,M)\u003chope_correct*1.1)\r\n%%","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":336,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-12T02:53:45.000Z","updated_at":"2026-03-25T02:55:11.000Z","published_at":"2017-10-16T01:45: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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161\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\u003eYou have a light bulb that can fail any moment according to the exponential probability distribution.\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\u003eAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant.\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\u003eNotice that this probability is very small if N is very large.\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\u003eNow suppose, the bulb has already survived N hours.\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\u003ePlease calculate the probability of its surviving M more hours.\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":2736,"title":"Pernicious Anniversary Problem","description":"Since Cody is 5 years old, it's pernicious. A \u003chttp://rosettacode.org/wiki/Pernicious_numbers Pernicious number\u003e is an integer whose population count is a prime. Check if the given number is pernicious.","description_html":"\u003cp\u003eSince Cody is 5 years old, it's pernicious. A \u003ca href = \"http://rosettacode.org/wiki/Pernicious_numbers\"\u003ePernicious number\u003c/a\u003e is an integer whose population count is a prime. Check if the given number is pernicious.\u003c/p\u003e","function_template":"function y = isPernicious(x)\r\n  y = false;\r\nend","test_suite":"%%\r\nx = 5;\r\ny_correct = true;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 1;\r\ny_correct = false;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 2^randi(16);\r\ny_correct = false;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 17;\r\ny_correct = true;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 18;\r\ny_correct = true;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 61;\r\ny_correct = true;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 6;\r\ny_correct = true;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 2115;\r\ny_correct = false;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 2114;\r\ny_correct = true;\r\nassert(isequal(isPernicious(x),y_correct))\r\n%%\r\nx = 2017;\r\ny_correct = true;\r\nassert(isequal(isPernicious(x),y_correct))\r\n\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":13,"comments_count":1,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":838,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2014-12-08T08:48:45.000Z","updated_at":"2026-04-10T14:31:08.000Z","published_at":"2017-10-16T01:45:06.000Z","restored_at":"2017-10-25T14:37:50.000Z","restored_by":null,"spam":false,"simulink":false,"admin_reviewed":true,"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\u003eSince Cody is 5 years old, it's pernicious. 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://rosettacode.org/wiki/Pernicious_numbers\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePernicious number\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is an integer whose population count is a prime. Check if the given number is pernicious.\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":44370,"title":"Octoberfest festival","description":"A group of students decided to visit Octoberfest festival. First they ordered one beer, then after half-hour they taken one more, after one more half-hour they ordered two more beers like sum of previous two times. Then after having spend a good time and anoter half an hour they ordered three beers. The situation went on. Task: calculate how many beers they ordered after n half-hours for given n - number of half-hours.\r\n\r\nExample:\r\n\r\nn=1 result will be 2;\r\n\r\nn=2 result will be 4.","description_html":"\u003cp\u003eA group of students decided to visit Octoberfest festival. First they ordered one beer, then after half-hour they taken one more, after one more half-hour they ordered two more beers like sum of previous two times. Then after having spend a good time and anoter half an hour they ordered three beers. The situation went on. Task: calculate how many beers they ordered after n half-hours for given n - number of half-hours.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003en=1 result will be 2;\u003c/p\u003e\u003cp\u003en=2 result will be 4.\u003c/p\u003e","function_template":"function totalNumberOfOrderedBeers = OctoberfestFestival(n)  \r\n  totalNumberOfOrderedBeers=n\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 2;\r\nassert(isequal(OctoberfestFestival(x),y_correct))\r\n%%\r\nx = 5;\r\ny_correct = 20;\r\nassert(isequal(OctoberfestFestival(x),y_correct))\r\n%%\r\nx = 10;\r\ny_correct = 232;\r\nassert(isequal(OctoberfestFestival(x),y_correct))","published":true,"deleted":false,"likes_count":4,"comments_count":11,"created_by":90467,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":498,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-10T19:33:58.000Z","updated_at":"2026-03-18T12:47:33.000Z","published_at":"2017-10-16T01:45: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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eA group of students decided to visit Octoberfest festival. First they ordered one beer, then after half-hour they taken one more, after one more half-hour they ordered two more beers like sum of previous two times. Then after having spend a good time and anoter half an hour they ordered three beers. The situation went on. Task: calculate how many beers they ordered after n half-hours for given n - number of half-hours.\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:\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\u003en=1 result will be 2;\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\u003en=2 result will be 4.\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":44314,"title":"A Simple Tide Gauge with MATLAB","description":"*\u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767* \r\n\r\nYou are standing in a few inches of sea water on a beach.\r\n\r\nYou are wondering whether the high tide is coming soon or it has just passed. \r\n\r\nTherefore, you will write a code in MATLAB to analyze following data. \r\n\r\nYou followed the sequence of water lines left by several swash of waves. \r\n\r\nThe data array A contains the distances the water traveled past your feet during each upward swash of waves. \r\n\r\nYour code will return 1 if the high tide is coming soon. \r\n\r\nYour code will return 0 if the high tide has just passed.    \r\n","description_html":"\u003cp\u003e\u003cb\u003e\u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767 \u0026#8767\u003c/b\u003e\u003c/p\u003e\u003cp\u003eYou are standing in a few inches of sea water on a beach.\u003c/p\u003e\u003cp\u003eYou are wondering whether the high tide is coming soon or it has just passed.\u003c/p\u003e\u003cp\u003eTherefore, you will write a code in MATLAB to analyze following data.\u003c/p\u003e\u003cp\u003eYou followed the sequence of water lines left by several swash of waves.\u003c/p\u003e\u003cp\u003eThe data array A contains the distances the water traveled past your feet during each upward swash of waves.\u003c/p\u003e\u003cp\u003eYour code will return 1 if the high tide is coming soon.\u003c/p\u003e\u003cp\u003eYour code will return 0 if the high tide has just passed.\u003c/p\u003e","function_template":"function tide = gauge(A)\r\n  tide=max(A)-min(A);\r\n  tide=tide*0;\r\nend","test_suite":"%%\r\nA = [5 8 10 12 8 13 14 10 10 15];\r\ntide_correct = 1;\r\nassert(isequal(gauge(A),tide_correct))\r\n%%\r\nA = [15 16 11 9 10 15 7 12 6 11 5 6];\r\ntide_correct = 0;\r\nassert(isequal(gauge(A),tide_correct))\r\n%%\r\nA = [9 15 3 9 5 18 4 17 18 19 8 13 12 21 17 24];\r\ntide_correct = 1;\r\nassert(isequal(gauge(A),tide_correct))\r\n%%\r\nA = [22 12 22 12 9 14 17 16 15 8 13 6 10 7 13 3];\r\ntide_correct = 0;\r\nassert(isequal(gauge(A),tide_correct))\r\n%%\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":3,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":394,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-12T00:26:53.000Z","updated_at":"2026-03-25T04:12:58.000Z","published_at":"2017-10-16T01:45: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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u0026amp;#8767 \u0026amp;#8767 \u0026amp;#8767 \u0026amp;#8767 \u0026amp;#8767 \u0026amp;#8767 \u0026amp;#8767 \u0026amp;#8767\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\u003eYou are standing in a few inches of sea water on a beach.\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\u003eYou are wondering whether the high tide is coming soon or it has just passed.\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\u003eTherefore, you will write a code in MATLAB to analyze following data.\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\u003eYou followed the sequence of water lines left by several swash of waves.\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 data array A contains the distances the water traveled past your feet during each upward swash of waves.\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 code will return 1 if the high tide is coming soon.\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 code will return 0 if the high tide has just passed.\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":564,"title":"How to subtract?","description":"*\u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn* \r\n\r\n* Imagine you need to subtract one number from another using MATLAB.\r\n* You will not be using eval for this task.\r\n* Given two ASCII strings representing two integers X and Y.\r\n* Each of them has only 12 or less ASCII characters.\r\n* Each of them represents signed integers, such as '+2345'\r\n* Please output the result of (X-Y) in a similar style.","description_html":"\u003cp\u003e\u003cb\u003e\u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn \u0026plusmn\u003c/b\u003e\u003c/p\u003e\u003cul\u003e\u003cli\u003eImagine you need to subtract one number from another using MATLAB.\u003c/li\u003e\u003cli\u003eYou will not be using eval for this task.\u003c/li\u003e\u003cli\u003eGiven two ASCII strings representing two integers X and Y.\u003c/li\u003e\u003cli\u003eEach of them has only 12 or less ASCII characters.\u003c/li\u003e\u003cli\u003eEach of them represents signed integers, such as '+2345'\u003c/li\u003e\u003cli\u003ePlease output the result of (X-Y) in a similar style.\u003c/li\u003e\u003c/ul\u003e","function_template":"function Z = mysub(X,Y)\r\n   Z = 0;\r\nend\r\n","test_suite":"%%\r\nX='+68768686834554';\r\nY='+76574535435398';\r\nZ_correct='-7805848600844';\r\nassert(isequal(mysub(X,Y),Z_correct))\r\n\r\n%%\r\nX='+1';\r\nY='+2';\r\nZ_correct ='-1';\r\nassert(isequal(mysub(X,Y),Z_correct))\r\n\r\n%%\r\nX='+100';\r\nY='+20';\r\nZ_correct ='+80';\r\nassert(isequal(mysub(X,Y),Z_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":11,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1536,"test_suite_updated_at":"2017-10-16T20:04:25.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2012-04-08T02:27:39.000Z","updated_at":"2026-04-13T22:37:20.000Z","published_at":"2017-10-16T01:45: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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn \u0026amp;plusmn\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\u003eImagine you need to subtract one number from another using MATLAB.\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\u003eYou will not be using eval for this task.\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\u003eGiven two ASCII strings representing two integers X and Y.\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\u003eEach of them has only 12 or less ASCII characters.\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\u003eEach of them represents signed integers, such as '+2345'\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\u003ePlease output the result of (X-Y) in a similar style.\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":44369,"title":"Circle/Pentagon Overlap","description":"Your function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The function should return the number of pentagon vertices that lie within or on the circle. The tolerance for lying on the circle is 0.02.","description_html":"\u003cp\u003eYour function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The function should return the number of pentagon vertices that lie within or on the circle. The tolerance for lying on the circle is 0.02.\u003c/p\u003e","function_template":"function y = circle_pentagon_overlap(p,cp,r)\r\n y = 0;\r\nend","test_suite":"%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 5;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0];\r\nr = 4;\r\ny_correct = 0;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0];\r\nr = 15;\r\ny_correct = 5;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [2,0];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [2,0.75];\r\nr = 5;\r\ny_correct = 3;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [7.5,0];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,-5];\r\nr = 9;\r\ny_correct = 4;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 5;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [19,8];\r\nr = 5;\r\ny_correct = 3;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [19.5,10];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [19.5,10];\r\nr = 6.6;\r\ny_correct = 4;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [19.5,10];\r\nr = 7;\r\ny_correct = 5;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 5;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [26.97,28.45];\r\nr = 8;\r\ny_correct = 0;\r\nassert(isequal(circle_pentagon_overlap(p,cp,r),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":328,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-10T18:44:43.000Z","updated_at":"2026-04-07T14:02:38.000Z","published_at":"2017-10-16T01:45:09.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eYour function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The function should return the number of pentagon vertices that lie within or on the circle. The tolerance for lying on the circle is 0.02.\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":44358,"title":"I Plead the Fifth","description":"Write a function to provide a yes or no answer to the input string. However, it must plead the 5th amendment (return an empty string) if the number five or any variation thereof (e.g., fifth, fifty, fifteen, 5) is within the input string.","description_html":"\u003cp\u003eWrite a function to provide a yes or no answer to the input string. However, it must plead the 5th amendment (return an empty string) if the number five or any variation thereof (e.g., fifth, fifty, fifteen, 5) is within the input string.\u003c/p\u003e","function_template":"function answer = I_plead_the_fifth(question)\r\n str = 'yes/no';\r\nend","test_suite":"%%\r\nquestion = 'Are you the fifth child?';\r\nassert(isempty(I_plead_the_fifth(question)))\r\n\r\n%%\r\nquestion = 'Were you at home on the night of 24 Oct 1974?';\r\nassert(strcmpi(I_plead_the_fifth(question),'yes') || ...\r\n    strcmpi(I_plead_the_fifth(question),'no'))\r\n\r\n%%\r\nquestion = 'Did you go to work on 15 Oct 1955?';\r\nassert(isempty(I_plead_the_fifth(question)))\r\n\r\n%%\r\nquestion = 'Did you go to the bowling alley last week?';\r\nassert(strcmpi(I_plead_the_fifth(question),'yes') || ...\r\n    strcmpi(I_plead_the_fifth(question),'no'))\r\n\r\n%%\r\nquestion = 'Do you like bread?';\r\nassert(strcmpi(I_plead_the_fifth(question),'yes') || ...\r\n    strcmpi(I_plead_the_fifth(question),'no'))\r\n\r\n%%\r\nquestion = 'Are there five fingers on your right hand?';\r\nassert(isempty(I_plead_the_fifth(question)))\r\n\r\n%%\r\nquestion = 'Do you like pumpkins?';\r\nassert(strcmpi(I_plead_the_fifth(question),'yes') || ...\r\n    strcmpi(I_plead_the_fifth(question),'no'))\r\n\r\n%%\r\nquestion = 'Do you have fifteen siblings?';\r\nassert(isempty(I_plead_the_fifth(question)))\r\n\r\n%%\r\nquestion = 'Do two quarters equal fifty cents?';\r\nassert(isempty(I_plead_the_fifth(question)))\r\n\r\n%%\r\nquestion = 'Do you own five dogs?';\r\nassert(isempty(I_plead_the_fifth(question)))\r\n\r\n%%\r\nquestion = 'Is my name Harry?';\r\nassert(strcmpi(I_plead_the_fifth(question),'yes') || ...\r\n    strcmpi(I_plead_the_fifth(question),'no'))","published":true,"deleted":false,"likes_count":6,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":427,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-03T17:12:42.000Z","updated_at":"2026-03-22T03:30:09.000Z","published_at":"2017-10-16T01:45:09.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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 provide a yes or no answer to the input string. However, it must plead the 5th amendment (return an empty string) if the number five or any variation thereof (e.g., fifth, fifty, fifteen, 5) is within the input string.\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":44363,"title":"Is this is a Tic Tac Toe X Win?","description":"For the game of Tic Tac Toe we will be storing the state of the game in a matrix M.\r\nFor this game:\r\n\r\nWe would store the state as this:\r\n-1  1  1 \r\n 1 -1 -1\r\n 1 -1 -1\r\nIf there were any blanks squares, they would be 0;\r\nFor this challenge, given a game state, does X (1) have a three in a row on any row, column or major diagonal?","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: 243.3px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 121.65px; transform-origin: 407px 121.65px; 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: 50.5px 8px; transform-origin: 50.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor the game 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 = \"https://en.wikipedia.org/wiki/Tic-tac-toe\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eTic Tac Toe\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: 167.5px 8px; transform-origin: 167.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e we will be storing the state of the game in a matrix M.\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: 45.5px 8px; transform-origin: 45.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor this game:\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: 0px 8px; transform-origin: 0px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\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: 102.5px 8px; transform-origin: 102.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWe would store the state as this:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 30.65px; transform-origin: 404px 30.65px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 36px 8.5px; tab-size: 4; transform-origin: 36px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e-1  1  1 \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 32px 8.5px; tab-size: 4; transform-origin: 32px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e 1 -1 -1\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 32px 8.5px; tab-size: 4; transform-origin: 32px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e 1 -1 -1\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; 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: 158px 8px; transform-origin: 158px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf there were any blanks squares, they would be 0;\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: 349px 8px; transform-origin: 349px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor this challenge, given a game state, does X (1) have a three in a row on any row, column or major diagonal?\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function flagWin = your_fcn_name(M)\r\n  flagWin = false\r\nend","test_suite":"%%\r\nx = [1 1 1\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 0 0\r\n     0 1 0\r\n     0 0 1];\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 0 0\r\n     0 -1 0\r\n     1 0 1];\r\ny_correct = 0;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 0 0\r\n     1 0 0\r\n     1 0 0];\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 0 0\r\n     1 -1 0\r\n     1 0 0];\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [0 0 1\r\n     0 1 0\r\n     1 0 0];\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1  0 0\r\n     0 -1 0\r\n     0  0 1];\r\ny_correct = 0;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 0 0\r\n     0 1 0\r\n     0 0 1];\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [-1 0 0\r\n     0 -1 0\r\n     0 0 -1];\r\ny_correct = 0;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":240,"edited_by":223089,"edited_at":"2022-07-28T15:36:47.000Z","deleted_by":null,"deleted_at":null,"solvers_count":534,"test_suite_updated_at":"2022-07-28T15:36:47.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-09T23:11:43.000Z","updated_at":"2026-04-07T14:05:08.000Z","published_at":"2017-10-16T01:45:09.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\u003eFor the game 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=\\\"https://en.wikipedia.org/wiki/Tic-tac-toe\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eTic Tac Toe\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e we will be storing the state of the game in a matrix M.\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\u003eFor this game:\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\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWe would store the state as this:\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[-1  1  1 \\n 1 -1 -1\\n 1 -1 -1]]\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf there were any blanks squares, they would be 0;\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\u003eFor this challenge, given a game state, does X (1) have a three in a row on any row, column or major diagonal?\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":44384,"title":"Find the nearest prime number","description":"Happy 5th birthday, Cody! Since 5 is a prime number, let's have some fun looking for other prime numbers.\r\n\r\nGiven a positive integer x, find the nearest prime number. Keep in mind that the nearest prime may be less than x.\r\n\r\n*Examples*\r\n\r\n  nearestprime(5) = 5\r\n  nearestprime(36) = 37\r\n  nearestprime(200) = 199\r\n\r\nNOTE: You may ignore cases in which two prime numbers are equally close to x. (e.g., x=12 --\u003e 11 and 13 are both primes). ","description_html":"\u003cp\u003eHappy 5th birthday, Cody! Since 5 is a prime number, let's have some fun looking for other prime numbers.\u003c/p\u003e\u003cp\u003eGiven a positive integer x, find the nearest prime number. Keep in mind that the nearest prime may be less than x.\u003c/p\u003e\u003cp\u003e\u003cb\u003eExamples\u003c/b\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003enearestprime(5) = 5\r\nnearestprime(36) = 37\r\nnearestprime(200) = 199\r\n\u003c/pre\u003e\u003cp\u003eNOTE: You may ignore cases in which two prime numbers are equally close to x. (e.g., x=12 --\u0026gt; 11 and 13 are both primes).\u003c/p\u003e","function_template":"function y = nearestprime(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 0;\r\ny_correct = 2;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = 5;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 100;\r\ny_correct = 101;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 500;\r\ny_correct = 499;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 911;\r\ny_correct = 911;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 2500;\r\ny_correct = 2503;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 8000;\r\ny_correct = 7993;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 100000;\r\ny_correct = 100003;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 1300000;\r\ny_correct = 1299989;\r\nassert(isequal(nearestprime(x),y_correct))\r\n\r\n%%\r\nx = 179424710;\r\ny_correct = 179424719;\r\nassert(isequal(nearestprime(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":9,"comments_count":1,"created_by":4793,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":664,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-13T19:42:15.000Z","updated_at":"2026-04-07T15:16:58.000Z","published_at":"2017-10-16T01:45: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\u003eHappy 5th birthday, Cody! Since 5 is a prime number, let's have some fun looking for other prime numbers.\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\u003eGiven a positive integer x, find the nearest prime number. Keep in mind that the nearest prime may be less than 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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExamples\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[nearestprime(5) = 5\\nnearestprime(36) = 37\\nnearestprime(200) = 199]]\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\u003eNOTE: You may ignore cases in which two prime numbers are equally close to x. (e.g., x=12 --\u0026gt; 11 and 13 are both primes).\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":44385,"title":"Extra safe primes","description":"Did you know that the number 5 is the first safe prime? A safe prime is a prime number that can be expressed as 2p+1, where p is also a prime.\r\n\r\nTo celebrate Cody's Five-Year Anniversary, write a function to determine if a positive integer n is a safe prime in which the prime p (such that n=2p+1) is *also a safe prime*.\r\n\r\n*Examples*\r\n\r\n  isextrasafe(5) = false % because 5=2*2+1 and 2 is not a safe prime\r\n  isextrasafe(23) = true % because 23=2*11+1 and 11 is also a safe prime (11=2*5+1)\r\n","description_html":"\u003cp\u003eDid you know that the number 5 is the first safe prime? A safe prime is a prime number that can be expressed as 2p+1, where p is also a prime.\u003c/p\u003e\u003cp\u003eTo celebrate Cody's Five-Year Anniversary, write a function to determine if a positive integer n is a safe prime in which the prime p (such that n=2p+1) is \u003cb\u003ealso a safe prime\u003c/b\u003e.\u003c/p\u003e\u003cp\u003e\u003cb\u003eExamples\u003c/b\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eisextrasafe(5) = false % because 5=2*2+1 and 2 is not a safe prime\r\nisextrasafe(23) = true % because 23=2*11+1 and 11 is also a safe prime (11=2*5+1)\r\n\u003c/pre\u003e","function_template":"function tf = isextrasafe(x)\r\n    tf = false;\r\nend","test_suite":"%%\r\nx = 0;\r\nassert(isequal(isextrasafe(x),false))\r\n\r\n%%\r\nx = 5;\r\nassert(isequal(isextrasafe(x),false))\r\n\r\n%%\r\nx = 7;\r\nassert(isequal(isextrasafe(x),false))\r\n\r\n%%\r\nx = 11;\r\nassert(isequal(isextrasafe(x),true))\r\n\r\n%%\r\nx = 15;\r\nassert(isequal(isextrasafe(x),false))\r\n\r\n%%\r\nx = 23;\r\nassert(isequal(isextrasafe(x),true))\r\n\r\n%%\r\nx = 71;\r\nassert(isequal(isextrasafe(x),false))\r\n\r\n%%\r\nx = 719;\r\nassert(isequal(isextrasafe(x),true))\r\n\r\n%%\r\nx = 2039;\r\nassert(isequal(isextrasafe(x),true))\r\n\r\n%%\r\nx = 2040;\r\nassert(isequal(isextrasafe(x),false))\r\n\r\n%%\r\nx = 5807;\r\nassert(isequal(isextrasafe(x),true))","published":true,"deleted":false,"likes_count":13,"comments_count":4,"created_by":4793,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":757,"test_suite_updated_at":"2017-10-19T17:09:19.000Z","rescore_all_solutions":true,"group_id":34,"created_at":"2017-10-13T20:02:13.000Z","updated_at":"2026-04-10T14:37:08.000Z","published_at":"2017-10-16T01:45: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\u003eDid you know that the number 5 is the first safe prime? A safe prime is a prime number that can be expressed as 2p+1, where p is also a prime.\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\u003eTo celebrate Cody's Five-Year Anniversary, write a function to determine if a positive integer n is a safe prime in which the prime p (such that n=2p+1) is\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\u003ealso a safe prime\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExamples\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[isextrasafe(5) = false % because 5=2*2+1 and 2 is not a safe prime\\nisextrasafe(23) = true % because 23=2*11+1 and 11 is also a safe prime (11=2*5+1)]]\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":44319,"title":"Write c^3 as sum of two squares a^2+b^2","description":"write c^3 as sum of two squares a^2+b^2. a and b must be integer and greater than zero.\r\n\r\nFor example \r\n\r\n 5^3 = 2^2 + 11^2\r\n 5^3 = 5^2 + 10^2\r\n 10^3 = 10^2 + 30^2\r\n 10^3 = 18^2 + 26^2\r\n\r\nsort output matrix so that each row and first column is in ascending order.","description_html":"\u003cp\u003ewrite c^3 as sum of two squares a^2+b^2. a and b must be integer and greater than zero.\u003c/p\u003e\u003cp\u003eFor example\u003c/p\u003e\u003cpre\u003e 5^3 = 2^2 + 11^2\r\n 5^3 = 5^2 + 10^2\r\n 10^3 = 10^2 + 30^2\r\n 10^3 = 18^2 + 26^2\u003c/pre\u003e\u003cp\u003esort output matrix so that each row and first column is in ascending order.\u003c/p\u003e","function_template":"function y = sumoftwosquares(c)\r\n\r\nend","test_suite":"%%\r\nc = 1;\r\ny_correct = [];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 5;\r\ny_correct = [2 11; 5 10];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 6;\r\ny_correct = [];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 10;\r\ny_correct = [10 30; 18 26];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 20;\r\ny_correct = [16 88; 40 80];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 24;\r\ny_correct = [];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 40;\r\ny_correct = [80 240; 144 208];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 65;\r\ny_correct = [7 524; 65 520; 140 505; 191 488; 208 481; 260 455; 320 415; 364 377];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 100;\r\ny_correct = [280 960; 352 936; 600 800];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 123;\r\ny_correct = [];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 340;\r\ny_correct = [408 6256;1360 6120; 1680 6040; 2280 5840; 2584 5712; 3304 5328; 3824 4968; 4080 4760];\r\nassert(isequal(sumoftwosquares(c),y_correct))\r\n\r\n%%\r\nc = 500;\r\ny_correct = [1160 11120; 2000 11000; 5000 10000; 5744 9592; 7600 8200];\r\nassert(isequal(sumoftwosquares(c),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":329,"test_suite_updated_at":"2017-10-16T17:19:22.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-12T19:54:46.000Z","updated_at":"2026-04-01T13:09:32.000Z","published_at":"2017-10-16T01:45: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 c^3 as sum of two squares a^2+b^2. a and b must be integer and greater than 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\u003eFor 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[ 5^3 = 2^2 + 11^2\\n 5^3 = 5^2 + 10^2\\n 10^3 = 10^2 + 30^2\\n 10^3 = 18^2 + 26^2]]\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\u003esort output matrix so that each row and first column is in ascending order.\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":44342,"title":"Spot the First Occurrence of 5","description":"This problem series invites you to solve two simple problems related to the integer NUMBER FIVE, in order to celebrate \u003chttps://www.mathworks.com/matlabcentral/cody/contests/1?s_tid=Cody5YA_cody_home Cody's 5th birthday\u003e. \r\n\r\nIn this problem, let's determine the position (index) of the first occurrence of 5 along the first non-singleton dimension of an input array. \r\n\r\nE.g., \r\n\r\n* If the input is a vector, return the index of the first occurrence of 5. \r\n\r\n  x = [1 2 5 3 5];\r\n  y = 3;\r\n\r\n* If the input is a matrix, return the index of the first occurrence of 5 in each column. If 5 is not found, simply return 0; \r\n\r\n  % Input x is a matrix\r\n  x = [1 2 5\r\n       5 9 1\r\n       5 6 5];\r\n\r\n  % Output y\r\n  y = [2 0 1];\r\n\r\nNext problem in this series: \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44352-the-top-5-primes The Top 5 Primes\u003e","description_html":"\u003cp\u003eThis problem series invites you to solve two simple problems related to the integer NUMBER FIVE, in order to celebrate \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/contests/1?s_tid=Cody5YA_cody_home\"\u003eCody's 5th birthday\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eIn this problem, let's determine the position (index) of the first occurrence of 5 along the first non-singleton dimension of an input array.\u003c/p\u003e\u003cp\u003eE.g.,\u003c/p\u003e\u003cul\u003e\u003cli\u003eIf the input is a vector, return the index of the first occurrence of 5.\u003c/li\u003e\u003c/ul\u003e\u003cpre class=\"language-matlab\"\u003ex = [1 2 5 3 5];\r\ny = 3;\r\n\u003c/pre\u003e\u003cul\u003e\u003cli\u003eIf the input is a matrix, return the index of the first occurrence of 5 in each column. If 5 is not found, simply return 0;\u003c/li\u003e\u003c/ul\u003e\u003cpre class=\"language-matlab\"\u003e% Input x is a matrix\r\nx = [1 2 5\r\n     5 9 1\r\n     5 6 5];\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003e% Output y\r\ny = [2 0 1];\r\n\u003c/pre\u003e\u003cp\u003eNext problem in this series: \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44352-the-top-5-primes\"\u003eThe Top 5 Primes\u003c/a\u003e\u003c/p\u003e","function_template":"function y = locOf5(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nassessFunctionAbsence({'regexp','regexpi','regexprep','str2num'},'FileName','locOf5.m')\r\n\r\n%%\r\nx = 2:2:20;\r\ny_correct = 0;\r\nassert(isequal(locOf5(x),y_correct))\r\n\r\n%%\r\nx = rot90(1:10);\r\ny_correct = 6;\r\nassert(isequal(locOf5(x),y_correct))\r\n\r\n%%\r\nx = [1 2 5\r\n     5 9 1\r\n     5 6 5];\r\ny_correct = [2 0 1];\r\nassert(isequal(locOf5(x),y_correct))\r\n\r\n%%\r\nx = magic(5);\r\ny_correct = [0 2 0 0 0];\r\nassert(isequal(locOf5(x),y_correct))\r\n\r\n%%\r\nx = [1 2 3 4 5;\r\n     5 4 3 2 1\r\n     2 3 5 2 1\r\n     1 5 2 6 8\r\n     3 5 2 2 5];\r\ny_correct = [2 4 3 0 1];\r\nassert(isequal(locOf5(x),y_correct))\r\n\r\n% %%\r\n% x = randi([-10,10],20,1e6); \r\n% x(x==5) = 0;\r\n% p = sort(randi([0 size(x,1)],5,size(x,2)));\r\n% y_correct = p(1,:);\r\n% p(2:end,~y_correct) = 0;\r\n% [~,col,v] = find(p);\r\n% x((col-1)*size(x,1)+v) = 5;\r\n% assert(isequal(locOf5(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":434,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-20T14:43:55.000Z","updated_at":"2026-03-18T13:43:25.000Z","published_at":"2017-10-16T01:45:08.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 problem series invites you to solve two simple problems related to the integer NUMBER FIVE, in order to celebrate\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://www.mathworks.com/matlabcentral/cody/contests/1?s_tid=Cody5YA_cody_home\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody's 5th birthday\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\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn this problem, let's determine the position (index) of the first occurrence of 5 along the first non-singleton dimension of an input array.\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\u003eE.g.,\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\u003eIf the input is a vector, return the index of the first occurrence of 5.\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[x = [1 2 5 3 5];\\ny = 3;]]\u003e\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\u003eIf the input is a matrix, return the index of the first occurrence of 5 in each column. If 5 is not found, simply return 0;\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[% Input x is a matrix\\nx = [1 2 5\\n     5 9 1\\n     5 6 5];\\n\\n% Output y\\ny = [2 0 1];]]\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\u003eNext problem in this series:\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://www.mathworks.com/matlabcentral/cody/problems/44352-the-top-5-primes\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eThe Top 5 Primes\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":44349,"title":"Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock.","description":"Submit your answer to this problem a multiple of 5 seconds after the hour.  Your answer is irrelevant; the only thing that matters is *when* you submit it.  It can be 5 seconds after, 555 seconds, or 3300 seconds after the hour.  So long as the number of seconds is a multiple of five, you are good to go.","description_html":"\u003cp\u003eSubmit your answer to this problem a multiple of 5 seconds after the hour.  Your answer is irrelevant; the only thing that matters is \u003cb\u003ewhen\u003c/b\u003e you submit it.  It can be 5 seconds after, 555 seconds, or 3300 seconds after the hour.  So long as the number of seconds is a multiple of five, you are good to go.\u003c/p\u003e","function_template":"function y = time_for_five(x)\r\n  y = 555555;\r\nend","test_suite":"%%\r\nfiletext = fileread('time_for_five.m');\r\nassert(isempty(strfind(filetext, 'fopen')));\r\nassert(isempty(strfind(filetext, 'assert')));\r\n%%\r\ny = time_for_five(5);\r\n\r\na=clock;\r\n\r\nif mod(floor(a(6)),5)==0\r\n    y_correct= y\r\nelse\r\n    y_correct = NaN;\r\nend\r\n\r\nassert(isequal(y,y_correct))","published":true,"deleted":false,"likes_count":14,"comments_count":13,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":957,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-26T17:42:30.000Z","updated_at":"2026-03-18T13:20:10.000Z","published_at":"2017-10-16T01:45:08.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\u003eSubmit your answer to this problem a multiple of 5 seconds after the hour. Your answer is irrelevant; the only thing that matters is\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\u003ewhen\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e you submit it. It can be 5 seconds after, 555 seconds, or 3300 seconds after the hour. So long as the number of seconds is a multiple of five, you are good to go.\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":44360,"title":"Pentagonal Numbers","description":"Your function will receive a lower and upper bound. It should return all pentagonal numbers within that inclusive range in ascending order. Additionally, it should return an array that indicates those numbers that are divisible by 5. For example,\r\n\r\n [p,d] = pentagonal_numbers(10,40)\r\n\r\nshould return\r\n\r\n p = [12,22,35]\r\n d = [ 0, 0, 1]","description_html":"\u003cp\u003eYour function will receive a lower and upper bound. It should return all pentagonal numbers within that inclusive range in ascending order. Additionally, it should return an array that indicates those numbers that are divisible by 5. For example,\u003c/p\u003e\u003cpre\u003e [p,d] = pentagonal_numbers(10,40)\u003c/pre\u003e\u003cp\u003eshould return\u003c/p\u003e\u003cpre\u003e p = [12,22,35]\r\n d = [ 0, 0, 1]\u003c/pre\u003e","function_template":"function [p,d] = pentagonal_numbers(10,40)\r\n p = [5];\r\n d = [1];\r\nend","test_suite":"%%\r\nx1 = 1; x2 = 25;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[1,5,12,22]))\r\nassert(isequal(d,[0,1,0,0]))\r\n\r\n%%\r\nx1 = 1; x2 = 4;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,1))\r\nassert(isequal(d,0))\r\n\r\n%%\r\nx1 = 10; x2 = 40;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[12,22,35]))\r\nassert(isequal(d,[0,0,1]))\r\n\r\n%%\r\nx1 = 10; x2 = 99;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[12,22,35,51,70,92]))\r\nassert(isequal(d,[0,0,1,0,1,0]))\r\n\r\n%%\r\nx1 = 100; x2 = 999;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[117,145,176,210,247,287,330,376,425,477,532,590,651,715,782,852,925]))\r\nassert(isequal(d,[0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1]))\r\n\r\n%%\r\nx1 = 40; x2 = 50;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isempty(p))\r\nassert(isempty(d))\r\n\r\n%%\r\nx1 = 1000; x2 = 1500;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[1001,1080,1162,1247,1335,1426]))\r\nassert(isequal(d,[0,1,0,0,1,0]))\r\n\r\n%%\r\nx1 = 1500; x2 = 3000;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[1520,1617,1717,1820,1926,2035,2147,2262,2380,2501,2625,2752,2882]))\r\nassert(isequal(d,[1,0,0,1,0,1,0,0,1,0,1,0,0]))\r\n\r\n%%\r\nx1 = 1; x2 = 3000;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[1,5,12,22,35,51,70,92,117,145,176,210,247,287,330,376,425,477,532,590,651,715,782,852,925,1001,1080,1162,1247,1335,1426,1520,1617,1717,1820,1926,2035,2147,2262,2380,2501,2625,2752,2882]))\r\nassert(isequal(d,[0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0]))\r\n\r\n%%\r\nx1 = 10000; x2 = 12000;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[10045,10292,10542,10795,11051,11310,11572,11837]))\r\nassert(isequal(d,[1,0,0,1,0,1,0,0]))\r\n\r\n%%\r\nx1 = 100000; x2 = 110000;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[100492,101270,102051,102835,103622,104412,105205,106001,106800,107602,108407,109215]))\r\nassert(isequal(d,[0,1,0,1,0,0,1,0,1,0,0,1]))\r\n\r\n%%\r\nx1 = 1000000; x2 = 1010101;\r\n[p,d] = pentagonal_numbers(x1,x2)\r\nassert(isequal(p,[1000825,1003277,1005732,1008190]))\r\nassert(isequal(d,[1,0,0,1]))","published":true,"deleted":false,"likes_count":12,"comments_count":3,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":679,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-05T17:43:36.000Z","updated_at":"2026-04-07T13:59:33.000Z","published_at":"2017-10-16T01:45:09.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\u003eYour function will receive a lower and upper bound. It should return all pentagonal numbers within that inclusive range in ascending order. Additionally, it should return an array that indicates those numbers that are divisible by 5. 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[ [p,d] = pentagonal_numbers(10,40)]]\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\u003eshould return\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[ p = [12,22,35]\\n d = [ 0, 0, 1]]]\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":44368,"title":"Inscribed Pentagon?","description":"Your function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon will be centered about the circle. The function should return one of the following values:\r\n\r\n  0: the pentagon is completely enclosed within the circle but is not inscribed\r\n  1: the pentagon is inscribed in the circle (within ±0.02)\r\n  2: the vertices of the pentagon extend beyond the circle\r\n\r\nPoints will be rounded to the nearest hundredth. See the test cases for examples.","description_html":"\u003cp\u003eYour function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon will be centered about the circle. The function should return one of the following values:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e0: the pentagon is completely enclosed within the circle but is not inscribed\r\n1: the pentagon is inscribed in the circle (within ±0.02)\r\n2: the vertices of the pentagon extend beyond the circle\r\n\u003c/pre\u003e\u003cp\u003ePoints will be rounded to the nearest hundredth. See the test cases for examples.\u003c/p\u003e","function_template":"function y = inscribed_pentagon(p,cp,r)\r\n y = 0;\r\nend","test_suite":"%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,6.58; 6.42,1.92; 3.97,-5.63; -3.97,-5.63; -6.42,1.92];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,4.55; 4.28,1.44; 2.65,-3.59; -2.65,-3.59; -4.28,1.44];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,6.58; 6.42,1.92; 3.97,-5.63; -3.97,-5.63; -6.42,1.92] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,4.55; 4.28,1.44; 2.65,-3.59; -2.65,-3.59; -4.28,1.44] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [25.01,12.47; 25.98,4.58; 18.78,1.23; 13.37,7.03; 17.22,13.97];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.27,11.12; 23.92,5.87; 19.12,3.63; 15.52,7.50; 18.08,12.13];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [32.54,38.78; 38.84,26.41; 29.02,16.59; 16.65,22.89; 18.83,36.61];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.49,35.54; 34.69,27.29; 28.14,20.74; 19.89,24.95; 21.34,34.09];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon(p,cp,r),y_correct))","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":307,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-10T16:31:01.000Z","updated_at":"2026-04-07T14:00:57.000Z","published_at":"2017-10-16T01:45:09.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\u003eYour function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon will be centered about the circle. The function should return one of the following values:\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[0: the pentagon is completely enclosed within the circle but is not inscribed\\n1: the pentagon is inscribed in the circle (within ±0.02)\\n2: the vertices of the pentagon extend beyond the circle]]\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\u003ePoints will be rounded to the nearest hundredth. See the test cases for examples.\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":44338,"title":"Recaman Sequence - I","description":"Recaman Sequence (A005132 - \u003chttp://oeis.org/A005132 - OEIS Link\u003e) is defined as follow;\r\n\r\n  seq(0) = 0; \r\n  for n \u003e 0, seq(n) = seq(n-1) - n if positive and not already in the sequence, \r\n  otherwise seq(n) = seq(n-1) + n. \r\n\r\n  seq = 0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9 ...\r\nindex = 1, 2, 3 ,...\r\n\r\nTo avoid zero index, start indexing from 1.\r\nreturn the first n elements in Recaman Sequence\r\n\r\n*Related Challenges :*\r\n\r\n# Recaman Sequence - I\r\n# \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44339 Recaman Sequence - II\u003e\r\n# \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44340 Recaman Sequence - III\u003e\r\n","description_html":"\u003cp\u003eRecaman Sequence (A005132 - \u003ca href = \"http://oeis.org/A005132\"\u003e- OEIS Link\u003c/a\u003e) is defined as follow;\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eseq(0) = 0; \r\nfor n \u0026gt; 0, seq(n) = seq(n-1) - n if positive and not already in the sequence, \r\notherwise seq(n) = seq(n-1) + n. \r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eseq = 0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9 ...\r\nindex = 1, 2, 3 ,...\r\n\u003c/pre\u003e\u003cp\u003eTo avoid zero index, start indexing from 1.\r\nreturn the first n elements in Recaman Sequence\u003c/p\u003e\u003cp\u003e\u003cb\u003eRelated Challenges :\u003c/b\u003e\u003c/p\u003e\u003col\u003e\u003cli\u003eRecaman Sequence - I\u003c/li\u003e\u003cli\u003e\u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44339\"\u003eRecaman Sequence - II\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44340\"\u003eRecaman Sequence - III\u003c/a\u003e\u003c/li\u003e\u003c/ol\u003e","function_template":"function y = Recaman(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 0;\r\nassert(isequal(Recaman(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = [0 1 3 6 2];\r\nassert(isequal(Recaman(x),y_correct))\r\n\r\n%%\r\nx = 8;\r\ny_correct = [0 1 3 6 2 7 13 20];\r\nassert(isequal(Recaman(x),y_correct))\r\n\r\n%%\r\nx = 10;\r\ny_correct = [0 1 3 6 2 7 13 20 12 21];\r\nassert(isequal(Recaman(x),y_correct))\r\n\r\n%%\r\nx = 5e4;\r\ny = Recaman(x);\r\nassert(isequal(length(Recaman(x)),x))\r\nassert(isequal(y(954),739))\r\nassert(isequal(y(7589),17654))\r\nassert(isequal(y(12345),18554))\r\n\r\n%%\r\nx = 1e5;\r\ny = Recaman(x);\r\nassert(isequal(length(Recaman(x)),x))\r\nassert(isequal(y(1e4),8658))\r\nassert(isequal(y(2e4),34358))\r\nassert(isequal(y(3e4),92474))\r\nassert(isequal(y(4e4),102344))","published":true,"deleted":false,"likes_count":3,"comments_count":8,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":321,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-19T06:55:43.000Z","updated_at":"2026-03-22T11:16:16.000Z","published_at":"2017-10-16T01:45: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\u003eRecaman Sequence (A005132 -\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://oeis.org/A005132\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e- OEIS Link\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e) is defined as follow;\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[seq(0) = 0; \\nfor n \u003e 0, seq(n) = seq(n-1) - n if positive and not already in the sequence, \\notherwise seq(n) = seq(n-1) + n. \\n\\nseq = 0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9 ...\\nindex = 1, 2, 3 ,...]]\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\u003eTo avoid zero index, start indexing from 1. return the first n elements in Recaman Sequence\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRelated Challenges :\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\u003eRecaman Sequence - I\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:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44339\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - II\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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44340\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - III\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":44334,"title":"Sums of Multiple Pairs of Triangular Numbers","description":"This is a follow-up to \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44289 Problem 44289\u003e - Find two triangular numbers whose sum is input.\r\n\r\nThere are some numbers that are the sum of multiple pairs of triangular numbers.  For example, 81 = 36+45 = 15+66 = 3+78.  Given a number X, find all of the possible pairs of triangular numbers that add up to X.  Your answer should be in a 2-by-X matrix.  Each column of the matrix should sum to X, and each pair of triangular numbers should only appear once.  The top row sorted from low to high.  The output for 81 would be:\r\n\r\n [ 3   15  36 \r\n  78   66  45]\r\n\r\nGood luck!","description_html":"\u003cp\u003eThis is a follow-up to \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44289\"\u003eProblem 44289\u003c/a\u003e - Find two triangular numbers whose sum is input.\u003c/p\u003e\u003cp\u003eThere are some numbers that are the sum of multiple pairs of triangular numbers.  For example, 81 = 36+45 = 15+66 = 3+78.  Given a number X, find all of the possible pairs of triangular numbers that add up to X.  Your answer should be in a 2-by-X matrix.  Each column of the matrix should sum to X, and each pair of triangular numbers should only appear once.  The top row sorted from low to high.  The output for 81 would be:\u003c/p\u003e\u003cpre\u003e [ 3   15  36 \r\n  78   66  45]\u003c/pre\u003e\u003cp\u003eGood luck!\u003c/p\u003e","function_template":"function y = multi_triangular(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 21;\r\ny_correct = [6;15];\r\nassert(isequal(multi_triangular(x),y_correct))\r\n%%\r\nx=81;\r\ny_correct=[ 3   15  36 ;  78   66  45];\r\nassert(isequal(multi_triangular(x),y_correct))\r\n%%\r\nx=20;\r\ny_correct=[ 10 10];\r\nassert(isequal(multi_triangular(x),y_correct'))\r\n%%\r\nx=17956;\r\ny_correct=[ 1 190 378 1485 2556  4095 4753 6328 8911;\r\n 17955 17766 17578 16471 15400 13861 13203 11628 9045];\r\nassert(isequal(multi_triangular(x),y_correct))\r\n%%\r\nx=70;\r\ny_correct=[15 55];\r\nassert(isequal(multi_triangular(x),y_correct'));\r\n%%\r\nx=37052031;\r\ny_correct=[7503 16110 93528 119316 136503 393828 496506 778128 1033203 1194285 1675365 1876953 2503203 2627778 3214380 3436131 3983253 4226778 4943940 5112003 5279625 6063903 6417153 7055646 7771653 8456328 8855736 9801378 10015050 11221953 11580078 12834711 13846953 14084778 15149760 15387378 15531951 17096628 17567628 18395145;\r\n37044528 37035921 36958503 36932715 36915528 36658203 36555525 36273903 36018828 35857746 35376666 35175078 34548828 34424253 33837651 33615900 33068778 32825253 32108091 31940028 31772406 30988128 30634878 29996385 29280378 28595703 28196295 27250653 27036981 25830078 25471953 24217320 23205078 22967253 21902271 21664653 21520080 19955403 19484403 18656886];\r\nassert(isequal(multi_triangular(x),y_correct));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":247,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-15T19:37:34.000Z","updated_at":"2026-03-22T12:09:49.000Z","published_at":"2017-10-16T01:45: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\u003eThis is a follow-up 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=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44289\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44289\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e - Find two triangular numbers whose sum is input.\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 some numbers that are the sum of multiple pairs of triangular numbers. For example, 81 = 36+45 = 15+66 = 3+78. Given a number X, find all of the possible pairs of triangular numbers that add up to X. Your answer should be in a 2-by-X matrix. Each column of the matrix should sum to X, and each pair of triangular numbers should only appear once. The top row sorted from low to high. The output for 81 would be:\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[ [ 3   15  36 \\n  78   66  45]]]\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\u003eGood luck!\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":44381,"title":"Cache me Outside","description":"The test suite includes a simple recursive Fibonacci sequence generator, but it's terribly inefficient. One simple method for improving its performance is using a technique called memoization. Write a function that takes a function_handle that we wish to memoize and returns a function_handle to a memoized version of the initial handle.","description_html":"\u003cp\u003eThe test suite includes a simple recursive Fibonacci sequence generator, but it's terribly inefficient. One simple method for improving its performance is using a technique called memoization. Write a function that takes a function_handle that we wish to memoize and returns a function_handle to a memoized version of the initial handle.\u003c/p\u003e","function_template":"function memfcn = memoize_this(fcn)\r\n    memfcn = fcn;\r\nend","test_suite":"%%\r\nmemfib = memoize_this(@fib);\r\n\r\n[seq, n1] = fib(1, memfib);\r\nassert(n1 == 1);\r\n\r\n[seq, n2] = fib(20, memfib);\r\nassert(n2 - n1 == 19);\r\n\r\n[seq, n3] = fib(100, memfib);\r\nassert(n3 - n2 == 81);\r\n\r\n\r\nfunction [seq, n] = fib(n, memfib)\r\n    persistent num\r\n    if isempty(num)\r\n        num = 1;\r\n    else\r\n        num = num + 1;\r\n    end\r\n    \r\n    if n \u003c 3\r\n        seq = ones(1, n);\r\n    else\r\n        seq = memfib(n-1, memfib);\r\n        seq = [seq, seq(end-1) + seq(end)];\r\n    end\r\n    \r\n    n = num;\r\nend","published":true,"deleted":false,"likes_count":5,"comments_count":6,"created_by":134,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":102,"test_suite_updated_at":"2017-10-17T21:30:35.000Z","rescore_all_solutions":true,"group_id":35,"created_at":"2017-10-12T20:12:52.000Z","updated_at":"2026-04-01T04:17:42.000Z","published_at":"2017-10-16T01:51:02.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eThe test suite includes a simple recursive Fibonacci sequence generator, but it's terribly inefficient. One simple method for improving its performance is using a technique called memoization. Write a function that takes a function_handle that we wish to memoize and returns a function_handle to a memoized version of the initial handle.\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":44321,"title":"Van Eck's Sequence's nth member","description":"Return the Van Eck's Sequence's nth member.\r\n\r\nFor detailed info : \u003chttp://oeis.org/A181391 OEIS link\u003e and \u003chttps://www.theguardian.com/science/alexs-adventures-in-numberland/2014/oct/07/neil-sloane-the-man-who-loved-only-integer-sequences here\u003e\r\n\r\n seq = 0, 0, 1, 0, 2, 0, 2, 2, 1, 6, 0, 5...\r\n\r\nFirst member is 0;\r\n\r\nSecond member is 0;\r\n\r\nthird member is 1 etc\r\n","description_html":"\u003cp\u003eReturn the Van Eck's Sequence's nth member.\u003c/p\u003e\u003cp\u003eFor detailed info : \u003ca href = \"http://oeis.org/A181391\"\u003eOEIS link\u003c/a\u003e and \u003ca href = \"https://www.theguardian.com/science/alexs-adventures-in-numberland/2014/oct/07/neil-sloane-the-man-who-loved-only-integer-sequences\"\u003ehere\u003c/a\u003e\u003c/p\u003e\u003cpre\u003e seq = 0, 0, 1, 0, 2, 0, 2, 2, 1, 6, 0, 5...\u003c/pre\u003e\u003cp\u003eFirst member is 0;\u003c/p\u003e\u003cp\u003eSecond member is 0;\u003c/p\u003e\u003cp\u003ethird member is 1 etc\u003c/p\u003e","function_template":"function result = VanEcksSequence(n)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 0;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n\r\n%%\r\nx = 2;\r\ny_correct = 0;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n\r\n%%\r\nx = 4;\r\ny_correct = 0;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n\r\n%%\r\nx = 6;\r\ny_correct = 0;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n\r\n%%\r\nx = 11;\r\ny_correct = 0;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n\r\n%%\r\nx = 50;\r\ny_correct = 3;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n\r\n%%\r\nx = 500;\r\ny_correct = 4;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n\r\n\r\n%%\r\nx = 5000;\r\ny_correct = 402;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n\r\n%%\r\nx = 50000;\r\ny_correct = 114;\r\nassert(isequal(VanEcksSequence(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":12,"comments_count":1,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":331,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-13T08:14:57.000Z","updated_at":"2026-03-24T14:52:41.000Z","published_at":"2017-10-16T01:45:07.000Z","restored_at":"2017-09-28T06:15:18.000Z","restored_by":null,"spam":false,"simulink":false,"admin_reviewed":true,"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\u003eReturn the Van Eck's Sequence's nth member.\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 detailed info :\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://oeis.org/A181391\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eOEIS link\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=\\\"https://www.theguardian.com/science/alexs-adventures-in-numberland/2014/oct/07/neil-sloane-the-man-who-loved-only-integer-sequences\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehere\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=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ seq = 0, 0, 1, 0, 2, 0, 2, 2, 1, 6, 0, 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\u003eFirst member is 0;\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\u003eSecond member is 0;\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\u003ethird member is 1 etc\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":44307,"title":"The glass half full","description":"Identical glasses are placed in a triangular tower structure, such that the top level (L = 1) comprises one glass, the next level down (L = 2) comprises three glasses, the next level down (L = 3) comprises six glasses, and so on.\r\n\r\nFollow the \u003chttps://imgur.com/a/j9ZZa link\u003e to see a diagram shows the first three levels. The glasses in each levels are represented by the blue circles, while the yellow circles represent the positions of the glasses in the next higher level.\r\n\r\nWater is poured into the top glass at a constant volumetric flow rate. When the glass is filled, the water starts spilling over and into the glasses below. Note that *water only spills outward* , meaning that at some point, some glasses will remain empty.\r\n\r\nGiven the volume of a glass in liters, v, the volumetric flow rate in liters per second, u, and an integer, L, representing a level in the glass structure, return the total number of glasses in that level, g, the number of glasses in that level that will be filled with water, f, and the time, in seconds, it would take to fill all \"fillable\" glasses in that level, t, starting with no water in any of the levels.\r\n\r\nExample:\r\n\r\nInput: v = 0.25, u = 0.1, L = 2\r\n\r\nOutput: g = 3, f = 3, t = 10","description_html":"\u003cp\u003eIdentical glasses are placed in a triangular tower structure, such that the top level (L = 1) comprises one glass, the next level down (L = 2) comprises three glasses, the next level down (L = 3) comprises six glasses, and so on.\u003c/p\u003e\u003cp\u003eFollow the \u003ca href = \"https://imgur.com/a/j9ZZa\"\u003elink\u003c/a\u003e to see a diagram shows the first three levels. The glasses in each levels are represented by the blue circles, while the yellow circles represent the positions of the glasses in the next higher level.\u003c/p\u003e\u003cp\u003eWater is poured into the top glass at a constant volumetric flow rate. When the glass is filled, the water starts spilling over and into the glasses below. Note that \u003cb\u003ewater only spills outward\u003c/b\u003e , meaning that at some point, some glasses will remain empty.\u003c/p\u003e\u003cp\u003eGiven the volume of a glass in liters, v, the volumetric flow rate in liters per second, u, and an integer, L, representing a level in the glass structure, return the total number of glasses in that level, g, the number of glasses in that level that will be filled with water, f, and the time, in seconds, it would take to fill all \"fillable\" glasses in that level, t, starting with no water in any of the levels.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003eInput: v = 0.25, u = 0.1, L = 2\u003c/p\u003e\u003cp\u003eOutput: g = 3, f = 3, t = 10\u003c/p\u003e","function_template":"function [g, f, t] = filltime(v, u, L)\r\n    [g, f, t] = [v, u, L];\r\nend","test_suite":"%%\r\n[g f t] = filltime(0.25, 0.1, 2);\r\nassert(isequal([g f t],[3 3 10]))\r\n\r\n%%\r\n[g f t] = filltime(0.45, 0.3, 6);\r\nassert(isequal([g f t],[21 15 69]))\r\n\r\n%%\r\n[g f t] = filltime(3, 0.8, 7);\r\nassert(isequal([g f t],[28 18 240]))\r\n\r\n\r\n%%\r\n[g f t] = filltime(2, 8, 47);\r\nassert(isequal([g f t],[1128 138 811]))","published":true,"deleted":false,"likes_count":8,"comments_count":1,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":260,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-09T07:06:17.000Z","updated_at":"2026-04-07T08:44:37.000Z","published_at":"2017-10-16T01:45: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\u003eIdentical glasses are placed in a triangular tower structure, such that the top level (L = 1) comprises one glass, the next level down (L = 2) comprises three glasses, the next level down (L = 3) comprises six glasses, and so on.\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\u003eFollow 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://imgur.com/a/j9ZZa\\\"\u003e\u003cw:r\u003e\u003cw:t\u003elink\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e to see a diagram shows the first three levels. The glasses in each levels are represented by the blue circles, while the yellow circles represent the positions of the glasses in the next higher level.\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\u003eWater is poured into the top glass at a constant volumetric flow rate. When the glass is filled, the water starts spilling over and into the glasses below. Note that\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\u003ewater only spills outward\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e , meaning that at some point, some glasses will remain empty.\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\u003eGiven the volume of a glass in liters, v, the volumetric flow rate in liters per second, u, and an integer, L, representing a level in the glass structure, return the total number of glasses in that level, g, the number of glasses in that level that will be filled with water, f, and the time, in seconds, it would take to fill all \\\"fillable\\\" glasses in that level, t, starting with no water in any of the levels.\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\u003eExample:\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\u003eInput: v = 0.25, u = 0.1, L = 2\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\u003eOutput: g = 3, f = 3, t = 10\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":44305,"title":"5 Prime Numbers","description":"Your function will be given lower and upper integer bounds. Your task is to return a vector containing the first five prime numbers in that range that contain the number five. But, if you can't find at least five such numbers, the function should give up and return -1.\r\n\r\nFor example, for n_min = 60 and n_max = 1000, the set of prime numbers is:\r\n\r\n p = [61,67,71,73,79, ... 149,151,157,163, ... 241,251,257,263, ... 349,353,359,367, ... 983,991,997]\r\n\r\nThis set contains at least five numbers that contain a five; the first five are:\r\n\r\n p5 = [151,157,251,257,353]\r\n\r\nwhich is the set that your function should return in this case. If, however, n_max were set at 300, five such numbers do not exist and the function should then give up (return -1).","description_html":"\u003cdiv style = \"text-align: start; line-height: 20px; 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: normal; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"display: block; min-width: 0px; padding-top: 0px; transform-origin: 420.4375px 118px; vertical-align: baseline; perspective-origin: 420.4375px 118px; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; transform-origin: 309px 31.5px; white-space: pre-wrap; perspective-origin: 309px 31.5px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eYour function will be given lower and upper integer bounds. Your task is to return a vector containing the first five prime numbers in that range that contain the number five. But, if you can't find at least five such numbers, the function should give up and return -1.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; transform-origin: 309px 10.5px; white-space: pre-wrap; perspective-origin: 309px 10.5px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eFor example, for n_min = 60 and n_max = 1000, the set of prime numbers is:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-bottom: 10px; margin-left: 3px; margin-right: 3px; margin-top: 10px; transform-origin: 417.4375px 10px; perspective-origin: 417.4375px 10px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: 18px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-right: 45px; min-height: 0px; padding-left: 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; perspective-origin: 0px 0px; margin-right: 45px; \"\u003e\u003cspan style=\"margin-right: 0px; \"\u003e p = [61,67,71,73,79, \u003c/span\u003e\u003cspan style=\"border-bottom-color: rgb(255, 0, 0); border-left-color: rgb(255, 0, 0); border-right-color: rgb(255, 0, 0); border-top-color: rgb(255, 0, 0); caret-color: rgb(255, 0, 0); color: rgb(255, 0, 0); margin-right: 0px; outline-color: rgb(255, 0, 0); text-decoration-color: rgb(255, 0, 0); column-rule-color: rgb(255, 0, 0); \"\u003e… \u003c/span\u003e\u003cspan style=\"margin-right: 0px; \"\u003e149,151,157,163, \u003c/span\u003e\u003cspan style=\"border-bottom-color: rgb(255, 0, 0); border-left-color: rgb(255, 0, 0); border-right-color: rgb(255, 0, 0); border-top-color: rgb(255, 0, 0); caret-color: rgb(255, 0, 0); color: rgb(255, 0, 0); margin-right: 0px; outline-color: rgb(255, 0, 0); text-decoration-color: rgb(255, 0, 0); column-rule-color: rgb(255, 0, 0); \"\u003e… \u003c/span\u003e\u003cspan style=\"margin-right: 0px; \"\u003e241,251,257,263, \u003c/span\u003e\u003cspan style=\"border-bottom-color: rgb(255, 0, 0); border-left-color: rgb(255, 0, 0); border-right-color: rgb(255, 0, 0); border-top-color: rgb(255, 0, 0); caret-color: rgb(255, 0, 0); color: rgb(255, 0, 0); margin-right: 0px; outline-color: rgb(255, 0, 0); text-decoration-color: rgb(255, 0, 0); column-rule-color: rgb(255, 0, 0); \"\u003e… \u003c/span\u003e\u003cspan style=\"margin-right: 0px; \"\u003e349,353,359,367, \u003c/span\u003e\u003cspan style=\"border-bottom-color: rgb(255, 0, 0); border-left-color: rgb(255, 0, 0); border-right-color: rgb(255, 0, 0); border-top-color: rgb(255, 0, 0); caret-color: rgb(255, 0, 0); color: rgb(255, 0, 0); margin-right: 0px; outline-color: rgb(255, 0, 0); text-decoration-color: rgb(255, 0, 0); column-rule-color: rgb(255, 0, 0); \"\u003e… \u003c/span\u003e\u003cspan style=\"margin-right: 0px; \"\u003e983,991,997]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 10px; text-align: left; transform-origin: 309px 10.5px; white-space: pre-wrap; perspective-origin: 309px 10.5px; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThis set contains at least five numbers that contain a five; the first five are:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-bottom: 10px; margin-left: 3px; margin-right: 3px; margin-top: 10px; transform-origin: 417.4375px 10px; perspective-origin: 417.4375px 10px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: 18px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-right: 45px; min-height: 0px; padding-left: 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; perspective-origin: 0px 0px; margin-right: 45px; \"\u003e\u003cspan style=\"margin-right: 0px; \"\u003e p5 = [151,157,251,257,353]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 10px; text-align: left; transform-origin: 309px 21px; white-space: pre-wrap; perspective-origin: 309px 21px; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003ewhich is the set that your function should return in this case. If, however, n_max were set at 300, five such numbers do not exist and the function should then give up (return -1).\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = five_primes(n_min,n_max)\r\n  y = [];\r\nend","test_suite":"%%\r\nn_min = 60;\r\nn_max = 1000;\r\ny_correct = [151,157,251,257,353];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 60;\r\nn_max = 300;\r\ny_correct = -1;\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 1;\r\nn_max = 200;\r\ny_correct = [5,53,59,151,157];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 1;\r\nn_max = 100;\r\ny_correct = -1;\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 500;\r\nn_max = 600;\r\ny_correct = [503,509,521,523,541];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 500;\r\nn_max = 555;\r\ny_correct = [503,509,521,523,541];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 500;\r\nn_max = 500000000;\r\ny_correct = [503,509,521,523,541];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 5000;\r\nn_max = 5020;\r\ny_correct = -1;\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 5000;\r\nn_max = 5200;\r\ny_correct = [5003,5009,5011,5021,5023];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 5000;\r\nn_max = 55555555;\r\ny_correct = [5003,5009,5011,5021,5023];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 55555;\r\nn_max = 56789;\r\ny_correct = [55579,55589,55603,55609,55619];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))\r\n\r\n%%\r\nn_min = 987654321;\r\nn_max = 988777666;\r\ny_correct = [987654323,987654337,987654347,987654359,987654361];\r\nassert(isequal(five_primes(n_min,n_max),y_correct))","published":true,"deleted":false,"likes_count":7,"comments_count":2,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":453,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-08T18:33:05.000Z","updated_at":"2026-04-06T09:57:52.000Z","published_at":"2017-10-16T01:45:06.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\u003eYour function will be given lower and upper integer bounds. Your task is to return a vector containing the first five prime numbers in that range that contain the number five. But, if you can't find at least five such numbers, the function should give up and return -1.\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\u003eFor example, for n_min = 60 and n_max = 1000, the set of prime numbers is:\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[ p = [61,67,71,73,79, … 149,151,157,163, … 241,251,257,263, … 349,353,359,367, … 983,991,997]]]\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis set contains at least five numbers that contain a five; the first five are:\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[ p5 = [151,157,251,257,353]]]\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ewhich is the set that your function should return in this case. If, however, n_max were set at 300, five such numbers do not exist and the function should then give up (return -1).\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":44339,"title":"Recaman Sequence - II","description":"Take an arbitrary starting point as input and create Recaman Sequence. Then find the 1, return its index.\r\n\r\nFor example: if n = 0 (default Recaman sequence)\r\n  \r\n  seq = [0 1 3 6 2];\r\n\r\n1 is in the second place. \r\n\r\nif n = 10;\r\n\r\n  seq = [10 9 7 4 8 3 9 2 10 1 11 22 34 21];\r\n\r\n1 is in the 10th place\r\n\r\n*Related Challenges :*\r\n\r\n# \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44338 Recaman Sequence - I\u003e\r\n# Recaman Sequence - II\r\n# \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44340 Recaman Sequence - III\u003e","description_html":"\u003cp\u003eTake an arbitrary starting point as input and create Recaman Sequence. Then find the 1, return its index.\u003c/p\u003e\u003cp\u003eFor example: if n = 0 (default Recaman sequence)\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eseq = [0 1 3 6 2];\r\n\u003c/pre\u003e\u003cp\u003e1 is in the second place.\u003c/p\u003e\u003cp\u003eif n = 10;\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eseq = [10 9 7 4 8 3 9 2 10 1 11 22 34 21];\r\n\u003c/pre\u003e\u003cp\u003e1 is in the 10th place\u003c/p\u003e\u003cp\u003e\u003cb\u003eRelated Challenges :\u003c/b\u003e\u003c/p\u003e\u003col\u003e\u003cli\u003e\u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44338\"\u003eRecaman Sequence - I\u003c/a\u003e\u003c/li\u003e\u003cli\u003eRecaman Sequence - II\u003c/li\u003e\u003cli\u003e\u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44340\"\u003eRecaman Sequence - III\u003c/a\u003e\u003c/li\u003e\u003c/ol\u003e","function_template":"function y = RecamanII(startPoint)\r\n\r\nend","test_suite":"%%\r\nx = 0;\r\ny_correct = 2;\r\nassert(isequal(RecamanII(x),y_correct))\r\n\r\n%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(RecamanII(x),y_correct))\r\n\r\n%%\r\nx = 3;\r\ny_correct = 4;\r\nassert(isequal(RecamanII(x),y_correct))\r\n\r\n%%\r\nx = 90;\r\ny_correct = 35;\r\nassert(isequal(RecamanII(x),y_correct))\r\n\r\n%%\r\nx = 123456;\r\ny_correct = 895;\r\nassert(isequal(RecamanII(x),y_correct))\r\n\r\n%%\r\nx = 123456789;\r\ny_correct = 46633;\r\nassert(isequal(RecamanII(x),y_correct))\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":281,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-19T07:08:59.000Z","updated_at":"2026-04-07T13:57:31.000Z","published_at":"2017-10-16T01:45: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\u003eTake an arbitrary starting point as input and create Recaman Sequence. Then find the 1, return its index.\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 example: if n = 0 (default Recaman sequence)\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[seq = [0 1 3 6 2];]]\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\u003e1 is in the second place.\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\u003eif n = 10;\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[seq = [10 9 7 4 8 3 9 2 10 1 11 22 34 21];]]\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\u003e1 is in the 10th place\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRelated Challenges :\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:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44338\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - I\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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - II\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:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44340\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - III\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":44375,"title":"Missing five","description":"Convert decimal numbers to a base-9 notation missing the digit *5*\r\n\r\n\u003c\u003chttp://www.alfnie.com/software/missing5.jpg\u003e\u003e\r\n\r\nToo many five-themed problems? Wondering whether everything would be simpler if we just got rid of the digit 5? Let's try!\r\n\r\nIn a world without 5's, positive integers may be represented using a base-9 notation that uses only the digits 0, 1, 2, 3, 4, 6, 7, 8, and 9. We'll call this the \"missing-5\" notation. The following list shows the first 100 positive numbers (i.e. 1 through 100) using \"missing-5\" notation:\r\n\r\n    '1'      '2'      '3'      '4'      '6'      '7'      '8'      '9'      '10'     '11' \r\n    '12'     '13'     '14'     '16'     '17'     '18'     '19'     '20'     '21'     '22' \r\n    '23'     '24'     '26'     '27'     '28'     '29'     '30'     '31'     '32'     '33' \r\n    '34'     '36'     '37'     '38'     '39'     '40'     '41'     '42'     '43'     '44' \r\n    '46'     '47'     '48'     '49'     '60'     '61'     '62'     '63'     '64'     '66' \r\n    '67'     '68'     '69'     '70'     '71'     '72'     '73'     '74'     '76'     '77' \r\n    '78'     '79'     '80'     '81'     '82'     '83'     '84'     '86'     '87'     '88' \r\n    '89'     '90'     '91'     '92'     '93'     '94'     '96'     '97'     '98'     '99' \r\n    '100'    '101'    '102'    '103'    '104'    '106'    '107'    '108'    '109'    '110'\r\n    '111'    '112'    '113'    '114'    '116'    '117'    '118'    '119'    '120'    '121'\r\n\r\nYou may notice that this is simply the sorted list of positive numbers which do not contain the digit 5 in their decimal representation. \r\n\r\nYour function should convert a positive decimal number N into its \"missing-5\" notation. For example\r\n\r\n dec2missing5(20)\r\n\r\nshould return _'22'_ (the 20th positive number in missing-5 notation), and\r\n\r\n dec2missing5(100)\r\n\r\nshould return _'121'_ (the 100th positive number in missing-5 notation)\r\n\r\nGood luck!\r\n\r\n_Small print_: Your function may output a number, a char array, or a string; whatever you find simpler (e.g. in the example above, valid outputs are 121, '121', or \"121\"). Input numbers in testsuite are always relatively low valued positive integers (\u003c10,000)","description_html":"\u003cp\u003eConvert decimal numbers to a base-9 notation missing the digit \u003cb\u003e5\u003c/b\u003e\u003c/p\u003e\u003cimg src = \"http://www.alfnie.com/software/missing5.jpg\"\u003e\u003cp\u003eToo many five-themed problems? Wondering whether everything would be simpler if we just got rid of the digit 5? Let's try!\u003c/p\u003e\u003cp\u003eIn a world without 5's, positive integers may be represented using a base-9 notation that uses only the digits 0, 1, 2, 3, 4, 6, 7, 8, and 9. We'll call this the \"missing-5\" notation. The following list shows the first 100 positive numbers (i.e. 1 through 100) using \"missing-5\" notation:\u003c/p\u003e\u003cpre\u003e    '1'      '2'      '3'      '4'      '6'      '7'      '8'      '9'      '10'     '11' \r\n    '12'     '13'     '14'     '16'     '17'     '18'     '19'     '20'     '21'     '22' \r\n    '23'     '24'     '26'     '27'     '28'     '29'     '30'     '31'     '32'     '33' \r\n    '34'     '36'     '37'     '38'     '39'     '40'     '41'     '42'     '43'     '44' \r\n    '46'     '47'     '48'     '49'     '60'     '61'     '62'     '63'     '64'     '66' \r\n    '67'     '68'     '69'     '70'     '71'     '72'     '73'     '74'     '76'     '77' \r\n    '78'     '79'     '80'     '81'     '82'     '83'     '84'     '86'     '87'     '88' \r\n    '89'     '90'     '91'     '92'     '93'     '94'     '96'     '97'     '98'     '99' \r\n    '100'    '101'    '102'    '103'    '104'    '106'    '107'    '108'    '109'    '110'\r\n    '111'    '112'    '113'    '114'    '116'    '117'    '118'    '119'    '120'    '121'\u003c/pre\u003e\u003cp\u003eYou may notice that this is simply the sorted list of positive numbers which do not contain the digit 5 in their decimal representation.\u003c/p\u003e\u003cp\u003eYour function should convert a positive decimal number N into its \"missing-5\" notation. For example\u003c/p\u003e\u003cpre\u003e dec2missing5(20)\u003c/pre\u003e\u003cp\u003eshould return \u003ci\u003e'22'\u003c/i\u003e (the 20th positive number in missing-5 notation), and\u003c/p\u003e\u003cpre\u003e dec2missing5(100)\u003c/pre\u003e\u003cp\u003eshould return \u003ci\u003e'121'\u003c/i\u003e (the 100th positive number in missing-5 notation)\u003c/p\u003e\u003cp\u003eGood luck!\u003c/p\u003e\u003cp\u003e\u003ci\u003eSmall print\u003c/i\u003e: Your function may output a number, a char array, or a string; whatever you find simpler (e.g. in the example above, valid outputs are 121, '121', or \"121\"). Input numbers in testsuite are always relatively low valued positive integers (\u0026lt;10,000)\u003c/p\u003e","function_template":"function y = dec2missing5(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nassert(isequal(regexprep(char(string(dec2missing5(3))),'^0*',''),'3'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(14))),'^0*',''),'16'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(19))),'^0*',''),'21'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(80))),'^0*',''),'99'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(91))),'^0*',''),'111'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(313))),'^0*',''),'388'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(732))),'^0*',''),'1003'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(748))),'^0*',''),'1021'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(1249))),'^0*',''),'1738'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(1873))),'^0*',''),'2611'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(2790))),'^0*',''),'3840'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(3035))),'^0*',''),'4142'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(3391))),'^0*',''),'4688'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(3547))),'^0*',''),'4881'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(3724))),'^0*',''),'6098'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4057))),'^0*',''),'6608'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4221))),'^0*',''),'6810'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4389))),'^0*',''),'7017'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4444))),'^0*',''),'7088'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4489))),'^0*',''),'7138'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4530))),'^0*',''),'7193'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4533))),'^0*',''),'7197'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4569))),'^0*',''),'7237'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4585))),'^0*',''),'7264'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4651))),'^0*',''),'7338'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(4680))),'^0*',''),'7380'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(5455))),'^0*',''),'8431'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(5711))),'^0*',''),'8846'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(5949))),'^0*',''),'9140'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(5999))),'^0*',''),'9206'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(6075))),'^0*',''),'9300'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(6526))),'^0*',''),'9961'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(6601))),'^0*',''),'10044'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(6634))),'^0*',''),'10091'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(6728))),'^0*',''),'10206'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(6787))),'^0*',''),'10281'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(6902))),'^0*',''),'10419'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(7037))),'^0*',''),'10689'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(7212))),'^0*',''),'10903'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(7493))),'^0*',''),'11246'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(7962))),'^0*',''),'11927'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(7996))),'^0*',''),'11974'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(8062))),'^0*',''),'12048'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(8109))),'^0*',''),'12110'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(8248))),'^0*',''),'12284'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(8427))),'^0*',''),'12603'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(8538))),'^0*',''),'12737'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(8620))),'^0*',''),'12838'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(8959))),'^0*',''),'13264'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(9190))),'^0*',''),'13641'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(9289))),'^0*',''),'13771'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(9436))),'^0*',''),'13944'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(9480))),'^0*',''),'14003'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(9533))),'^0*',''),'14072'))\r\n%%\r\nassert(isequal(regexprep(char(string(dec2missing5(9541))),'^0*',''),'14081'))\r\n%%\r\nfor n=1:100, assert(all(char(string(dec2missing5(randi(10000))))~='5')); end\r\n%%\r\nx='1000'; for n=1:7, x=char(string(dec2missing5(str2double(x)))); end; assert(isequal(regexprep(x,'^0*',''),'11027'));\r\n%%\r\nx='234'; for n=1:10, x=char(string(dec2missing5(str2double(x)))); end; assert(isequal(regexprep(x,'^0*',''),'4240'));\r\n%%\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13944,14003,14072,14081]),regexp(fileread('dec2missing5.m'),'((\\s*[\\+\\-\\*\\/]\\s*)?[\\d\\.])+','match'))),'please do not use look-up table solutions');\r\n\r\n","published":true,"deleted":false,"likes_count":9,"comments_count":7,"created_by":43,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":381,"test_suite_updated_at":"2017-10-31T17:07:46.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-11T00:58:23.000Z","updated_at":"2026-04-07T15:19:53.000Z","published_at":"2017-10-16T01:45: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\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/media/image1.JPEG\"}],\"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\u003eConvert decimal numbers to a base-9 notation missing the digit\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\u003e5\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:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"relationshipId\\\" w:val=\\\"rId1\\\"/\u003e\u003c/w:customXmlPr\u003e\u003c/w:customXml\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\u003eToo many five-themed problems? Wondering whether everything would be simpler if we just got rid of the digit 5? Let's try!\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\u003eIn a world without 5's, positive integers may be represented using a base-9 notation that uses only the digits 0, 1, 2, 3, 4, 6, 7, 8, and 9. We'll call this the \\\"missing-5\\\" notation. The following list shows the first 100 positive numbers (i.e. 1 through 100) using \\\"missing-5\\\" notation:\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[    '1'      '2'      '3'      '4'      '6'      '7'      '8'      '9'      '10'     '11' \\n    '12'     '13'     '14'     '16'     '17'     '18'     '19'     '20'     '21'     '22' \\n    '23'     '24'     '26'     '27'     '28'     '29'     '30'     '31'     '32'     '33' \\n    '34'     '36'     '37'     '38'     '39'     '40'     '41'     '42'     '43'     '44' \\n    '46'     '47'     '48'     '49'     '60'     '61'     '62'     '63'     '64'     '66' \\n    '67'     '68'     '69'     '70'     '71'     '72'     '73'     '74'     '76'     '77' \\n    '78'     '79'     '80'     '81'     '82'     '83'     '84'     '86'     '87'     '88' \\n    '89'     '90'     '91'     '92'     '93'     '94'     '96'     '97'     '98'     '99' \\n    '100'    '101'    '102'    '103'    '104'    '106'    '107'    '108'    '109'    '110'\\n    '111'    '112'    '113'    '114'    '116'    '117'    '118'    '119'    '120'    '121']]\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\u003eYou may notice that this is simply the sorted list of positive numbers which do not contain the digit 5 in their decimal representation.\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 should convert a positive decimal number N into its \\\"missing-5\\\" notation. 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[ dec2missing5(20)]]\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\u003eshould return\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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e'22'\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (the 20th positive number in missing-5 notation), and\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[ dec2missing5(100)]]\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\u003eshould return\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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e'121'\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (the 100th positive number in missing-5 notation)\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\u003eGood luck!\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:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSmall print\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: Your function may output a number, a char array, or a string; whatever you find simpler (e.g. in the example above, valid outputs are 121, '121', or \\\"121\\\"). Input numbers in testsuite are always relatively low valued positive integers (\u0026lt;10,000)\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\"},{\"partUri\":\"/media/image1.JPEG\",\"contentType\":\"image/JPEG\",\"content\":\"data:image/JPEG;base64,/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCADqASMDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD3+iiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAoopCwA5IAoAKK5fXPH2g6GXjmuxLcp/wAsIRubPoew/EivP9U+MGpTsV02yht0/vSkux/AYA/WsKmIpw3Z6eEyfGYrWnDTu9D2fcB1IH41G08SDLSIB7kV8333jHxFqP8Ax8avc4z0jbyx/wCO4rGlmlnk3zSPI/Tc7EmuZ4+P2Ue5S4Rq2vVqJfj/AJH1C2r6epwb2AH0Mg/xpyanZSn5LqFvo4NfLFFT9ff8pv8A6ow/5/fh/wAE+sBIh6Mp/GnDB6V8sWup6hZEfZb65gHYRysv8jXR6f8AEnxNYYBvVuUH8M6A/qMH9auOPg/iVjkrcJ4mKvSmpfgfQlFeX6R8YbOXbHqllJAe8kR3r+XUfrXf6XrenazbibT7uOdD3U8j6jqPxrqhWhP4WeDisuxOFf76DX5GlRRRWpxBRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAJRSH1Nee+OPiLFoofTtLZJr88O/VYfr6t7fn6GJ1IwV5HThcJVxVRU6SuzpPEfi3S/DNuHvJsytny4U+Z3/DsPc8V434i+Imta6zxRymytCeIoW5I/2m6n8MCuYuLi51G8aaeSSe5lblmO5mPpXoPhT4V3N+q3etl7aA4K26n52/3j/D9Ov0rzZVquIfLDRH2lLLsBlFNVcW+af9bI8/srC61G4W3sreSeZuixrk13Wj/CTV75RJqM8dip/gx5jY/A4/WvXtL0TTtGtxBp9pHAg67Ryfqep/GtGt6eBitZ6nmYzinEVPdw65V+JwVh8J/D9oo+0ie7YdTJIRn8FxXQ23g/w9a4MOkWgI6MYVJ/PGa3KOldUaUI7I8Crj8TWf7ybfzKS6Rp8YwlnAB7IBUc2haXcD97p9tJ/vRKf6Vo0VXKuxh7ap/MzmLz4feGbxCH0qGPPeIbD/47iuX1P4O2Eu59Ov5rds5CSDzFH8j+pr0+is5UKct0ddDNMZQd4VGfOus/D/xBoqtLJafaIB/y0t/n/MdR+VYFlf3WnXK3FlcSQTDo0bYNfVBAYYIBrlPEfgDRvEAaRovs12ek8XBz7joa5KmBtrTZ9HhOKOdezxsLp9V/kcf4Y+LLhhbeIFBHAW5jX/0JR/T8q9VtrqG9t0nt5VkicZVkOQRXzr4l8Har4ZlP2mLzbUnCXEY+U/X+6frS+FvGGoeFrnMDebaMcyW7HAb3Hofepp4qVN8lU1xuQ4fF0/rGXtenT/gH0hRWRoPiGw8RWC3VjLuHG5DwyH0IrX5r0k01dHxdSnKnJwmrNC0UUUyAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAEo6UVyXjrxYnhnRz5RBvpwVgQ9vVj7D/CplJQXMzbD0J16ipU1dsw/iN47GlxvpGly/wCnOP3sin/Uj/4o/p+VeP2dndanfR2trE89xK2FUckn1/8Ar01VudQvcKHnuZ5M4HLOxP8AMmvevA3guHwzp/mzhZNQmUebJj7o/ur7fzx9K8tKWKqXex93UnQyHCKMdakv6+4h8GfD+z8PQpd3SrcakRkyEcR57L/j1rt8YHFFFenCEYKyPhcTiauJqOpVd2xaKKKswCiiigAooooAKKKKACiikJAGTQBBd2tveWzwXMSSwuMMrrkEe9fOnjLT9J0zxDNa6ROZIU++vURv3UHvj9Old58QviEYPN0XRpv3vK3Fyh+56qp/vep7fXp5PFFJPMkMMbSSOQqooyWJ6ACvLxlWMnyRV2fdcNYCvQi8TVlyxfTv5s0/D3iG98Oaml5aOdvSSMn5XX3FfQ3h/XbPxDpUV9aOCrcMvdG7g+9eF6/4F1Tw9o9tqFyA6yDEyoM+SSeAT39PrxzTPBfiqbwxrCuWLWUxCzx57f3h7ipw9WVGXJU2N82wFDNKLxOFacl26+R9GUVDb3EV1bxzwuHjdQyspyCD3qavWPz9pp2YtFFFAgooooAKKKKACiiigAooooAKKKKACiiigAooooAguriO0tpLiZwkcalmY9AAOtfNvinX5vEeuz30hPlZ2wL/AHUHT8e59zXqHxa182WkRaTA+Jbw5kweRGOv5nA/OvLvCuhv4h8Q21gAfLJ3zEdkHX/D6kV5uMqOc1Sifa8OYWGGoTx9b5eh6J8K/CQjhGv3kf7xwRaqw+6vQt9T0Ht9a9VFRW8EdrbxwRKEjRQqqBwAKlrupU1Tgoo+Wx+MnjK8q0+v5C0UUVocYUUUUAFFfI/xQ8Yay/xJ1xLLWL63tobjyFiguXRV2KFPAPqprkP+Es8R/wDQwar/AOBsn+NAH3PRXwx/wlniP/oYNV/8DZP8aP8AhLPEf/Qwar/4Gyf40Afc9FfDH/CWeJP+hg1X/wADJP8A4qvT/gRr2r6h8QZYb7Vb65hFjI2ye4d1zuTnBNAH0sSAMk15X8RPiCbdpdF0eUrN924uFP3P9lT6+p7fXpL8QfiCLMSaRpEubn7s0yn/AFfsPf8AlXkKJLcTqkatJLI2AByWJrz8Vibe5Dc+wyLIlK2KxS91bJ/mxIopJ5UiijZ5HIVUUZJJ7CvcfAPgKPQIV1DUEV9TccDqIQew9/U/gOOrPAPgBNEjXUdSQPqDj5VPIhHoPf3r0GqwuG5ffnuY59nnt39Xw79xbvv/AMAr3tpDfWkttcRrJFIpVlYZBBr5x8WeHpfDWuzWTAmFvngc/wASE/zHSvpauM+I/hsa54eeaGMNd2gMkRA5I7r+IH8q0xVH2kLrdHFkGZPB4lRk/clo/wDM574T+J2lifQ7uTLxjfbEn+Huv4dfx9q9U618s6VqM2k6pb30BxJC4b6juK+nNOvYdR0+3vIG3RTRh1PsRmowdXnhyvdG/EuAWHxHtYfDP8y3RRRXafNhRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABTScAn0paztcvhpuiXt6ekMLP+QpN2VyoRc5KK6ngnj3VjrHjC9kViYoW8iMegXg/+PZr0D4Q6MINJuNWkUb7l9kZ/wBheP8A0LP5V44S80ufmeR2+pYmvp3QdNTSNDs7BORDEq59Tjk/jXm4Re0quoz7fiCawmAp4SHX9DTooor0z4YKKKKACmSyJDE8sjBURSzE9gKfXMfETUf7J+Hev3YbawspEQ+jONin82FAHxlqV6+pareX8md9zM8zZ9WYn+tfR3w++EXhDVPAWj6hrOj/AGi/uYfOkl+0zJuDMSvCuB90r2r5qiieeaOKNSzyMFVfUnpX3dpNiul6NY6emNtrbxwLj0VQv9KAOM/4Ul8PP+he/wDJ24/+OUf8KS+Hn/Qvf+Ttx/8AHK9ApCcDJoA8/PwU+HgHPh//AMnbj/45XDeIIvCfgnUJoPB2ni21No2hnuluZZPLQ4JUbmIzwOe1dT8QfiCLMSaRpEn+kn5ZplP+r9h7/wAq8hRJbiZUjVpJZGwAOSxNefisVb3Ibn1+RZFz2xWKVorZf5+QIktxMsaK0ksjYAHJYmvbfAPgFNEjTUtRRX1Bx8q9RCPQe/vR4A8Apoka6jqSK+oOPlU8iEe3v716DTwuF5ffnuRnue+3vh8O7QW77/8AAFooorvPkwprqHQqehGKdRQB81eMdHGh+KL2zVdsO/zIhjA2NzgfQ5H4V6d8I9YN5oM+nSMC1nJ8o/2G5H65rK+MumhTp2pKACS0LnHJ7r/JvzrB+FWoG08XraliEu4mTGeMj5gf0b868uH7rE26M+8xD/tDJFUfxR/Tf8D3qiiivUPgwooooAKKKKACiiigAooooAKKKKACiiigBK434oXX2fwRdoDhpWRB/wB9DP6A12Vec/GKQp4atEBxvulBHqNrH+grKu7U5HflcFPG00+6PKvC9p9u8UaZb9muEJHqAcn9BX00owoHtXzz8N4/M8eab6JvY/8AfDD+tfQ9cuAX7tvzPb4tnfFxh2QtFFFd58qFFFFABXlX7QGo/Y/hqbUNg3t5FER6hcyfzQV6rXz9+0rqOZNA0xW6CW4df++VX+T0AeVfDnTf7V+I2gWm3cpvI5GHqqHe36Ka+tvEHjXw34VX/ic6vb20mMiEtukI/wBxct+OK+NvD+vXvhnVP7S01lS8WN44pWGTHuUqWHvgnFFlpeueJ7+VrOzvtTunO+V0RpWJPdm/qaAPo+f9obwbFLsit9XuB/eit0A/8ecGqfiD4vQ6xo4j0GC7tmmyGluFVWVf9kAnr614nZ+FLnT7101WERSxHmHcGIPvg8fSt4lUUkkAAdT0Arz8Vire5Dc+wyLIlO2JxS91bIkVZJpQqq0kjtgADJYn+Zr27wD4BTRYk1LUUV9QcfKp5EI9B7+9fOJ8ZXuk6zb3mjyLHJbPuV2QMGPQ5B7YJr6Z+G/xDsvHujGQKtvqduALq2ByB6Ov+yf06e5eFw3L789yM+zz218Nh37q3ff/AIB29FFFd58kFFFFABRRRQBxfxQtPtPgi7cAFoWRx/30Af0JrxfwtdNZ+KtLnUkYuUBI9Cdp/Q17542QSeDdWB7Wzn8lJr5zs5PKvreQcFJVbp6GvLxnu1YyPueG37XAVqL8/wAUfVanKg+1LTIjmJPoKfXqHw73CiiigQUUUUAFFFFABRRRQAUUUUAFFFFABXmvxkH/ABTlkfS7X/0B69Jrhfixbed4MeX/AJ4zI/67f/Zqxrr92z0cply42k/NHmvwzfb48sAf4g4/8cJ/pX0JXzZ4JuRa+M9KlP8Az22cf7QK/wBa+kgcgGufAP8AdteZ7HFkbYyMu8f1Y6iiiu4+WCiiigAr58+M3gXxh4q8bC90zRpLmwgtY4I5Fmj55Zj8pbPViOnavoOgnAoA+X/AnwO1fVNVMvim2m07TYCC0ZI8yc/3RjoPU/l6j0bxd4t0/wAL6f8A8I14VhhtTGNsjQKAsPqB6v6n+tW/iD8QhYiTSNIkzdn5Zp1P+q9h/tfy+tePKsk0oRVaSR2wABksT/M15+KxVvchufXZFkXtLYrFK0Vsu/m/IFWSaUKoaSR2wABksT/M17B4U+Flj/ZEjeIrVbia6jKmAniJT6EH73uOnb3t+APACaNGmp6nGG1Bh8iHkQA/+zep/Ae/olPC4Xl9+e5Oe577ZvD4Z2it33/4B8ffFD4eTeAdcRYnefS7sFrWZ/vDHVG/2hxz3B+oGN4G8UzeDvF1jq8TN5KPsuUX/lpCfvL/AFHuBX098Y9Fi1n4ZaruUGWzQXcTf3SnX/x3cPxr49rvPkz77ikSaJJY2DRuoZWHQg9DUlcd8LNRbU/hhoFw5yy23k5/65sY/wD2WuxoAKKKKACiiigDB8ZMF8HauT/z6SD81NfN9shkuYUXG5nUD86+gviNci28Dai3d1WMD/eYL/WvCNDgNzr+nQhS2+5jBAGeNwzXmY3WpGJ9zwwuTBVqr/qyPqCL/VJ9BT6anCKPanV6aPh3uFFFFAgooooAKKKKACiiigAooooAKKKKAErC8Y2Laj4S1K2QFnaFioA6kcj9QK3abIoaNlPcYqZK6aNKNR06kZrdO58qW072t1DcR43xOHX6g5FfUtjcx3ljBcRNujkRWUjuCOK+aPEOnNpPiC/sWUKIpmCgf3Tyv6EV7P8AC7VxqPhOO2ZgZbMmJh7dV/Tj8K87BS5Jygz7Tiekq+GpYqG3+Z3NFFFemfDhRRQTgUAMd1RSzEBQOSa8v8dfEm3jtvsHh+7jnklX57uFwyop/ukcE+/b69JPiF8QVsVl0fSZAbogrPOp/wBUPQf7X8vr08aJCKSSAAO/QCvPxWKt7kNz6/IsiVRLFYpWitl3/wCASKsk0oVQ0kjtgADJYn+Zr2vwB4ATRo01TU0Daiw+ROogB/8AZvU/gPfjfgrd6FquvX6SANqdsoe33nhk6Myj1Bxn2I9692p4XDcvvz3Iz7PHWbw2Hdord9/+AL0ooorvPkzmviDMkHw58SO5wDps6fiyFR+pr4lr6g/aA8URaZ4OTQo3H2vU3G5QeViRgxP4sFHv83pXzFHG8sqRRqWkchVUDJJPagD67+CSMnwk0Xd/EZ2A9vOevQaxPCOjHw94R0nSWA8y1tUSTHTfj5v/AB7NbdABRRRQAUUUHgUAeZ/GLUDDo1nYq2DcTbmHqqj/ABK/lXC/Day+2eOLLIykIaVsj0GB+pFTfE7Vxqfi+WFH3Q2iiFcHI3dWP1ycf8Brp/g5pPyX2qyL94iGM49OW/mPyry3+9xXofdwX1HInfef6/8AAPWR0ooor1D4QKKKKACiiigAooooAKKKKACiiigAooooAKKKKAPHfjBohjurXWIk+WQeTMR69VP5ZH4CsL4aa+NG8TJbyvttb3Ebegf+E/nkfjXtXiDSIdd0S60+f7sqYBx90jkH8Dg1803lnPp19NaXKGOeFyrD0Iry8SnSqqqj7rJKsMwwE8DU3W3p0+4+qgQRmiuQ+H/ikeItDVZm/wBNtsRzZ43ccN+P8811+RjJr0oSU48yPi8RQnh6rpTWqAkAZNeY/EL4gixEmkaRJm7PyzTqf9V7D/a/l9aPiD8QRYiTSNIk/wBLPyzTqf8AVew/2v5fWvHlWSaUKqtJI7YAAyWJ/ma4cVire5Dc+oyLIlUtisUrRWy7+b8gVZJpQqhpJHbAAGSxP8zV3x/4D8QaD4TtdWcbrd2xdxRjJgz90se49T0Bx1zXr3gDwAmjRpqepxhtQYfIh5EAP/s3qfwHv388EVzA8E8SSQyKUeN1yrKRggjuKeFwvL789xZ5nzrN4fDO0Fu+/wDwD4U0rVb3RdTg1LTrh7e7t33xyL2P9R6jvX0X4S/aB0TULWKDxLHJpt6Bhp40LwufXjLL9MEe9Zfjb9nxbieS+8JXCQ7iWawuGIUf7j9vo35143q3gbxTocjLqGgX8QXq4hLp/wB9rlf1rvPkj6yX4m+CHi8weJ9N2+hmwfyPNcf4p+PvhrSrd49DD6te9FIVo4VPqWIyfwHPqK+YhaXBfYIJS2cY2HNbmk+BPFWtyrHp/h+/kDcCRoSiD6u2FH50AUvEHiDUvFGtT6rqtwZrqY8noqr2VR2Ar1H4G/DqbVtXh8U6lCV06zfdaq6/6+UdGH+yp5z/AHsehre8E/s+LBLFfeLp0k2kMLC3bKn/AH37/Rfzr3W3t4bS3jt7eJIoI1CRxou1VUcAADoKAJqKKKACiiigBKxPFeuR6B4eur5iN6piNT/E54A/Pr7ZraJABPpXhHxM8UDW9YFhbOWs7NiMg8O/c/h0/P1rDEVVThfqeplGXyxuJUOi1focVma7uSfmkmlf6lmJ/wAa+k/CujLoPhyz08HLRpl29WPJP5k15L8LfDn9qa4dTnXNtYkFQRw0h6fl1+uK90HAxXPgadk6j6nscUY5TqRwsNo7+otFFFd58mFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFACV5d8U/CRuYf7dso8zRDFwij7yf3vqP5fSvUeaZJGsqFHGVIwQazq01Ui4s68DjJ4SvGtDofMvh3Xbrw7rEV/bc7flkjzw6nqP8+lejeLvifDJpMdtocjfaLiMGSXGDCD2/3v5VzvxB8Ev4fvDf2UZOmzN0X/AJYse30PY/h6Z4avIdSrQvTP0OGEwOauGM3a3X+foPVXmkCqGkkdsADksTXtXw/8AJo8aapqkYbUHGUQ8iAf1b1Pbp65pfC7wpp4s01yWWK5um4jVTkQe3+9/L+fqQrrwuGt+8lufP8AEGdubeEoaRWj8/L0F7cUUUV6B8iFFFFABRRRQAUUUUAFFFFACUUdB1rg/HPj+DQInsbBkm1FhgjORDx1Pv6ConNQXNI6MNhauJqKlSV2yt8SfGo0m0bSdPl/06ZcO6n/AFK/4nt+dePaXplzrGpQWFom6aVto9AO5PsBzURNzqF7n95cXM7+7M7E/qTXu3gDwWnhuwNzdKrajOP3hznYOyj+vv8AQV5iUsVUu/hR9xOVHIcHyR1qS/r7kdB4e0W30DRrfT7cfLGvzMRy7dyfxrVoor1UklZHwM5yqSc5O7YtFFFMkKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigCvd2kN7bSW1xEskUilWRhkEV4b42+H1z4elkvbBXn00/Me7Q+x9R7/n6n3mmSRpKhR1DKRgg1jWoRqxsz0stzOtgKnNB6dV3PmbQfEWo+HL0XNhNtz9+NuUkHoRXtvhfx/pXiNFiZha3p48iRhlv90965vxb8K4pvMvdBxFJyWtSfkb/dP8P06fSvKLuzutPuWt7uCS3nTqjqQfTP/wBevPUquGdnqj66dHL88hz03y1Px+fc+qc56UtfP+gfEnXNGKxzyfbrYY+SY/MB7N1/PNelaP8AE/w/qaYuJzYy5xtuPlB+jdMV208VTn1PmMbkWMwru48y7rU7alqtb3ttdxLLbzxyIejI4IP41YyD3roTPHaadmLRRRTEJRSFgOpH4msrU/Euj6OM32oQQnGQpYbjj0HU0m0tWXCnObtFXZrVBdXlvZQPPczJFEgyzu2AB715rrfxgtYkeLRrVp5OgmmG1B746n9K8y1nxFqniCfzdRu3lAOVjHCL9FHFclXGQhpHVnv4DhvFYh81VckfPf7j0Dxd8VTKJLLQMqudrXbDqP8AZB/mfy715nDBdalerFCklxdTvwBlmcnkn/69bHh3wdq3iWUfZIdlsDhriQYQfT1PsPxxXt3hjwZpnhi3HkR+ZdMMSXDj5m+noPYfrXNGnVxL5p6I9ytjcDktN0sOuaf9bv8AQxvA3w/h0CNb+/VZdSYcd1hHoPU+p/L372iivShCMFyxPicTiquKqOrVd2xaKKKs5wooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooASsvWPD+l67b+TqFnHMB0JGGX6Ecj8K1KKTSasyoTlCXNB2Z47rnwguYWMujXQmX/njPwR9GHB/IVwOpaDqujsVv7CeDH8TLlf++hx+tfUFNeNXGGUH6iuOpgqctVofR4TifF0Vy1Eprz3PlSC6uLV99vPLC3rG5U/pW3beOPE1pxFrFx/wPD/APoQNe53/gvw9qRZrnSrdnY5Louxj+Iwawrj4TeHJv8AVJcQf7kxP881j9UrR+GR6i4iy6uv39HX0TPN1+JniteuoqfrCn+FMl+I/iuUn/ialR6LCn/xNd8fg3pHbUL7/vpP/iafH8HdFQ5e8vn9i6D+S0ewxP8AMH9qZGtVS/8AJUeUXXiXXL0n7Rq14wPUCUgfkOKzVV5pNqhnkc9ByWNe/Wvwx8L2xDNYtKw/56SsR+WcV0NjommaauLKwt4Bjny4wufyoWCqS+OQpcTYSirYal+SPBtJ+HviLV9rLZG2iP8Ay0uTs/Tr+lekeH/hVpOnbJtSJv7gc7XGIwf93v8AjXoGABwKWumnhKcNdzw8bxBjMUuW/KuyI44khQJGgVVGAAMYFS0UV1Hht33CiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//2Q==\"}]}"},{"id":44364,"title":"Is this a valid Tic Tac Toe State?","description":"For the game of \u003chttps://en.wikipedia.org/wiki/Tic-tac-toe Tic Tac Toe\u003e we will be storing the state of the game in a matrix M.\r\n\r\nFor this game: \r\n\r\n\u003c\u003chttps://upload.wikimedia.org/wikipedia/commons/3/32/Tic_tac_toe.svg\u003e\u003e\r\n\r\nWe would store the state as this:\r\n\r\n  -1  1  1 \r\n   1 -1 -1\r\n   1 -1 -1\r\n\r\nIf there were any blanks squares, they would be 0;\r\n\r\nFor this challenge, X goes first. Neither side is compelled to take a win if possible. The game stops when either player wins.\r\n\r\nFor this challenge, is the the given board state\r\n 0: legal \r\n 1: this state can not occur in a game\r\n\r\nThe example in the image would return 0 because if X goes first there can never be more O than X. The state matrix will only hold [-1 0 1], so we are only checking for logic of the game.","description_html":"\u003cp\u003eFor the game of \u003ca href = \"https://en.wikipedia.org/wiki/Tic-tac-toe\"\u003eTic Tac Toe\u003c/a\u003e we will be storing the state of the game in a matrix M.\u003c/p\u003e\u003cp\u003eFor this game:\u003c/p\u003e\u003cimg src = \"https://upload.wikimedia.org/wikipedia/commons/3/32/Tic_tac_toe.svg\"\u003e\u003cp\u003eWe would store the state as this:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e-1  1  1 \r\n 1 -1 -1\r\n 1 -1 -1\r\n\u003c/pre\u003e\u003cp\u003eIf there were any blanks squares, they would be 0;\u003c/p\u003e\u003cp\u003eFor this challenge, X goes first. Neither side is compelled to take a win if possible. The game stops when either player wins.\u003c/p\u003e\u003cp\u003eFor this challenge, is the the given board state\r\n 0: legal \r\n 1: this state can not occur in a game\u003c/p\u003e\u003cp\u003eThe example in the image would return 0 because if X goes first there can never be more O than X. The state matrix will only hold [-1 0 1], so we are only checking for logic of the game.\u003c/p\u003e","function_template":"function y = isLegalTicTacToeState(M)\r\n  y = round(rand);\r\nend","test_suite":"%%\r\nx = [1 1 0\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [0 0 0\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 1;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [  -1  1  1 \r\n        1 -1 -1\r\n        1 -1 -1];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [ 0 -1 1\r\n     -1  1 0\r\n      1  0 0];\r\ny_correct = 1;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [ 1  1  1\r\n     -1 -1 -1\r\n      0  0  0];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [-1 1 1\r\n     0 -1 1\r\n     1 0 -1];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [-1 1 0\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 1;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [-1 0 0\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [-1 1 0\r\n     0 1 0\r\n     0 1 0];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [1  1  1\r\n     -1 1 -1\r\n     -1 1 -1];\r\ny_correct = 1;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":6,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":123,"test_suite_updated_at":"2017-10-20T22:46:06.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-09T23:21:35.000Z","updated_at":"2026-02-03T09:11:08.000Z","published_at":"2017-10-20T22:46: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\u003eFor the game 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=\\\"https://en.wikipedia.org/wiki/Tic-tac-toe\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eTic Tac Toe\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e we will be storing the state of the game in a matrix M.\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 this game:\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\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\u003eWe would store the state as this:\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[-1  1  1 \\n 1 -1 -1\\n 1 -1 -1]]\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\u003eIf there were any blanks squares, they would be 0;\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 this challenge, X goes first. Neither side is compelled to take a win if possible. The game stops when either player wins.\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 this challenge, is the the given board state 0: legal 1: this state can not occur in a game\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 example in the image would return 0 because if X goes first there can never be more O than X. The state matrix will only hold [-1 0 1], so we are only checking for logic of the game.\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":44365,"title":"An asteroid and a spacecraft","description":"\r\n\u0026#128640 Imagine a non-relativistic simple situation. \r\n\r\nAssume positions p0, p1, p2, and p3 are three dimensional Cartesian coordinates.\r\n\r\nYour spacecraft started from the position p0 at time t0. \r\n\r\nYour spacecraft is moving with a constant velocity.\r\n\r\nYour spacecraft is expected to reach a star at the location p1 at time t1.\r\n\r\nYou just heard over the radio that an asteroid has been identified at the location p2 at time t0.\r\n\r\nThe asteroid is moving with a constant velocity.\r\n\r\nThe asteroid is expected to reach another star at the location p3 at time t1. \r\n\r\nYou need to write a code 'safetrip' in MATLAB to return true if the minimum distance between your spacecraft and the asteroid will be more than the distance d during the time interval between t0 and t1, otherwise return false.","description_html":"\u003cp\u003e\u0026#128640 Imagine a non-relativistic simple situation.\u003c/p\u003e\u003cp\u003eAssume positions p0, p1, p2, and p3 are three dimensional Cartesian coordinates.\u003c/p\u003e\u003cp\u003eYour spacecraft started from the position p0 at time t0.\u003c/p\u003e\u003cp\u003eYour spacecraft is moving with a constant velocity.\u003c/p\u003e\u003cp\u003eYour spacecraft is expected to reach a star at the location p1 at time t1.\u003c/p\u003e\u003cp\u003eYou just heard over the radio that an asteroid has been identified at the location p2 at time t0.\u003c/p\u003e\u003cp\u003eThe asteroid is moving with a constant velocity.\u003c/p\u003e\u003cp\u003eThe asteroid is expected to reach another star at the location p3 at time t1.\u003c/p\u003e\u003cp\u003eYou need to write a code 'safetrip' in MATLAB to return true if the minimum distance between your spacecraft and the asteroid will be more than the distance d during the time interval between t0 and t1, otherwise return false.\u003c/p\u003e","function_template":"function ok = safetrip(d, t0, t1, p0, p1, p2, p3)\r\n    if d\u003e1000000000\r\n        ok = true;\r\n    end\r\nend","test_suite":"%%\r\np0 = [0 0 0];\r\np1 = [1 1 1];\r\np2 = [2 2 2];\r\np3 = [3 3 3];\r\nt0 = 0; \r\nt1 = 1;\r\nd = 1;\r\nok = true;\r\nassert(isequal(safetrip(d, t0, t1, p0, p1, p2, p3), ok))\r\n\r\n%%\r\np0 = [3 3 3];\r\np1 = [2 2 2];\r\np2 = [2 2 2];\r\np3 = [3 3 3];\r\nt0 = 0; \r\nt1 = 1;\r\nd = 1;\r\nok = false;\r\nassert(isequal(safetrip(d, t0, t1, p0, p1, p2, p3), ok))\r\n\r\n%%\r\np0 = [1 2 3];\r\np1 = [4 5 6];\r\np2 = [3 2 1];\r\np3 = [6 5 4];\r\nt0 = 10; \r\nt1 = 20;\r\nd = 2;\r\nok = true;\r\nassert(isequal(safetrip(d, t0, t1, p0, p1, p2, p3), ok))\r\n\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":8,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":168,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-10T02:30:44.000Z","updated_at":"2026-03-26T15:11:20.000Z","published_at":"2017-10-16T01:51:00.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003e\u0026amp;#128640 Imagine a non-relativistic simple situation.\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\u003eAssume positions p0, p1, p2, and p3 are three dimensional Cartesian coordinates.\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\u003eYour spacecraft started from the position p0 at time t0.\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\u003eYour spacecraft is moving with a constant velocity.\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\u003eYour spacecraft is expected to reach a star at the location p1 at time t1.\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\u003eYou just heard over the radio that an asteroid has been identified at the location p2 at time t0.\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\u003eThe asteroid is moving with a constant velocity.\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\u003eThe asteroid is expected to reach another star at the location p3 at time t1.\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\u003eYou need to write a code 'safetrip' in MATLAB to return true if the minimum distance between your spacecraft and the asteroid will be more than the distance d during the time interval between t0 and t1, otherwise return false.\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":44311,"title":"Number of Even Elements in Fibonacci Sequence","description":"Find how many even Fibonacci numbers are available in the first d numbers.\r\n\r\nConsider the following first 14 numbers\r\n\r\n  1 1 2 3 5 8 13 21 34 55 89 144 233 377 ...\r\n\r\n4 of them are even. ","description_html":"\u003cp\u003eFind how many even Fibonacci numbers are available in the first d numbers.\u003c/p\u003e\u003cp\u003eConsider the following first 14 numbers\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e1 1 2 3 5 8 13 21 34 55 89 144 233 377 ...\r\n\u003c/pre\u003e\u003cp\u003e4 of them are even.\u003c/p\u003e","function_template":"function y = evenFibo(d)\r\n  y = x;\r\nend","test_suite":"%%\r\nd = 14;\r\ny_correct = 4;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 20;\r\ny_correct = 6;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 50;\r\ny_correct = 16;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 100;\r\ny_correct = 33;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 150;\r\ny_correct = 50;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 200;\r\ny_correct = 66;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 500;\r\ny_correct = 166;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 1000;\r\ny_correct = 333;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 1e4;\r\ny_correct = 3333;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 2e4;\r\ny_correct = 6666;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 3e5;\r\ny_correct = 1e5;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 6e6;\r\ny_correct = 2e6;\r\nassert(isequal(evenFibo(d),y_correct))\r\n% \r\n% %%\r\n% d = 9223372036854775807;\r\n% y_correct = 3074457345618258432;\r\n% assert(isequal(evenFibo(d),y_correct))\r\n","published":true,"deleted":false,"likes_count":21,"comments_count":9,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1641,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-11T12:36:15.000Z","updated_at":"2026-04-08T12:45:53.000Z","published_at":"2017-10-16T01:50:58.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\u003eFind how many even Fibonacci numbers are available in the first d numbers.\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\u003eConsider the following first 14 numbers\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[1 1 2 3 5 8 13 21 34 55 89 144 233 377 ...]]\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\u003e4 of them are even.\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":281,"title":"Acid and water","description":"\u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878;\r\n\r\nAssume that there is a 100 liter tank. \r\n\r\nIt is initially filled with just distilled water. \r\n\r\nIt is continuously drained at R liters per minute. \r\n\r\nThis tank is always maintained full and homogeneous by continuously adding and stirring R liters per minute of an unknown acid (or some fancy oil if it helps you solving this problem). \r\n\r\nHow many liters W of water will be in the tank after M minutes?\r\n\r\nNeglect any expansion or contraction when the acid is mixed with water. ","description_html":"\u003cp\u003e\u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878;\u003c/p\u003e\u003cp\u003eAssume that there is a 100 liter tank.\u003c/p\u003e\u003cp\u003eIt is initially filled with just distilled water.\u003c/p\u003e\u003cp\u003eIt is continuously drained at R liters per minute.\u003c/p\u003e\u003cp\u003eThis tank is always maintained full and homogeneous by continuously adding and stirring R liters per minute of an unknown acid (or some fancy oil if it helps you solving this problem).\u003c/p\u003e\u003cp\u003eHow many liters W of water will be in the tank after M minutes?\u003c/p\u003e\u003cp\u003eNeglect any expansion or contraction when the acid is mixed with water.\u003c/p\u003e","function_template":"function W = tank(R,M)\r\n  W = 100 * R * M;\r\nend","test_suite":"%%\r\nR=1; \r\nM=1;\r\nW=99;\r\nassert(tank(R,M)\u003eW)\r\n%%\r\nR=2; \r\nM=2;\r\nW=96;\r\nassert(tank(R,M)\u003eW)\r\n%%\r\nR=10; \r\nM=10;\r\nW=36;\r\nassert(tank(R,M)\u003eW)\r\n%%\r\nR=15; \r\nM=20;\r\nW=5;\r\nassert(tank(R,M)\u003cW)\r\n%%\r\nR=7; \r\nM=8;\r\nW=58;\r\nassert(tank(R,M)\u003cW)\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":13,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":261,"test_suite_updated_at":"2012-02-07T16:08:37.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2012-02-07T16:08:37.000Z","updated_at":"2026-03-26T15:49:26.000Z","published_at":"2017-10-16T01:50:58.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003e\u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878;\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\u003eAssume that there is a 100 liter tank.\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\u003eIt is initially filled with just distilled water.\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\u003eIt is continuously drained at R liters per minute.\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\u003eThis tank is always maintained full and homogeneous by continuously adding and stirring R liters per minute of an unknown acid (or some fancy oil if it helps you solving this 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHow many liters W of water will be in the tank after M minutes?\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\u003eNeglect any expansion or contraction when the acid is mixed with water.\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":44372,"title":"Polarisation","description":"You have n polarising filters stacked one on top of another, and you know each axis angle. How much light gets passed through the filter bank? For more information, see \u003chttps://en.wikipedia.org/wiki/Polarizer Polarizer (Wikipedia)\u003e.\r\n\r\n    \u003e\u003e n = [0, 90];\r\n    \u003e\u003e polarised([0, 90])\r\n\r\n    ans = 0","description_html":"\u003cp\u003eYou have n polarising filters stacked one on top of another, and you know each axis angle. How much light gets passed through the filter bank? For more information, see \u003ca href = \"https://en.wikipedia.org/wiki/Polarizer\"\u003ePolarizer (Wikipedia)\u003c/a\u003e.\u003c/p\u003e\u003cpre\u003e    \u0026gt;\u0026gt; n = [0, 90];\r\n    \u0026gt;\u0026gt; polarised([0, 90])\u003c/pre\u003e\u003cpre\u003e    ans = 0\u003c/pre\u003e","function_template":"function y = polarised(x)\r\n  y = max(x);\r\nend","test_suite":"%%\r\nx = 5;\r\ny_correct = 0.5;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\nx = 180;\r\ny_correct = 0.5;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\nx = 365;\r\ny_correct = 0.5;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\nx = [91, 1];\r\ny_correct = 0;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\na = randi([-360, 360]);\r\nb = 90*(1+2*randi([-3, 3]));\r\nx = [a, a+b];\r\ny_correct = 0;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\na = randi([-360, 360]);\r\nb = 90*(1+2*randi([-3, 3]));\r\nx = [a, a+b];\r\ny_correct = 0;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\nx = [0, 22.5];\r\ny_correct = 0.85355339059/2;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\nx = [0, -45];\r\ny_correct = 0.25;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\nx = [5, 140];\r\ny_correct = 0.25;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n%%\r\nx = 5 + (1:5)*22.5;\r\ny_correct = 0.53079004294/2;\r\nassert(abs(polarised(x)-y_correct) \u003c 1e-10)\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":10,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":270,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-10T21:58:52.000Z","updated_at":"2026-04-07T15:12:18.000Z","published_at":"2017-10-16T01:45: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\u003eYou have n polarising filters stacked one on top of another, and you know each axis angle. How much light gets passed through the filter bank? For more information, see\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/Polarizer\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePolarizer (Wikipedia)\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\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    \u003e\u003e n = [0, 90];\\n    \u003e\u003e polarised([0, 90])\\n\\n    ans = 0]]\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":44310,"title":"Digit concentration in Champernowne's constant","description":"Consider the first 50 digits of Champernowne's constant\r\n \r\n    0.12345678910111213141516171819202122232425262728293...\r\n  \r\nThere are two zeros (do not count the left side of \".\" (integer part) ) in this series. So the digit concentration for 0 for the first 50 digits is = 2 / 50 = 0.04.\r\n\r\nAlso the number of '2' (x) digit is counted as 13. So the digit concentration of number '2' for the first 50 (d) digit is = 13/50 = 0.26\r\n\r\nCalculate the digit concentration of number x for the first d digit of constant.\r\n","description_html":"\u003cp\u003eConsider the first 50 digits of Champernowne's constant\u003c/p\u003e\u003cpre\u003e    0.12345678910111213141516171819202122232425262728293...\u003c/pre\u003e\u003cp\u003eThere are two zeros (do not count the left side of \".\" (integer part) ) in this series. So the digit concentration for 0 for the first 50 digits is = 2 / 50 = 0.04.\u003c/p\u003e\u003cp\u003eAlso the number of '2' (x) digit is counted as 13. So the digit concentration of number '2' for the first 50 (d) digit is = 13/50 = 0.26\u003c/p\u003e\u003cp\u003eCalculate the digit concentration of number x for the first d digit of constant.\u003c/p\u003e","function_template":"function concentration = digitCon(d,x)\r\n  y = x;\r\nend","test_suite":"%%\r\nd = 1;\r\nx = 1;\r\ny_correct = 1;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 10;\r\nx = 5;\r\ny_correct = 0.1000;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 10;\r\nx = 1;\r\ny_correct = 0.2000;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 20;\r\nx = 9;\r\ny_correct = 0.0500;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n\r\n%%\r\nd = 50;\r\nx = 0;\r\ny_correct = 0.0400;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 50;\r\nx = 2;\r\ny_correct = 0.2600;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1000;\r\nx = 9;\r\ny_correct = 0.0670;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1e4;\r\nx = 8;\r\ny_correct = 0.0747;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1e5;\r\nx = 7;\r\ny_correct = 0.0864;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1e6;\r\nx = 6;\r\ny_correct = 0.0935;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1e6;\r\nx = 5;\r\ny_correct = 0.0937;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 2e6;\r\nx = 4;\r\ny_correct = 0.0903;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 2000124;\r\nx = 3;\r\ny_correct = 0.1162;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)","published":true,"deleted":false,"likes_count":5,"comments_count":1,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":125,"test_suite_updated_at":"2017-10-25T07:12:47.000Z","rescore_all_solutions":true,"group_id":35,"created_at":"2017-09-11T10:35:46.000Z","updated_at":"2026-02-03T09:31:30.000Z","published_at":"2017-10-16T01:50:58.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\u003eConsider the first 50 digits of Champernowne's constant\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[    0.12345678910111213141516171819202122232425262728293...]]\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\u003eThere are two zeros (do not count the left side of \\\".\\\" (integer part) ) in this series. So the digit concentration for 0 for the first 50 digits is = 2 / 50 = 0.04.\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\u003eAlso the number of '2' (x) digit is counted as 13. So the digit concentration of number '2' for the first 50 (d) digit is = 13/50 = 0.26\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\u003eCalculate the digit concentration of number x for the first d digit of constant.\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":44344,"title":"The 5th Root","description":"Write a function to find the 5th root of a number.\r\n\r\nIt sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method to solve the problem.","description_html":"\u003cp\u003eWrite a function to find the 5th root of a number.\u003c/p\u003e\u003cp\u003eIt sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method to solve the problem.\u003c/p\u003e","function_template":"function f = fifth_root(n)\r\n f = n^(1/5)\r\nend","test_suite":"%%\r\nfiletext = fileread('fifth_root.m');\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'power')),'power() forbidden')\r\nassert(isempty(strfind(filetext, 'mpower')),'mpower() forbidden')\r\nassert(isempty(strfind(filetext, 'realpow')),'realpow() forbidden')\r\nassert(isempty(strfind(filetext, 'nthroot')),'nthroot() forbidden')\r\nassert(isempty(strfind(filetext, 'roots')),'roots() forbidden')\r\n\r\n%%\r\nn = 1/9765625;\r\nassert(abs(fifth_root(n)-1/25)\u003c1e-5)\r\n\r\n%%\r\nn = 1/5555;\r\nassert(abs(fifth_root(n)-0.178263811215444)\u003c1e-5)\r\n\r\n%%\r\nn = 1/3125;\r\nassert(abs(fifth_root(n)-1/5)\u003c1e-5)\r\n\r\n%%\r\nn = 1/125;\r\nassert(abs(fifth_root(n)-0.380730787743176)\u003c1e-5)\r\n\r\n%%\r\nn = 1/5;\r\nassert(abs(fifth_root(n)-0.724779663677696)\u003c1e-5)\r\n\r\n%%\r\nn = 1;\r\nassert(abs(fifth_root(n)-1)\u003c1e-5)\r\n\r\n%%\r\nn = 5;\r\nassert(abs(fifth_root(n)-1.37972966146121)\u003c1e-5)\r\n\r\n%%\r\nn = 25;\r\nassert(abs(fifth_root(n)-1.90365393871588)\u003c1e-5)\r\n\r\n%%\r\nn = 50;\r\nassert(abs(fifth_root(n)-2.18672414788656)\u003c1e-5)\r\n\r\n%%\r\nn = 500;\r\nassert(abs(fifth_root(n)-3.46572421577573)\u003c1e-5)\r\n\r\n%%\r\nn = 3125;\r\nassert(abs(fifth_root(n)-5)\u003c1e-5)\r\n\r\n%%\r\nn = 759375;\r\nassert(abs(fifth_root(n)-15)\u003c1e-5)\r\n\r\n%%\r\nn = 9765625;\r\nassert(abs(fifth_root(n)-25)\u003c1e-5)\r\n\r\n%%\r\nn = 312500000;\r\nassert(abs(fifth_root(n)-50)\u003c1e-5)\r\n\r\n%%\r\nn = 75937500000;\r\nassert(abs(fifth_root(n)-150)\u003c1e-5)\r\n\r\n%%\r\nn = 31250000000000;\r\nassert(abs(fifth_root(n)-500)\u003c1e-5)\r\n\r\n%%\r\nn = 52658067346875;\r\nassert(abs(fifth_root(n)-555)\u003c1e-5)","published":true,"deleted":false,"likes_count":13,"comments_count":3,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":559,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-22T16:03:40.000Z","updated_at":"2026-02-03T09:23:18.000Z","published_at":"2017-10-16T01:50:59.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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 find the 5th root of a 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIt sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method to solve the problem.\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":44337,"title":"Sums of Distinct Powers","description":"You will be given three numbers: base, nstart, and nend.  Write a MATLAB script that will compute the sum of a sequence of both the distinct powers of base as well as sums of distinct powers of base.  Your sequence should start with the 'nstart'th term and end with the 'nend'th term.  For example:\r\n\r\n* base=4\r\n* nstart=2\r\n* nend=6\r\n\r\nThe first several sums of the distinct powers of 4 are:\r\n\r\n* 1 (4^0)\r\n* 4 (4^1)\r\n* 5 (4^1 + 4^0)\r\n* 16 (4^2)\r\n* 17 (4^2 + 4^0)\r\n* 20 (4^2 + 4^1)\r\n* 21 (4^2 + 4^1 + 4^0)\r\n* 64 (4^3)\r\n* 65 (4^3 + 4^0)\r\n\r\nSince nstart=2 and nend=6 in this example, you take the second through the sixth terms of this sequence.  The correct output would be 4+5+16+17+20, or 62.  Notice that the number 8 does not occur in this pattern.  While 8 is a multiple of 4, 8=4^1+4^1.  Because there are two 4^1 terms in the sum, 8 does not qualify as a sum of *distinct* powers of 4.  You can assume that all three will be integers, base\u003e1, and that nstart\u003cnend.  Good luck!","description_html":"\u003cp\u003eYou will be given three numbers: base, nstart, and nend.  Write a MATLAB script that will compute the sum of a sequence of both the distinct powers of base as well as sums of distinct powers of base.  Your sequence should start with the 'nstart'th term and end with the 'nend'th term.  For example:\u003c/p\u003e\u003cul\u003e\u003cli\u003ebase=4\u003c/li\u003e\u003cli\u003enstart=2\u003c/li\u003e\u003cli\u003enend=6\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe first several sums of the distinct powers of 4 are:\u003c/p\u003e\u003cul\u003e\u003cli\u003e1 (4^0)\u003c/li\u003e\u003cli\u003e4 (4^1)\u003c/li\u003e\u003cli\u003e5 (4^1 + 4^0)\u003c/li\u003e\u003cli\u003e16 (4^2)\u003c/li\u003e\u003cli\u003e17 (4^2 + 4^0)\u003c/li\u003e\u003cli\u003e20 (4^2 + 4^1)\u003c/li\u003e\u003cli\u003e21 (4^2 + 4^1 + 4^0)\u003c/li\u003e\u003cli\u003e64 (4^3)\u003c/li\u003e\u003cli\u003e65 (4^3 + 4^0)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eSince nstart=2 and nend=6 in this example, you take the second through the sixth terms of this sequence.  The correct output would be 4+5+16+17+20, or 62.  Notice that the number 8 does not occur in this pattern.  While 8 is a multiple of 4, 8=4^1+4^1.  Because there are two 4^1 terms in the sum, 8 does not qualify as a sum of \u003cb\u003edistinct\u003c/b\u003e powers of 4.  You can assume that all three will be integers, base\u0026gt;1, and that nstart\u0026lt;nend.  Good luck!\u003c/p\u003e","function_template":"function y = sum_distinct_powers(base,nstart,nend)\r\n  y = base*nstart*nend;\r\nend","test_suite":"%%\r\nbase=4;nstart=2;nend=6;y_correct=62;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=5;nstart=1;nend=1000;y_correct=1193853250;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=3;nstart=1;nend=1000;y_correct=14438162;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=3;nstart=100;nend=1000;y_correct=14397354;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=2;nstart=1;nend=2017;y_correct=2035153;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=7;nstart=1234;nend=2345;y_correct=843569026324;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=7;nstart=1;nend=10;y_correct=1265;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nnstart=1;nend=50;\r\njunk=arrayfun(@(base) sum_distinct_powers(base,nstart,nend),2:10);\r\ny_correct=[1275 7120 26365 75000 178591 374560 714465 1266280 2116675];\r\nassert(isequal(junk,y_correct))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":9,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":156,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-18T16:30:15.000Z","updated_at":"2026-02-03T09:26:51.000Z","published_at":"2017-10-16T01:50:59.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\u003eYou will be given three numbers: base, nstart, and nend. Write a MATLAB script that will compute the sum of a sequence of both the distinct powers of base as well as sums of distinct powers of base. Your sequence should start with the 'nstart'th term and end with the 'nend'th term. For example:\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\u003ebase=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\u003enstart=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\u003enend=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\u003eThe first several sums of the distinct powers of 4 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=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1 (4^0)\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\u003e4 (4^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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e5 (4^1 + 4^0)\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\u003e16 (4^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\u003e17 (4^2 + 4^0)\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\u003e20 (4^2 + 4^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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e21 (4^2 + 4^1 + 4^0)\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 (4^3)\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\u003e65 (4^3 + 4^0)\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 nstart=2 and nend=6 in this example, you take the second through the sixth terms of this sequence. The correct output would be 4+5+16+17+20, or 62. Notice that the number 8 does not occur in this pattern. While 8 is a multiple of 4, 8=4^1+4^1. Because there are two 4^1 terms in the sum, 8 does not qualify as a sum of\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\u003edistinct\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e powers of 4. You can assume that all three will be integers, base\u0026gt;1, and that nstart\u0026lt;nend. Good luck!\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":44367,"title":"Inscribed Pentagon? 2","description":"Your function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon may or may not be centered on the circle. The function should return one of the following values:\r\n\r\n -1: the pentagon is not centered on the circle (within 5% of r)^\r\n  0: the pentagon is completely enclosed within the circle but is not inscribed\r\n  1: the pentagon is inscribed in the circle (within ±0.02)\r\n  2: the vertices of the pentagon extend beyond the circle\r\n\r\nPoints will be rounded to the nearest hundredth. See the test cases for examples. (There will not be a case where some vertices are within the circle and others without.)\r\n\r\n^ Due to the asymmetric nature of the pentagon, its centroid does not coincide with center of its inscribing circle, hence the ±5% tolerance window. ","description_html":"\u003cp\u003eYour function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon may or may not be centered on the circle. The function should return one of the following values:\u003c/p\u003e\u003cpre\u003e -1: the pentagon is not centered on the circle (within 5% of r)^\r\n  0: the pentagon is completely enclosed within the circle but is not inscribed\r\n  1: the pentagon is inscribed in the circle (within ±0.02)\r\n  2: the vertices of the pentagon extend beyond the circle\u003c/pre\u003e\u003cp\u003ePoints will be rounded to the nearest hundredth. See the test cases for examples. (There will not be a case where some vertices are within the circle and others without.)\u003c/p\u003e\u003cp\u003e^ Due to the asymmetric nature of the pentagon, its centroid does not coincide with center of its inscribing circle, hence the ±5% tolerance window.\u003c/p\u003e","function_template":"function y = inscribed_pentagon2(p,cp,r)\r\n y = -1;\r\nend","test_suite":"%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,6.58; 6.42,1.92; 3.97,-5.63; -3.97,-5.63; -6.42,1.92];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,4.55; 4.28,1.44; 2.65,-3.59; -2.65,-3.59; -4.28,1.44];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0.5];\r\nr = 8.75;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [1.98,-0.47];\r\nr = 8.75;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,6.58; 6.42,1.92; 3.97,-5.63; -3.97,-5.63; -6.42,1.92] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,4.55; 4.28,1.44; 2.65,-3.59; -2.65,-3.59; -4.28,1.44] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp_temp = [20,8];\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55] + repmat(cp_temp,[5,1]);\r\ncp = [19.5,9.08];\r\nr = 2.5;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp_temp = [20,8];\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55] + repmat(cp_temp,[5,1]);\r\ncp = [19.86,7.19];\r\nr = 7.5;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [25.01,12.47; 25.98,4.58; 18.78,1.23; 13.37,7.03; 17.22,13.97];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.27,11.12; 23.92,5.87; 19.12,3.63; 15.52,7.50; 18.08,12.13];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [32.54,38.78; 38.84,26.41; 29.02,16.59; 16.65,22.89; 18.83,36.61];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.49,35.54; 34.69,27.29; 28.14,20.74; 19.89,24.95; 21.34,34.09];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [26.41,29.04];\r\nr = 6.13;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [27.07,27.66];\r\nr = 9.63;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))","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":88,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-10T15:28:54.000Z","updated_at":"2026-04-02T01:39:53.000Z","published_at":"2017-10-16T01:51:00.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\u003eYour function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon may or may not be centered on the circle. The function should return one of the following values:\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[ -1: the pentagon is not centered on the circle (within 5% of r)^\\n  0: the pentagon is completely enclosed within the circle but is not inscribed\\n  1: the pentagon is inscribed in the circle (within ±0.02)\\n  2: the vertices of the pentagon extend beyond the circle]]\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\u003ePoints will be rounded to the nearest hundredth. See the test cases for examples. (There will not be a case where some vertices are within the circle and others without.)\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^ Due to the asymmetric nature of the pentagon, its centroid does not coincide with center of its inscribing circle, hence the ±5% tolerance window.\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":44340,"title":"Recaman Sequence - III","description":"I want to create a Recaman sequence where there is a \"1\" in the n-th position. So from which integer should I start the Recaman sequence? If there are more than one starting integer that generates a sequence with a 1 in the n-th position, return the lowest one.\r\nFor example if I want to place the digit 1 in the 7th place in the sequence then I should start the sequence from six as follow;\r\nseq = [6 5 3 6 2 7 1 8 16]\r\nYou can also start the sequence with 12 and obtain a series where there is a 1 in 7th position;\r\nseq = [12 11 9 6 2 7 1]\r\nRelated Challenges :\r\nRecaman Sequence - I\r\nRecaman Sequence - II\r\nRecaman Sequence - III","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: 308.167px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 154.083px; transform-origin: 407px 154.083px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; 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 31.5px; text-align: left; transform-origin: 384px 31.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: 371.5px 8px; transform-origin: 371.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eI want to create a Recaman sequence where there is a \"1\" in the n-th position. So from which integer should I start the Recaman sequence? If there are more than one starting integer that generates a sequence with a 1 in the n-th position, return the lowest one.\u003c/span\u003e\u003c/span\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: 368.5px 8px; transform-origin: 368.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example if I want to place the digit 1 in the 7th place in the sequence then I should start the sequence from six as follow;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 104px 8.5px; tab-size: 4; transform-origin: 104px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eseq = [6 5 3 6 2 7 1 8 16]\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; 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: 294.5px 8px; transform-origin: 294.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou can also start the sequence with 12 and obtain a series where there is a 1 in 7th position;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; 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; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 92px 8.5px; tab-size: 4; transform-origin: 92px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eseq = [12 11 9 6 2 7 1]\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; 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: 72.5px 8px; transform-origin: 72.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eRelated Challenges :\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 61.3px; 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; 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\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/44338\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eRecaman Sequence - I\u003c/span\u003e\u003c/span\u003e\u003c/a\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\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/44339\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eRecaman Sequence - II\u003c/span\u003e\u003c/span\u003e\u003c/a\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: 75px 8px; transform-origin: 75px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eRecaman Sequence - III\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function startPoint = RecamanIII(onesplace)\r\n\r\nend","test_suite":"%%\r\nfiletext = fileread('RecamanIII.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'str2num'); \r\nassert(~illegal)\r\n\r\n%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 2;\r\ny_correct = 0;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 3;\r\ny_correct = 4;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 9;\r\ny_correct = 13;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 13;\r\ny_correct = 15;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 15;\r\ny_correct = 26;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 26;\r\ny_correct = 54;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 54;\r\ny_correct = 208;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 208;\r\ny_correct = 2485;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":12,"created_by":8703,"edited_by":223089,"edited_at":"2022-10-11T07:22:46.000Z","deleted_by":null,"deleted_at":null,"solvers_count":89,"test_suite_updated_at":"2022-10-11T07:22:46.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-19T07:36:19.000Z","updated_at":"2026-03-22T11:36:50.000Z","published_at":"2017-10-16T01:50:59.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\u003eI want to create a Recaman sequence where there is a \\\"1\\\" in the n-th position. So from which integer should I start the Recaman sequence? If there are more than one starting integer that generates a sequence with a 1 in the n-th position, return the lowest one.\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\u003eFor example if I want to place the digit 1 in the 7th place in the sequence then I should start the sequence from six as follow;\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[seq = [6 5 3 6 2 7 1 8 16]]]\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou can also start the sequence with 12 and obtain a series where there is a 1 in 7th position;\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[seq = [12 11 9 6 2 7 1]]]\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRelated Challenges :\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:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44338\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - I\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=\\\"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:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44339\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - II\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=\\\"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\u003eRecaman Sequence - III\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":44359,"title":"5th Time's a Charm","description":"Write a function that will return the input value. However, your function must fail the first four times, only functioning properly every fifth time. Furthermore, the first four times the function is called, successively closer, but not correct, values must be supplied by the function.\r\n\r\nFor example, if x = 10, you may return any number not equal to 10 the first function call. Here, we will return 27. Then, the second function call must return a value between 27 and 10, but not equal to either, and so on, until 10 is returned the fifth time.","description_html":"\u003cp\u003eWrite a function that will return the input value. However, your function must fail the first four times, only functioning properly every fifth time. Furthermore, the first four times the function is called, successively closer, but not correct, values must be supplied by the function.\u003c/p\u003e\u003cp\u003eFor example, if x = 10, you may return any number not equal to 10 the first function call. Here, we will return 27. Then, the second function call must return a value between 27 and 10, but not equal to either, and so on, until 10 is returned the fifth time.\u003c/p\u003e","function_template":"function y = fifth_times_a_charm(x)\r\n y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny1 = fifth_times_a_charm(x);\r\nassert(~isequal(y1,x))\r\n\r\ny2 = fifth_times_a_charm(x);\r\nassert(~isequal(y2,x))\r\nassert(abs(x-y2)\u003cabs(x-y1))\r\n\r\ny3 = fifth_times_a_charm(x);\r\nassert(~isequal(y3,x))\r\nassert(abs(x-y3)\u003cabs(x-y2))\r\n\r\ny4 = fifth_times_a_charm(x);\r\nassert(~isequal(y4,x))\r\nassert(abs(x-y4)\u003cabs(x-y3))\r\n\r\ny5 = fifth_times_a_charm(x);\r\nassert(isequal(y5,x))\r\n\r\n%%\r\nx = -1;\r\ny1 = fifth_times_a_charm(x);\r\nassert(~isequal(y1,x))\r\n\r\ny2 = fifth_times_a_charm(x);\r\nassert(~isequal(y2,x))\r\nassert(abs(x-y2)\u003cabs(x-y1))\r\n\r\ny3 = fifth_times_a_charm(x);\r\nassert(~isequal(y3,x))\r\nassert(abs(x-y3)\u003cabs(x-y2))\r\n\r\ny4 = fifth_times_a_charm(x);\r\nassert(~isequal(y4,x))\r\nassert(abs(x-y4)\u003cabs(x-y3))\r\n\r\ny5 = fifth_times_a_charm(x);\r\nassert(isequal(y5,x))\r\n\r\n%%\r\nx = 42;\r\ny1 = fifth_times_a_charm(x);\r\nassert(~isequal(y1,x))\r\n\r\ny2 = fifth_times_a_charm(x);\r\nassert(~isequal(y2,x))\r\nassert(abs(x-y2)\u003cabs(x-y1))\r\n\r\ny3 = fifth_times_a_charm(x);\r\nassert(~isequal(y3,x))\r\nassert(abs(x-y3)\u003cabs(x-y2))\r\n\r\ny4 = fifth_times_a_charm(x);\r\nassert(~isequal(y4,x))\r\nassert(abs(x-y4)\u003cabs(x-y3))\r\n\r\ny5 = fifth_times_a_charm(x);\r\nassert(isequal(y5,x))\r\n\r\n%%\r\nx = i;\r\ny1 = fifth_times_a_charm(x);\r\nassert(~isequal(y1,x))\r\n\r\ny2 = fifth_times_a_charm(x);\r\nassert(~isequal(y2,x))\r\nassert(abs(x-y2)\u003cabs(x-y1))\r\n\r\ny3 = fifth_times_a_charm(x);\r\nassert(~isequal(y3,x))\r\nassert(abs(x-y3)\u003cabs(x-y2))\r\n\r\ny4 = fifth_times_a_charm(x);\r\nassert(~isequal(y4,x))\r\nassert(abs(x-y4)\u003cabs(x-y3))\r\n\r\ny5 = fifth_times_a_charm(x);\r\nassert(isequal(y5,x))","published":true,"deleted":false,"likes_count":7,"comments_count":5,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":193,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-03T17:35:55.000Z","updated_at":"2026-03-13T03:06:49.000Z","published_at":"2017-10-16T01:51:00.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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 that will return the input value. However, your function must fail the first four times, only functioning properly every fifth time. Furthermore, the first four times the function is called, successively closer, but not correct, values must be supplied by the function.\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\u003eFor example, if x = 10, you may return any number not equal to 10 the first function call. Here, we will return 27. Then, the second function call must return a value between 27 and 10, but not equal to either, and so on, until 10 is returned the fifth time.\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":44350,"title":"Breaking Out of the Matrix","description":"Do you want to take the Red Pill, or the Blue Pill?\r\n\r\nIf you take the Blue Pill, you will simply pass along to the next problem, not knowing what Cody has in store for you.\r\n\r\nIf you take the Red Pill, you will be asked to write a MATLAB function that will Break a Matrix. The inputs to the function will be a matrix M, along with a number of rows (R) and columns (C). You goal is to break the larger 2-D matrix up into a 3-D matrix comprised of enough RxC matrices so that you can recreate the 2-D matrix. When creating your 3-D matrix, go down the columns first, and then across the rows.  Increment only one column (or one row) at a time.  Do not go C columns down at each step.\r\n\r\nFor example, R=2 and C=3, and M is as follows:\r\n\r\n M=[1 4 7 10\r\n    2 5 8 11\r\n    3 6 9 12]\r\n\r\nThis means that your output should be a 2x3x4 matrix:\r\n\r\n X(:,:,1) =\r\n     1     4     7\r\n     2     5     8\r\n X(:,:,2) =\r\n     2     5     8\r\n     3     6     9\r\n X(:,:,3) =\r\n     4     7    10\r\n     5     8    11\r\n X(:,:,4) =\r\n     5     8    11\r\n     6     9    12\r\n\r\nYou can assume that R and C will always be less than or equal to the appropriate dimension of the original matrix. Good luck!\r\n","description_html":"\u003cp\u003eDo you want to take the Red Pill, or the Blue Pill?\u003c/p\u003e\u003cp\u003eIf you take the Blue Pill, you will simply pass along to the next problem, not knowing what Cody has in store for you.\u003c/p\u003e\u003cp\u003eIf you take the Red Pill, you will be asked to write a MATLAB function that will Break a Matrix. The inputs to the function will be a matrix M, along with a number of rows (R) and columns (C). You goal is to break the larger 2-D matrix up into a 3-D matrix comprised of enough RxC matrices so that you can recreate the 2-D matrix. When creating your 3-D matrix, go down the columns first, and then across the rows.  Increment only one column (or one row) at a time.  Do not go C columns down at each step.\u003c/p\u003e\u003cp\u003eFor example, R=2 and C=3, and M is as follows:\u003c/p\u003e\u003cpre\u003e M=[1 4 7 10\r\n    2 5 8 11\r\n    3 6 9 12]\u003c/pre\u003e\u003cp\u003eThis means that your output should be a 2x3x4 matrix:\u003c/p\u003e\u003cpre\u003e X(:,:,1) =\r\n     1     4     7\r\n     2     5     8\r\n X(:,:,2) =\r\n     2     5     8\r\n     3     6     9\r\n X(:,:,3) =\r\n     4     7    10\r\n     5     8    11\r\n X(:,:,4) =\r\n     5     8    11\r\n     6     9    12\u003c/pre\u003e\u003cp\u003eYou can assume that R and C will always be less than or equal to the appropriate dimension of the original matrix. Good luck!\u003c/p\u003e","function_template":"function y = BreakTheMatrix(M,R,C)\r\n  y = x;\r\nend","test_suite":"%%\r\nM=[1 4 7 10;\r\n2 5 8 11;\r\n3 6 9 12];\r\nR=2;C=3;\r\nX(:,:,1) =[1 4 7 ; 2 5 8];\r\nX(:,:,2) =[2 5 8 ; 3 6 9];\r\nX(:,:,3) =[4 7 10 ; 5 8 11];\r\nX(:,:,4) =[5 8 11 ; 6 9 12];\r\nassert(isequal(BreakTheMatrix(M,R,C),X))\r\n%%\r\nx=1:ceil(35+25*rand());r=1;c=1;\r\nM=BreakTheMatrix(x,r,c);\r\nassert(all(arrayfun(@(y) (M(:,:,y)==y),1:numel(x))))\r\n%%\r\nx=eye(7);r=2;c=2;\r\nM=BreakTheMatrix(x,r,c);\r\nids=[1 8 15 22 29 36];\r\nurs=ids(1:5)+1;\r\nlls=urs+5;\r\nz=setxor(1:size(M,3),[ids urs lls]);\r\na1=arrayfun(@(a) isequal(M(:,:,a),eye(2)),ids);\r\na2=arrayfun(@(a) isequal(M(:,:,a),[0 1 ; 0 0]),urs);\r\na3=arrayfun(@(a) isequal(M(:,:,a),[0 0 ; 1 0]),lls);\r\na4=arrayfun(@(a) isequal(M(:,:,a),zeros(2)),z);\r\nassert(all([a1 a2 a3 a4]))\r\n%%\r\nu=ceil(10*rand())+4;\r\nx=magic(u);r=u;c=u;\r\nM=BreakTheMatrix(x,r,c);\r\nassert(isequal(M,x))\r\n%%\r\ntemp=ceil(8*rand)+3;\r\nx=ones(temp);r=2;c=2;\r\nM=BreakTheMatrix(x,r,c);\r\nassert(size(M,3)==(temp-1)^2);\r\nassert(all(arrayfun(@(a) isequal(M(:,:,a),ones(2)),1:size(M,3))))\r\n%%\r\nx=eye(7);r=7;c=7;\r\nassert(isequal(x,BreakTheMatrix(x,r,c)))","published":true,"deleted":false,"likes_count":9,"comments_count":14,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":379,"test_suite_updated_at":"2017-10-31T19:02:59.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-28T14:36:19.000Z","updated_at":"2026-03-31T15:14:35.000Z","published_at":"2017-10-16T01:45:08.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\u003eDo you want to take the Red Pill, or the Blue Pill?\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\u003eIf you take the Blue Pill, you will simply pass along to the next problem, not knowing what Cody has in store for you.\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\u003eIf you take the Red Pill, you will be asked to write a MATLAB function that will Break a Matrix. The inputs to the function will be a matrix M, along with a number of rows (R) and columns (C). You goal is to break the larger 2-D matrix up into a 3-D matrix comprised of enough RxC matrices so that you can recreate the 2-D matrix. When creating your 3-D matrix, go down the columns first, and then across the rows. Increment only one column (or one row) at a time. Do not go C columns down at each step.\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 example, R=2 and C=3, and M is as follows:\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[ M=[1 4 7 10\\n    2 5 8 11\\n    3 6 9 12]]]\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\u003eThis means that your output should be a 2x3x4 matrix:\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[ X(:,:,1) =\\n     1     4     7\\n     2     5     8\\n X(:,:,2) =\\n     2     5     8\\n     3     6     9\\n X(:,:,3) =\\n     4     7    10\\n     5     8    11\\n X(:,:,4) =\\n     5     8    11\\n     6     9    12]]\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\u003eYou can assume that R and C will always be less than or equal to the appropriate dimension of the original matrix. Good luck!\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":44352,"title":"The Top 5 Primes","description":"This problem series invites you to solve two simple problems related to the integer NUMBER FIVE, in order to celebrate \u003chttps://www.mathworks.com/matlabcentral/cody/contests/1?s_tid=Cody5YA_cody_home Cody's 5th birthday\u003e. \r\n\r\nIn this problem, let's find the top 5 greatest prime numbers along the first non-singleton dimension of an input array. \r\n\r\nExample \r\n\r\n* If the input is a vector, the output is a length-5 vector containing the top 5 prime numbers of the input sorted in descending order. Append NaNs as needed in the output if the number of primes is less than 5. \r\n\r\n  x = 1:10;\r\n  y = [7 5 3 2 NaN];\r\n\r\n* If the input is a m-by-n (m \u003e= 5) matrix, the output is a 5-by-n matrix containing the column-wise top 5 prime numbers of the input matrix sorted in descending order. Whenever there are less than 5 primes found in a specific column of the input, simply append NaNs as needed in the same column of the output. \r\n\r\n  % Input x is a matrix\r\n  x = [17     6     3\r\n       13     8    17\r\n        1     2     5\r\n        5     3     7\r\n        7    11     2\r\n       31     7     6];\r\n\r\n  % Output y\r\n  y = [31    11    17\r\n       17     7     7\r\n       13     3     5\r\n        7     2     3\r\n        5   NaN     2];\r\n\r\nPrevious problem in this series: \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44342-spot-the-first-occurrence-of-5 Spot the First Occurrence of 5\u003e","description_html":"\u003cp\u003eThis problem series invites you to solve two simple problems related to the integer NUMBER FIVE, in order to celebrate \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/contests/1?s_tid=Cody5YA_cody_home\"\u003eCody's 5th birthday\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eIn this problem, let's find the top 5 greatest prime numbers along the first non-singleton dimension of an input array.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cul\u003e\u003cli\u003eIf the input is a vector, the output is a length-5 vector containing the top 5 prime numbers of the input sorted in descending order. Append NaNs as needed in the output if the number of primes is less than 5.\u003c/li\u003e\u003c/ul\u003e\u003cpre class=\"language-matlab\"\u003ex = 1:10;\r\ny = [7 5 3 2 NaN];\r\n\u003c/pre\u003e\u003cul\u003e\u003cli\u003eIf the input is a m-by-n (m \u0026gt;= 5) matrix, the output is a 5-by-n matrix containing the column-wise top 5 prime numbers of the input matrix sorted in descending order. Whenever there are less than 5 primes found in a specific column of the input, simply append NaNs as needed in the same column of the output.\u003c/li\u003e\u003c/ul\u003e\u003cpre class=\"language-matlab\"\u003e% Input x is a matrix\r\nx = [17     6     3\r\n     13     8    17\r\n      1     2     5\r\n      5     3     7\r\n      7    11     2\r\n     31     7     6];\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003e% Output y\r\ny = [31    11    17\r\n     17     7     7\r\n     13     3     5\r\n      7     2     3\r\n      5   NaN     2];\r\n\u003c/pre\u003e\u003cp\u003ePrevious problem in this series: \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44342-spot-the-first-occurrence-of-5\"\u003eSpot the First Occurrence of 5\u003c/a\u003e\u003c/p\u003e","function_template":"function y = top5primes(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nassessFunctionAbsence({'regexp','regexpi','regexprep','str2num'},'FileName','top5primes.m')\r\n\r\n%%\r\nx = 1:10;\r\ny_correct = [7 5 3 2 NaN];\r\nassert(isequaln(top5primes(x),y_correct))\r\n\r\n%%\r\nx = (1:2:100).';\r\ny_correct = [97 89 83 79 73].';\r\nassert(isequaln(top5primes(x),y_correct))\r\n\r\n%%\r\nx = [17     6     3\r\n     13     8    17\r\n      1     2     5\r\n      5     3     7\r\n      7    11     2\r\n     31     7     6];\r\ny_correct = [31    11    17\r\n             17     7     7\r\n             13     3     5\r\n              7     2     3\r\n              5   NaN     2];\r\nassert(isequaln(top5primes(x),y_correct))\r\n\r\n%%\r\nx = interp1(magic(30).',1:5).';\r\ny_correct = [877   733   863   719   881\r\n             829   701   751   173   769\r\n             797   139    59   157    29\r\n              89   107    43   109    13\r\n              73   NaN    11    61   NaN];\r\nassert(isequaln(top5primes(x),y_correct))\r\n\r\n%%\r\nrng(0);\r\nx = reshape(randperm(200,180),36,5);\r\ny_correct = [163   181   173   197   193\r\n              71   179   149   191   157\r\n              23   167   113   139   151\r\n              19   131   101    83   137\r\n             NaN   109    67    73   127];\r\nassert(isequaln(top5primes(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":342,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-01T01:52:48.000Z","updated_at":"2026-04-07T13:51:21.000Z","published_at":"2017-10-16T01:45:08.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 problem series invites you to solve two simple problems related to the integer NUMBER FIVE, in order to celebrate\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://www.mathworks.com/matlabcentral/cody/contests/1?s_tid=Cody5YA_cody_home\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody's 5th birthday\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\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn this problem, let's find the top 5 greatest prime numbers along the first non-singleton dimension of an input array.\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\u003eExample\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\u003eIf the input is a vector, the output is a length-5 vector containing the top 5 prime numbers of the input sorted in descending order. Append NaNs as needed in the output if the number of primes is less than 5.\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[x = 1:10;\\ny = [7 5 3 2 NaN];]]\u003e\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\u003eIf the input is a m-by-n (m \u0026gt;= 5) matrix, the output is a 5-by-n matrix containing the column-wise top 5 prime numbers of the input matrix sorted in descending order. Whenever there are less than 5 primes found in a specific column of the input, simply append NaNs as needed in the same column of the output.\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[% Input x is a matrix\\nx = [17     6     3\\n     13     8    17\\n      1     2     5\\n      5     3     7\\n      7    11     2\\n     31     7     6];\\n\\n% Output y\\ny = [31    11    17\\n     17     7     7\\n     13     3     5\\n      7     2     3\\n      5   NaN     2];]]\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 in this series:\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://www.mathworks.com/matlabcentral/cody/problems/44342-spot-the-first-occurrence-of-5\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSpot the First Occurrence of 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":44386,"title":"Circumscribed Pentagon?","description":"Building off of \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44368 Problem 44368\u003e, your function will be provided with the five vertices of a regular pentagon (p) as well as the center point (cp) and radius (r) of a circle. The function should return one of the following values:\r\n\r\n  0: the pentagon is completely enclosed within the circle but is not inscribed\r\n  1: the pentagon is inscribed in the circle (within ±0.02)\r\n  2: the vertices of the pentagon extend beyond the circle, but its edges still cross back into the circle\r\n  3: the pentagon circumscribes the circle (within ±0.02)\r\n  4: the pentagon completely encloses, and does not touch, the circle\r\n\r\nPoints will be rounded to the nearest hundredth. See the test cases for examples.","description_html":"\u003cp\u003eBuilding off of \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44368\"\u003eProblem 44368\u003c/a\u003e, your function will be provided with the five vertices of a regular pentagon (p) as well as the center point (cp) and radius (r) of a circle. The function should return one of the following values:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e0: the pentagon is completely enclosed within the circle but is not inscribed\r\n1: the pentagon is inscribed in the circle (within ±0.02)\r\n2: the vertices of the pentagon extend beyond the circle, but its edges still cross back into the circle\r\n3: the pentagon circumscribes the circle (within ±0.02)\r\n4: the pentagon completely encloses, and does not touch, the circle\r\n\u003c/pre\u003e\u003cp\u003ePoints will be rounded to the nearest hundredth. See the test cases for examples.\u003c/p\u003e","function_template":"function y = circumscribed_pentagon(p,cp,r)\r\n  y = 0;\r\nend","test_suite":"%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5.61; 5.40,1.69; 3.34,-4.66; -3.34,-4.66; -5.40,1.69];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,6.18; 5.88,1.91; 3.63,-5.00; -3.63,-5.00; -5.88,1.91];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 3;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,4.55; 4.28,1.44; 2.65,-3.59; -2.65,-3.59; -4.28,1.44];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [20,13.61; 25.40,9.69; 23.34,3.34; 16.66,3.34; 14.60,9.69];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [20,14.18; 25.88,9.91; 23.63,3.00; 16.37,3.00; 14.12,9.91];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 3;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,6.58; 6.42,1.92; 3.97,-5.63; -3.97,-5.63; -6.42,1.92] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 4;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,4.55; 4.28,1.44; 2.65,-3.59; -2.65,-3.59; -4.28,1.44] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [25.01,12.47; 25.98,4.58; 18.78,1.23; 13.37,7.03; 17.22,13.97];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 4;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.27,11.12; 23.92,5.87; 19.12,3.63; 15.52,7.50; 18.08,12.13];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 1;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [32.54,38.78; 38.84,26.41; 29.02,16.59; 16.65,22.89; 18.83,36.61];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 4;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.49,35.54; 34.69,27.29; 28.14,20.74; 19.89,24.95; 21.34,34.09];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 0;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [26.97,34.06; 32.37,30.14; 30.31,23.79; 23.63,23.79; 21.57,30.14];\r\ncp = [26.97,28.45];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))\r\n\r\n%%\r\np = [31.35,32.83; 32.49,25.64; 26.00,22.34; 20.85,27.48; 24.16,33.97];\r\ncp = [26.97,28.45];\r\nr = 5.01;\r\ny_correct = 3;\r\nassert(isequal(circumscribed_pentagon(p,cp,r),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":64,"test_suite_updated_at":"2017-12-08T15:45:11.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-13T20:03:45.000Z","updated_at":"2025-11-04T13:12:51.000Z","published_at":"2017-10-16T01:51:02.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\u003eBuilding 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=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44368\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44368\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, your function will be provided with the five vertices of a regular pentagon (p) as well as the center point (cp) and radius (r) of a circle. The function should return one of the following values:\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[0: the pentagon is completely enclosed within the circle but is not inscribed\\n1: the pentagon is inscribed in the circle (within ±0.02)\\n2: the vertices of the pentagon extend beyond the circle, but its edges still cross back into the circle\\n3: the pentagon circumscribes the circle (within ±0.02)\\n4: the pentagon completely encloses, and does not touch, the circle]]\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\u003ePoints will be rounded to the nearest hundredth. See the test cases for examples.\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":44306,"title":"Is it really a 5?","description":"A number containing at least one five will be passed to your function, which must return true or false depending upon whether the English spelling of the number may contain \"five\" anywhere. For example:\r\n\r\n n = 5; return true since it is spelled \"five\"\r\n n = 15; return false since it is spelled \"fifteen\" and does not contain the four-letter string \"five\"\r\n\r\nThis criterion applies to any common spelling of the number. For example, 1500 can be written fifteen hundred. But, it can also be written one thousand five hundred. So, 1500 would be considered to contain a \"five\" for this problem.\r\n\r\nSee the test suite for more examples.","description_html":"\u003cp\u003eA number containing at least one five will be passed to your function, which must return true or false depending upon whether the English spelling of the number may contain \"five\" anywhere. For example:\u003c/p\u003e\u003cpre\u003e n = 5; return true since it is spelled \"five\"\r\n n = 15; return false since it is spelled \"fifteen\" and does not contain the four-letter string \"five\"\u003c/pre\u003e\u003cp\u003eThis criterion applies to any common spelling of the number. For example, 1500 can be written fifteen hundred. But, it can also be written one thousand five hundred. So, 1500 would be considered to contain a \"five\" for this problem.\u003c/p\u003e\u003cp\u003eSee the test suite for more examples.\u003c/p\u003e","function_template":"function tf = is_it_really_a_5(n)\r\n tf = 0;\r\nend","test_suite":"%%\r\nn = 5;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 15;\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 25;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 35;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 50;\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 52;\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 55;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 59;\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 85;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 105;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 115;\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 125;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 250;\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 500;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 555;\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 5000; %5,000\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 15000; %15,000\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 55555; %55,555\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 50000; %50,000\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 55000; %55,000\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 50500; %50,500\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 50050; %50,050\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 50005; %50,005\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 500000; %500,000\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 5000000; %5,000,000\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 15000000; %15,000,000\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 50000000; %50,000,000\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 105000000; %105,000,000\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 50050050; %50,050,050\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 50000005; %50,000,005\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 50000015; %50,000,015\r\nassert(isequal(is_it_really_a_5(n),0))\r\n\r\n%%\r\nn = 500000000; %500,000,000\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 5000000000; %5,000,000,000\r\nassert(isequal(is_it_really_a_5(n),1))\r\n\r\n%%\r\nn = 50000000000; %50,000,000,000\r\nassert(isequal(is_it_really_a_5(n),0))","published":true,"deleted":false,"likes_count":7,"comments_count":1,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":317,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-08T22:07:48.000Z","updated_at":"2026-04-15T11:02:38.000Z","published_at":"2017-10-16T01:45: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\u003eA number containing at least one five will be passed to your function, which must return true or false depending upon whether the English spelling of the number may contain \\\"five\\\" anywhere. 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 = 5; return true since it is spelled \\\"five\\\"\\n n = 15; return false since it is spelled \\\"fifteen\\\" and does not contain the four-letter string \\\"five\\\"]]\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\u003eThis criterion applies to any common spelling of the number. For example, 1500 can be written fifteen hundred. But, it can also be written one thousand five hundred. So, 1500 would be considered to contain a \\\"five\\\" for this 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\u003eSee the test suite for more examples.\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":44341,"title":"Hexagonal numbers on a spiral matrix","description":"Put hexagonal numbers in a ( m x m ) spiral matrix and return the sum of its diagonal elements.\r\n\r\nFormula of hexagonal numbers h(n) = 2n^2 - n\r\n\r\nIf m = 5;\r\n\r\n  spiral(5) =   \r\n    21    22    23    24    25\r\n    20     7     8     9    10\r\n    19     6     1     2    11\r\n    18     5     4     3    12\r\n    17    16    15    14    13\r\n\r\nFirst 5x5=25 hexagonal numbers are;\r\n\r\n  h = [1 6 15 28 45 66 91 120 153 190 231 276 325 378 435 496 561 630 703 780 861 946 1035 1128 1225]\r\n\r\nWe put them in a spiral format;\r\n\r\n   spiralHex = [\r\n861\t946\t1035\t1128\t1225\r\n780\t91\t120\t153\t190\r\n703\t66\t1\t6\t231\r\n630\t45\t28\t15\t276\r\n561\t496\t435\t378\t325\r\n\r\nAnd sum its diag = 861 + 91 + 1 + 15 + 325 = 1293.\r\n\r\nReturn the output as char.","description_html":"\u003cp\u003ePut hexagonal numbers in a ( m x m ) spiral matrix and return the sum of its diagonal elements.\u003c/p\u003e\u003cp\u003eFormula of hexagonal numbers h(n) = 2n^2 - n\u003c/p\u003e\u003cp\u003eIf m = 5;\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003espiral(5) =   \r\n  21    22    23    24    25\r\n  20     7     8     9    10\r\n  19     6     1     2    11\r\n  18     5     4     3    12\r\n  17    16    15    14    13\r\n\u003c/pre\u003e\u003cp\u003eFirst 5x5=25 hexagonal numbers are;\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eh = [1 6 15 28 45 66 91 120 153 190 231 276 325 378 435 496 561 630 703 780 861 946 1035 1128 1225]\r\n\u003c/pre\u003e\u003cp\u003eWe put them in a spiral format;\u003c/p\u003e\u003cpre\u003e   spiralHex = [\r\n861\t946\t1035\t1128\t1225\r\n780\t91\t120\t153\t190\r\n703\t66\t1\t6\t231\r\n630\t45\t28\t15\t276\r\n561\t496\t435\t378\t325\u003c/pre\u003e\u003cp\u003eAnd sum its diag = 861 + 91 + 1 + 15 + 325 = 1293.\u003c/p\u003e\u003cp\u003eReturn the output as char.\u003c/p\u003e","function_template":"function y = hexagonalSpiral(m)\r\n  \r\nend","test_suite":"%%\r\nm = 1;\r\ny_correct = '1';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 2;\r\ny_correct = '16';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 5;\r\ny_correct = '1293';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 16;\r\ny_correct = '420800';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 100;\r\ny_correct = '4000333360';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 1295;\r\ny_correct = '1456830580539887';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 2500;\r\ny_correct = '39062505208334000';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 5000;\r\ny_correct = '1250000041666668000';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 8000;\r\ny_correct = '13107200170666668800';\r\nassert(isequal(hexagonalSpiral(m),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":164,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-19T08:06:36.000Z","updated_at":"2025-12-26T10:11:44.000Z","published_at":"2017-10-16T01:50:59.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\u003ePut hexagonal numbers in a ( m x m ) spiral matrix and return the sum of its diagonal elements.\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\u003eFormula of hexagonal numbers h(n) = 2n^2 - n\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\u003eIf m = 5;\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[spiral(5) =   \\n  21    22    23    24    25\\n  20     7     8     9    10\\n  19     6     1     2    11\\n  18     5     4     3    12\\n  17    16    15    14    13]]\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\u003eFirst 5x5=25 hexagonal numbers are;\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[h = [1 6 15 28 45 66 91 120 153 190 231 276 325 378 435 496 561 630 703 780 861 946 1035 1128 1225]]]\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\u003eWe put them in a spiral format;\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[   spiralHex = [\\n861  946  1035  1128  1225\\n780  91  120  153  190\\n703  66  1  6  231\\n630  45  28  15  276\\n561  496  435  378  325]]\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\u003eAnd sum its diag = 861 + 91 + 1 + 15 + 325 = 1293.\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\u003eReturn the output as char.\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":44353,"title":"Group-wise Euclidean distance","description":"*Input*:\r\n \r\n* *x* —— An array of size *n-by-d*, where each row vector denotes a point in a d-dimensional space;\r\n* *g* —— A grouping (index) vector g of size *n-by-1*, which divides the points in x into groups. Specifically, the rows in x corresponding to the same group index in g belong to the same group. \r\n\r\n*Output*: \r\n\r\n* *y* —— The group-wise Euclidean distance matrix associated with the points in x. Suppose that m = max(g), then y will be an *m-by-m* matrix, where each element y(i,j) is the Euclidean distance between group i and group j, which is defined as the minimum of the Euclidean distances between any points in group i and any other points in group j. \r\n\r\n*Example*:\r\n\r\nExample 1: n = 6, d = 1\r\n\r\n  g = [2   1   3  2  1].';\r\n  x = [3  10  15  8  5].';\r\n  y = [0   2   5            % y(1,2) = y(2,1) = min(10-3,5-3,10-8,8-5) = 2\r\n       2   0   7            % y(1,3) = y(3,1) = min(15-10,15-5) = 5\r\n       5   7   0];          % y(2,3) = y(3,2) = min(15-3,15-8) = 7\r\n\r\nExample 2: n = 3, d = 2\r\n\r\n  g = [1 2 2].';\r\n  x = [0   0\r\n       5  12\r\n       3   4];\r\n  y = [0  5;\r\n       5  0];    % y(1,2) = y(2,1) = min(sqrt(5^2+12^2),sqrt(3^2+4^2)) = 5\r\n  \r\n*Testing*:\r\n\r\nThe test suite will focus mainly on the large-scale problem dimensions (e.g., large n and/or d). The purpose is to direct attention towards efficient runtime speed of execution. Note that your solution may run into a time-out error if it is not sufficiently efficient (which is why this problem falls into the \u003chttps://www.mathworks.com/matlabcentral/cody/groups/35 Cody5:Hard\u003e category).\r\n\r\n*Scoring*:\r\n\r\nWe have modified Cody's default size-based scoring function into a performance-based scoring system (implemented by our fellow Cody player \u003chttps://www.mathworks.com/matlabcentral/cody/players/3021298-ly-cao LY Cao\u003e), in which the score of your submission equals 5 times the execution time of your solution (which reprents a score resolution of 0.2 seconds and allows for more room for performance improvement). Please ignore the code size and focus only on improving the code performance, as our test suite will reject any submissions running longer than 20 seconds (in contrast to Cody's default 40 seconds timeout limit).  \r\n\r\nPlease be advised that an amazingly fast solution would earn a score \u003c 5, meaning that it completes execution of all test cases within a second!\r\n\r\n*Update* (11/21/2017):\r\nAdditional test cases are added to ban cheater solutions (e.g., hard-coded submissions 1351541, 1351007, 1350563, 1349442, all came from \u003chttps://www.mathworks.com/matlabcentral/cody/players/3931805-marco-tullio Marco Tullio\u003e).\r\n","description_html":"\u003cp\u003e\u003cb\u003eInput\u003c/b\u003e:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003cb\u003ex\u003c/b\u003e —— An array of size \u003cb\u003en-by-d\u003c/b\u003e, where each row vector denotes a point in a d-dimensional space;\u003c/li\u003e\u003cli\u003e\u003cb\u003eg\u003c/b\u003e —— A grouping (index) vector g of size \u003cb\u003en-by-1\u003c/b\u003e, which divides the points in x into groups. Specifically, the rows in x corresponding to the same group index in g belong to the same group.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003e\u003cb\u003eOutput\u003c/b\u003e:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003cb\u003ey\u003c/b\u003e —— The group-wise Euclidean distance matrix associated with the points in x. Suppose that m = max(g), then y will be an \u003cb\u003em-by-m\u003c/b\u003e matrix, where each element y(i,j) is the Euclidean distance between group i and group j, which is defined as the minimum of the Euclidean distances between any points in group i and any other points in group j.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003e\u003cb\u003eExample\u003c/b\u003e:\u003c/p\u003e\u003cp\u003eExample 1: n = 6, d = 1\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eg = [2   1   3  2  1].';\r\nx = [3  10  15  8  5].';\r\ny = [0   2   5            % y(1,2) = y(2,1) = min(10-3,5-3,10-8,8-5) = 2\r\n     2   0   7            % y(1,3) = y(3,1) = min(15-10,15-5) = 5\r\n     5   7   0];          % y(2,3) = y(3,2) = min(15-3,15-8) = 7\r\n\u003c/pre\u003e\u003cp\u003eExample 2: n = 3, d = 2\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eg = [1 2 2].';\r\nx = [0   0\r\n     5  12\r\n     3   4];\r\ny = [0  5;\r\n     5  0];    % y(1,2) = y(2,1) = min(sqrt(5^2+12^2),sqrt(3^2+4^2)) = 5\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eTesting\u003c/b\u003e:\u003c/p\u003e\u003cp\u003eThe test suite will focus mainly on the large-scale problem dimensions (e.g., large n and/or d). The purpose is to direct attention towards efficient runtime speed of execution. Note that your solution may run into a time-out error if it is not sufficiently efficient (which is why this problem falls into the \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/groups/35\"\u003eCody5:Hard\u003c/a\u003e category).\u003c/p\u003e\u003cp\u003e\u003cb\u003eScoring\u003c/b\u003e:\u003c/p\u003e\u003cp\u003eWe have modified Cody's default size-based scoring function into a performance-based scoring system (implemented by our fellow Cody player \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/players/3021298-ly-cao\"\u003eLY Cao\u003c/a\u003e), in which the score of your submission equals 5 times the execution time of your solution (which reprents a score resolution of 0.2 seconds and allows for more room for performance improvement). Please ignore the code size and focus only on improving the code performance, as our test suite will reject any submissions running longer than 20 seconds (in contrast to Cody's default 40 seconds timeout limit).\u003c/p\u003e\u003cp\u003ePlease be advised that an amazingly fast solution would earn a score \u0026lt; 5, meaning that it completes execution of all test cases within a second!\u003c/p\u003e\u003cp\u003e\u003cb\u003eUpdate\u003c/b\u003e (11/21/2017):\r\nAdditional test cases are added to ban cheater solutions (e.g., hard-coded submissions 1351541, 1351007, 1350563, 1349442, all came from \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/players/3931805-marco-tullio\"\u003eMarco Tullio\u003c/a\u003e).\u003c/p\u003e","function_template":"function y = groupDist(x,g)\r\n  y = x;\r\nend","test_suite":"%%\r\nassessFunctionAbsence({'regexp','regexpi','regexprep','str2num','tic','toc','persistent','global','rng','assert','!','system','unix','noCheater'},'FileName','groupDist.m')\r\n\r\n%%\r\nfid = fopen('noCheater.p','Wb');\r\nfwrite(fid, hex2dec(reshape([\r\n    '7630312E30307630302E30300007701CAB777FB100000015000000740000007E3D5C20F'...'\r\n    '5319EEB8B0D3D9C9C87C18B91C13D7310D9D8E837C95E62D49A3FE08B071790DBC222B5'...\r\n    '839E9A19EA6AA7CF3785A7E7CEC1CFE46E0E9A5DB7C82D69A4FAB7BF308D0871C342A5F'...\r\n    'EF9AF61623F1D97F80207388D54ABA3CB3D551617DA33AA3F5040CD425FC9B29E2A4233'...\r\n    'AE7C5ADEF399'],2,[]).')); rehash path; \r\nfclose(fid); \r\nassert(noCheater(),'Cheater detected!')\r\n\r\n%%\r\ng = [2   1   3  2  1].';\r\nx = [3  10  15  8  5].';\r\ny_correct = [0   2   5            \r\n             2   0   7      \r\n             5   7   0]; \r\nassert(isequaln(y_correct,groupDist(x,g)))\r\n\r\n%%\r\ng = [1 2 2].';\r\nx = [0   0\r\n     5  12\r\n     3   4];\r\ny_correct = [0  5;\r\n             5  0];    \r\nassert(isequal(y_correct,groupDist(x,g)))\r\n\r\n%%\r\ng = [2 2 3 3 3 1].';\r\nx = [-5   12\r\n      3    4\r\n     -7  -24\r\n     25    4\r\n      9   40\r\n      0    0];\r\ny_correct = [0    5   25;\r\n             5    0   22\r\n             25  22    0];  \r\nassert(isequal(y_correct,groupDist(x,g)))\r\n\r\n%% Randomized case to disallow hard-coded solution\r\ng = randperm(10).';\r\nx = rand(10,1);\r\na = sortrows([g,x]);\r\ny_correct = abs(a(:,2)-a(:,2).');\r\nassert(isequal(round(y_correct,10),round(groupDist(x,g),10))) \r\n\r\n%% Additional test case to disallow hard-coded solution\r\ng = [1,2,3].';\r\nx = [2,5,10].';\r\ny_correct = [0   3   8            \r\n             3   0   5      \r\n             8   5   0]; \r\nassert(isequaln(y_correct,groupDist(x,g)))\r\n\r\n%%\r\nglobal t\r\nt = zeros(1,3); \r\nrng(923,'twister');\r\nn = 5e3; d = 3; m = 5;\r\nx = rand(n,d);\r\ng = randi(m,n,1); \r\ny_correct = [0,0.00653919638188362,0.00319052186150122,0.00858841434457234,0.00359654235965771\r\n             0.00653919638188362,0,0.00855286615862212,0.00589790293838067,0.00484910151004134\r\n             0.00319052186150122,0.00855286615862212,0,0.00591041083080696,0.00483607360689871\r\n             0.00858841434457234,0.00589790293838067,0.00591041083080696,0,0.00695738487959094\r\n             0.00359654235965771,0.00484910151004134,0.00483607360689871,0.00695738487959094,0];\r\ntic, y = groupDist(x,g); t(1) = toc;\r\nassert(isequal(round(y_correct,10),round(y,10))) \r\n\r\n%%\r\nglobal t\r\nrng(123) \r\nrng(max('cody5'),'combRecursive');\r\nn = 5e3; d = 3; m = 100;\r\nx = 10*rand(n,d);\r\ng = randi(m,n,1); \r\ntic, y = groupDist(x,g); t(2) = toc;\r\nassert(norm(y-y.') \u003c 1e-11 \u0026\u0026 all(~diag(y)) \u0026\u0026 all(size(y)==m) \u0026\u0026 abs(det(y)-0.030846735888559)\u003c1e-8 \u0026\u0026...\r\n    abs(cond(y)-1.606720826682107e+04) \u003c 1e-6 \u0026\u0026 abs(max(nonzeros(y))-1.058563379304832)\u003c1e-10 \u0026\u0026...\r\n    abs(mean(nonzeros(y))-0.419901913602729)\u003c1e-8)\r\n\r\n%%\r\nglobal t \r\nrng(sum('Cody5, Oct. 16, 2017'),'multFibonacci') \r\nn = 5e3; d = 1e2;  m = 100;\r\nx = 5*randn(n,d) + 20;\r\ng = randi(m,n,1); \r\ntic, y = groupDist(x,g); t(3) = toc;\r\nassert(norm(y-y.') \u003c 1e-11 \u0026\u0026 all(~diag(y)) \u0026\u0026 all(size(y)==m) \u0026\u0026 ...\r\n    abs(cond(y)-2.024633860688276e+02) \u003c 1e-8 \u0026\u0026 abs(max(nonzeros(y))-57.768463869822135)\u003c1e-10 \u0026\u0026...\r\n    abs(mean(nonzeros(y))-53.852605466762945)\u003c1e-8) \r\n \r\n%%\r\nglobal t\r\nfid = fopen('score.p','Wb');\r\nfwrite(fid,uint8(sscanf([...\r\n     '7630312E30307630302E3030000B901C454EFFB100000031000001330000018D483A60'...\r\n     '366BC9545F84AE26323B67424D4E8A7A2E5B7D8ACAA45A1C3C5C8B33E245C95243E3CB'...\r\n     'AF5D0D993BDA70B7AB5DA365A83E8CA87FFC45265E23EF80943784C5F48E6E53D5DA34'...\r\n     'F1F2ECD34683EABE3B7461DC9E8004CC50B2A79D73495F6F625B5365602B2E6C6093D2'...\r\n     '997D371DA457CE82327E686AF512A507B2CB62A375BFD1B283DDD2C01EDEF2771EDAA3'...\r\n     '6ABB4852BA4061E20149688E812EB41A9AF8627EF35755492D2830EB8718BCFE88027E'...\r\n     '6EA960B63A3B3E26E0451B1DCF14F3C20E70D9D93B08E7FF4AE8D82E7CC38042FD38F7'...\r\n     'A14D312EF5652823FEB7E8B52AF5C69F5E7D16B116B5F979EDA77459D6BB61B7971A51'...\r\n     '041227DD601319D667DF62E8DA5E381FDD07A2806FE835BD2569E5315CDFC19C6B6A2B'...\r\n     '4F0FF6BA803F1759ACAB133CCFAB6D5A5D002FC2C5F381F0'],'%2X')));\r\nfclose(fid);\r\nscore(round(5*sum(t)))\r\nfprintf('The execution time of test case %d is %.5f seconds \\n',[5:7;t])\r\nfprintf('The total execution time is %.5f seconds \\n',sum(t))\r\nassert(sum(t)\u003c20, 'Sorry, your solution is too slow. The execution time must not exceed 20 seconds.')\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":4,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":75,"test_suite_updated_at":"2017-11-21T22:49:00.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-01T04:33:43.000Z","updated_at":"2026-02-03T09:16:35.000Z","published_at":"2017-10-16T01:51:00.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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e:\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e —— An array of size\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\u003en-by-d\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, where each row vector denotes a point in a d-dimensional space;\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eg\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e —— A grouping (index) vector g of size\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\u003en-by-1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, which divides the points in x into groups. Specifically, the rows in x corresponding to the same group index in g belong to the same group.\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e:\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e —— The group-wise Euclidean distance matrix associated with the points in x. Suppose that m = max(g), then y will be an\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\u003em-by-m\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix, where each element y(i,j) is the Euclidean distance between group i and group j, which is defined as the minimum of the Euclidean distances between any points in group i and any other points in group j.\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\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\u003eExample 1: n = 6, d = 1\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[g = [2   1   3  2  1].';\\nx = [3  10  15  8  5].';\\ny = [0   2   5            % y(1,2) = y(2,1) = min(10-3,5-3,10-8,8-5) = 2\\n     2   0   7            % y(1,3) = y(3,1) = min(15-10,15-5) = 5\\n     5   7   0];          % y(2,3) = y(3,2) = min(15-3,15-8) = 7]]\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\u003eExample 2: n = 3, d = 2\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[g = [1 2 2].';\\nx = [0   0\\n     5  12\\n     3   4];\\ny = [0  5;\\n     5  0];    % y(1,2) = y(2,1) = min(sqrt(5^2+12^2),sqrt(3^2+4^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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTesting\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\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\u003eThe test suite will focus mainly on the large-scale problem dimensions (e.g., large n and/or d). The purpose is to direct attention towards efficient runtime speed of execution. Note that your solution may run into a time-out error if it is not sufficiently efficient (which is why this problem falls into 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://www.mathworks.com/matlabcentral/cody/groups/35\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody5:Hard\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e category).\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eScoring\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\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\u003eWe have modified Cody's default size-based scoring function into a performance-based scoring system (implemented by our fellow Cody player\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://www.mathworks.com/matlabcentral/cody/players/3021298-ly-cao\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eLY Cao\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e), in which the score of your submission equals 5 times the execution time of your solution (which reprents a score resolution of 0.2 seconds and allows for more room for performance improvement). Please ignore the code size and focus only on improving the code performance, as our test suite will reject any submissions running longer than 20 seconds (in contrast to Cody's default 40 seconds timeout limit).\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\u003ePlease be advised that an amazingly fast solution would earn a score \u0026lt; 5, meaning that it completes execution of all test cases within a second!\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eUpdate\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (11/21/2017): Additional test cases are added to ban cheater solutions (e.g., hard-coded submissions 1351541, 1351007, 1350563, 1349442, all came from\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://www.mathworks.com/matlabcentral/cody/players/3931805-marco-tullio\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eMarco Tullio\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":44309,"title":"Pi Digit Probability","description":"Assume that the next digit of pi constant is determined by the historical digit distribution. What is the probability of next digit (N) being (n). \r\n\r\nFor example if we consider the first 100 digits of pi, we will see that the digit '3' is occured 12 times. So the probability of the being '3' the 101th digit will be 12/100 = 0.12.\r\n\r\nRound the results to four decimals.","description_html":"\u003cp\u003eAssume that the next digit of pi constant is determined by the historical digit distribution. What is the probability of next digit (N) being (n).\u003c/p\u003e\u003cp\u003eFor example if we consider the first 100 digits of pi, we will see that the digit '3' is occured 12 times. So the probability of the being '3' the 101th digit will be 12/100 = 0.12.\u003c/p\u003e\u003cp\u003eRound the results to four decimals.\u003c/p\u003e","function_template":"function y = pidigit(N,n)\r\n  y = x;\r\nend","test_suite":"%%\r\nN = 101;\r\nn = 3;\r\ny_correct = 0.1200;\r\nassert(abs(pidigit(N,n)-y_correct)\u003c0.0001)\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[101,201,202,203,1001]),regexp(fileread('pidigit.m'),'[\\d\\.\\+\\-\\*\\/]+','match')))) % modified from the comment of Alfonso on https://www.mathworks.com/matlabcentral/cody/problems/44343\r\n\r\n%%\r\nN = 201;\r\nn = 6;\r\ny_correct = 0.0750;\r\nassert(abs(pidigit(N,n)-y_correct)\u003c0.0001)\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[101,201,202,203,1001]),regexp(fileread('pidigit.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nN = 202;\r\nn = 6;\r\ny_correct = 0.0796;\r\nassert(abs(pidigit(N,n)-y_correct)\u003c0.0001)\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[101,201,202,203,1001]),regexp(fileread('pidigit.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nN = 203;\r\nn = 6;\r\ny_correct = 0.0792;\r\nassert(abs(pidigit(N,n)-y_correct)\u003c0.0001)\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[101,201,202,203,1001]),regexp(fileread('pidigit.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nN = 1001;\r\nn = 9;\r\ny_correct = 0.1050;\r\nassert(abs(pidigit(N,n)-y_correct)\u003c0.0001)\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[101,201,202,203,1001]),regexp(fileread('pidigit.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n","published":true,"deleted":false,"likes_count":18,"comments_count":27,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":853,"test_suite_updated_at":"2017-10-21T07:59:48.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-11T06:41:07.000Z","updated_at":"2026-04-17T02:20:31.000Z","published_at":"2017-10-16T01:45: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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eAssume that the next digit of pi constant is determined by the historical digit distribution. What is the probability of next digit (N) being (n).\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\u003eFor example if we consider the first 100 digits of pi, we will see that the digit '3' is occured 12 times. So the probability of the being '3' the 101th digit will be 12/100 = 0.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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRound the results to four decimals.\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":44380,"title":"ASCII Birthday Cake","description":"Given an age and a name, give draw an ASCII birthday cake. For example, given the name \"CODY\" and the age 5, return a string with the following (no trailing spaces)\r\n\r\n   6 6 6 6 6\r\n   | | | | |\r\n __|_|_|_|_|__\r\n{             }\r\n{             }\r\n{    CODY     }\r\n{             }\r\n{_____________}\r\n\r\nThis uses the \u003chttps://www.mathworks.com/help/matlab/ref/string.html string datatype\u003e, not a char array.","description_html":"\u003cp\u003eGiven an age and a name, give draw an ASCII birthday cake. For example, given the name \"CODY\" and the age 5, return a string with the following (no trailing spaces)\u003c/p\u003e\u003cpre\u003e   6 6 6 6 6\r\n   | | | | |\r\n __|_|_|_|_|__\r\n{             }\r\n{             }\r\n{    CODY     }\r\n{             }\r\n{_____________}\u003c/pre\u003e\u003cp\u003eThis uses the \u003ca href = \"https://www.mathworks.com/help/matlab/ref/string.html\"\u003estring datatype\u003c/a\u003e, not a char array.\u003c/p\u003e","function_template":"function s = birthday_cake(name, n)\r\n    s = \"\";\r\n    s = s + \"name\";\r\nend","test_suite":"%%\r\ncake = string(char([32 32 32 54 32 54 32 54 32 54 32 54 10 32 32 32 124 32 124 32 124 32 124 32 124 10 32 95 95 124 95 124 95 124 95 124 95 124 95 95 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 67 79 68 89 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 95 95 95 95 95 95 95 95 95 95 95 95 95 125 10]));\r\nfprintf('%s\\n', cake);\r\nassert(isequal(birthday_cake(\"CODY\", 5), cake));\r\n\r\n%%\r\ncake = string(char([32 32 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 10 32 32 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 10 32 95 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 95 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 64 98 109 116 114 97 110 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 125 10]));\r\nfprintf('%s\\n', cake);\r\nassert(isequal(birthday_cake(\"@bmtran\", 29), cake));\r\n\r\n%%\r\ncake = string(char([32 32 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 10 32 32 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 10 32 95 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 95 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 77 65 84 76 65 66 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 125 10]));\r\nfprintf('%s\\n', cake);\r\nassert(isequal(birthday_cake(\"MATLAB\", 33), cake));\r\n\r\n%%\r\ncake = string(char([32 32 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 10 32 32 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 10 32 95 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 95 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 67 108 101 118 101 32 77 111 108 101 114 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 125 10]));\r\nfprintf('%s\\n', cake);\r\nassert(isequal(birthday_cake(\"Cleve Moler\", 78), cake));\r\n\r\n%%\r\ncake = string(char([32 32 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 10 32 32 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 10 32 95 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 95 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 65 108 97 110 32 84 117 114 105 110 103 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 125 10]));\r\nfprintf('%s\\n', cake);\r\nassert(isequal(birthday_cake(\"Alan Turing\", 105), cake));\r\n\r\n%%\r\ncake = string(char([32 32 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 32 54 10 32 32 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 32 124 10 32 95 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 124 95 95 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 83 105 114 32 73 115 97 97 99 32 78 101 119 116 111 110 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 125 10 123 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 125 10]));\r\nfprintf('%s\\n', cake);\r\nassert(isequal(birthday_cake(\"Sir Isaac Newton\", 375), cake));","published":true,"deleted":false,"likes_count":10,"comments_count":4,"created_by":134,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":228,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-10-12T19:48:13.000Z","updated_at":"2026-04-07T09:25:44.000Z","published_at":"2017-10-16T01:45: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\u003eGiven an age and a name, give draw an ASCII birthday cake. For example, given the name \\\"CODY\\\" and the age 5, return a string with the following (no trailing spaces)\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[   6 6 6 6 6\\n   | | | | |\\n __|_|_|_|_|__\\n{             }\\n{             }\\n{    CODY     }\\n{             }\\n{_____________}]]\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\u003eThis uses 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://www.mathworks.com/help/matlab/ref/string.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003estring datatype\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, not a char array.\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":44316,"title":"Pandigital Multiples of 11 (based on Project Euler 491)","description":"A \"Pandigital number of order X\" is one that contains all of the numbers from 0 to X, but with no leading zeroes. If X\u003e9, the cycle 0-9 repeats itself. For example, 2310 is a Pandigital number of order 3 (0-3), while 120345678901 is a Pandigital number of order 11, with the \"01\" at the end of the number representing 10 and 11, respectively (10 and 11 mod 10, essentially). 0321 is not a Pandigital number, as it has a leading zero.\r\n\r\nGiven a number X, determine how many pandigital numbers of that order are divisible by 11.  You do not need to return the numbers themselves, just how many of them there are.","description_html":"\u003cp\u003eA \"Pandigital number of order X\" is one that contains all of the numbers from 0 to X, but with no leading zeroes. If X\u0026gt;9, the cycle 0-9 repeats itself. For example, 2310 is a Pandigital number of order 3 (0-3), while 120345678901 is a Pandigital number of order 11, with the \"01\" at the end of the number representing 10 and 11, respectively (10 and 11 mod 10, essentially). 0321 is not a Pandigital number, as it has a leading zero.\u003c/p\u003e\u003cp\u003eGiven a number X, determine how many pandigital numbers of that order are divisible by 11.  You do not need to return the numbers themselves, just how many of them there are.\u003c/p\u003e","function_template":"function y = pandigitalby11(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 2;y_correct = 0;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\nx = 3;y_correct = 6;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\nx = 7;y_correct = 4032;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\np6=pandigitalby11(6);\r\np8=pandigitalby11(8);\r\np9=pandigitalby11(9);\r\n\r\nassert(p8\u003ep6);\r\nassert(p9\u003ep8);\r\n\r\nf6=factor(p6);\r\nf8=factor(p8);\r\nf9=factor(p9);\r\nf9e1=f9(end-1);\r\n\r\nassert(p6\u003e256);\r\nassert(max(f9)\u003cmax(f8));\r\nassert(f9e1\u003emax(f6));\r\nassert(numel(f9)\u003enumel(f8));\r\n%%\r\nx = 11;y_correct = 9072000;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\nx = 14;y_correct = 3216477600;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\nassert(isequal(pandigitalby11(16),222911740800))","published":true,"deleted":false,"likes_count":5,"comments_count":15,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":53,"test_suite_updated_at":"2017-10-23T01:32:05.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-12T15:26:05.000Z","updated_at":"2026-02-03T09:29:47.000Z","published_at":"2017-10-16T01:50:58.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eA \\\"Pandigital number of order X\\\" is one that contains all of the numbers from 0 to X, but with no leading zeroes. If X\u0026gt;9, the cycle 0-9 repeats itself. For example, 2310 is a Pandigital number of order 3 (0-3), while 120345678901 is a Pandigital number of order 11, with the \\\"01\\\" at the end of the number representing 10 and 11, respectively (10 and 11 mod 10, essentially). 0321 is not a Pandigital number, as it has a leading 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a number X, determine how many pandigital numbers of that order are divisible by 11. You do not need to return the numbers themselves, just how many of them there are.\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":44345,"title":"MATLAB Counter","description":"Write a function f = counter(x0,b) to construct a counter handle f that counts with an initial value x0 and a step size b. \r\n\r\nE.g.,\r\n\r\n  \u003e\u003e f = counter(0,1)  % Initialize a counter f() with initial_count = 0 and step_size = 1\r\n  \u003e\u003e f()\r\n  ans =\r\n       0\r\n  \u003e\u003e f()\r\n  ans =\r\n       1\r\n  \u003e\u003e f()\r\n  ans =\r\n       2\r\n\r\n\r\n","description_html":"\u003cp\u003eWrite a function f = counter(x0,b) to construct a counter handle f that counts with an initial value x0 and a step size b.\u003c/p\u003e\u003cp\u003eE.g.,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e\u0026gt;\u0026gt; f = counter(0,1)  % Initialize a counter f() with initial_count = 0 and step_size = 1\r\n\u0026gt;\u0026gt; f()\r\nans =\r\n     0\r\n\u0026gt;\u0026gt; f()\r\nans =\r\n     1\r\n\u0026gt;\u0026gt; f()\r\nans =\r\n     2\r\n\u003c/pre\u003e","function_template":"function y = counter(x,b)\r\n  y = x;\r\nend","test_suite":"%%\r\nassessFunctionAbsence({'regexp','regexpi','regexprep','str2num'},'FileName','counter.m')\r\n\r\n%%\r\nf = counter(0,1);\r\nassert(isequal(f(),0))\r\nassert(isequal(f(),1))\r\nassert(isequal(2,f()))\r\nassert(isequal(3,f()))\r\n\r\n%%\r\nf = counter(1,0);\r\nassert(isequal(f(),1))\r\nassert(isequal(f(),1))\r\nassert(isequal(1,f()))\r\nassert(isequal(1,f()))\r\n\r\n%%\r\nf = counter(10,2);\r\nassert(isequal(f(),10))\r\nassert(isequal(f(),12))\r\nassert(isequal(14,f()))\r\nassert(isequal(16,f()))\r\n\r\n%%\r\nf = counter(0,5);\r\ny_correct = [0, 5, 10, 15, 20, 55];\r\nassert(isequal([f() f() f() f() f() f()+f()],y_correct))\r\n\r\n%%\r\nx0 = randi(10);\r\nb = randi(10);\r\nf = counter(x0,b);\r\ny_correct = x0 + (0:1000)*b;\r\nassert(isequal(arrayfun(@(n)f(),0:1000),y_correct))","published":true,"deleted":false,"likes_count":23,"comments_count":9,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":301,"test_suite_updated_at":"2017-10-17T00:19:49.000Z","rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-24T01:58:21.000Z","updated_at":"2026-04-13T19:23:03.000Z","published_at":"2017-10-16T01:45:08.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 f = counter(x0,b) to construct a counter handle f that counts with an initial value x0 and a step size b.\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\u003eE.g.,\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[\u003e\u003e f = counter(0,1)  % Initialize a counter f() with initial_count = 0 and step_size = 1\\n\u003e\u003e f()\\nans =\\n     0\\n\u003e\u003e f()\\nans =\\n     1\\n\u003e\u003e f()\\nans =\\n     2]]\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":44374,"title":"Tautology","description":"Check if the given expression is always true. For example, the sentence\r\n\r\n  '~(A \u0026 B) == (~A | ~B)'\r\n\r\nis always true.\r\n\r\nCharacters in the input sequences may include *~ \u0026 | == ( )*, whitespace, 0 for false, 1 for true and letters for variables.","description_html":"\u003cp\u003eCheck if the given expression is always true. For example, the sentence\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e'~(A \u0026 B) == (~A | ~B)'\r\n\u003c/pre\u003e\u003cp\u003eis always true.\u003c/p\u003e\u003cp\u003eCharacters in the input sequences may include \u003cb\u003e~ \u0026 | == ( )\u003c/b\u003e, whitespace, 0 for false, 1 for true and letters for variables.\u003c/p\u003e","function_template":"function y = tautology(x)\r\n  y = true;\r\nend","test_suite":"%%\r\nx = '0';\r\ny_correct = false;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = '1';\r\ny_correct = true;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = 'A';\r\ny_correct = false;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = '~A';\r\ny_correct = false;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = 'A|1';\r\ny_correct = true;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = '1\u0026A';\r\ny_correct = false;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = 'A|B';\r\ny_correct = false;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = 'A\u0026B';\r\ny_correct = false;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = 'A|A';\r\ny_correct = false;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = 'A|~A';\r\ny_correct = true;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = '0==0';\r\ny_correct = true;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = '~0';\r\ny_correct = true;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = '~(A \u0026 B) == (~A | ~B)';\r\ny_correct = true;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = '~(Z \u0026 Y) == (~Y | ~Z)';\r\ny_correct = true;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = 'A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|X|V|W|Y|Z';\r\ny_correct = false;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nx = 'A|B|C|D|E|F|G|H|I|J|K|L|M|~A|O|P|Q|R|S|T|U|X|V|W|Y|Z';\r\ny_correct = true;\r\nassert(isequal(tautology(x),y_correct))\r\n%%\r\nassert(isequal(tautology('(A|B)|C'),false));\r\n%%\r\nassert(isequal(tautology('(A|B)|(C == C)'),true));\r\n%%\r\nassert(isequal(tautology('(A == B)|(B == C)|(C == A)'),true));\r\n%%\r\nassert(isequal(tautology('~(~(~(~(~(~(0))))))'),false)); \r\n%%\r\nassert(isequal(tautology('~(~(~(~(~(~(~0))))))'),true));\r\n% provided by Alfonso:\r\nassert(isequal(tautology('((0\u00261)|~B)\u0026~B'),false)); \r\n%%\r\nassert(isequal(tautology('((0\u0026~B)\u0026~B)'),false)); \r\n%%\r\nassert(isequal(tautology('((0|A)\u0026~A)'),false)); \r\n%%\r\nassert(isequal(tautology('((0|A)|1)'),true)); \r\n%%\r\nassert(isequal(tautology('((0|~B)|1)'),true)); \r\n%%\r\nassert(isequal(tautology('((1\u00260)|B)'),false)); \r\n%%\r\nassert(isequal(tautology('((1\u00261)\u0026A)'),false)); \r\n%%\r\nassert(isequal(tautology('((1|0)|A)'),true)); \r\n%%\r\nassert(isequal(tautology('((1|A)|0)'),true)); \r\n%%\r\nassert(isequal(tautology('((1|~A)\u0026B)'),false)); \r\n%%\r\nassert(isequal(tautology('((A\u00261)|~A)|A'),true)); \r\n%%\r\nassert(isequal(tautology('((A\u0026~A)\u0026~B)|~A'),false)); \r\n%%\r\nassert(isequal(tautology('((A\u0026~B)\u00261)|B'),false)); \r\n%%\r\nassert(isequal(tautology('((A|0)\u00261)\u0026~B'),false)); \r\n%%\r\nassert(isequal(tautology('((A|A)\u0026A)|~A'),true)); \r\n%%\r\nassert(isequal(tautology('((B|0)\u0026B)'),false)); \r\n%%\r\nassert(isequal(tautology('((B|1)\u0026B)\u0026A'),false)); \r\n%%\r\nassert(isequal(tautology('((B|A)|~A)'),true)); \r\n%%\r\nassert(isequal(tautology('((~A\u0026~A)\u00260)\u0026B'),false)); \r\n%%\r\nassert(isequal(tautology('((~A\u0026~A)|0)'),false)); \r\n%%\r\nassert(isequal(tautology('((~A\u0026~A)|~A)|1'),true)); \r\n%%\r\nassert(isequal(tautology('((~A|A)|~B)\u00261'),true)); \r\n%%\r\nassert(isequal(tautology('((~A|B)|A)'),true)); \r\n%%\r\nassert(isequal(tautology('((~A|~A)|1)'),true)); \r\n%%\r\nassert(isequal(tautology('((~A|~B)\u00260)'),false)); \r\n%%\r\nassert(isequal(tautology('((~B\u00260)\u0026A)'),false)); \r\n%%\r\nassert(isequal(tautology('(0\u00261)|1\u00261'),true)); \r\n%%\r\nassert(isequal(tautology('(0|~A\u0026B)'),false)); \r\n%%\r\nassert(isequal(tautology('(1|A\u00260)'),true)); \r\n%%\r\nassert(isequal(tautology('(A\u0026A\u0026~B)'),false)); \r\n%%\r\nassert(isequal(tautology('(A\u0026~A|1)'),true)); \r\n%%\r\nassert(isequal(tautology('(A|1)|B'),true)); \r\n%%\r\nassert(isequal(tautology('(A|A)|A|1'),true)); \r\n%%\r\nassert(isequal(tautology('(B\u00261)|~B'),true)); \r\n%%\r\nassert(isequal(tautology('(B\u0026~B)\u0026~B\u00260'),false)); \r\n%%\r\nassert(isequal(tautology('(B|~B)|B'),true)); \r\n%%\r\nassert(isequal(tautology('(~A\u0026B\u00260)'),false)); \r\n%%\r\nassert(isequal(tautology('(~A|0)|~B\u0026~A'),false)); \r\n%%\r\nassert(isequal(tautology('(~A|1)|1'),true)); \r\n%%\r\nassert(isequal(tautology('(~A|B\u0026B)'),false)); \r\n%%\r\nassert(isequal(tautology('(~A|B)|~B'),true)); \r\n%%\r\nassert(isequal(tautology('(~A|~A)|0'),false)); \r\n%%\r\nassert(isequal(tautology('(~B\u00260)\u00261|1'),true)); \r\n%%\r\nassert(isequal(tautology('1\u0026B|~B|0'),true)); \r\n%%\r\nassert(isequal(tautology('B\u00261\u0026A\u00261'),false)); \r\n%%\r\nassert(isequal(tautology('~A\u00260\u00261|1'),true)); \r\n%%\r\nassert(isequal(tautology('~B\u00260\u0026~A|B'),false)); \r\n%%\r\nassert(isequal(tautology('~B|1|1|~B'),true)); \r\n%%\r\nassert(isequal(tautology('~B|~B\u00261|1'),true));\r\n%%\r\nassert(isequal(tautology('A==~A'),false));\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":30,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":44,"test_suite_updated_at":"2017-10-31T07:45:16.000Z","rescore_all_solutions":true,"group_id":35,"created_at":"2017-10-10T23:20:08.000Z","updated_at":"2026-02-03T08:59:32.000Z","published_at":"2017-10-16T01:51:01.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\u003eCheck if the given expression is always true. For example, the sentence\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['~(A \u0026 B) == (~A | ~B)']]\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\u003eis always true.\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\u003eCharacters in the input sequences may include\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~ \u0026amp; | == ( )\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, whitespace, 0 for false, 1 for true and letters for variables.\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":44382,"title":"Parse me a Lisp","description":"*Description*\r\n\r\nIn Lisp and its variants, function calls are done using parenthesis where the first item in the parenthesis is the function being called and the following items are arguments to the function. Given a mathematical ( |+ - * /| ) expression using this notation, return the result. Note: In Lisp, functions that normally take only two arguments can be called with many arguments, with the function being applied to all elements from left to right.\r\n\r\n*Simple example*\r\n\r\n  (+ 1 1 1 1 1)\r\n\r\nwould give 5.\r\n\r\n*Complicated example*\r\n\r\n  (* (* 10 (+ 1 4)) (+ 10 (/ 12 2 3) 1) 0.1)\r\n\r\nwould give 65.","description_html":"\u003cp\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/p\u003e\u003cp\u003eIn Lisp and its variants, function calls are done using parenthesis where the first item in the parenthesis is the function being called and the following items are arguments to the function. Given a mathematical ( \u003ctt\u003e+ - * /\u003c/tt\u003e ) expression using this notation, return the result. Note: In Lisp, functions that normally take only two arguments can be called with many arguments, with the function being applied to all elements from left to right.\u003c/p\u003e\u003cp\u003e\u003cb\u003eSimple example\u003c/b\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e(+ 1 1 1 1 1)\r\n\u003c/pre\u003e\u003cp\u003ewould give 5.\u003c/p\u003e\u003cp\u003e\u003cb\u003eComplicated example\u003c/b\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e(* (* 10 (+ 1 4)) (+ 10 (/ 12 2 3) 1) 0.1)\r\n\u003c/pre\u003e\u003cp\u003ewould give 65.\u003c/p\u003e","function_template":"function x = eval_lisp(s)\r\n    x = s\r\nend","test_suite":"%%\r\nexpr = \"(+ 1 1 1 1 1)\";\r\nassert(isequal(eval_lisp(expr), 5));\r\n\r\n%%\r\nexpr = \"(+ 1 5)\";\r\nassert(isequal(eval_lisp(expr), 6));\r\n\r\n%%\r\nexpr = \"(+ 1 1 1 1 1 1 1 1 1 1 1 1 1)\";\r\nassert(isequal(eval_lisp(expr), 13));\r\n\r\n%%\r\nexpr = \"(+ 1 2 3 4 5 6 7 8 9 10)\";\r\nassert(isequal(eval_lisp(expr), 55));\r\n\r\n%%\r\nexpr = \"(* 1 2 3 4 5 6 7 8 9 10)\";\r\nassert(isequal(eval_lisp(expr), 3628800));\r\n\r\n%%\r\nexpr = \"(* (* 10 (+ 1 4)) (+ 10 (/ 12 2 3) 1) 0.1)\";\r\nassert(isequal(eval_lisp(expr), 65));\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":4,"created_by":134,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":89,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-12T20:43:01.000Z","updated_at":"2026-02-03T07:40:05.000Z","published_at":"2017-10-16T01:51:02.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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eDescription\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\u003eIn Lisp and its variants, function calls are done using parenthesis where the first item in the parenthesis is the function being called and the following items are arguments to the function. Given a mathematical (\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e+ - * /\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ) expression using this notation, return the result. Note: In Lisp, functions that normally take only two arguments can be called with many arguments, with the function being applied to all elements from left to right.\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSimple 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[(+ 1 1 1 1 1)]]\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\u003ewould give 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eComplicated 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[(* (* 10 (+ 1 4)) (+ 10 (/ 12 2 3) 1) 0.1)]]\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\u003ewould give 65.\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":44347,"title":"Ned's queens","description":"A tribute to Cody's five-year anniversary should also celebrate the people behind Cody, and in this particular case, our illustrious Quizmaster, Ned Gulley.\r\n\r\nThe N-Queens problem (N stands for Ned, of course) is a well known computing challenge. If you are unfamiliar with this problem, refer to \u003chttps://www.mathworks.com/matlabcentral/cody/problems/113-n-queens-checker Problem 113\u003e, incidentally written by... You guessed it.\r\n\r\nThis problem is the real deal. Given a positive integer, n, representing the number of queens and the size of the board, return the number of possible solutions, s, and a list of the solutions, q.\r\n\r\nq shall be an array with s rows and n columns, such that each row represents one solution. The column indeces of q shall represent the column indeces of the positions of the queens in the respective solution, while the values of the array elements shall represent the row indeces of the positions of the queens in the respective solution. q does not have to be sorted.\r\n\r\nNote: All symmetries/rotations count as individual solutions.\r\n\r\nExample:\r\n\r\n Input: n = 4\r\n\r\n Output: s = 2, q = [2 4 1 3;3 1 4 2]","description_html":"\u003cp\u003eA tribute to Cody's five-year anniversary should also celebrate the people behind Cody, and in this particular case, our illustrious Quizmaster, Ned Gulley.\u003c/p\u003e\u003cp\u003eThe N-Queens problem (N stands for Ned, of course) is a well known computing challenge. If you are unfamiliar with this problem, refer to \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/113-n-queens-checker\"\u003eProblem 113\u003c/a\u003e, incidentally written by... You guessed it.\u003c/p\u003e\u003cp\u003eThis problem is the real deal. Given a positive integer, n, representing the number of queens and the size of the board, return the number of possible solutions, s, and a list of the solutions, q.\u003c/p\u003e\u003cp\u003eq shall be an array with s rows and n columns, such that each row represents one solution. The column indeces of q shall represent the column indeces of the positions of the queens in the respective solution, while the values of the array elements shall represent the row indeces of the positions of the queens in the respective solution. q does not have to be sorted.\u003c/p\u003e\u003cp\u003eNote: All symmetries/rotations count as individual solutions.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e Input: n = 4\u003c/pre\u003e\u003cpre\u003e Output: s = 2, q = [2 4 1 3;3 1 4 2]\u003c/pre\u003e","function_template":"function [s, q] = nqueens(n)\r\n    s = n;\r\n    q = 1:n;\r\nend","test_suite":"%%\r\nn = 1;\r\ns_correct = 1;\r\nq_correct = 1;\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isequal(sortrows(q),sortrows(q_correct)))\r\n\r\n%%\r\nn = 2;\r\ns_correct = 0;\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isempty(q))\r\n\r\n%%\r\nn = 3;\r\ns_correct = 0;\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isempty(q))\r\n\r\n%%\r\nn = 4;\r\ns_correct = 2;\r\nq_correct = [3  1  4  2;2  4  1  3]\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isequal(sortrows(q),sortrows(q_correct)))\r\n\r\n%%\r\nn = 5;\r\ns_correct = 10;\r\nq_correct = [5  3  1  4  2;5  2  4  1  3;4  2  5  3  1;4  1  3  5  2;3  5  2  4  1;3  1  4  2  5;2  4  1  3  5;2  5  3  1  4;1  4  2  5  3;1  3  5  2  4];\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isequal(sortrows(q),sortrows(q_correct)))\r\n\r\n%%\r\nn = 6;\r\ns_correct = 4;\r\nq_correct = [5  3  1  6  4  2;4  1  5  2  6  3;3  6  2  5  1  4;2  4  6  1  3  5];\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isequal(sortrows(q),sortrows(q_correct)))\r\n\r\n%%\r\nn = 7;\r\ns_correct = 40;\r\nq_correct = [7  5  3  1  6  4  2;7  4  1  5  2  6  3;7  3  6  2  5  1  4;7  2  4  6  1  3  5;6  4  7  1  3  5  2;6  4  2  7  5  3  1;6  3  5  7  1  4  2;6  3  7  4  1  5  2;6  3  1  4  7  5  2;6  2  5  1  4  7  3;6  1  3  5  7  2  4;5  7  2  4  6  1  3;5  7  2  6  3  1  4;5  3  1  6  4  2  7;5  2  6  3  7  4  1;5  1  4  7  3  6  2;5  1  6  4  2  7  3;4  6  1  3  5  7  2;4  7  5  2  6  1  3;4  7  3  6  2  5  1;4  2  7  5  3  1  6;4  1  5  2  6  3  7;4  1  3  6  2  7  5;3  6  2  5  1  4  7;3  5  7  2  4  6  1;3  7  4  1  5  2  6;3  7  2  4  6  1  5;3  1  6  4  2  7  5;3  1  6  2  5  7  4;2  6  3  7  4  1  5;2  5  3  1  7  4  6;2  5  7  4  1  3  6;2  5  1  4  7  3  6;2  4  6  1  3  5  7;2  4  1  7  5  3  6;2  7  5  3  1  6  4;1  6  4  2  7  5  3;1  5  2  6  3  7  4;1  4  7  3  6  2  5;1  3  5  7  2  4  6];\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isequal(sortrows(q),sortrows(q_correct)))\r\n\r\n%%\r\nn = 8;\r\ns_correct = 92;\r\nq_correct = [8  4  1  3  6  2  7  5\r\n8  3  1  6  2  5  7  4;8  2  5  3  1  7  4  6;8  2  4  1  7  5  3  6;7  5  3  1  6  8  2  4;7  4  2  5  8  1  3  6;7  4  2  8  6  1  3  5;7  3  8  2  5  1  6  4;7  3  1  6  8  5  2  4;7  2  6  3  1  4  8  5;7  2  4  1  8  5  3  6;7  1  3  8  6  4  2  5;6  8  2  4  1  7  5  3;6  4  7  1  8  2  5  3;6  4  7  1  3  5  2  8;6  4  2  8  5  7  1  3;6  4  1  5  8  2  7  3;6  3  5  8  1  4  2  7;6  3  5  7  1  4  2  8;6  3  7  4  1  8  2  5;6  3  7  2  4  8  1  5;6  3  7  2  8  5  1  4;6  3  1  7  5  8  2  4;6  3  1  8  4  2  7  5;6  3  1  8  5  2  4  7;6  2  7  1  4  8  5  3;6  2  7  1  3  5  8  4;6  1  5  2  8  3  7  4;5  7  4  1  3  8  6  2;5  7  2  4  8  1  3  6;5  7  2  6  3  1  8  4;5  7  2  6  3  1  4  8;5  7  1  4  2  8  6  3;5  7  1  3  8  6  4  2;5  8  4  1  3  6  2  7;5  8  4  1  7  2  6  3;5  3  8  4  7  1  6  2;5  3  1  7  2  8  6  4;5  3  1  6  8  2  4  7;5  2  6  1  7  4  8  3;5  2  8  1  4  7  3  6;5  2  4  6  8  3  1  7;5  2  4  7  3  8  6  1;5  1  8  6  3  7  2  4;5  1  8  4  2  7  3  6;5  1  4  6  8  2  7  3;4  7  5  3  1  6  8  2;4  7  5  2  6  1  3  8;4  7  3  8  2  5  1  6;4  7  1  8  5  2  6  3;4  6  8  3  1  7  5  2;4  6  8  2  7  1  3  5;4  6  1  5  2  8  3  7;4  8  5  3  1  7  2  6;4  8  1  5  7  2  6  3;4  8  1  3  6  2  7  5;4  2  5  8  6  1  3  7;4  2  8  5  7  1  3  6;4  2  8  6  1  3  5  7;4  2  7  5  1  8  6  3;4  2  7  3  6  8  5  1;4  2  7  3  6  8  1  5;4  1  5  8  6  3  7  2;4  1  5  8  2  7  3  6;3  7  2  8  5  1  4  6;3  7  2  8  6  4  1  5;3  6  4  2  8  5  7  1;3  6  4  1  8  5  7  2;3  6  8  2  4  1  7  5;3  6  8  1  4  7  5  2;3  6  8  1  5  7  2  4;3  6  2  5  8  1  7  4;3  6  2  7  5  1  8  4;3  6  2  7  1  4  8  5;3  5  7  1  4  2  8  6;3  5  8  4  1  7  2  6;3  5  2  8  6  4  7  1;3  5  2  8  1  7  4  6;3  8  4  7  1  6  2  5;3  1  7  5  8  2  4  6;2  7  5  8  1  4  6  3;2  7  3  6  8  5  1  4;2  6  8  3  1  4  7  5;2  6  1  7  4  8  3  5;2  5  7  4  1  8  6  3;2  5  7  1  3  8  6  4;2  4  6  8  3  1  7  5;2  8  6  1  3  5  7  4;1  7  5  8  2  4  6  3;1  7  4  6  8  2  5  3;1  6  8  3  7  4  2  5;1  5  8  6  3  7  2  4];\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isequal(sortrows(q),sortrows(q_correct)))\r\n\r\n%%\r\nn = 9;\r\ns_correct = 352;\r\nq_correct = [9  7  4  2  8  6  1  3  5;9  7  3  8  2  5  1  6  4;9  7  2  4  1  8  5  3  6;9  6  8  2  4  1  7  5  3;9  6  4  7  1  8  2  5  3;9  6  4  2  8  5  7  1  3;9  6  3  7  2  8  5  1  4;9  6  3  1  8  5  2  4  7;9  6  2  7  1  3  5  8  4;9  5  8  4  1  7  2  6  3;9  5  3  8  4  7  1  6  2;9  5  3  1  7  2  8  6  4;9  5  3  1  6  8  2  4  7;9  5  1  8  4  2  7  3  6;9  5  1  4  6  8  2  7  3;9  4  6  8  3  1  7  5  2;9  4  6  8  2  7  1  3  5;9  4  8  1  3  6  2  7  5;9  4  2  5  8  6  1  3  7;9  4  2  7  3  6  8  1  5;9  4  1  5  8  2  7  3  6;9  3  6  4  1  8  5  7  2;9  3  6  2  7  5  1  8  4;9  3  6  2  7  1  4  8  5;9  3  5  2  8  1  7  4  6;9  2  6  8  3  1  4  7  5;9  2  5  7  4  1  8  6  3;9  2  5  7  1  3  8  6  4;8  6  9  3  1  4  7  5  2;8  6  3  9  7  1  4  2  5;8  6  2  7  1  4  9  5  3;8  6  1  3  5  7  9  4  2;8  6  1  3  7  9  4  2  5;8  5  3  6  9  7  1  4  2;8  5  3  9  7  2  4  6  1;8  5  3  1  7  4  6  9  2;8  5  3  1  6  2  9  7  4;8  5  2  9  7  4  1  3  6;8  5  2  9  1  4  7  3  6;8  5  2  4  1  7  9  6  3;8  5  2  4  1  7  9  3  6;8  5  1  6  9  2  4  7  3;8  4  7  9  2  6  1  3  5;8  4  9  7  3  1  6  2  5;8  4  9  3  5  7  1  6  2;8  4  9  3  6  2  7  5  1;8  4  9  1  5  2  6  3  7;8  4  1  7  5  2  6  9  3;8  3  5  9  1  6  4  2  7;8  3  5  2  9  6  4  7  1;8  3  1  4  7  9  6  2  5;8  2  5  7  1  4  6  9  3;8  2  4  1  7  9  6  3  5;8  2  9  6  3  1  4  7  5;8  1  5  7  2  6  3  9  4;8  1  4  6  3  9  7  5  2;8  1  4  7  5  2  9  6  3;8  1  4  7  3  6  9  2  5;7  9  6  3  1  8  5  2  4;7  9  4  2  5  8  6  1  3;7  9  3  5  2  8  6  4  1;7  9  3  8  2  4  6  1  5;7  9  2  6  1  3  5  8  4;7  9  1  3  5  8  2  4  6;7  5  8  2  9  3  6  4  1;7  5  8  2  9  6  3  1  4;7  5  3  9  6  8  2  4  1;7  5  2  8  1  4  9  3  6;7  5  2  8  1  3  9  6  4;7  5  1  6  9  3  8  4  2;7  5  1  8  6  3  9  2  4;7  4  8  3  9  6  2  5  1;7  4  8  1  5  9  2  6  3;7  4  2  5  8  1  3  6  9;7  4  2  5  9  1  3  8  6;7  4  2  8  6  1  3  5  9;7  4  2  9  5  1  8  6  3;7  4  2  9  6  3  5  8  1;7  4  1  5  2  9  6  8  3;7  4  1  8  5  3  6  9  2;7  4  1  8  2  9  6  3  5;7  4  1  3  8  6  2  9  5;7  4  1  3  6  9  2  8  5;7  4  1  3  9  6  8  5  2;7  4  1  9  2  6  8  3  5;7  3  6  8  1  4  9  5  2;7  3  6  8  1  5  9  2  4;7  3  6  2  5  1  9  4  8;7  3  8  6  2  9  5  1  4;7  3  8  2  5  1  9  4  6;7  3  8  2  4  6  9  5  1;7  3  1  6  8  5  2  4  9;7  3  1  9  5  8  2  4  6;7  2  6  3  1  8  5  9  4;7  2  4  6  1  9  5  3  8;7  2  4  9  1  8  5  3  6;7  2  4  1  8  5  9  6  3;7  2  8  6  1  3  5  9  4;7  1  6  9  2  4  8  3  5;7  1  6  2  5  8  4  9  3;7  1  6  8  2  4  9  3  5;7  1  4  6  9  3  5  8  2;7  1  4  2  8  6  9  3  5;7  1  4  8  5  3  9  6  2;7  1  8  5  2  9  3  6  4;6  8  5  2  9  7  4  1  3;6  8  3  7  9  2  5  1  4;6  8  3  1  9  2  5  7  4;6  8  3  1  9  5  2  4  7;6  8  2  7  1  3  5  9  4;6  8  1  5  9  2  4  7  3;6  8  1  7  4  2  9  5  3;6  9  7  4  1  8  2  5  3;6  9  5  8  1  3  7  2  4;6  9  5  2  8  3  7  4  1;6  9  5  1  8  4  2  7  3;6  9  3  1  8  4  2  7  5;6  9  1  4  7  3  8  2  5;6  4  7  1  8  5  2  9  3;6  4  7  1  8  2  5  3  9;6  4  7  1  3  9  2  8  5;6  4  9  5  8  2  7  3  1;6  4  9  1  5  2  8  3  7;6  4  9  1  3  7  2  8  5;6  4  2  8  5  9  1  3  7;6  4  2  8  5  3  1  9  7;6  4  2  8  3  9  7  5  1;6  4  2  7  9  3  5  8  1;6  4  1  7  9  2  8  5  3;6  3  7  4  1  9  2  5  8;6  3  7  2  4  8  1  5  9;6  3  7  2  4  9  1  8  5;6  3  7  2  8  5  1  4  9;6  3  9  7  1  4  2  5  8;6  3  9  4  1  8  2  5  7;6  3  9  2  5  8  1  7  4;6  3  5  8  1  4  2  7  9;6  3  5  8  1  9  4  2  7;6  3  5  8  1  9  7  2  4;6  3  1  4  7  9  2  5  8;6  3  1  8  5  2  9  7  4;6  3  1  8  4  9  7  5  2;6  2  9  5  3  8  4  7  1;6  2  5  7  9  4  8  1  3;6  2  5  7  9  3  8  4  1;6  1  7  4  8  3  5  9  2;6  1  5  7  9  4  2  8  3;6  1  5  7  9  3  8  2  4;6  1  5  2  9  7  4  8  3;5  8  6  9  3  1  7  4  2;5  8  6  1  3  7  9  4  2;5  8  4  9  7  3  1  6  2;5  8  4  1  7  2  6  3  9;5  8  4  1  3  6  9  7  2;5  8  2  9  6  3  1  4  7;5  8  2  9  3  1  7  4  6;5  8  2  7  3  6  9  1  4;5  8  2  7  3  1  9  4  6;5  8  1  9  4  2  7  3  6;5  8  1  4  7  3  6  9  2;5  7  9  4  8  1  3  6  2;5  7  9  4  2  8  6  3  1;5  7  9  3  8  2  4  6  1;5  7  4  1  8  2  9  6  3;5  7  4  1  3  8  6  2  9;5  7  4  1  3  9  6  8  2;5  7  4  1  3  6  9  2  8;5  7  2  6  3  1  8  4  9;5  7  2  6  8  1  4  9  3;5  7  2  4  8  1  3  9  6;5  7  2  4  8  1  9  6  3;5  7  1  6  8  2  4  9  3;5  7  1  4  2  8  6  9  3;5  9  4  6  8  2  7  1  3;5  9  2  6  8  3  1  4  7;5  9  2  4  7  3  8  6  1;5  3  6  9  7  4  1  8  2;5  3  6  9  7  2  4  8  1;5  3  6  9  7  1  4  2  8;5  3  6  9  2  8  1  4  7;5  3  9  6  8  2  4  1  7;5  3  9  4  2  8  6  1  7;5  3  8  6  2  9  7  1  4;5  3  8  6  2  9  1  4  7;5  3  8  4  7  9  2  6  1;5  3  8  4  2  9  6  1  7;5  3  1  6  8  2  4  7  9;5  3  1  6  2  9  7  4  8;5  3  1  7  2  8  6  4  9;5  2  6  9  7  4  1  3  8;5  2  6  9  3  8  4  7  1;5  2  6  1  3  7  9  4  8;5  2  9  6  3  7  4  1  8;5  2  9  1  6  8  3  7  4;5  2  4  9  7  3  1  6  8;5  2  4  1  7  9  3  6  8;5  2  8  3  7  4  1  9  6;5  2  8  3  7  9  1  6  4;5  2  8  1  4  7  9  6  3;5  2  8  1  7  9  3  6  4;5  1  6  4  2  8  3  9  7;5  1  8  6  3  7  2  4  9;5  1  8  4  2  7  9  6  3;4  8  5  3  1  6  2  9  7;4  8  5  3  1  7  2  6  9;4  8  1  5  7  2  6  3  9;4  7  5  2  9  6  8  3  1;4  7  5  2  9  1  3  8  6;4  7  5  2  9  1  6  8  3;4  7  9  6  3  1  8  5  2;4  7  9  2  5  8  1  3  6;4  7  9  2  6  1  3  5  8;4  7  3  6  9  1  8  5  2;4  7  3  8  6  2  9  5  1;4  7  3  8  6  1  9  2  5;4  7  3  8  2  5  9  6  1;4  7  1  6  9  2  8  5  3;4  7  1  3  9  6  8  5  2;4  7  1  8  5  2  9  3  6;4  6  8  3  1  7  5  2  9;4  6  8  2  5  7  9  1  3;4  6  8  2  5  1  9  7  3;4  6  8  2  7  1  3  5  9;4  6  9  3  1  8  2  5  7;4  6  3  9  7  1  8  2  5;4  6  3  9  2  8  5  7  1;4  6  3  9  2  5  8  1  7;4  6  1  5  2  8  3  7  9;4  6  1  9  5  8  2  7  3;4  6  1  9  7  3  8  2  5;4  9  5  8  1  3  6  2  7;4  9  5  3  1  6  8  2  7;4  9  5  3  1  7  2  8  6;4  9  3  6  2  7  5  1  8;4  2  7  9  1  8  5  3  6;4  2  7  9  1  5  8  6  3;4  2  7  3  1  8  5  9  6;4  2  5  8  1  3  6  9  7;4  2  9  5  1  8  6  3  7;4  2  9  3  6  8  1  5  7;4  2  8  3  9  7  5  1  6;4  1  7  9  2  6  8  3  5;4  1  5  9  2  6  8  3  7;4  1  5  2  9  7  3  8  6;4  1  5  8  2  7  3  6  9;4  1  9  6  3  7  2  8  5;4  1  3  6  9  2  8  5  7;3  8  6  4  9  1  5  7  2;3  8  6  9  2  5  1  4  7;3  8  6  1  9  2  5  7  4;3  8  4  7  9  2  5  1  6;3  8  2  4  9  7  5  1  6;3  7  4  8  5  9  1  6  2;3  7  4  2  9  5  1  8  6;3  7  4  2  9  6  1  5  8;3  7  9  4  2  5  8  6  1;3  7  9  1  5  2  8  6  4;3  7  2  4  8  1  5  9  6;3  7  2  8  5  9  1  6  4;3  7  2  8  6  4  1  5  9;3  6  8  5  2  9  7  4  1;3  6  8  5  1  9  7  2  4;3  6  8  2  4  9  7  5  1;3  6  8  1  5  9  2  4  7;3  6  8  1  4  7  5  2  9;3  6  9  5  8  1  4  2  7;3  6  9  7  4  1  8  2  5;3  6  9  7  2  4  8  1  5;3  6  9  7  1  4  2  5  8;3  6  9  2  5  7  4  1  8;3  6  9  2  8  1  4  7  5;3  6  9  1  8  4  2  7  5;3  6  2  9  5  1  8  4  7;3  6  2  7  1  4  8  5  9;3  5  7  1  4  2  8  6  9;3  5  8  2  9  7  1  4  6;3  5  8  2  9  6  1  7  4;3  5  9  4  1  7  2  6  8;3  5  9  2  4  7  1  8  6;3  5  2  8  1  4  7  9  6;3  5  2  8  1  7  4  6  9;3  9  6  4  1  7  5  2  8;3  9  6  8  2  4  1  7  5;3  9  6  2  5  7  1  4  8;3  9  4  8  5  2  6  1  7;3  9  4  2  8  6  1  7  5;3  9  4  1  8  6  2  7  5;3  9  2  5  8  1  7  4  6;3  1  7  5  8  2  4  6  9;3  1  7  2  8  6  4  9  5;3  1  6  8  5  2  4  9  7;3  1  4  7  9  2  5  8  6;3  1  9  7  5  2  8  6  4;3  1  8  4  9  7  5  2  6;2  8  6  9  3  1  4  7  5;2  8  5  3  9  6  4  1  7;2  8  1  4  7  9  6  3  5;2  7  5  8  1  4  6  3  9;2  7  5  1  9  4  6  8  3;2  7  9  6  3  1  4  8  5;2  6  3  1  8  4  9  7  5;2  6  9  3  5  8  4  1  7;2  6  1  3  7  9  4  8  5;2  6  1  9  5  8  4  7  3;2  6  1  7  5  3  9  4  8;2  6  1  7  4  8  3  5  9;2  5  7  4  1  3  9  6  8;2  5  7  9  4  8  1  3  6;2  5  7  9  3  6  4  1  8;2  5  7  1  3  8  6  4  9;2  5  8  6  9  3  1  7  4;2  5  8  6  9  3  1  4  7;2  5  8  1  3  6  9  7  4;2  5  8  1  9  6  3  7  4;2  5  9  4  1  8  6  3  7;2  4  7  1  3  9  6  8  5;2  4  8  3  9  6  1  5  7;2  4  9  7  5  3  1  6  8;2  4  9  7  3  1  6  8  5;2  4  1  7  9  6  3  5  8;2  9  6  4  7  1  3  5  8;2  9  6  3  5  8  1  4  7;2  9  6  3  7  4  1  8  5;2  9  5  3  8  4  7  1  6;1  8  5  3  6  9  2  4  7;1  8  5  3  9  7  2  4  6;1  8  4  2  7  9  6  3  5;1  7  5  8  2  9  3  6  4;1  7  4  6  9  2  5  3  8;1  7  4  8  3  5  9  2  6;1  7  4  8  3  9  6  2  5;1  6  8  5  2  4  9  7  3;1  6  8  3  7  4  2  9  5;1  6  4  2  7  9  3  5  8;1  6  4  2  8  3  9  7  5;1  6  2  9  7  4  8  3  5;1  6  9  5  2  8  3  7  4;1  5  7  2  6  3  9  4  8;1  5  7  9  4  2  8  6  3;1  5  7  9  3  8  2  4  6;1  5  2  6  9  3  8  4  7;1  5  9  6  4  2  8  3  7;1  5  9  2  6  8  3  7  4;1  4  7  3  8  2  5  9  6;1  4  7  9  2  5  8  6  3;1  4  6  8  2  5  3  9  7;1  4  6  3  9  2  8  5  7;1  4  8  3  9  7  5  2  6;1  4  2  8  6  9  3  5  7;1  3  7  2  8  5  9  4  6;1  3  6  8  2  4  9  7  5;1  3  8  6  9  2  5  7  4];\r\n[s, q] = nqueens(n);\r\nassert(isequal(s,s_correct) \u0026\u0026 isequal(sortrows(q),sortrows(q_correct)))","published":true,"deleted":false,"likes_count":6,"comments_count":1,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":92,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-24T19:13:26.000Z","updated_at":"2026-02-03T09:18:46.000Z","published_at":"2017-10-16T01:51:00.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\u003eA tribute to Cody's five-year anniversary should also celebrate the people behind Cody, and in this particular case, our illustrious Quizmaster, Ned Gulley.\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 N-Queens problem (N stands for Ned, of course) is a well known computing challenge. If you are unfamiliar with this problem, refer 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=\\\"https://www.mathworks.com/matlabcentral/cody/problems/113-n-queens-checker\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 113\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, incidentally written by... You guessed it.\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\u003eThis problem is the real deal. Given a positive integer, n, representing the number of queens and the size of the board, return the number of possible solutions, s, and a list of the solutions, q.\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\u003eq shall be an array with s rows and n columns, such that each row represents one solution. The column indeces of q shall represent the column indeces of the positions of the queens in the respective solution, while the values of the array elements shall represent the row indeces of the positions of the queens in the respective solution. q does not have to be sorted.\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\u003eNote: All symmetries/rotations count as individual solutions.\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\u003eExample:\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[ Input: n = 4\\n\\n Output: s = 2, q = [2 4 1 3;3 1 4 2]]]\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":44343,"title":"Pair Primes","description":"Let's define pair primes as follow;\r\nFor 2 digits numbers: 11 and 17 are pair primes because both of them are 2 digits prime numbers and last digit of the first prime equals to the first digit of second prime number. 11 and 11 are not pair primes because a = b.\r\nFor 3 digit numbers: 389 and 967 are pair primes because both of them are 3 digits prime numbers and last digit of the first prime equals to the first digit of the second prime number (797 and 797 are not pair primes because a = b). 467 and 673 are pair primes too because the last two digits of the first prime number (67) equals to the first two digit (67) of the second prime number. 211 and 113 are pair primes too but they satisfy two conditions: last digit of the first prime equals to the first digit of the second prime also last two digits of the first prime equals to the first two digits of the first prime.\r\nFor 4 digit numbers:\r\n1-) 1637 and 7549 are pair primes. First ends with 7 and second starts with 7.\r\n2-) 6221 and 2113 are pair primes. First ends with 21 and second starts with 21.\r\n3-) 1429 and 4297 are pair primes. First ends with 429 and second starts with 429. You should be careful. 2111 and 1117 are also four digit pair primes. It satisfies three conditions. First ends with 1 and second starts with 1. First ends with 11 and second starts with 11. First ends with 111 and second starts with 111. [2111 1117] pair should be counted for once.\r\nGiven the digit counts, can you determine how many unique pair primes are there (a~=b)","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: 387.9px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 193.95px; transform-origin: 407px 193.95px; 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: 104.5px 8px; transform-origin: 104.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eLet's define pair primes as follow;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 183.9px; 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 91.95px; transform-origin: 391px 91.95px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 40.8667px; 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 20.4333px; text-align: left; transform-origin: 363px 20.4333px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 74.5px 8px; transform-origin: 74.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eFor 2 digits numbers:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 283.5px 8px; transform-origin: 283.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e 11 and 17 are pair primes because both of them are 2 digits prime numbers and last digit of the first prime equals to the first digit of second prime number. 11 and 11 are not pair primes because a = b.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 122.6px; 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 61.3px; text-align: left; transform-origin: 363px 61.3px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 70.5px 8px; transform-origin: 70.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eFor 3 digit numbers:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 292px 8px; transform-origin: 292px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e 389 and 967 are pair primes because both of them are 3 digits prime numbers and last digit of the first prime equals to the first digit of the second prime number (797 and 797 are not pair primes because a = b). 467 and 673 are pair primes too because the last two digits of the first prime number (67) equals to the first two digit (67) of the second prime number. 211 and 113 are pair primes too but they satisfy two conditions: last digit of the first prime equals to the first digit of the second prime also last two digits of the first prime equals to the first two digits of the first prime.\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: 70.5px 8px; transform-origin: 70.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eFor 4 digit numbers:\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: 244.5px 8px; transform-origin: 244.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1-) 1637 and 7549 are pair primes. First ends with 7 and second starts with 7.\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: 252px 8px; transform-origin: 252px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e2-) 6221 and 2113 are pair primes. First ends with 21 and second starts with 21.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 63px; 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 31.5px; text-align: left; transform-origin: 384px 31.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: 383px 8px; transform-origin: 383px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e3-) 1429 and 4297 are pair primes. First ends with 429 and second starts with 429. You should be careful. 2111 and 1117 are also four digit pair primes. It satisfies three conditions. First ends with 1 and second starts with 1. First ends with 11 and second starts with 11. First ends with 111 and second starts with 111. [2111 1117] pair should be counted for once.\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: 279px 8px; transform-origin: 279px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven the digit counts, can you determine how many unique pair primes are there (a~=b)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = pairPrimes(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nfiletext = fileread('pairPrimes.m');\r\nillegal = contains(filetext, 'regexp') || contains(filetext, 'interp1') || ...\r\n          contains(filetext, 'elseif') || contains(filetext, 'str2num'); \r\nassert(~illegal)\r\n\r\n%%\r\nx = 2;\r\ny_correct = 51;\r\nassert(isequal(pairPrimes(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[51,2485,136162,8578934]),regexp(fileread('pairPrimes.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 3;\r\ny_correct = 2485;\r\nassert(isequal(pairPrimes(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[51,2485,136162,8578934]),regexp(fileread('pairPrimes.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 4;\r\ny_correct = 136162;\r\nassert(isequal(pairPrimes(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[51,2485,136162,8578934]),regexp(fileread('pairPrimes.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 5;\r\ny_correct = 8578934;\r\nassert(isequal(pairPrimes(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[51,2485,136162,8578934]),regexp(fileread('pairPrimes.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n","published":true,"deleted":false,"likes_count":9,"comments_count":5,"created_by":8703,"edited_by":223089,"edited_at":"2022-10-11T06:50:24.000Z","deleted_by":null,"deleted_at":null,"solvers_count":105,"test_suite_updated_at":"2022-10-11T06:50:24.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-22T08:07:44.000Z","updated_at":"2026-02-03T07:36:30.000Z","published_at":"2017-10-16T01:50:59.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\u003eLet's define pair primes as follow;\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eFor 2 digits numbers:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 11 and 17 are pair primes because both of them are 2 digits prime numbers and last digit of the first prime equals to the first digit of second prime number. 11 and 11 are not pair primes because a = b.\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eFor 3 digit numbers:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 389 and 967 are pair primes because both of them are 3 digits prime numbers and last digit of the first prime equals to the first digit of the second prime number (797 and 797 are not pair primes because a = b). 467 and 673 are pair primes too because the last two digits of the first prime number (67) equals to the first two digit (67) of the second prime number. 211 and 113 are pair primes too but they satisfy two conditions: last digit of the first prime equals to the first digit of the second prime also last two digits of the first prime equals to the first two digits of the first prime.\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eFor 4 digit numbers:\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\u003e1-) 1637 and 7549 are pair primes. First ends with 7 and second starts with 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2-) 6221 and 2113 are pair primes. First ends with 21 and second starts with 21.\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\u003e3-) 1429 and 4297 are pair primes. First ends with 429 and second starts with 429. You should be careful. 2111 and 1117 are also four digit pair primes. It satisfies three conditions. First ends with 1 and second starts with 1. First ends with 11 and second starts with 11. First ends with 111 and second starts with 111. [2111 1117] pair should be counted for once.\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\u003eGiven the digit counts, can you determine how many unique pair primes are there (a~=b)\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\"}]}"}],"term":"tag:\"cody5\"","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:\"cody5\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"cody5\"","","\"","cody5","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fbf303a30d0\u003e":null,"#\u003cMathWorks::Search::Field:0x00007fbf303a3030\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fbf303a2770\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fbf303a3350\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fbf303a32b0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fbf303a3210\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fbf303a3170\u003e":"tag:\"cody5\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fbf303a3170\u003e":"tag:\"cody5\""},"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":"cody-search","password":"78X075ddcV44","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:\"cody5\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"cody5\"","","\"","cody5","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fbf303a30d0\u003e":null,"#\u003cMathWorks::Search::Field:0x00007fbf303a3030\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fbf303a2770\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fbf303a3350\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fbf303a32b0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fbf303a3210\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fbf303a3170\u003e":"tag:\"cody5\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fbf303a3170\u003e":"tag:\"cody5\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":369,"difficulty_rating":"easy-medium"},{"id":361,"difficulty_rating":"easy-medium"},{"id":44315,"difficulty_rating":"easy-medium"},{"id":2736,"difficulty_rating":"easy-medium"},{"id":44370,"difficulty_rating":"easy-medium"},{"id":44314,"difficulty_rating":"easy-medium"},{"id":564,"difficulty_rating":"easy-medium"},{"id":44369,"difficulty_rating":"easy-medium"},{"id":44358,"difficulty_rating":"easy-medium"},{"id":44363,"difficulty_rating":"easy-medium"},{"id":44384,"difficulty_rating":"easy-medium"},{"id":44385,"difficulty_rating":"easy-medium"},{"id":44319,"difficulty_rating":"easy-medium"},{"id":44342,"difficulty_rating":"easy-medium"},{"id":44349,"difficulty_rating":"easy-medium"},{"id":44360,"difficulty_rating":"easy-medium"},{"id":44368,"difficulty_rating":"easy-medium"},{"id":44338,"difficulty_rating":"easy-medium"},{"id":44334,"difficulty_rating":"easy-medium"},{"id":44381,"difficulty_rating":"easy-medium"},{"id":44321,"difficulty_rating":"easy-medium"},{"id":44307,"difficulty_rating":"easy-medium"},{"id":44305,"difficulty_rating":"easy-medium"},{"id":44339,"difficulty_rating":"easy-medium"},{"id":44375,"difficulty_rating":"easy-medium"},{"id":44364,"difficulty_rating":"easy-medium"},{"id":44365,"difficulty_rating":"easy-medium"},{"id":44311,"difficulty_rating":"easy-medium"},{"id":281,"difficulty_rating":"easy-medium"},{"id":44372,"difficulty_rating":"easy-medium"},{"id":44310,"difficulty_rating":"medium"},{"id":44344,"difficulty_rating":"medium"},{"id":44337,"difficulty_rating":"medium"},{"id":44367,"difficulty_rating":"medium"},{"id":44340,"difficulty_rating":"medium"},{"id":44359,"difficulty_rating":"medium"},{"id":44350,"difficulty_rating":"medium"},{"id":44352,"difficulty_rating":"medium"},{"id":44386,"difficulty_rating":"medium"},{"id":44306,"difficulty_rating":"medium"},{"id":44341,"difficulty_rating":"medium"},{"id":44353,"difficulty_rating":"medium"},{"id":44309,"difficulty_rating":"medium"},{"id":44380,"difficulty_rating":"medium"},{"id":44316,"difficulty_rating":"medium"},{"id":44345,"difficulty_rating":"medium-hard"},{"id":44374,"difficulty_rating":"medium-hard"},{"id":44382,"difficulty_rating":"medium-hard"},{"id":44347,"difficulty_rating":"medium-hard"},{"id":44343,"difficulty_rating":"medium-hard"}]}}