{"group":{"group":{"id":2432,"name":"Algorithm I","lockable":false,"created_at":"2020-04-02T00:28:40.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Greedy algorithm\nDynamic Programming","is_default":false,"created_by":363598,"badge_id":62,"featured":false,"trending":false,"solution_count_in_trending_period":10,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":6561,"published":true,"community_created":true,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGreedy algorithm\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\u003eDynamic Programming\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}","description_html":"\u003cdiv style = \"text-align: start; line-height: 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: 51px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 289.5px 25.5px; transform-origin: 289.5px 25.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 266.5px 10.5px; text-align: left; transform-origin: 266.5px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eGreedy algorithm\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: 266.5px 10.5px; text-align: left; transform-origin: 266.5px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eDynamic Programming\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","published_at":"2022-09-08T20:01:52.000Z"},"current_player":null},"problems":[{"id":93,"title":"Calculate the Levenshtein distance between two strings","description":"This problem description is lifted from http://en.wikipedia.org/wiki/Levenshtein_distance.\r\nThe Levenshtein distance between two strings is defined as the minimum number of edits needed to transform one string into the other, with the allowable edit operations being insertion, deletion, or substitution of a single character.\r\nFor example, the Levenshtein distance between \"kitten\" and \"sitting\" is 3, since the following three edits change one into the other, and there is no way to do it with fewer than three edits:\r\n kitten =\u003e sitten  (substitution of 's' for 'k')\r\n sitten =\u003e sittin  (substitution of 'e' for 'i')\r\n sittin =\u003e sitting (insert 'g' at the end).\r\nSo when\r\n s1 = 'kitten'\r\nand\r\n s2 = 'sitting'\r\nthen the distance d is equal to 3.","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: 348.167px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 174.083px; transform-origin: 407px 174.083px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 117.5px 8px; transform-origin: 117.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis problem description is lifted from\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://en.wikipedia.org/wiki/Levenshtein_distance\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehttp://en.wikipedia.org/wiki/Levenshtein_distance\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 381.5px 8px; transform-origin: 381.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe Levenshtein distance between two strings is defined as the minimum number of edits needed to transform one string into the other, with the allowable edit operations being insertion, deletion, or substitution of a single character.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 379px 8px; transform-origin: 379px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, the Levenshtein distance between \"kitten\" and \"sitting\" is 3, since the following three edits change one into the other, and there is no way to do it with fewer than three edits:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 30.65px; transform-origin: 404px 30.65px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 192px 8.5px; tab-size: 4; transform-origin: 192px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 144px 8.5px; transform-origin: 144px 8.5px; \"\u003e kitten =\u0026gt; sitten  (substitution of \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 16px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 16px 8.5px; \"\u003e's' \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(14, 0, 255); border-block-start-color: rgb(14, 0, 255); border-bottom-color: rgb(14, 0, 255); border-inline-end-color: rgb(14, 0, 255); border-inline-start-color: rgb(14, 0, 255); border-left-color: rgb(14, 0, 255); border-right-color: rgb(14, 0, 255); border-top-color: rgb(14, 0, 255); caret-color: rgb(14, 0, 255); color: rgb(14, 0, 255); column-rule-color: rgb(14, 0, 255); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(14, 0, 255); perspective-origin: 16px 8.5px; text-decoration-color: rgb(14, 0, 255); text-emphasis-color: rgb(14, 0, 255); transform-origin: 16px 8.5px; \"\u003efor \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 12px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 12px 8.5px; \"\u003e'k'\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\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: 192px 8.5px; tab-size: 4; transform-origin: 192px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 144px 8.5px; transform-origin: 144px 8.5px; \"\u003e sitten =\u0026gt; sittin  (substitution of \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 16px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 16px 8.5px; \"\u003e'e' \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(14, 0, 255); border-block-start-color: rgb(14, 0, 255); border-bottom-color: rgb(14, 0, 255); border-inline-end-color: rgb(14, 0, 255); border-inline-start-color: rgb(14, 0, 255); border-left-color: rgb(14, 0, 255); border-right-color: rgb(14, 0, 255); border-top-color: rgb(14, 0, 255); caret-color: rgb(14, 0, 255); color: rgb(14, 0, 255); column-rule-color: rgb(14, 0, 255); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(14, 0, 255); perspective-origin: 16px 8.5px; text-decoration-color: rgb(14, 0, 255); text-emphasis-color: rgb(14, 0, 255); transform-origin: 16px 8.5px; \"\u003efor \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 12px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 12px 8.5px; \"\u003e'i'\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\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: 172px 8.5px; tab-size: 4; transform-origin: 172px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 108px 8.5px; transform-origin: 108px 8.5px; \"\u003e sittin =\u0026gt; sitting (insert \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 16px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 16px 8.5px; \"\u003e'g' \u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 48px 8.5px; transform-origin: 48px 8.5px; \"\u003eat the end).\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 27px 8px; transform-origin: 27px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSo when\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 56px 8.5px; tab-size: 4; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 24px 8.5px; transform-origin: 24px 8.5px; \"\u003e s1 = \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 32px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 32px 8.5px; \"\u003e'kitten'\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 12px 8px; transform-origin: 12px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eand\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 60px 8.5px; tab-size: 4; transform-origin: 60px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 24px 8.5px; transform-origin: 24px 8.5px; \"\u003e s2 = \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 36px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 36px 8.5px; \"\u003e'sitting'\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 103px 8px; transform-origin: 103px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ethen the distance d is equal to 3.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function d = levenshtein(s1,s2)\r\n  d = 0;\r\nend","test_suite":"%%\r\nfiletext = fileread('levenshtein.m');\r\nassert(isempty(strfind(filetext, 'switch')))\r\nassert(isempty(strfind(filetext, 'elseif')))\r\n\r\n\r\n%%\r\n\r\ns1 = 'kitten';\r\ns2 = 'sitting';\r\nd_correct = 3;\r\nassert(isequal(levenshtein(s1,s2),d_correct))\r\n\r\n%% \r\n\r\ns1 = 'Saturday';\r\ns2 = 'Sunday';\r\nd_correct = 3;\r\nassert(isequal(levenshtein(s1,s2),d_correct))\r\n\r\n%% \r\n\r\ns1 = 'MATLAB rocks!';\r\ns2 = 'MathWorks';\r\nd_correct = 9;\r\nassert(isequal(levenshtein(s1,s2),d_correct))\r\n\r\n%% \r\n\r\ns1 = 'Four score and seven years ago';\r\ns2 = 'Eighty seven years before today';\r\nd_correct = 25;\r\nassert(isequal(levenshtein(s1,s2),d_correct))\r\n\r\n%% \r\n\r\ns1 = 'Row row row your boat';\r\ns2 = 'Gently down the stream';\r\nd_correct = 18;\r\nassert(isequal(levenshtein(s1,s2),d_correct))\r\n\r\n%%\r\n\r\ns1 = 'ninety-nine bottles of beer on the wall';\r\ns2 = 'eighty-six bottles of beer on the wall';\r\nd_correct = 6;\r\nassert(isequal(levenshtein(s1,s2),d_correct))\r\n\r\n%%\r\n\r\ns1 = 'these are the times that try men''s souls';\r\ns2 = 'soulwise, these are trying times';\r\nd_correct = 27;\r\nassert(isequal(levenshtein(s1,s2),d_correct))\r\n\r\n%%\r\n\r\ns1 = 'abc';\r\ns2 = 'abc';\r\nd_correct = 0;\r\nassert(isequal(levenshtein(s1,s2),d_correct))\r\n\r\n%%\r\n\r\ns1 = 'god';\r\ns2 = 'dog';\r\nd_correct = 2;\r\nassert(isequal(levenshtein(s1,s2),d_correct))","published":true,"deleted":false,"likes_count":25,"comments_count":3,"created_by":1,"edited_by":223089,"edited_at":"2022-11-28T06:34:46.000Z","deleted_by":null,"deleted_at":null,"solvers_count":1507,"test_suite_updated_at":"2022-11-28T06:34:46.000Z","rescore_all_solutions":false,"group_id":2,"created_at":"2012-01-18T01:00:30.000Z","updated_at":"2026-03-02T01:10:11.000Z","published_at":"2012-01-18T01:00:30.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\u003eThis problem description is lifted from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Levenshtein_distance\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://en.wikipedia.org/wiki/Levenshtein_distance\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe Levenshtein distance between two strings is defined as the minimum number of edits needed to transform one string into the other, with the allowable edit operations being insertion, deletion, or substitution of a single character.\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, the Levenshtein distance between \\\"kitten\\\" and \\\"sitting\\\" is 3, since the following three edits change one into the other, and there is no way to do it with fewer than three edits:\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[ kitten =\u003e sitten  (substitution of 's' for 'k')\\n sitten =\u003e sittin  (substitution of 'e' for 'i')\\n sittin =\u003e sitting (insert 'g' at the end).]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSo when\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[ s1 = 'kitten']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eand\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[ s2 = 'sitting']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethen the distance d is equal to 3.\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":2309,"title":"Calculate the Damerau-Levenshtein distance between two strings.","description":"\u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/2303-compute-hamming-distances-between-each-pair-of-rows-from-two-input-matrices Problem 2303\u003e reminded me a few older ones dealing with metrics between strings, problems \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/93-calculate-the-levenshtein-distance-between-two-strings 93\u003e,\r\n\u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/846-calculate-the-hamming-distance-between-two-strings 846\u003e or\r\n\u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/848-calculate-a-modified-levenshtein-distance-between-two-strings 848\u003e\r\n about Hamming and Levenshtein distances.\r\n\r\n\u003chttp://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance Damerau-Levenshtein distance\u003e is an extension to Levenshtein distance. It is also defined as minimum number of simple edit operations on string to change it into another, but the list of allowed operations is extended.\r\n\r\nAs it is written on Wikipedia there are 4 allowed edits: deletion, insertion and substitution of an single character and an transposition of two adjacent characters.\r\n\r\nExample. Such defined distance between words _gifts_ and _profit_ is 5:\r\n\r\n  gifts   =\u003e pgifts    (insertion of 'p')\r\n  pgifts  =\u003e prgifts   (insertion of 'r')\r\n  prgifts =\u003e proifts   (substitution of 'g' to 'o')\r\n  proifts =\u003e profits   (transposition of 'if' to 'fi')\r\n  profits =\u003e profit    (deletion of 's')\r\n  \r\n\r\n","description_html":"\u003cp\u003e\u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/2303-compute-hamming-distances-between-each-pair-of-rows-from-two-input-matrices\"\u003eProblem 2303\u003c/a\u003e reminded me a few older ones dealing with metrics between strings, problems \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/93-calculate-the-levenshtein-distance-between-two-strings\"\u003e93\u003c/a\u003e, \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/846-calculate-the-hamming-distance-between-two-strings\"\u003e846\u003c/a\u003e or \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/848-calculate-a-modified-levenshtein-distance-between-two-strings\"\u003e848\u003c/a\u003e\r\n about Hamming and Levenshtein distances.\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance\"\u003eDamerau-Levenshtein distance\u003c/a\u003e is an extension to Levenshtein distance. It is also defined as minimum number of simple edit operations on string to change it into another, but the list of allowed operations is extended.\u003c/p\u003e\u003cp\u003eAs it is written on Wikipedia there are 4 allowed edits: deletion, insertion and substitution of an single character and an transposition of two adjacent characters.\u003c/p\u003e\u003cp\u003eExample. Such defined distance between words \u003ci\u003egifts\u003c/i\u003e and \u003ci\u003eprofit\u003c/i\u003e is 5:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003egifts   =\u0026gt; pgifts    (insertion of 'p')\r\npgifts  =\u0026gt; prgifts   (insertion of 'r')\r\nprgifts =\u0026gt; proifts   (substitution of 'g' to 'o')\r\nproifts =\u0026gt; profits   (transposition of 'if' to 'fi')\r\nprofits =\u0026gt; profit    (deletion of 's')\r\n\u003c/pre\u003e","function_template":"function distance = Damerau_Levenshtein(str1,str2)\r\n  distance = 0;\r\nend","test_suite":"%%\r\nassert(isequal(Damerau_Levenshtein('mom','dad'),3));\r\n% 3 substitutions\r\n%%\r\nassert(isequal(Damerau_Levenshtein('dogs','dog'),1));\r\n% 1 deletion\r\n%%\r\nassert(isequal(Damerau_Levenshtein('true','true'),0));\r\n% identity\r\n%%\r\nassert(isequal(Damerau_Levenshtein('true','false'),4));\r\n% 1 insertion, 3 substitutions\r\n%%\r\nassert(isequal(Damerau_Levenshtein('abc','ca'),2));\r\n% 1 deletion, 1 transposition\r\n%%\r\nassert(isequal(Damerau_Levenshtein('tee','tree'),1));\r\n%%\r\nassert(isequal(Damerau_Levenshtein('email','mails'),2));\r\n%%\r\nassert(isequal(Damerau_Levenshtein('profit','gifts'),5));\r\n%%\r\n% symmetry\r\nrnd=@()char(randi([97 122],1,randi([4 10])));\r\nfor k=1:10\r\n  str1=rnd();\r\n  str2=rnd();\r\n  a=Damerau_Levenshtein(str1,str2);\r\n  b=Damerau_Levenshtein(str2,str1);\r\n  assert(isequal(a,b))\r\nend\r\n%%\r\n% trinagle inequality\r\nrnd=@()char(randi([97 122],1,randi([4 10])));\r\nfor k=1:50\r\n  str1=rnd();\r\n  str2=rnd();\r\n  str3=rnd();\r\n  a=Damerau_Levenshtein(str2,str3);\r\n  b=Damerau_Levenshtein(str3,str1);\r\n  c=Damerau_Levenshtein(str1,str2);\r\n  assert(a+b\u003e=c)\r\nend","published":true,"deleted":false,"likes_count":1,"comments_count":8,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":45,"test_suite_updated_at":"2014-05-07T12:40:15.000Z","rescore_all_solutions":false,"group_id":32,"created_at":"2014-05-07T12:34:17.000Z","updated_at":"2026-03-26T02:24:43.000Z","published_at":"2014-05-07T12:40:15.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:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/matlabcentral/cody/problems/2303-compute-hamming-distances-between-each-pair-of-rows-from-two-input-matrices\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 2303\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e reminded me a few older ones dealing with metrics between strings, problems\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/matlabcentral/cody/problems/93-calculate-the-levenshtein-distance-between-two-strings\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e93\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/matlabcentral/cody/problems/846-calculate-the-hamming-distance-between-two-strings\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e846\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e or\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/matlabcentral/cody/problems/848-calculate-a-modified-levenshtein-distance-between-two-strings\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e848\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e about Hamming and Levenshtein distances.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDamerau-Levenshtein distance\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is an extension to Levenshtein distance. It is also defined as minimum number of simple edit operations on string to change it into another, but the list of allowed operations is extended.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs it is written on Wikipedia there are 4 allowed edits: deletion, insertion and substitution of an single character and an transposition of two adjacent characters.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample. Such defined distance between words\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003egifts\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eprofit\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is 5:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[gifts   =\u003e pgifts    (insertion of 'p')\\npgifts  =\u003e prgifts   (insertion of 'r')\\nprgifts =\u003e proifts   (substitution of 'g' to 'o')\\nproifts =\u003e profits   (transposition of 'if' to 'fi')\\nprofits =\u003e profit    (deletion of 's')]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":45385,"title":"Coin distribution","description":"Imagine, u r in a shop. ur bill is n(2200). u want to pay the bill with minimum no of coins u have.\r\n\r\nu've coins of - 2000,1000,500,100,50,20,10,5,2,1.\r\n\r\nThere are multiple ways to do that but due to the imposed condition, the correct solution for the above scenario is -\r\n\r\n   2000 - 1\r\n    100 - 2\r\n\r\nthe output should be a 2D matrix of size 2-by-x; where the 1st row contains the coins u used and 2nd row contains how many. \r\n\r\n  out=[2000 100;\r\n          1   2]","description_html":"\u003cp\u003eImagine, u r in a shop. ur bill is n(2200). u want to pay the bill with minimum no of coins u have.\u003c/p\u003e\u003cp\u003eu've coins of - 2000,1000,500,100,50,20,10,5,2,1.\u003c/p\u003e\u003cp\u003eThere are multiple ways to do that but due to the imposed condition, the correct solution for the above scenario is -\u003c/p\u003e\u003cpre\u003e   2000 - 1\r\n    100 - 2\u003c/pre\u003e\u003cp\u003ethe output should be a 2D matrix of size 2-by-x; where the 1st row contains the coins u used and 2nd row contains how many.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eout=[2000 100;\r\n        1   2]\r\n\u003c/pre\u003e","function_template":"function out = coin(n)","test_suite":"%%\r\ny=[2000         100\r\n      1           2]\r\nassert(isequal(coin(2200),y))\r\n\r\n%%\r\ny=[100,20,2;2,1,1]\r\nassert(isequal(coin(222),y))\r\n\r\n%%\r\ny=[2000         500         100          50          20          10           5           2           1\r\n    3           1           2           1           1           1           1           1           1]\r\nassert(isequal( coin(6788),y))\r\n\r\n%%\r\ny=[2000         100          20           5           2           1\r\n   56728           3           2           1           1           1]\r\nassert(isequal(  coin(113456348),y))\r\n\r\n%%\r\ny=[2;2]\r\nassert(isequal( coin(4),y))\r\n\r\n%%\r\ny=[1000         100          20           5           2\r\n           1           4           2           1           2]\r\nassert(isequal( coin(1449),y))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":46,"test_suite_updated_at":"2020-03-24T19:30:04.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-03-24T18:58:31.000Z","updated_at":"2026-02-09T18:16:23.000Z","published_at":"2020-03-24T19:30:04.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\u003eImagine, u r in a shop. ur bill is n(2200). u want to pay the bill with minimum no of coins u have.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eu've coins of - 2000,1000,500,100,50,20,10,5,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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are multiple ways to do that but due to the imposed condition, the correct solution for the above scenario is -\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   2000 - 1\\n    100 - 2]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethe output should be a 2D matrix of size 2-by-x; where the 1st row contains the coins u used and 2nd row contains how many.\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[out=[2000 100;\\n        1   2]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":45422,"title":"Coin Distribution - 02 ","description":"Prev prob \u003chttps://www.mathworks.com/matlabcentral/cody/problems/45385-coin-distribution\u003e\r\n\r\nGiven a set of coins and an amount, find out how many ways the amount can be made using the coins given.\r\nAssume, there is an infinite supply of all the coins.\r\n\r\nFor instance,\r\n\r\n Amount = 10\r\n Coins  = [ 2,3,5]\r\n\r\n possible ways are - [2,2,2,2,2],[2,3,5],[5,5],[2,2,3,3]\r\n so total no. of ways = 4.","description_html":"\u003cp\u003ePrev prob \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/45385-coin-distribution\"\u003ehttps://www.mathworks.com/matlabcentral/cody/problems/45385-coin-distribution\u003c/a\u003e\u003c/p\u003e\u003cp\u003eGiven a set of coins and an amount, find out how many ways the amount can be made using the coins given.\r\nAssume, there is an infinite supply of all the coins.\u003c/p\u003e\u003cp\u003eFor instance,\u003c/p\u003e\u003cpre\u003e Amount = 10\r\n Coins  = [ 2,3,5]\u003c/pre\u003e\u003cpre\u003e possible ways are - [2,2,2,2,2],[2,3,5],[5,5],[2,2,3,3]\r\n so total no. of ways = 4.\u003c/pre\u003e","function_template":"function out = coin_lev(coins,amount)","test_suite":"%%\r\ncoins= [ 2,3,5];\r\namount = 10;\r\nassert(isequal(coin_lev(coins,amount),4))\r\n\r\n%%\r\ncoins= [2,3,5,10];\r\namount = 15;\r\nassert(isequal(coin_lev(coins,amount),9))\r\n\r\n%%\r\ncoins= [ 2,3,5];\r\namount = 50;\r\nassert(isequal(coin_lev(coins,amount),51))\r\n\r\n%%\r\ncoins= [2,5,10,1,20];\r\namount = 1225;\r\nassert(isequal(coin_lev(coins,amount),49884828))\r\n\r\n%%\r\ncoins= [ 11,19,23];\r\namount = 12252;\r\nassert(isequal(coin_lev(coins,amount),15681))\r\n%%\r\ncoins= [ 11,19,23,100];\r\namount = 50;\r\nassert(isequal(coin_lev(coins,amount),0))\r\n\r\n%%\r\ncoins= [1,2,3,4,5,8,10,15,20,25];\r\namount = 200;\r\nassert(isequal(coin_lev(coins,amount),119495730))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":32,"test_suite_updated_at":"2020-04-02T19:38:33.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-04-02T19:03:04.000Z","updated_at":"2026-02-09T20:05:28.000Z","published_at":"2020-04-02T19:38:33.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrev prob\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/45385-coin-distribution\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://www.mathworks.com/matlabcentral/cody/problems/45385-coin-distribution\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a set of coins and an amount, find out how many ways the amount can be made using the coins given. Assume, there is an infinite supply of all the coins.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 instance,\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[ Amount = 10\\n Coins  = [ 2,3,5]\\n\\n possible ways are - [2,2,2,2,2],[2,3,5],[5,5],[2,2,3,3]\\n so total no. of ways = 4.]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":2126,"title":"Split bread like the Pharaohs - Egyptian fractions and greedy algorithm","description":"How would you split 5 loaves of bread among 8 people in all fairness? Get a hint from the Pharaohs. 5/8 = 4/8 + 1/8 , i.e. each receives 1/2 of loaf plus 1/8 - splitting 4 loaves into 1/2 and then the last loaf into 8 pieces.\r\nEgyptian fraction is writing any rational number p/q in terms of unity fractions;\r\ne.g.  \r\n\r\n        3/4 = 1/2 + 1/4, OR \r\n            = 1/3 + 1/4 + 1/6\r\n\r\n      13/48 = 1/4 + 1/48\r\nWrite a program to return the Egyptian fraction of a given rational number p, q. You outputs in the above cases should be the series of denominator values,\r\n    i.e.   egyptian_fraction( 13, 48) should return [4,48],\r\nYou can use simple greedy algorithm or alternatives.\r\nReferences\r\nhttp://en.wikipedia.org/wiki/Egyptian_fraction\r\nAMS blog post by Tyler Clark (@tylermath12) http://blogs.ams.org/jmm2014/2014/01/17/friday-morning-math-fun/\r\nBonus points if you can enumerate all possible Egyptian fractions of (p,q), but thats a problem for another day.\r\nP.S: Updated test suite to check for proper solutions only","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: 460.333px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 230.167px; transform-origin: 407px 230.167px; 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: 379.5px 8px; transform-origin: 379.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eHow would you split 5 loaves of bread among 8 people in all fairness? Get a hint from the Pharaohs. 5/8 = 4/8 + 1/8 , i.e. each receives 1/2 of loaf plus 1/8 - splitting 4 loaves into 1/2 and then the last loaf into 8 pieces.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 242px 8px; transform-origin: 242px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eEgyptian fraction is writing any rational number p/q in terms of unity fractions;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 122.6px; 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 61.3px; transform-origin: 404px 61.3px; 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: 24px 8.5px; tab-size: 4; transform-origin: 24px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ee.g.  \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; tab-size: 4; 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: 112px 8.5px; tab-size: 4; transform-origin: 112px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        3/4 = 1/2 + 1/4, OR \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: 116px 8.5px; tab-size: 4; transform-origin: 116px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e            = 1/3 + 1/4 + 1/6\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; tab-size: 4; 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: 96px 8.5px; tab-size: 4; transform-origin: 96px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e      13/48 = 1/4 + 1/48\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 383.5px 8px; transform-origin: 383.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a program to return the Egyptian fraction of a given rational number p, q. You outputs in the above cases should be the series of denominator values,\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 236px 8.5px; tab-size: 4; transform-origin: 236px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 180px 8.5px; transform-origin: 180px 8.5px; \"\u003e    i.e.   egyptian_fraction( 13, 48) should \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 52px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 52px 8.5px; \"\u003ereturn [4,48]\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003e,\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 165px 8px; transform-origin: 165px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou can use simple greedy algorithm or alternatives.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 41px 8px; transform-origin: 41px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eReferences\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 61.3px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: decimal; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 30.65px; transform-origin: 391px 30.65px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehttp://en.wikipedia.org/wiki/Egyptian_fraction\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 142px 8px; transform-origin: 142px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAMS blog post by Tyler Clark (@tylermath12)\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehttp://blogs.ams.org/jmm2014/2014/01/17/friday-morning-math-fun/\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 347px 8px; transform-origin: 347px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eBonus points if you can enumerate all possible Egyptian fractions of (p,q), but thats a problem for another day.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 178px 8px; transform-origin: 178px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eP.S: Updated test suite to check for proper solutions only\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function denoms = egyptian_fraction(p,q)\r\n  denoms = [];\r\n  \r\n  if ( p == 1 )\r\n     denoms(end+1) = q;\r\n     return;\r\n  end\r\n  % treat other cases..\r\nend","test_suite":"%%\r\n% Updated test suite to remove trivial solutions;\r\n\r\n%%\r\n Vmin = 13; Vmax = 48;\r\n arr = egyptian_fraction(Vmin,Vmax);\r\n assert(isequal(arr, [4 48]))\r\n \r\n%%\r\n Vmin = 3; Vmax = 4;\r\n arr = egyptian_fraction(Vmin,Vmax);\r\n assert(isequal(arr, [2 4]) || isequal(arr, [3 4 6]))\r\n \r\n%%\r\n Vmin = 2;\r\n in = primes(20);\r\n Vmax = in(randi(numel(in)));\r\n arr = egyptian_fraction(Vmin,Vmax);\r\n l=lcm(arr(1),arr(2));\r\n for k=3:numel(arr)\r\n     l=lcm(l,arr(k));\r\n end\r\n assert(isequal(sum(arr),sum(l./arr)/(Vmax/l)))\r\n \r\n \r\n%%\r\n% Small\r\n Vmin = 10; Vmax = 55;\r\n denom = floor(unique(egyptian_fraction(Vmin,Vmax)));\r\n\r\n egyptian_value = sum(1./denom);\r\n\r\n rel_tol = Vmin/Vmax*1e-6;\r\n actual_error = abs( egyptian_value - Vmin/Vmax );\r\n assert(isequal(actual_error \u003c rel_tol ,true))\r\n\r\n%%\r\n% Pie\r\n Vmin = 113; Vmax = 355;\r\n denom = floor(unique(egyptian_fraction(Vmin,Vmax)));\r\n\r\n egyptian_value = sum(1./denom);\r\n\r\n rel_tol = Vmin/Vmax*1e-6;\r\n actual_error = abs( egyptian_value - Vmin/Vmax );\r\n assert(isequal(actual_error \u003c rel_tol ,true))\r\n\r\n%%\r\n% Ramanujan\r\n Vmin = 1023; Vmax = 1729;\r\n denom = floor(unique(egyptian_fraction(Vmin,Vmax)));\r\n\r\n egyptian_value = sum(1./denom);\r\n\r\n rel_tol = Vmin/Vmax*1e-6;\r\n actual_error = abs( egyptian_value - Vmin/Vmax );\r\n assert(isequal(actual_error \u003c rel_tol ,true))\r\n\r\n%%\r\n% E\r\n Vmin = 27; Vmax = 183;\r\n denom = floor(unique(egyptian_fraction(Vmin,Vmax)));\r\n egyptian_value = sum(1./denom);\r\n\r\n rel_tol = Vmin/Vmax*1e-6;\r\n actual_error = abs( egyptian_value - Vmin/Vmax );\r\n assert(isequal(actual_error \u003c rel_tol ,true))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":5,"created_by":3378,"edited_by":223089,"edited_at":"2023-03-29T14:08:28.000Z","deleted_by":null,"deleted_at":null,"solvers_count":96,"test_suite_updated_at":"2023-03-29T14:08:28.000Z","rescore_all_solutions":false,"group_id":38,"created_at":"2014-01-19T06:15:39.000Z","updated_at":"2026-03-31T17:38:29.000Z","published_at":"2014-01-19T17:44:14.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\u003eHow would you split 5 loaves of bread among 8 people in all fairness? Get a hint from the Pharaohs. 5/8 = 4/8 + 1/8 , i.e. each receives 1/2 of loaf plus 1/8 - splitting 4 loaves into 1/2 and then the last loaf into 8 pieces.\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\u003eEgyptian fraction is writing any rational number p/q in terms of unity fractions;\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[e.g.  \\n\\n        3/4 = 1/2 + 1/4, OR \\n            = 1/3 + 1/4 + 1/6\\n\\n      13/48 = 1/4 + 1/48]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a program to return the Egyptian fraction of a given rational number p, q. You outputs in the above cases should be the series of denominator values,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    i.e.   egyptian_fraction( 13, 48) should return [4,48],]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou can use simple greedy algorithm or alternatives.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eReferences\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://en.wikipedia.org/wiki/Egyptian_fraction\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAMS blog post by Tyler Clark (@tylermath12)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://blogs.ams.org/jmm2014/2014/01/17/friday-morning-math-fun/\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBonus points if you can enumerate all possible Egyptian fractions of (p,q), but thats a problem for another day.\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\u003eP.S: Updated test suite to check for proper solutions only\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":45425,"title":"The Tortoise and the Hare - 01","description":"Suppose in an infinitely long line, the hare is standing in position 0.\r\n\r\nFrom that place, it can jump either in the +ve direction or in the -ve [but not both].\r\n\r\nOne condition is that, in i-th jump, it can move i step. Meaning -\r\n  \r\n  0\r\n1  [1st step \u003e\u003e so 0+1]\r\n3  [2nd step \u003e\u003e so 1+2]\r\n6\r\n10\r\n\r\nGiven a position x, determine whether the hare will be in that position or not. \r\n\r\nFor example, \r\n\r\n if x=15 then true \r\n if x=14 then false.\r\n\r\nSimilar problem \u003chttps://www.mathworks.com/matlabcentral/cody/problems/45347-cat-s-paw-01\u003e","description_html":"\u003cp\u003eSuppose in an infinitely long line, the hare is standing in position 0.\u003c/p\u003e\u003cp\u003eFrom that place, it can jump either in the +ve direction or in the -ve [but not both].\u003c/p\u003e\u003cp\u003eOne condition is that, in i-th jump, it can move i step. Meaning -\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e0\r\n1  [1st step \u0026gt;\u0026gt; so 0+1]\r\n3  [2nd step \u0026gt;\u0026gt; so 1+2]\r\n6\r\n10\r\n\u003c/pre\u003e\u003cp\u003eGiven a position x, determine whether the hare will be in that position or not.\u003c/p\u003e\u003cp\u003eFor example,\u003c/p\u003e\u003cpre\u003e if x=15 then true \r\n if x=14 then false.\u003c/pre\u003e\u003cp\u003eSimilar problem \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/45347-cat-s-paw-01\"\u003ehttps://www.mathworks.com/matlabcentral/cody/problems/45347-cat-s-paw-01\u003c/a\u003e\u003c/p\u003e","function_template":"function tf = rabbit_02(x)","test_suite":"%%\r\nassert(isequal(rabbit_02(15),1))\r\n%%\r\nassert(isequal(rabbit_02(45),1))\r\n%%\r\nassert(isequal(rabbit_02(555),0))\r\n%%\r\nassert(isequal(rabbit_02(25651),1))\r\n%%\r\nassert(isequal(rabbit_02(-256514),0))\r\n%%\r\nassert(isequal(rabbit_02(-2566245),1))\r\n%%\r\nassert(isequal(rabbit_02(10011),1))\r\n%%\r\nassert(isequal(rabbit_02(9191),0))\r\n%%\r\nassert(isequal(rabbit_02(9191985078),1))\r\n%%\r\nassert(isequal(rabbit_02(-111222333),0))\r\n%%\r\nassert(isequal(rabbit_02(-111236070),1))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":53,"test_suite_updated_at":"2020-04-07T04:52:58.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-04-07T04:44:29.000Z","updated_at":"2026-02-09T21:15:15.000Z","published_at":"2020-04-07T04:52:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSuppose in an infinitely long line, the hare is standing in position 0.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFrom that place, it can jump either in the +ve direction or in the -ve [but not both].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOne condition is that, in i-th jump, it can move i step. Meaning -\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[0\\n1  [1st step \u003e\u003e so 0+1]\\n3  [2nd step \u003e\u003e so 1+2]\\n6\\n10]]\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\u003eGiven a position x, determine whether the hare will be in that position or not.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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[ if x=15 then true \\n if x=14 then false.]]\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\u003eSimilar problem\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/45347-cat-s-paw-01\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://www.mathworks.com/matlabcentral/cody/problems/45347-cat-s-paw-01\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":45426,"title":"The Tortoise and the Hare - 02","description":"Previous problem \u003chttps://www.mathworks.com/matlabcentral/cody/problems/45425-the-tortoise-and-the-hare-01\u003e\r\n\r\nSuppose in an infinitely long line, the tortoise is standing in position 0.\r\n\r\nFrom that place, it can move in both +ve and -ve direction. The condition is that, in i-th jump, it can move i step forward or backward. \r\n\r\nSo one possible scenario can be -\r\n\r\n 0 [i=1] --- 1 step forward\r\n 1 [i=2] --- 2 step forward\r\n 3 [i=3] --- 3 step forward\r\n 6 [i=4] --- 4 step backward\r\n 2 [i=5] --- 5 step forward\r\n 7 [i=6] --- 6 step backward\r\n 1 [i=7] --- 7 step forward\r\n 8\r\n\r\nIf you look carefully, you'll find that -- If the tortoise moves this way, it'll always be able to reach any destination (x). \r\n\r\nThe question is what is the minimum number of moves it'll take to reach destination x.\r\n\r\nFor example -- \r\n\r\n if x=8\r\n  \u003e\u003e in the above example, it takes 7 steps\r\n  \u003e\u003e but if it moves this way  -- [0,-1,1,4,8] -- steps required = 4.\r\n\r\nSo 4 is the optimum way.\r\n","description_html":"\u003cp\u003ePrevious problem \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/45425-the-tortoise-and-the-hare-01\"\u003ehttps://www.mathworks.com/matlabcentral/cody/problems/45425-the-tortoise-and-the-hare-01\u003c/a\u003e\u003c/p\u003e\u003cp\u003eSuppose in an infinitely long line, the tortoise is standing in position 0.\u003c/p\u003e\u003cp\u003eFrom that place, it can move in both +ve and -ve direction. The condition is that, in i-th jump, it can move i step forward or backward.\u003c/p\u003e\u003cp\u003eSo one possible scenario can be -\u003c/p\u003e\u003cpre\u003e 0 [i=1] --- 1 step forward\r\n 1 [i=2] --- 2 step forward\r\n 3 [i=3] --- 3 step forward\r\n 6 [i=4] --- 4 step backward\r\n 2 [i=5] --- 5 step forward\r\n 7 [i=6] --- 6 step backward\r\n 1 [i=7] --- 7 step forward\r\n 8\u003c/pre\u003e\u003cp\u003eIf you look carefully, you'll find that -- If the tortoise moves this way, it'll always be able to reach any destination (x).\u003c/p\u003e\u003cp\u003eThe question is what is the minimum number of moves it'll take to reach destination x.\u003c/p\u003e\u003cp\u003eFor example --\u003c/p\u003e\u003cpre\u003e if x=8\r\n  \u0026gt;\u0026gt; in the above example, it takes 7 steps\r\n  \u0026gt;\u0026gt; but if it moves this way  -- [0,-1,1,4,8] -- steps required = 4.\u003c/pre\u003e\u003cp\u003eSo 4 is the optimum way.\u003c/p\u003e","function_template":"function y = rabbit(n)","test_suite":"%%\r\nassert(isequal(rabbit(8),4))\r\n%%\r\nassert(isequal(rabbit(18),7))\r\n%%\r\nassert(isequal(rabbit(-600),35))\r\n%%\r\nassert(isequal(rabbit(6600),115))\r\n%%\r\nassert(isequal(rabbit(99999),449))\r\n%%\r\nassert(isequal(rabbit(-16),7))\r\n%%\r\nassert(isequal(rabbit(45237929),9513))\r\n%%\r\nassert(isequal(rabbit(46),11))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":5,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":24,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-04-07T05:20:53.000Z","updated_at":"2026-03-30T18:12:01.000Z","published_at":"2020-04-07T05:20:53.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\u003ePrevious problem\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/45425-the-tortoise-and-the-hare-01\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://www.mathworks.com/matlabcentral/cody/problems/45425-the-tortoise-and-the-hare-01\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSuppose in an infinitely long line, the tortoise is standing in position 0.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFrom that place, it can move in both +ve and -ve direction. The condition is that, in i-th jump, it can move i step forward or backward.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSo one possible scenario can be -\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ 0 [i=1] --- 1 step forward\\n 1 [i=2] --- 2 step forward\\n 3 [i=3] --- 3 step forward\\n 6 [i=4] --- 4 step backward\\n 2 [i=5] --- 5 step forward\\n 7 [i=6] --- 6 step backward\\n 1 [i=7] --- 7 step forward\\n 8]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf you look carefully, you'll find that -- If the tortoise moves this way, it'll always be able to reach any destination (x).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe question is what is the minimum number of moves it'll take to reach destination x.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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[ if x=8\\n  \u003e\u003e in the above example, it takes 7 steps\\n  \u003e\u003e but if it moves this way  -- [0,-1,1,4,8] -- steps required = 4.]]\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\u003eSo 4 is the optimum way.\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":45449,"title":"Quarantine Days","description":"In these quarantine days, a list of what Max may do on a typical day is given in a table with the starting hour to ending hour.\r\n\r\n Task       Start         End\r\nSleep         0            6\r\nWalk          6            7\r\nBreakfast     8            9\r\nMovie         10           16\r\nStudy         15           21\r\nDinner        22           23\r\n\r\nNow Max wants to perform the maximum amount of tasks in a single day. How should he make his routine?\r\n\r\nFor this problem -- just return the number of tasks.","description_html":"\u003cp\u003eIn these quarantine days, a list of what Max may do on a typical day is given in a table with the starting hour to ending hour.\u003c/p\u003e\u003cpre\u003e Task       Start         End\r\nSleep         0            6\r\nWalk          6            7\r\nBreakfast     8            9\r\nMovie         10           16\r\nStudy         15           21\r\nDinner        22           23\u003c/pre\u003e\u003cp\u003eNow Max wants to perform the maximum amount of tasks in a single day. How should he make his routine?\u003c/p\u003e\u003cp\u003eFor this problem -- just return the number of tasks.\u003c/p\u003e","function_template":"function yy = activity_2(x)\r\nend","test_suite":"%%\r\nStart=[0,6,8,10,15,22]';\r\nFinish=[6,7,9,16,21,23]';\r\nx=table(Start,Finish);\r\nassert(isequal(activity_2(x),5))\r\n\r\n%%\r\nStart=[0,5,8,10,15,22,23,3,11,16]';\r\nFinish=[6,8,11,11,17,24,24,4,16,18]';\r\nx=table(Start,Finish);\r\nassert(isequal(activity_2(x),6))\r\n\r\n%%\r\nStart=[0,5,8,10,15,22,23,3,11,16,5,12,14]';\r\nFinish=[6,8,11,11,17,24,24,4,16,18,10,13,16]';\r\nx=table(Start,Finish);\r\nassert(isequal(activity_2(x),7))\r\n\r\n%%\r\nStart=[1,12,16,21,11]';\r\nFinish=[11,13,18,24,17]';\r\nx=table(Start,Finish);\r\nassert(isequal(activity_2(x),4))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":22,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-04-13T02:15:41.000Z","updated_at":"2026-02-09T22:19:31.000Z","published_at":"2020-04-13T02:31:01.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn these quarantine days, a list of what Max may do on a typical day is given in a table with the starting hour to ending hour.\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[ Task       Start         End\\nSleep         0            6\\nWalk          6            7\\nBreakfast     8            9\\nMovie         10           16\\nStudy         15           21\\nDinner        22           23]]\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\u003eNow Max wants to perform the maximum amount of tasks in a single day. How should he make his routine?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor this problem -- just return the number of tasks.\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":45463,"title":"Word Ladder","description":"Given a set of words, and two other words - start and destination,\r\n\r\nFind the smallest chain from start to the destination such that adjacent words in the chain only differ by one character and each word in the chain exists in the set. \r\n\r\nAll the words are of the same length.\r\nThe starting word is not in the set but destination word would be.\r\n\r\nFor example, \r\n\r\n Start = 'COLD'\r\n Destination = 'WARM'\r\n set ={ CORD CARD DART FORT WARM FARM WARD}\r\n\r\n COLD → CORD → CARD → WARD → WARM","description_html":"\u003cp\u003eGiven a set of words, and two other words - start and destination,\u003c/p\u003e\u003cp\u003eFind the smallest chain from start to the destination such that adjacent words in the chain only differ by one character and each word in the chain exists in the set.\u003c/p\u003e\u003cp\u003eAll the words are of the same length.\r\nThe starting word is not in the set but destination word would be.\u003c/p\u003e\u003cp\u003eFor example,\u003c/p\u003e\u003cpre\u003e Start = 'COLD'\r\n Destination = 'WARM'\r\n set ={ CORD CARD DART FORT WARM FARM WARD}\u003c/pre\u003e\u003cpre\u003e COLD → CORD → CARD → WARD → WARM\u003c/pre\u003e","function_template":"function out2 = word_lad_2(ary,st,des)","test_suite":"%%\r\nary={ 'CORD', 'CARD', 'DART', 'FORT', 'WARM', 'FARM', 'WARD'}\r\nst='COLD'\r\ndes='WARM'\r\ny_correct = {'CORD','CARD','WARD','WARM'};\r\nassert(isequal(word_lad_2(ary,st,des),y_correct))\r\n\r\n%%\r\nary={'pan','can','fan','pat','mat','fat','lot','opt','apt','act','ape','put','aut'}\r\nst='man'\r\ndes='ape'\r\ny_correct = {'pan'\t'pat'\t'put'\t'aut'\t'apt'\t'ape'};\r\nassert(isequal(word_lad_2(ary,st,des),y_correct))\r\n\r\n%%\r\nary={'leg','hot','dot','dog','lot','log','cog','hog','zog','fog'}\r\nst='hit'\r\ndes='fog'\r\ny_correct = {'hot','hog','fog'};\r\nassert(isequal(word_lad_2(ary,st,des),y_correct))\r\n\r\n%%\r\nary={'safer', 'rifer','upper','rifre', 'rider','tider' ,'cider','coder','loder', 'cooer', 'cooey', 'gooey', 'goosy' , 'goose' ,'loose','nosey','doose'}\r\nst='refer'\r\ndes='loose'\r\ny_correct = {'rifer'\t'rider'\t'cider'\t'coder'\t'cooer'\t'cooey'\t'gooey'\t'goosy'\t'goose'\t'loose'};\r\nassert(isequal(word_lad_2(ary,st,des),y_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":"2020-04-16T07:12:17.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-04-16T07:11:43.000Z","updated_at":"2026-02-10T01:03:52.000Z","published_at":"2020-04-16T07:12:17.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 a set of words, and two other words - start and destination,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the smallest chain from start to the destination such that adjacent words in the chain only differ by one character and each word in the chain exists in the set.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAll the words are of the same length. The starting word is not in the set but destination word would be.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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[ Start = 'COLD'\\n Destination = 'WARM'\\n set ={ CORD CARD DART FORT WARM FARM WARD}\\n\\n COLD → CORD → CARD → WARD → WARM]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":45321,"title":"Kolakoski Sequence","description":"This is a modified version of the kolakoski sequence. \r\n\r\n\r\nRefer to the problem \u003chttps://www.mathworks.com/matlabcentral/cody/problems/2371\u003e for the original one.\r\n\r\nfor this case,\r\n\r\n\r\nGiven a particular initial vector a and length x,\r\ngenerate the kolakoski sequence (first x terms) from that vector.\r\n\r\n\r\nFor example if a=[2,1] and x=10 ;  the sequence would look like --\r\n\r\n\r\n 2     2     1     1     2     1     2     2     1     2     2","description_html":"\u003cp\u003eThis is a modified version of the kolakoski sequence.\u003c/p\u003e\u003cp\u003eRefer to the problem \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/2371\"\u003ehttps://www.mathworks.com/matlabcentral/cody/problems/2371\u003c/a\u003e for the original one.\u003c/p\u003e\u003cp\u003efor this case,\u003c/p\u003e\u003cp\u003eGiven a particular initial vector a and length x,\r\ngenerate the kolakoski sequence (first x terms) from that vector.\u003c/p\u003e\u003cp\u003eFor example if a=[2,1] and x=10 ;  the sequence would look like --\u003c/p\u003e\u003cpre\u003e 2     2     1     1     2     1     2     2     1     2     2\u003c/pre\u003e","function_template":"function y = kolakoski_seq_3(a,x)\r\n  y = x;\r\nend","test_suite":"%%\r\na = [2,1];\r\nx=10;\r\ny_correct = [2     2     1     1     2     1     2     2     1     2  ];\r\nassert(isequal( kolakoski_seq_3(a,x),y_correct))\r\n%%\r\na = [2,1];\r\nx=15;\r\ny_correct = [2     2     1     1     2     1     2     2     1     2     2  1  1     2     1 ];\r\nassert(isequal( kolakoski_seq_3(a,x),y_correct))\r\n%%\r\na = [1,3,1,2];\r\nx=30;\r\ny_correct = [1, 3, 3, 3, 1, 1, 1, 2, 2, 2, 1, 3, 1, 2, 2, 1, 1, 3, 3, 1, 2, 2, 2, 1, 3, 3, 1, 1, 2, 1];\r\nassert(isequal( kolakoski_seq_3(a,x),y_correct))\r\n%%\r\na = [4,2];\r\nx=15;\r\ny_correct = [ 4     4     4     4     2     2     2     2     4     4     4     4  2     2     2];\r\nassert(isequal( kolakoski_seq_3(a,x),y_correct))\r\n%%\r\na = [1,3,2];\r\nx=15;\r\ny_correct = [1     3     3     3     2     2     2     1     1     1     3     3 2     2     1];\r\nassert(isequal( kolakoski_seq_3(a,x),y_correct))\r\n%%\r\na = [1,3,2,1];\r\nx=30;\r\ny_correct = [1, 3, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1, 3, 3, 2, 2, 1, 1, 3, 2, 1, 1, 1, 1, 3, 3, 3, 2, 2, 1];\r\nassert(isequal( kolakoski_seq_3(a,x),y_correct))\r\n%%\r\na = [3,12,1,5];\r\nx=40;\r\ny_correct = [3     3     3    12    12    12     1     1     1     5     5     5     5     5     5     5     5 5     5     5     5     3     3     3     3     3     3     3     3     3     3     3     3    12 12    12    12    12    12    12];\r\nassert(isequal( kolakoski_seq_3(a,x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":5,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-02-11T22:04:19.000Z","updated_at":"2026-02-10T02:18:16.000Z","published_at":"2020-02-11T22:17:59.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a modified version of the kolakoski sequence.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRefer to the problem\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/2371\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://www.mathworks.com/matlabcentral/cody/problems/2371\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt; for the original one.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003efor this case,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a particular initial vector a and length x, generate the kolakoski sequence (first x terms) from that vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example if a=[2,1] and x=10 ; the sequence would look like --\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[ 2     2     1     1     2     1     2     2     1     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\"}]}"},{"id":475,"title":"Is this group simply connected?","description":"Given connectivity information about a graph, your job is to figure out if the graph is fully connected. You are given a list of vertex pairs that specify undirected connectivity (edges) among vertices. Vertex labels are always positive integers.\r\n\r\nExample 1:\r\n \r\n Input  node_pairs = [ 8 9\r\n                       8 3 ]\r\n Output tf is true\r\n                       \r\nThe three nodes of this graph are fully connected, since this graph could be drawn like so:\r\n\r\n 3--8--9\r\n\r\nExample 2:\r\n\r\n Input  node_pairs = [ 1 2 \r\n                       2 3\r\n                       1 4\r\n                       3 4\r\n                       5 6 ]\r\n Output tf is false\r\n\r\nThis graph could be drawn like so:\r\n\r\n 1--2  5--6\r\n |  |\r\n 4--3\r\n\r\nThere are two distinct subgraphs.","description_html":"\u003cp\u003eGiven connectivity information about a graph, your job is to figure out if the graph is fully connected. You are given a list of vertex pairs that specify undirected connectivity (edges) among vertices. Vertex labels are always positive integers.\u003c/p\u003e\u003cp\u003eExample 1:\u003c/p\u003e\u003cpre\u003e Input  node_pairs = [ 8 9\r\n                       8 3 ]\r\n Output tf is true\u003c/pre\u003e\u003cp\u003eThe three nodes of this graph are fully connected, since this graph could be drawn like so:\u003c/p\u003e\u003cpre\u003e 3--8--9\u003c/pre\u003e\u003cp\u003eExample 2:\u003c/p\u003e\u003cpre\u003e Input  node_pairs = [ 1 2 \r\n                       2 3\r\n                       1 4\r\n                       3 4\r\n                       5 6 ]\r\n Output tf is false\u003c/pre\u003e\u003cp\u003eThis graph could be drawn like so:\u003c/p\u003e\u003cpre\u003e 1--2  5--6\r\n |  |\r\n 4--3\u003c/pre\u003e\u003cp\u003eThere are two distinct subgraphs.\u003c/p\u003e","function_template":"function tf = isConnected(node_pairs)\r\n  tf = true;\r\nend","test_suite":"%%\r\n\r\nnode_pairs = [8 9; 8 3];\r\ntf = true;\r\nassert(isequal(isConnected(node_pairs),tf))\r\n\r\n%%\r\n\r\nnode_pairs = [ 1 2;\r\n               2 3;\r\n               1 4;\r\n               3 4;\r\n               5 6 ];\r\ntf = false;\r\nassert(isequal(isConnected(node_pairs),tf))\r\n\r\n%%\r\n\r\nnode_pairs = [ 1 2;\r\n               2 3;\r\n               1 4;\r\n               3 4;\r\n               5 6;\r\n               6 2 ];\r\ntf = true;\r\nassert(isequal(isConnected(node_pairs),tf))\r\n\r\n%%\r\n\r\nnode_pairs = [ 1 2; 2 100];\r\ntf = true;\r\nassert(isequal(isConnected(node_pairs),tf))\r\n\r\n\r\n%%\r\n\r\nnode_pairs = [ 1 2; 50 100];\r\ntf = false;\r\nassert(isequal(isConnected(node_pairs),tf))\r\n\r\n%%\r\n\r\nnode_pairs = [ 4 17 ];\r\ntf = true;\r\nassert(isequal(isConnected(node_pairs),tf))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":2,"created_by":7,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":36,"test_suite_updated_at":"2012-03-09T22:15:16.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-03-09T22:05:26.000Z","updated_at":"2026-03-03T23:05:27.000Z","published_at":"2012-03-12T16:23:04.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 connectivity information about a graph, your job is to figure out if the graph is fully connected. You are given a list of vertex pairs that specify undirected connectivity (edges) among vertices. Vertex labels are always positive integers.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 1:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ Input  node_pairs = [ 8 9\\n                       8 3 ]\\n Output tf is true]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe three nodes of this graph are fully connected, since this graph could be drawn like so:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ 3--8--9]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 2:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ Input  node_pairs = [ 1 2 \\n                       2 3\\n                       1 4\\n                       3 4\\n                       5 6 ]\\n Output tf is false]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis graph could be drawn like so:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ 1--2  5--6\\n |  |\\n 4--3]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are two distinct subgraphs.\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":45473,"title":"Sub-sequence - 01","description":"Find the length of the longest increasing subsequence in the given array.\r\n\r\n  a=[2,4,2,1,3,5,6]\r\n  longest increasing subsequence = [2,4,5,6]\r\n                                 = [1,3,5,6]\r\n                                 = [2,3,5,6]\r\n  so, length = 4","description_html":"\u003cp\u003eFind the length of the longest increasing subsequence in the given array.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ea=[2,4,2,1,3,5,6]\r\nlongest increasing subsequence = [2,4,5,6]\r\n                               = [1,3,5,6]\r\n                               = [2,3,5,6]\r\nso, length = 4\r\n\u003c/pre\u003e","function_template":"function yy = longest_sub_2(x)","test_suite":"%%\r\nx =[2,4,2,1,3,5,6];\r\nassert(isequal(longest_sub_2(x),4))\r\n\r\n%%\r\nx=[15,27,14,38,26,55,46,65,85];\r\nassert(isequal(longest_sub_2(x),6))\r\n\r\n%%\r\nx =[2,4,2,1,3,5,6,12,0,2,1,1,2,1,4,5,6,12,3,2];\r\nassert(isequal(longest_sub_2(x),7))\r\n\r\n%%\r\nx =[82\t91\t13\t92\t64\t10\t28\t55\t96\t97\t16\t98\t96\t49\t81\t15\t43\t92\t80\t96\t66\t4\t85\t94\t68];\r\nassert(isequal(longest_sub_2(x),6))\r\n\r\n%%\r\nx =[758\t744\t393\t656\t172\t707\t32\t277\t47\t98\t824\t695\t318\t951\t35\t439\t382\t766\t796\t187\t490\t446\t647\t710\t755\t277\t680\t656\t163\t119\t499\t960\t341\t586\t224\t752\t256\t506\t700\t891\t960\t548\t139\t150\t258\t841\t255\t815\t244\t930];\r\nassert(isequal(longest_sub_2(x),11))\r\n\r\n%%\r\nx =ones(1,1000);\r\nassert(isequal(longest_sub_2(x),1))\r\n\r\n%%\r\nx =[ones(1,1000),zeros(1,50),2*ones(1,20)];\r\nassert(isequal(longest_sub_2(x),2))\r\n\r\n%%\r\nx=[34999 19660\t25109\t61605\t47329\t35166\t83083\t58527\t54973\t91720\t28584\t75721\t75373\t38045\t56783\t7586\t5396\t53080\t77917\t93402\t12991\t56883\t46940\t1191\t33713\t16219\t79429\t31122\t52854\t16565\t60199\t26298\t65408\t68922\t74816\t45055\t8383\t22898\t91334\t15238\t82582\t53835\t99614\t7818\t44268\t10666\t96190\t464\t77492\t81731\t86870\t8444\t39979\t25988\t80007\t43142\t91065\t18185\t26381\t14554\t13607\t86930\t57971\t54987\t14496\t85304\t62206\t35096\t51325\t40181\t7597\t23992\t12332\t18391\t23996\t41727\t4966\t90272\t94479\t49087\t48926\t33772\t90006\t36925\t11121\t78026\t38974\t24170\t40392\t9646\t13198\t94206\t95614\t57521\t5978\t23478\t35316\t82120\t1541\t4303\t16900\t64912\t73173\t64775\t45093\t54701\t29633\t74470\t18896\t68678\t18352\t36849\t62562\t78023\t8113\t92939\t77572\t48680\t43586\t44679\t30635\t50851\t51078\t81763\t79484\t64432\t37861\t81159\t53283\t35073\t93901\t87595\t55016\t62248\t58705\t20775\t30125\t47093\t23049\t84431\t19477\t22593\t17071\t22767\t43570\t31111\t92338\t43021\t18482\t90489\t97975\t43887\t11112\t25807\t40872\t59490\t26222\t60285\t71122\t22175\t11742\t29668\t31878\t42417\t50786\t8552\t26249\t80102\t2923\t92886\t73034\t48861\t57853\t23729\t45885\t96309\t54681\t52114\t23160\t48890\t62407\t67914\t39552\t36744\t98799\t3774\t88517\t91329\t79619\t9872\t26188\t33536\t67973\t13656\t72123\t10677\t65376\t49418\t77906\t71504\t90373\t89093\t33417\t69875\t19781\t3055\t74408\t50003\t47993\t90473\t60987\t61767\t85945\t80549\t57673\t18293\t23994\t88652\t2868\t48991\t16793\t97869\t71270\t50048\t47109\t5962\t68198\t4244\t7145\t52165\t9674\t81815\t81755\t72244\t14987\t65961\t51860\t97298\t64900\t80034\t45380\t43240\t82532\t8347\t13318\t17339\t39094\t83138\t80337\t6048\t39926\t52688\t41680\t65686\t62798\t29199\t43166\t1549\t98407\t16717\t10622\t37241\t19812\t48969\t33950\t95164\t92034\t5268\t73786\t26912\t42284\t54788\t94274\t41775\t98306\t30146\t70110\t66634\t53913\t69811\t66653\t17814\t12802\t99909\t17113\t3261\t56120\t88187\t66918\t19044\t36892\t46073\t98164\t15641\t85553\t64477\t37628\t19093\t42826\t48203\t12062\t58951\t22619\t38462\t58299\t25181\t29045\t61710\t26529\t82438\t98267\t73025\t34388\t58407\t10777\t90631\t87966\t81777\t26073\t59436\t2252\t42526\t31272\t16149\t17877\t42289\t9423\t59853\t47093\t69595\t69989\t63854\t3361\t6881\t31960\t53087\t65445\t40762\t81999\t71836\t96865\t53134\t32515\t10563\t61096\t77881\t42346\t9083\t26648\t15366\t28101\t44009\t52715\t45743\t87538\t51806\t94363\t63771\t95770\t24071\t67613\t28907\t67181\t69515\t6800\t25480\t22405\t66784\t84440\t34447\t78052\t67534\t672\t60218\t38678\t91600\t116\t46245\t42435\t46092\t77016\t32248\t78474\t47136\t3577\t17588\t72176\t47349\t15273\t34113\t60739\t19175\t73843\t24285\t91743\t26907\t76551\t18867\t28750\t9112\t57621\t68337\t54660\t42573\t64445\t64762\t67902\t63579\t94518\t20894\t70929\t23624\t11940\t60731\t45014\t45873\t66195\t77029\t35022\t66201\t41616\t84193\t83292\t25645\t61347\t58225\t54074\t86995\t26478\t31808\t11922\t93983\t64556\t47947\t63932\t54472\t64732\t54389\t72105\t52250\t99371\t21868\t10580\t10970\t6360\t40458\t44838\t36582\t76351\t62790\t77199\t93286\t97275\t19203\t13888\t69627\t9383\t52541\t53035\t86114\t48486\t39346\t67144\t74126\t52006\t34772\t15000\t58610\t26215\t4446\t75494\t24279\t44241\t68780\t35923\t73635\t39471\t68342\t70405\t44231\t1958\t33086\t42431\t27028\t19706\t82173\t42993\t88778\t39119\t76912\t39680\t80852\t75508\t37740\t21602\t79041\t94931\t32757\t67127\t43865\t83351\t76886\t16726\t86199\t98988\t51443\t88429\t58803\t15476\t19987\t40696\t74871\t82559\t78997\t31853\t53407\t8996\t11171\t13630\t67866\t49518\t18972\t49501\t14761\t5498\t85072\t56056\t92961\t69667\t58280\t81540\t87902\t98892\t53\t86544\t61257\t98996\t52769\t47953\t80135\t22785\t49810\t90086\t57467\t84518\t73865\t58599\t24674\t66642\t8349\t62596\t66095\t72976\t89076\t98231\t76903\t58145\t92832\t58010\t1699\t12086\t86272\t48430\t84486\t20941\t55230\t62989\t3200\t61472\t36242\t4954\t48957\t19252\t12309\t20550\t14652\t18908\t4266\t63520\t28187\t53860\t69517\t49912\t53581\t44519\t12394\t49036\t85300\t87393\t27030\t20847\t56498\t64032\t41703\t20598\t94794\t8208\t10571\t14205\t16647\t62096\t57371\t5208\t93121\t72867\t73785\t6341\t86045\t93441\t98440\t85894\t78556\t51338\t17761\t39859\t13394\t3089\t93915\t30131\t29554\t33294\t46707\t64820\t2523\t84221\t55904\t85410\t34788\t44603\t5424\t17711\t66281\t33083\t89849\t11816\t98842\t53999\t70692\t99950\t28785\t41453\t46484\t76396\t81821\t10023\t17812\t35964\t5671\t52189\t33585\t17567\t20895\t90516\t67540\t46847\t91214\t10402\t74555\t73627\t56187\t18420\t59722\t29994\t13413\t21261\t89495\t7146\t24249\t5376\t44173\t1329\t89720\t19666\t9338\t30737\t45606\t10167\t99539\t33210\t29735\t6205\t29825\t4636\t50543\t76143\t63107\t8990\t8087\t77725\t90514\t53378\t10916\t82581\t33810\t29398\t74632\t1034\t4845\t66792\t60347\t52611\t72971\t70726\t78138\t28798\t69254\t55667\t39653\t6160\t78018\t33759\t60787\t74126\t10482\t12789\t54955\t48523\t89048\t79897\t73435\t5134\t7289\t8853\t79836\t94301\t68372\t13209\t72273\t11036\t11750\t64072\t32882\t65382\t74914\t58319\t74004\t23483\t73496\t97060\t86694\t8624\t36644\t36920\t68503\t59795\t78937\t36766\t20603\t8667\t77194\t20568\t38828\t55178\t22896\t64195\t48449\t15185\t78194\t10061\t29407\t23738\t53088\t9150\t40532\t10485\t11229\t78443\t29158\t60354\t96443\t43249\t69476\t75810\t43265\t65550\t10976\t93376\t18747\t26618\t79784\t48761\t76896\t39601\t27294\t3724\t67330\t42957\t45174\t60986\t5941\t31582\t77273\t69644\t12534\t13016\t9236\t783\t42311\t65558\t72293\t53121\t10882\t63177\t12650\t13431\t9860\t14203\t16826\t19625\t31748\t31643\t21757\t25105\t89293\t70323\t55574\t18444\t21204\t7735\t91381\t70672\t55779\t31343\t16621\t62250\t98794\t17044\t25780\t39680\t7400\t68410\t40239\t98284\t40219\t62068\t15437\t38135\t16114\t75812\t87112\t35078\t68554\t29415\t53063\t83243\t59750\t33532\t29923\t45260\t42265\t35961\t55832\t74255\t42434\t42936\t12488\t2444\t29019\t31753\t65370\t95694\t93574\t45789\t24048\t76390\t75933\t74065\t74369\t10593\t68157\t46327\t21217\t9852\t82358\t17501\t16357\t66599\t89439\t51656\t70271\t15360\t95346\t54089\t67974\t3657\t80921\t74862\t12019\t52505\t32584\t54645\t39889\t41510\t18074\t25539\t2054\t92368\t65370\t93262\t16352\t92110\t79466\t57740\t44004\t25762\t75195\t22867\t6419\t76733\t67121\t71522\t64207\t41905\t39077\t81615\t31743\t81454\t78908\t85227\t50564\t63567\t95090\t44397\t6002\t86675\t63119\t35508\t99701\t22418\t65246\t60500\t38725\t14219\t2514\t42112\t18411\t72578\t37037\t84157\t73423\t57103\t17686\t95739\t26533\t92459\t22378\t37357\t8751\t64012\t18062\t4506\t72318\t34744\t66062\t38387\t62735\t2165\t91057\t80056\t74585\t81312\t38331\t61728\t57550\t53006\t27507\t24863\t45164\t22772\t80445\t98611\t3000\t53567\t8708\t80210\t98915\t6695\t93940\t1818\t68384\t78374\t53414\t88536\t89901\t62594\t13787\t21781\t18215\t4182\t10695\t61645\t93967\t35446\t41063\t98435\t94558\t67665\t98831\t76684\t33670\t66239\t24417\t29551\t68018\t52785\t41160\t60264\t75053\t58354\t55180\t58358\t51182\t8260\t71958\t99616\t35454\t97126\t34645\t88655\t45470\t41343\t21774\t12566\t30892\t72611\t78288\t69379\t981\t84322\t92234\t77096\t4266\t37819\t70434\t72952\t22428\t26906\t67304\t47750\t62372\t23645\t17713\t82965\t76693\t93448\t10789\t18223\t9910\t48977\t19325\t89590\t9909\t4417\t55730\t77250\t31195\t17899\t33896\t21015\t51016\t90637\t62893\t10154\t39086\t5462\t50129\t43173\t99757\t81161\t48566\t89445\t13755\t39001\t92736\t91750\t71358\t61834\t34329\t93603\t12478\t73059\t64648\t83316\t39829\t74983\t83523\t32247\t55227\t97913\t54931\t33043\t61948\t36064\t75651\t41391\t49235\t69475\t97274\t32776\t83781\t73908\t95418\t3193\t35687\t66266\t28151\t23039\t71113\t62458\t59061\t66044\t4756\t34879\t45135\t24091\t71505\t85619\t28151\t73106\t13777\t83673\t13861\t58821\t36616\t80676\t50379\t48960\t87705\t35315\t44945\t96354\t4230\t97296\t18921\t66713\t58644\t67512\t36103\t62028\t81116\t1926\t8388\t97481\t65135\t23124\t40350\t12203\t26844\t25785\t33167\t15224\t34801\t12166\t88416\t9428\t93005\t39902\t4741\t34238\t73597\t79469\t54491\t68623\t89364\t5480\t30367\t4620\t19548\t72017\t72176\t87780\t58244\t7069\t92275\t80038\t28595\t54367\t98478\t71568\t83897\t43327\t47063\t56072\t26910\t74902\t50389\t64681\t30775\t13873\t47558\t36246\t78812\t78030\t66852\t13351\t2156\t55985\t30082\t93941\t98091\t28663\t80083\t89612\t59753\t88402\t94374\t54916\t72839\t57676\t2586\t44654\t64631\t52121\t37232\t93714\t82954\t84909\t37254\t59319\t87256\t93351\t66847\t20678\t65386\t7206\t40673\t66694\t93373\t81096\t48455\t75675\t41705\t97179\t98798\t86415\t38889\t45475\t24669\t78443\t88284\t91372\t55829\t59887\t14888\t89972\t45040\t20568\t89966\t76259\t88249\t28496\t67323\t66428\t12282\t40732\t27529\t71667\t28339\t89620\t82658\t39003\t49791\t69481\t83437\t60963\t57474\t32605\t45643\t71380\t88441\t72086\t1862\t67478\t43851\t43783\t11704\t81469\t32486\t24623\t34272\t37570\t54656\t56193\t39583\t39814\t51537\t65754\t95092\t72235\t40008\t83188\t13434\t6047\t8425\t16390\t32422\t30173\t1169\t53991\t9538\t14652\t63115\t85933\t97423\t57084\t99686\t55355\t51546\t33069\t43001\t49181\t7104\t88774\t6464\t43619\t82663\t39454\t61348\t81865\t88624\t93112\t19079\t25859\t89787\t59337\t50385\t61281\t81943\t53189\t20208\t45390\t42792\t96606\t62006\t69539\t72017\t34690\t51700\t55670\t15650\t56206\t69481\t42646\t83628\t73139\t36004\t45422\t38639\t77556\t73428\t43028\t69376\t94522\t78424\t70558\t10934\t38994\t59091\t45939\t5034\t22869\t83419\t1565\t86372\t7807\t66905\t50022\t21800\t57162\t12219\t67117\t59959\t5598\t5635\t15251\t1963\t43518\t83223\t61740\t52013\t86387\t9770\t90806\t10802\t51700\t14316\t55938\t458\t76669\t84871\t91683\t98697\t50514\t27143\t10076\t50785\t58561\t76289\t8297\t66160\t51698\t17105\t93856\t59049\t44064\t94192\t65592\t45195\t83970\t53263\t55389\t68007\t36719\t23930\t57893\t86689\t40678\t11262\t44385\t30019\t40139\t83337\t40363\t39018\t36045\t14026\t26014\t8682\t42940\t25729\t29756\t42486\t11921\t49507\t70641\t24358\t78508\t7409\t39389\t340\t22068\t131\t18918\t14249\t26808\t17490\t13865\t59889\t90106\t93938\t22119\t48268\t37602\t52379\t26488\t6836\t43633\t17386\t2611\t95468\t43060\t96156\t76242\t735\t68004\t70596\t64513\t55231\t21811\t77237\t22803\t37087\t89093\t85638\t40244\t31802\t60864\t91020\t90910\t59160\t33258\t85307\t44240\t90436\t3318\t53243\t71650\t17931\t33654\t18772\t32193\t40386\t54857\t4874\t55274\t27482\t24151\t24315\t15416\t95642];\r\nassert(isequal(longest_sub_2(x),72))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":22,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-04-23T15:37:38.000Z","updated_at":"2026-02-10T06:04:32.000Z","published_at":"2020-04-23T15:37: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\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the length of the longest increasing subsequence in the given array.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[a=[2,4,2,1,3,5,6]\\nlongest increasing subsequence = [2,4,5,6]\\n                               = [1,3,5,6]\\n                               = [2,3,5,6]\\nso, length = 4]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":45474,"title":"Sub-sequence - 02","description":"Given two sequences, find the length of the longest common subsequence.\r\n\r\n  a=[1,1,1,1,1,2,3,1,4]\r\n b=[2,3,0,0,9,5,4,1]\r\n longest Common subsequence = [2,3,4]\r\n                             = [2,3,1]\r\nso,length=3","description_html":"\u003cp\u003eGiven two sequences, find the length of the longest common subsequence.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ea=[1,1,1,1,1,2,3,1,4]\r\nb=[2,3,0,0,9,5,4,1]\r\nlongest Common subsequence = [2,3,4]\r\n                           = [2,3,1]\r\nso,length=3\r\n\u003c/pre\u003e","function_template":"function y = longest_sub_common(a,b)","test_suite":"%%\r\na=[1,1,1,1,1,2,3,1,4]\r\nb=[2,3,0,0,9,5,4,1]\r\nassert(isequal(longest_sub_common(a,b),3))\r\n\r\n%%\r\na=[1,1,1,1,1,2,3]\r\nb=[2,3,0,0,9,5,4,1]\r\nassert(isequal(longest_sub_common(a,b),2))\r\n\r\n%%\r\na=[1,1,1,1,1,2,3,1,4]\r\nb=zeros(1,500);\r\nassert(isequal(longest_sub_common(a,b),0))\r\n\r\n%%\r\na=[1,1,1,1,1,2,3,1,4]\r\nb=[zeros(1,50),ones(1,200),ones(1,20)*3]\r\nassert(isequal(longest_sub_common(a,b),6))\r\n\r\n%%\r\na='aaabbbcccxyz'\r\nb='abcyycbaabc'\r\nassert(isequal(longest_sub_common(a,b),5))\r\n\r\n%%\r\na=[10\t9\t8\t2\t4\t2\t1\t4\t7\t7\t6\t5\t3\t6\t8\t8\t6\t8\t7\t2\t6\t4\t1\t2\t2\t7\t5\t7\t3\t1\t6\t3\t10\t10\t4\t1\t7\t9\t10\t1\t5\t6\t7\t8\t7\t8\t4\t6\t2\t1\t10\t3\t6\t10\t2\t2\t4\t10\t4\t3\t2\t4\t4\t2\t5\t1\t7\t1\t6\t8\t3\t5\t6\t1\t5\t7\t3\t9\t10\t9\t6\t3\t8\t3\t10\t7\t7\t2\t1\t3\t9\t10\t7\t8\t3\t6\t9\t5\t10\t1\t4\t6\t1\t8\t6\t6\t9\t9\t8\t4\t5\t8\t2\t2\t3\t6\t10\t8\t4\t3\t9\t10\t7\t3\t1\t9\t6\t10\t1\t6\t3\t9\t2\t5\t4\t9\t7\t3\t4\t2\t7\t6\t2\t2\t5\t10\t6\t1\t1\t9\t5\t4\t8\t4\t6\t8\t9\t4\t7\t10\t1\t6\t5\t4\t3\t8\t10\t2\t8\t2\t10\t9\t5\t8\t5\t9\t4\t1\t6\t10\t2\t5\t8\t1\t10\t8\t6\t2\t5\t6\t10\t9\t10\t7\t5\t10\t5\t3\t4\t8\t6\t8\t10\t10\t6\t10\t2\t1\t4\t6\t6\t10\t6\t5\t6\t8\t1\t9\t2\t5\t3\t4\t7\t2\t3\t2\t2\t4\t9\t5\t5\t2\t10\t5\t9\t7\t4\t9\t8\t5\t9\t9\t5\t4\t6\t10\t8\t4\t8\t10\t6\t6\t4\t1\t2\t1\t5\t1\t10\t7\t1\t1\t3\t5\t2\t1\t8\t4\t8\t5\t5\t1\t1\t1\t6\t3\t9\t9\t10\t5\t3\t3\t6\t8\t4\t5\t7\t10\t2\t8\t6\t5\t9\t4\t2\t7\t7\t4\t9\t10\t10\t2\t3\t1\t7\t2\t5\t9\t6\t4\t3\t5\t10\t2\t5\t9\t1\t7\t10\t3\t2\t7\t10\t7\t9\t2\t8\t4\t5\t2\t9\t7\t8\t9\t1\t10\t5\t8\t8\t9\t2\t5\t7\t10\t9\t9\t6\t6\t9\t1\t9\t5\t1\t8\t2\t2\t7\t3\t4\t5\t5\t4\t7\t2\t2\t1\t4\t8\t3\t8\t7\t9\t9\t3\t4\t6\t4\t9\t9\t6\t3\t7\t3\t5\t4\t6\t10\t8\t10\t3\t6\t1\t8\t7\t9\t10\t10\t5\t1\t6\t3\t3\t4\t1\t8\t8\t6\t4\t9\t6\t10\t9\t4\t6\t4\t7\t8\t8\t2\t9\t1\t5\t8\t8\t4\t8\t9\t3\t2\t3\t4\t3\t10\t1\t6\t2\t9\t2\t6\t10\t4\t1\t3\t4\t4\t3\t10\t7\t10\t5\t10\t1\t7\t9\t3\t10\t8\t9\t6\t8\t4\t3\t4\t6\t9\t3\t5\t9\t7\t10\t3\t9\t7\t3\t5\t4\t6\t9\t2\t9\t9\t4\t5\t6\t8\t8\t8\t4\t5\t10\t6\t9\t3\t7\t6\t10\t1\t6\t6\t1]\r\nb=[14\t14\t7\t12\t3\t10\t4\t7\t13\t3\t5\t8\t6\t12\t15\t3\t4\t11\t6\t15\t15\t10\t13\t7\t10\t15\t9\t15\t11\t8\t10\t14\t3\t6\t15\t7\t10\t14\t15\t10\t2\t1\t10\t9\t15\t12\t10\t8\t4\t15\t9\t1\t11\t8\t1\t14\t5\t4\t2\t5\t4\t10\t1\t5\t5\t14\t7\t12\t10\t12\t2\t15\t13\t1\t7\t5\t10\t4\t9\t10\t9\t7\t1\t8\t7\t2\t7\t7\t9\t13\t11\t14\t1\t4\t7\t15\t12\t7\t6\t1\t12\t8\t3\t7\t3\t12\t6\t15\t1\t13\t10\t9\t10\t11\t2\t14\t1\t5\t3\t14\t2\t9\t10\t10\t13\t1\t13\t8\t11\t4\t9\t11\t15\t7\t2\t1\t10\t12\t11\t6\t15\t8\t15\t2\t4\t12\t14\t12\t5\t3\t13\t12\t5\t4\t5\t13\t13\t9\t9\t5\t11\t12\t7\t7\t7\t5\t11\t14\t14\t12\t4\t11\t2\t2\t3\t3\t9\t2\t13\t11\t14\t8\t10\t14\t9\t5\t15\t1\t5\t15\t6\t5\t2\t14\t3\t5\t14\t8\t10\t9\t11\t1\t8\t1\t13\t6\t13\t4\t9\t15\t1\t1\t1\t11\t9\t2\t12\t10\t2\t2\t3\t12\t2\t4\t4\t2\t13\t11\t12\t10\t8\t5\t10\t2\t3\t1\t15\t15\t2\t8\t10\t5\t12\t9\t7\t5\t12\t14\t11\t7]\r\nassert(isequal(longest_sub_common(a,b),121))\r\n\r\n%%\r\na='aaabaaabaaabaaa'\r\nb='abababababa'\r\nassert(isequal(longest_sub_common(a,b),9))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":22,"test_suite_updated_at":"2020-04-23T16:07:08.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-04-23T15:59:45.000Z","updated_at":"2026-02-10T12:11:50.000Z","published_at":"2020-04-23T16:07:08.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven two sequences, find the length of the longest common subsequence.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[a=[1,1,1,1,1,2,3,1,4]\\nb=[2,3,0,0,9,5,4,1]\\nlongest Common subsequence = [2,3,4]\\n                           = [2,3,1]\\nso,length=3]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":45475,"title":"Sub-sequence - 03","description":"Given three sequences, find the length of the longest common subsequence.\r\n\r\nIt is similar to the previous problem -- \r\n\r\n\u003chttps://www.mathworks.com/matlabcentral/cody/groups/1/problems/45474-sub-sequence-02\u003e","description_html":"\u003cp\u003eGiven three sequences, find the length of the longest common subsequence.\u003c/p\u003e\u003cp\u003eIt is similar to the previous problem --\u003c/p\u003e\u003cp\u003e\u003ca href = \"https://www.mathworks.com/matlabcentral/cody/groups/1/problems/45474-sub-sequence-02\"\u003ehttps://www.mathworks.com/matlabcentral/cody/groups/1/problems/45474-sub-sequence-02\u003c/a\u003e\u003c/p\u003e","function_template":"function y = longest_sub_common_3d(a,b,c)","test_suite":"%%\r\na=[1,1,1,1,1,2,3,1,4]\r\nb=[2,3,0,0,9,5,4,1]\r\nc=[10,10,9,9,4,4,5]\r\nassert(isequal(longest_sub_common_3d(a,b,c),1))\r\n\r\n%%\r\na=[1,1,1,1,1,2,3,1,4]\r\nb=[2,3,0,1,0,9,5,4,1,10]\r\nc=[10,10,9,9,4,4,5,1,1,3]\r\nassert(isequal(longest_sub_common_3d(a,b,c),2))\r\n\r\n%%\r\na=' arthur'\r\nb='ser arthur '\r\nc='ser arthur dayne'\r\nassert(isequal(longest_sub_common_3d(a,b,c),7))\r\n\r\n%%\r\na=[105\t29\t60\t106\t30\t28\t103\t8\t34\t66\t23\t71\t89\t56\t73\t89\t26\t67\t13\t58\t94\t103\t56\t31\t73\t102\t57\t109\t22\t13\t34\t45\t47\t35\t78\t11\t45\t33\t35\t12\t66\t32\t18\t1\t32\t62\t97\t5\t101\t15\t93\t89\t102\t16\t57\t45\t20\t64\t68\t24\t58\t110\t55\t78\t46\t4\t33\t89\t39\t10\t57\t41\t83\t59\t90\t91\t22\t14\t92\t71\t2\t100\t58\t61\t68\t85\t95\t43\t10\t82\t37\t94\t42\t92\t20\t15\t98\t5\t77\t82\t49\t43\t109\t45\t49\t18\t37\t35\t100\t28\t35]\r\nb=[46\t79\t16\t97\t10\t52\t4\t84\t78\t24\t76\t62\t95\t63\t101\t47\t40\t55\t29\t104\t52\t29\t48\t78\t45\t21\t96\t65\t42\t25\t25\t58\t49\t83\t8\t95\t76\t16\t96\t23\t68\t61\t19\t1\t86\t85\t47\t7\t66\t20\t81\t60\t29\t102\t85\t99\t8\t21\t82\t78\t87\t56\t48\t68\t95\t75\t59\t34\t79\t43\t64\t99\t94\t100\t105\t91\t1\t1\t10\t29\t3\t48\t38\t61\t103\t34\t38\t96\t38\t16\t57\t96\t43\t78\t70\t50\t53\t106\t10\t32\t50\t66\t98\t53\t49\t83\t52\t96\t52\t56\t55]\r\n%c=[46\t79\t16\t97\t10\t52\t4\t84\t78\t24\t76\t62\t95\t63\t101\t47\t40\t55\t29\t104\t52\t29\t48\t78\t45\t21\t96\t65\t42\t25\t25\t58\t49\t83\t8\t95\t76\t16\t96\t23\t68\t61\t19\t1\t86\t85\t47\t7\t66\t20\t81\t60\t29\t102\t85\t99\t8\t21\t82\t78\t87\t56\t48\t68\t95\t75\t59\t34\t79\t43\t64\t99\t94\t100\t105\t91\t1\t1\t10\t29\t3\t48\t38\t61\t103\t34\t38\t96\t38\t16\t57\t96\t43\t78\t70\t50\t53\t106\t10\t32\t50\t66\t98\t53\t49\t83\t52\t96\t52\t56\t55]\r\nc=[26\t10\t8\t99\t26\t96\t80\t97\t105\t16\t44\t109\t72\t100\t54\t2\t70\t26\t59\t81\t68\t66\t49\t28\t48\t2\t68\t107\t11\t4\t99\t28\t1\t91\t16\t98\t11\t40\t66\t65\t75\t72\t49\t16\t84\t27\t73\t96\t10\t108\t4\t93\t93\t6\t61\t105\t36\t90\t67\t88\t89\t6\t32\t73\t55\t108\t84\t64\t34\t29\t99\t50\t91\t11\t96\t4\t100\t100\t59\t14\t20\t79\t93\t4\t85\t107\t39\t71\t39\t25\t88\t81\t31\t65\t47\t11\t3\t55\t31\t38\t32\t19\t45\t78\t23\t74\t50\t49\t20\t22\t69]\r\nassert(isequal(longest_sub_common_3d(a,b,c),6))\r\n\r\n%%\r\na=repelem('abc',1,50)\r\nb=repelem('acb',1,50)\r\nc=repelem('acdb',1,50)\r\nassert(isequal(longest_sub_common_3d(a,b,c),100))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":"2020-04-23T16:36:03.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-04-23T16:29:45.000Z","updated_at":"2026-03-18T19:22:50.000Z","published_at":"2020-04-23T16:36:03.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 three sequences, find the length of the longest common subsequence.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIt is similar to the previous problem --\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/groups/1/problems/45474-sub-sequence-02\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://www.mathworks.com/matlabcentral/cody/groups/1/problems/45474-sub-sequence-02\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":2523,"title":"longest common substring : Skipped character version","description":"Two strings are given. Find the longest common substring between them. The substring characters need not be adjacent. They, however, must appear in same order in both input strings.\r\n\r\nExample:\r\n\r\n  str1 = 'abcdefghi';\r\n  str2 = 'zazbzczd';\r\n  \r\n  output = 'abcd'","description_html":"\u003cp\u003eTwo strings are given. Find the longest common substring between them. The substring characters need not be adjacent. They, however, must appear in same order in both input strings.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003estr1 = 'abcdefghi';\r\nstr2 = 'zazbzczd';\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eoutput = 'abcd'\r\n\u003c/pre\u003e","function_template":"function y = skipped(str1,str2)\r\n  y = x;\r\nend","test_suite":"%%\r\nstr1 = 'abcdefghi';\r\nstr2 = 'zazbzczd';\r\ny_correct = 'abcd';\r\nassert(isequal(skipped(str1,str2),y_correct))\r\n\r\n%%\r\nstr1 = 'abcdefghi';\r\nstr2 = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz';\r\ny_correct = '';\r\nassert(isequal(skipped(str1,str2),y_correct))\r\n\r\n\r\n\r\n%%\r\nstr1 = 'catcatcat';\r\nstr2 = 'catcatcat';\r\ny_correct = str1;\r\nassert(isequal(skipped(str1,str2),y_correct))\r\n\r\n\r\n%%\r\nstr1 = 'an example of a string';\r\nstr2 = 'the example z a s t r i i i n ssss';\r\ny_correct = ' example  a strin';\r\nassert(isequal(skipped(str1,str2),y_correct))\r\n\r\n\r\n%%\r\nstr1 = 'a string with many characters';\r\nstr2 = 'zzz zzz zzz zzz zzz';\r\ny_correct = '    ';\r\nassert(isequal(skipped(str1,str2),y_correct))\r\n\r\n\r\n%%\r\nstr1 = 'lets!not!use!spaces';\r\nstr2 = 'z!zzzzzzzzZZZzZzZ!zzzzz!zzzzzzzzz!!!!!!!!!zzz';\r\ny_correct = '!!!';\r\nassert(isequal(skipped(str1,str2),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":4,"created_by":17203,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":52,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":32,"created_at":"2014-08-20T10:44:21.000Z","updated_at":"2026-03-26T03:20:58.000Z","published_at":"2014-08-20T10:44:21.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\u003eTwo strings are given. Find the longest common substring between them. The substring characters need not be adjacent. They, however, must appear in same order in both input strings.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[str1 = 'abcdefghi';\\nstr2 = 'zazbzczd';\\n\\noutput = 'abcd']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":45415,"title":"Find an optimal placement of coolers on a grid","description":"In a certain chemical plant, 6 new pieces of cooling equipment (coolers) are to be installed in a vacant space. This vacant space was divided into a grid of 6 cells by 6 cells. Your task is to assign the 6 coolers to 6 cells in this grid with the following requirements:\r\n\r\n# There must be one cooler for every column in the grid.\r\n# If you decide to install a cooler at row R, column C, then the cooler at column C+1 must be installed either on row R-1, R, or R+1 only. This is done to ease the connection of coolers by piping.\r\n# The total installation cost for the 6 coolers must be minimum.\r\n\r\nFor this problem, you are given a cost matrix (COST) in relation to the third requirement above. COST is a 6 x 6 matrix where the _r,c_-th element is the cost of assigning any cooler to row _r_, column _c_ (All the coolers are identical). Write a function that accepts the matrix COST, and output the value of the minimum cost of installation. You are ensured that all elements of COST are integers in the range [1,1000].\r\n\r\nIn the sample test case below, the optimal placement is at the following rows: 4,3,3,2,2,2.\r\n\r\n  \u003e\u003e COST = [695   766   710   119   752   548;\r\n             318   796   755   499   256   139;\r\n             951   187   277   960   506   150;\r\n              35   490   680   341   700   258;\r\n             439   446   656   586   891   841;\r\n             382   647   163   224   960   255];\r\n  \u003e\u003e coolers(COST)\r\n  ans = \r\n        1393\r\n    \r\nMeanwhile, the optimal placement for the case below is at rows: 5,6,5,6,5,6\r\n\r\n  \u003e\u003e COST = [815   617   918    76   569   312;\r\n             244   474   286    54   470   529;\r\n             930   352   758   531   455   988;\r\n             350   831   754   780    12   602;\r\n             197   586   381   935   163   263;\r\n             252   550   568   130   795   100];\r\n  \u003e\u003e coolers(COST)\r\n  ans = \r\n        1521\r\n","description_html":"\u003cp\u003eIn a certain chemical plant, 6 new pieces of cooling equipment (coolers) are to be installed in a vacant space. This vacant space was divided into a grid of 6 cells by 6 cells. Your task is to assign the 6 coolers to 6 cells in this grid with the following requirements:\u003c/p\u003e\u003col\u003e\u003cli\u003eThere must be one cooler for every column in the grid.\u003c/li\u003e\u003cli\u003eIf you decide to install a cooler at row R, column C, then the cooler at column C+1 must be installed either on row R-1, R, or R+1 only. This is done to ease the connection of coolers by piping.\u003c/li\u003e\u003cli\u003eThe total installation cost for the 6 coolers must be minimum.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eFor this problem, you are given a cost matrix (COST) in relation to the third requirement above. COST is a 6 x 6 matrix where the \u003ci\u003er,c\u003c/i\u003e-th element is the cost of assigning any cooler to row \u003ci\u003er\u003c/i\u003e, column \u003ci\u003ec\u003c/i\u003e (All the coolers are identical). Write a function that accepts the matrix COST, and output the value of the minimum cost of installation. You are ensured that all elements of COST are integers in the range [1,1000].\u003c/p\u003e\u003cp\u003eIn the sample test case below, the optimal placement is at the following rows: 4,3,3,2,2,2.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e\u0026gt;\u0026gt; COST = [695   766   710   119   752   548;\r\n           318   796   755   499   256   139;\r\n           951   187   277   960   506   150;\r\n            35   490   680   341   700   258;\r\n           439   446   656   586   891   841;\r\n           382   647   163   224   960   255];\r\n\u0026gt;\u0026gt; coolers(COST)\r\nans = \r\n      1393\r\n\u003c/pre\u003e\u003cp\u003eMeanwhile, the optimal placement for the case below is at rows: 5,6,5,6,5,6\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e\u0026gt;\u0026gt; COST = [815   617   918    76   569   312;\r\n           244   474   286    54   470   529;\r\n           930   352   758   531   455   988;\r\n           350   831   754   780    12   602;\r\n           197   586   381   935   163   263;\r\n           252   550   568   130   795   100];\r\n\u0026gt;\u0026gt; coolers(COST)\r\nans = \r\n      1521\r\n\u003c/pre\u003e","function_template":"function y = coolers(COST)\r\n  y = x;\r\nend","test_suite":"%%\r\nfiletext = fileread('coolers.m')\r\nassert(isempty(strfind(filetext, 'rand')))\r\n%%\r\nCOST = [815   617   918    76   569   312;\r\n   244   474   286    54   470   529;\r\n   930   352   758   531   455   988;\r\n   350   831   754   780    12   602;\r\n   197   586   381   935   163   263;\r\n   252   550   568   130   795   100];\r\nassert(isequal(coolers(COST),1521))\r\n%%\r\nCOST = [690   153   107    85   182   550;\r\n   749   826   962   400   264   145;\r\n   451   539     5   260   146   854;\r\n    84   997   775   801   137   623;\r\n   229    79   818   432   870   351;\r\n   914   443   869   911   580   514];\r\nassert(isequal(coolers(COST),1179))\r\n%%\r\nCOST = [402   418   338   242   576    44;\r\n    76    50   901   404    60   169;\r\n   240   903   370    97   235   650;\r\n   124   945   112   132   354   732;\r\n   184   491   781   943   822   648;\r\n   240   490   390   957    16   451];\r\nassert(isequal(coolers(COST),697))\r\n%%\r\nCOST = [1 1 1000 1000 1000 1;\r\n        1 1000 1 1000 1000 1000;\r\n        1 1000 1000 1000 1 1000;\r\n        1 1000 1000 1 1000 1000;\r\n        1 1000 1000 1000 1000 1000;\r\n        1 1000 1000 1000 1000 1000];\r\nassert(isequal(coolers(COST),2004))\r\n%%\r\nCOST = [548   369   487   818   351   208;\r\n   297   626   436   795   940   302;\r\n   745   781   447   645   876   471;\r\n   189    82   307   379   551   231;\r\n   687   930   509   812   623   845;\r\n   184   776   511   533   588   195];\r\nassert(isequal(coolers(COST),1739))\r\n%%\r\nCOST = [226   431   259   222    86   489;\r\n   171   185   409   118   263   579;\r\n   228   905   595   297   802   238;\r\n   436   980   263   319    30   459;\r\n   312   439   603   425   929   964;\r\n   924   112   712   508   731   547];\r\nassert(isequal(coolers(COST),1234))\r\n%%\r\nCOST = [522   368    99   107   891   501;\r\n   232   988   262   654   335   480;\r\n   489    38   336   495   699   905;\r\n   625   886   680   780   198   610;\r\n   680   914   137   716    31   618;\r\n   396   797   722   904   745   860];\r\nassert(isequal(coolers(COST),1454))\r\n%%\r\nCOST = [806   490    60   819   973    84;\r\n   577   168   682   818   649   134;\r\n   183   979    43   723   801   174;\r\n   240   713    72   150   454   391;\r\n   887   501   522   660   433   832;\r\n    29   472    97   519   826   804];\r\nassert(isequal(coolers(COST),1172))\r\n%%\r\nCOST = [61         292         373          53         418         699;\r\n         400         432         199         738         984         667;\r\n         527          16         490         270         302         179;\r\n         417         985         340         423         702         129;\r\n         657         168         952         548         667        1000;\r\n         628         107         921         943         540         172];\r\nassert(isequal(coolers(COST),1253))\r\n%%\r\nCOST = [33   461   191   385   825   907;\r\n   562   982   429   583   983   880;\r\n   882   157   483   252   731   818;\r\n   670   856   121   291   344   261;\r\n   191   645   590   618   585   595;\r\n   369   377   227   266   108    23];\r\nassert(isequal(coolers(COST),1192))\r\n%%\r\nCOST = [426   599    69   719   779   441;\r\n   313   471   320   969   424   528;\r\n   162   696   531   532    91   458;\r\n   179   700   655   326   267   876;\r\n   423   639   408   106   154   519;\r\n    95    34   820   611   282   944];\r\nassert(isequal(coolers(COST),1316))\r\n%%\r\nCOST = [638   696   345   916   323   474;\r\n   958    68   781     2   785   153;\r\n   241   255   676   463   472   342;\r\n   677   225     7   425    36   608;\r\n   290   668   603   461   176   192;\r\n   672   845   387   771   722   739];\r\nassert(isequal(coolers(COST),1126))\r\n%%\r\nCOST = [243    92   648   237   771   257;\r\n   918   577   680   120   351   614;\r\n   270   684   636   608   663   583;\r\n   766   547   946   451   417   541;\r\n   189   426   209   459   842   870;\r\n   288   645   710   662   833   265];\r\nassert(isequal(coolers(COST),1711))\r\n%%\r\nCOST = [319   545   219   366   193   862;\r\n   120   648   106   764   139   485;\r\n   940   544   110   628   697   394;\r\n   646   722    64   772    94   672;\r\n   480   523   405   933   526   742;\r\n   640   994   449   973   531   521];\r\nassert(isequal(coolers(COST),1669))\r\n%%\r\nCOST = [674   622   842   636   885   896;\r\n   575   722   853   599   699   975;\r\n   794   844   722   911   905   664;\r\n   632   680   510   715   878   836;\r\n   523   869   667   944   689   720;\r\n   878   698   713   696   609   917];\r\nassert(isequal(coolers(COST),3837))\r\n%%\r\nCOST = [82 122 681 602 355 371;...\r\n    483 544 417 347 776 384;...\r\n    129 315 643 365 237 862;...\r\n    253 383 215 172 845 464;...\r\n    884 792 618 796 817 571;...\r\n    197 840 676 493 847 696];\r\nassert(isequal(coolers(COST),1452))\r\n%%\r\nCOST = [961 170 710 563 536 327;...\r\n    547 179 176 177 199 603;...\r\n    637 244 859 514 624 362;...\r\n    571 752 910 549 27 135;...\r\n    928 200 962 166 319 914;...\r\n    864 983 571 494 533 641];\r\nassert(isequal(coolers(COST),1569))\r\n%%\r\nCOST = [659 381 223 112 267 869;...\r\n    676 822 1000 425 292 529;...\r\n    745 172 64 614 189 915;...\r\n    843 330 426 989 23 974;...\r\n    517 967 405 220 450 586;...\r\n    152 807 401 355 244 119];\r\nassert(isequal(coolers(COST),1835))\r\n%%\r\nCOST = [927 925 215 554 571 679;...\r\n    594 643 249 631 336 213;...\r\n    884 105 227 986 958 82;...\r\n    425 701 704 635 440 275;...\r\n    608 396 755 601 602 868;...\r\n    71 85 548 910 721 560];\r\nassert(isequal(coolers(COST),1751))\r\n%%\r\nCOST = [465 433 384 904 809 299;...\r\n    431 506 712 219 180 769;...\r\n    774 376 481 874 166 502;...\r\n    654 481 730 83 182 910;...\r\n    658 343 938 466 692 58;...\r\n    162 778 518 22 214 437];\r\nassert(isequal(coolers(COST),1317))\r\n%%\r\nCOST = [573 952 497 860 78 228;...\r\n    566 767 809 627 339 710;...\r\n    824 752 633 181 581 149;...\r\n    127 139 689 574 476 659;...\r\n    301 350 640 164 806 634;...\r\n    3 152 730 907 531 230];\r\nassert(isequal(coolers(COST),1568))\r\n%%\r\nCOST = [183 958 897 179 998 879;...\r\n    167 26 190 747 5 747;...\r\n    150 972 661 50 543 118;...\r\n    203 298 942 72 862 510;...\r\n    955 526 976 490 910 169;...\r\n    16 863 108 850 846 832];\r\nassert(isequal(coolers(COST),539))\r\n%%\r\nCOST = [929 868 245 81 27 760;...\r\n    170 742 641 361 786 926;...\r\n    884 448 809 829 923 833;...\r\n    388 710 854 215 493 260;...\r\n    383 945 399 792 835 214;...\r\n    272 175 116 655 132 523];\r\nassert(isequal(coolers(COST),1564))\r\n%%\r\nCOST = [398 438 798 217 378 972;...\r\n    480 773 656 812 168 361;...\r\n    994 745 33 139 541 645;...\r\n    605 443 558 882 102 68;...\r\n    945 54 720 924 40 208;...\r\n    491 88 111 13 934 40];\r\nassert(isequal(coolers(COST),749))\r\n%%\r\nCOST = [470 581 9 642 470 879;...\r\n    151 541 825 106 220 189;...\r\n    992 706 768 269 923 760;...\r\n    428 6 998 764 321 32;...\r\n    956 783 228 806 858 643;...\r\n    725 927 920 105 260 567];\r\nassert(isequal(coolers(COST),1216))\r\n%%\r\nCOST = [377 187 35 595 562 603;...\r\n    213 486 489 499 634 474;...\r\n    793 839 972 568 931 357;...\r\n    146 142 113 427 978 476;...\r\n    490 733 744 77 94 672;...\r\n    13 692 639 291 662 960];\r\nassert(isequal(coolers(COST),1048))\r\n%%\r\nCOST = [90 52 454 629 707 46;...\r\n    798 505 738 133 536 886;...\r\n    591 769 510 619 194 840;...\r\n    913 283 383 384 690 119;...\r\n    102 226 906 992 51 411;...\r\n    294 332 966 287 185 121];\r\nassert(isequal(coolers(COST),1042))\r\n%%\r\nCOST = [573 666 232 754 549 464;...\r\n    950 974 53 622 461 590;...\r\n    257 623 902 395 646 188;...\r\n    990 64 794 360 514 612;...\r\n    350 374 374 89 815 52;...\r\n    209 167 833 342 98 576];\r\nassert(isequal(coolers(COST),934))\r\n%%\r\nCOST = [843 797 666 67 652 382;...\r\n    500 294 961 898 134 301;...\r\n    440 116 944 498 639 341;...\r\n    150 376 113 772 385 919;...\r\n    29 829 649 61 766 457;...\r\n    757 842 481 263 653 443];\r\nassert(isequal(coolers(COST),1166))\r\n%%\r\nCOST = [455 767 602 56 365 673;...\r\n    946 343 650 99 677 203;...\r\n    220 619 343 650 376 869;...\r\n    883 454 494 765 864 752;...\r\n    20 11 702 988 292 420;...\r\n    342 600 888 126 134 1];\r\nassert(isequal(coolers(COST),994))\r\n%%\r\nCOST = [150 436 24 66 150 132;...\r\n    274 904 575 924 351 887;...\r\n    873 926 47 535 336 675;...\r\n    602 506 423 367 785 836;...\r\n    322 628 468 364 487 657;...\r\n    285 720 23 152 465 984];\r\nassert(isequal(coolers(COST),958))\r\n%%\r\nCOST = [980 191 386 245 842 952;...\r\n    251 125 311 804 79 966;...\r\n    625 3 4 824 238 766;...\r\n    729 153 816 853 818 575;...\r\n    499 535 639 468 406 916;...\r\n    850 511 449 971 467 496];\r\nassert(isequal(coolers(COST),1655))\r\n%%\r\nCOST = [167 167 988 896 65 887;...\r\n    326 948 151 835 264 421;...\r\n    297 812 959 3 103 284;...\r\n    559 711 531 641 484 49;...\r\n    68 971 75 804 419 220;...\r\n    69 999 312 246 382 240];\r\nassert(isequal(coolers(COST),640))\r\n%%\r\nCOST = [30 653 667 689 433 469;...\r\n    703 321 848 321 905 546;...\r\n    8 104 763 532 631 180;...\r\n    611 536 808 874 984 635;...\r\n    409 165 633 55 586 963;...\r\n    249 884 711 501 841 535];\r\nassert(isequal(coolers(COST),2007))\r\n%%\r\nCOST = [480 679 683 689 62 13;...\r\n    794 566 947 148 220 217;...\r\n    93 479 100 778 83 12;...\r\n    881 321 512 400 951 643;...\r\n    4 602 111 899 17 517;...\r\n    512 914 546 308 115 246];\r\nassert(isequal(coolers(COST),648))\r\n%%\r\nCOST = [194 309 342 580 56 396;...\r\n    91 745 840 329 35 170;...\r\n    369 840 983 269 287 431;...\r\n    8 263 627 551 78 417;...\r\n    603 515 182 181 901 729;...\r\n    479 447 124 679 847 407];\r\nassert(isequal(coolers(COST),1129))\r\n%%\r\nCOST = [952 211 79 334 443 924;...\r\n    912 131 934 693 633 153;...\r\n    952 521 603 204 930 406;...\r\n    347 906 378 959 530 313;...\r\n    291 403 665 712 627 694;...\r\n    887 216 793 167 681 891];\r\nassert(isequal(coolers(COST),2052))\r\n%%\r\nCOST = [491 677 35 27 661 34;...\r\n    806 829 437 501 330 407;...\r\n    327 111 937 828 660 717;...\r\n    550 280 263 259 14 922;...\r\n    389 768 570 46 719 985;...\r\n    897 217 360 247 392 984];\r\nassert(isequal(coolers(COST),1266))\r\n%%\r\nCOST = [897 655 269 739 879 390;...\r\n    866 864 153 13 903 300;...\r\n    801 275 631 606 153 735;...\r\n    555 841 317 577 193 105;...\r\n    419 71 960 808 791 793;...\r\n    128 379 499 655 61 783];\r\nassert(isequal(coolers(COST),1254))\r\n%%\r\nCOST = [533 130 314 596 463 399;...\r\n    254 451 642 537 368 478;...\r\n    71 673 787 331 680 67;...\r\n    626 857 290 412 568 412;...\r\n    25 499 498 795 652 970;...\r\n    63 49 819 344 492 781];\r\nassert(isequal(coolers(COST),1580))\r\n%%\r\nCOST = [730 112 727 411 679 798;...\r\n    766 397 148 143 254 712;...\r\n    757 493 148 799 844 784;...\r\n    844 259 705 931 294 624;...\r\n    771 37 381 5 27 826;...\r\n    979 975 77 651 94 36];\r\nassert(isequal(coolers(COST),953))\r\n%%\r\nCOST = [406 27 672 377 507 436;...\r\n    250 156 53 114 329 158;...\r\n    481 834 735 965 754 601;...\r\n    881 195 500 433 837 938;...\r\n    281 830 944 85 254 108;...\r\n    600 339 290 717 535 900];\r\nassert(isequal(coolers(COST),931))\r\n%%\r\nCOST = [551 355 642 427 787 943;...\r\n    428 774 128 34 512 97;...\r\n    153 882 497 930 563 846;...\r\n    248 735 311 925 685 910;...\r\n    448 407 579 359 93 12;...\r\n    533 605 944 260 873 524];\r\nassert(isequal(coolers(COST),1430))\r\n%%\r\nCOST = [651 279 401 430 885 568;...\r\n    386 840 555 38 256 895;...\r\n    650 427 444 976 910 215;...\r\n    763 632 91 523 895 4;...\r\n    576 834 745 910 399 881;...\r\n    632 271 33 384 626 236];\r\nassert(isequal(coolers(COST),1575))\r\n%%\r\nCOST = [245 391 532 153 716 903;...\r\n    641 802 889 231 281 290;...\r\n    305 158 264 658 413 500;...\r\n    826 626 235 563 363 784;...\r\n    884 699 840 292 782 678;...\r\n    946 86 496 623 136 150];\r\nassert(isequal(coolers(COST),1276))\r\n%%\r\nCOST = [697 977 429 793 902 349;...\r\n    130 126 15 420 52 166;...\r\n    946 753 326 533 809 29;...\r\n    887 828 135 926 335 956;...\r\n    516 782 451 900 229 681;...\r\n    680 191 573 545 823 861];\r\nassert(isequal(coolers(COST),772))\r\n%%\r\nCOST = [940 301 652 887 695 895;...\r\n    681 74 170 115 207 842;...\r\n    918 768 532 443 555 131;...\r\n    257 85 634 660 880 190;...\r\n    886 729 15 295 558 154;...\r\n    921 448 471 951 753 29];\r\nassert(isequal(coolers(COST),1239))\r\n%%\r\nCOST = [10 496 746 686 237 463;...\r\n    597 259 338 268 196 926;...\r\n    610 733 585 970 706 216;...\r\n    919 117 469 184 181 2;...\r\n    734 747 88 300 523 907;...\r\n    302 810 829 412 297 681];\r\nassert(isequal(coolers(COST),1182))\r\n%%\r\nCOST = [515 394 842 779 399 396;...\r\n    523 8 49 728 671 399;...\r\n    103 546 317 651 441 752;...\r\n    997 510 784 665 133 523;...\r\n    359 247 973 939 440 491;...\r\n    626 46 587 536 548 89];\r\nassert(isequal(coolers(COST),1435))\r\n%%\r\nCOST = [251 93 71 159 652 1;...\r\n    448 954 301 63 499 641;...\r\n    638 163 814 702 285 8;...\r\n    710 971 77 87 831 107;...\r\n    993 598 355 617 819 107;...\r\n    933 241 133 174 939 368];\r\nassert(isequal(coolers(COST),771))\r\n%%\r\nCOST = [240 788 66 813 71 954;...\r\n    347 270 611 815 242 209;...\r\n    250 844 702 90 732 117;...\r\n    388 741 112 732 41 647;...\r\n    422 827 96 904 425 109;...\r\n    641 183 598 453 541 984];\r\nassert(isequal(coolers(COST),1343))\r\n%%\r\nCOST = [249 916 747 918 880 282;...\r\n    607 901 476 471 799 169;...\r\n    817 215 584 270 325 746;...\r\n    831 548 261 763 670 478;...\r\n    490 785 85 773 297 654;...\r\n    761 195 299 22 930 967];\r\nassert(isequal(coolers(COST),1567))\r\n%%\r\nCOST = [314 77 818 283 736 557;...\r\n    77 154 767 639 157 274;...\r\n    792 827 375 593 435 133;...\r\n    366 301 190 326 833 700;...\r\n    586 384 647 989 360 486;...\r\n    184 651 4 124 77 183];\r\nassert(isequal(coolers(COST),956))\r\n%%\r\nCOST = [102 248 381 378 851 968;...\r\n    202 438 749 973 257 477;...\r\n    135 670 157 606 286 995;...\r\n    324 548 59 339 780 491;...\r\n    951 610 340 928 702 504;...\r\n    533 864 818 899 493 769];\r\nassert(isequal(coolers(COST),1799))\r\n%%\r\nCOST = [389 799 340 268 52 543;...\r\n    454 221 273 177 628 809;...\r\n    133 858 171 432 30 794;...\r\n    759 905 665 476 137 502;...\r\n    566 293 536 786 695 277;...\r\n    649 726 830 131 516 120];\r\nassert(isequal(coolers(COST),1234))\r\n%%\r\nCOST = [887 183 567 504 84 962;...\r\n    971 32 378 261 74 467;...\r\n    943 725 822 733 770 787;...\r\n    639 145 305 163 818 423;...\r\n    91 636 320 922 741 944;...\r\n    75 790 785 223 759 2];\r\nassert(isequal(coolers(COST),1447))\r\n%%\r\nCOST = [982 666 329 847 415 7;...\r\n    571 685 928 902 662 767;...\r\n    347 793 757 596 784 22;...\r\n    558 349 289 69 248 394;...\r\n    300 251 607 219 555 253;...\r\n    160 346 767 870 230 205];\r\nassert(isequal(coolers(COST),1039))\r\n%%\r\nCOST = [663 975 947 135 372 260;...\r\n    915 120 967 806 227 134;...\r\n    7 519 68 525 447 420;...\r\n    747 822 438 945 267 507;...\r\n    800 638 321 989 460 325;...\r\n    908 954 135 410 433 685];\r\nassert(isequal(coolers(COST),1081))\r\n%%\r\nCOST = [444 502 305 970 394 701;...\r\n    436 556 767 690 459 110;...\r\n    794 631 268 718 209 7;...\r\n    816 98 40 560 758 598;...\r\n    753 246 297 534 547 660;...\r\n    790 616 557 876 358 581];\r\nassert(isequal(coolers(COST),1667))\r\n%%\r\nCOST = [910 165 870 241 503 143;...\r\n    637 281 788 9 568 381;...\r\n    526 260 970 672 189 397;...\r\n    260 548 181 905 325 577;...\r\n    52 542 931 573 717 20;...\r\n    732 789 46 156 553 578];\r\nassert(isequal(coolers(COST),1369))\r\n%%\r\nCOST = [933 303 817 55 540 946;...\r\n    107 460 451 638 938 377;...\r\n    733 49 807 425 661 68;...\r\n    971 386 791 906 395 182;...\r\n    609 362 283 418 259 576;...\r\n    720 288 69 155 848 186];\r\nassert(isequal(coolers(COST),1495))\r\n%%\r\nCOST = [292 28 747 842 871 890;...\r\n    462 659 747 511 212 66;...\r\n    347 159 174 166 837 510;...\r\n    319 803 118 715 860 621;...\r\n    460 409 175 908 524 734;...\r\n    236 328 628 219 478 230];\r\nassert(isequal(coolers(COST),1040))\r\n%%\r\nCOST = [22 327 315 114 208 74;...\r\n    139 138 160 701 785 595;...\r\n    770 385 153 180 527 862;...\r\n    970 563 137 804 572 449;...\r\n    387 634 710 514 423 653;...\r\n    994 542 465 549 722 304];\r\nassert(isequal(coolers(COST),716))\r\n%%\r\nCOST = [608 457 948 406 340 75;...\r\n    279 600 453 439 896 664;...\r\n    800 843 811 679 546 704;...\r\n    797 32 929 466 750 919;...\r\n    955 188 673 954 125 661;...\r\n    445 944 373 355 454 691];\r\nassert(isequal(coolers(COST),2010))\r\n%%\r\nCOST = [854 26 473 324 731 29;...\r\n    468 57 679 802 774 128;...\r\n    459 143 115 300 901 134;...\r\n    807 172 237 776 139 129;...\r\n    825 626 290 553 795 936;...\r\n    191 30 173 555 190 274];\r\nassert(isequal(coolers(COST),1199))\r\n%%\r\nCOST = [943 546 850 417 382 152;...\r\n    639 256 8 518 723 437;...\r\n    873 306 635 887 96 13;...\r\n    368 16 360 150 668 230;...\r\n    237 588 115 435 297 264;...\r\n    188 963 541 60 599 512];\r\nassert(isequal(coolers(COST),627))\r\n%%\r\nCOST = [216 475 261 618 402 95;...\r\n    347 826 590 145 15 376;...\r\n    748 304 480 717 75 546;...\r\n    414 822 199 402 592 112;...\r\n    56 566 240 463 447 905;...\r\n    391 55 781 708 927 634];\r\nassert(isequal(coolers(COST),940))\r\n%%\r\nCOST = [906 61 814 762 771 880;...\r\n    631 674 316 876 876 374;...\r\n    15 478 312 872 68 767;...\r\n    317 306 345 173 647 169;...\r\n    112 517 667 851 325 520;...\r\n    630 708 862 960 641 628];\r\nassert(isequal(coolers(COST),1043))\r\n%%\r\nCOST = [714 628 766 404 544 135;...\r\n    307 193 319 751 411 541;...\r\n    264 777 253 488 901 858;...\r\n    917 865 201 385 57 199;...\r\n    616 334 70 62 444 156;...\r\n    94 136 552 214 538 62];\r\nassert(isequal(coolers(COST),575))\r\n%%\r\nCOST = [662 683 487 77 915 603;...\r\n    19 138 680 445 92 466;...\r\n    292 630 705 166 994 299;...\r\n    974 858 461 399 97 134;...\r\n    765 900 365 921 314 296;...\r\n    244 349 281 512 786 167];\r\nassert(isequal(coolers(COST),1112))\r\n%%\r\nCOST = [318 40 863 414 595 658;...\r\n    110 617 277 415 310 685;...\r\n    833 670 532 984 902 474;...\r\n    972 38 523 58 94 142;...\r\n    219 4 568 397 320 951;...\r\n    707 143 334 792 887 883];\r\nassert(isequal(coolers(COST),1040))\r\n%%\r\nCOST = [438 952 914 477 226 187;...\r\n    835 2 534 251 568 647;...\r\n    326 296 805 308 999 129;...\r\n    368 49 563 967 132 82;...\r\n    795 443 751 209 955 660;...\r\n    100 790 10 521 124 28];\r\nassert(isequal(coolers(COST),914))\r\n%%\r\nCOST = [986 693 226 415 41 625;...\r\n    540 603 797 499 583 296;...\r\n    374 776 997 950 565 75;...\r\n    707 592 282 954 356 294;...\r\n    948 377 711 733 881 235;...\r\n    383 851 665 385 625 346];\r\nassert(isequal(coolers(COST),1955))\r\n%%\r\nCOST = [849 636 448 593 844 465;...\r\n    161 844 327 69 424 31;...\r\n    158 783 280 206 545 435;...\r\n    509 265 932 724 528 558;...\r\n    604 315 400 576 186 639;...\r\n    162 184 380 201 82 35];\r\nassert(isequal(coolers(COST),1044))\r\n%%\r\nCOST = [710 855 367 351 91 968;...\r\n    170 385 350 193 258 434;...\r\n    594 400 631 920 428 785;...\r\n    609 326 665 289 578 526;...\r\n    773 556 993 551 900 332;...\r\n    57 296 945 920 219 432];\r\nassert(isequal(coolers(COST),1623))\r\n%%\r\nCOST = [718 654 235 805 97 557;...\r\n    917 41 201 104 600 840;...\r\n    891 505 381 730 234 205;...\r\n    135 895 595 649 33 622;...\r\n    120 386 269 475 580 175;...\r\n    894 293 623 933 843 290];\r\nassert(isequal(coolers(COST),1365))\r\n%%\r\nCOST = [19 283 206 904 234 347;...\r\n    702 245 435 541 247 298;...\r\n    953 287 143 818 171 405;...\r\n    750 964 376 709 236 303;...\r\n    757 231 794 44 276 758;...\r\n    543 538 813 146 952 360];\r\nassert(isequal(coolers(COST),1417))\r\n%%\r\nCOST = [125 458 201 22 719 780;...\r\n    618 78 960 483 450 568;...\r\n    356 905 666 808 660 77;...\r\n    363 282 542 737 754 252;...\r\n    69 614 869 573 805 134;...\r\n    868 662 558 9 30 565];\r\nassert(isequal(coolers(COST),953))\r\n%%\r\nCOST = [541 43 122 494 863 421;...\r\n    69 528 592 856 685 488;...\r\n    989 257 360 725 635 461;...\r\n    252 409 720 200 142 516;...\r\n    316 948 524 158 80 272;...\r\n    301 920 261 371 877 232];\r\nassert(isequal(coolers(COST),1198))\r\n%%\r\nCOST = [900 895 226 336 740 434;...\r\n    909 88 105 620 889 290;...\r\n    604 540 10 993 860 632;...\r\n    366 429 60 649 598 296;...\r\n    599 618 323 540 655 623;...\r\n    669 559 780 233 916 48];\r\nassert(isequal(coolers(COST),2054))\r\n%%\r\nCOST = [995 67 543 281 171 63;...\r\n    207 928 781 599 372 407;...\r\n    608 88 522 37 40 464;...\r\n    348 333 932 64 710 203;...\r\n    718 527 148 323 642 870;...\r\n    28 247 417 99 175 598];\r\nassert(isequal(coolers(COST),730))\r\n%%\r\nCOST = [24 867 571 301 445 250;...\r\n    900 616 326 522 983 956;...\r\n    453 27 451 562 579 143;...\r\n    59 323 578 242 235 513;...\r\n    107 464 75 913 811 972;...\r\n    999 100 58 826 452 649];\r\nassert(isequal(coolers(COST),902))\r\n%%\r\nCOST = [615 424 874 119 114 462;...\r\n    470 274 301 99 491 864;...\r\n    578 445 401 891 600 263;...\r\n    912 628 518 34 91 824;...\r\n    377 535 62 840 979 329;...\r\n    229 386 232 508 654 942];\r\nassert(isequal(coolers(COST),1065))\r\n%%\r\nCOST = [245 314 524 145 800 565;...\r\n    958 58 893 245 209 218;...\r\n    511 45 406 379 897 858;...\r\n    565 813 605 271 746 862;...\r\n    994 413 95 216 537 314;...\r\n    771 385 336 634 970 327];\r\nassert(isequal(coolers(COST),1381))\r\n%%\r\nCOST = [841 334 286 610 505 816;...\r\n    493 367 657 384 8 910;...\r\n    52 795 232 31 920 778;...\r\n    779 39 622 858 411 758;...\r\n    427 727 76 604 733 406;...\r\n    280 873 967 848 152 702];\r\nassert(isequal(coolers(COST),1140))\r\n%%\r\nCOST = [566 563 904 539 781 176;...\r\n    585 547 605 738 537 417;...\r\n    345 551 927 182 770 740;...\r\n    705 695 117 427 639 893;...\r\n    161 928 341 99 894 26;...\r\n    2 945 37 304 61 138];\r\nassert(isequal(coolers(COST),1153))\r\n%%\r\nCOST = [425 619 192 805 191 892;...\r\n    765 7 715 860 504 674;...\r\n    525 741 178 567 51 686;...\r\n    755 992 987 755 57 696;...\r\n    170 129 17 520 336 800;...\r\n    673 361 40 586 631 661];\r\nassert(isequal(coolers(COST),1579))\r\n%%\r\nCOST = [520 255 928 227 995 523;...\r\n    332 846 588 2 984 274;...\r\n    935 539 102 894 965 719;...\r\n    247 911 367 454 667 779;...\r\n    512 351 276 579 727 82;...\r\n    741 936 267 316 335 222];\r\nassert(isequal(coolers(COST),1598))\r\n%%\r\nCOST = [204 470 675 379 889 587;...\r\n    625 379 552 618 563 969;...\r\n    726 341 52 563 195 582;...\r\n    835 64 308 831 222 100;...\r\n    19 762 966 958 706 167;...\r\n    203 403 932 76 597 103];\r\nassert(isequal(coolers(COST),993))\r\n%%\r\nCOST = [147 800 210 627 782 774;...\r\n    672 400 481 412 936 748;...\r\n    640 756 113 639 740 319;...\r\n    373 296 133 857 254 511;...\r\n    163 641 65 764 720 774;...\r\n    390 886 80 977 694 573];\r\nassert(isequal(coolers(COST),1784))\r\n%%\r\nCOST = [954 463 111 359 365 588;...\r\n    172 130 200 135 400 778;...\r\n    908 550 163 999 927 658;...\r\n    753 970 37 514 496 529;...\r\n    287 443 273 388 610 826;...\r\n    628 591 231 250 5 963];\r\nassert(isequal(coolers(COST),1501))\r\n%%\r\nCOST = [314 306 715 905 664 101;...\r\n    798 19 460 387 603 287;...\r\n    286 163 920 604 657 355;...\r\n    15 444 989 561 310 536;...\r\n    95 767 933 846 332 991;...\r\n    329 682 462 285 189 29];\r\nassert(isequal(coolers(COST),1729))\r\n%%\r\nCOST = [710 876 77 818 359 455;...\r\n    906 865 377 174 364 30;...\r\n    866 356 150 677 268 638;...\r\n    120 632 35 876 338 60;...\r\n    956 865 783 758 87 170;...\r\n    441 21 328 230 452 685];\r\nassert(isequal(coolers(COST),1098))\r\n%%\r\nCOST = [555 461 15 279 896 625;...\r\n    7 371 5 645 888 207;...\r\n    289 825 167 288 394 110;...\r\n    377 538 366 322 676 566;...\r\n    147 818 719 156 253 275;...\r\n    75 461 160 388 950 72];\r\nassert(isequal(coolers(COST),1175))\r\n%%\r\nCOST = [159 896 447 617 948 551;...\r\n    50 608 812 304 334 161;...\r\n    681 15 145 90 390 118;...\r\n    782 345 975 522 151 399;...\r\n    808 534 834 826 334 832;...\r\n    266 628 341 764 554 186];\r\nassert(isequal(coolers(COST),569))\r\n%%\r\nCOST = [501 491 579 185 613 662;...\r\n    127 887 776 198 738 896;...\r\n    865 906 662 862 304 275;...\r\n    767 499 470 126 43 998;...\r\n    565 530 220 646 836 835;...\r\n    390 910 603 438 370 792];\r\nassert(isequal(coolers(COST),1584))\r\n%%\r\nCOST = [657 988 206 794 242 185;...\r\n    544 789 495 682 210 88;...\r\n    387 853 32 651 273 309;...\r\n    823 486 828 238 776 231;...\r\n    596 874 265 478 332 910;...\r\n    782 334 678 937 604 937];\r\nassert(isequal(coolers(COST),1504))\r\n%%\r\nCOST = [32 626 369 811 16 974;...\r\n    594 256 338 724 95 373;...\r\n    44 905 619 675 515 321;...\r\n    425 768 87 914 953 784;...\r\n    522 563 376 821 844 213;...\r\n    841 898 188 549 936 960];\r\nassert(isequal(coolers(COST),1717))\r\n%%\r\nCOST = [931 594 600 844 914 151;...\r\n    366 98 227 771 577 947;...\r\n    345 560 714 510 288 651;...\r\n    693 44 725 707 267 983;...\r\n    717 758 345 792 891 194;...\r\n    801 660 33 331 367 829];\r\nassert(isequal(coolers(COST),1626))\r\n%%\r\nCOST = [494 60 648 497 429 28;...\r\n    591 516 624 763 42 906;...\r\n    45 54 954 180 226 472;...\r\n    565 844 177 692 667 911;...\r\n    634 595 475 915 872 328;...\r\n    499 692 843 163 345 692];\r\nassert(isequal(coolers(COST),526))\r\n%%\r\nCOST = [18 334 151 424 616 681;...\r\n    513 633 839 529 102 394;...\r\n    332 416 727 276 670 392;...\r\n    337 577 109 828 348 207;...\r\n    954 960 162 793 670 725;...\r\n    751 616 298 274 296 820];\r\nassert(isequal(coolers(COST),1421))\r\n%%\r\nCOST = [927 854 101 228 459 109;...\r\n    515 430 413 358 952 652;...\r\n    194 926 925 925 133 147;...\r\n    603 374 56 503 71 694;...\r\n    199 699 385 804 707 626;...\r\n    411 589 241 351 932 44];\r\nassert(isequal(coolers(COST),1345))\r\n%%\r\nCOST = [798 582 93 769 788 680;...\r\n    987 602 334 283 125 10;...\r\n    437 253 652 650 158 129;...\r\n    345 655 504 923 415 764;...\r\n    49 61 531 331 688 842;...\r\n    226 941 380 814 658 747];\r\nassert(isequal(coolers(COST),1350))\r\n%%\r\nCOST = [945 618 338 215 587 443;...\r\n    920 559 552 293 939 692;...\r\n    224 731 744 450 619 760;...\r\n    510 64 413 241 251 400;...\r\n    788 493 508 264 103 568;...\r\n    523 230 129 892 547 206];\r\nassert(isequal(coolers(COST),1251))\r\n%%\r\nCOST = [944 708 393 379 767 434;...\r\n    513 657 243 634 337 103;...\r\n    277 779 282 32 626 237;...\r\n    230 581 905 921 327 972;...\r\n    953 504 703 470 312 699;...\r\n    690 879 854 520 647 660];\r\nassert(isequal(coolers(COST),1565))\r\n%%\r\nCOST = [327 450 172 573 377 40;...\r\n    20 769 722 832 394 565;...\r\n    571 628 90 348 429 50;...\r\n    37 315 918 780 424 873;...\r\n    265 293 430 709 219 861;...\r\n    191 79 80 591 497 339];\r\nassert(isequal(coolers(COST),1224))\r\n%%\r\nCOST = [975 347 346 214 761 636;...\r\n    955 234 903 936 580 803;...\r\n    989 756 13 970 622 670;...\r\n    158 226 133 376 490 472;...\r\n    3 449 389 985 221 945;...\r\n    249 260 841 123 145 592];\r\nassert(isequal(coolers(COST),1311))\r\n%%\r\nCOST = [227 932 883 581 327 592;...\r\n    684 697 780 627 288 1;...\r\n    321 96 19 112 497 904;...\r\n    749 246 771 214 182 683;...\r\n    999 935 686 37 934 74;...\r\n    270 480 868 445 941 997];\r\nassert(isequal(coolers(COST),804))\r\n%%\r\nCOST = [315 176 835 189 254 788;...\r\n    810 588 997 578 287 438;...\r\n    462 155 973 629 126 551;...\r\n    588 446 746 365 529 987;...\r\n    478 538 200 637 821 690;...\r\n    553 462 37 892 300 971];\r\nassert(isequal(coolers(COST),2037))\r\n%%\r\nCOST = [96 320 833 203 939 1;...\r\n    899 796 571 493 975 484;...\r\n    59 302 71 730 608 148;...\r\n    124 608 267 955 958 315;...\r\n    631 462 171 763 331 172;...\r\n    371 293 561 81 902 593];\r\nassert(isequal(coolers(COST),1341))\r\n%%\r\nCOST = [658 16 262 188 656 56;...\r\n    349 974 894 744 782 820;...\r\n    54 735 973 719 863 107;...\r\n    48 753 995 189 786 7;...\r\n    56 34 347 434 434 276;...\r\n    72 118 293 46 348 943];\r\nassert(isequal(coolers(COST),862))\r\n%%\r\nCOST = [675 962 293 837 855 788;...\r\n    386 823 439 42 174 175;...\r\n    857 11 399 424 536 720;...\r\n    675 142 138 76 295 233;...\r\n    609 483 953 314 903 208;...\r\n    440 581 361 946 82 217];\r\nassert(isequal(coolers(COST),1114))\r\n%%\r\nCOST = [977 461 237 907 842 269;...\r\n    382 4 832 993 684 981;...\r\n    636 465 438 391 172 313;...\r\n    47 825 508 827 238 572;...\r\n    233 872 186 955 435 612;...\r\n    875 302 152 894 26 902];\r\nassert(isequal(coolers(COST),1700))\r\n%%\r\nCOST = [397 297 634 847 995 269;...\r\n    693 572 965 41 429 758;...\r\n    205 317 201 330 268 610;...\r\n    63 810 599 710 473 967;...\r\n    623 366 84 861 161 774;...\r\n    689 699 545 501 159 573];\r\nassert(isequal(coolers(COST),1320))\r\n%%\r\nCOST = [451 355 996 87 199 597;...\r\n    288 581 84 520 657 323;...\r\n    753 299 469 553 699 831;...\r\n    95 714 94 686 460 123;...\r\n    107 361 726 300 158 252;...\r\n    735 719 913 602 422 938];\r\nassert(isequal(coolers(COST),1069))\r\n\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":2,"created_by":255320,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":56,"test_suite_updated_at":"2020-04-03T23:22:52.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-04-01T22:04:29.000Z","updated_at":"2026-02-26T16:11:43.000Z","published_at":"2020-04-01T22:55:22.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn a certain chemical plant, 6 new pieces of cooling equipment (coolers) are to be installed in a vacant space. This vacant space was divided into a grid of 6 cells by 6 cells. Your task is to assign the 6 coolers to 6 cells in this grid with the following requirements:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere must be one cooler for every column in the grid.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf you decide to install a cooler at row R, column C, then the cooler at column C+1 must be installed either on row R-1, R, or R+1 only. This is done to ease the connection of coolers by piping.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe total installation cost for the 6 coolers must be minimum.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor this problem, you are given a cost matrix (COST) in relation to the third requirement above. COST is a 6 x 6 matrix where the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003er,c\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e-th element is the cost of assigning any cooler to row\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003er\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, column\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ec\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (All the coolers are identical). Write a function that accepts the matrix COST, and output the value of the minimum cost of installation. You are ensured that all elements of COST are integers in the range [1,1000].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn the sample test case below, the optimal placement is at the following rows: 4,3,3,2,2,2.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[\u003e\u003e COST = [695   766   710   119   752   548;\\n           318   796   755   499   256   139;\\n           951   187   277   960   506   150;\\n            35   490   680   341   700   258;\\n           439   446   656   586   891   841;\\n           382   647   163   224   960   255];\\n\u003e\u003e coolers(COST)\\nans = \\n      1393]]\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\u003eMeanwhile, the optimal placement for the case below is at rows: 5,6,5,6,5,6\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[\u003e\u003e COST = [815   617   918    76   569   312;\\n           244   474   286    54   470   529;\\n           930   352   758   531   455   988;\\n           350   831   754   780    12   602;\\n           197   586   381   935   163   263;\\n           252   550   568   130   795   100];\\n\u003e\u003e coolers(COST)\\nans = \\n      1521]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":55305,"title":"Chain multiplication - 02","description":"Following up on the problem in 55295, you found the number of multiplications needed to multiply two matrices.\r\nNow, you are given a sequence of matrices. There are many different ways you can multiply the matrices. For example, \r\nsay, you are given 4 matrix - A, B, C, D. They can be multiplied as follows - A(B(CD)), A((BC)D), ((AB)C)D, (AB)(CD), (A(BC))D.\r\n\r\nyou have to figure out which is the optimal way of multiplying those matrices based on the mininum number of multiplications required. For example, consider a simple 3 matrix case.\r\nA(1,2), B(2,3), C(3,2)\r\nA(BC) =\u003e BC requires 12 multiplications; multiplying A matrix with the result requires 4 multiplications. Total = 12+4= 16.\r\n(AB)C =\u003e AB requires 6 multiplications; multiplying the result with the C matrix requires 6 multiplications. Total = 6+6= 12.\r\nTherefore, to multiply ABC - the optimal way is (AB)C requiring 12 multiplications in total.\r\n\r\nHere, you will be given an array 'a' containing the size of consequtive matrices. The output is the minimum number of multiplications required to multiply those matrices.\r\nhere, a = [2, 4, 6, 1] represents 3 matrices --  A(2,4), B(4,6), and C(6,1)","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: 414px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 207px; transform-origin: 407px 207px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eFollowing up on the problem in \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/55295-chain-multiplication-01\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e55295\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e, you found the number of multiplications needed to multiply two matrices.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eNow, you are given a sequence of matrices. There are many different ways you can multiply the matrices. For example, \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003esay, you are given 4 matrix - A, B, C, D. They can be multiplied as follows - A(B(CD)), A((BC)D), ((AB)C)D, (AB)(CD), (A(BC))D.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eyou have to figure out which is the optimal way of multiplying those matrices based on the mininum number of multiplications required. For example, consider a simple 3 matrix case.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eA(1,2), B(2,3), C(3,2)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eA(BC) =\u0026gt; BC requires 12 multiplications; multiplying A matrix with the result requires 4 multiplications. Total = 12+4= 16.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e(AB)C =\u0026gt; AB requires 6 multiplications; multiplying the result with the C matrix requires 6 multiplications. Total = 6+6= 12.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eTherefore, to multiply ABC - the optimal way is (AB)C requiring 12 multiplications in total.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eHere, you will be given an array 'a' containing the size of consequtive matrices. The output is the minimum number of multiplications required to multiply those matrices.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003ehere, a = [2, 4, 6, 1] represents 3 matrices --  A(2,4), B(4,6), and C(6,1)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = chain_mul_02(a)\r\n  y = x;\r\nend","test_suite":"%%\r\na=[1,2,3,2];\r\ny_correct = 12;\r\nassert(isequal(chain_mul_02(a),y_correct))\r\n\r\n%%\r\na=[4,10,3,12,20,7];\r\ny_correct = 1344;\r\nassert(isequal(chain_mul_02(a),y_correct))\r\n\r\n\r\n%%\r\na=[1,2,3,4];\r\ny_correct = 18;\r\nassert(isequal(chain_mul_02(a),y_correct))\r\n\r\n\r\n%%\r\na=[81,213,78,96,2,1,98,102, 1200,4];\r\ny_correct = 179067;\r\nassert(isequal(chain_mul_02(a),y_correct))\r\n\r\n%%\r\na=[40, 20, 30, 10, 30];\r\ny_correct = 26000;\r\nassert(isequal(chain_mul_02(a),y_correct))\r\n\r\n%%\r\na=[7,1,5,4,2];\r\ny_correct = 42;\r\nassert(isequal(chain_mul_02(a),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":363598,"edited_by":363598,"edited_at":"2022-08-14T21:58:45.000Z","deleted_by":null,"deleted_at":null,"solvers_count":21,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2022-08-14T20:23:49.000Z","updated_at":"2026-02-10T20:51:38.000Z","published_at":"2022-08-14T21:45:21.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\u003eFollowing up on the problem in \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/55295-chain-multiplication-01\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e55295\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, you found the number of multiplications needed to multiply two matrices.\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\u003eNow, you are given a sequence of matrices. There are many different ways you can multiply the matrices. For example, \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\u003esay, you are given 4 matrix - A, B, C, D. They can be multiplied as follows - A(B(CD)), A((BC)D), ((AB)C)D, (AB)(CD), (A(BC))D.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eyou have to figure out which is the optimal way of multiplying those matrices based on the mininum number of multiplications required. For example, consider a simple 3 matrix case.\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\u003eA(1,2), B(2,3), C(3,2)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA(BC) =\u0026gt; BC requires 12 multiplications; multiplying A matrix with the result requires 4 multiplications. Total = 12+4= 16.\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(AB)C =\u0026gt; AB requires 6 multiplications; multiplying the result with the C matrix requires 6 multiplications. Total = 6+6= 12.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTherefore, to multiply ABC - the optimal way is (AB)C requiring 12 multiplications in total.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHere, you will be given an array 'a' containing the size of consequtive matrices. The output is the minimum number of multiplications required to multiply those matrices.\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\u003ehere, a = [2, 4, 6, 1] represents 3 matrices --  A(2,4), B(4,6), and C(6,1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"}],"no_progress_badge":{"id":53,"name":"Unknown","symbol":"unknown","description":"Partially completed groups","description_html":null,"image_location":"/images/responsive/supporting/matlabcentral/cody/badges/problem_groups_unknown_2.png","bonus":null,"players_count":0,"active":false,"created_by":null,"updated_by":null,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"created_at":"2018-01-10T23:20:29.000Z","updated_at":"2018-01-10T23:20:29.000Z","community_badge_id":null,"award_multiples":false}}