{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":2949,"title":"Combination logic","description":"Create an algorithm in MATLAB that calculate the combination for the given positive integers n and k as inputs. When k \u003e n, the result is 0. The formula of the combination, for n \u003e= k, can be seen below:\r\n\r\n\u003c\u003chttp://imageshack.com/a/img540/5995/Q17BWT.png\u003e\u003e","description_html":"\u003cp\u003eCreate an algorithm in MATLAB that calculate the combination for the given positive integers n and k as inputs. When k \u0026gt; n, the result is 0. The formula of the combination, for n \u0026gt;= k, can be seen below:\u003c/p\u003e\u003cimg src = \"http://imageshack.com/a/img540/5995/Q17BWT.png\"\u003e","function_template":"function y = combine(n,k)\r\n  y = n+k;\r\nend","test_suite":"%%\r\nn = 2;\r\nk = 3;\r\ny_correct = 0;\r\nassert(isequal(combine(n,k),y_correct))\r\n\r\n%%\r\nn = 3;\r\nk = 2;\r\ny_correct = 3;\r\nassert(isequal(combine(n,k),y_correct))\r\n\r\n%%\r\nn = 80;\r\nk = 3;\r\ny_correct = 82160;\r\nassert(isequal(combine(n,k),y_correct))\r\n\r\n%%\r\nn = 45;\r\nk = 6;\r\ny_correct = 8145060;\r\nassert(isequal(combine(n,k),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":33785,"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":1,"created_at":"2015-02-04T22:09:30.000Z","updated_at":"2026-02-20T13:40:48.000Z","published_at":"2015-02-04T22:09:38.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/media/image1.png\"}],\"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\u003eCreate an algorithm in MATLAB that calculate the combination for the given positive integers n and k as inputs. When k \u0026gt; n, the result is 0. The formula of the combination, for n \u0026gt;= k, can be seen below:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"relationshipId\\\" w:val=\\\"rId1\\\"/\u003e\u003c/w:customXmlPr\u003e\u003c/w:customXml\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"},{\"partUri\":\"/media/image1.png\",\"contentType\":\"image/png\",\"content\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAADAFBMVEV4eHiTk5P29vaBgYGcnJzAwMC3t7eKiorS0tLt7e3b29vk5OTJycn///9vb28AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD61b95AAAAyklEQVR42q2SSQ6FIAxAWzQxkcj976lEE5R+hojQOmw+Cxa8RwcoGnhf6oNDD0AvGL8j/E2wC+JiXwSaAKbbatGkLjBrX13szynmtPXnKc2eCRiMGQtXxrq2hmZRuuXx6SVdPlPpopeC387sFMMIwdsyAMFAEcHuptW5oIaKYgjHBBoZ512snMeJ8g7o0DmA5jwKXRdqy9W6gfMzhd7iMOySlxq0qn/z4leR43HNQ8WrLtYi1Dz+pnjsmt/8ZsulwLgQOOeC4EyQHH5z1GUZiLNTtwAAAABJRU5ErkJggg==\"}]}"},{"id":44737,"title":"Get the combinations","description":"Consider\r\np,q = 2 vectors of same or different length.\r\nGet a Output Array which has all the possible combinations of Elements of vectors p and q\r\nfor example: \r\n\r\n  p = [1 2 3], q = [10 12]\r\nthen \r\n\r\n  Output = [1 10;2 10;3 10;1 12;2 12;3 12]\r\n","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: 133.733px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 66.8667px; transform-origin: 407px 66.8667px; 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\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: 362px 8px; transform-origin: 362px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eConsider p,q = 2 vectors of same or different length. Get a Output Array which has all the possible combinations of Elements of vectors p and q for example:\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: 96px 8.5px; transform-origin: 96px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ep = [1 2 3], q = [10 12]\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: 20px 8.5px; transform-origin: 20px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ethen \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: 0px 8.5px; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\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: 160px 8.5px; transform-origin: 160px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eOutput = [1 10;2 10;3 10;1 12;2 12;3 12]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = combineit(p,q)\r\n  y = {p.*q};\r\nend","test_suite":"%%\r\np=[10:15]\r\nq=[2:5]\r\ny_correct = [10     2;\r\n    11     2;\r\n    12     2;\r\n    13     2;\r\n    14     2;\r\n    15     2;\r\n    10     3;\r\n    11     3;\r\n    12     3;\r\n    13     3;\r\n    14     3;\r\n    15     3;\r\n    10     4;\r\n    11     4;\r\n    12     4;\r\n    13     4;\r\n    14     4;\r\n    15     4;\r\n    10     5;\r\n    11     5;\r\n    12     5;\r\n    13     5;\r\n    14     5;\r\n    15     5]\r\nassert(isequal(combineit(p,q),y_correct))\r\n\r\n%%\r\np=[-2:2];\r\nq=[-1 0 1];\r\ny_correct = [-2    -1     0     1     2    -2    -1     0     1     2    -2    -1     0     1     2\r\n    -1    -1    -1    -1    -1     0     0     0     0     0     1     1     1     1     1]'; \r\nassert(isequal(combineit(p,q),y_correct))\r\n\r\n%%\r\np=[1 1 2 3 5 8 13];\r\nq=[1.618];\r\ny_correct = [1 1.618; 1 1.618; 2 1.618; 3 1.618; 5 1.618; 8 1.618; 13 1.618];  \r\nassert(isequal(combineit(p,q),y_correct))\r\n\r\n%%\r\np=[0 0.5 1];\r\nq=[exp(1) pi];\r\ny_correct = [0 exp(1); 0.5 exp(1); 1 exp(1); 0 pi; 0.5 pi; 1 pi]\r\nassert(isequal(combineit(p,q),y_correct))\r\n\r\n%%\r\np=[];\r\nq=[];\r\nassert(isempty(combineit(p,q)))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":136465,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":"2021-05-09T10:37:16.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2018-09-11T12:58:36.000Z","updated_at":"2026-04-03T07:15:22.000Z","published_at":"2018-09-11T12:58:36.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\u003eConsider p,q = 2 vectors of same or different length. Get a Output Array which has all the possible combinations of Elements of vectors p and q for example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[p = [1 2 3], q = [10 12]\\nthen \\n\\nOutput = [1 10;2 10;3 10;1 12;2 12;3 12]]]\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":60927,"title":" Pairs with Given Sum","description":"Given an array of integers and a target sum, return all unique pairs whose sum is equal to the target. The output should be a matrix with 2 columns representing each pair.\r\nAssume pairs are unordered, i.e., (2, 3) and (3, 2) are considered the same pair.  \r\ntry to maintain the sequence as the numbers appear in the input array.\r\n","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 143.438px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 408px 71.7125px; transform-origin: 408px 71.7188px; 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: 385px 21px; text-align: left; transform-origin: 385px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven an array of integers and a target sum, return all unique pairs whose sum is equal to the target. The output should be a matrix with 2 columns representing each pair.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAssume pairs are unordered, i.e., (2, 3) and (3, 2) are considered the same pair.\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e  \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 20.4375px; 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: 392px 10.2125px; transform-origin: 392px 10.2188px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"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: 364px 10.2125px; text-align: left; transform-origin: 364px 10.2188px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003etry to maintain the sequence as the numbers appear in the input array.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; 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 y = sum_pair(x,s)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1, 2, 3, 4, 5];\r\ns=6;\r\ny_correct = [1,5; 2,4];\r\nassert(isequal(sum_pair(x,s),y_correct))\r\n\r\n%%\r\nx = [15, 5, 20];\r\ns=25;\r\ny_correct = [5, 20];\r\nassert(isequal(sum_pair(x,s),y_correct))\r\n\r\n\r\n%%\r\nx = [15, 5, 20];\r\ns= 5;\r\ny_correct = [];\r\nassert(isempty(sum_pair(x,s)))\r\n\r\n%%\r\nx = [5, 1, 3, 7, 5, 9, 2, 8, 4, 6, 0, -1, 10, 3, 7];\r\ns= 10;\r\ny_correct = [ 5, 5; 1, 9; 3, 7; 4, 6; 2, 8; 0, 10];\r\nassert(isequal(size(sum_pair(x,s)), [6,2]))\r\nassert(isequal(sum(sum_pair(x,s),'all'), 60))","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":10,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2025-06-02T12:36:47.000Z","updated_at":"2025-12-31T15:00:18.000Z","published_at":"2025-06-02T12:36:47.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an array of integers and a target sum, return all unique pairs whose sum is equal to the target. The output should be a matrix with 2 columns representing each pair.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssume pairs are unordered, i.e., (2, 3) and (3, 2) are considered the same pair.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e  \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003etry to maintain the sequence as the numbers appear in the input array.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\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":42790,"title":"Full combinations","description":"Given n input vectors x1, x2, …, xn, generate a p*n matrix y whose rows contain all element-wise combinations of the vectors x1, x2, …, xn, where p = numel(x1)*numel(x2)*…* numel(xn). The rows of y are organized in an \"increasing\" ordering; see examples below.  \r\n\r\n* Example 1 (character array, n = 2): Input: x1 = 'ab'; x2 = 'cde'; Output: \r\n\r\n\r\n    y = ['ac'\r\n         'ad'\r\n         'ae'\r\n         'bc'\r\n         'bd'\r\n         'be'] \r\n\r\n\r\n* Example 2 (numeric array, n = 3): Input: x1 = [0 1], x2 = [0 1]; x3 = [0 1]; Output: \r\n\r\n    y = [0 0 0\r\n         0 0 1\r\n         0 1 0\r\n         0 1 1\r\n         1 0 0\r\n         1 0 1\r\n         1 1 0\r\n         1 1 1]\r\n\r\n\r\nYou may assume that all inputs are valid vectors whose lengths are at least 1. \r\n \r\n\r\nNote: The Statistics and Machine Learning toolbox provides two useful functions for full factorial design, namely *ff2n* (for binary case) and *fullfact* (for general cases). However, they do not directly accomplish the task in Example 1. The purpose of this problem is to create a toolbox independent function to achieve our goal. Have fun!\r\n","description_html":"\u003cp\u003eGiven n input vectors x1, x2, …, xn, generate a p*n matrix y whose rows contain all element-wise combinations of the vectors x1, x2, …, xn, where p = numel(x1)*numel(x2)*…* numel(xn). The rows of y are organized in an \"increasing\" ordering; see examples below.\u003c/p\u003e\u003cul\u003e\u003cli\u003eExample 1 (character array, n = 2): Input: x1 = 'ab'; x2 = 'cde'; Output:\u003c/li\u003e\u003c/ul\u003e\u003cpre\u003e    y = ['ac'\r\n         'ad'\r\n         'ae'\r\n         'bc'\r\n         'bd'\r\n         'be'] \u003c/pre\u003e\u003cul\u003e\u003cli\u003eExample 2 (numeric array, n = 3): Input: x1 = [0 1], x2 = [0 1]; x3 = [0 1]; Output:\u003c/li\u003e\u003c/ul\u003e\u003cpre\u003e    y = [0 0 0\r\n         0 0 1\r\n         0 1 0\r\n         0 1 1\r\n         1 0 0\r\n         1 0 1\r\n         1 1 0\r\n         1 1 1]\u003c/pre\u003e\u003cp\u003eYou may assume that all inputs are valid vectors whose lengths are at least 1.\u003c/p\u003e\u003cp\u003eNote: The Statistics and Machine Learning toolbox provides two useful functions for full factorial design, namely \u003cb\u003eff2n\u003c/b\u003e (for binary case) and \u003cb\u003efullfact\u003c/b\u003e (for general cases). However, they do not directly accomplish the task in Example 1. The purpose of this problem is to create a toolbox independent function to achieve our goal. Have fun!\u003c/p\u003e","function_template":"function y = myfullfact(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx1 = [0 1]; x2 = [0 1]; x3 = [0 1];\r\ny_correct = [0 0 0\r\n             0 0 1\r\n             0 1 0\r\n             0 1 1\r\n             1 0 0\r\n             1 0 1\r\n             1 1 0\r\n             1 1 1];\r\nassert(isequal(myfullfact(x1,x2,x3),y_correct))\r\n\r\n%%\r\nx1 = [0 1]; x2 = [-1]; x3 = [-1 0 1];\r\ny_correct = [0  -1  -1\r\n             0  -1   0\r\n             0  -1   1\r\n             1  -1  -1\r\n             1  -1   0\r\n             1  -1   1];\r\nassert(isequal(myfullfact(x1,x2,x3),y_correct))\r\n\r\n%% \r\nx1 = 0; x2 = 2; x3 = 4; x4 = 8; x5 = 7; x6 = 6; x7 = 4; x8 = 1; x9 = 1; x10 = 0;\r\ny_correct = [x1 x2 x3 x4 x5 x6 x7 x8 x9 x10];\r\nassert(isequal(myfullfact(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10),y_correct))\r\n\r\n%%\r\nx1 = 'ab'; x2 = 'cde';\r\ny_correct = ['ac'\r\n             'ad'\r\n             'ae'\r\n             'bc'\r\n             'bd'\r\n             'be'];\r\nassert(isequal(myfullfact(x1,x2),y_correct))\r\n\r\n%%\r\nx1 = 'a'; x2 = 'a'; x3 = 'z';\r\ny_correct = 'aaz';\r\nassert(isequal(myfullfact(x1,x2,x3),y_correct))\r\n\r\n%%\r\nx1 = '!@#'; x2 = '23';\r\ny_correct = ['!2'\r\n             '!3'\r\n             '@2'\r\n             '@3'\r\n             '#2'\r\n             '#3'];\r\nassert(isequal(myfullfact(x1,x2),y_correct))\r\n\r\n%%\r\nx1 = '@#'; x2 = 'm'; x3 = 'a'; x4 = 't'; x5 = 'l'; x6 = 'a'; x7 = 'b'; x8 = '$%*';\r\ny_correct = ['@matlab$'\r\n             '@matlab%'\r\n             '@matlab*'\r\n             '#matlab$'\r\n             '#matlab%'\r\n             '#matlab*'];\r\nassert(isequal(myfullfact(x1,x2,x3,x4,x5,x6,x7,x8),y_correct))\r\n\r\n%%\r\n% A manual implementation used to validate other solutions. Please be advised that generalization of this is straightforward but inefficient in terms of Cody size. To get a solution with possibly smaller size, try different ideas please.  \r\nfor iter = 1:20\r\n    a = randi(10,5,1);\r\n    x = arrayfun(@(x)(1:x).',a,'un',0);\r\n    [x1,x2,x3,x4,x5] = deal(x{:});\r\n    y1 = repelem(x1, prod(a(2:5)), 1);\r\n    y2 = repmat(repelem(x2, prod(a(3:5)), 1), a(1), 1);\r\n    y3 = repmat(repelem(x3, prod(a(4:5)), 1), prod(a(1:2)), 1);\r\n    y4 = repmat(repelem(x4, a(5), 1), prod(a(1:3)), 1);\r\n    y5 = repmat(x5, prod(a(1:4)), 1); \r\n    y_correct = [y1, y2, y3, y4, y5];\r\n    assert(isequal(myfullfact(x1,x2,x3,x4,x5),y_correct));\r\nend","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":28,"test_suite_updated_at":"2016-03-29T21:03:54.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-03-29T19:44:39.000Z","updated_at":"2025-12-05T13:12:00.000Z","published_at":"2016-03-29T19:47:42.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven n input vectors x1, x2, …, xn, generate a p*n matrix y whose rows contain all element-wise combinations of the vectors x1, x2, …, xn, where p = numel(x1)*numel(x2)*…* numel(xn). The rows of y are organized in an \\\"increasing\\\" ordering; see examples below.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 1 (character array, n = 2): Input: x1 = 'ab'; x2 = 'cde'; Output:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    y = ['ac'\\n         'ad'\\n         'ae'\\n         'bc'\\n         'bd'\\n         'be']]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 2 (numeric array, n = 3): Input: x1 = [0 1], x2 = [0 1]; x3 = [0 1]; Output:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    y = [0 0 0\\n         0 0 1\\n         0 1 0\\n         0 1 1\\n         1 0 0\\n         1 0 1\\n         1 1 0\\n         1 1 1]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may assume that all inputs are valid vectors whose lengths are at least 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote: The Statistics and Machine Learning toolbox provides two useful functions for full factorial design, namely\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\u003eff2n\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (for binary case) and\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\u003efullfact\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (for general cases). However, they do not directly accomplish the task in Example 1. The purpose of this problem is to create a toolbox independent function to achieve our goal. Have fun!\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":45782,"title":"Upstairs!","description":"The stair has n steps. Every times you can up one or two steps. Give all the different solutions to upstairs.\r\n\r\nFor example\r\nn = 4.\r\n\r\nsols = {[1,1,1,1],[1,1,2],[1,2,1],[2,2]}\r\n\r\nn = 5\r\n\r\nsols = {[1,1,1,1,1],[1,1,1,1,2],[1,1,2,1],[1,2,1,1],[1,2,2],[2,1,1,1],[2,1,2],[2,2,1]}\r\n\r\nHave fun!\r\n\r\n","description_html":"\u003cp\u003eThe stair has n steps. Every times you can up one or two steps. Give all the different solutions to upstairs.\u003c/p\u003e\u003cp\u003eFor example\r\nn = 4.\u003c/p\u003e\u003cp\u003esols = {[1,1,1,1],[1,1,2],[1,2,1],[2,2]}\u003c/p\u003e\u003cp\u003en = 5\u003c/p\u003e\u003cp\u003esols = {[1,1,1,1,1],[1,1,1,1,2],[1,1,2,1],[1,2,1,1],[1,2,2],[2,1,1,1],[2,1,2],[2,2,1]}\u003c/p\u003e\u003cp\u003eHave fun!\u003c/p\u003e","function_template":"function y = upstairs(x)\r\ny = x;\r\nend","test_suite":"%%\r\nx = [5,10,20]\r\nlen = [8          89       10946];\r\nfor i = 1 : length(x)\r\n    y = upstairs(x(i));\r\n    assert(isequal(unique(cell2mat(y)),1:2));\r\n    assert(isequal(length(unique(cellfun(@num2str,y,'UniformOutput',false))),len(i)));\r\n    assert(isequal(unique(cellfun(@sum,y)),x(i)));\r\nend\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":3668,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":6,"test_suite_updated_at":"2020-06-07T15:42:41.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2020-06-07T15:05:30.000Z","updated_at":"2025-11-18T14:35:19.000Z","published_at":"2020-06-07T15:31:42.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe stair has n steps. Every times you can up one or two steps. Give all the different solutions to upstairs.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example n = 4.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003esols = {[1,1,1,1],[1,1,2],[1,2,1],[2,2]}\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en = 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003esols = {[1,1,1,1,1],[1,1,1,1,2],[1,1,2,1],[1,2,1,1],[1,2,2],[2,1,1,1],[2,1,2],[2,2,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\u003eHave fun!\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":44705,"title":"Expand 10^n to Powers of 4","description":"Given an integer n, return the coefficients \r\n\r\n     c = [c_n,c_n-1,...,c_0]\r\n\r\nSuch that\r\n\r\n    10^n = c_n*4^(n) + c_n-1*4^(n-1) +...+ c_0*4^(0)\r\n\r\nWith the constraint that\r\n\r\n   c_n = c_0\r\n\r\nFor example,\r\n\r\n  n = 1\r\n10^n = 10 = 2*4^(1) + 2*4^(0), so c = [2  2] \r\n","description_html":"\u003cp\u003eGiven an integer n, return the coefficients\u003c/p\u003e\u003cpre\u003e     c = [c_n,c_n-1,...,c_0]\u003c/pre\u003e\u003cp\u003eSuch that\u003c/p\u003e\u003cpre\u003e    10^n = c_n*4^(n) + c_n-1*4^(n-1) +...+ c_0*4^(0)\u003c/pre\u003e\u003cp\u003eWith the constraint that\u003c/p\u003e\u003cpre\u003e   c_n = c_0\u003c/pre\u003e\u003cp\u003eFor example,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003en = 1\r\n10^n = 10 = 2*4^(1) + 2*4^(0), so c = [2  2] \r\n\u003c/pre\u003e","function_template":"function ans = ten2pow4(n)\r\n  \r\nend","test_suite":"%%\r\nn = 0;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 1;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 2;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 3;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 4;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 5;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 6;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n)\u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 7;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 8;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 9;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 10;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end))\u0026coeff(1)\u003e0)\r\n\r\n%%\r\nn = 11;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end))\u0026coeff(1)\u003e0)\r\n\r\n%%\r\nn = 12;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end))\u0026coeff(1)\u003e0)\r\n\r\n%%\r\nn = 13;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end))\u0026coeff(1)\u003e0)\r\n\r\n%%\r\nn = 14;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end))\u0026coeff(1)\u003e0)\r\n\r\n%%\r\nn = 15;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end))\u0026coeff(1)\u003e0)\r\n\r\n%%\r\nn = 16;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)","published":true,"deleted":false,"likes_count":5,"comments_count":3,"created_by":178544,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":48,"test_suite_updated_at":"2018-08-14T12:07:53.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-08-02T21:15:38.000Z","updated_at":"2026-03-31T14:15:54.000Z","published_at":"2018-08-02T21:19: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\u003eGiven an integer n, return the coefficients\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[     c = [c_n,c_n-1,...,c_0]]]\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\u003eSuch that\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    10^n = c_n*4^(n) + c_n-1*4^(n-1) +...+ c_0*4^(0)]]\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\u003eWith the constraint that\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[   c_n = c_0]]\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 example,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[n = 1\\n10^n = 10 = 2*4^(1) + 2*4^(0), so c = [2  2]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":2949,"title":"Combination logic","description":"Create an algorithm in MATLAB that calculate the combination for the given positive integers n and k as inputs. When k \u003e n, the result is 0. The formula of the combination, for n \u003e= k, can be seen below:\r\n\r\n\u003c\u003chttp://imageshack.com/a/img540/5995/Q17BWT.png\u003e\u003e","description_html":"\u003cp\u003eCreate an algorithm in MATLAB that calculate the combination for the given positive integers n and k as inputs. When k \u0026gt; n, the result is 0. The formula of the combination, for n \u0026gt;= k, can be seen below:\u003c/p\u003e\u003cimg src = \"http://imageshack.com/a/img540/5995/Q17BWT.png\"\u003e","function_template":"function y = combine(n,k)\r\n  y = n+k;\r\nend","test_suite":"%%\r\nn = 2;\r\nk = 3;\r\ny_correct = 0;\r\nassert(isequal(combine(n,k),y_correct))\r\n\r\n%%\r\nn = 3;\r\nk = 2;\r\ny_correct = 3;\r\nassert(isequal(combine(n,k),y_correct))\r\n\r\n%%\r\nn = 80;\r\nk = 3;\r\ny_correct = 82160;\r\nassert(isequal(combine(n,k),y_correct))\r\n\r\n%%\r\nn = 45;\r\nk = 6;\r\ny_correct = 8145060;\r\nassert(isequal(combine(n,k),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":33785,"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":1,"created_at":"2015-02-04T22:09:30.000Z","updated_at":"2026-02-20T13:40:48.000Z","published_at":"2015-02-04T22:09:38.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/media/image1.png\"}],\"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\u003eCreate an algorithm in MATLAB that calculate the combination for the given positive integers n and k as inputs. When k \u0026gt; n, the result is 0. The formula of the combination, for n \u0026gt;= k, can be seen below:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"relationshipId\\\" w:val=\\\"rId1\\\"/\u003e\u003c/w:customXmlPr\u003e\u003c/w:customXml\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"},{\"partUri\":\"/media/image1.png\",\"contentType\":\"image/png\",\"content\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAADAFBMVEV4eHiTk5P29vaBgYGcnJzAwMC3t7eKiorS0tLt7e3b29vk5OTJycn///9vb28AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD61b95AAAAyklEQVR42q2SSQ6FIAxAWzQxkcj976lEE5R+hojQOmw+Cxa8RwcoGnhf6oNDD0AvGL8j/E2wC+JiXwSaAKbbatGkLjBrX13szynmtPXnKc2eCRiMGQtXxrq2hmZRuuXx6SVdPlPpopeC387sFMMIwdsyAMFAEcHuptW5oIaKYgjHBBoZ512snMeJ8g7o0DmA5jwKXRdqy9W6gfMzhd7iMOySlxq0qn/z4leR43HNQ8WrLtYi1Dz+pnjsmt/8ZsulwLgQOOeC4EyQHH5z1GUZiLNTtwAAAABJRU5ErkJggg==\"}]}"},{"id":44737,"title":"Get the combinations","description":"Consider\r\np,q = 2 vectors of same or different length.\r\nGet a Output Array which has all the possible combinations of Elements of vectors p and q\r\nfor example: \r\n\r\n  p = [1 2 3], q = [10 12]\r\nthen \r\n\r\n  Output = [1 10;2 10;3 10;1 12;2 12;3 12]\r\n","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: 133.733px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 66.8667px; transform-origin: 407px 66.8667px; 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\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: 362px 8px; transform-origin: 362px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eConsider p,q = 2 vectors of same or different length. Get a Output Array which has all the possible combinations of Elements of vectors p and q for example:\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: 96px 8.5px; transform-origin: 96px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ep = [1 2 3], q = [10 12]\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: 20px 8.5px; transform-origin: 20px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ethen \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: 0px 8.5px; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\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: 160px 8.5px; transform-origin: 160px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eOutput = [1 10;2 10;3 10;1 12;2 12;3 12]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = combineit(p,q)\r\n  y = {p.*q};\r\nend","test_suite":"%%\r\np=[10:15]\r\nq=[2:5]\r\ny_correct = [10     2;\r\n    11     2;\r\n    12     2;\r\n    13     2;\r\n    14     2;\r\n    15     2;\r\n    10     3;\r\n    11     3;\r\n    12     3;\r\n    13     3;\r\n    14     3;\r\n    15     3;\r\n    10     4;\r\n    11     4;\r\n    12     4;\r\n    13     4;\r\n    14     4;\r\n    15     4;\r\n    10     5;\r\n    11     5;\r\n    12     5;\r\n    13     5;\r\n    14     5;\r\n    15     5]\r\nassert(isequal(combineit(p,q),y_correct))\r\n\r\n%%\r\np=[-2:2];\r\nq=[-1 0 1];\r\ny_correct = [-2    -1     0     1     2    -2    -1     0     1     2    -2    -1     0     1     2\r\n    -1    -1    -1    -1    -1     0     0     0     0     0     1     1     1     1     1]'; \r\nassert(isequal(combineit(p,q),y_correct))\r\n\r\n%%\r\np=[1 1 2 3 5 8 13];\r\nq=[1.618];\r\ny_correct = [1 1.618; 1 1.618; 2 1.618; 3 1.618; 5 1.618; 8 1.618; 13 1.618];  \r\nassert(isequal(combineit(p,q),y_correct))\r\n\r\n%%\r\np=[0 0.5 1];\r\nq=[exp(1) pi];\r\ny_correct = [0 exp(1); 0.5 exp(1); 1 exp(1); 0 pi; 0.5 pi; 1 pi]\r\nassert(isequal(combineit(p,q),y_correct))\r\n\r\n%%\r\np=[];\r\nq=[];\r\nassert(isempty(combineit(p,q)))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":136465,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":"2021-05-09T10:37:16.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2018-09-11T12:58:36.000Z","updated_at":"2026-04-03T07:15:22.000Z","published_at":"2018-09-11T12:58:36.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\u003eConsider p,q = 2 vectors of same or different length. Get a Output Array which has all the possible combinations of Elements of vectors p and q for example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[p = [1 2 3], q = [10 12]\\nthen \\n\\nOutput = [1 10;2 10;3 10;1 12;2 12;3 12]]]\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":60927,"title":" Pairs with Given Sum","description":"Given an array of integers and a target sum, return all unique pairs whose sum is equal to the target. The output should be a matrix with 2 columns representing each pair.\r\nAssume pairs are unordered, i.e., (2, 3) and (3, 2) are considered the same pair.  \r\ntry to maintain the sequence as the numbers appear in the input array.\r\n","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 143.438px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 408px 71.7125px; transform-origin: 408px 71.7188px; 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: 385px 21px; text-align: left; transform-origin: 385px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven an array of integers and a target sum, return all unique pairs whose sum is equal to the target. The output should be a matrix with 2 columns representing each pair.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAssume pairs are unordered, i.e., (2, 3) and (3, 2) are considered the same pair.\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e  \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 20.4375px; 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: 392px 10.2125px; transform-origin: 392px 10.2188px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"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: 364px 10.2125px; text-align: left; transform-origin: 364px 10.2188px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003etry to maintain the sequence as the numbers appear in the input array.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; 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 y = sum_pair(x,s)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1, 2, 3, 4, 5];\r\ns=6;\r\ny_correct = [1,5; 2,4];\r\nassert(isequal(sum_pair(x,s),y_correct))\r\n\r\n%%\r\nx = [15, 5, 20];\r\ns=25;\r\ny_correct = [5, 20];\r\nassert(isequal(sum_pair(x,s),y_correct))\r\n\r\n\r\n%%\r\nx = [15, 5, 20];\r\ns= 5;\r\ny_correct = [];\r\nassert(isempty(sum_pair(x,s)))\r\n\r\n%%\r\nx = [5, 1, 3, 7, 5, 9, 2, 8, 4, 6, 0, -1, 10, 3, 7];\r\ns= 10;\r\ny_correct = [ 5, 5; 1, 9; 3, 7; 4, 6; 2, 8; 0, 10];\r\nassert(isequal(size(sum_pair(x,s)), [6,2]))\r\nassert(isequal(sum(sum_pair(x,s),'all'), 60))","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":10,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2025-06-02T12:36:47.000Z","updated_at":"2025-12-31T15:00:18.000Z","published_at":"2025-06-02T12:36:47.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an array of integers and a target sum, return all unique pairs whose sum is equal to the target. The output should be a matrix with 2 columns representing each pair.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssume pairs are unordered, i.e., (2, 3) and (3, 2) are considered the same pair.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e  \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003etry to maintain the sequence as the numbers appear in the input array.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\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":42790,"title":"Full combinations","description":"Given n input vectors x1, x2, …, xn, generate a p*n matrix y whose rows contain all element-wise combinations of the vectors x1, x2, …, xn, where p = numel(x1)*numel(x2)*…* numel(xn). The rows of y are organized in an \"increasing\" ordering; see examples below.  \r\n\r\n* Example 1 (character array, n = 2): Input: x1 = 'ab'; x2 = 'cde'; Output: \r\n\r\n\r\n    y = ['ac'\r\n         'ad'\r\n         'ae'\r\n         'bc'\r\n         'bd'\r\n         'be'] \r\n\r\n\r\n* Example 2 (numeric array, n = 3): Input: x1 = [0 1], x2 = [0 1]; x3 = [0 1]; Output: \r\n\r\n    y = [0 0 0\r\n         0 0 1\r\n         0 1 0\r\n         0 1 1\r\n         1 0 0\r\n         1 0 1\r\n         1 1 0\r\n         1 1 1]\r\n\r\n\r\nYou may assume that all inputs are valid vectors whose lengths are at least 1. \r\n \r\n\r\nNote: The Statistics and Machine Learning toolbox provides two useful functions for full factorial design, namely *ff2n* (for binary case) and *fullfact* (for general cases). However, they do not directly accomplish the task in Example 1. The purpose of this problem is to create a toolbox independent function to achieve our goal. Have fun!\r\n","description_html":"\u003cp\u003eGiven n input vectors x1, x2, …, xn, generate a p*n matrix y whose rows contain all element-wise combinations of the vectors x1, x2, …, xn, where p = numel(x1)*numel(x2)*…* numel(xn). The rows of y are organized in an \"increasing\" ordering; see examples below.\u003c/p\u003e\u003cul\u003e\u003cli\u003eExample 1 (character array, n = 2): Input: x1 = 'ab'; x2 = 'cde'; Output:\u003c/li\u003e\u003c/ul\u003e\u003cpre\u003e    y = ['ac'\r\n         'ad'\r\n         'ae'\r\n         'bc'\r\n         'bd'\r\n         'be'] \u003c/pre\u003e\u003cul\u003e\u003cli\u003eExample 2 (numeric array, n = 3): Input: x1 = [0 1], x2 = [0 1]; x3 = [0 1]; Output:\u003c/li\u003e\u003c/ul\u003e\u003cpre\u003e    y = [0 0 0\r\n         0 0 1\r\n         0 1 0\r\n         0 1 1\r\n         1 0 0\r\n         1 0 1\r\n         1 1 0\r\n         1 1 1]\u003c/pre\u003e\u003cp\u003eYou may assume that all inputs are valid vectors whose lengths are at least 1.\u003c/p\u003e\u003cp\u003eNote: The Statistics and Machine Learning toolbox provides two useful functions for full factorial design, namely \u003cb\u003eff2n\u003c/b\u003e (for binary case) and \u003cb\u003efullfact\u003c/b\u003e (for general cases). However, they do not directly accomplish the task in Example 1. The purpose of this problem is to create a toolbox independent function to achieve our goal. Have fun!\u003c/p\u003e","function_template":"function y = myfullfact(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx1 = [0 1]; x2 = [0 1]; x3 = [0 1];\r\ny_correct = [0 0 0\r\n             0 0 1\r\n             0 1 0\r\n             0 1 1\r\n             1 0 0\r\n             1 0 1\r\n             1 1 0\r\n             1 1 1];\r\nassert(isequal(myfullfact(x1,x2,x3),y_correct))\r\n\r\n%%\r\nx1 = [0 1]; x2 = [-1]; x3 = [-1 0 1];\r\ny_correct = [0  -1  -1\r\n             0  -1   0\r\n             0  -1   1\r\n             1  -1  -1\r\n             1  -1   0\r\n             1  -1   1];\r\nassert(isequal(myfullfact(x1,x2,x3),y_correct))\r\n\r\n%% \r\nx1 = 0; x2 = 2; x3 = 4; x4 = 8; x5 = 7; x6 = 6; x7 = 4; x8 = 1; x9 = 1; x10 = 0;\r\ny_correct = [x1 x2 x3 x4 x5 x6 x7 x8 x9 x10];\r\nassert(isequal(myfullfact(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10),y_correct))\r\n\r\n%%\r\nx1 = 'ab'; x2 = 'cde';\r\ny_correct = ['ac'\r\n             'ad'\r\n             'ae'\r\n             'bc'\r\n             'bd'\r\n             'be'];\r\nassert(isequal(myfullfact(x1,x2),y_correct))\r\n\r\n%%\r\nx1 = 'a'; x2 = 'a'; x3 = 'z';\r\ny_correct = 'aaz';\r\nassert(isequal(myfullfact(x1,x2,x3),y_correct))\r\n\r\n%%\r\nx1 = '!@#'; x2 = '23';\r\ny_correct = ['!2'\r\n             '!3'\r\n             '@2'\r\n             '@3'\r\n             '#2'\r\n             '#3'];\r\nassert(isequal(myfullfact(x1,x2),y_correct))\r\n\r\n%%\r\nx1 = '@#'; x2 = 'm'; x3 = 'a'; x4 = 't'; x5 = 'l'; x6 = 'a'; x7 = 'b'; x8 = '$%*';\r\ny_correct = ['@matlab$'\r\n             '@matlab%'\r\n             '@matlab*'\r\n             '#matlab$'\r\n             '#matlab%'\r\n             '#matlab*'];\r\nassert(isequal(myfullfact(x1,x2,x3,x4,x5,x6,x7,x8),y_correct))\r\n\r\n%%\r\n% A manual implementation used to validate other solutions. Please be advised that generalization of this is straightforward but inefficient in terms of Cody size. To get a solution with possibly smaller size, try different ideas please.  \r\nfor iter = 1:20\r\n    a = randi(10,5,1);\r\n    x = arrayfun(@(x)(1:x).',a,'un',0);\r\n    [x1,x2,x3,x4,x5] = deal(x{:});\r\n    y1 = repelem(x1, prod(a(2:5)), 1);\r\n    y2 = repmat(repelem(x2, prod(a(3:5)), 1), a(1), 1);\r\n    y3 = repmat(repelem(x3, prod(a(4:5)), 1), prod(a(1:2)), 1);\r\n    y4 = repmat(repelem(x4, a(5), 1), prod(a(1:3)), 1);\r\n    y5 = repmat(x5, prod(a(1:4)), 1); \r\n    y_correct = [y1, y2, y3, y4, y5];\r\n    assert(isequal(myfullfact(x1,x2,x3,x4,x5),y_correct));\r\nend","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":28,"test_suite_updated_at":"2016-03-29T21:03:54.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-03-29T19:44:39.000Z","updated_at":"2025-12-05T13:12:00.000Z","published_at":"2016-03-29T19:47:42.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven n input vectors x1, x2, …, xn, generate a p*n matrix y whose rows contain all element-wise combinations of the vectors x1, x2, …, xn, where p = numel(x1)*numel(x2)*…* numel(xn). The rows of y are organized in an \\\"increasing\\\" ordering; see examples below.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 1 (character array, n = 2): Input: x1 = 'ab'; x2 = 'cde'; Output:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    y = ['ac'\\n         'ad'\\n         'ae'\\n         'bc'\\n         'bd'\\n         'be']]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 2 (numeric array, n = 3): Input: x1 = [0 1], x2 = [0 1]; x3 = [0 1]; Output:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    y = [0 0 0\\n         0 0 1\\n         0 1 0\\n         0 1 1\\n         1 0 0\\n         1 0 1\\n         1 1 0\\n         1 1 1]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may assume that all inputs are valid vectors whose lengths are at least 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote: The Statistics and Machine Learning toolbox provides two useful functions for full factorial design, namely\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\u003eff2n\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (for binary case) and\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\u003efullfact\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (for general cases). However, they do not directly accomplish the task in Example 1. The purpose of this problem is to create a toolbox independent function to achieve our goal. Have fun!\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":45782,"title":"Upstairs!","description":"The stair has n steps. Every times you can up one or two steps. Give all the different solutions to upstairs.\r\n\r\nFor example\r\nn = 4.\r\n\r\nsols = {[1,1,1,1],[1,1,2],[1,2,1],[2,2]}\r\n\r\nn = 5\r\n\r\nsols = {[1,1,1,1,1],[1,1,1,1,2],[1,1,2,1],[1,2,1,1],[1,2,2],[2,1,1,1],[2,1,2],[2,2,1]}\r\n\r\nHave fun!\r\n\r\n","description_html":"\u003cp\u003eThe stair has n steps. Every times you can up one or two steps. Give all the different solutions to upstairs.\u003c/p\u003e\u003cp\u003eFor example\r\nn = 4.\u003c/p\u003e\u003cp\u003esols = {[1,1,1,1],[1,1,2],[1,2,1],[2,2]}\u003c/p\u003e\u003cp\u003en = 5\u003c/p\u003e\u003cp\u003esols = {[1,1,1,1,1],[1,1,1,1,2],[1,1,2,1],[1,2,1,1],[1,2,2],[2,1,1,1],[2,1,2],[2,2,1]}\u003c/p\u003e\u003cp\u003eHave fun!\u003c/p\u003e","function_template":"function y = upstairs(x)\r\ny = x;\r\nend","test_suite":"%%\r\nx = [5,10,20]\r\nlen = [8          89       10946];\r\nfor i = 1 : length(x)\r\n    y = upstairs(x(i));\r\n    assert(isequal(unique(cell2mat(y)),1:2));\r\n    assert(isequal(length(unique(cellfun(@num2str,y,'UniformOutput',false))),len(i)));\r\n    assert(isequal(unique(cellfun(@sum,y)),x(i)));\r\nend\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":3668,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":6,"test_suite_updated_at":"2020-06-07T15:42:41.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2020-06-07T15:05:30.000Z","updated_at":"2025-11-18T14:35:19.000Z","published_at":"2020-06-07T15:31:42.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe stair has n steps. Every times you can up one or two steps. Give all the different solutions to upstairs.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example n = 4.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003esols = {[1,1,1,1],[1,1,2],[1,2,1],[2,2]}\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en = 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003esols = {[1,1,1,1,1],[1,1,1,1,2],[1,1,2,1],[1,2,1,1],[1,2,2],[2,1,1,1],[2,1,2],[2,2,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\u003eHave fun!\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":44705,"title":"Expand 10^n to Powers of 4","description":"Given an integer n, return the coefficients \r\n\r\n     c = [c_n,c_n-1,...,c_0]\r\n\r\nSuch that\r\n\r\n    10^n = c_n*4^(n) + c_n-1*4^(n-1) +...+ c_0*4^(0)\r\n\r\nWith the constraint that\r\n\r\n   c_n = c_0\r\n\r\nFor example,\r\n\r\n  n = 1\r\n10^n = 10 = 2*4^(1) + 2*4^(0), so c = [2  2] \r\n","description_html":"\u003cp\u003eGiven an integer n, return the coefficients\u003c/p\u003e\u003cpre\u003e     c = [c_n,c_n-1,...,c_0]\u003c/pre\u003e\u003cp\u003eSuch that\u003c/p\u003e\u003cpre\u003e    10^n = c_n*4^(n) + c_n-1*4^(n-1) +...+ c_0*4^(0)\u003c/pre\u003e\u003cp\u003eWith the constraint that\u003c/p\u003e\u003cpre\u003e   c_n = c_0\u003c/pre\u003e\u003cp\u003eFor example,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003en = 1\r\n10^n = 10 = 2*4^(1) + 2*4^(0), so c = [2  2] \r\n\u003c/pre\u003e","function_template":"function ans = ten2pow4(n)\r\n  \r\nend","test_suite":"%%\r\nn = 0;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 1;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 2;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 3;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 4;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 5;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 6;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n)\u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 7;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 8;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 9;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)\r\n\r\n%%\r\nn = 10;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end))\u0026coeff(1)\u003e0)\r\n\r\n%%\r\nn = 11;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end))\u0026coeff(1)\u003e0)\r\n\r\n%%\r\nn = 12;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end))\u0026coeff(1)\u003e0)\r\n\r\n%%\r\nn = 13;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end))\u0026coeff(1)\u003e0)\r\n\r\n%%\r\nn = 14;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end))\u0026coeff(1)\u003e0)\r\n\r\n%%\r\nn = 15;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end))\u0026coeff(1)\u003e0)\r\n\r\n%%\r\nn = 16;\r\ncoeff = ten2pow4(n);\r\nassert(isequal(dot(coeff, 4.^flip(0:n)),10^n) \u0026 isequal(coeff(1),coeff(end)) \u0026 coeff(1)\u003e0)","published":true,"deleted":false,"likes_count":5,"comments_count":3,"created_by":178544,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":48,"test_suite_updated_at":"2018-08-14T12:07:53.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-08-02T21:15:38.000Z","updated_at":"2026-03-31T14:15:54.000Z","published_at":"2018-08-02T21:19: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\u003eGiven an integer n, return the coefficients\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[     c = [c_n,c_n-1,...,c_0]]]\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\u003eSuch that\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    10^n = c_n*4^(n) + c_n-1*4^(n-1) +...+ c_0*4^(0)]]\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\u003eWith the constraint that\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[   c_n = c_0]]\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 example,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[n = 1\\n10^n = 10 = 2*4^(1) + 2*4^(0), so c = [2  2]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"tag:\"combination\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"combination\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"combination\"","","\"","combination","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f7726149b10\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f7726149a70\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f77261491b0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f7726149d90\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f7726149cf0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f7726149c50\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f7726149bb0\u003e":"tag:\"combination\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f7726149bb0\u003e":"tag:\"combination\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"combination\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"combination\"","","\"","combination","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f7726149b10\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f7726149a70\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f77261491b0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f7726149d90\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f7726149cf0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f7726149c50\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f7726149bb0\u003e":"tag:\"combination\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f7726149bb0\u003e":"tag:\"combination\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":2949,"difficulty_rating":"easy"},{"id":44737,"difficulty_rating":"easy"},{"id":60927,"difficulty_rating":"easy-medium"},{"id":42790,"difficulty_rating":"easy-medium"},{"id":45782,"difficulty_rating":"easy-medium"},{"id":44705,"difficulty_rating":"medium"}]}}