{"group":{"group":{"id":122,"name":"All Things Fibonacci","lockable":false,"created_at":"2019-01-18T22:44:03.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"It's everybody's favorite algorithmic sequence. Dig deep and you'll find bunny rabbits, golden ratios, and sunflower seeds. What's not to like? As a result, it shows up everywhere people write code. Here are my favorite Fibonacci-related problems on Cody.\nBy the way, that image is of Leonardo of Pisa. History knows him as Fibonacci, but his friends never called him that. Maybe we should call these things \"Leo sequences.\"","is_default":false,"created_by":7,"badge_id":62,"featured":false,"trending":false,"solution_count_in_trending_period":261,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":226,"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\u003eIt's everybody's favorite algorithmic sequence. Dig deep and you'll find bunny rabbits, golden ratios, and sunflower seeds. What's not to like? As a result, it shows up everywhere people write code. Here are my favorite Fibonacci-related problems on Cody.\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\u003eBy the way, that image is of Leonardo of Pisa. History knows him as Fibonacci, but his friends never called him that. Maybe we should call these things \\\"Leo sequences.\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}","description_html":"\u003cdiv style = \"text-align: start; line-height: normal; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"display: block; min-width: 0px; padding-top: 0px; perspective-origin: 289.5px 63px; transform-origin: 289.5px 63px; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; white-space: pre-wrap; perspective-origin: 266.5px 63px; transform-origin: 266.5px 63px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eIt's everybody's favorite algorithmic sequence. Dig deep and you'll find bunny rabbits, golden ratios, and sunflower seeds. What's not to like? As a result, it shows up everywhere people write code. Here are my favorite Fibonacci-related problems on Cody. By the way, that image is of Leonardo of Pisa. History knows him as Fibonacci, but his friends never called him that. Maybe we should call these things \"Leo sequences.\"\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","published_at":"2019-02-04T20:54:51.000Z"},"current_player":null},"problems":[{"id":12,"title":"Fibonacci sequence","description":"Calculate the nth Fibonacci number.\r\nGiven n, return f where f = fib(n) and f(1) = 1, f(2) = 1, f(3) = 2, ...\r\nExamples:\r\n Input  n = 5\r\n Output f is 5\r\n\r\n Input  n = 7\r\n Output f is 13","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 181px; display: block; min-width: 0px; padding-block-start: 0px; padding-inline-start: 2px; padding-left: 2px; padding-top: 0px; perspective-origin: 468.5px 90.5px; transform-origin: 468.5px 90.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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 444.5px 10.5px; text-align: left; transform-origin: 444.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 111.642px 8px; transform-origin: 111.642px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eCalculate the nth Fibonacci number.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 444.5px 10.5px; text-align: left; transform-origin: 444.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 199.117px 8px; transform-origin: 199.117px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven n, return f where f = fib(n) and f(1) = 1, f(2) = 1, f(3) = 2, ...\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 444.5px 10.5px; text-align: left; transform-origin: 444.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 32.675px 8px; transform-origin: 32.675px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExamples:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 90px; 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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 464.5px 45px; transform-origin: 464.5px 45px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 18px; 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; font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; line-height: 18px; 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; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 464.5px 9px; text-wrap-mode: nowrap; transform-origin: 464.5px 9px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(33, 33, 33); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(33, 33, 33); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(33, 33, 33); border-left-style: none; border-left-width: 0px; border-right-color: rgb(33, 33, 33); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 50.05px 8.5px; tab-size: 4; transform-origin: 50.05px 8.5px; unicode-bidi: normal; white-space-collapse: preserve; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 30.8px 8.5px; transform-origin: 30.8px 8.5px; \"\u003e Input  \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(133, 22, 209); border-block-start-color: rgb(133, 22, 209); border-bottom-color: rgb(133, 22, 209); border-inline-end-color: rgb(133, 22, 209); border-inline-start-color: rgb(133, 22, 209); border-left-color: rgb(133, 22, 209); border-right-color: rgb(133, 22, 209); border-top-color: rgb(133, 22, 209); caret-color: rgb(133, 22, 209); color: rgb(133, 22, 209); column-rule-color: rgb(133, 22, 209); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(133, 22, 209); perspective-origin: 19.25px 8.5px; text-decoration-color: rgb(133, 22, 209); text-emphasis-color: rgb(133, 22, 209); transform-origin: 19.25px 8.5px; \"\u003en = 5\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 18px; 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; font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; line-height: 18px; 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; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 464.5px 9px; text-wrap-mode: nowrap; transform-origin: 464.5px 9px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(33, 33, 33); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(33, 33, 33); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(33, 33, 33); border-left-style: none; border-left-width: 0px; border-right-color: rgb(33, 33, 33); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 53.9px 8.5px; tab-size: 4; transform-origin: 53.9px 8.5px; unicode-bidi: normal; white-space-collapse: preserve; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 30.8px 8.5px; transform-origin: 30.8px 8.5px; \"\u003e Output \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(133, 22, 209); border-block-start-color: rgb(133, 22, 209); border-bottom-color: rgb(133, 22, 209); border-inline-end-color: rgb(133, 22, 209); border-inline-start-color: rgb(133, 22, 209); border-left-color: rgb(133, 22, 209); border-right-color: rgb(133, 22, 209); border-top-color: rgb(133, 22, 209); caret-color: rgb(133, 22, 209); color: rgb(133, 22, 209); column-rule-color: rgb(133, 22, 209); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(133, 22, 209); perspective-origin: 23.1px 8.5px; text-decoration-color: rgb(133, 22, 209); text-emphasis-color: rgb(133, 22, 209); transform-origin: 23.1px 8.5px; \"\u003ef is 5\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 18px; 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; font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; line-height: 18px; 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; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 464.5px 9px; text-wrap-mode: nowrap; transform-origin: 464.5px 9px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(33, 33, 33); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(33, 33, 33); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(33, 33, 33); border-left-style: none; border-left-width: 0px; border-right-color: rgb(33, 33, 33); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; 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-collapse: preserve; \"\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: 18px; 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; font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; line-height: 18px; 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; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 464.5px 9px; text-wrap-mode: nowrap; transform-origin: 464.5px 9px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(33, 33, 33); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(33, 33, 33); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(33, 33, 33); border-left-style: none; border-left-width: 0px; border-right-color: rgb(33, 33, 33); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 50.05px 8.5px; tab-size: 4; transform-origin: 50.05px 8.5px; unicode-bidi: normal; white-space-collapse: preserve; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 30.8px 8.5px; transform-origin: 30.8px 8.5px; \"\u003e Input  \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(133, 22, 209); border-block-start-color: rgb(133, 22, 209); border-bottom-color: rgb(133, 22, 209); border-inline-end-color: rgb(133, 22, 209); border-inline-start-color: rgb(133, 22, 209); border-left-color: rgb(133, 22, 209); border-right-color: rgb(133, 22, 209); border-top-color: rgb(133, 22, 209); caret-color: rgb(133, 22, 209); color: rgb(133, 22, 209); column-rule-color: rgb(133, 22, 209); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(133, 22, 209); perspective-origin: 19.25px 8.5px; text-decoration-color: rgb(133, 22, 209); text-emphasis-color: rgb(133, 22, 209); transform-origin: 19.25px 8.5px; \"\u003en = 7\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 18px; 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; font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; line-height: 18px; 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; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 464.5px 9px; text-wrap-mode: nowrap; transform-origin: 464.5px 9px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(33, 33, 33); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(33, 33, 33); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(33, 33, 33); border-left-style: none; border-left-width: 0px; border-right-color: rgb(33, 33, 33); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 57.75px 8.5px; tab-size: 4; transform-origin: 57.75px 8.5px; unicode-bidi: normal; white-space-collapse: preserve; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 30.8px 8.5px; transform-origin: 30.8px 8.5px; \"\u003e Output \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(133, 22, 209); border-block-start-color: rgb(133, 22, 209); border-bottom-color: rgb(133, 22, 209); border-inline-end-color: rgb(133, 22, 209); border-inline-start-color: rgb(133, 22, 209); border-left-color: rgb(133, 22, 209); border-right-color: rgb(133, 22, 209); border-top-color: rgb(133, 22, 209); caret-color: rgb(133, 22, 209); color: rgb(133, 22, 209); column-rule-color: rgb(133, 22, 209); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(133, 22, 209); perspective-origin: 26.95px 8.5px; text-decoration-color: rgb(133, 22, 209); text-emphasis-color: rgb(133, 22, 209); transform-origin: 26.95px 8.5px; \"\u003ef is 13\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function f = fib(n)\r\n  f = n;\r\nend","test_suite":"%%\r\nfiletext = fileread('fib.m');\r\nillegal = contains(filetext, 'regexp') || contains(filetext, 'assert') || ...\r\n          contains(filetext, 'switch') || contains(filetext, 'elseif') || ...\r\n          contains(filetext, '610')     || contains(filetext, '1597');\r\nassert(~illegal)\r\n\r\n%%\r\nn = 1;\r\nf = 1;\r\nassert(isequal(fib(n),f))\r\n\r\n%%\r\nn = 6;\r\nf = 8;\r\nassert(isequal(fib(n),f))\r\n\r\n%%\r\nn = 7;\r\nf = 13;\r\nassert(isequal(fib(n),f))\r\n\r\n%%\r\nn = 10;\r\nf = 55;\r\nassert(isequal(fib(n),f))\r\n\r\n%%\r\nn = 12;\r\nf = 144;\r\nassert(isequal(fib(n),f))\r\n\r\n%%\r\nn = 15;\r\nf = 610;\r\nassert(isequal(fib(n),f))\r\n\r\n%%\r\nn = 17;\r\nf = 1597;\r\nassert(isequal(fib(n),f))\r\n\r\n%%\r\nn = 20;\r\nf = 6765;\r\nassert(isequal(fib(n),f))","published":true,"deleted":false,"likes_count":108,"comments_count":25,"created_by":1,"edited_by":223089,"edited_at":"2026-02-05T13:22:21.000Z","deleted_by":null,"deleted_at":null,"solvers_count":14133,"test_suite_updated_at":"2026-02-05T13:22:22.000Z","rescore_all_solutions":false,"group_id":2,"created_at":"2012-01-18T01:00:18.000Z","updated_at":"2026-04-03T07:15:44.000Z","published_at":"2012-01-18T01:00:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCalculate the nth Fibonacci number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven n, return f where f = fib(n) and f(1) = 1, f(2) = 1, f(3) = 2, ...\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ Input  n = 5\\n Output f is 5\\n\\n Input  n = 7\\n Output f is 13]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":1946,"title":"Fibonacci-Sum of Squares","description":"Given the Fibonacci sequence defined by the following recursive relation,\r\n\r\n* F(n) = F(n-1) + F(n-2)\r\n* where F(1) = 1 and F(1) = 1\r\n\r\ndetermine the sum of squares for the first \"n\" terms.\r\n\r\nFor example, n=5 --\u003e 1^2 + 1^2 + 2^2 + 3^2 + 5^2 = 40.\r\n\r\n* INPUT  n=5\r\n* OUTPUT S=40\r\n\r\n","description_html":"\u003cp\u003eGiven the Fibonacci sequence defined by the following recursive relation,\u003c/p\u003e\u003cul\u003e\u003cli\u003eF(n) = F(n-1) + F(n-2)\u003c/li\u003e\u003cli\u003ewhere F(1) = 1 and F(1) = 1\u003c/li\u003e\u003c/ul\u003e\u003cp\u003edetermine the sum of squares for the first \"n\" terms.\u003c/p\u003e\u003cp\u003eFor example, n=5 --\u0026gt; 1^2 + 1^2 + 2^2 + 3^2 + 5^2 = 40.\u003c/p\u003e\u003cul\u003e\u003cli\u003eINPUT  n=5\u003c/li\u003e\u003cli\u003eOUTPUT S=40\u003c/li\u003e\u003c/ul\u003e","function_template":"function S = FibSumSquares(n)\r\n  S = n;\r\nend","test_suite":"%%\r\nn = 5;\r\nS = 40;\r\nassert(isequal(FibSumSquares(n),S))\r\n\r\n%%\r\nn = 8;\r\nS = 714;\r\nassert(isequal(FibSumSquares(n),S))\r\n\r\n%%\r\nn = 11;\r\nS = 12816;\r\nassert(isequal(FibSumSquares(n),S))\r\n\r\n%%\r\nn = 15;\r\nS = 602070;\r\nassert(isequal(FibSumSquares(n),S))\r\n\r\n%%\r\nn = 21;\r\nS = 193864606;\r\nassert(isequal(FibSumSquares(n),S))\r\n\r\n%%\r\nn = 26;\r\nS = 23843770274;\r\nassert(isequal(FibSumSquares(n),S))","published":true,"deleted":false,"likes_count":10,"comments_count":4,"created_by":18441,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1715,"test_suite_updated_at":"2017-05-23T15:39:51.000Z","rescore_all_solutions":false,"group_id":122,"created_at":"2013-10-19T23:17:50.000Z","updated_at":"2026-03-31T16:29:48.000Z","published_at":"2013-10-19T23:37:18.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 the Fibonacci sequence defined by the following recursive relation,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eF(n) = F(n-1) + F(n-2)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ewhere F(1) = 1 and F(1) = 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003edetermine the sum of squares for the first \\\"n\\\" terms.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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, n=5 --\u0026gt; 1^2 + 1^2 + 2^2 + 3^2 + 5^2 = 40.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eINPUT n=5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOUTPUT S=40\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44311,"title":"Number of Even Elements in Fibonacci Sequence","description":"Find how many even Fibonacci numbers are available in the first d numbers.\r\n\r\nConsider the following first 14 numbers\r\n\r\n  1 1 2 3 5 8 13 21 34 55 89 144 233 377 ...\r\n\r\n4 of them are even. ","description_html":"\u003cp\u003eFind how many even Fibonacci numbers are available in the first d numbers.\u003c/p\u003e\u003cp\u003eConsider the following first 14 numbers\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e1 1 2 3 5 8 13 21 34 55 89 144 233 377 ...\r\n\u003c/pre\u003e\u003cp\u003e4 of them are even.\u003c/p\u003e","function_template":"function y = evenFibo(d)\r\n  y = x;\r\nend","test_suite":"%%\r\nd = 14;\r\ny_correct = 4;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 20;\r\ny_correct = 6;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 50;\r\ny_correct = 16;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 100;\r\ny_correct = 33;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 150;\r\ny_correct = 50;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 200;\r\ny_correct = 66;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 500;\r\ny_correct = 166;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 1000;\r\ny_correct = 333;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 1e4;\r\ny_correct = 3333;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 2e4;\r\ny_correct = 6666;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 3e5;\r\ny_correct = 1e5;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 6e6;\r\ny_correct = 2e6;\r\nassert(isequal(evenFibo(d),y_correct))\r\n% \r\n% %%\r\n% d = 9223372036854775807;\r\n% y_correct = 3074457345618258432;\r\n% assert(isequal(evenFibo(d),y_correct))\r\n","published":true,"deleted":false,"likes_count":21,"comments_count":9,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1640,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-11T12:36:15.000Z","updated_at":"2026-03-31T16:31:07.000Z","published_at":"2017-10-16T01:50:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind how many even Fibonacci numbers are available in the first d numbers.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eConsider the following first 14 numbers\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[1 1 2 3 5 8 13 21 34 55 89 144 233 377 ...]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4 of them are even.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":232,"title":"Project Euler: Problem 2, Sum of even Fibonacci","description":"Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:\r\n1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...\r\nBy considering the terms in the Fibonacci sequence whose values do not exceed the input value, find the sum of the even-valued terms.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 123px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 406.5px 61.5px; transform-origin: 406.5px 61.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 21px; text-align: left; transform-origin: 383.5px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 383.5px 7.81667px; transform-origin: 383.5px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eEach new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:\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: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 109.992px 7.81667px; transform-origin: 109.992px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...\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: 383.5px 21px; text-align: left; transform-origin: 383.5px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 376.317px 7.81667px; transform-origin: 376.317px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eBy considering the terms in the Fibonacci sequence whose values do not exceed the input value, find the sum of the even-valued terms.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = euler002(x)\r\n  y = rand;\r\nend","test_suite":"%%\r\nfiletext = fileread('euler002.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp') || ...\r\n    contains(filetext, '144');\r\nassert(~illegal)\r\n\r\n%%\r\nx =2;\r\nassert(isequal(euler002(x),2))\r\n\r\n%%\r\nx =4000000;\r\ny_correct = 4613732;\r\nassert(isequal(euler002(x),y_correct))\r\n\r\n%%\r\nx =97455000;\r\ny_correct = 82790070;\r\nassert(isequal(euler002(x),y_correct))\r\n\r\n%%\r\nx =597455000;\r\ny_correct = 350704366;\r\nassert(isequal(euler002(x),y_correct))\r\n\r\n%%\r\nx =666576;\r\ny_correct = 257114;\r\nassert(isequal(euler002(x),y_correct))","published":true,"deleted":false,"likes_count":31,"comments_count":8,"created_by":1,"edited_by":223089,"edited_at":"2024-07-04T14:55:54.000Z","deleted_by":null,"deleted_at":null,"solvers_count":2837,"test_suite_updated_at":"2024-07-04T14:55:54.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2012-02-02T15:26:01.000Z","updated_at":"2026-03-31T16:32:01.000Z","published_at":"2012-02-07T15:29:53.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\u003eEach new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...\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\u003eBy considering the terms in the Fibonacci sequence whose values do not exceed the input value, find the sum of the even-valued terms.\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":2024,"title":"Triangle sequence ","description":"A sequence of triangles is constructed in the following way:\r\n1) the first triangle is Pythagoras' 3-4-5 triangle\r\n2) the second triangle is a right-angle triangle whose second longest side is the hypotenuse of the first triangle, and whose shortest side is the same length as the second longest side of the first triangle\r\n3) the third triangle is a right-angle triangle whose second longest side is the hypotenuse of the second triangle, and whose shortest side is the same length as the second longest side of the second triangle etc.\r\nEach triangle in the sequence is constructed so that its second longest side is the hypotenuse of the previous triangle and its shortest side is the same length as the second longest side of the previous triangle.\r\nWhat is the area of a square whose side is the hypotenuse of the nth triangle in the sequence?","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: 234px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 117px; transform-origin: 407px 117px; 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: 185px 8px; transform-origin: 185px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA sequence of triangles is constructed in the following way:\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: 148.5px 8px; transform-origin: 148.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1) the first triangle is Pythagoras' 3-4-5 triangle\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 365.5px 8px; transform-origin: 365.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e2) the second triangle is a right-angle triangle whose second longest side is the hypotenuse of the first triangle, and whose shortest side is the same length as the second longest side of the first triangle\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: 368px 8px; transform-origin: 368px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e3) the third triangle is a right-angle triangle whose second longest side is the hypotenuse of the second triangle, and whose shortest side is the same length as the second longest side of the second triangle etc.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eEach triangle in the sequence is constructed so that its second longest side is the hypotenuse of the previous triangle and its shortest side is the same length as the second longest side of the previous triangle.\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: 299px 8px; transform-origin: 299px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWhat is the area of a square whose side is the hypotenuse of the nth triangle in the sequence?\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function area = triangle_sequence(n)\r\n  area = n;\r\nend","test_suite":"%%\r\nfiletext = fileread('triangle_sequence.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp') || ...\r\n          contains(filetext, 'str2num'); \r\nassert(~illegal)\r\n%%\r\nn = 1;\r\narea_correct = 25;\r\ntolerance = 1e-6;\r\nassert(abs(triangle_sequence(n)-area_correct)\u003ctolerance)\r\n%%\r\nn = 2;\r\narea_correct = 41;\r\ntolerance = 1e-6;\r\nassert(abs(triangle_sequence(n)-area_correct)\u003ctolerance)\r\n%%\r\nn = 3;\r\narea_correct = 66;\r\ntolerance = 1e-6;\r\nassert(abs(triangle_sequence(n)-area_correct)\u003ctolerance)\r\n%%\r\nn = 9;\r\narea_correct = 1186;\r\ntolerance = 1e-6;\r\nassert(abs(triangle_sequence(n)-area_correct)\u003ctolerance)\r\n%%\r\nn = 13;\r\narea_correct = 8129;\r\ntolerance = 1e-6;\r\nassert(abs(triangle_sequence(n)-area_correct)\u003ctolerance)\r\n%%\r\nn = 22;\r\narea_correct = 617911;\r\ntolerance = 1e-6;\r\nassert(abs(triangle_sequence(n)-area_correct)\u003ctolerance)\r\n%%\r\nn = 50;\r\narea_correct = 439116598409;\r\ntolerance = 1e-3;\r\nassert(abs(triangle_sequence(n)-area_correct)\u003ctolerance)","published":true,"deleted":false,"likes_count":156,"comments_count":39,"created_by":974,"edited_by":223089,"edited_at":"2023-03-16T15:12:00.000Z","deleted_by":null,"deleted_at":null,"solvers_count":5829,"test_suite_updated_at":"2023-03-16T15:12:00.000Z","rescore_all_solutions":false,"group_id":7,"created_at":"2013-11-27T20:39:45.000Z","updated_at":"2026-03-31T16:33:25.000Z","published_at":"2013-11-28T17:12:38.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\u003eA sequence of triangles is constructed in the following way:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1) the first triangle is Pythagoras' 3-4-5 triangle\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2) the second triangle is a right-angle triangle whose second longest side is the hypotenuse of the first triangle, and whose shortest side is the same length as the second longest side of the first triangle\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e3) the third triangle is a right-angle triangle whose second longest side is the hypotenuse of the second triangle, and whose shortest side is the same length as the second longest side of the second triangle etc.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEach triangle in the sequence is constructed so that its second longest side is the hypotenuse of the previous triangle and its shortest side is the same length as the second longest side of the previous triangle.\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\u003eWhat is the area of a square whose side is the hypotenuse of the nth triangle in the sequence?\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":44481,"title":"How many Fibonacci numbers? ","description":"Find the number of unique Fibonacci numbers (don't count repeats) in a vector of positive integers.\r\n\r\nExample:\r\n\r\n x = [1 2 3 4 5 6 7 8 8]\r\n y = 5","description_html":"\u003cp\u003eFind the number of unique Fibonacci numbers (don't count repeats) in a vector of positive integers.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e x = [1 2 3 4 5 6 7 8 8]\r\n y = 5\u003c/pre\u003e","function_template":"function y = fib_count(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 4 5 7 10 11 13 20 21 23 29];\r\ny_correct = 4;\r\nassert(isequal(fib_count(x),y_correct))\r\n\r\n%%\r\nx = 5:5:100;\r\ny_correct = 2;\r\nassert(isequal(fib_count(x),y_correct))\r\n\r\n%%\r\n%x = [2 2 3 3 3 3 3 3 5 5 6 6 6 7 86168291600238450732788312165664788095941068326060883324529903470149056115823592713458328176574447204501];\r\n% Changed the test suite to a number that can be represented as an integer in DOUBLE\r\nx = [2 2 3 3 3 3 3 3 5 5 6 6 6 7 8944394323791465];\r\ny_correct = 3;\r\nassert(isequal(fib_count(x),y_correct))\r\n\r\n%%\r\nx = [2 2 3 3 3 3 3 3 5 5 6 6 6 7 8944394323791464];\r\ny_correct = 4;\r\nassert(isequal(fib_count(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":9,"created_by":172785,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":984,"test_suite_updated_at":"2019-02-08T20:17:38.000Z","rescore_all_solutions":true,"group_id":122,"created_at":"2018-01-06T17:29:02.000Z","updated_at":"2026-03-31T16:35:24.000Z","published_at":"2018-01-06T17:29:06.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the number of unique Fibonacci numbers (don't count repeats) in a vector of 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:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x = [1 2 3 4 5 6 7 8 8]\\n y = 5]]\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":42340,"title":"Fibonacci Decomposition","description":"Every positive integer has a unique decomposition into nonconsecutive Fibonacci numbers f1+f2+ ... Given a positive integer n, return these numbers. \r\n\r\nReturn the vector f = [f1, f2, ...] sorted from smallest to largest. sum(f) = n.\r\n\r\nExamples\r\n\r\n n = 3\r\n f = 3\r\n\r\n n = 32\r\n f = [3 8 21]\r\n\r\nReference: \u003chttp://www.johndcook.com/blog/2015/05/17/fibonacci-number-system/\u003e","description_html":"\u003cp\u003eEvery positive integer has a unique decomposition into nonconsecutive Fibonacci numbers f1+f2+ ... Given a positive integer n, return these numbers.\u003c/p\u003e\u003cp\u003eReturn the vector f = [f1, f2, ...] sorted from smallest to largest. sum(f) = n.\u003c/p\u003e\u003cp\u003eExamples\u003c/p\u003e\u003cpre\u003e n = 3\r\n f = 3\u003c/pre\u003e\u003cpre\u003e n = 32\r\n f = [3 8 21]\u003c/pre\u003e\u003cp\u003eReference: \u003ca href = \"http://www.johndcook.com/blog/2015/05/17/fibonacci-number-system/\"\u003ehttp://www.johndcook.com/blog/2015/05/17/fibonacci-number-system/\u003c/a\u003e\u003c/p\u003e","function_template":"function f = fib_decomposition(n)\r\n  f = 1;\r\nend","test_suite":"%%\r\nn = 1;\r\nf_correct = 1;\r\nassert(isequal(fib_decomposition(n),f_correct))\r\n\r\n%%\r\nn = 4;\r\nf_correct = [1 3];\r\nassert(isequal(fib_decomposition(n),f_correct))\r\n\r\n%%\r\nn = 6;\r\nf_correct = [1 5];\r\nassert(isequal(fib_decomposition(n),f_correct))\r\n\r\n%%\r\nn = 2010;\r\nf_correct = [2 34 377 1597];\r\nassert(isequal(fib_decomposition(n),f_correct))\r\n\r\n%%\r\nn = 35601;\r\nf_correct = [1 34 144 6765 28657];\r\nassert(isequal(fib_decomposition(n),f_correct))\r\n\r\n%%\r\nn = 9227467;\r\nf_correct = [2 9227465];\r\nassert(isequal(fib_decomposition(n),f_correct))\r\n\r\n%%\r\nn = 2015;\r\nf_correct = [2 5 34 377 1597];\r\nassert(isequal(fib_decomposition(n),f_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":16,"comments_count":2,"created_by":7,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":925,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-05-28T16:03:19.000Z","updated_at":"2026-03-31T16:36:14.000Z","published_at":"2015-05-28T16:04:31.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEvery positive integer has a unique decomposition into nonconsecutive Fibonacci numbers f1+f2+ ... Given a positive integer n, return these numbers.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the vector f = [f1, f2, ...] sorted from smallest to largest. sum(f) = n.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ n = 3\\n f = 3\\n\\n n = 32\\n f = [3 8 21]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReference:\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.johndcook.com/blog/2015/05/17/fibonacci-number-system/\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://www.johndcook.com/blog/2015/05/17/fibonacci-number-system/\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":752,"title":"Is X a Fibonacci Matrix?","description":"In honor of Cleve's new blog and post:\r\n\r\n\u003chttp://blogs.mathworks.com/cleve/2012/06/03/fibonacci-matrices/\u003e\r\n\r\nIs X a Fibonacci matrix?\r\n\r\nWrite a function to determine whether or not the input matrix is a Fibonacci matrix.","description_html":"\u003cp\u003eIn honor of Cleve's new blog and post:\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://blogs.mathworks.com/cleve/2012/06/03/fibonacci-matrices/\"\u003ehttp://blogs.mathworks.com/cleve/2012/06/03/fibonacci-matrices/\u003c/a\u003e\u003c/p\u003e\u003cp\u003eIs X a Fibonacci matrix?\u003c/p\u003e\u003cp\u003eWrite a function to determine whether or not the input matrix is a Fibonacci matrix.\u003c/p\u003e","function_template":"function tf = isFibMat(x)\r\n  tf = rand \u003e 0.5;\r\nend","test_suite":"%%\r\nx = [0 1;1 1];\r\ntf = true;\r\nassert(isequal(isFibMat(x),tf))\r\nclear all;\r\n\r\n%%\r\nx = [1 0;1 1];\r\ntf = false;\r\nassert(isequal(isFibMat(x),tf))\r\nclear all;\r\n\r\n%%\r\nx = [0 1;1 1]^40;\r\ntf = true;\r\nassert(isequal(isFibMat(x),tf))\r\nclear all;\r\n\r\n%%\r\nx = [0 1;1 1]^40+1;\r\ntf = false;\r\nassert(isequal(isFibMat(x),tf))\r\nclear all;\r\n\r\n%%\r\nx = [0 1;1 1]^17;\r\ntf = true;\r\nassert(isequal(isFibMat(x),tf))\r\nclear all;\r\n\r\n%%\r\nx = [0 1;1 1]^17-5;\r\ntf = false;\r\nassert(isequal(isFibMat(x),tf))\r\nclear all;\r\n\r\n%%\r\nx = [0 0 1;0 1 1;1 1 1]^3;\r\ntf = false;\r\nassert(isequal(isFibMat(x),tf))\r\nclear all;\r\n\r\n%%\r\nx = [0 0 1;0 1 1];\r\ntf = false;\r\nassert(isequal(isFibMat(x),tf))\r\nclear all;\r\n\r\n%%\r\nx = [[0 1;1 1]^3 [5; 8]];\r\ntf = false;\r\nassert(isequal(isFibMat(x),tf))\r\nclear all;\r\n\r\n%%\r\nx = uint8([0 1; 1 1]^5);\r\ntf = true;\r\nassert(isequal(isFibMat(x),tf))\r\nclear all;\r\n\r\n%%\r\nx = -([0 1; 1 1]^5);\r\ntf = false;\r\nassert(isequal(isFibMat(x),tf))\r\nclear all;\r\n\r\n%%\r\nx = [0 1; 1 1]^5;\r\nx(2) = nan;\r\ntf = false;\r\nassert(isequal(isFibMat(x),tf))\r\nclear all;\r\n\r\n%%\r\nx = [4 7;7 11];\r\ntf = false;\r\nassert(isequal(isFibMat(x),tf))\r\nclear all;\r\n\r\n%%\r\nfor ii = 1:55\r\n    assert(true==isFibMat([0 1;1 1]^ii))\r\nend","published":true,"deleted":false,"likes_count":14,"comments_count":7,"created_by":255,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":771,"test_suite_updated_at":"2012-06-12T18:22:27.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2012-06-06T21:24:01.000Z","updated_at":"2026-03-31T16:38:37.000Z","published_at":"2012-06-06T21:24:41.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn honor of Cleve's new blog and post:\u003c/w:t\u003e\u003c/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://blogs.mathworks.com/cleve/2012/06/03/fibonacci-matrices/\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://blogs.mathworks.com/cleve/2012/06/03/fibonacci-matrices/\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIs X a Fibonacci matrix?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine whether or not the input matrix is a Fibonacci matrix.\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":8057,"title":"(Linear) Recurrence Equations - Generalised Fibonacci-like sequences","description":"This problem is inspired by problems \u003chttp://uk.mathworks.com/matlabcentral/cody/problems/2187-generalized-fibonacci 2187\u003e, \u003chttp://uk.mathworks.com/matlabcentral/cody/problems/3092-return-fibonacci-sequence-do-not-use-loop-and-condition 3092\u003e and \u003chttp://uk.mathworks.com/matlabcentral/cody/?term=tag%3A%22fibonacci%22 other problems\u003e based on Fibonacci sequence.\r\n\r\nI haven't seen here many problems based on other recursive sequences such as \u003chttp://oeis.org/A000032 Lucas numbers\u003e, \u003chttp://oeis.org/A000129 Pell numbers\u003e, \u003chttp://oeis.org/A000931 Padovan sequence\u003e or \u003chttp://oeis.org/A000073 Tribonacci numbers\u003e so this is a problem about them all.\r\n\r\nYour function input will be _N_, _Init_ and _Rules_. _Init_ and _Rules_ represent initial values of sequence and a kernel which denotes recurrence relation:\r\n\r\n    Init  : [ A1 A2 ... Ak]\r\n    Rules : [ Ck ... C2 C1]\r\n  \r\n    function: f(n) = (Ck) * f(n-k) + ... + (C2) * f(n-2) + (C1) * f(n-1)\r\n              and f(1) = A1, f(2) = A2, ..., f(k) = Ak,\r\n\r\n_Init_ and _Rules_ have the same length, _N_ may be a single number or a vector. Your function should return values of _f(N)_. Example:\r\n\r\n   % Fibonacci sequence:      f(1)=f(2)=1, f(n)=f(n-2)+f(n-1)\r\n    \u003e\u003e Init = [1 1];\r\n    \u003e\u003e Rules = [1 1];\r\n    \u003e\u003e N = 1:10;\r\n    \u003e\u003e fibonacci = recurrence_seq(N,Init,Rules),\r\n    fibonacci = \r\n        1   1   2   3   5   8  13  21  34  55\r\n   \r\n    \r\n     \r\n\r\nOther info:\r\n\r\n* Different approaches may lead to solutions which won't be able to compute _f(n)_ for _n_ being equal 0 or negative integer. If your solution doesn't return correct answer for those numbers it will still pass if it returns NaNs for _n\u003c1_.\r\n* Please, try to avoid unnecessary things like strings, _ans_, etc. ","description_html":"\u003cp\u003eThis problem is inspired by problems \u003ca href = \"http://uk.mathworks.com/matlabcentral/cody/problems/2187-generalized-fibonacci\"\u003e2187\u003c/a\u003e, \u003ca href = \"http://uk.mathworks.com/matlabcentral/cody/problems/3092-return-fibonacci-sequence-do-not-use-loop-and-condition\"\u003e3092\u003c/a\u003e and \u003ca href = \"http://uk.mathworks.com/matlabcentral/cody/?term=tag%3A%22fibonacci%22\"\u003eother problems\u003c/a\u003e based on Fibonacci sequence.\u003c/p\u003e\u003cp\u003eI haven't seen here many problems based on other recursive sequences such as \u003ca href = \"http://oeis.org/A000032\"\u003eLucas numbers\u003c/a\u003e, \u003ca href = \"http://oeis.org/A000129\"\u003ePell numbers\u003c/a\u003e, \u003ca href = \"http://oeis.org/A000931\"\u003ePadovan sequence\u003c/a\u003e or \u003ca href = \"http://oeis.org/A000073\"\u003eTribonacci numbers\u003c/a\u003e so this is a problem about them all.\u003c/p\u003e\u003cp\u003eYour function input will be \u003ci\u003eN\u003c/i\u003e, \u003ci\u003eInit\u003c/i\u003e and \u003ci\u003eRules\u003c/i\u003e. \u003ci\u003eInit\u003c/i\u003e and \u003ci\u003eRules\u003c/i\u003e represent initial values of sequence and a kernel which denotes recurrence relation:\u003c/p\u003e\u003cpre\u003e    Init  : [ A1 A2 ... Ak]\r\n    Rules : [ Ck ... C2 C1]\u003c/pre\u003e\u003cpre\u003e    function: f(n) = (Ck) * f(n-k) + ... + (C2) * f(n-2) + (C1) * f(n-1)\r\n              and f(1) = A1, f(2) = A2, ..., f(k) = Ak,\u003c/pre\u003e\u003cp\u003e\u003ci\u003eInit\u003c/i\u003e and \u003ci\u003eRules\u003c/i\u003e have the same length, \u003ci\u003eN\u003c/i\u003e may be a single number or a vector. Your function should return values of \u003ci\u003ef(N)\u003c/i\u003e. Example:\u003c/p\u003e\u003cpre\u003e   % Fibonacci sequence:      f(1)=f(2)=1, f(n)=f(n-2)+f(n-1)\r\n    \u0026gt;\u0026gt; Init = [1 1];\r\n    \u0026gt;\u0026gt; Rules = [1 1];\r\n    \u0026gt;\u0026gt; N = 1:10;\r\n    \u0026gt;\u0026gt; fibonacci = recurrence_seq(N,Init,Rules),\r\n    fibonacci = \r\n        1   1   2   3   5   8  13  21  34  55\u003c/pre\u003e\u003cp\u003eOther info:\u003c/p\u003e\u003cul\u003e\u003cli\u003eDifferent approaches may lead to solutions which won't be able to compute \u003ci\u003ef(n)\u003c/i\u003e for \u003ci\u003en\u003c/i\u003e being equal 0 or negative integer. If your solution doesn't return correct answer for those numbers it will still pass if it returns NaNs for \u003ci\u003en\u0026lt;1\u003c/i\u003e.\u003c/li\u003e\u003cli\u003ePlease, try to avoid unnecessary things like strings, \u003ci\u003eans\u003c/i\u003e, etc.\u003c/li\u003e\u003c/ul\u003e","function_template":"function values = recurrence_seq(N, Init, Rules)\r\n  values = N;\r\n  values(N\u003c1) = NaN;\r\n\r\n\r\n\r\nend","test_suite":"%% Fibonacci\r\nInit = [1,1];\r\nRules = [1,1];\r\nN = 1:10;\r\nvalues_correct = [1 1 2 3 5 8 13 21 34 55];\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%% Fibonacci - shifted\r\nInit = [2,3];\r\nRules = [1,1];\r\nN = 1:10;\r\nvalues_correct = [2, 3, 5, 8, 13, 21, 34, 55, 89, 144];\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%% Fibonacci - negative n\r\nInit = [1,1];\r\nRules = [1,1];\r\nN = -5:5;\r\nvalues_correct = [5, -3, 2, -1, 1, 0, 1, 1, 2, 3, 5];\r\nvalues_accepted = [nan, nan, nan, nan, nan, nan, 1, 1, 2, 3, 5];\r\nvalues = recurrence_seq(N, Init, Rules);\r\nassert(isequal(values,values_correct)||isequaln(values,values_accepted))\r\n%% Lucas numbers\r\nInit = [1,3];\r\nRules = [1,1];\r\nN = 1:10;\r\nvalues_correct = [1, 3, 4, 7, 11, 18, 29, 47, 76, 123];\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%% Padovan sequence\r\nInit = [1, 1, 1];\r\nRules = [1, 1, 0];\r\nN = 4:21;\r\nvalues_correct = [2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37, 49, 65, 86, 114, 151, 200];\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%% Pell numbers\r\nInit = [0, 1];\r\nRules = [1, 2];\r\nN = 4:3:19;\r\nvalues_correct = [5, 70, 985, 13860, 195025, 2744210];\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%% 3^n-2^n sequence\r\nInit = [3-2, 9-4];\r\nRules = [-6 5];\r\nN = 1:10;\r\nvalues_correct = [1, 5, 19, 65, 211, 665, 2059, 6305, 19171, 58025];\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%% Perrin sequence\r\nInit = [3, 0, 2];\r\nRules = [1, 1, 0];\r\nN = [28:38, 10:-1:1];\r\nvalues_correct = [1983, 2627, 3480, 4610, 6107, 8090, 10717, 14197, 18807, 24914, 33004, 12, 10, 7, 5, 5, 2, 3, 2, 0, 3];\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%% \r\nInit = [3, 0, 2]; % Perrin init\r\nRules = [1, 1, 1]; % Tribonacci rules\r\nN = [1:15];\r\nvalues_correct = [3, 0, 2, 5, 7, 14, 26, 47, 87, 160, 294, 541, 995, 1830, 3366];\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%% Tribonacci\r\nInit = [0, 0, 1];\r\nRules = [1, 1, 1];\r\nN = [1:23];\r\nvalues_correct = [0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927, 1705, 3136, 5768, 10609, 19513, 35890, 66012, 121415];\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%% Tetranacci\r\nInit = [0, 0, 0, 1];\r\nRules = [1, 1, 1, 1];\r\nN = [20:23];\r\nvalues_correct = [20569, 39648, 76424, 147312];\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%% Heptanacci\r\nInit = [0, 0, 0, 0, 0, 0, 1];\r\nRules = [1, 1, 1, 1, 1, 1, 1];\r\nN = [7:15, 19];\r\nvalues_correct = [1, 1, 2, 4, 8, 16, 32, 64, 127, 2000];\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%%\r\nInit = [1, -1];\r\nRules = [1, -1];\r\nN = 1:10;\r\nvalues_correct = [1, -1, 2, -3, 5, -8, 13, -21, 34, -55];\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%%\r\nInit = [1, -1];\r\nRules = [-1, 1];\r\nN = 1:10;\r\nvalues_correct = [1, -1, -2, -1, 1, 2, 1, -1, -2, -1];\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%%\r\nInit = [1, -1];\r\nRules = [1, 1];\r\nN = 1:10;\r\nvalues_correct = [1, -1, 0, -1, -1, -2, -3, -5, -8, -13];\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%%\r\nInit = [1, 1];\r\nRules = [2, -1];\r\nN = 1:10;\r\nvalues_correct = ones(1,10);\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%%\r\nInit = [1, 2];\r\nRules = [2, -1];\r\nN = 1:10;\r\nvalues_correct = [1, 2, 0, 4, -4, 12, -20, 44, -84, 172];\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%% Jacobsthal numbers\r\nInit = [0, 1];\r\nRules = [2, 1];\r\nN = 1:10;\r\nvalues_correct = [0, 1, 1, 3, 5, 11, 21, 43, 85, 171];\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%% A028242\r\nInit = [1, 0, 2];\r\nRules = [-1 1 1];\r\nN = 1:20;\r\nvalues_correct = [1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9];\r\nassert(isequal(recurrence_seq(N, Init, Rules),values_correct))\r\n%%\r\n\r\n","published":true,"deleted":false,"likes_count":18,"comments_count":3,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":414,"test_suite_updated_at":"2015-04-02T15:23:44.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-04-02T14:52:53.000Z","updated_at":"2026-03-26T04:58:55.000Z","published_at":"2015-04-02T14:54: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\u003eThis problem is inspired by 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://uk.mathworks.com/matlabcentral/cody/problems/2187-generalized-fibonacci\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2187\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://uk.mathworks.com/matlabcentral/cody/problems/3092-return-fibonacci-sequence-do-not-use-loop-and-condition\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e3092\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://uk.mathworks.com/matlabcentral/cody/?term=tag%3A%22fibonacci%22\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eother problems\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e based on Fibonacci 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\u003eI haven't seen here many problems based on other recursive sequences such as\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://oeis.org/A000032\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eLucas numbers\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://oeis.org/A000129\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePell numbers\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://oeis.org/A000931\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePadovan sequence\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://oeis.org/A000073\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eTribonacci numbers\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e so this is a problem about them all.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour function input will be\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\u003eN\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: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\u003eInit\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\u003eRules\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: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\u003eInit\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\u003eRules\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e represent initial values of sequence and a kernel which denotes recurrence relation:\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[    Init  : [ A1 A2 ... Ak]\\n    Rules : [ Ck ... C2 C1]\\n\\n    function: f(n) = (Ck) * f(n-k) + ... + (C2) * f(n-2) + (C1) * f(n-1)\\n              and f(1) = A1, f(2) = A2, ..., f(k) = Ak,]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInit\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\u003eRules\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e have the same length,\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\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e may be a single number or a vector. Your function should return values of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ef(N)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. 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[   % Fibonacci sequence:      f(1)=f(2)=1, f(n)=f(n-2)+f(n-1)\\n    \u003e\u003e Init = [1 1];\\n    \u003e\u003e Rules = [1 1];\\n    \u003e\u003e N = 1:10;\\n    \u003e\u003e fibonacci = recurrence_seq(N,Init,Rules),\\n    fibonacci = \\n        1   1   2   3   5   8  13  21  34  55]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOther info:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDifferent approaches may lead to solutions which won't be able to compute\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\u003ef(n)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for\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\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e being equal 0 or negative integer. If your solution doesn't return correct answer for those numbers it will still pass if it returns NaNs for\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\u003en\u0026lt;1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePlease, try to avoid unnecessary things like strings,\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\u003eans\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, etc.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"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}}