{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":1323,"title":"Alternating sum","description":"Given vector x, calculate the alternating sum\r\n\r\n   y = x(1) - x(2) + x(3) - x(4) + ...","description_html":"\u003cp\u003eGiven vector x, calculate the alternating sum\u003c/p\u003e\u003cpre\u003e   y = x(1) - x(2) + x(3) - x(4) + ...\u003c/pre\u003e","function_template":"function y=altsum(x)\r\ny=0;\r\n","test_suite":"%%\r\nx=508;\r\nassert(isequal(altsum(x),508))\r\n%%\r\nx=[1692 591];\r\nassert(isequal(altsum(x),1101))\r\n%%\r\nx=[-644 380 1009];\r\nassert(isequal(altsum(x),-15))\r\n%%\r\nx=[-20 -48 0 -318];\r\nassert(isequal(altsum(x),346))\r\n%%\r\nx=[1095 -1874 428 896 731 578 40];\r\nassert(isequal(altsum(x),2694))","published":true,"deleted":false,"likes_count":8,"comments_count":0,"created_by":245,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":841,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":27,"created_at":"2013-03-07T20:03:18.000Z","updated_at":"2026-04-01T15:59:34.000Z","published_at":"2013-03-07T20:11:39.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 vector x, calculate the alternating sum\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   y = x(1) - x(2) + x(3) - x(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":566,"title":"Sum of first n terms of a harmonic progression","description":"Given inputs a, d and n, return the sum of the first n terms of the harmonic progression a, a/(1+d), a/(1+2d), a/(1+3d),....","description_html":"\u003cdiv style = \"text-align: start; line-height: 20px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: normal; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"display: block; min-width: 0px; padding-top: 0px; transform-origin: 332px 21px; vertical-align: baseline; perspective-origin: 332px 21px; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; transform-origin: 309px 21px; white-space: pre-wrap; perspective-origin: 309px 21px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eGiven inputs a, d and n, return the sum of the first n terms of the harmonic progression a, a/(1+d), a/(1+2d), a/(1+3d),....\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function s = harmonicSum(a,d,n)\r\n  s=0;\r\nend","test_suite":"%%\r\na=1;d=1;n=1;\r\ny_correct = 1;\r\nassert(isequal(harmonicSum(a,d,n),y_correct));\r\n\r\n%%\r\na=2;d=2;n=5;\r\ny_correct = round(3.5746,4);\r\nassert(isequal(round(harmonicSum(a,d,n),4),y_correct));\r\n\r\n%%\r\na=4;d=5;n=2;\r\ny_correct = round(4.6667,4);\r\nassert(isequal(round(harmonicSum(a,d,n),4),y_correct));","published":true,"deleted":false,"likes_count":3,"comments_count":14,"created_by":2974,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":501,"test_suite_updated_at":"2020-09-29T02:43:20.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2012-04-08T16:38:19.000Z","updated_at":"2026-04-01T16:06:03.000Z","published_at":"2012-04-08T18:58: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\u003eGiven inputs a, d and n, return the sum of the first n terms of the harmonic progression a, a/(1+d), a/(1+2d), a/(1+3d),....\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":189,"title":"Sum all integers from 1 to 2^n","description":"Given the number x, y must be the summation of all integers from 1 to 2^x. For instance if x=2 then y must be 1+2+3+4=10.","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: 42px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 21px; transform-origin: 407px 21px; vertical-align: baseline; \"\u003e\u003cdiv style=\"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: 342.5px 8px; transform-origin: 342.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven the number x, y must be the summation of all integers from 1 to 2^x. For instance if x=2 then y must be 1+2+3+4=10.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = sum_int(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nfiletext = fileread('sum_int.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp');\r\nassert(~illegal)\r\n%%\r\nx = 1;\r\ny_correct = 3;\r\nassert(isequal(sum_int(x),y_correct))\r\n\r\n%%\r\nx = 3;\r\ny_correct = 36;\r\nassert(isequal(sum_int(x),y_correct))\r\n\r\n%%\r\nx = 7;\r\ny_correct = 8256;\r\nassert(isequal(sum_int(x),y_correct))\r\n\r\n%%\r\nx = 10;\r\ny_correct = 524800;\r\nassert(isequal(sum_int(x),y_correct))\r\n\r\n%%\r\nx = 11;\r\ny_correct = 2098176;\r\nassert(isequal(sum_int(x),y_correct))\r\n\r\n%%\r\nx = 14;\r\ny_correct = 134225920;\r\nassert(isequal(sum_int(x),y_correct))\r\n\r\n%%\r\nx = 17;\r\ny_correct = 8590000128;\r\nassert(isequal(sum_int(x),y_correct))","published":true,"deleted":false,"likes_count":94,"comments_count":24,"created_by":431,"edited_by":223089,"edited_at":"2022-11-24T08:12:49.000Z","deleted_by":null,"deleted_at":null,"solvers_count":17502,"test_suite_updated_at":"2022-11-24T08:12:49.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2012-01-31T00:43:21.000Z","updated_at":"2026-04-03T02:25:23.000Z","published_at":"2012-01-31T00:45:23.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven the number x, y must be the summation of all integers from 1 to 2^x. For instance if x=2 then y must be 1+2+3+4=10.\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":240,"title":"Project Euler: Problem 6, Natural numbers, squares and sums.","description":"The sum of the squares of the first ten natural numbers is,\r\n\r\n1^2 + 2^2 + ... + 10^2 = 385\r\nThe square of the sum of the first ten natural numbers is,\r\n\r\n(1 + 2 + ... + 10)^2 = 55^2 = 3025\r\nHence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 - 385 = 2640.\r\n\r\nFind the difference between the sum of the squares of the first N (where N is the input) natural numbers and the square of the sum.\r\n\r\nThank you to \u003chttp://projecteuler.net/problem=6 Project Euler Problem 6\u003e","description_html":"\u003cp\u003eThe sum of the squares of the first ten natural numbers is,\u003c/p\u003e\u003cp\u003e1^2 + 2^2 + ... + 10^2 = 385\r\nThe square of the sum of the first ten natural numbers is,\u003c/p\u003e\u003cp\u003e(1 + 2 + ... + 10)^2 = 55^2 = 3025\r\nHence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 - 385 = 2640.\u003c/p\u003e\u003cp\u003eFind the difference between the sum of the squares of the first N (where N is the input) natural numbers and the square of the sum.\u003c/p\u003e\u003cp\u003eThank you to \u003ca href=\"http://projecteuler.net/problem=6\"\u003eProject Euler Problem 6\u003c/a\u003e\u003c/p\u003e","function_template":"function y = euler006(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 10;\r\ny_correct = 2640;\r\nassert(isequal(euler006(x),y_correct))\r\n\r\n%%\r\nx = 20;\r\ny_correct = 41230;\r\nassert(isequal(euler006(x),y_correct))\r\n\r\n%%\r\nx = 200;\r\ny_correct = 401323300;\r\nassert(isequal(euler006(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":12,"comments_count":3,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":2540,"test_suite_updated_at":"2012-02-02T20:31:39.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2012-02-02T20:31:39.000Z","updated_at":"2026-03-26T08:44:39.000Z","published_at":"2012-02-02T20:32:49.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\u003eThe sum of the squares of the first ten natural numbers is,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1^2 + 2^2 + ... + 10^2 = 385 The square of the sum of the first ten natural numbers is,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(1 + 2 + ... + 10)^2 = 55^2 = 3025 Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 - 385 = 2640.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 difference between the sum of the squares of the first N (where N is the input) natural numbers and the square of the sum.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThank you to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://projecteuler.net/problem=6\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProject Euler Problem 6\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":1084,"title":"Square Digits Number Chain Terminal Value (Inspired by Project Euler Problem 92)","description":"Given a number _n_, return the terminal value of the number chain formed by summing the square of the digits. According to the Project Euler problem, this number chain always terminates with either 1 or 89.\r\n\r\nProject Euler Problem 92: \u003chttp://projecteuler.net/problem=92 Link\u003e","description_html":"\u003cp\u003eGiven a number \u003ci\u003en\u003c/i\u003e, return the terminal value of the number chain formed by summing the square of the digits. According to the Project Euler problem, this number chain always terminates with either 1 or 89.\u003c/p\u003e\u003cp\u003eProject Euler Problem 92: \u003ca href=\"http://projecteuler.net/problem=92\"\u003eLink\u003c/a\u003e\u003c/p\u003e","function_template":"function y = digits_squared_chain(x)\r\n  y = 1;\r\nend","test_suite":"%%\r\nassert(digits_squared_chain(649) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(79) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(608) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(487) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(739) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(565) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(68) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(383) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(379) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(203) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(632) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(391) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(863) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(13) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(100) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(236) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(293) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(230) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(31) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(806) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(623) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(7) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(13) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(836) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(954) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(567) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(388) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(789) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(246) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(787) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(311) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(856) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(143) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(873) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(215) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(995) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(455) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(948) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(875) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(788) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(722) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(250) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(227) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(640) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(835) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(965) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(726) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(689) == 89)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":134,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":256,"test_suite_updated_at":"2012-12-05T06:42:14.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2012-12-03T06:49:33.000Z","updated_at":"2026-03-26T09:05:10.000Z","published_at":"2012-12-05T06:42:14.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 number\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, return the terminal value of the number chain formed by summing the square of the digits. According to the Project Euler problem, this number chain always terminates with either 1 or 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eProject Euler Problem 92:\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://projecteuler.net/problem=92\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eLink\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":434,"title":"Return the Fibonacci Sequence","description":"Write a code which returns the Fibonacci Sequence such that the largest value in the sequence is less than the input integer N.  For example, \r\n\r\n\r\n  \u003e\u003e fib_seq(34)\r\n\r\n  ans =\r\n\r\n       1  1  2  3  5  8  13  21\r\n\r\n  \u003e\u003e fib_seq(35)\r\n\r\n  ans =\r\n\r\n       1  1  2  3  5  8  13  21  34","description_html":"\u003cp\u003eWrite a code which returns the Fibonacci Sequence such that the largest value in the sequence is less than the input integer N.  For example,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e\u003e\u003e fib_seq(34)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eans =\r\n\u003c/pre\u003e\u003cpre\u003e       1  1  2  3  5  8  13  21\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003e\u003e\u003e fib_seq(35)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eans =\r\n\u003c/pre\u003e\u003cpre\u003e       1  1  2  3  5  8  13  21  34\u003c/pre\u003e","function_template":"function y = fib_seq(N)\r\n  y = x;\r\nend","test_suite":"%%\r\nX = fib_seq(34);\r\nassert(isequal(X(end),21) \u0026\u0026 length(X)==8)\r\n%%\r\nX = fib_seq(35);\r\nassert(isequal(X(end),34) \u0026\u0026 length(X)==9)\r\n%%\r\nX = fib_seq(145);\r\nassert(isequal(X(end),144) \u0026\u0026 length(X)==12)\r\n%%\r\nX = fib_seq(4196);\r\nassert(isequal(X(end),4181) \u0026\u0026 length(X)==19)\r\n%%\r\nX = fib_seq(987419996);\r\nassert(isequal(X(end),701408733) \u0026\u0026 length(X)==44)\r\n%%\r\nX = fib_seq(1134903171);\r\nassert(isequal(X(end),1134903170) \u0026\u0026 length(X)==45)\r\n%%\r\nX = fib_seq(98691443031971);\r\nassert(isequal(X(end),72723460248141) \u0026\u0026 length(X)==68)","published":true,"deleted":false,"likes_count":10,"comments_count":2,"created_by":459,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1507,"test_suite_updated_at":"2017-05-23T15:28:28.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2012-03-02T01:07:27.000Z","updated_at":"2026-03-22T08:21:13.000Z","published_at":"2012-03-02T01:12:20.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a code which returns the Fibonacci Sequence such that the largest value in the sequence is less than the input integer N. For example,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[\u003e\u003e fib_seq(34)\\n\\nans =\\n\\n       1  1  2  3  5  8  13  21\\n\\n\u003e\u003e fib_seq(35)\\n\\nans =\\n\\n       1  1  2  3  5  8  13  21  34]]\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":1190,"title":"Golomb's self-describing sequence (based on Euler 341)","description":"The Golomb's self-describing sequence {G(n)} is the only nondecreasing sequence of natural numbers such that n appears exactly G(n) times in the sequence. The values of G(n) for the first few n are\r\n\r\n* |n =\u0026nbsp;    1    2    3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t…|\r\n* |G(n) 1    2\t2\t3\t3\t4\t4\t4\t5\t5\t\u0026nbsp;5\t\u0026nbsp;6\t\u0026nbsp;6\t\u0026nbsp;6\t\u0026nbsp;6\t\u0026nbsp;…|\r\n\r\nWrite a MATLAB script that will give you G(n) when given n.\r\n\r\nEfficiency is key here, since some of the values in the test suite will take a while to calculate.","description_html":"\u003cp\u003eThe Golomb's self-describing sequence {G(n)} is the only nondecreasing sequence of natural numbers such that n appears exactly G(n) times in the sequence. The values of G(n) for the first few n are\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ctt\u003en =\u0026nbsp;    1    2    3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t…\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003eG(n) 1    2\t2\t3\t3\t4\t4\t4\t5\t5\t\u0026nbsp;5\t\u0026nbsp;6\t\u0026nbsp;6\t\u0026nbsp;6\t\u0026nbsp;6\t\u0026nbsp;…\u003c/tt\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eWrite a MATLAB script that will give you G(n) when given n.\u003c/p\u003e\u003cp\u003eEfficiency is key here, since some of the values in the test suite will take a while to calculate.\u003c/p\u003e","function_template":"function y = euler341(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nassert(isequal(euler341(1),1))\r\n%%\r\nassert(isequal(euler341(10),5))\r\n%%\r\nassert(isequal(euler341(310),42))\r\n%%\r\nassert(isequal(euler341(4242),210))\r\n%%\r\nassert(isequal(euler341(328509),3084))\r\n%%\r\nassert(isequal(euler341(551368),4247))\r\n%%\r\nassert(isequal(euler341(614125),4540))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":183,"test_suite_updated_at":"2013-10-01T17:43:23.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2013-01-09T15:55:47.000Z","updated_at":"2026-03-25T04:50:04.000Z","published_at":"2013-01-09T15:55:47.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\u003eThe Golomb's self-describing sequence {G(n)} is the only nondecreasing sequence of natural numbers such that n appears exactly G(n) times in the sequence. The values of G(n) for the first few n are\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 …\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eG(n) 1 2 2 3 3 4 4 4 5 5 5 6 6 6 6 …\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a MATLAB script that will give you G(n) when given 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\u003eEfficiency is key here, since some of the values in the test suite will take a while to calculate.\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":594,"title":"\"Look and say\" sequence","description":"What's the next number in this sequence?\r\n\r\n* [0]\r\n* [1 0]\r\n* [1 1 1 0]\r\n* [3 1 1 0]\r\n* [1 3 2 1 1 0]\r\n\r\nThis a variant on the well-known \u003chttp://en.wikipedia.org/wiki/Look-and-say_sequence \"look and say\" or  Morris sequence\u003e, where each new iteration is made up by 'saying' the number of numbers you see. That last line is \"one 3; then two 1s; then one 0\".\r\n\r\nCreate a function that returns the next element of this sequence, given a vector as a starting seed..","description_html":"\u003cp\u003eWhat's the next number in this sequence?\u003c/p\u003e\u003cul\u003e\u003cli\u003e[0]\u003c/li\u003e\u003cli\u003e[1 0]\u003c/li\u003e\u003cli\u003e[1 1 1 0]\u003c/li\u003e\u003cli\u003e[3 1 1 0]\u003c/li\u003e\u003cli\u003e[1 3 2 1 1 0]\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThis a variant on the well-known \u003ca href = \"http://en.wikipedia.org/wiki/Look-and-say_sequence\"\u003e\"look and say\" or  Morris sequence\u003c/a\u003e, where each new iteration is made up by 'saying' the number of numbers you see. That last line is \"one 3; then two 1s; then one 0\".\u003c/p\u003e\u003cp\u003eCreate a function that returns the next element of this sequence, given a vector as a starting seed..\u003c/p\u003e","function_template":"function NEXT = look_and_say(SEED)\r\n  NEXT = SEED;\r\nend","test_suite":"%%\r\nassert(isequal(look_and_say([1]),[1 1]))\r\n%%\r\nassert(isequal(look_and_say([1 1 1 1 1]),[5 1]))\r\n%%\r\nassert(isequal(look_and_say([1 3 3 1 5 2 2]),[1 1 2 3 1 1 1 5 2 2]))\r\n%%\r\nassert(isequal(look_and_say([8 6 7 5 3 0 9]),[1 8 1 6 1 7 1 5 1 3 1 0 1 9]))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":4,"created_by":78,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":238,"test_suite_updated_at":"2012-04-17T19:20:53.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-17T15:20:45.000Z","updated_at":"2026-03-25T05:08:20.000Z","published_at":"2012-04-17T15:21:34.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\u003eWhat's the next number in this sequence?\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\u003e[0]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[1 0]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[1 1 1 0]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[3 1 1 0]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[1 3 2 1 1 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\u003eThis a variant on the well-known\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://en.wikipedia.org/wiki/Look-and-say_sequence\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\\\"look and say\\\" or Morris sequence\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, where each new iteration is made up by 'saying' the number of numbers you see. That last line is \\\"one 3; then two 1s; then one 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\u003eCreate a function that returns the next element of this sequence, given a vector as a starting seed..\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":2423,"title":"Integer Sequence - II : New Fibonacci","description":"Crack the following Integer Sequence. (Hints : It has been obtained from original Fibonacci Sequence and all the terms are also part of original Fibonacci 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: 42px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 21px; transform-origin: 407px 21px; vertical-align: baseline; \"\u003e\u003cdiv style=\"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: 374px 8px; transform-origin: 374px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eCrack the following Integer Sequence. (Hints : It has been obtained from original Fibonacci Sequence and all the terms are also part of original Fibonacci Sequence)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = newFibo(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nfiletext = fileread('newFibo.m');\r\nillegal = contains(filetext, 'if') || contains(filetext, 'interp') || ...\r\n          contains(filetext, 'str2num') || contains(filetext, 'regexp') ...\r\n          || contains(filetext, 'switch'); \r\nassert(~illegal)\r\n\r\n%%\r\nassert(isequal(newFibo(1),1))\r\n\r\n%%\r\nassert(isequal(newFibo(2),1))\r\n\r\n%%\r\nassert(isequal(newFibo(3),1))\r\n\r\n%%\r\nassert(isequal(newFibo(4),2))\r\n\r\n%%\r\nassert(isequal(newFibo(5),5))\r\n\r\n%%\r\nassert(isequal(newFibo(6),21))\r\n\r\n%%\r\nassert(isequal(newFibo(8),10946))\r\n\r\n%%\r\nassert(isequal(newFibo(9),5702887))\r\n\r\n%%\r\nassert(isequal(newFibo(10),139583862445))","published":true,"deleted":false,"likes_count":20,"comments_count":13,"created_by":17203,"edited_by":223089,"edited_at":"2022-12-26T07:26:12.000Z","deleted_by":null,"deleted_at":null,"solvers_count":679,"test_suite_updated_at":"2022-12-26T07:26:12.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2014-07-14T07:40:27.000Z","updated_at":"2026-03-01T13:32:27.000Z","published_at":"2014-07-14T07:40:27.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\u003eCrack the following Integer Sequence. (Hints : It has been obtained from original Fibonacci Sequence and all the terms are also part of original Fibonacci 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":2371,"title":"Integer sequence - 2 : Kolakoski sequence","description":"Get the n-th term of Kolakoski Sequence.","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: 21px; display: block; min-width: 0px; padding-block-start: 0px; padding-inline-start: 2px; padding-left: 2px; padding-top: 0px; perspective-origin: 408px 10.5px; transform-origin: 408px 10.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"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: 384px 10.5px; text-align: left; transform-origin: 384px 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: 60.6583px 8px; transform-origin: 60.6583px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGet the n-th term of\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 1.94167px 8px; transform-origin: 1.94167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://oeis.org/A000002\"\u003e\u003cspan style=\"border-block-end-color: rgb(0, 91, 130); border-block-start-color: rgb(0, 91, 130); border-bottom-color: rgb(0, 91, 130); border-inline-end-color: rgb(0, 91, 130); border-inline-start-color: rgb(0, 91, 130); border-left-color: rgb(0, 91, 130); border-right-color: rgb(0, 91, 130); border-top-color: rgb(0, 91, 130); caret-color: rgb(0, 91, 130); color: rgb(0, 91, 130); column-rule-color: rgb(0, 91, 130); outline-color: rgb(0, 91, 130); text-decoration-color: rgb(0, 91, 130); text-emphasis-color: rgb(0, 91, 130); \"\u003e\u003cspan style=\"\"\u003eKolakoski Sequence\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 1.94167px 8px; transform-origin: 1.94167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x)\r\n    \r\nend","test_suite":"%%\r\nfiletext = fileread('your_fcn_name.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp ''') || ...\r\n        contains(filetext, 'oeis') || contains(filetext, 'str2num');\r\nassert(~illegal)\r\n\r\n%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 2;\r\ny_correct = 2;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 3;\r\ny_correct = 2;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 9;\r\ny_correct = 2;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 12;\r\ny_correct = 2;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 31;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 34;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 37;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 50;\r\ny_correct = 2;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 200;\r\ny_correct = 2;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 200;\r\ny_correct = 2;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = randi(20, 1, 10);\r\ny = [1 2 2 1 1 2 1 2 2 1 2 2 1 1 2 1 1 2 2 1];\r\nassert(isequal(arrayfun(@your_fcn_name, x),y(x)))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":6,"created_by":17203,"edited_by":223089,"edited_at":"2026-01-28T14:20:54.000Z","deleted_by":null,"deleted_at":null,"solvers_count":190,"test_suite_updated_at":"2026-01-28T14:20:54.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2014-06-18T07:19:02.000Z","updated_at":"2026-03-25T04:59:59.000Z","published_at":"2014-06-18T07:19:35.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\u003eGet the n-th term of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://oeis.org/A000002\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eKolakoski Sequence\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":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":415,"title":"Sum the Infinite Series","description":"  Given that 0 \u003c x and x \u003c 2*pi where x is in radians, write a function\r\n\r\n [c,s] = infinite_series(x);\r\n\r\nthat returns with the sums of the two infinite series\r\n\r\n c = cos(2*x)/1/2 + cos(3*x)/2/3 + cos(4*x)/3/4 + ... + cos((n+1)*x)/n/(n+1) + ...\r\n s = sin(2*x)/1/2 + sin(3*x)/2/3 + sin(4*x)/3/4 + ... + sin((n+1)*x)/n/(n+1) + ...\r\n","description_html":"\u003cpre class=\"language-matlab\"\u003eGiven that 0 \u0026lt; x and x \u0026lt; 2*pi where x is in radians, write a function\r\n\u003c/pre\u003e\u003cpre\u003e [c,s] = infinite_series(x);\u003c/pre\u003e\u003cp\u003ethat returns with the sums of the two infinite series\u003c/p\u003e\u003cpre\u003e c = cos(2*x)/1/2 + cos(3*x)/2/3 + cos(4*x)/3/4 + ... + cos((n+1)*x)/n/(n+1) + ...\r\n s = sin(2*x)/1/2 + sin(3*x)/2/3 + sin(4*x)/3/4 + ... + sin((n+1)*x)/n/(n+1) + ...\u003c/pre\u003e","function_template":"function  [c,s] = infinite_series(x)\r\n  c = 0; s = 0;\r\nend","test_suite":"%%\r\nx = 1;      \r\n[c,s] = infinite_series(x);\r\nc_correct = -0.3800580037051224; s_correct =  0.3845865774434312;\r\nassert(abs(c-c_correct)\u003c50*eps \u0026 abs(s-s_correct)\u003c50*eps)\r\n%%\r\nx = exp(1); \r\n[c,s] = infinite_series(x);\r\nc_correct =  0.2832904461013926; s_correct = -0.2693088098978689;\r\nassert(abs(c-c_correct)\u003c50*eps \u0026 abs(s-s_correct)\u003c50*eps)\r\n%%\r\nx = sqrt(3);\r\n[c,s] = infinite_series(x);\r\nc_correct = -0.3675627321761342; s_correct = -0.2464611942058812;\r\nassert(abs(c-c_correct)\u003c50*eps \u0026 abs(s-s_correct)\u003c50*eps)\r\n%%\r\nx = 0.001;  \r\n[c,s] = infinite_series(x);\r\nc_correct =  0.9984257500575904; s_correct =  0.0079069688545917;\r\nassert(abs(c-c_correct)\u003c50*eps \u0026 abs(s-s_correct)\u003c50*eps)\r\n%%\r\nx = pi/4;   \r\n[c,s] = infinite_series(x);\r\nc_correct = -0.2042534159513846; s_correct =  0.5511304391316155;\r\nassert(abs(c-c_correct)\u003c50*eps \u0026 abs(s-s_correct)\u003c50*eps)\r\n%%\r\nx = 0.0263; \r\n[c,s] = infinite_series(x);\r\nc_correct =  0.9574346130196565; s_correct =  0.1214323234202421;\r\nassert(abs(c-c_correct)\u003c50*eps \u0026 abs(s-s_correct)\u003c50*eps)\r\n%%\r\nx = 6.273;  \r\n[c,s] = infinite_series(x);\r\nc_correct =  0.9837633160098646; s_correct = -0.0568212139709541;\r\nassert(abs(c-c_correct)\u003c50*eps \u0026 abs(s-s_correct)\u003c50*eps)\r\n%%\r\nx = 31/7;   \r\n[c,s] = infinite_series(x);\r\nc_correct = -0.2961416175321223; s_correct =  0.3148962998550185;\r\nassert(abs(c-c_correct)\u003c50*eps \u0026 abs(s-s_correct)\u003c50*eps)\r\n","published":true,"deleted":false,"likes_count":10,"comments_count":8,"created_by":28,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":143,"test_suite_updated_at":"2012-02-26T05:22:31.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2012-02-26T05:22:31.000Z","updated_at":"2026-03-25T12:52:47.000Z","published_at":"2012-02-26T05:22: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=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Given that 0 \u003c x and x \u003c 2*pi where x is in radians, write a function\\n\\n [c,s] = infinite_series(x);]]\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\u003ethat returns with the sums of the two infinite series\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ c = cos(2*x)/1/2 + cos(3*x)/2/3 + cos(4*x)/3/4 + ... + cos((n+1)*x)/n/(n+1) + ...\\n s = sin(2*x)/1/2 + sin(3*x)/2/3 + sin(4*x)/3/4 + ... + sin((n+1)*x)/n/(n+1) + ...]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":317,"title":"Find the stride of the longest skip sequence","description":"We define a _skip sequence_ as a regularly-spaced list of integers such as might be generated by MATLAB's \u003chttp://www.mathworks.com/help/matlab/ref/colon.html colon operator\u003e. We will call the inter-element increment the _stride_. So the vector 2:3:17 or [2 5 8 11 14 17] is a six-element skip sequence with stride 3.\r\n\r\nGiven the vector a, your job is to find the stride associated with the longest skip sequence you can assemble using any of the elements of a in any order. You can assume that stride is positive and unique.\r\n\r\nExample:\r\n\r\n input  a = [1 5 3 11 7 2 4 9]\r\n output stride is 2\r\n\r\nsince from the elements of a we can build the six-element sequence [1 3 5 7 9 11].","description_html":"\u003cp\u003eWe define a \u003ci\u003eskip sequence\u003c/i\u003e as a regularly-spaced list of integers such as might be generated by MATLAB's \u003ca href=\"http://www.mathworks.com/help/matlab/ref/colon.html\"\u003ecolon operator\u003c/a\u003e. We will call the inter-element increment the \u003ci\u003estride\u003c/i\u003e. So the vector 2:3:17 or [2 5 8 11 14 17] is a six-element skip sequence with stride 3.\u003c/p\u003e\u003cp\u003eGiven the vector a, your job is to find the stride associated with the longest skip sequence you can assemble using any of the elements of a in any order. You can assume that stride is positive and unique.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e input  a = [1 5 3 11 7 2 4 9]\r\n output stride is 2\u003c/pre\u003e\u003cp\u003esince from the elements of a we can build the six-element sequence [1 3 5 7 9 11].\u003c/p\u003e","function_template":"function stride = skip_sequence_stride(a)\r\n  stride = 0;\r\nend","test_suite":"%%\r\na = [1 5 3 11 7 2 4 9];\r\nstride = 2;\r\nassert(isequal(skip_sequence_stride(a),stride))\r\n\r\n%%\r\na = [1:5:20 23:3:42 2:9:100];\r\nstride = 9;\r\nassert(isequal(skip_sequence_stride(a),stride))\r\n\r\n%%\r\na = [2:2:22 13:17];\r\na = a(randperm(length(a)));\r\nstride = 2;\r\nassert(isequal(skip_sequence_stride(a),stride))\r\n\r\n%%\r\na = 37:5:120;\r\na = a(randperm(length(a)));\r\nstride = 5;\r\nassert(isequal(skip_sequence_stride(a),stride))\r\n\r\n%%\r\na = [1:5 101:10:171 201:205];\r\na = a(randperm(length(a)));\r\nstride = 10;\r\nassert(isequal(skip_sequence_stride(a),stride))\r\n\r\n%%\r\na = [7:17:302 primes(300)];\r\na = sort(a);\r\nstride = 17;\r\nassert(isequal(skip_sequence_stride(a),stride))\r\n","published":true,"deleted":false,"likes_count":9,"comments_count":6,"created_by":7,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":179,"test_suite_updated_at":"2014-02-13T19:31:00.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2012-02-13T21:03:00.000Z","updated_at":"2026-03-25T13:01:34.000Z","published_at":"2012-02-14T06:35:51.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\u003eWe define a\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\u003eskip sequence\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e as a regularly-spaced list of integers such as might be generated by MATLAB's\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/ref/colon.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ecolon operator\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. We will call the inter-element increment 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\u003estride\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. So the vector 2:3:17 or [2 5 8 11 14 17] is a six-element skip sequence with stride 3.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven the vector a, your job is to find the stride associated with the longest skip sequence you can assemble using any of the elements of a in any order. You can assume that stride is positive and unique.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ input  a = [1 5 3 11 7 2 4 9]\\n output stride is 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\u003esince from the elements of a we can build the six-element sequence [1 3 5 7 9 11].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":1323,"title":"Alternating sum","description":"Given vector x, calculate the alternating sum\r\n\r\n   y = x(1) - x(2) + x(3) - x(4) + ...","description_html":"\u003cp\u003eGiven vector x, calculate the alternating sum\u003c/p\u003e\u003cpre\u003e   y = x(1) - x(2) + x(3) - x(4) + ...\u003c/pre\u003e","function_template":"function y=altsum(x)\r\ny=0;\r\n","test_suite":"%%\r\nx=508;\r\nassert(isequal(altsum(x),508))\r\n%%\r\nx=[1692 591];\r\nassert(isequal(altsum(x),1101))\r\n%%\r\nx=[-644 380 1009];\r\nassert(isequal(altsum(x),-15))\r\n%%\r\nx=[-20 -48 0 -318];\r\nassert(isequal(altsum(x),346))\r\n%%\r\nx=[1095 -1874 428 896 731 578 40];\r\nassert(isequal(altsum(x),2694))","published":true,"deleted":false,"likes_count":8,"comments_count":0,"created_by":245,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":841,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":27,"created_at":"2013-03-07T20:03:18.000Z","updated_at":"2026-04-01T15:59:34.000Z","published_at":"2013-03-07T20:11:39.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 vector x, calculate the alternating sum\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   y = x(1) - x(2) + x(3) - x(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":566,"title":"Sum of first n terms of a harmonic progression","description":"Given inputs a, d and n, return the sum of the first n terms of the harmonic progression a, a/(1+d), a/(1+2d), a/(1+3d),....","description_html":"\u003cdiv style = \"text-align: start; line-height: 20px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: normal; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"display: block; min-width: 0px; padding-top: 0px; transform-origin: 332px 21px; vertical-align: baseline; perspective-origin: 332px 21px; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; transform-origin: 309px 21px; white-space: pre-wrap; perspective-origin: 309px 21px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eGiven inputs a, d and n, return the sum of the first n terms of the harmonic progression a, a/(1+d), a/(1+2d), a/(1+3d),....\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function s = harmonicSum(a,d,n)\r\n  s=0;\r\nend","test_suite":"%%\r\na=1;d=1;n=1;\r\ny_correct = 1;\r\nassert(isequal(harmonicSum(a,d,n),y_correct));\r\n\r\n%%\r\na=2;d=2;n=5;\r\ny_correct = round(3.5746,4);\r\nassert(isequal(round(harmonicSum(a,d,n),4),y_correct));\r\n\r\n%%\r\na=4;d=5;n=2;\r\ny_correct = round(4.6667,4);\r\nassert(isequal(round(harmonicSum(a,d,n),4),y_correct));","published":true,"deleted":false,"likes_count":3,"comments_count":14,"created_by":2974,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":501,"test_suite_updated_at":"2020-09-29T02:43:20.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2012-04-08T16:38:19.000Z","updated_at":"2026-04-01T16:06:03.000Z","published_at":"2012-04-08T18:58: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\u003eGiven inputs a, d and n, return the sum of the first n terms of the harmonic progression a, a/(1+d), a/(1+2d), a/(1+3d),....\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":189,"title":"Sum all integers from 1 to 2^n","description":"Given the number x, y must be the summation of all integers from 1 to 2^x. For instance if x=2 then y must be 1+2+3+4=10.","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: 42px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 21px; transform-origin: 407px 21px; vertical-align: baseline; \"\u003e\u003cdiv style=\"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: 342.5px 8px; transform-origin: 342.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven the number x, y must be the summation of all integers from 1 to 2^x. For instance if x=2 then y must be 1+2+3+4=10.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = sum_int(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nfiletext = fileread('sum_int.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp');\r\nassert(~illegal)\r\n%%\r\nx = 1;\r\ny_correct = 3;\r\nassert(isequal(sum_int(x),y_correct))\r\n\r\n%%\r\nx = 3;\r\ny_correct = 36;\r\nassert(isequal(sum_int(x),y_correct))\r\n\r\n%%\r\nx = 7;\r\ny_correct = 8256;\r\nassert(isequal(sum_int(x),y_correct))\r\n\r\n%%\r\nx = 10;\r\ny_correct = 524800;\r\nassert(isequal(sum_int(x),y_correct))\r\n\r\n%%\r\nx = 11;\r\ny_correct = 2098176;\r\nassert(isequal(sum_int(x),y_correct))\r\n\r\n%%\r\nx = 14;\r\ny_correct = 134225920;\r\nassert(isequal(sum_int(x),y_correct))\r\n\r\n%%\r\nx = 17;\r\ny_correct = 8590000128;\r\nassert(isequal(sum_int(x),y_correct))","published":true,"deleted":false,"likes_count":94,"comments_count":24,"created_by":431,"edited_by":223089,"edited_at":"2022-11-24T08:12:49.000Z","deleted_by":null,"deleted_at":null,"solvers_count":17502,"test_suite_updated_at":"2022-11-24T08:12:49.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2012-01-31T00:43:21.000Z","updated_at":"2026-04-03T02:25:23.000Z","published_at":"2012-01-31T00:45:23.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven the number x, y must be the summation of all integers from 1 to 2^x. For instance if x=2 then y must be 1+2+3+4=10.\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":240,"title":"Project Euler: Problem 6, Natural numbers, squares and sums.","description":"The sum of the squares of the first ten natural numbers is,\r\n\r\n1^2 + 2^2 + ... + 10^2 = 385\r\nThe square of the sum of the first ten natural numbers is,\r\n\r\n(1 + 2 + ... + 10)^2 = 55^2 = 3025\r\nHence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 - 385 = 2640.\r\n\r\nFind the difference between the sum of the squares of the first N (where N is the input) natural numbers and the square of the sum.\r\n\r\nThank you to \u003chttp://projecteuler.net/problem=6 Project Euler Problem 6\u003e","description_html":"\u003cp\u003eThe sum of the squares of the first ten natural numbers is,\u003c/p\u003e\u003cp\u003e1^2 + 2^2 + ... + 10^2 = 385\r\nThe square of the sum of the first ten natural numbers is,\u003c/p\u003e\u003cp\u003e(1 + 2 + ... + 10)^2 = 55^2 = 3025\r\nHence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 - 385 = 2640.\u003c/p\u003e\u003cp\u003eFind the difference between the sum of the squares of the first N (where N is the input) natural numbers and the square of the sum.\u003c/p\u003e\u003cp\u003eThank you to \u003ca href=\"http://projecteuler.net/problem=6\"\u003eProject Euler Problem 6\u003c/a\u003e\u003c/p\u003e","function_template":"function y = euler006(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 10;\r\ny_correct = 2640;\r\nassert(isequal(euler006(x),y_correct))\r\n\r\n%%\r\nx = 20;\r\ny_correct = 41230;\r\nassert(isequal(euler006(x),y_correct))\r\n\r\n%%\r\nx = 200;\r\ny_correct = 401323300;\r\nassert(isequal(euler006(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":12,"comments_count":3,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":2540,"test_suite_updated_at":"2012-02-02T20:31:39.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2012-02-02T20:31:39.000Z","updated_at":"2026-03-26T08:44:39.000Z","published_at":"2012-02-02T20:32:49.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\u003eThe sum of the squares of the first ten natural numbers is,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1^2 + 2^2 + ... + 10^2 = 385 The square of the sum of the first ten natural numbers is,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(1 + 2 + ... + 10)^2 = 55^2 = 3025 Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 - 385 = 2640.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 difference between the sum of the squares of the first N (where N is the input) natural numbers and the square of the sum.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThank you to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://projecteuler.net/problem=6\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProject Euler Problem 6\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":1084,"title":"Square Digits Number Chain Terminal Value (Inspired by Project Euler Problem 92)","description":"Given a number _n_, return the terminal value of the number chain formed by summing the square of the digits. According to the Project Euler problem, this number chain always terminates with either 1 or 89.\r\n\r\nProject Euler Problem 92: \u003chttp://projecteuler.net/problem=92 Link\u003e","description_html":"\u003cp\u003eGiven a number \u003ci\u003en\u003c/i\u003e, return the terminal value of the number chain formed by summing the square of the digits. According to the Project Euler problem, this number chain always terminates with either 1 or 89.\u003c/p\u003e\u003cp\u003eProject Euler Problem 92: \u003ca href=\"http://projecteuler.net/problem=92\"\u003eLink\u003c/a\u003e\u003c/p\u003e","function_template":"function y = digits_squared_chain(x)\r\n  y = 1;\r\nend","test_suite":"%%\r\nassert(digits_squared_chain(649) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(79) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(608) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(487) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(739) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(565) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(68) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(383) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(379) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(203) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(632) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(391) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(863) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(13) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(100) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(236) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(293) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(230) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(31) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(806) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(623) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(7) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(13) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(836) == 1)\r\n\r\n%%\r\nassert(digits_squared_chain(954) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(567) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(388) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(789) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(246) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(787) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(311) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(856) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(143) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(873) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(215) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(995) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(455) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(948) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(875) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(788) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(722) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(250) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(227) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(640) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(835) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(965) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(726) == 89)\r\n\r\n%%\r\nassert(digits_squared_chain(689) == 89)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":134,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":256,"test_suite_updated_at":"2012-12-05T06:42:14.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2012-12-03T06:49:33.000Z","updated_at":"2026-03-26T09:05:10.000Z","published_at":"2012-12-05T06:42:14.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 number\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, return the terminal value of the number chain formed by summing the square of the digits. According to the Project Euler problem, this number chain always terminates with either 1 or 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eProject Euler Problem 92:\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://projecteuler.net/problem=92\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eLink\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":434,"title":"Return the Fibonacci Sequence","description":"Write a code which returns the Fibonacci Sequence such that the largest value in the sequence is less than the input integer N.  For example, \r\n\r\n\r\n  \u003e\u003e fib_seq(34)\r\n\r\n  ans =\r\n\r\n       1  1  2  3  5  8  13  21\r\n\r\n  \u003e\u003e fib_seq(35)\r\n\r\n  ans =\r\n\r\n       1  1  2  3  5  8  13  21  34","description_html":"\u003cp\u003eWrite a code which returns the Fibonacci Sequence such that the largest value in the sequence is less than the input integer N.  For example,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e\u003e\u003e fib_seq(34)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eans =\r\n\u003c/pre\u003e\u003cpre\u003e       1  1  2  3  5  8  13  21\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003e\u003e\u003e fib_seq(35)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eans =\r\n\u003c/pre\u003e\u003cpre\u003e       1  1  2  3  5  8  13  21  34\u003c/pre\u003e","function_template":"function y = fib_seq(N)\r\n  y = x;\r\nend","test_suite":"%%\r\nX = fib_seq(34);\r\nassert(isequal(X(end),21) \u0026\u0026 length(X)==8)\r\n%%\r\nX = fib_seq(35);\r\nassert(isequal(X(end),34) \u0026\u0026 length(X)==9)\r\n%%\r\nX = fib_seq(145);\r\nassert(isequal(X(end),144) \u0026\u0026 length(X)==12)\r\n%%\r\nX = fib_seq(4196);\r\nassert(isequal(X(end),4181) \u0026\u0026 length(X)==19)\r\n%%\r\nX = fib_seq(987419996);\r\nassert(isequal(X(end),701408733) \u0026\u0026 length(X)==44)\r\n%%\r\nX = fib_seq(1134903171);\r\nassert(isequal(X(end),1134903170) \u0026\u0026 length(X)==45)\r\n%%\r\nX = fib_seq(98691443031971);\r\nassert(isequal(X(end),72723460248141) \u0026\u0026 length(X)==68)","published":true,"deleted":false,"likes_count":10,"comments_count":2,"created_by":459,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1507,"test_suite_updated_at":"2017-05-23T15:28:28.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2012-03-02T01:07:27.000Z","updated_at":"2026-03-22T08:21:13.000Z","published_at":"2012-03-02T01:12:20.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a code which returns the Fibonacci Sequence such that the largest value in the sequence is less than the input integer N. For example,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[\u003e\u003e fib_seq(34)\\n\\nans =\\n\\n       1  1  2  3  5  8  13  21\\n\\n\u003e\u003e fib_seq(35)\\n\\nans =\\n\\n       1  1  2  3  5  8  13  21  34]]\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":1190,"title":"Golomb's self-describing sequence (based on Euler 341)","description":"The Golomb's self-describing sequence {G(n)} is the only nondecreasing sequence of natural numbers such that n appears exactly G(n) times in the sequence. The values of G(n) for the first few n are\r\n\r\n* |n =\u0026nbsp;    1    2    3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t…|\r\n* |G(n) 1    2\t2\t3\t3\t4\t4\t4\t5\t5\t\u0026nbsp;5\t\u0026nbsp;6\t\u0026nbsp;6\t\u0026nbsp;6\t\u0026nbsp;6\t\u0026nbsp;…|\r\n\r\nWrite a MATLAB script that will give you G(n) when given n.\r\n\r\nEfficiency is key here, since some of the values in the test suite will take a while to calculate.","description_html":"\u003cp\u003eThe Golomb's self-describing sequence {G(n)} is the only nondecreasing sequence of natural numbers such that n appears exactly G(n) times in the sequence. The values of G(n) for the first few n are\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ctt\u003en =\u0026nbsp;    1    2    3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t…\u003c/tt\u003e\u003c/li\u003e\u003cli\u003e\u003ctt\u003eG(n) 1    2\t2\t3\t3\t4\t4\t4\t5\t5\t\u0026nbsp;5\t\u0026nbsp;6\t\u0026nbsp;6\t\u0026nbsp;6\t\u0026nbsp;6\t\u0026nbsp;…\u003c/tt\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eWrite a MATLAB script that will give you G(n) when given n.\u003c/p\u003e\u003cp\u003eEfficiency is key here, since some of the values in the test suite will take a while to calculate.\u003c/p\u003e","function_template":"function y = euler341(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nassert(isequal(euler341(1),1))\r\n%%\r\nassert(isequal(euler341(10),5))\r\n%%\r\nassert(isequal(euler341(310),42))\r\n%%\r\nassert(isequal(euler341(4242),210))\r\n%%\r\nassert(isequal(euler341(328509),3084))\r\n%%\r\nassert(isequal(euler341(551368),4247))\r\n%%\r\nassert(isequal(euler341(614125),4540))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":183,"test_suite_updated_at":"2013-10-01T17:43:23.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2013-01-09T15:55:47.000Z","updated_at":"2026-03-25T04:50:04.000Z","published_at":"2013-01-09T15:55:47.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\u003eThe Golomb's self-describing sequence {G(n)} is the only nondecreasing sequence of natural numbers such that n appears exactly G(n) times in the sequence. The values of G(n) for the first few n are\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 …\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eG(n) 1 2 2 3 3 4 4 4 5 5 5 6 6 6 6 …\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a MATLAB script that will give you G(n) when given 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\u003eEfficiency is key here, since some of the values in the test suite will take a while to calculate.\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":594,"title":"\"Look and say\" sequence","description":"What's the next number in this sequence?\r\n\r\n* [0]\r\n* [1 0]\r\n* [1 1 1 0]\r\n* [3 1 1 0]\r\n* [1 3 2 1 1 0]\r\n\r\nThis a variant on the well-known \u003chttp://en.wikipedia.org/wiki/Look-and-say_sequence \"look and say\" or  Morris sequence\u003e, where each new iteration is made up by 'saying' the number of numbers you see. That last line is \"one 3; then two 1s; then one 0\".\r\n\r\nCreate a function that returns the next element of this sequence, given a vector as a starting seed..","description_html":"\u003cp\u003eWhat's the next number in this sequence?\u003c/p\u003e\u003cul\u003e\u003cli\u003e[0]\u003c/li\u003e\u003cli\u003e[1 0]\u003c/li\u003e\u003cli\u003e[1 1 1 0]\u003c/li\u003e\u003cli\u003e[3 1 1 0]\u003c/li\u003e\u003cli\u003e[1 3 2 1 1 0]\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThis a variant on the well-known \u003ca href = \"http://en.wikipedia.org/wiki/Look-and-say_sequence\"\u003e\"look and say\" or  Morris sequence\u003c/a\u003e, where each new iteration is made up by 'saying' the number of numbers you see. That last line is \"one 3; then two 1s; then one 0\".\u003c/p\u003e\u003cp\u003eCreate a function that returns the next element of this sequence, given a vector as a starting seed..\u003c/p\u003e","function_template":"function NEXT = look_and_say(SEED)\r\n  NEXT = SEED;\r\nend","test_suite":"%%\r\nassert(isequal(look_and_say([1]),[1 1]))\r\n%%\r\nassert(isequal(look_and_say([1 1 1 1 1]),[5 1]))\r\n%%\r\nassert(isequal(look_and_say([1 3 3 1 5 2 2]),[1 1 2 3 1 1 1 5 2 2]))\r\n%%\r\nassert(isequal(look_and_say([8 6 7 5 3 0 9]),[1 8 1 6 1 7 1 5 1 3 1 0 1 9]))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":4,"created_by":78,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":238,"test_suite_updated_at":"2012-04-17T19:20:53.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-17T15:20:45.000Z","updated_at":"2026-03-25T05:08:20.000Z","published_at":"2012-04-17T15:21:34.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\u003eWhat's the next number in this sequence?\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\u003e[0]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[1 0]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[1 1 1 0]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[3 1 1 0]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[1 3 2 1 1 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\u003eThis a variant on the well-known\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://en.wikipedia.org/wiki/Look-and-say_sequence\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\\\"look and say\\\" or Morris sequence\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, where each new iteration is made up by 'saying' the number of numbers you see. That last line is \\\"one 3; then two 1s; then one 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\u003eCreate a function that returns the next element of this sequence, given a vector as a starting seed..\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":2423,"title":"Integer Sequence - II : New Fibonacci","description":"Crack the following Integer Sequence. (Hints : It has been obtained from original Fibonacci Sequence and all the terms are also part of original Fibonacci 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: 42px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 21px; transform-origin: 407px 21px; vertical-align: baseline; \"\u003e\u003cdiv style=\"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: 374px 8px; transform-origin: 374px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eCrack the following Integer Sequence. (Hints : It has been obtained from original Fibonacci Sequence and all the terms are also part of original Fibonacci Sequence)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = newFibo(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nfiletext = fileread('newFibo.m');\r\nillegal = contains(filetext, 'if') || contains(filetext, 'interp') || ...\r\n          contains(filetext, 'str2num') || contains(filetext, 'regexp') ...\r\n          || contains(filetext, 'switch'); \r\nassert(~illegal)\r\n\r\n%%\r\nassert(isequal(newFibo(1),1))\r\n\r\n%%\r\nassert(isequal(newFibo(2),1))\r\n\r\n%%\r\nassert(isequal(newFibo(3),1))\r\n\r\n%%\r\nassert(isequal(newFibo(4),2))\r\n\r\n%%\r\nassert(isequal(newFibo(5),5))\r\n\r\n%%\r\nassert(isequal(newFibo(6),21))\r\n\r\n%%\r\nassert(isequal(newFibo(8),10946))\r\n\r\n%%\r\nassert(isequal(newFibo(9),5702887))\r\n\r\n%%\r\nassert(isequal(newFibo(10),139583862445))","published":true,"deleted":false,"likes_count":20,"comments_count":13,"created_by":17203,"edited_by":223089,"edited_at":"2022-12-26T07:26:12.000Z","deleted_by":null,"deleted_at":null,"solvers_count":679,"test_suite_updated_at":"2022-12-26T07:26:12.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2014-07-14T07:40:27.000Z","updated_at":"2026-03-01T13:32:27.000Z","published_at":"2014-07-14T07:40:27.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\u003eCrack the following Integer Sequence. (Hints : It has been obtained from original Fibonacci Sequence and all the terms are also part of original Fibonacci 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":2371,"title":"Integer sequence - 2 : Kolakoski sequence","description":"Get the n-th term of Kolakoski Sequence.","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: 21px; display: block; min-width: 0px; padding-block-start: 0px; padding-inline-start: 2px; padding-left: 2px; padding-top: 0px; perspective-origin: 408px 10.5px; transform-origin: 408px 10.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"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: 384px 10.5px; text-align: left; transform-origin: 384px 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: 60.6583px 8px; transform-origin: 60.6583px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGet the n-th term of\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 1.94167px 8px; transform-origin: 1.94167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://oeis.org/A000002\"\u003e\u003cspan style=\"border-block-end-color: rgb(0, 91, 130); border-block-start-color: rgb(0, 91, 130); border-bottom-color: rgb(0, 91, 130); border-inline-end-color: rgb(0, 91, 130); border-inline-start-color: rgb(0, 91, 130); border-left-color: rgb(0, 91, 130); border-right-color: rgb(0, 91, 130); border-top-color: rgb(0, 91, 130); caret-color: rgb(0, 91, 130); color: rgb(0, 91, 130); column-rule-color: rgb(0, 91, 130); outline-color: rgb(0, 91, 130); text-decoration-color: rgb(0, 91, 130); text-emphasis-color: rgb(0, 91, 130); \"\u003e\u003cspan style=\"\"\u003eKolakoski Sequence\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 1.94167px 8px; transform-origin: 1.94167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x)\r\n    \r\nend","test_suite":"%%\r\nfiletext = fileread('your_fcn_name.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp ''') || ...\r\n        contains(filetext, 'oeis') || contains(filetext, 'str2num');\r\nassert(~illegal)\r\n\r\n%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 2;\r\ny_correct = 2;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 3;\r\ny_correct = 2;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 9;\r\ny_correct = 2;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 12;\r\ny_correct = 2;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 31;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 34;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 37;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 50;\r\ny_correct = 2;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 200;\r\ny_correct = 2;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 200;\r\ny_correct = 2;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = randi(20, 1, 10);\r\ny = [1 2 2 1 1 2 1 2 2 1 2 2 1 1 2 1 1 2 2 1];\r\nassert(isequal(arrayfun(@your_fcn_name, x),y(x)))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":6,"created_by":17203,"edited_by":223089,"edited_at":"2026-01-28T14:20:54.000Z","deleted_by":null,"deleted_at":null,"solvers_count":190,"test_suite_updated_at":"2026-01-28T14:20:54.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2014-06-18T07:19:02.000Z","updated_at":"2026-03-25T04:59:59.000Z","published_at":"2014-06-18T07:19:35.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\u003eGet the n-th term of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://oeis.org/A000002\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eKolakoski Sequence\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":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":415,"title":"Sum the Infinite Series","description":"  Given that 0 \u003c x and x \u003c 2*pi where x is in radians, write a function\r\n\r\n [c,s] = infinite_series(x);\r\n\r\nthat returns with the sums of the two infinite series\r\n\r\n c = cos(2*x)/1/2 + cos(3*x)/2/3 + cos(4*x)/3/4 + ... + cos((n+1)*x)/n/(n+1) + ...\r\n s = sin(2*x)/1/2 + sin(3*x)/2/3 + sin(4*x)/3/4 + ... + sin((n+1)*x)/n/(n+1) + ...\r\n","description_html":"\u003cpre class=\"language-matlab\"\u003eGiven that 0 \u0026lt; x and x \u0026lt; 2*pi where x is in radians, write a function\r\n\u003c/pre\u003e\u003cpre\u003e [c,s] = infinite_series(x);\u003c/pre\u003e\u003cp\u003ethat returns with the sums of the two infinite series\u003c/p\u003e\u003cpre\u003e c = cos(2*x)/1/2 + cos(3*x)/2/3 + cos(4*x)/3/4 + ... + cos((n+1)*x)/n/(n+1) + ...\r\n s = sin(2*x)/1/2 + sin(3*x)/2/3 + sin(4*x)/3/4 + ... + sin((n+1)*x)/n/(n+1) + ...\u003c/pre\u003e","function_template":"function  [c,s] = infinite_series(x)\r\n  c = 0; s = 0;\r\nend","test_suite":"%%\r\nx = 1;      \r\n[c,s] = infinite_series(x);\r\nc_correct = -0.3800580037051224; s_correct =  0.3845865774434312;\r\nassert(abs(c-c_correct)\u003c50*eps \u0026 abs(s-s_correct)\u003c50*eps)\r\n%%\r\nx = exp(1); \r\n[c,s] = infinite_series(x);\r\nc_correct =  0.2832904461013926; s_correct = -0.2693088098978689;\r\nassert(abs(c-c_correct)\u003c50*eps \u0026 abs(s-s_correct)\u003c50*eps)\r\n%%\r\nx = sqrt(3);\r\n[c,s] = infinite_series(x);\r\nc_correct = -0.3675627321761342; s_correct = -0.2464611942058812;\r\nassert(abs(c-c_correct)\u003c50*eps \u0026 abs(s-s_correct)\u003c50*eps)\r\n%%\r\nx = 0.001;  \r\n[c,s] = infinite_series(x);\r\nc_correct =  0.9984257500575904; s_correct =  0.0079069688545917;\r\nassert(abs(c-c_correct)\u003c50*eps \u0026 abs(s-s_correct)\u003c50*eps)\r\n%%\r\nx = pi/4;   \r\n[c,s] = infinite_series(x);\r\nc_correct = -0.2042534159513846; s_correct =  0.5511304391316155;\r\nassert(abs(c-c_correct)\u003c50*eps \u0026 abs(s-s_correct)\u003c50*eps)\r\n%%\r\nx = 0.0263; \r\n[c,s] = infinite_series(x);\r\nc_correct =  0.9574346130196565; s_correct =  0.1214323234202421;\r\nassert(abs(c-c_correct)\u003c50*eps \u0026 abs(s-s_correct)\u003c50*eps)\r\n%%\r\nx = 6.273;  \r\n[c,s] = infinite_series(x);\r\nc_correct =  0.9837633160098646; s_correct = -0.0568212139709541;\r\nassert(abs(c-c_correct)\u003c50*eps \u0026 abs(s-s_correct)\u003c50*eps)\r\n%%\r\nx = 31/7;   \r\n[c,s] = infinite_series(x);\r\nc_correct = -0.2961416175321223; s_correct =  0.3148962998550185;\r\nassert(abs(c-c_correct)\u003c50*eps \u0026 abs(s-s_correct)\u003c50*eps)\r\n","published":true,"deleted":false,"likes_count":10,"comments_count":8,"created_by":28,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":143,"test_suite_updated_at":"2012-02-26T05:22:31.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2012-02-26T05:22:31.000Z","updated_at":"2026-03-25T12:52:47.000Z","published_at":"2012-02-26T05:22: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=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Given that 0 \u003c x and x \u003c 2*pi where x is in radians, write a function\\n\\n [c,s] = infinite_series(x);]]\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\u003ethat returns with the sums of the two infinite series\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ c = cos(2*x)/1/2 + cos(3*x)/2/3 + cos(4*x)/3/4 + ... + cos((n+1)*x)/n/(n+1) + ...\\n s = sin(2*x)/1/2 + sin(3*x)/2/3 + sin(4*x)/3/4 + ... + sin((n+1)*x)/n/(n+1) + ...]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":317,"title":"Find the stride of the longest skip sequence","description":"We define a _skip sequence_ as a regularly-spaced list of integers such as might be generated by MATLAB's \u003chttp://www.mathworks.com/help/matlab/ref/colon.html colon operator\u003e. We will call the inter-element increment the _stride_. So the vector 2:3:17 or [2 5 8 11 14 17] is a six-element skip sequence with stride 3.\r\n\r\nGiven the vector a, your job is to find the stride associated with the longest skip sequence you can assemble using any of the elements of a in any order. You can assume that stride is positive and unique.\r\n\r\nExample:\r\n\r\n input  a = [1 5 3 11 7 2 4 9]\r\n output stride is 2\r\n\r\nsince from the elements of a we can build the six-element sequence [1 3 5 7 9 11].","description_html":"\u003cp\u003eWe define a \u003ci\u003eskip sequence\u003c/i\u003e as a regularly-spaced list of integers such as might be generated by MATLAB's \u003ca href=\"http://www.mathworks.com/help/matlab/ref/colon.html\"\u003ecolon operator\u003c/a\u003e. We will call the inter-element increment the \u003ci\u003estride\u003c/i\u003e. So the vector 2:3:17 or [2 5 8 11 14 17] is a six-element skip sequence with stride 3.\u003c/p\u003e\u003cp\u003eGiven the vector a, your job is to find the stride associated with the longest skip sequence you can assemble using any of the elements of a in any order. You can assume that stride is positive and unique.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e input  a = [1 5 3 11 7 2 4 9]\r\n output stride is 2\u003c/pre\u003e\u003cp\u003esince from the elements of a we can build the six-element sequence [1 3 5 7 9 11].\u003c/p\u003e","function_template":"function stride = skip_sequence_stride(a)\r\n  stride = 0;\r\nend","test_suite":"%%\r\na = [1 5 3 11 7 2 4 9];\r\nstride = 2;\r\nassert(isequal(skip_sequence_stride(a),stride))\r\n\r\n%%\r\na = [1:5:20 23:3:42 2:9:100];\r\nstride = 9;\r\nassert(isequal(skip_sequence_stride(a),stride))\r\n\r\n%%\r\na = [2:2:22 13:17];\r\na = a(randperm(length(a)));\r\nstride = 2;\r\nassert(isequal(skip_sequence_stride(a),stride))\r\n\r\n%%\r\na = 37:5:120;\r\na = a(randperm(length(a)));\r\nstride = 5;\r\nassert(isequal(skip_sequence_stride(a),stride))\r\n\r\n%%\r\na = [1:5 101:10:171 201:205];\r\na = a(randperm(length(a)));\r\nstride = 10;\r\nassert(isequal(skip_sequence_stride(a),stride))\r\n\r\n%%\r\na = [7:17:302 primes(300)];\r\na = sort(a);\r\nstride = 17;\r\nassert(isequal(skip_sequence_stride(a),stride))\r\n","published":true,"deleted":false,"likes_count":9,"comments_count":6,"created_by":7,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":179,"test_suite_updated_at":"2014-02-13T19:31:00.000Z","rescore_all_solutions":false,"group_id":27,"created_at":"2012-02-13T21:03:00.000Z","updated_at":"2026-03-25T13:01:34.000Z","published_at":"2012-02-14T06:35:51.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\u003eWe define a\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\u003eskip sequence\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e as a regularly-spaced list of integers such as might be generated by MATLAB's\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/ref/colon.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ecolon operator\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. We will call the inter-element increment 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\u003estride\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. So the vector 2:3:17 or [2 5 8 11 14 17] is a six-element skip sequence with stride 3.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven the vector a, your job is to find the stride associated with the longest skip sequence you can assemble using any of the elements of a in any order. You can assume that stride is positive and unique.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ input  a = [1 5 3 11 7 2 4 9]\\n output stride is 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\u003esince from the elements of a we can build the six-element sequence [1 3 5 7 9 11].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"group:\"Sequences \u0026 Series I\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"group:\"Sequences \u0026 Series I\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"group":[["group:\"Sequences \u0026 Series I\"","","\"","Sequences \u0026 Series I","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fa2b429e740\u003e":["Sequences \u0026 Series I"],"#\u003cMathWorks::Search::Field:0x00007fa2b429e6a0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fa2b429dde0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fa2b429e9c0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fa2b429e920\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fa2b429e880\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fa2b429e7e0\u003e":"group:\"Sequences \u0026 Series I\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fa2b429e7e0\u003e":"group:\"Sequences \u0026 Series I\""},"queried_facets":{"#\u003cMathWorks::Search::Field:0x00007fa2b429e740\u003e":["Sequences \u0026 Series I"]}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"group:\"Sequences \u0026 Series I\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"group":[["group:\"Sequences \u0026 Series I\"","","\"","Sequences \u0026 Series I","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fa2b429e740\u003e":["Sequences \u0026 Series I"],"#\u003cMathWorks::Search::Field:0x00007fa2b429e6a0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fa2b429dde0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fa2b429e9c0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fa2b429e920\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fa2b429e880\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fa2b429e7e0\u003e":"group:\"Sequences \u0026 Series I\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fa2b429e7e0\u003e":"group:\"Sequences \u0026 Series I\""},"queried_facets":{"#\u003cMathWorks::Search::Field:0x00007fa2b429e740\u003e":["Sequences \u0026 Series I"]}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":1323,"difficulty_rating":"easy-medium"},{"id":566,"difficulty_rating":"easy-medium"},{"id":189,"difficulty_rating":"easy-medium"},{"id":240,"difficulty_rating":"easy-medium"},{"id":1084,"difficulty_rating":"easy-medium"},{"id":434,"difficulty_rating":"easy-medium"},{"id":1190,"difficulty_rating":"medium"},{"id":594,"difficulty_rating":"medium"},{"id":232,"difficulty_rating":"medium"},{"id":2423,"difficulty_rating":"medium"},{"id":2371,"difficulty_rating":"medium"},{"id":752,"difficulty_rating":"medium"},{"id":415,"difficulty_rating":"medium-hard"},{"id":317,"difficulty_rating":"medium-hard"}]}}