{"group":{"group":{"id":30,"name":"Sequences \u0026 Series III","lockable":false,"created_at":"2017-07-12T15:35:37.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"These problems could continue on forever.","is_default":false,"created_by":26769,"badge_id":44,"featured":false,"trending":false,"solution_count_in_trending_period":20,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":409,"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":"{\"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\u003eThese problems could continue on forever.\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\"}]}","description_html":"\u003cdiv style = \"text-align: start; line-height: normal; 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: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"display: block; min-width: 0px; padding-top: 0px; perspective-origin: 289.5px 10.5px; transform-origin: 289.5px 10.5px; \"\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; white-space: pre-wrap; perspective-origin: 266.5px 10.5px; transform-origin: 266.5px 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; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThese problems could continue on forever.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","published_at":"2019-05-08T19:57:01.000Z"},"current_player":null},"problems":[{"id":3001,"title":"Sphenic number sequence","description":"Sphenic numbers are positive integers that are products of three distinct prime numbers: 30, 42, 66, 70, 78, 102, 105, 110, 114, 130, ... For example, 30 = 2*3*5, 42 = 2*3*7, etc.\r\nReturn the numbers from the sphenic sequence corresponding to the supplied indices. For example, if n = 3:7, your function should return [66, 70, 78, 102, 105].\r\nThis problem is related to Problem 3002 and Problem 3003.","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: 123px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 61.5px; transform-origin: 407px 61.5px; vertical-align: baseline; \"\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\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eSphenic numbers\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: 317.5px 8px; transform-origin: 317.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e are positive integers that are products of three distinct prime numbers: 30, 42, 66, 70, 78, 102, 105, 110, 114, 130, ... For example, 30 = 2*3*5, 42 = 2*3*7, etc.\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: 365px 8px; transform-origin: 365px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn the numbers from the sphenic sequence corresponding to the supplied indices. For example, if n = 3:7, your function should return [66, 70, 78, 102, 105].\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: 80px 8px; transform-origin: 80px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis problem is related to\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://www.mathworks.com/matlabcentral/cody/problems/3002-not-square-free-number-sequence\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 3002\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: 14px 8px; transform-origin: 14px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and\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://www.mathworks.com/matlabcentral/cody/problems/3003-mobius-function\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 3003\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [arr] = sphenic_seq(n)\r\n\r\narr = n;\r\n\r\nend","test_suite":"%%\r\nn = 1:5;\r\narr_corr = [30, 42, 66, 70, 78];\r\nassert(isequal(sphenic_seq(n),arr_corr))\r\n\r\n%%\r\nn = 1:10;\r\narr_corr = [30, 42, 66, 70, 78, 102, 105, 110, 114, 130];\r\nassert(isequal(sphenic_seq(n),arr_corr))\r\n\r\n%%\r\nn = 3:7;\r\narr_corr = [66, 70, 78, 102, 105];\r\nassert(isequal(sphenic_seq(n),arr_corr))\r\n\r\n%%\r\nn = 20:30;\r\narr_corr = [222   230   231   238   246   255   258   266   273   282   285];\r\nassert(isequal(sphenic_seq(n),arr_corr))\r\n\r\n%%\r\nn = 69;\r\narr_corr = 582;\r\nassert(isequal(sphenic_seq(n),arr_corr))\r\n\r\n%%\r\nn = 1:53;\r\narr_corr = [30, 42, 66, 70, 78, 102, 105, 110, 114, 130, 138, 154, 165, 170, 174, 182, 186, 190, 195, 222, 230, 231, 238, 246, 255, 258, 266, 273, 282, 285, 286, 290, 310, 318, 322, 345, 354, 357, 366, 370, 374, 385, 399, 402, 406, 410, 418, 426, 429, 430, 434, 435, 438];\r\nassert(isequal(sphenic_seq(n),arr_corr))\r\n\r\n%% prevents cheating\r\ni1 = randi(20,1);\r\nn = i1:(i1+randi(25,1));\r\narr_tot = [30, 42, 66, 70, 78, 102, 105, 110, 114, 130, 138, 154, 165, 170, 174, 182, 186, 190, 195, 222, 230, 231, 238, 246, 255, 258, 266, 273, 282, 285, 286, 290, 310, 318, 322, 345, 354, 357, 366, 370, 374, 385, 399, 402, 406, 410, 418, 426, 429, 430, 434, 435, 438];\r\narr_corr = arr_tot(n);\r\nassert(isequal(sphenic_seq(n),arr_corr))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":26769,"edited_by":223089,"edited_at":"2022-10-09T05:23:45.000Z","deleted_by":null,"deleted_at":null,"solvers_count":87,"test_suite_updated_at":"2022-10-09T05:23:45.000Z","rescore_all_solutions":false,"group_id":30,"created_at":"2015-02-11T02:19:47.000Z","updated_at":"2026-03-16T14:15:22.000Z","published_at":"2015-02-11T02:19:47.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:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSphenic numbers\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e are positive integers that are products of three distinct prime numbers: 30, 42, 66, 70, 78, 102, 105, 110, 114, 130, ... For example, 30 = 2*3*5, 42 = 2*3*7, etc.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the numbers from the sphenic sequence corresponding to the supplied indices. For example, if n = 3:7, your function should return [66, 70, 78, 102, 105].\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 problem is related 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/3002-not-square-free-number-sequence\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3002\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.mathworks.com/matlabcentral/cody/problems/3003-mobius-function\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3003\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":3001,"title":"Sphenic number sequence","description":"Sphenic numbers are positive integers that are products of three distinct prime numbers: 30, 42, 66, 70, 78, 102, 105, 110, 114, 130, ... For example, 30 = 2*3*5, 42 = 2*3*7, etc.\r\nReturn the numbers from the sphenic sequence corresponding to the supplied indices. For example, if n = 3:7, your function should return [66, 70, 78, 102, 105].\r\nThis problem is related to Problem 3002 and Problem 3003.","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: 123px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 61.5px; transform-origin: 407px 61.5px; vertical-align: baseline; \"\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\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eSphenic numbers\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: 317.5px 8px; transform-origin: 317.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e are positive integers that are products of three distinct prime numbers: 30, 42, 66, 70, 78, 102, 105, 110, 114, 130, ... For example, 30 = 2*3*5, 42 = 2*3*7, etc.\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: 365px 8px; transform-origin: 365px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn the numbers from the sphenic sequence corresponding to the supplied indices. For example, if n = 3:7, your function should return [66, 70, 78, 102, 105].\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: 80px 8px; transform-origin: 80px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis problem is related to\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://www.mathworks.com/matlabcentral/cody/problems/3002-not-square-free-number-sequence\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 3002\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: 14px 8px; transform-origin: 14px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and\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://www.mathworks.com/matlabcentral/cody/problems/3003-mobius-function\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 3003\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [arr] = sphenic_seq(n)\r\n\r\narr = n;\r\n\r\nend","test_suite":"%%\r\nn = 1:5;\r\narr_corr = [30, 42, 66, 70, 78];\r\nassert(isequal(sphenic_seq(n),arr_corr))\r\n\r\n%%\r\nn = 1:10;\r\narr_corr = [30, 42, 66, 70, 78, 102, 105, 110, 114, 130];\r\nassert(isequal(sphenic_seq(n),arr_corr))\r\n\r\n%%\r\nn = 3:7;\r\narr_corr = [66, 70, 78, 102, 105];\r\nassert(isequal(sphenic_seq(n),arr_corr))\r\n\r\n%%\r\nn = 20:30;\r\narr_corr = [222   230   231   238   246   255   258   266   273   282   285];\r\nassert(isequal(sphenic_seq(n),arr_corr))\r\n\r\n%%\r\nn = 69;\r\narr_corr = 582;\r\nassert(isequal(sphenic_seq(n),arr_corr))\r\n\r\n%%\r\nn = 1:53;\r\narr_corr = [30, 42, 66, 70, 78, 102, 105, 110, 114, 130, 138, 154, 165, 170, 174, 182, 186, 190, 195, 222, 230, 231, 238, 246, 255, 258, 266, 273, 282, 285, 286, 290, 310, 318, 322, 345, 354, 357, 366, 370, 374, 385, 399, 402, 406, 410, 418, 426, 429, 430, 434, 435, 438];\r\nassert(isequal(sphenic_seq(n),arr_corr))\r\n\r\n%% prevents cheating\r\ni1 = randi(20,1);\r\nn = i1:(i1+randi(25,1));\r\narr_tot = [30, 42, 66, 70, 78, 102, 105, 110, 114, 130, 138, 154, 165, 170, 174, 182, 186, 190, 195, 222, 230, 231, 238, 246, 255, 258, 266, 273, 282, 285, 286, 290, 310, 318, 322, 345, 354, 357, 366, 370, 374, 385, 399, 402, 406, 410, 418, 426, 429, 430, 434, 435, 438];\r\narr_corr = arr_tot(n);\r\nassert(isequal(sphenic_seq(n),arr_corr))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":26769,"edited_by":223089,"edited_at":"2022-10-09T05:23:45.000Z","deleted_by":null,"deleted_at":null,"solvers_count":87,"test_suite_updated_at":"2022-10-09T05:23:45.000Z","rescore_all_solutions":false,"group_id":30,"created_at":"2015-02-11T02:19:47.000Z","updated_at":"2026-03-16T14:15:22.000Z","published_at":"2015-02-11T02:19:47.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:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSphenic numbers\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e are positive integers that are products of three distinct prime numbers: 30, 42, 66, 70, 78, 102, 105, 110, 114, 130, ... For example, 30 = 2*3*5, 42 = 2*3*7, etc.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the numbers from the sphenic sequence corresponding to the supplied indices. For example, if n = 3:7, your function should return [66, 70, 78, 102, 105].\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 problem is related 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/3002-not-square-free-number-sequence\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3002\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.mathworks.com/matlabcentral/cody/problems/3003-mobius-function\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3003\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":3002,"title":"Not square-free number sequence","description":"Not square-free numbers are all positive integers divisible by a square greater than one: 4, 8, 9, 12, 16, 18, 20, 24, 25, 27, ... For example, 4 = 2^2, 8 = 2^2 * 2, 9 = 3^2, 12 = 2^2 * 3, etc.\r\nReturn numbers from the square-free sequence corresponding to the supplied indices. For example, if n = 3:7, your function should return [9, 12, 16, 18, 20].\r\nThis problem is related to Problem 3001 and Problem 3003.","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: 123px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 61.5px; transform-origin: 407px 61.5px; vertical-align: baseline; \"\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\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eNot square-free numbers\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: 296.5px 8px; transform-origin: 296.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e are all positive integers divisible by a square greater than one: 4, 8, 9, 12, 16, 18, 20, 24, 25, 27, ... For example, 4 = 2^2, 8 = 2^2 * 2, 9 = 3^2, 12 = 2^2 * 3, etc.\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: 365.5px 8px; transform-origin: 365.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn numbers from the square-free sequence corresponding to the supplied indices. For example, if n = 3:7, your function should return [9, 12, 16, 18, 20].\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: 80px 8px; transform-origin: 80px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis problem is related to\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://www.mathworks.com/matlabcentral/cody/problems/3001-sphenic-number-sequence\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 3001\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: 14px 8px; transform-origin: 14px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and\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://www.mathworks.com/matlabcentral/cody/problems/3003-mobius-function\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 3003\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [arr] = not_squarefree_seq(n)\r\n\r\narr = n;\r\n\r\nend\r\n","test_suite":"%%\r\nn = 1:5;\r\narr_corr = [4, 8, 9, 12, 16];\r\nassert(isequal(not_squarefree_seq(n),arr_corr))\r\n\r\n%%\r\nn = 1:10;\r\narr_corr = [4, 8, 9, 12, 16, 18, 20, 24, 25, 27];\r\nassert(isequal(not_squarefree_seq(n),arr_corr))\r\n\r\n%%\r\nn = 3:7;\r\narr_corr = [9    12    16    18    20];\r\nassert(isequal(not_squarefree_seq(n),arr_corr))\r\n\r\n%%\r\nn = 20:30;\r\narr_corr = [52    54    56    60    63    64    68    72    75    76    80];\r\nassert(isequal(not_squarefree_seq(n),arr_corr))\r\n\r\n%%\r\nn = 69;\r\narr_corr = 175;\r\nassert(isequal(not_squarefree_seq(n),arr_corr))\r\n\r\n%%\r\nn = 1:62;\r\narr_corr = [4, 8, 9, 12, 16, 18, 20, 24, 25, 27, 28, 32, 36, 40, 44, 45, 48, 49, 50, 52, 54, 56, 60, 63, 64, 68, 72, 75, 76, 80, 81, 84, 88, 90, 92, 96, 98, 99, 100, 104, 108, 112, 116, 117, 120, 121, 124, 125, 126, 128, 132, 135, 136, 140, 144, 147, 148, 150, 152, 153, 156, 160];\r\nassert(isequal(not_squarefree_seq(n),arr_corr))\r\n\r\n%% prevents cheating\r\ni1 = randi(20,1);\r\nn = i1:(i1+randi(25,1));\r\narr_tot = [4, 8, 9, 12, 16, 18, 20, 24, 25, 27, 28, 32, 36, 40, 44, 45, 48, 49, 50, 52, 54, 56, 60, 63, 64, 68, 72, 75, 76, 80, 81, 84, 88, 90, 92, 96, 98, 99, 100, 104, 108, 112, 116, 117, 120, 121, 124, 125, 126, 128, 132, 135, 136, 140, 144, 147, 148, 150, 152, 153, 156, 160];\r\narr_corr = arr_tot(n);\r\nassert(isequal(not_squarefree_seq(n),arr_corr))\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":26769,"edited_by":223089,"edited_at":"2022-10-09T05:12:26.000Z","deleted_by":null,"deleted_at":null,"solvers_count":81,"test_suite_updated_at":"2022-10-09T05:12:26.000Z","rescore_all_solutions":false,"group_id":30,"created_at":"2015-02-11T02:39:31.000Z","updated_at":"2026-03-16T14:13:50.000Z","published_at":"2015-02-11T02:39:31.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:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eNot square-free numbers\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e are all positive integers divisible by a square greater than one: 4, 8, 9, 12, 16, 18, 20, 24, 25, 27, ... For example, 4 = 2^2, 8 = 2^2 * 2, 9 = 3^2, 12 = 2^2 * 3, etc.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn numbers from the square-free sequence corresponding to the supplied indices. For example, if n = 3:7, your function should return [9, 12, 16, 18, 20].\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 problem is related 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/3001-sphenic-number-sequence\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3001\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.mathworks.com/matlabcentral/cody/problems/3003-mobius-function\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3003\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":3092,"title":"Return fibonacci sequence  do not use loop and condition","description":"Calculate the nth Fibonacci number.\r\n\r\nGiven n, return f where f = fib(n) and f(1) = 1, f(2) = 1, f(3) = 2, ...\r\n\r\nExamples:\r\n\r\n Input  n = 5\r\n Output f is 5\r\n Input  n = 7\r\n Output f is 13\r\n\r\nbut, *loop and conditional statement is forbidden*","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: 203.733px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 101.867px; transform-origin: 407px 101.867px; 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: 113.5px 8px; transform-origin: 113.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eCalculate the nth Fibonacci number.\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: 204px 8px; transform-origin: 204px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven n, return f where f = fib(n) and f(1) = 1, f(2) = 1, f(3) = 2, ...\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: 32px 8px; transform-origin: 32px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExamples:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.7333px; 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 40.8667px; transform-origin: 404px 40.8667px; 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: 52px 8.5px; transform-origin: 52px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 32px 8.5px; transform-origin: 32px 8.5px; \"\u003e Input  \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 20px 8.5px; text-decoration: none; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 20px 8.5px; \"\u003en = 5\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: 56px 8.5px; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 32px 8.5px; transform-origin: 32px 8.5px; \"\u003e Output \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 24px 8.5px; text-decoration: none; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 24px 8.5px; \"\u003ef is 5\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: 52px 8.5px; transform-origin: 52px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 32px 8.5px; transform-origin: 32px 8.5px; \"\u003e Input  \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 20px 8.5px; text-decoration: none; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 20px 8.5px; \"\u003en = 7\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: 60px 8.5px; transform-origin: 60px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 32px 8.5px; transform-origin: 32px 8.5px; \"\u003e Output \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 28px 8.5px; text-decoration: none; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 28px 8.5px; \"\u003ef is 13\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: 12px 8px; transform-origin: 12px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ebut,\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\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: 153px 8px; transform-origin: 153px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eloop and conditional statement is forbidden\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function f = fib(n)\r\n  f = n;\r\nend","test_suite":"%%% functions forbidden\r\n\r\n\r\n% Clean user's function from some known jailbreaking mechanisms\r\nfunctions={'!','feval','eval','str2func','str2num','regex','system','dos','unix','perl','assert','fopen','write','save','setenv','path','please','for','if','while','switch','round','roundn','fix','ceil','char','floor'};\r\nassessFunctionAbsence(functions, 'FileName', 'fib.m');\r\n%%\r\nn = 1;\r\nf = 1;\r\nassert(abs(fib(n) - f) \u003c 1e-4)\r\n\r\n%%\r\nn = 6;\r\nf = 8;\r\nassert(abs(fib(n) - f) \u003c 1e-4)\r\n\r\n%%\r\nn = 10;\r\nf = 55;\r\nassert(abs(fib(n) - f) \u003c 1e-4)\r\n\r\n%%\r\nn = 20;\r\nf = 6765;\r\nassert(abs(fib(n) - f) \u003c 1e-4)","published":true,"deleted":false,"likes_count":15,"comments_count":11,"created_by":3668,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":855,"test_suite_updated_at":"2021-02-15T12:43:32.000Z","rescore_all_solutions":false,"group_id":30,"created_at":"2015-03-18T15:03:18.000Z","updated_at":"2026-03-16T14:19:58.000Z","published_at":"2015-03-18T15:25:13.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\u003eCalculate the nth Fibonacci 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\u003eGiven n, return f where f = fib(n) and f(1) = 1, f(2) = 1, f(3) = 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\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[ Input  n = 5\\n Output f is 5\\n Input  n = 7\\n Output f is 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ebut,\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\u003eloop and conditional statement is forbidden\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":3003,"title":"Mobius function","description":"From wikipedia:\r\nFor any positive integer n, define μ(n) as the sum of the primitive n-th roots of unity. It has values in {−1, 0, 1} depending on the factorization of n into prime factors:\r\nμ(n) = 1 if n is a square-free positive integer with an even number of prime factors.\r\nμ(n) = −1 if n is a square-free positive integer with an odd number of prime factors.\r\nμ(n) = 0 if n has a squared prime factor.\r\nReturn numbers from the Mobius function sequence corresponding to the supplied indices. For example, if n = 3:7, your function should return [-1, 0, -1, 1, -1].\r\nHint: solving Problem 3001 and Problem 3002 will provide much of the code needed for this problem. You'll need to add prime numbers to the sphenic number set (resulting from Problem 3001).","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: 256.3px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 128.15px; transform-origin: 407px 128.15px; 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: 16.5px 8px; transform-origin: 16.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFrom\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ewikipedia\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e:\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: 380px 8px; transform-origin: 380px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor any positive integer n, define μ(n) as the sum of the primitive n-th roots of unity. It has values in {−1, 0, 1} depending on the factorization of n into prime factors:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 61.3px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 30.65px; transform-origin: 391px 30.65px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 259px 8px; transform-origin: 259px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eμ(n) = 1 if n is a square-free positive integer with an even number of prime factors.\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: 259.5px 8px; transform-origin: 259.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eμ(n) = −1 if n is a square-free positive integer with an odd number of prime factors.\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: 125px 8px; transform-origin: 125px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eμ(n) = 0 if n has a squared prime factor.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\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: 79px 8px; transform-origin: 79px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn numbers from the\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eMobius function sequence\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: 214.5px 8px; transform-origin: 214.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e corresponding to the supplied indices. For example, if n = 3:7, your function should return [-1, 0, -1, 1, -1].\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: 38px 8px; transform-origin: 38px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eHint: solving\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://www.mathworks.com/matlabcentral/cody/problems/3001-sphenic-number-sequence\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 3001\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: 14px 8px; transform-origin: 14px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and\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://www.mathworks.com/matlabcentral/cody/problems/3002-not-square-free-number-sequence\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 3002\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: 232.5px 8px; transform-origin: 232.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e will provide much of the code needed for this problem. You'll need to add prime numbers to the sphenic number set (resulting from Problem 3001).\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [arr] = mobius_func_seq(n)\r\n\r\narr =n;\r\n\r\nend\r\n","test_suite":"%%\r\nn = 1:5;\r\narr_corr = [1, -1, -1, 0, -1];\r\nassert(isequal(mobius_func_seq(n),arr_corr))\r\n\r\n%%\r\nn = 1:10;\r\narr_corr = [1, -1, -1, 0, -1, 1, -1, 0, 0, 1];\r\nassert(isequal(mobius_func_seq(n),arr_corr))\r\n\r\n%%\r\nn = 3:7;\r\narr_corr = [-1, 0, -1, 1, -1];\r\nassert(isequal(mobius_func_seq(n),arr_corr))\r\n\r\n%%\r\nn = 20:30;\r\narr_corr = [0     1     1    -1     0     0     1     0     0    -1    -1];\r\nassert(isequal(mobius_func_seq(n),arr_corr))\r\n\r\n%%\r\nn = 99;\r\narr_corr = 0;\r\nassert(isequal(mobius_func_seq(n),arr_corr))\r\n\r\n%%\r\nn = 1:77;\r\narr_corr = [1, -1, -1, 0, -1, 1, -1, 0, 0, 1, -1, 0, -1, 1, 1, 0, -1, 0, -1, 0, 1, 1, -1, 0, 0, 1, 0, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, 1, 1, 0, -1, -1, -1, 0, 0, 1, -1, 0, 0, 0, 1, 0, -1, 0, 1, 0, 1, 1, -1, 0, -1, 1, 0, 0, 1, -1, -1, 0, 1, -1, -1, 0, -1, 1, 0, 0, 1];\r\nassert(isequal(mobius_func_seq(n),arr_corr))\r\n\r\n%% prevents cheating\r\ni1 = randi(20,1);\r\nn = i1:(i1+randi(25,1));\r\narr_tot = [1, -1, -1, 0, -1, 1, -1, 0, 0, 1, -1, 0, -1, 1, 1, 0, -1, 0, -1, 0, 1, 1, -1, 0, 0, 1, 0, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, 1, 1, 0, -1, -1, -1, 0, 0, 1, -1, 0, 0, 0, 1, 0, -1, 0, 1, 0, 1, 1, -1, 0, -1, 1, 0, 0, 1, -1, -1, 0, 1, -1, -1, 0, -1, 1, 0, 0, 1];\r\narr_corr = arr_tot(n);\r\nassert(isequal(mobius_func_seq(n),arr_corr))","published":true,"deleted":false,"likes_count":5,"comments_count":3,"created_by":26769,"edited_by":223089,"edited_at":"2022-10-09T11:44:37.000Z","deleted_by":null,"deleted_at":null,"solvers_count":63,"test_suite_updated_at":"2022-10-09T11:44:37.000Z","rescore_all_solutions":false,"group_id":30,"created_at":"2015-02-11T03:05:35.000Z","updated_at":"2026-03-16T14:39:18.000Z","published_at":"2015-02-11T03:05:35.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\u003eFrom\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ewikipedia\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor any positive integer n, define μ(n) as the sum of the primitive n-th roots of unity. It has values in {−1, 0, 1} depending on the factorization of n into prime factors:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eμ(n) = 1 if n is a square-free positive integer with an even number of prime factors.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eμ(n) = −1 if n is a square-free positive integer with an odd number of prime factors.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eμ(n) = 0 if n has a squared prime factor.\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\u003eReturn numbers from 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=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eMobius function sequence\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e corresponding to the supplied indices. For example, if n = 3:7, your function should return [-1, 0, -1, 1, -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\u003eHint: solving\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/3001-sphenic-number-sequence\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3001\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.mathworks.com/matlabcentral/cody/problems/3002-not-square-free-number-sequence\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3002\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e will provide much of the code needed for this problem. You'll need to add prime numbers to the sphenic number set (resulting from Problem 3001).\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":3002,"title":"Not square-free number sequence","description":"Not square-free numbers are all positive integers divisible by a square greater than one: 4, 8, 9, 12, 16, 18, 20, 24, 25, 27, ... For example, 4 = 2^2, 8 = 2^2 * 2, 9 = 3^2, 12 = 2^2 * 3, etc.\r\nReturn numbers from the square-free sequence corresponding to the supplied indices. For example, if n = 3:7, your function should return [9, 12, 16, 18, 20].\r\nThis problem is related to Problem 3001 and Problem 3003.","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: 123px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 61.5px; transform-origin: 407px 61.5px; vertical-align: baseline; \"\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\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eNot square-free numbers\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: 296.5px 8px; transform-origin: 296.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e are all positive integers divisible by a square greater than one: 4, 8, 9, 12, 16, 18, 20, 24, 25, 27, ... For example, 4 = 2^2, 8 = 2^2 * 2, 9 = 3^2, 12 = 2^2 * 3, etc.\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: 365.5px 8px; transform-origin: 365.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn numbers from the square-free sequence corresponding to the supplied indices. For example, if n = 3:7, your function should return [9, 12, 16, 18, 20].\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: 80px 8px; transform-origin: 80px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis problem is related to\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://www.mathworks.com/matlabcentral/cody/problems/3001-sphenic-number-sequence\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 3001\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: 14px 8px; transform-origin: 14px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and\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://www.mathworks.com/matlabcentral/cody/problems/3003-mobius-function\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 3003\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [arr] = not_squarefree_seq(n)\r\n\r\narr = n;\r\n\r\nend\r\n","test_suite":"%%\r\nn = 1:5;\r\narr_corr = [4, 8, 9, 12, 16];\r\nassert(isequal(not_squarefree_seq(n),arr_corr))\r\n\r\n%%\r\nn = 1:10;\r\narr_corr = [4, 8, 9, 12, 16, 18, 20, 24, 25, 27];\r\nassert(isequal(not_squarefree_seq(n),arr_corr))\r\n\r\n%%\r\nn = 3:7;\r\narr_corr = [9    12    16    18    20];\r\nassert(isequal(not_squarefree_seq(n),arr_corr))\r\n\r\n%%\r\nn = 20:30;\r\narr_corr = [52    54    56    60    63    64    68    72    75    76    80];\r\nassert(isequal(not_squarefree_seq(n),arr_corr))\r\n\r\n%%\r\nn = 69;\r\narr_corr = 175;\r\nassert(isequal(not_squarefree_seq(n),arr_corr))\r\n\r\n%%\r\nn = 1:62;\r\narr_corr = [4, 8, 9, 12, 16, 18, 20, 24, 25, 27, 28, 32, 36, 40, 44, 45, 48, 49, 50, 52, 54, 56, 60, 63, 64, 68, 72, 75, 76, 80, 81, 84, 88, 90, 92, 96, 98, 99, 100, 104, 108, 112, 116, 117, 120, 121, 124, 125, 126, 128, 132, 135, 136, 140, 144, 147, 148, 150, 152, 153, 156, 160];\r\nassert(isequal(not_squarefree_seq(n),arr_corr))\r\n\r\n%% prevents cheating\r\ni1 = randi(20,1);\r\nn = i1:(i1+randi(25,1));\r\narr_tot = [4, 8, 9, 12, 16, 18, 20, 24, 25, 27, 28, 32, 36, 40, 44, 45, 48, 49, 50, 52, 54, 56, 60, 63, 64, 68, 72, 75, 76, 80, 81, 84, 88, 90, 92, 96, 98, 99, 100, 104, 108, 112, 116, 117, 120, 121, 124, 125, 126, 128, 132, 135, 136, 140, 144, 147, 148, 150, 152, 153, 156, 160];\r\narr_corr = arr_tot(n);\r\nassert(isequal(not_squarefree_seq(n),arr_corr))\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":26769,"edited_by":223089,"edited_at":"2022-10-09T05:12:26.000Z","deleted_by":null,"deleted_at":null,"solvers_count":81,"test_suite_updated_at":"2022-10-09T05:12:26.000Z","rescore_all_solutions":false,"group_id":30,"created_at":"2015-02-11T02:39:31.000Z","updated_at":"2026-03-16T14:13:50.000Z","published_at":"2015-02-11T02:39:31.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:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eNot square-free numbers\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e are all positive integers divisible by a square greater than one: 4, 8, 9, 12, 16, 18, 20, 24, 25, 27, ... For example, 4 = 2^2, 8 = 2^2 * 2, 9 = 3^2, 12 = 2^2 * 3, etc.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn numbers from the square-free sequence corresponding to the supplied indices. For example, if n = 3:7, your function should return [9, 12, 16, 18, 20].\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 problem is related 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/3001-sphenic-number-sequence\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3001\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.mathworks.com/matlabcentral/cody/problems/3003-mobius-function\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3003\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":3003,"title":"Mobius function","description":"From wikipedia:\r\nFor any positive integer n, define μ(n) as the sum of the primitive n-th roots of unity. It has values in {−1, 0, 1} depending on the factorization of n into prime factors:\r\nμ(n) = 1 if n is a square-free positive integer with an even number of prime factors.\r\nμ(n) = −1 if n is a square-free positive integer with an odd number of prime factors.\r\nμ(n) = 0 if n has a squared prime factor.\r\nReturn numbers from the Mobius function sequence corresponding to the supplied indices. For example, if n = 3:7, your function should return [-1, 0, -1, 1, -1].\r\nHint: solving Problem 3001 and Problem 3002 will provide much of the code needed for this problem. You'll need to add prime numbers to the sphenic number set (resulting from Problem 3001).","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: 256.3px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 128.15px; transform-origin: 407px 128.15px; 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: 16.5px 8px; transform-origin: 16.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFrom\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ewikipedia\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e:\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: 380px 8px; transform-origin: 380px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor any positive integer n, define μ(n) as the sum of the primitive n-th roots of unity. It has values in {−1, 0, 1} depending on the factorization of n into prime factors:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 61.3px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 30.65px; transform-origin: 391px 30.65px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 259px 8px; transform-origin: 259px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eμ(n) = 1 if n is a square-free positive integer with an even number of prime factors.\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: 259.5px 8px; transform-origin: 259.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eμ(n) = −1 if n is a square-free positive integer with an odd number of prime factors.\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: 125px 8px; transform-origin: 125px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eμ(n) = 0 if n has a squared prime factor.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\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: 79px 8px; transform-origin: 79px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn numbers from the\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eMobius function sequence\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: 214.5px 8px; transform-origin: 214.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e corresponding to the supplied indices. For example, if n = 3:7, your function should return [-1, 0, -1, 1, -1].\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: 38px 8px; transform-origin: 38px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eHint: solving\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://www.mathworks.com/matlabcentral/cody/problems/3001-sphenic-number-sequence\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 3001\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: 14px 8px; transform-origin: 14px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and\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://www.mathworks.com/matlabcentral/cody/problems/3002-not-square-free-number-sequence\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 3002\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: 232.5px 8px; transform-origin: 232.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e will provide much of the code needed for this problem. You'll need to add prime numbers to the sphenic number set (resulting from Problem 3001).\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [arr] = mobius_func_seq(n)\r\n\r\narr =n;\r\n\r\nend\r\n","test_suite":"%%\r\nn = 1:5;\r\narr_corr = [1, -1, -1, 0, -1];\r\nassert(isequal(mobius_func_seq(n),arr_corr))\r\n\r\n%%\r\nn = 1:10;\r\narr_corr = [1, -1, -1, 0, -1, 1, -1, 0, 0, 1];\r\nassert(isequal(mobius_func_seq(n),arr_corr))\r\n\r\n%%\r\nn = 3:7;\r\narr_corr = [-1, 0, -1, 1, -1];\r\nassert(isequal(mobius_func_seq(n),arr_corr))\r\n\r\n%%\r\nn = 20:30;\r\narr_corr = [0     1     1    -1     0     0     1     0     0    -1    -1];\r\nassert(isequal(mobius_func_seq(n),arr_corr))\r\n\r\n%%\r\nn = 99;\r\narr_corr = 0;\r\nassert(isequal(mobius_func_seq(n),arr_corr))\r\n\r\n%%\r\nn = 1:77;\r\narr_corr = [1, -1, -1, 0, -1, 1, -1, 0, 0, 1, -1, 0, -1, 1, 1, 0, -1, 0, -1, 0, 1, 1, -1, 0, 0, 1, 0, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, 1, 1, 0, -1, -1, -1, 0, 0, 1, -1, 0, 0, 0, 1, 0, -1, 0, 1, 0, 1, 1, -1, 0, -1, 1, 0, 0, 1, -1, -1, 0, 1, -1, -1, 0, -1, 1, 0, 0, 1];\r\nassert(isequal(mobius_func_seq(n),arr_corr))\r\n\r\n%% prevents cheating\r\ni1 = randi(20,1);\r\nn = i1:(i1+randi(25,1));\r\narr_tot = [1, -1, -1, 0, -1, 1, -1, 0, 0, 1, -1, 0, -1, 1, 1, 0, -1, 0, -1, 0, 1, 1, -1, 0, 0, 1, 0, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, 1, 1, 0, -1, -1, -1, 0, 0, 1, -1, 0, 0, 0, 1, 0, -1, 0, 1, 0, 1, 1, -1, 0, -1, 1, 0, 0, 1, -1, -1, 0, 1, -1, -1, 0, -1, 1, 0, 0, 1];\r\narr_corr = arr_tot(n);\r\nassert(isequal(mobius_func_seq(n),arr_corr))","published":true,"deleted":false,"likes_count":5,"comments_count":3,"created_by":26769,"edited_by":223089,"edited_at":"2022-10-09T11:44:37.000Z","deleted_by":null,"deleted_at":null,"solvers_count":63,"test_suite_updated_at":"2022-10-09T11:44:37.000Z","rescore_all_solutions":false,"group_id":30,"created_at":"2015-02-11T03:05:35.000Z","updated_at":"2026-03-16T14:39:18.000Z","published_at":"2015-02-11T03:05:35.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\u003eFrom\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ewikipedia\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor any positive integer n, define μ(n) as the sum of the primitive n-th roots of unity. It has values in {−1, 0, 1} depending on the factorization of n into prime factors:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eμ(n) = 1 if n is a square-free positive integer with an even number of prime factors.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eμ(n) = −1 if n is a square-free positive integer with an odd number of prime factors.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eμ(n) = 0 if n has a squared prime factor.\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\u003eReturn numbers from 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=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eMobius function sequence\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e corresponding to the supplied indices. For example, if n = 3:7, your function should return [-1, 0, -1, 1, -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\u003eHint: solving\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/3001-sphenic-number-sequence\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3001\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.mathworks.com/matlabcentral/cody/problems/3002-not-square-free-number-sequence\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3002\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e will provide much of the code needed for this problem. You'll need to add prime numbers to the sphenic number set (resulting from Problem 3001).\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":3010,"title":"Self-similarity 1 - Every other term","description":"Self-similar integer sequences are certain sequences that can be reproduced by extracting a portion of the existing sequence. See the \u003chttps://oeis.org/selfsimilar.html OEIS page\u003e for more information.\r\n\r\nIn this problem, you are to check if the sequence is self-similar by every other term. The problem set assumes that you use the easiest route: take the first element and then every other element thereafter of the original sequence, and compare that result to the first half of the original sequence. The function should return true if the extracted sequence is equal to the first half of the original sequence.\r\n\r\nFor example,\r\n\r\n* seq_original_set = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4]\r\n* seq_every_other = [0,  ,  1, , 1, , 2, , 1, , 2, , 2, , 3, ,] (extra commas are instructional and should not be in the every-other series) \r\n* seq_orig_first_half = [0, 1, 1, 2, 1, 2, 2, 3]\r\n\r\nSince seq_every_other = seq_orig_first_half, the set is self-similar.\r\n\r\nThis problem is related to \u003chttps://www.mathworks.com/matlabcentral/cody/problems/3011-self-similarity-2-every-third-term Problem 3011\u003e and \u003chttps://www.mathworks.com/matlabcentral/cody/problems/3012-self-similarity-3-every-other-pair-of-terms Problem 3012\u003e.","description_html":"\u003cp\u003eSelf-similar integer sequences are certain sequences that can be reproduced by extracting a portion of the existing sequence. See the \u003ca href = \"https://oeis.org/selfsimilar.html\"\u003eOEIS page\u003c/a\u003e for more information.\u003c/p\u003e\u003cp\u003eIn this problem, you are to check if the sequence is self-similar by every other term. The problem set assumes that you use the easiest route: take the first element and then every other element thereafter of the original sequence, and compare that result to the first half of the original sequence. The function should return true if the extracted sequence is equal to the first half of the original sequence.\u003c/p\u003e\u003cp\u003eFor example,\u003c/p\u003e\u003cul\u003e\u003cli\u003eseq_original_set = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4]\u003c/li\u003e\u003cli\u003eseq_every_other = [0,  ,  1, , 1, , 2, , 1, , 2, , 2, , 3, ,] (extra commas are instructional and should not be in the every-other series)\u003c/li\u003e\u003cli\u003eseq_orig_first_half = [0, 1, 1, 2, 1, 2, 2, 3]\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eSince seq_every_other = seq_orig_first_half, the set is self-similar.\u003c/p\u003e\u003cp\u003eThis problem is related to \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/3011-self-similarity-2-every-third-term\"\u003eProblem 3011\u003c/a\u003e and \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/3012-self-similarity-3-every-other-pair-of-terms\"\u003eProblem 3012\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = self_similarity_1(seq)\r\n\r\ntf = 0;\r\n\r\nend","test_suite":"%%\r\nseq = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 2, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 2, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 2, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 2, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 2, 1, 0, 0, 1, 0, 1, 0];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 4, 4, 0, 4, 8, 0, 0, 4, 4, 8, 0, 0, 8, 0, 0, 4, 8, 4, 0, 8, 0, 0, 0, 0, 12, 8, 0, 0, 8, 0, 0, 4, 0, 8, 0, 4, 8, 0, 0, 8, 8, 0, 0, 0, 8, 0, 0, 0, 4, 12, 0, 8, 8, 0, 0, 8, 0, 8, 0, 0, 8, 0, 0, 4, 16, 0, 0, 8, 0, 0, 0, 4, 8, 8, 0, 0, 0, 0, 0, 8, 4, 8, 0, 0, 16, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 8, 4, 0, 12, 8];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 2, 2, 1, 0, 2, 2, 1, 0, 1, 0, 2, 2, 2, 0, 1, 3, 0, 1, 2, 2, 2, 2, 1, 2, 0, 4, 1, 0, 0, 0, 2, 0, 2, 0, 2, 2, 0, 0, 1, 3, 3, 0, 0, 2, 1, 4, 2, 0, 2, 2, 2, 0, 2, 2, 1, 0, 2, 0, 0, 0, 4, 0, 1, 2, 0, 3, 0, 4, 0, 2, 2, 1, 0, 2, 2, 0, 0, 2, 2, 0, 2, 0, 0, 2, 0, 0, 1, 2, 3, 2, 3, 2];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 2, 1, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 2, 1, 1, 1, 1, 2, 2, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 2, 2, 1, 2, 1, 2, 2, 2, 2, 2, 1, 2, 1, 1, 2, 2];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 5, 2, 5, 3, 4, 2, 5, 4, 7, 3, 8, 5, 7, 2, 7, 5, 8, 3, 7, 4, 5, 1, 6, 5, 9, 4, 11, 7, 10, 3, 11, 8, 13, 5, 12, 7, 9, 2, 9, 7, 12, 5, 13, 8, 11, 3, 10, 7, 11, 4, 9, 5, 6, 1, 7, 6, 11, 5, 14, 9, 13, 4, 15, 11, 18, 7, 17, 10, 13, 3, 14, 11, 19, 8, 21, 13, 18, 5, 17, 12, 19];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 2, 4, 2, 4, 4, 8, 2, 4, 4, 8, 4, 8, 8, 16, 2, 4, 4, 8, 4, 8, 8, 16, 4, 8, 8, 16, 8, 16, 16, 32, 2, 4, 4, 8, 4, 8, 8, 16, 4, 8, 8, 16, 8, 16, 16, 32, 4, 8, 8, 16, 8, 16, 16, 32, 8, 16, 16, 32, 16, 32, 32, 64, 2, 4, 4, 8, 4, 8, 8, 16, 4, 8, 8, 16, 8, 16, 16, 32, 4, 8, 8, 16, 8, 16, 16, 32];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 6, 6, 30, 6, 30, 30, 54, 6, 102, 30, 78, 30, 78, 54, 150, 6, 102, 102, 126, 30, 270, 78, 150, 30, 150, 78, 318, 54, 174, 150, 198, 6, 390, 102, 270, 102, 222, 126, 390, 30, 246, 270, 270, 78, 510, 150, 294, 30, 390, 150, 510, 78, 318, 390, 390, 54, 630, 174, 366];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 2, 1, 2, 2, 2, 1, 4, 2, 3, 2, 3, 2, 5, 1, 4, 4, 4, 2, 7, 3, 4, 2, 5, 3, 9, 2, 5, 5, 4, 1, 11, 4, 7, 4, 6, 4, 10, 2, 7, 7, 7, 3, 13, 4, 7, 2, 9, 5, 14, 3, 8, 9, 10, 2, 16, 8, 9, 5, 9, 5, 21, 1, 11, 11, 10, 4, 17, 7, 10, 4, 11, 6, 11, 4, 16, 10, 11, 2, 23, 7, 12, 7, 14, 7, 20, 3];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 2, 0, 0, 1, 1, 0, 2, 1, 1, 1, 0, 0, 2, 1, 0, 2, 1, 0, 2, 0, 2, 1, 0, 1, 2, 0, 0, 2, 1, 1, 2, 1, 1, 1, 1, 0, 2, 0, 0, 2, 2, 1, 2, 0, 1, 2, 0, 1, 3, 0, 0, 2, 1, 0, 2, 2, 1, 1, 0, 0, 3, 1, 2, 2, 1, 0, 2, 0, 1, 2, 0, 1];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 24, 24, 96, 24, 144, 96, 192, 24, 312, 144, 288, 96, 336, 192, 576, 24, 432, 312, 480, 144, 768, 288, 576, 96, 744, 336, 960, 192, 720, 576, 768, 24, 1152, 432, 1152, 312, 912, 480, 1344, 144, 1008, 768, 1056, 288, 1872, 576, 1152, 96, 1368, 744, 1728, 336];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 2, 0, 0, 1, 1, 0, 2, 1, 1, 1, 0, 0, 2, 1, 0, 2, 1, 0, 2, 0, 2, 1, 0, 1, 2, 0, 0, 2, 1, 1, 2, 1, 1, 2, 1, 0, 2, 0, 0, 2, 2, 1, 2, 0, 1, 2, 0, 1, 3, 0, 0, 2, 1, 0, 2, 2, 1, 1, 0, 0, 3, 1, 2, 2, 1, 0, 2, 0, 1, 2, 0, 1];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 2, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 2, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 2, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 2, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 2, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 2, 1, 0, 0, 1, 0, 1, 0];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 2, 2, 1, 0, 2, 2, 1, 0, 1, 0, 1, 2, 2, 0, 1, 3, 0, 1, 2, 2, 2, 2, 1, 2, 0, 4, 1, 0, 0, 0, 2, 0, 2, 0, 2, 2, 0, 0, 1, 3, 3, 0, 0, 2, 1, 4, 2, 0, 2, 2, 2, 0, 2, 2, 1, 0, 2, 0, 0, 0, 4, 0, 1, 2, 0, 3, 0, 4, 0, 2, 2, 1, 0, 2, 2, 0, 0, 2, 2, 0, 2, 0, 0, 2, 0, 0, 1, 2, 3, 2, 3, 2];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 4, 4, 0, 4, 8, 0, 0, 4, 4, 8, 0, 0, 8, 0, 0, 4, 8, 4, 0, 8, 0, 0, 0, 0, 12, 8, 0, 0, 8, 0, 0, 4, 0, 8, 0, 4, 8, 0, 0, 8, 8, 0, 0, 0, 8, 0, 0, 0, 4, 12, 0, 8, 8, 0, 0, 0, 0, 8, 0, 0, 8, 0, 0, 4, 16, 0, 0, 8, 0, 0, 0, 4, 8, 8, 0, 0, 0, 0, 0, 8, 4, 8, 0, 0, 16, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 8, 4, 0, 12, 8];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 0, 1, -1, 0, 1, 1, -2, -1, 1, 0, 1, 1, 0, 1, -3, -2, 1, -1, 2, 1, -1, 0, 1, 1, 0, 1, -1, 0, 1, 1, -4, -3, 1, -2, 3, 1, -2, -1, 3, 2, -1, 1, -2, -1, 1, 0, 1, 1, 0, 1, -1, 0, 1, 1, -2, -1, 1, 0, 1, 1, 0, 1, -5, -4, 1, -3, 4, 1, -3, -2, 5, 3, -2, 1, -3, -2, 1, -1, 4, 3, -1, 2, -3, -1, 2, 1, -3, -2, 1, -1, 2, 1, -1, 0, 1, 1, 0, 1, -1, 0, 1, 1];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 2, 1, 3, 2, 2, 1, 4, 3, 3, 2, 3, 2, 2, 1, 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 2, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 2, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 24, 24, 96, 24, 144, 96, 192, 24, 312, 144, 288, 96, 336, 192, 576, 24, 432, 312, 480, 144, 768, 288, 576, 96, 744, 336, 960, 192, 720, 576, 768, 24, 1152, 432, 1152, 312, 912, 480, 1344, 312, 1008, 768, 1056, 288, 1872, 576, 1152, 96, 1368, 744, 1728, 336];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 2, 4, 2, 4, 4, 8, 2, 4, 4, 8, 4, 4, 8, 16, 2, 4, 4, 8, 4, 8, 8, 16, 4, 8, 8, 16, 8, 16, 16, 32, 2, 4, 4, 8, 4, 8, 8, 16, 4, 8, 8, 16, 8, 16, 16, 32, 4, 8, 16, 16, 8, 16, 16, 32, 8, 8, 16, 32, 16, 32, 32, 64, 2, 4, 4, 8, 4, 8, 8, 16, 4, 8, 8, 16, 8, 16, 16, 32, 4, 8, 8, 16, 8, 16, 16, 32];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 6, 6, 30, 6, 30, 30, 54, 6, 102, 30, 78, 30, 78, 54, 150, 6, 102, 102, 126, 30, 270, 78, 150, 30, 150, 78, 318, 54, 174, 150, 198, 6, 390, 102, 270, 102, 222, 126, 390, 30, 246, 270, 270, 78, 510, 150, 294, 30, 390, 150, 510, 78, 318, 318, 390, 54, 630, 174, 366];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 2, 1, 3, 2, 2, 1, 4, 3, 3, 2, 3, 2, 2, 1, 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, 6, 5, 5, 4, 5, 3, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 2, 1, 2, 2, 2, 1, 4, 2, 3, 2, 3, 2, 5, 1, 4, 4, 4, 2, 7, 3, 4, 2, 5, 3, 9, 2, 5, 5, 5, 1, 11, 4, 7, 4, 6, 4, 10, 2, 7, 7, 7, 3, 13, 4, 7, 2, 9, 5, 14, 3, 8, 9, 10, 2, 16, 5, 9, 5, 9, 5, 21, 1, 11, 11, 10, 4, 17, 7, 10, 4, 11, 6, 18, 4, 16, 10, 11, 2, 23, 7, 12, 7, 14, 7, 20, 3];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 2, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 2, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 2, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 2, 1, 1, 1, 1, 2, 2, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 2, 2, 1, 2, 1, 2, 2, 2, 2, 2, 1, 2, 1, 1, 2, 2];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 0, 1, -1, 0, 1, 1, -2, -1, 1, 0, 1, 1, 0, 1, -3, -2, 1, -1, 2, 1, -1, 0, 1, 1, 0, 1, -1, 0, 1, -1, -4, -3, 1, -2, 3, 1, -2, -1, 3, 2, -1, 1, -2, -1, 1, 0, 1, 1, 0, 1, -1, 0, 1, 1, -2, -1, 1, 0, 1, 1, 0, 1, -5, -4, 1, -3, 4, 1, -3, -2, 5, 3, -2, 1, -3, -2, 1, -1, 4, 3, -1, 2, -3, -1, 2, 1, -3, -2, 1, -1, 2, 1, -1, 0, 1, 1, 0, 1, -1, 0, 1, 1];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 5, 2, 5, 3, 4, 1, 5, 4, 7, 3, 8, 5, 7, 2, 7, 5, 8, 3, 7, 4, 5, 1, 6, 5, 9, 4, 11, 7, 10, 3, 11, 8, 13, 5, 12, 7, 9, 2, 9, 7, 12, 5, 13, 8, 11, 3, 10, 7, 11, 4, 9, 5, 6, 1, 7, 6, 11, 5, 14, 9, 13, 4, 15, 11, 18, 7, 17, 10, 13, 3, 14, 11, 19, 8, 21, 13, 18, 5, 17, 12, 19];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_1(seq),tf_corr))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":72,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":30,"created_at":"2015-02-13T04:04:32.000Z","updated_at":"2026-03-16T14:11:36.000Z","published_at":"2015-02-13T04:04:32.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\u003eSelf-similar integer sequences are certain sequences that can be reproduced by extracting a portion of the existing sequence. See 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://oeis.org/selfsimilar.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eOEIS page\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e for more information.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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, you are to check if the sequence is self-similar by every other term. The problem set assumes that you use the easiest route: take the first element and then every other element thereafter of the original sequence, and compare that result to the first half of the original sequence. The function should return true if the extracted sequence is equal to the first half of the original 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: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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eseq_original_set = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 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\u003eseq_every_other = [0, , 1, , 1, , 2, , 1, , 2, , 2, , 3, ,] (extra commas are instructional and should not be in the every-other series)\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\u003eseq_orig_first_half = [0, 1, 1, 2, 1, 2, 2, 3]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSince seq_every_other = seq_orig_first_half, the set is self-similar.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 related 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/3011-self-similarity-2-every-third-term\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3011\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.mathworks.com/matlabcentral/cody/problems/3012-self-similarity-3-every-other-pair-of-terms\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3012\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":3011,"title":"Self-similarity 2 - Every third term","description":"Self-similar integer sequences are certain sequences that can be reproduced by extracting a portion of the existing sequence. See the \u003chttps://oeis.org/selfsimilar.html OEIS page\u003e for more information.\r\n\r\nIn this problem, you are to check if the sequence is self-similar by every third term. The problem set assumes that you start with the first element and then take every third element thereafter of the original sequence, and compare that result to the first third of the original sequence. The function should return true if the extracted sequence is equal to the first third of the original sequence.\r\n\r\nFor example,\r\n\r\n* seq_original_set = [0, 1, 2, 1, 2, 3, 2, 3, 2, 1, 2, 3, 2, 3, 4]\r\n* seq_every_third = [0, , , 1, , , 2, , , 1, , , 2, , ,] (extra commas are instructional and should not be in the every-other series) \r\n* seq_orig_first_third = [0, 1, 2, 1, 2]\r\n\r\nSince seq_every_third = seq_orig_first_third, the set is self-similar.\r\n\r\nThis problem is related to \u003chttps://www.mathworks.com/matlabcentral/cody/problems/3010-self-similarity-1-every-other-term Problem 3010\u003e and \u003chttps://www.mathworks.com/matlabcentral/cody/problems/3012-self-similarity-3-every-other-pair-of-terms Problem 3012\u003e.","description_html":"\u003cp\u003eSelf-similar integer sequences are certain sequences that can be reproduced by extracting a portion of the existing sequence. See the \u003ca href = \"https://oeis.org/selfsimilar.html\"\u003eOEIS page\u003c/a\u003e for more information.\u003c/p\u003e\u003cp\u003eIn this problem, you are to check if the sequence is self-similar by every third term. The problem set assumes that you start with the first element and then take every third element thereafter of the original sequence, and compare that result to the first third of the original sequence. The function should return true if the extracted sequence is equal to the first third of the original sequence.\u003c/p\u003e\u003cp\u003eFor example,\u003c/p\u003e\u003cul\u003e\u003cli\u003eseq_original_set = [0, 1, 2, 1, 2, 3, 2, 3, 2, 1, 2, 3, 2, 3, 4]\u003c/li\u003e\u003cli\u003eseq_every_third = [0, , , 1, , , 2, , , 1, , , 2, , ,] (extra commas are instructional and should not be in the every-other series)\u003c/li\u003e\u003cli\u003eseq_orig_first_third = [0, 1, 2, 1, 2]\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eSince seq_every_third = seq_orig_first_third, the set is self-similar.\u003c/p\u003e\u003cp\u003eThis problem is related to \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/3010-self-similarity-1-every-other-term\"\u003eProblem 3010\u003c/a\u003e and \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/3012-self-similarity-3-every-other-pair-of-terms\"\u003eProblem 3012\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = self_similarity_2(seq)\r\n\r\ntf = 0;\r\n\r\nend\r\n","test_suite":"%%\r\nseq = [1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 2, 2, 1, 0, 2, 2, 1, 0, 1, 0, 2, 2, 2, 0, 1, 3, 0, 1, 2, 2, 2, 2, 1, 2, 0, 4, 1, 0, 0, 0, 2, 0, 2, 0, 2, 2, 0, 0, 1, 3, 3, 0, 0, 2, 1, 4, 2, 0, 2, 2, 2, 0, 2, 2, 1, 0, 2, 0, 0, 0, 4, 0, 1, 2, 0, 3, 0, 4, 0, 2, 2, 1, 0, 2, 2, 0, 0, 2, 2, 0, 2, 0, 0, 2, 0, 0, 1, 2, 3, 2, 3, 2];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 2, 1, 4, 7, 2, 5, 9, 1, 10, 19, 4, 13, 22, 7, 16, 25, 2, 11, 20, 5, 14, 23, 8, 17, 26, 1, 28, 55, 10, 37, 64, 19, 46, 73, 4, 31, 58, 13, 40, 67, 22, 49, 76, 7, 34, 61, 16, 43, 70, 25, 52, 79, 2, 29, 56, 11, 38, 65, 20, 47, 74, 5, 32, 59, 14, 41, 68, 23, 50, 77, 8, 35, 62, 17, 44, 71];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 0, 1, 0, 0, 2, 1, 1, 2, 0, 0, 1, 0, 0, 3, 2, 2, 3, 1, 1, 2, 1, 1, 3, 2, 2, 3, 0, 0, 1, 0, 0, 2, 1, 1, 2, 0, 0, 1, 0, 0, 4, 3, 3, 4, 2, 2, 3, 2, 2, 4, 3, 3, 4, 1, 1, 2, 1, 1, 3, 2, 2, 3, 1, 1, 2, 1, 1, 4, 3, 3, 4, 2, 2, 3, 2, 2, 4, 3, 3];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 2, 1, 11, 12, 2, 12, 22, 1, 11, 12, 11, 12, 112, 12, 112, 122, 2, 12, 22, 12, 112, 122, 22, 122, 222, 1, 11, 12, 11, 111, 112, 12, 112, 122, 11, 111, 112, 111, 1111, 1112, 112, 1112, 1122, 12, 112, 122, 112, 1112, 1122, 122, 1122, 1222, 2, 12, 22, 12, 112];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 2, 1, 2, 3, 2, 3, 2, 1, 2, 3, 2, 3, 4, 3, 4, 3, 2, 3, 4, 3, 4, 3, 2, 3, 2, 1, 2, 3, 2, 3, 4, 3, 4, 3, 2, 3, 4, 3, 4, 5, 4, 5, 4, 3, 4, 5, 4, 5, 4, 3, 4, 3, 2, 3, 4, 3, 4, 5, 4, 5, 4, 3, 4, 5, 4, 5, 4, 3, 4, 3, 2, 3, 4, 3, 4, 3, 2, 3, 2, 1, 2, 3, 2, 3, 4, 3, 4, 3, 2, 3, 4, 3, 4, 5, 4, 5, 4, 3, 4, 5, 4, 5, 4, 3];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 4, 1, 2, 5, 4, 5, 8, 1, 2, 5, 1, 3, 6, 5, 6, 9, 4, 5, 8, 5, 6, 9, 8, 9, 12, 1, 2, 5, 2, 3, 6, 5, 6, 9, 2, 3, 6, 3, 4, 7, 6, 7, 10, 5, 6, 9, 6, 7, 10, 9, 10, 13, 4, 5, 8, 5, 6, 9, 8, 9, 12, 5, 6, 9, 6, 7];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 0, 2, 1, 0, 0, 0, 0, 2, 1, 0, 1, 2, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 1, 2, 0, 0, 0, 0, 1, 2, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 1, 2, 0, 0, 0, 0, 1, 2, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 12, 36, 12, 84, 72, 36, 96, 180, 12, 216, 180, 84, 168, 288, 72, 372, 216, 36, 240, 504, 96, 432, 288, 180, 372, 504, 12, 672, 360, 216, 384, 756, 144, 648, 576, 84, 456, 720, 168, 1080, 504, 288, 528, 1008, 72, 864, 576, 372, 684, 1116, 216, 1176, 648, 36];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 0, 2, 2, 1, 0, 1, 0, 2, 2, 2, 0, 1, 3, 0, 1, 2, 2, 2, 2, 1, 2, 0, 4, 1, 0, 0, 0, 2, 0, 2, 0, 2, 2, 0, 0, 1, 3, 3, 0, 0, 2, 1, 4, 2, 0, 2, 2, 2, 0, 2, 2, 1, 0, 2, 0, 0, 0, 4, 0, 1, 2, 0, 3, 0, 4, 0, 2, 2, 1, 0, 2, 2, 0, 0, 2, 2, 0, 2, 0, 0, 2, 0, 0, 1, 2, 3, 2, 3, 2];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 0, 1, 0, 1, 2, 1, 1, 2, 0, 0, 1, 0, 0, 3, 2, 2, 3, 1, 1, 2, 1, 1, 3, 2, 2, 3, 0, 0, 1, 0, 0, 2, 1, 1, 2, 0, 0, 1, 0, 0, 4, 3, 3, 4, 2, 2, 3, 2, 2, 4, 3, 3, 4, 1, 1, 2, 1, 1, 3, 2, 2, 3, 1, 1, 2, 1, 1, 4, 3, 3, 4, 2, 2, 3, 2, 2, 4, 3, 3];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 3, 2, 4, 6, 3, 6, 9, 2, 4, 6, 4, 8, 12, 6, 12, 18, 3, 6, 9, 6, 12, 18, 9, 18, 27, 2, 4, 6, 4, 8, 12, 6, 12, 18, 4, 8, 12, 8, 16, 24, 12, 24, 36, 6, 12, 18, 12, 24, 36, 18, 36, 54, 3, 6, 9, 6, 12, 18, 9, 18, 27, 6, 12, 18, 12, 24, 36, 18, 36, 54, 9, 18, 27, 18, 36, 54, 27, 54];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 4, 1, 2, 5, 4, 5, 8, 1, 2, 5, 2, 3, 6, 5, 6, 9, 4, 5, 8, 5, 6, 9, 8, 9, 12, 1, 2, 5, 2, 3, 6, 5, 6, 9, 2, 3, 6, 3, 4, 7, 6, 7, 10, 5, 6, 9, 6, 7, 10, 9, 10, 13, 4, 5, 8, 5, 6, 9, 8, 9, 12, 5, 6, 9, 6, 7];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 0, 2, 1, 0, 0, 0, 0, 2, 1, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 1, 2, 0, 0, 0, 0, 1, 2, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 1, 2, 0, 0, 0, 0, 1, 2, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 12, 36, 12, 84, 72, 36, 96, 180, 12, 216, 144, 84, 168, 288, 72, 372, 216, 36, 240, 504, 96, 432, 288, 180, 372, 504, 12, 672, 360, 216, 384, 756, 144, 648, 576, 84, 456, 720, 168, 1080, 504, 288, 528, 1008, 72, 864, 576, 372, 684, 1116, 216, 1176, 648, 36];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 2, 2, 1, 3, 2, 3, 0, 1, 2, 3, 2, 3, 0, 3, 0, 1, 2, 3, 0, 3, 0, 1, 0, 1, 2, 1, 2, 3, 2, 3, 0, 3, 0, 1, 2, 3, 0, 3, 0, 1, 0, 1, 2, 3, 0, 1, 0, 1, 2, 1, 2, 3, 2, 3, 0, 3, 0, 1, 0, 1, 2, 3, 0, 1, 0, 1, 2, 1, 2, 3, 0, 1, 2, 1, 2, 3, 2, 3, 0, 1, 2, 3, 2, 3, 0, 3, 0, 1, 2, 3, 0, 3, 0, 1, 0, 1, 2, 3, 0, 1, 0, 1, 2];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 3, 2, 3, 1, 3, 1, 2, 2, 3, 1, 3, 1, 2, 1, 2, 3, 3, 1, 2, 1, 2, 3, 2, 3, 1, 2, 3, 1, 3, 1, 2, 1, 2, 3, 3, 1, 2, 1, 2, 3, 2, 3, 1, 1, 2, 3, 2, 3, 1, 3, 1, 2, 3, 1, 2, 1, 2, 3, 2, 3, 1, 1, 2, 3, 2, 3, 1, 3, 1, 2, 2, 3, 1, 3, 1, 2, 1, 2, 3, 2, 3, 1, 3, 1, 2, 1, 2, 3, 3, 1, 2, 1, 2, 3, 2, 3, 1, 1, 2, 3, 2, 3, 1];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 2, 1, 4, 7, 2, 5, 8, 1, 10, 19, 4, 13, 22, 7, 16, 25, 2, 11, 20, 5, 14, 23, 8, 17, 26, 1, 28, 55, 10, 37, 64, 19, 46, 73, 4, 31, 58, 13, 40, 67, 22, 49, 76, 7, 34, 61, 16, 43, 70, 25, 52, 79, 2, 29, 56, 11, 38, 65, 20, 47, 74, 5, 32, 59, 14, 41, 68, 23, 50, 77, 8, 35, 62, 17, 44, 71];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 2, 1, 2, 3, 2, 3, 4, 1, 3, 5, 2, 4, 6, 3, 5, 7, 2, 4, 6, 3, 5, 7, 4, 6, 8, 1, 2, 3, 3, 4, 5, 5, 6, 7, 2, 3, 4, 4, 5, 6, 6, 7, 8, 3, 4, 5, 5, 6, 7, 7, 8, 9, 2, 3, 4, 4, 5, 6, 6, 7, 8, 3, 4, 5, 5, 6, 7, 7, 8, 9, 4, 5, 6, 6, 7, 8, 8, 9, 10, 1, 3, 5, 2, 4, 6, 3, 5, 7, 3, 5, 7, 4, 6, 8, 5, 7, 9, 5, 7, 9];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 3, 2, 1, 1, 3, 1, 1, 2, 3, 2, 1, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [\t1, 2, 0, 2, 6, 0, 0, 4, 0, 2, 0, 0, 6, 4, 0, 0, 6, 0, 0, 4, 0, 4, 0, 0, 0, 2, 0, 2, 12, 0, 0, 4, 0, 0, 0, 0, 6, 4, 0, 4, 0, 0, 0, 4, 0, 0, 0, 0, 6, 6, 0, 0, 12, 0, 0, 0, 0, 4, 0, 0, 0, 4, 0, 4, 6, 0, 0, 4, 0, 0, 0, 0, 0, 4, 0, 2, 12, 0, 0, 4, 0, 2, 0, 0, 12, 0, 0, 0, 0, 0, 0, 8, 0, 4, 0, 0, 0, 4, 0, 0, 6, 0];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 3, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 0, 2, 6, 0, 0, 6, 4, 2, 4, 12, 6, 4, 8, 0, 10, 0, 0, 16, 8, 6, 4, 12, 4, 14, 8, 2, 34, 12, 4, 16, 40, 12, 12, 48, 6, 28, 8, 4, 44, 24, 8, 16, 44, 0, 12, 24, 10, 58, 16, 0, 28, 36, 0, 24, 100, 16, 16, 48, 8, 28, 16, 6, 62];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 0, 2, 6, 0, 0, 4, 0, 2, 0, 0, 6, 6, 4, 0, 10, 12, 0, 4, 8, 4, 4, 0, 0, 14, 8, 2, 12, 12, 0, 4, 8, 0, 8, 0, 6, 4, 4, 6, 8, 24, 4, 16, 8, 0, 8, 0, 10, 18, 8, 12, 34, 12, 0, 24, 44, 4, 8, 24, 8, 28, 12, 4, 46, 48, 4, 28, 36, 0, 16];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 2, 1, 4, 5, 2, 5, 8, 1, 3, 5, 4, 13, 14, 5, 14, 17, 2, 5, 8, 5, 14, 17, 8, 17, 26, 1, 4, 5, 4, 13, 14, 5, 14, 17, 4, 13, 14, 13, 40, 41, 14, 41, 44, 5, 14, 17, 14, 41, 44, 17, 44, 53, 2, 5, 8, 5, 14, 17, 8, 17, 26, 5, 14, 17, 14, 41, 44, 17, 44, 53, 8, 17, 26, 17, 44, 53, 26, 53, 80];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 4, 4, 4, 20, 24, 4, 32, 52, 4, 24, 48, 20, 56, 32, 24, 116, 72, 4, 80, 120, 32, 48, 96, 52, 124, 56, 4, 160, 120, 24, 128, 244, 48, 72, 192, 20, 152, 80, 56, 312, 168, 32, 176, 240, 24, 96, 192, 116, 228, 124, 72, 280, 216, 4, 288, 416, 80, 120, 240, 120, 248, 128, 32, 500];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 3, 2, 4, 6, 3, 6, 9, 2, 4, 6, 4, 8, 16, 6, 12, 18, 3, 6, 9, 6, 12, 18, 9, 18, 27, 2, 4, 6, 4, 8, 12, 6, 12, 18, 4, 8, 12, 8, 16, 24, 12, 24, 36, 6, 12, 18, 12, 24, 36, 18, 36, 54, 3, 6, 9, 6, 12, 18, 9, 18, 27, 6, 12, 18, 12, 24, 36, 18, 36, 54, 9, 18, 27, 18, 36, 54, 27, 54];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 2, 1, 4, 5, 2, 5, 8, 1, 4, 5, 4, 13, 14, 5, 14, 17, 2, 5, 8, 5, 14, 17, 8, 17, 26, 1, 4, 5, 4, 13, 14, 5, 14, 17, 4, 13, 14, 13, 40, 41, 14, 41, 44, 5, 14, 17, 14, 41, 44, 17, 44, 53, 2, 5, 8, 5, 14, 17, 8, 17, 26, 5, 14, 17, 14, 41, 44, 17, 44, 53, 8, 17, 26, 17, 44, 53, 26, 53, 80];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 0, 2, 6, 0, 0, 4, 0, 2, 0, 0, 6, 8, 4, 2, 10, 12, 0, 4, 8, 4, 4, 0, 0, 14, 8, 2, 12, 12, 0, 4, 8, 0, 8, 0, 6, 4, 4, 6, 8, 24, 4, 16, 8, 0, 8, 0, 10, 18, 8, 12, 34, 12, 0, 24, 44, 4, 8, 24, 8, 28, 12, 4, 46, 48, 4, 28, 36, 0, 16];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 4, 4, 4, 20, 24, 4, 32, 52, 4, 24, 48, 40, 56, 32, 64, 116, 72, 4, 80, 120, 32, 48, 96, 52, 124, 56, 4, 160, 120, 24, 128, 244, 48, 72, 192, 20, 152, 80, 56, 312, 168, 32, 176, 240, 24, 96, 192, 116, 228, 124, 72, 280, 216, 4, 288, 416, 80, 120, 240, 120, 248, 128, 32, 500];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 2, 1, 11, 12, 2, 12, 22, 1, 11, 12, 11, 111, 112, 12, 112, 122, 2, 12, 22, 12, 112, 122, 22, 122, 222, 1, 11, 12, 11, 111, 112, 12, 112, 122, 11, 111, 112, 111, 1111, 1112, 112, 1112, 1122, 12, 112, 122, 112, 1112, 1122, 122, 1122, 1222, 2, 12, 22, 12, 112];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 4, 4, 4, 4, 12, 4, 4, 4, 4, 12, 4, 4, 12, 4, 12, 4, 12, 4, 4, 12, 4, 4, 4, 4, 20, 12, 4, 4, 12, 12, 4, 4, 4, 12, 12, 4, 12, 4, 12, 12, 12, 4, 4, 4, 12, 4, 4, 4, 4, 20, 12, 12, 12, 4, 12, 4, 4, 12, 4, 12, 12, 4, 4, 4, 36, 4, 4, 12, 4, 12, 4, 4, 12, 12, 20, 4, 4, 12, 4, 12, 4, 12, 4, 4, 36];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 2, 1, 2, 3, 2, 3, 2, 1, 2, 3, 4, 3, 4, 3, 1, 3, 2, 3, 4, 3, 4, 3, 2, 3, 2, 1, 2, 3, 2, 3, 4, 3, 4, 3, 2, 3, 4, 3, 4, 5, 4, 5, 4, 3, 4, 5, 4, 5, 4, 3, 4, 3, 2, 3, 4, 3, 4, 5, 4, 5, 4, 3, 4, 5, 4, 5, 4, 3, 4, 3, 2, 3, 4, 3, 4, 3, 2, 3, 2, 1, 2, 3, 2, 3, 4, 3, 4, 3, 2, 3, 4, 3, 4, 5, 4, 5, 4, 3, 4, 5, 4, 5, 4, 3];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 3, 2, 3, 1, 3, 1, 2, 1, 3, 1, 3, 1, 2, 2, 2, 3, 3, 1, 2, 1, 2, 3, 2, 3, 1, 2, 3, 1, 3, 1, 2, 1, 2, 3, 3, 1, 2, 1, 2, 3, 2, 3, 1, 1, 2, 3, 2, 3, 1, 3, 1, 2, 3, 1, 2, 1, 2, 3, 2, 3, 1, 1, 2, 3, 2, 3, 1, 3, 1, 2, 2, 3, 1, 3, 1, 2, 1, 2, 3, 2, 3, 1, 3, 1, 2, 1, 2, 3, 3, 1, 2, 1, 2, 3, 2, 3, 1, 1, 2, 3, 2, 3, 1];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 2, 1, 2, 3, 2, 3, 4, 1, 2, 5, 2, 4, 5, 3, 5, 7, 2, 4, 6, 3, 5, 7, 4, 6, 8, 1, 2, 3, 3, 4, 5, 5, 6, 7, 2, 3, 4, 4, 5, 6, 6, 7, 8, 3, 4, 5, 5, 6, 7, 7, 8, 9, 2, 3, 4, 4, 5, 6, 6, 7, 8, 3, 4, 5, 5, 6, 7, 7, 8, 9, 4, 5, 6, 6, 7, 8, 8, 9, 10, 1, 3, 5, 2, 4, 6, 3, 5, 7, 3, 5, 7, 4, 6, 8, 5, 7, 9, 5, 7, 9];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3, 3, 6, 9, 6, 6, 3, 9, 3];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 3, 1, 1, 2, 3, 2, 2];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 4, 4, 4, 4, 12, 4, 4, 8, 4, 12, 4, 4, 12, 4, 12, 4, 12, 4, 4, 12, 4, 4, 4, 4, 20, 12, 4, 4, 12, 12, 4, 4, 4, 12, 12, 4, 12, 4, 12, 12, 12, 4, 4, 4, 12, 4, 4, 4, 4, 20, 12, 12, 12, 4, 12, 4, 4, 12, 4, 12, 12, 4, 4, 4, 36, 4, 4, 12, 4, 12, 4, 4, 12, 12, 20, 4, 4, 12, 4, 12, 4, 12, 4, 4, 36];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [\t1, 2, 0, 2, 6, 0, 1, 4, 0, 2, 0, 0, 6, 4, 1, 0, 6, 0, 0, 4, 0, 4, 0, 0, 0, 2, 0, 2, 12, 0, 0, 4, 0, 0, 0, 0, 6, 4, 0, 4, 0, 0, 0, 4, 0, 0, 0, 0, 6, 6, 0, 0, 12, 0, 0, 0, 0, 4, 0, 0, 0, 4, 0, 4, 6, 0, 0, 4, 0, 0, 0, 0, 0, 4, 0, 2, 12, 0, 0, 4, 0, 2, 0, 0, 12, 0, 0, 0, 0, 0, 0, 8, 0, 4, 0, 0, 0, 4, 0, 0, 6, 0];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 0, 2, 6, 0, 2, 6, 4, 2, 4, 12, 6, 4, 8, 2, 10, 0, 0, 16, 8, 6, 4, 12, 4, 14, 8, 2, 34, 12, 4, 16, 40, 12, 12, 48, 6, 28, 8, 4, 44, 24, 8, 16, 44, 0, 12, 24, 10, 58, 16, 0, 28, 36, 0, 24, 100, 16, 16, 48, 8, 28, 16, 6, 62];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 2, 1, 2, 3, 2, 3, 0, 1, 2, 3, 2, 3, 0, 3, 0, 1, 2, 3, 0, 3, 0, 1, 0, 1, 2, 1, 2, 3, 2, 3, 0, 3, 0, 1, 2, 3, 0, 3, 0, 1, 0, 1, 2, 3, 0, 1, 0, 1, 2, 1, 2, 3, 2, 3, 0, 3, 0, 1, 0, 1, 2, 3, 0, 1, 0, 1, 2, 1, 2, 3, 0, 1, 2, 1, 2, 3, 2, 3, 0, 1, 2, 3, 2, 3, 0, 3, 0, 1, 2, 3, 0, 3, 0, 1, 0, 1, 2, 3, 0, 1, 0, 1, 2];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_2(seq),tf_corr))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":66,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":30,"created_at":"2015-02-13T04:22:00.000Z","updated_at":"2026-03-11T15:38:45.000Z","published_at":"2015-02-13T04:22: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\u003eSelf-similar integer sequences are certain sequences that can be reproduced by extracting a portion of the existing sequence. See 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://oeis.org/selfsimilar.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eOEIS page\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e for more information.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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, you are to check if the sequence is self-similar by every third term. The problem set assumes that you start with the first element and then take every third element thereafter of the original sequence, and compare that result to the first third of the original sequence. The function should return true if the extracted sequence is equal to the first third of the original 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: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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eseq_original_set = [0, 1, 2, 1, 2, 3, 2, 3, 2, 1, 2, 3, 2, 3, 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\u003eseq_every_third = [0, , , 1, , , 2, , , 1, , , 2, , ,] (extra commas are instructional and should not be in the every-other series)\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\u003eseq_orig_first_third = [0, 1, 2, 1, 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\u003eSince seq_every_third = seq_orig_first_third, the set is self-similar.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 related 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/3010-self-similarity-1-every-other-term\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3010\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.mathworks.com/matlabcentral/cody/problems/3012-self-similarity-3-every-other-pair-of-terms\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3012\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":3012,"title":"Self-similarity 3 - Every other pair of terms","description":"Self-similar integer sequences are certain sequences that can be reproduced by extracting a portion of the existing sequence. See the \u003chttps://oeis.org/selfsimilar.html OEIS page\u003e for more information.\r\n\r\nIn this problem, you are to check if the sequence is self-similar by every other pair of terms. The problem set assumes that you start with the first element pair and then take every other element pair thereafter of the original sequence, and compare that result to the first half of the original sequence. The function should return true if the extracted sequence is equal to the first half of the original sequence.\r\n\r\nFor example,\r\n\r\n* seq_original_set = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3]\r\n* seq_every_other_pair = [0, 1, , , 1, 2, , , 1, 2, , , 2, 3, , , 1, 2, , ] (extra commas are instructional and should not be in the every-other series) \r\n* seq_orig_first_half = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2]\r\n\r\nSince seq_every_other_pair = seq_orig_first_half, the set is self-similar.\r\n\r\nThis problem is related to \u003chttps://www.mathworks.com/matlabcentral/cody/problems/3010-self-similarity-1-every-other-term Problem 3010\u003e and \u003chttps://www.mathworks.com/matlabcentral/cody/problems/3011-self-similarity-2-every-third-term Problem 3011\u003e.","description_html":"\u003cp\u003eSelf-similar integer sequences are certain sequences that can be reproduced by extracting a portion of the existing sequence. See the \u003ca href = \"https://oeis.org/selfsimilar.html\"\u003eOEIS page\u003c/a\u003e for more information.\u003c/p\u003e\u003cp\u003eIn this problem, you are to check if the sequence is self-similar by every other pair of terms. The problem set assumes that you start with the first element pair and then take every other element pair thereafter of the original sequence, and compare that result to the first half of the original sequence. The function should return true if the extracted sequence is equal to the first half of the original sequence.\u003c/p\u003e\u003cp\u003eFor example,\u003c/p\u003e\u003cul\u003e\u003cli\u003eseq_original_set = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3]\u003c/li\u003e\u003cli\u003eseq_every_other_pair = [0, 1, , , 1, 2, , , 1, 2, , , 2, 3, , , 1, 2, , ] (extra commas are instructional and should not be in the every-other series)\u003c/li\u003e\u003cli\u003eseq_orig_first_half = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2]\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eSince seq_every_other_pair = seq_orig_first_half, the set is self-similar.\u003c/p\u003e\u003cp\u003eThis problem is related to \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/3010-self-similarity-1-every-other-term\"\u003eProblem 3010\u003c/a\u003e and \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/3011-self-similarity-2-every-third-term\"\u003eProblem 3011\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = self_similarity_3(seq)\r\n\r\ntf = 0;\r\n\r\nend\r\n","test_suite":"%%\r\nseq = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 3, 1, 3, 3, 7, 1, 3, 3, 7, 3, 3, 7, 15, 1, 3, 3, 7, 3, 7, 7, 15, 3, 7, 7, 15, 7, 15, 15, 31, 1, 7, 3, 7, 3, 7, 7, 15, 3, 7, 7, 15, 7, 15, 15, 31, 3, 7, 7, 15, 7, 15, 15, 31, 7, 15, 15, 31, 15, 31, 31, 63, 1, 3, 3, 7, 3, 7, 7, 15, 3, 7, 7, 15, 7, 15, 15, 31, 3, 7, 7, 15, 7, 15, 15, 31];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 2, 4, 2, 4, 4, 8, 2, 4, 4, 8, 4, 8, 8, 16, 2, 4, 2, 8, 4, 8, 8, 16, 4, 8, 8, 16, 8, 16, 16, 32, 2, 4, 4, 8, 4, 8, 8, 16, 4, 8, 8, 16, 8, 16, 16, 32, 4, 8, 8, 16, 8, 16, 16, 32, 8, 16, 16, 32, 16, 32, 32, 64, 2, 4, 4, 8, 4, 8, 8, 16, 4, 8, 8, 16, 8, 16, 16, 32, 4, 8, 8, 16, 8, 16, 16, 32];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 2, 4, 2, 4, 4, 8, 2, 4, 4, 8, 4, 8, 8, 16, 2, 4, 4, 8, 4, 8, 8, 16, 4, 8, 8, 16, 8, 16, 16, 32, 2, 4, 4, 8, 4, 8, 8, 16, 4, 8, 8, 16, 8, 16, 16, 32, 4, 8, 8, 16, 8, 16, 16, 32, 8, 16, 16, 32, 16, 32, 32, 64, 2, 4, 4, 8, 4, 8, 8, 16, 4, 8, 8, 16, 8, 16, 16, 32, 4, 8, 8, 16, 8, 16, 16, 32];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 2, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 2, 1, 2, 2, 5, 1, 2, 2, 5, 2, 5, 5, 15, 1, 2, 2, 5, 2, 5, 5, 15, 2, 2, 5, 15, 5, 15, 15, 52, 1, 2, 2, 5, 2, 5, 5, 15, 2, 5, 5, 15, 5, 15, 15, 52, 2, 5, 5, 15, 5, 15, 15, 52, 5, 15, 15, 52, 15, 52, 52, 203, 1, 2, 2, 5, 2, 5, 5, 15, 2, 5, 5, 15, 5, 15, 15, 52, 2, 5, 5, 15, 5, 15];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 2, 2, 1, 2, 2, 2, 1, 2, 1, 1, 2, 1, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 2, 1, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 2, 1, 2, 2];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 3, 4, 4, 2, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 3, 1, 3, 3, 7, 1, 3, 3, 7, 3, 7, 7, 15, 1, 3, 3, 7, 3, 7, 7, 15, 3, 7, 7, 15, 7, 15, 15, 31, 1, 3, 3, 7, 3, 7, 7, 15, 3, 7, 7, 15, 7, 15, 15, 31, 3, 7, 7, 15, 7, 15, 15, 31, 7, 15, 15, 31, 15, 31, 31, 63, 1, 3, 3, 7, 3, 7, 7, 15, 3, 7, 7, 15, 7, 15, 15, 31, 3, 7, 7, 15, 7, 15, 15, 31];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 3, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 2, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 2, 1, 2, 2, 5, 1, 2, 2, 5, 2, 5, 5, 15, 1, 2, 2, 5, 2, 5, 5, 15, 2, 5, 5, 15, 5, 15, 15, 52, 1, 2, 2, 5, 2, 5, 5, 15, 2, 5, 5, 15, 5, 15, 15, 52, 2, 5, 5, 15, 5, 15, 15, 52, 5, 15, 15, 52, 15, 52, 52, 203, 1, 2, 2, 5, 2, 5, 5, 15, 2, 5, 5, 15, 5, 15, 15, 52, 2, 5, 5, 15, 5, 15];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 1, 1, 2, 1, 2, 2, 5, 1, 2, 2, 5, 2, 2, 5, 15, 1, 2, 2, 5, 2, 5, 5, 15, 2, 2, 5, 15, 5, 15, 15, 52, 1, 2, 5, 5, 2, 5, 5, 15, 2, 5, 5, 15, 5, 15, 15, 52, 2, 5, 5, 15, 5, 15, 15, 52, 5, 15, 15, 52, 15, 52, 52, 203, 1, 2, 2, 5, 2, 5, 5, 15, 2, 5, 5, 15, 5, 15, 15, 52, 2, 5, 5, 15, 5, 15];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 2, 2, 1, 1, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 1, 2, 1, 2, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 2, 1, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 2, 1, 2, 2];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 2, 2, 1, 1, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 2, 1, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 2, 1, 2, 2];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 2, 4, 2, 4, 4, 8, 2, 2, 4, 8, 4, 8, 8, 16, 2, 4, 4, 8, 4, 8, 8, 16, 4, 8, 8, 16, 8, 16, 16, 32, 2, 4, 4, 8, 4, 8, 8, 16, 4, 8, 8, 16, 8, 16, 16, 32, 4, 8, 8, 16, 8, 16, 16, 32, 8, 16, 16, 32, 16, 32, 32, 64, 2, 4, 4, 8, 4, 8, 8, 16, 4, 8, 8, 16, 8, 16, 16, 32, 4, 8, 8, 16, 8, 16, 16, 32];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4];\r\ntf_corr = 1;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n\r\n%%\r\nseq = [0, 1, 1, 3, 1, 3, 3, 7, 1, 3, 3, 7, 3, 7, 7, 15, 1, 3, 3, 7, 3, 7, 7, 15, 3, 7, 15, 7, 7, 15, 15, 31, 1, 3, 3, 7, 3, 7, 7, 15, 3, 7, 7, 15, 7, 15, 15, 31, 3, 7, 7, 15, 7, 15, 15, 31, 7, 15, 15, 31, 15, 31, 31, 63, 1, 3, 3, 7, 3, 7, 7, 15, 3, 7, 7, 15, 7, 15, 15, 31, 3, 7, 7, 15, 7, 15, 15, 31];\r\ntf_corr = 0;\r\nassert(isequal(self_similarity_3(seq),tf_corr))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":58,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":30,"created_at":"2015-02-13T04:36:07.000Z","updated_at":"2026-03-16T14:22:23.000Z","published_at":"2015-02-13T04:36: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\u003eSelf-similar integer sequences are certain sequences that can be reproduced by extracting a portion of the existing sequence. See 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://oeis.org/selfsimilar.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eOEIS page\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e for more information.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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, you are to check if the sequence is self-similar by every other pair of terms. The problem set assumes that you start with the first element pair and then take every other element pair thereafter of the original sequence, and compare that result to the first half of the original sequence. The function should return true if the extracted sequence is equal to the first half of the original 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: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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eseq_original_set = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 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\u003eseq_every_other_pair = [0, 1, , , 1, 2, , , 1, 2, , , 2, 3, , , 1, 2, , ] (extra commas are instructional and should not be in the every-other series)\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\u003eseq_orig_first_half = [0, 1, 1, 2, 1, 2, 2, 3, 1, 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\u003eSince seq_every_other_pair = seq_orig_first_half, the set is self-similar.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 related 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/3010-self-similarity-1-every-other-term\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3010\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.mathworks.com/matlabcentral/cody/problems/3011-self-similarity-2-every-third-term\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3011\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":3016,"title":"Twin Primes","description":"Twin primes are pairs of primes that are immediately next to each other (difference of two). The lesser of twin primes are 3, 5, 11, 17, 29, ... ( \u003chttp://oeis.org/A001359 ref.\u003e ). The greater of twin primes are 5, 7, 13, 19, 31, ... ( \u003chttp://oeis.org/A006512 ref.\u003e ). Therefore, the first five twin primes are [3,5] [5,7] [11,13] [17,19] [29,31].\r\n\r\nFor a given index range n, return the twin primes corresponding to that range as a two-row column array.","description_html":"\u003cp\u003eTwin primes are pairs of primes that are immediately next to each other (difference of two). The lesser of twin primes are 3, 5, 11, 17, 29, ... ( \u003ca href = \"http://oeis.org/A001359\"\u003eref.\u003c/a\u003e ). The greater of twin primes are 5, 7, 13, 19, 31, ... ( \u003ca href = \"http://oeis.org/A006512\"\u003eref.\u003c/a\u003e ). Therefore, the first five twin primes are [3,5] [5,7] [11,13] [17,19] [29,31].\u003c/p\u003e\u003cp\u003eFor a given index range n, return the twin primes corresponding to that range as a two-row column array.\u003c/p\u003e","function_template":"function [twins] = twin_primes(n)\r\n\r\ntwins = n;\r\n\r\nend","test_suite":"%%\r\nn = 1:5;\r\ntwins_corr = [3, 5, 11, 17, 29; 5, 7, 13, 19, 31];\r\nassert(isequal(twin_primes(n),twins_corr))\r\n\r\n%%\r\nn = 1:10;\r\ntwins_corr = [3, 5, 11, 17, 29, 41, 59, 71, 101, 107; 5, 7, 13, 19, 31, 43, 61, 73, 103, 109];\r\nassert(isequal(twin_primes(n),twins_corr))\r\n\r\n%%\r\nn = 1:25;\r\ntwins_corr = [3, 5, 11, 17, 29, 41, 59, 71, 101, 107, 137, 149, 179, 191, 197, 227, 239, 269, 281, 311, 347, 419, 431, 461, 521; 5, 7, 13, 19, 31, 43, 61, 73, 103, 109, 139, 151, 181, 193, 199, 229, 241, 271, 283, 313, 349, 421, 433, 463, 523];\r\nassert(isequal(twin_primes(n),twins_corr))\r\n\r\n%%\r\nn = 1:51;\r\ntwins_corr = [3, 5, 11, 17, 29, 41, 59, 71, 101, 107, 137, 149, 179, 191, 197, 227, 239, 269, 281, 311, 347, 419, 431, 461, 521, 569, 599, 617, 641, 659, 809, 821, 827, 857, 881, 1019, 1031, 1049, 1061, 1091, 1151, 1229, 1277, 1289, 1301, 1319, 1427, 1451, 1481, 1487, 1607; 5, 7, 13, 19, 31, 43, 61, 73, 103, 109, 139, 151, 181, 193, 199, 229, 241, 271, 283, 313, 349, 421, 433, 463, 523, 571, 601, 619, 643, 661, 811, 823, 829, 859, 883, 1021, 1033, 1051, 1063, 1093, 1153, 1231, 1279, 1291, 1303, 1321, 1429, 1453, 1483, 1489, 1609];\r\nassert(isequal(twin_primes(n),twins_corr))\r\n\r\n%%\r\nn = 10:29;\r\ntwins_corr = [107, 137, 149, 179, 191, 197, 227, 239, 269, 281, 311, 347, 419, 431, 461, 521, 569, 599, 617, 641; 109, 139, 151, 181, 193, 199, 229, 241, 271, 283, 313, 349, 421, 433, 463, 523, 571, 601, 619, 643];\r\nassert(isequal(twin_primes(n),twins_corr))\r\n\r\n%%\r\nn = 2:8;\r\ntwins_corr = [5, 11, 17, 29, 41, 59, 71; 7, 13, 19, 31, 43, 61, 73];\r\nassert(isequal(twin_primes(n),twins_corr))\r\n\r\n%%\r\nn = 35:42;\r\ntwins_corr = [881, 1019, 1031, 1049, 1061, 1091, 1151, 1229; 883, 1021, 1033, 1051, 1063, 1093, 1153, 1231];\r\nassert(isequal(twin_primes(n),twins_corr))\r\n\r\n%%\r\nn = 34:47;\r\ntwins_corr = [857, 881, 1019, 1031, 1049, 1061, 1091, 1151, 1229, 1277, 1289, 1301, 1319, 1427; 859, 883, 1021, 1033, 1051, 1063, 1093, 1153, 1231, 1279, 1291, 1303, 1321, 1429];\r\nassert(isequal(twin_primes(n),twins_corr))\r\n\r\n%%\r\nn = 9:-1:4;\r\ntwins_corr = [101, 71, 59, 41, 29, 17; 103, 73, 61, 43, 31, 19];\r\nassert(isequal(twin_primes(n),twins_corr))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":98,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":30,"created_at":"2015-02-14T03:03:50.000Z","updated_at":"2026-03-16T14:18:09.000Z","published_at":"2015-02-14T03:03:50.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\u003eTwin primes are pairs of primes that are immediately next to each other (difference of two). The lesser of twin primes are 3, 5, 11, 17, 29, ... (\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/A001359\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eref.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e ). The greater of twin primes are 5, 7, 13, 19, 31, ... (\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/A006512\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eref.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e ). Therefore, the first five twin primes are [3,5] [5,7] [11,13] [17,19] [29,31].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 a given index range n, return the twin primes corresponding to that range as a two-row column 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":3068,"title":"Pattern Recognition 1 - Known Unit Length","description":"You will be given various arrays, composed of numbers or strings. For this problem, the known pattern unit length is three. Write a function to determine if the supplied array is a strict repeating pattern. The array will have a length that is a multiple of three.\r\n\r\nFor example, [1 2 3 1 2 3 1 2 3] would return true since the first block ([1 2 3]) is strictly repeated through the remainder of the array. On the other hand, [1 2 3 1 2 3 2 2 3] would return false, since the last block is [2 2 3] rather than [1 2 3], as indicated by the first block.\r\n\r\nThis problem is a precursor to \u003chttps://www.mathworks.com/matlabcentral/cody/problems/3069-pattern-recognition-2-known-unit-length-various-array-length-including-cell-arrays Problem 3069\u003e and \u003chttps://www.mathworks.com/matlabcentral/cody/problems/3070-pattern-recognition-3-variable-unit-and-array-length-including-cell-arrays Problem 3070\u003e.","description_html":"\u003cp\u003eYou will be given various arrays, composed of numbers or strings. For this problem, the known pattern unit length is three. Write a function to determine if the supplied array is a strict repeating pattern. The array will have a length that is a multiple of three.\u003c/p\u003e\u003cp\u003eFor example, [1 2 3 1 2 3 1 2 3] would return true since the first block ([1 2 3]) is strictly repeated through the remainder of the array. On the other hand, [1 2 3 1 2 3 2 2 3] would return false, since the last block is [2 2 3] rather than [1 2 3], as indicated by the first block.\u003c/p\u003e\u003cp\u003eThis problem is a precursor to \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/3069-pattern-recognition-2-known-unit-length-various-array-length-including-cell-arrays\"\u003eProblem 3069\u003c/a\u003e and \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/3070-pattern-recognition-3-variable-unit-and-array-length-including-cell-arrays\"\u003eProblem 3070\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = pattern_recognition1(array)\r\n\r\ntf = 0;\r\n\r\nend\r\n","test_suite":"%%\r\narray = [1 2 3 1 2 3 1 2 3];\r\ntf = 1;\r\nassert(isequal(pattern_recognition1(array),tf))\r\n\r\n%%\r\narray = [1 2 2 1 2 2];\r\ntf = 1;\r\nassert(isequal(pattern_recognition1(array),tf))\r\n\r\n%%\r\narray = [1 10 100 1 10 100 1 10 100 1 10 100];\r\ntf = 1;\r\nassert(isequal(pattern_recognition1(array),tf))\r\n\r\n%%\r\narray = 'abcabcadcabcabc';\r\ntf = 0;\r\nassert(isequal(pattern_recognition1(array),tf))\r\n\r\n%%\r\narray = [1 2 3 1 2 3 2 2 3];\r\ntf = 0;\r\nassert(isequal(pattern_recognition1(array),tf))\r\n\r\n%%\r\narray = 'hi hi hi ';\r\ntf = 1;\r\nassert(isequal(pattern_recognition1(array),tf))\r\n\r\n%%\r\narray = [1 2 2 1 2 1];\r\ntf = 0;\r\nassert(isequal(pattern_recognition1(array),tf))\r\n\r\n%%\r\narray = 'abcabcabcabcabc';\r\ntf = 1;\r\nassert(isequal(pattern_recognition1(array),tf))\r\n\r\n%%\r\narray = 'hi ho hi ';\r\ntf = 0;\r\nassert(isequal(pattern_recognition1(array),tf))\r\n\r\n%%\r\narray = [1 10 100 1 10 100 1 10 10 1 10 100];\r\ntf = 0;\r\nassert(isequal(pattern_recognition1(array),tf))\r\n\r\n%%\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tarray = 'abcabcabcabcabc';\r\n\t\ttf = 1;\r\n\tcase 2\r\n\t\tarray = [1 10 100 1 10 100 1 10 10 1 10 100];\r\n\t\ttf = 0;\r\n\tcase 3\r\n\t\tarray = [1 2 2 1 2 2];\r\n\t\ttf = 1;\r\n\tcase 4\r\n\t\tarray = 'hi ho hi ';\r\n\t\ttf = 0;\r\nend\r\nassert(isequal(pattern_recognition1(array),tf))\r\n\r\n%%\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tarray = [1 2 3 1 2 3 2 2 3];\r\n\t\ttf = 0;\r\n\tcase 2\r\n\t\tarray = [1 10 100 1 10 100 1 10 100 1 10 100];\r\n\t\ttf = 1;\r\n\tcase 3\r\n\t\tarray = [1 2 3 1 2 3 2 2 3];\r\n\t\ttf = 0;\r\n\tcase 4\r\n\t\tarray = [1 2 2 1 2 2];\r\n\t\ttf = 1;\r\nend\r\nassert(isequal(pattern_recognition1(array),tf))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":74,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":30,"created_at":"2015-03-08T03:19:11.000Z","updated_at":"2026-03-16T14:08:57.000Z","published_at":"2015-03-08T03:19:11.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou will be given various arrays, composed of numbers or strings. For this problem, the known pattern unit length is three. Write a function to determine if the supplied array is a strict repeating pattern. The array will have a length that is a multiple of three.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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, [1 2 3 1 2 3 1 2 3] would return true since the first block ([1 2 3]) is strictly repeated through the remainder of the array. On the other hand, [1 2 3 1 2 3 2 2 3] would return false, since the last block is [2 2 3] rather than [1 2 3], as indicated by the first block.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 a precursor 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/3069-pattern-recognition-2-known-unit-length-various-array-length-including-cell-arrays\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3069\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.mathworks.com/matlabcentral/cody/problems/3070-pattern-recognition-3-variable-unit-and-array-length-including-cell-arrays\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3070\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":3069,"title":"Pattern Recognition 2 - Known Unit Length, Various Array Length (including cell arrays)","description":"You will be given various arrays, composed of numbers or strings, including cell arrays of strings. For this problem, the known pattern unit length is three. Write a function to determine if the supplied array is a strict repeating pattern. The array will not necessarily have a length that is a multiple of three.\r\n\r\nFor example, [1 2 3 1 2 3 1 2 3 1] would return true since the first block ([1 2 3]) is strictly repeated through the remainder of the array (including the last 1). On the other hand, [1 2 3 3 2 3 1 2 3] would return false, since the second block is [3 2 3] rather than [1 2 3], as indicated by the first block.\r\n\r\nThis problem is a follow-on to \u003chttps://www.mathworks.com/matlabcentral/cody/problems/3068-pattern-recognition-1-known-unit-length Problem 3068\u003e and a precursor to \u003chttps://www.mathworks.com/matlabcentral/cody/problems/3070-pattern-recognition-3-variable-unit-and-array-length-including-cell-arrays Problem 3070\u003e.","description_html":"\u003cp\u003eYou will be given various arrays, composed of numbers or strings, including cell arrays of strings. For this problem, the known pattern unit length is three. Write a function to determine if the supplied array is a strict repeating pattern. The array will not necessarily have a length that is a multiple of three.\u003c/p\u003e\u003cp\u003eFor example, [1 2 3 1 2 3 1 2 3 1] would return true since the first block ([1 2 3]) is strictly repeated through the remainder of the array (including the last 1). On the other hand, [1 2 3 3 2 3 1 2 3] would return false, since the second block is [3 2 3] rather than [1 2 3], as indicated by the first block.\u003c/p\u003e\u003cp\u003eThis problem is a follow-on to \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/3068-pattern-recognition-1-known-unit-length\"\u003eProblem 3068\u003c/a\u003e and a precursor to \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/3070-pattern-recognition-3-variable-unit-and-array-length-including-cell-arrays\"\u003eProblem 3070\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = pattern_recognition2(array)\r\n\r\ntf = 0;\r\n\r\nend\r\n","test_suite":"%%\r\narray = [1 2 3 1 2 3 1 2 3];\r\ntf = 1;\r\nassert(isequal(pattern_recognition2(array),tf))\r\n\r\n%%\r\narray = [1 2 2 1 2 2 1];\r\ntf = 1;\r\nassert(isequal(pattern_recognition2(array),tf))\r\n\r\n%%\r\narray = [1 2 1 2 2 2 1];\r\ntf = 0;\r\nassert(isequal(pattern_recognition2(array),tf))\r\n\r\n%%\r\narray = [1 10 100 1 10 100 1 10 100 1 10 100 1 10];\r\ntf = 1;\r\nassert(isequal(pattern_recognition2(array),tf))\r\n\r\n%%\r\narray = {'c3po','r2','d2','c3po','d2','r2','c3po','r2','d2','c3po'};\r\ntf = 0;\r\nassert(isequal(pattern_recognition2(array),tf))\r\n\r\n%%\r\narray = 'hi hi hi hi';\r\ntf = 1;\r\nassert(isequal(pattern_recognition2(array),tf))\r\n\r\n%%\r\narray = 'abcabcabcabcabcabcab';\r\ntf = 1;\r\nassert(isequal(pattern_recognition2(array),tf))\r\n\r\n%%\r\narray = {'c3po','r2','d2','c3po','r2','d2','c3po','r2','d2','c3po','r2'};\r\ntf = 1;\r\nassert(isequal(pattern_recognition2(array),tf))\r\n\r\n%%\r\narray = [1 2 3 3 2 3 1 2 3];\r\ntf = 0;\r\nassert(isequal(pattern_recognition2(array),tf))\r\n\r\n%%\r\narray = {'ab','cde','fg','ab','cbe','fg','ab','edc','fg'};\r\ntf = 0;\r\nassert(isequal(pattern_recognition2(array),tf))\r\n\r\n%%\r\narray = 'abcabcabcabcabcabea';\r\ntf = 0;\r\nassert(isequal(pattern_recognition2(array),tf))\r\n\r\n%%\r\narray = [1 10 100 1 100 10 1 10 100 1 10 100];\r\ntf = 0;\r\nassert(isequal(pattern_recognition2(array),tf))\r\n\r\n%%\r\narray = 'hi hi him';\r\ntf = 0;\r\nassert(isequal(pattern_recognition2(array),tf))\r\n\r\n%%\r\narray = {'ab','cde','fg','ab','cde','fg','ab','cde','fg'};\r\ntf = 1;\r\nassert(isequal(pattern_recognition2(array),tf))\r\n\r\n%%\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tarray = {'c3po','r2','d2','c3po','r2','d2','c3po','r2','d2','c3po'};\r\n\t\ttf = 1;\r\n\tcase 2\r\n\t\tarray = 'hi hi him';\r\n\t\ttf = 0;\r\n\tcase 3\r\n\t\tarray = [1 2 3 3 2 3 1 2 3];\r\n\t\ttf = 0;\r\n\tcase 4\r\n\t\tarray = [1 2 2 1 2 2 1];\r\n\t\ttf = 1;\r\nend\r\nassert(isequal(pattern_recognition2(array),tf))\r\n\r\n%%\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tarray = [1 2 3 3 2 3 1 2 3 1 2];\r\n\t\ttf = 0;\r\n\tcase 2\r\n\t\tarray = [1 10 100 1 100 10 1 10 100 1 10 100 1];\r\n\t\ttf = 0;\r\n\tcase 3\r\n\t\tarray = [1 2 2 1 2 2 1];\r\n\t\ttf = 1;\r\n\tcase 4\r\n\t\tarray = {'ab','cde','fg','ab','cde','fg','ab','cde','fg'};\r\n\t\ttf = 1;\r\nend\r\nassert(isequal(pattern_recognition2(array),tf))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":56,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":30,"created_at":"2015-03-08T03:28:05.000Z","updated_at":"2026-03-16T14:24:23.000Z","published_at":"2015-03-08T03:28: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\u003eYou will be given various arrays, composed of numbers or strings, including cell arrays of strings. For this problem, the known pattern unit length is three. Write a function to determine if the supplied array is a strict repeating pattern. The array will not necessarily have a length that is a multiple of three.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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, [1 2 3 1 2 3 1 2 3 1] would return true since the first block ([1 2 3]) is strictly repeated through the remainder of the array (including the last 1). On the other hand, [1 2 3 3 2 3 1 2 3] would return false, since the second block is [3 2 3] rather than [1 2 3], as indicated by the first block.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 a follow-on 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/3068-pattern-recognition-1-known-unit-length\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3068\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and a precursor 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/3070-pattern-recognition-3-variable-unit-and-array-length-including-cell-arrays\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3070\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":3070,"title":"Pattern Recognition 3 - Variable Unit and Array Length (including cell arrays)","description":"You will be given various arrays, composed of numbers or strings, including cell arrays of strings. For this problem, the pattern unit length is variable, ranging from three to half the array length (the unit will be completely repeated at least once). Write a function to determine if the supplied array is a strict repeating pattern. The array will not necessarily have a length that is a multiple of the unit length.\r\n\r\nFor example, [1 2 3 4 5 1 2 3 4 5 1 2 3] would return true since the first block (1:5) is strictly repeated through the remainder of the array (including the last [1 2 3]). On the other hand, 'abcabcabcabcabcabea' would return false, since the last complete block is 'abe' rather than 'abc', as indicated by the first block.\r\n\r\nThis problem is a follow-on to \u003chttps://www.mathworks.com/matlabcentral/cody/problems/3068-pattern-recognition-1-known-unit-length Problem 3068\u003e and \u003chttps://www.mathworks.com/matlabcentral/cody/problems/3069-pattern-recognition-2-known-unit-length-various-array-length-including-cell-arrays Problem 3069\u003e.","description_html":"\u003cp\u003eYou will be given various arrays, composed of numbers or strings, including cell arrays of strings. For this problem, the pattern unit length is variable, ranging from three to half the array length (the unit will be completely repeated at least once). Write a function to determine if the supplied array is a strict repeating pattern. The array will not necessarily have a length that is a multiple of the unit length.\u003c/p\u003e\u003cp\u003eFor example, [1 2 3 4 5 1 2 3 4 5 1 2 3] would return true since the first block (1:5) is strictly repeated through the remainder of the array (including the last [1 2 3]). On the other hand, 'abcabcabcabcabcabea' would return false, since the last complete block is 'abe' rather than 'abc', as indicated by the first block.\u003c/p\u003e\u003cp\u003eThis problem is a follow-on to \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/3068-pattern-recognition-1-known-unit-length\"\u003eProblem 3068\u003c/a\u003e and \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/3069-pattern-recognition-2-known-unit-length-various-array-length-including-cell-arrays\"\u003eProblem 3069\u003c/a\u003e.\u003c/p\u003e","function_template":"function [tf] = pattern_recognition3(array)\r\n\r\ntf = 0;\r\n\r\nend\r\n","test_suite":"%%\r\narray = [1 2 3 4 5 1 2 3 4 5 1 2 3];\r\ntf = 1;\r\nassert(isequal(pattern_recognition3(array),tf))\r\n\r\n%%\r\narray = [1 2 2 1 2 1 2 2 1 2 1 2];\r\ntf = 1;\r\nassert(isequal(pattern_recognition3(array),tf))\r\n\r\n%%\r\narray = [1 2 1 2 2 2 1 2];\r\ntf = 0;\r\nassert(isequal(pattern_recognition3(array),tf))\r\n\r\n%%\r\narray = [0.1 1 10 100 1000 10000];\r\narray = repmat(array,[1,5]);\r\ntf = 1;\r\nassert(isequal(pattern_recognition3(array),tf))\r\n\r\n%%\r\narray = {'c3po','r2','d2','c3po','d2','r2','c3po','r2','d2','c3po'};\r\ntf = 0;\r\nassert(isequal(pattern_recognition3(array),tf))\r\n\r\n%%\r\narray = 'hi ho hi ho hi ho hi';\r\ntf = 1;\r\nassert(isequal(pattern_recognition3(array),tf))\r\n\r\n%%\r\narray = 'a':'z';\r\narray = repmat(array,[1,5]);\r\ntf = 1;\r\nassert(isequal(pattern_recognition3(array),tf))\r\n\r\n%%\r\narray = {'c3','po','r2','d2','c3','po','r2','d2','c3','po','r2','d2','c3','po','r2'};\r\ntf = 1;\r\nassert(isequal(pattern_recognition3(array),tf))\r\n\r\n%%\r\narray = [1 2 3 3 2 3 1 2 3 1];\r\ntf = 0;\r\nassert(isequal(pattern_recognition3(array),tf))\r\n\r\n%%\r\narray = {'ab','cde','fg','ab','cbe','fg','ab','edc','fg'};\r\ntf = 0;\r\nassert(isequal(pattern_recognition3(array),tf))\r\n\r\n%%\r\narray = 'abcabcabcabcabcabea';\r\ntf = 0;\r\nassert(isequal(pattern_recognition3(array),tf))\r\n\r\n%%\r\narray = [1 10 100 1 100 10 1 10 100 1 10 100];\r\ntf = 0;\r\nassert(isequal(pattern_recognition3(array),tf))\r\n\r\n%%\r\narray = 'hi hi him';\r\ntf = 0;\r\nassert(isequal(pattern_recognition3(array),tf))\r\n\r\n%%\r\narray = {'ab','cde','fg','ab','cde','fg','ab','cde','fg'};\r\ntf = 1;\r\nassert(isequal(pattern_recognition3(array),tf))\r\n\r\n%%\r\narray = [ones(1,40) zeros(1,20) ones(1,40) zeros(1,20) ones(1,40)];\r\ntf = 1;\r\nassert(isequal(pattern_recognition3(array),tf))\r\n\r\n%%\r\narray = [-1:9 -1:4 -1:2 -1:9 -1:4 -1:2 -1:9 -1:4 -1:2 -1:9];\r\ntf = 1;\r\nassert(isequal(pattern_recognition3(array),tf))\r\n\r\n%%\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tarray = {'c3po','r2','d2','c3po','r2','d2','c3po','r2','d2','c3po'};\r\n\t\ttf = 1;\r\n\tcase 2\r\n\t\tarray = 'hi hi him';\r\n\t\ttf = 0;\r\n\tcase 3\r\n\t\tarray = [1 2 3 3 1 2 3 1 2 3];\r\n\t\ttf = 0;\r\n\tcase 4\r\n\t\tarray = [1 2 2 4 1 2 2 4 1];\r\n\t\ttf = 1;\r\nend\r\nassert(isequal(pattern_recognition3(array),tf))\r\n\r\n%%\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tarray = [1 2 3 3 2 3 1 2 3 1 2];\r\n\t\ttf = 0;\r\n\tcase 2\r\n\t\tarray = [1 10 100 1 10 1 10 100 1 10 100 1];\r\n\t\ttf = 0;\r\n\tcase 3\r\n\t\tarray = [1 2 2 4 5 1 2 2 4 5 1];\r\n\t\ttf = 1;\r\n\tcase 4\r\n\t\tarray = {'ab','cde','ab','cde','fg','ab','cde','ab','cde','fg','ab','cde','ab','cde','fg'};\r\n\t\ttf = 1;\r\nend\r\nassert(isequal(pattern_recognition3(array),tf))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":3,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":58,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":30,"created_at":"2015-03-08T03:41:45.000Z","updated_at":"2026-03-16T14:26:39.000Z","published_at":"2015-03-08T03:41:45.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 various arrays, composed of numbers or strings, including cell arrays of strings. For this problem, the pattern unit length is variable, ranging from three to half the array length (the unit will be completely repeated at least once). Write a function to determine if the supplied array is a strict repeating pattern. The array will not necessarily have a length that is a multiple of the unit length.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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, [1 2 3 4 5 1 2 3 4 5 1 2 3] would return true since the first block (1:5) is strictly repeated through the remainder of the array (including the last [1 2 3]). On the other hand, 'abcabcabcabcabcabea' would return false, since the last complete block is 'abe' rather than 'abc', as indicated by the first block.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 a follow-on 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/3068-pattern-recognition-1-known-unit-length\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3068\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.mathworks.com/matlabcentral/cody/problems/3069-pattern-recognition-2-known-unit-length-various-array-length-including-cell-arrays\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3069\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":3092,"title":"Return fibonacci sequence  do not use loop and condition","description":"Calculate the nth Fibonacci number.\r\n\r\nGiven n, return f where f = fib(n) and f(1) = 1, f(2) = 1, f(3) = 2, ...\r\n\r\nExamples:\r\n\r\n Input  n = 5\r\n Output f is 5\r\n Input  n = 7\r\n Output f is 13\r\n\r\nbut, *loop and conditional statement is forbidden*","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: 203.733px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 101.867px; transform-origin: 407px 101.867px; 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: 113.5px 8px; transform-origin: 113.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eCalculate the nth Fibonacci number.\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: 204px 8px; transform-origin: 204px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven n, return f where f = fib(n) and f(1) = 1, f(2) = 1, f(3) = 2, ...\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: 32px 8px; transform-origin: 32px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExamples:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.7333px; 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 40.8667px; transform-origin: 404px 40.8667px; 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: 52px 8.5px; transform-origin: 52px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 32px 8.5px; transform-origin: 32px 8.5px; \"\u003e Input  \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 20px 8.5px; text-decoration: none; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 20px 8.5px; \"\u003en = 5\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: 56px 8.5px; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 32px 8.5px; transform-origin: 32px 8.5px; \"\u003e Output \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 24px 8.5px; text-decoration: none; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 24px 8.5px; \"\u003ef is 5\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: 52px 8.5px; transform-origin: 52px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 32px 8.5px; transform-origin: 32px 8.5px; \"\u003e Input  \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 20px 8.5px; text-decoration: none; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 20px 8.5px; \"\u003en = 7\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: 60px 8.5px; transform-origin: 60px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 32px 8.5px; transform-origin: 32px 8.5px; \"\u003e Output \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 28px 8.5px; text-decoration: none; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 28px 8.5px; \"\u003ef is 13\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: 12px 8px; transform-origin: 12px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ebut,\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\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: 153px 8px; transform-origin: 153px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eloop and conditional statement is forbidden\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function f = fib(n)\r\n  f = n;\r\nend","test_suite":"%%% functions forbidden\r\n\r\n\r\n% Clean user's function from some known jailbreaking mechanisms\r\nfunctions={'!','feval','eval','str2func','str2num','regex','system','dos','unix','perl','assert','fopen','write','save','setenv','path','please','for','if','while','switch','round','roundn','fix','ceil','char','floor'};\r\nassessFunctionAbsence(functions, 'FileName', 'fib.m');\r\n%%\r\nn = 1;\r\nf = 1;\r\nassert(abs(fib(n) - f) \u003c 1e-4)\r\n\r\n%%\r\nn = 6;\r\nf = 8;\r\nassert(abs(fib(n) - f) \u003c 1e-4)\r\n\r\n%%\r\nn = 10;\r\nf = 55;\r\nassert(abs(fib(n) - f) \u003c 1e-4)\r\n\r\n%%\r\nn = 20;\r\nf = 6765;\r\nassert(abs(fib(n) - f) \u003c 1e-4)","published":true,"deleted":false,"likes_count":15,"comments_count":11,"created_by":3668,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":855,"test_suite_updated_at":"2021-02-15T12:43:32.000Z","rescore_all_solutions":false,"group_id":30,"created_at":"2015-03-18T15:03:18.000Z","updated_at":"2026-03-16T14:19:58.000Z","published_at":"2015-03-18T15:25:13.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\u003eCalculate the nth Fibonacci 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\u003eGiven n, return f where f = fib(n) and f(1) = 1, f(2) = 1, f(3) = 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\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[ Input  n = 5\\n Output f is 5\\n Input  n = 7\\n Output f is 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ebut,\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\u003eloop and conditional statement is forbidden\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":3095,"title":" Return fibonacci sequence do not use loop and condition version 2","description":"Calculate the nth Fibonacci number,return sequence\r\n\r\nGiven n, return f where f = fib(n) and f(1) = 1, f(2) = 1, f(3) = 2, ...\r\n\r\nExamples:\r\n\r\n Input  n = 2 : 5\r\n Output f is [1 2 3 5]\r\n Input  n = 7 : 10\r\n Output f is [13    21    34    55]\r\n\r\nbut, loop and conditional statement is forbidden","description_html":"\u003cp\u003eCalculate the nth Fibonacci number,return sequence\u003c/p\u003e\u003cp\u003eGiven n, return f where f = fib(n) and f(1) = 1, f(2) = 1, f(3) = 2, ...\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre\u003e Input  n = 2 : 5\r\n Output f is [1 2 3 5]\r\n Input  n = 7 : 10\r\n Output f is [13    21    34    55]\u003c/pre\u003e\u003cp\u003ebut, loop and conditional statement is forbidden\u003c/p\u003e","function_template":"function y = fib(x)\r\n  y = x;\r\nend","test_suite":"%%% Clean workspace\r\n% !/bin/cp fib.m safe\r\n% !/bin/rm *.*\r\n% !/bin/mv safe fib.m\r\n\r\n% Clean user's function from some known jailbreaking mechanisms\r\nfunctions={'!','feval','eval','str2func','str2num','regex','system','dos','unix','perl','assert','fopen','write','save','setenv','path','please','for','if','while','switch','round','roundn','fix','ceil','char','floor','\\.','^','power'};\r\nfid = fopen('fib.m');\r\n  st = char(fread(fid)');\r\n  for n = 1:numel(functions)\r\n    st = regexprep(st, functions{n}, 'error(''No fancy functions!''); %','ignorecase');\r\n  end\r\n  st = regexprep(st, 'function', 'error(''No fancy functions!''); %','ignorecase',2);\r\nfclose(fid);\r\nfid = fopen('fib.m' , 'w');\r\n  fwrite(fid,st);\r\nfclose(fid);\r\n\r\n%%\r\nn = 1:5;\r\nf = [1     1     2     3     5];\r\nassert(isequal(fib(n),f))\r\n\r\n%%\r\nn = 7 : 10;\r\nf = [13    21    34    55];\r\nassert(isequal(fib(n),f))\r\n\r\n%%\r\n\r\nn = 20 : 22;\r\nf = [ 6765       10946       17711];\r\nassert(isequal(fib(n),f))","published":true,"deleted":false,"likes_count":0,"comments_count":21,"created_by":3668,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":64,"test_suite_updated_at":"2015-03-19T15:13:29.000Z","rescore_all_solutions":false,"group_id":30,"created_at":"2015-03-19T14:56:25.000Z","updated_at":"2026-03-16T14:37:24.000Z","published_at":"2015-03-19T14:56:25.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\u003eCalculate the nth Fibonacci number,return 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:t\u003eGiven n, return f where f = fib(n) and f(1) = 1, f(2) = 1, f(3) = 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\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[ Input  n = 2 : 5\\n Output f is [1 2 3 5]\\n Input  n = 7 : 10\\n Output f is [13    21    34    55]]]\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\u003ebut, loop and conditional statement is forbidden\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":8045,"title":"Gold Standard","description":"Gold has long been used as currency and a standard for currency, due to its inherent value and rarity. Historical data for gold is available at \u003chttp://measuringworth.com/gold/ Measuring Worth\u003e.\r\n\r\nFor this problem, you will be provided with a historical year (HY) and a historical value (HV) in dollars. The function template includes data from the previously mentioned site for the value (in dollars) of an ounce of gold (GV) from 1791 to 2014. Write a function to determine the current value (CV) in dollars assuming that the gold standard can be accurately used to convert between years. Round the result to two decimal places. If HY is outside of the historical-data range, return NaN.\r\n\r\nAs an example, with HY = 2000 and HV = 1000:\r\n\r\n* GV(HY=2000) = $280.10\r\n* N = 1000/280.10 = 3.57 (ounces of gold)\r\n* CV = 3.57*1270 (current $/ounce of gold) = $4534.09.\r\n","description_html":"\u003cp\u003eGold has long been used as currency and a standard for currency, due to its inherent value and rarity. Historical data for gold is available at \u003ca href = \"http://measuringworth.com/gold/\"\u003eMeasuring Worth\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eFor this problem, you will be provided with a historical year (HY) and a historical value (HV) in dollars. The function template includes data from the previously mentioned site for the value (in dollars) of an ounce of gold (GV) from 1791 to 2014. Write a function to determine the current value (CV) in dollars assuming that the gold standard can be accurately used to convert between years. Round the result to two decimal places. If HY is outside of the historical-data range, return NaN.\u003c/p\u003e\u003cp\u003eAs an example, with HY = 2000 and HV = 1000:\u003c/p\u003e\u003cul\u003e\u003cli\u003eGV(HY=2000) = $280.10\u003c/li\u003e\u003cli\u003eN = 1000/280.10 = 3.57 (ounces of gold)\u003c/li\u003e\u003cli\u003eCV = 3.57*1270 (current $/ounce of gold) = $4534.09.\u003c/li\u003e\u003c/ul\u003e","function_template":"function [CV] = gold_standard(HY,HV)\r\n\r\nY = 1791:2014;\r\nGV = [19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 20.1, 21.64, 20.95, 19.46, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.94, 20.69, 20.69, 21.64, 20.86, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.7, 20.67, 20.67, 20.67, 20.67, 23.42, 30.02, 42.03, 32.52, 29.13, 28.57, 28.88, 27.49, 23.75, 23.09, 23.24, 23.52, 22.99, 23.75, 23.05, 21.66, 20.84, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 24.44, 34.94, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 39.26, 41.51, 36.41, 41.25, 58.6, 97.81, 159.74, 161.49, 125.32, 148.31, 193.55, 307.5, 612.56, 459.64, 375.91, 424, 360.66, 317.66, 368.24, 447.95, 438.31, 382.58, 384.93, 363.29, 344.97, 360.91, 385.42, 385.5, 389.09, 332.39, 295.24, 279.91, 280.1, 272.22, 311.33, 364.8, 410.52, 446, 606, 699, 874, 975, 1227, 1572, 1700, 1415, 1270];\r\n\r\nCV = 1;\r\n\r\nend\r\n","test_suite":"%% current check\r\nHY = 2014; HV = 1270; CV_corr = 1270;\r\nassert(abs(gold_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%% out-of-range check 1\r\nHY = 500; HV = 50; CV_corr = NaN;\r\nassert(isnan(gold_standard(HY,HV)))\r\n\r\n%% out-of-range check 2\r\nHY = 2500; HV = 5000; CV_corr = NaN;\r\nassert(isnan(gold_standard(HY,HV)))\r\n\r\n%%\r\nHY = 2010; HV = 1000; CV_corr = 1035.04;\r\nassert(abs(gold_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nHY = 2005; HV = 1000; CV_corr = 2847.53;\r\nassert(abs(gold_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nHY = 2000; HV = 1000; CV_corr = 4534.09;\r\nassert(abs(gold_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nHY = 1995; HV = 1000; CV_corr = 3294.42;\r\nassert(abs(gold_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nHY = 1990; HV = 1000; CV_corr = 3299.3;\r\nassert(abs(gold_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nHY = 1950; HV = 1000; CV_corr = 36285.71;\r\nassert(abs(gold_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nHY = 1900; HV = 1000; CV_corr = 61441.7;\r\nassert(abs(gold_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nHY = 1850; HV = 1000; CV_corr = 61441.7;\r\nassert(abs(gold_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nHY = 1800; HV = 1000; CV_corr = 65497.68;\r\nassert(abs(gold_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":63,"test_suite_updated_at":"2015-03-30T16:49:21.000Z","rescore_all_solutions":false,"group_id":30,"created_at":"2015-03-30T15:58:58.000Z","updated_at":"2026-03-24T03:34:47.000Z","published_at":"2015-03-30T15:58: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\u003eGold has long been used as currency and a standard for currency, due to its inherent value and rarity. Historical data for gold is available at\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://measuringworth.com/gold/\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eMeasuring Worth\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\u003eFor this problem, you will be provided with a historical year (HY) and a historical value (HV) in dollars. The function template includes data from the previously mentioned site for the value (in dollars) of an ounce of gold (GV) from 1791 to 2014. Write a function to determine the current value (CV) in dollars assuming that the gold standard can be accurately used to convert between years. Round the result to two decimal places. If HY is outside of the historical-data range, return NaN.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs an example, with HY = 2000 and HV = 1000:\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\u003eGV(HY=2000) = $280.10\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\u003eN = 1000/280.10 = 3.57 (ounces of gold)\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\u003eCV = 3.57*1270 (current $/ounce of gold) = $4534.09.\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":8046,"title":"Gold/Silver Standard","description":"Pursuant to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/8045-gold-standard Gold Standard\u003e problem, suppose that you have data for silver rather than gold to make an assessment regarding historical currency values. Historical data for the silver-to-gold ratio is also available from \u003chttp://measuringworth.com/gold/ Measuring Worth\u003e.\r\n\r\nFor this problem, you will be provided with a historical year (HY) and a historical value (HV) in dollars. The function template includes data from the previously mentioned site for the value (in dollars) of an ounce of gold (GV), in addition to the silver-to-gold ratio, from 1791 to 2014. Write a function to determine the current value (CV) in dollars assuming that the gold standard must be converted to the silver standard to accurately convert between years. Round the result to two decimal places. If HY is outside of the historical data range, return NaN.\r\n\r\nAs an example, with HY = 2000 and HV = 1000:\r\n\r\n* GV(HY=2000) = $280.10\r\n* N = 1000/280.10 = 3.57 (ounces of gold)\r\n* SR(HY=2000) = 55.96\r\n* NS = 55.96*3.57 = 199.79 (ounces of silver)\r\n* NG = 199.79/66.38 = 3.01 (current ounces of gold) [SR(2014) = 66.38]\r\n* CV = 3.01*1270 (current $/ounce of gold) = $3822.36.","description_html":"\u003cp\u003ePursuant to the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/8045-gold-standard\"\u003eGold Standard\u003c/a\u003e problem, suppose that you have data for silver rather than gold to make an assessment regarding historical currency values. Historical data for the silver-to-gold ratio is also available from \u003ca href = \"http://measuringworth.com/gold/\"\u003eMeasuring Worth\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eFor this problem, you will be provided with a historical year (HY) and a historical value (HV) in dollars. The function template includes data from the previously mentioned site for the value (in dollars) of an ounce of gold (GV), in addition to the silver-to-gold ratio, from 1791 to 2014. Write a function to determine the current value (CV) in dollars assuming that the gold standard must be converted to the silver standard to accurately convert between years. Round the result to two decimal places. If HY is outside of the historical data range, return NaN.\u003c/p\u003e\u003cp\u003eAs an example, with HY = 2000 and HV = 1000:\u003c/p\u003e\u003cul\u003e\u003cli\u003eGV(HY=2000) = $280.10\u003c/li\u003e\u003cli\u003eN = 1000/280.10 = 3.57 (ounces of gold)\u003c/li\u003e\u003cli\u003eSR(HY=2000) = 55.96\u003c/li\u003e\u003cli\u003eNS = 55.96*3.57 = 199.79 (ounces of silver)\u003c/li\u003e\u003cli\u003eNG = 199.79/66.38 = 3.01 (current ounces of gold) [SR(2014) = 66.38]\u003c/li\u003e\u003cli\u003eCV = 3.01*1270 (current $/ounce of gold) = $3822.36.\u003c/li\u003e\u003c/ul\u003e","function_template":"function [CV] = gold_silver_standard(HY,HV)\r\n\r\nY = 1791:2014;\r\nGV = [19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 20.1, 21.64, 20.95, 19.46, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.94, 20.69, 20.69, 21.64, 20.86, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.7, 20.67, 20.67, 20.67, 20.67, 23.42, 30.02, 42.03, 32.52, 29.13, 28.57, 28.88, 27.49, 23.75, 23.09, 23.24, 23.52, 22.99, 23.75, 23.05, 21.66, 20.84, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 24.44, 34.94, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 39.26, 41.51, 36.41, 41.25, 58.6, 97.81, 159.74, 161.49, 125.32, 148.31, 193.55, 307.5, 612.56, 459.64, 375.91, 424, 360.66, 317.66, 368.24, 447.95, 438.31, 382.58, 384.93, 363.29, 344.97, 360.91, 385.42, 385.5, 389.09, 332.39, 295.24, 279.91, 280.1, 272.22, 311.33, 364.8, 410.52, 446, 606, 699, 874, 975, 1227, 1572, 1700, 1415, 1270];\r\nSR = [15.05, 15.17, 15, 15.37, 15.55, 15.65, 15.41, 15.59, 15.74, 15.68, 15.46, 15.26, 15.41, 15.41, 15.79, 15.52, 15.43, 16.08, 15.96, 15.77, 15.53, 16.11, 16.25, 15.04, 15.26, 15.28, 15.11, 15.35, 15.33, 15.62, 15.95, 15.8, 15.84, 15.82, 15.7, 15.76, 15.74, 15.78, 15.78, 15.82, 15.72, 15.73, 15.93, 15.73, 15.8, 15.72, 15.83, 15.85, 15.62, 15.62, 15.7, 15.87, 15.93, 15.85, 15.92, 15.9, 15.8, 15.85, 15.78, 15.7, 15.46, 15.59, 15.33, 15.33, 15.38, 15.38, 15.27, 15.38, 15.19, 15.29, 15.5, 15.35, 15.37, 15.37, 15.44, 15.43, 15.57, 15.59, 15.6, 15.57, 15.57, 15.63, 15.93, 16.16, 16.64, 17.75, 17.2, 17.92, 18.39, 18.05, 18.25, 18.2, 18.64, 18.61, 19.41, 20.78, 21.1, 22, 22.1, 19.75, 20.92, 23.72, 26.49, 32.56, 31.6, 30.59, 34.2, 35.03, 34.36, 33.33, 34.68, 39.15, 38.1, 35.7, 33.87, 30.54, 31.24, 38.64, 39.74, 38.22, 38.33, 33.62, 34.19, 37.37, 40.48, 30.78, 24.61, 21, 18.44, 20.28, 32.76, 30.43, 31.69, 30.8, 29.78, 33.11, 36.47, 35.34, 38.78, 53.74, 71.25, 73.29, 69.83, 72.36, 54.19, 77.09, 77.44, 80.39, 88.84, 99.76, 99.73, 90.57, 77.67, 77.67, 67.4, 43.67, 48.73, 47.07, 48.61, 47.14, 39.12, 41.16, 41.04, 41.01, 39.24, 38.5, 38.5, 39.27, 38.34, 38.27, 37.82, 32.22, 27.34, 27.04, 27.04, 27.04, 22.56, 18.29, 23.16, 20.54, 26.66, 34.75, 38.21, 33.9, 36.51, 28.76, 32.05, 35.8, 27.69, 29.66, 43.65, 47.24, 37.03, 44.26, 51.68, 67.25, 63.84, 66.95, 69.49, 79.78, 89.83, 87.47, 83.85, 72.79, 74.78, 74.89, 67.91, 53.24, 53.26, 55.96, 61.95, 67.32, 74.22, 61.3, 60.7, 52.2, 51.91, 58.17, 66.27, 60.64, 44.75, 53.58, 59.31, 66.38];\r\n\r\nCV = 1;\r\n\r\nend\r\n","test_suite":"%% current check\r\nHY = 2014; HV = 1270; CV_corr = 1270;\r\nassert(abs(gold_silver_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%% out-of-range check 1\r\nHY = 500; HV = 50; CV_corr = NaN;\r\nassert(isnan(gold_silver_standard(HY,HV)))\r\n\r\n%% out-of-range check 2\r\nHY = 2500; HV = 5000; CV_corr = NaN;\r\nassert(isnan(gold_silver_standard(HY,HV)))\r\n\r\n%%\r\nHY = 2010; HV = 1000; CV_corr = 945.54;\r\nassert(abs(gold_silver_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nHY = 2005; HV = 1000; CV_corr = 2603.88;\r\nassert(abs(gold_silver_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nHY = 2000; HV = 1000; CV_corr = 3822.36;\r\nassert(abs(gold_silver_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nHY = 1995; HV = 1000; CV_corr = 3711.31;\r\nassert(abs(gold_silver_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nHY = 1990; HV = 1000; CV_corr = 3965.32;\r\nassert(abs(gold_silver_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nHY = 1950; HV = 1000; CV_corr = 25768.43;\r\nassert(abs(gold_silver_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nHY = 1900; HV = 1000; CV_corr = 30850.44;\r\nassert(abs(gold_silver_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nHY = 1850; HV = 1000; CV_corr = 14532.01;\r\nassert(abs(gold_silver_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nHY = 1800; HV = 1000; CV_corr = 15471.58;\r\nassert(abs(gold_silver_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tHY = 2000; HV = 1000; CV_corr = 3822.36;\r\n\tcase 2\r\n\t\tHY = 1995; HV = 1000; CV_corr = 3711.31;\r\n\tcase 3\r\n\t\tHY = 2005; HV = 1000; CV_corr = 2603.88;\r\n\tcase 4\r\n\t\tHY = 1800; HV = 1000; CV_corr = 15471.58;\r\nend\r\nassert(abs(gold_silver_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tHY = 1995; HV = 1000; CV_corr = 3711.31;\r\n\tcase 2\r\n\t\tHY = 1990; HV = 1000; CV_corr = 3965.32;\r\n\tcase 3\r\n\t\tHY = 2010; HV = 1000; CV_corr = 945.54;\r\n\tcase 4\r\n\t\tHY = 1900; HV = 1000; CV_corr = 30850.44;\r\nend\r\nassert(abs(gold_silver_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n\r\n%%\r\nind = randi(4);\r\nswitch ind\r\n\tcase 1\r\n\t\tHY = 1990; HV = 1000; CV_corr = 3965.32;\r\n\tcase 2\r\n\t\tHY = 1950; HV = 1000; CV_corr = 25768.43;\r\n\tcase 3\r\n\t\tHY = 1900; HV = 1000; CV_corr = 30850.44;\r\n\tcase 4\r\n\t\tHY = 2000; HV = 1000; CV_corr = 3822.36;\r\nend\r\nassert(abs(gold_silver_standard(HY,HV)-CV_corr)\u003c2e-5)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":56,"test_suite_updated_at":"2015-03-30T16:51:28.000Z","rescore_all_solutions":false,"group_id":30,"created_at":"2015-03-30T16:22:04.000Z","updated_at":"2026-03-27T06:19:08.000Z","published_at":"2015-03-30T16:22:04.000Z","restored_at":"2017-07-28T15:24:51.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\u003ePursuant to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/8045-gold-standard\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGold Standard\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e problem, suppose that you have data for silver rather than gold to make an assessment regarding historical currency values. Historical data for the silver-to-gold ratio is also available 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=\\\"http://measuringworth.com/gold/\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eMeasuring Worth\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\u003eFor this problem, you will be provided with a historical year (HY) and a historical value (HV) in dollars. The function template includes data from the previously mentioned site for the value (in dollars) of an ounce of gold (GV), in addition to the silver-to-gold ratio, from 1791 to 2014. Write a function to determine the current value (CV) in dollars assuming that the gold standard must be converted to the silver standard to accurately convert between years. Round the result to two decimal places. If HY is outside of the historical data range, return NaN.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs an example, with HY = 2000 and HV = 1000:\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\u003eGV(HY=2000) = $280.10\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\u003eN = 1000/280.10 = 3.57 (ounces of gold)\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\u003eSR(HY=2000) = 55.96\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\u003eNS = 55.96*3.57 = 199.79 (ounces of silver)\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\u003eNG = 199.79/66.38 = 3.01 (current ounces of gold) [SR(2014) = 66.38]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCV = 3.01*1270 (current $/ounce of gold) = $3822.36.\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":8047,"title":"Weighted Gold/Silver Standard","description":"Building off of the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/8045-gold-standard Gold Standard\u003e and \u003chttp://www.mathworks.com/matlabcentral/cody/problems/8046-gold-silver-standard Gold/Silver Standard\u003e problems, let's make a weighted currency convertor. The same data for gold value and silver-to-gold ratio will be provided in the function template.\r\n\r\nFor this problem, based on a historical year (HY) and a historical value (HV) in dollars, calculate the current value using the gold (CVG) and silver (CVS) references; see the referenced problems for details and examples of those individual problems. In this case, you will be provided a weighting that will range from 0 to 1, where 0 indicates complete weighting by gold and 1 indicates complete weighting by silver. Remember to round the result to two decimal places. If HY is outside of the historical data range, return NaN.\r\n\r\nAs an example, with HY = 2000, HV = 1000, and wt = 0.4:\r\n\r\n* CVG = $4534.09 (gold standard)\r\n* CVS = $3822.36 (silver standard)\r\n* CV = (1-0.4)*4534.09 + 0.4*3822.36 = $4249.40.","description_html":"\u003cp\u003eBuilding off of the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/8045-gold-standard\"\u003eGold Standard\u003c/a\u003e and \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/8046-gold-silver-standard\"\u003eGold/Silver Standard\u003c/a\u003e problems, let's make a weighted currency convertor. The same data for gold value and silver-to-gold ratio will be provided in the function template.\u003c/p\u003e\u003cp\u003eFor this problem, based on a historical year (HY) and a historical value (HV) in dollars, calculate the current value using the gold (CVG) and silver (CVS) references; see the referenced problems for details and examples of those individual problems. In this case, you will be provided a weighting that will range from 0 to 1, where 0 indicates complete weighting by gold and 1 indicates complete weighting by silver. Remember to round the result to two decimal places. If HY is outside of the historical data range, return NaN.\u003c/p\u003e\u003cp\u003eAs an example, with HY = 2000, HV = 1000, and wt = 0.4:\u003c/p\u003e\u003cul\u003e\u003cli\u003eCVG = $4534.09 (gold standard)\u003c/li\u003e\u003cli\u003eCVS = $3822.36 (silver standard)\u003c/li\u003e\u003cli\u003eCV = (1-0.4)*4534.09 + 0.4*3822.36 = $4249.40.\u003c/li\u003e\u003c/ul\u003e","function_template":"function [CV] = gold_silver_weighted_standard(HY,HV,wt)\r\n\r\nY = 1791:2014;\r\nGV = [19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 20.1, 21.64, 20.95, 19.46, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.39, 19.94, 20.69, 20.69, 21.64, 20.86, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.7, 20.67, 20.67, 20.67, 20.67, 23.42, 30.02, 42.03, 32.52, 29.13, 28.57, 28.88, 27.49, 23.75, 23.09, 23.24, 23.52, 22.99, 23.75, 23.05, 21.66, 20.84, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 20.67, 24.44, 34.94, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 39.26, 41.51, 36.41, 41.25, 58.6, 97.81, 159.74, 161.49, 125.32, 148.31, 193.55, 307.5, 612.56, 459.64, 375.91, 424, 360.66, 317.66, 368.24, 447.95, 438.31, 382.58, 384.93, 363.29, 344.97, 360.91, 385.42, 385.5, 389.09, 332.39, 295.24, 279.91, 280.1, 272.22, 311.33, 364.8, 410.52, 446, 606, 699, 874, 975, 1227, 1572, 1700, 1415, 1270];\r\nSR = [15.05, 15.17, 15, 15.37, 15.55, 15.65, 15.41, 15.59, 15.74, 15.68, 15.46, 15.26, 15.41, 15.41, 15.79, 15.52, 15.43, 16.08, 15.96, 15.77, 15.53, 16.11, 16.25, 15.04, 15.26, 15.28, 15.11, 15.35, 15.33, 15.62, 15.95, 15.8, 15.84, 15.82, 15.7, 15.76, 15.74, 15.78, 15.78, 15.82, 15.72, 15.73, 15.93, 15.73, 15.8, 15.72, 15.83, 15.85, 15.62, 15.62, 15.7, 15.87, 15.93, 15.85, 15.92, 15.9, 15.8, 15.85, 15.78, 15.7, 15.46, 15.59, 15.33, 15.33, 15.38, 15.38, 15.27, 15.38, 15.19, 15.29, 15.5, 15.35, 15.37, 15.37, 15.44, 15.43, 15.57, 15.59, 15.6, 15.57, 15.57, 15.63, 15.93, 16.16, 16.64, 17.75, 17.2, 17.92, 18.39, 18.05, 18.25, 18.2, 18.64, 18.61, 19.41, 20.78, 21.1, 22, 22.1, 19.75, 20.92, 23.72, 26.49, 32.56, 31.6, 30.59, 34.2, 35.03, 34.36, 33.33, 34.68, 39.15, 38.1, 35.7, 33.87, 30.54, 31.24, 38.64, 39.74, 38.22, 38.33, 33.62, 34.19, 37.37, 40.48, 30.78, 24.61, 21, 18.44, 20.28, 32.76, 30.43, 31.69, 30.8, 29.78, 33.11, 36.47, 35.34, 38.78, 53.74, 71.25, 73.29, 69.83, 72.36, 54.19, 77.09, 77.44, 80.39, 88.84, 99.76, 99.73, 90.57, 77.67, 77.67, 67.4, 43.67, 48.73, 47.07, 48.61, 47.14, 39.12, 41.16, 41.04, 41.01, 39.24, 38.5, 38.5, 39.27, 38.34, 38.27, 37.82, 32.22, 27.34, 27.04, 27.04, 27.04, 22.56, 18.29, 23.16, 20.54, 26.66, 34.75, 38.21, 33.9, 36.51, 28.76, 32.05, 35.8, 27.69, 29.66, 43.65, 47.24, 37.03, 44.26, 51.68, 67.25, 63.84, 66.95, 69.49, 79.78, 89.83, 87.47, 83.85, 72.79, 74.78, 74.89, 67.91, 53.24, 53.26, 55.96, 61.95, 67.32, 74.22, 61.3, 60.7, 52.2, 51.91, 58.17, 66.27, 60.64, 44.75, 53.58, 59.31, 66.38];\r\n\r\nCV = 1;\r\n\r\nend\r\n","test_suite":"%% current check\r\nHY = 2014; HV = 1270; wt = 0.5; CV_corr = 1270;\r\nassert(abs(gold_silver_weighted_standard(HY,HV,wt)-CV_corr)\u003c5e-2)\r\n\r\n%% out-of-range check 1\r\nHY = 500; HV = 50; wt = 0.5; CV_corr = NaN;\r\nassert(isnan(gold_silver_weighted_standard(HY,HV,wt)))\r\n\r\n%% out-of-range check 2\r\nHY = 2500; HV = 5000; wt = 0.5; CV_corr = NaN;\r\nassert(isnan(gold_silver_weighted_standard(HY,HV,wt)))\r\n\r\n%%\r\nHY = 2010; HV = 1000; wt = 0.5; CV_corr = 990.29;\r\nassert(abs(gold_silver_weighted_standard(HY,HV,wt)-CV_corr)\u003c5e-2)\r\n\r\n%%\r\nHY = 2005; HV = 1000; wt = 0.5; CV_corr = 2725.7;\r\nassert(abs(gold_silver_weighted_standard(HY,HV,wt)-CV_corr)\u003c5e-2)\r\n\r\n%%\r\nHY = 2000; HV = 1000; wt = 0.5; CV_corr = 4178.23;\r\nassert(abs(gold_silver_weighted_standard(HY,HV,wt)-CV_corr)\u003c5e-2)\r\n\r\n%%\r\nHY = 1995; HV = 1000; wt = 0.5; CV_corr = 3502.87;\r\nassert(abs(gold_silver_weighted_standard(HY,HV,wt)-CV_corr)\u003c5e-2)\r\n\r\n%%\r\nHY = 1990; HV = 1000; wt = 0.5; CV_corr = 3632.31;\r\nassert(abs(gold_silver_weighted_standard(HY,HV,wt)-CV_corr)\u003c5e-2)\r\n\r\n%%\r\nHY = 1950; HV = 1000; wt = 0.5; CV_corr = 31027.07;\r\nassert(abs(gold_silver_weighted_standard(HY,HV,wt)-CV_corr)\u003c5e-2)\r\n\r\n%%\r\nHY = 1900; HV = 1000; wt = 0.5; CV_corr = 46146.07;\r\nassert(abs(gold_silver_weighted_standard(HY,HV,wt)-CV_corr)\u003c5e-2)\r\n\r\n%%\r\nHY = 1850; HV = 1000; wt = 0.5; CV_corr = 37986.86;\r\nassert(abs(gold_silver_weighted_standard(HY,HV,wt)-CV_corr)\u003c5e-2)\r\n\r\n%%\r\nHY = 1800; HV = 1000; wt = 0.5; CV_corr = 40484.63;\r\nassert(abs(gold_silver_weighted_standard(HY,HV,wt)-CV_corr)\u003c5e-2)\r\n\r\n%%\r\nHY = 2000; HV = 1000;\r\nwt = randi(10)/10;\r\nswitch (wt*10)\r\n\tcase 0\r\n\t\tCV_corr = 4534.09;\r\n\tcase 1\r\n\t\tCV_corr = 4462.92;\r\n\tcase 2\r\n\t\tCV_corr = 4391.75;\r\n\tcase 3\r\n\t\tCV_corr = 4320.57;\r\n\tcase 4\r\n\t\tCV_corr = 4249.4;\r\n\tcase 5\r\n\t\tCV_corr = 4178.23;\r\n\tcase 6\r\n\t\tCV_corr = 4107.05;\r\n\tcase 7\r\n\t\tCV_corr = 4035.88;\r\n\tcase 8\r\n\t\tCV_corr = 3964.7;\r\n\tcase 9\r\n\t\tCV_corr = 3893.53;\r\n\tcase 10\r\n\t\tCV_corr = 3822.36;\r\nend\r\nassert(abs(gold_silver_weighted_standard(HY,HV,wt)-CV_corr)\u003c5e-2)\r\n\r\n%%\r\nHY = 1800; HV = 1000;\r\nwt = randi(10)/10;\r\nswitch (wt*10)\r\n\tcase 0\r\n\t\tCV_corr = 65497.68;\r\n\tcase 1\r\n\t\tCV_corr = 60495.07;\r\n\tcase 2\r\n\t\tCV_corr = 55492.46;\r\n\tcase 3\r\n\t\tCV_corr = 50489.85;\r\n\tcase 4\r\n\t\tCV_corr = 45487.24;\r\n\tcase 5\r\n\t\tCV_corr = 40484.63;\r\n\tcase 6\r\n\t\tCV_corr = 35482.02;\r\n\tcase 7\r\n\t\tCV_corr = 30479.41;\r\n\tcase 8\r\n\t\tCV_corr = 25476.8;\r\n\tcase 9\r\n\t\tCV_corr = 20474.19;\r\n\tcase 10\r\n\t\tCV_corr = 15471.58;\r\nend\r\nassert(abs(gold_silver_weighted_standard(HY,HV,wt)-CV_corr)\u003c5e-2)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":50,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":30,"created_at":"2015-03-30T16:47:31.000Z","updated_at":"2026-03-27T06:22:48.000Z","published_at":"2015-03-30T16:47:31.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 the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/8045-gold-standard\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGold Standard\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/8046-gold-silver-standard\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGold/Silver Standard\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e problems, let's make a weighted currency convertor. The same data for gold value and silver-to-gold ratio will be provided in the function template.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 problem, based on a historical year (HY) and a historical value (HV) in dollars, calculate the current value using the gold (CVG) and silver (CVS) references; see the referenced problems for details and examples of those individual problems. In this case, you will be provided a weighting that will range from 0 to 1, where 0 indicates complete weighting by gold and 1 indicates complete weighting by silver. Remember to round the result to two decimal places. If HY is outside of the historical data range, return NaN.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs an example, with HY = 2000, HV = 1000, and wt = 0.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\u003eCVG = $4534.09 (gold standard)\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\u003eCVS = $3822.36 (silver standard)\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\u003eCV = (1-0.4)*4534.09 + 0.4*3822.36 = $4249.40.\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\"}]}"}],"no_progress_badge":{"id":53,"name":"Unknown","symbol":"unknown","description":"Partially completed groups","description_html":null,"image_location":"/images/responsive/supporting/matlabcentral/cody/badges/problem_groups_unknown_2.png","bonus":null,"players_count":0,"active":false,"created_by":null,"updated_by":null,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"created_at":"2018-01-10T23:20:29.000Z","updated_at":"2018-01-10T23:20:29.000Z","community_badge_id":null,"award_multiples":false}}