{"group":{"group":{"id":84606,"name":"MATLAB 1 Cody Problems","lockable":false,"created_at":"2024-02-29T13:37:11.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"This list of problems requires that you learn how to create MATLAB functions and tests your abilities on simple MATLAB activities.\nCody scores your answers by efficiency as measured by code created.","is_default":false,"created_by":2842368,"badge_id":62,"featured":false,"trending":false,"solution_count_in_trending_period":2150,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":6431,"published":false,"community_created":true,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis list of problems requires that you learn how to create MATLAB functions and tests your abilities on simple MATLAB activities.\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\u003eCody scores your answers by efficiency as measured by code created.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 72px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 318px 36px; transform-origin: 318px 36px; 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: 295px 21px; text-align: left; transform-origin: 295px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThis list of problems requires that you learn how to create MATLAB functions and tests your abilities on simple MATLAB activities.\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: 295px 10.5px; text-align: left; transform-origin: 295px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eCody scores your answers by efficiency as measured by code created.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","published_at":null},"current_player":null},"problems":[{"id":3,"title":"Find the sum of all the numbers of the input vector","description":"Find the sum of all the numbers of the input vector x. \r\n\r\n Examples:\r\n\r\n  Input  x = [1 2 3 5]\r\n  Output y is 11\r\n\r\n  Input  x = [42 -1]\r\n  Output y is 41\r\n ","description_html":"\u003cp\u003eFind the sum of all the numbers of the input vector x.\u003c/p\u003e\u003cpre\u003e Examples:\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput  x = [1 2 3 5]\r\nOutput y is 11\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput  x = [42 -1]\r\nOutput y is 41\r\n\u003c/pre\u003e","function_template":"function y = vecsum(x)\r\n   y = x\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(vecsum(x),y_correct))\r\n\r\n%%\r\nx = [1 2 3 5];\r\ny_correct = 11;\r\nassert(isequal(vecsum(x),y_correct))\r\n\r\n%%\r\nx = [1 2 3 5];\r\ny_correct = 11;\r\nassert(isequal(vecsum(x),y_correct))\r\n\r\n%%\r\nx = 1:100;\r\ny_correct = 5050;\r\nassert(isequal(vecsum(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":343,"comments_count":85,"created_by":1,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":54196,"test_suite_updated_at":"2013-07-17T17:49:37.000Z","rescore_all_solutions":false,"group_id":2,"created_at":"2012-01-18T01:00:17.000Z","updated_at":"2026-04-06T06:44:28.000Z","published_at":"2012-01-18T01:00:17.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the sum of all the numbers of the input vector x.\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[ Examples:\\n\\nInput  x = [1 2 3 5]\\nOutput y is 11\\n\\nInput  x = [42 -1]\\nOutput y is 41]]\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":8,"title":"Add two numbers","description":"Given a and b, return the sum a+b in c.","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: 21px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 10.5px; transform-origin: 407px 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; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 123.5px 8px; transform-origin: 123.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a and b, return the sum a+b in c.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function c = add_two_numbers(a,b)\r\n  c = 17;\r\nend","test_suite":"%%\r\nfiletext = fileread('add_two_numbers.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp') || ...\r\n          contains(filetext, 'if') || contains(filetext, 'switch'); \r\nassert(~illegal)\r\n\r\n%%\r\na = 1;\r\nb = 2;\r\nc_correct = 3;\r\nassert(isequal(add_two_numbers(a,b),c_correct))\r\n\r\n%%\r\na = 17;\r\nb = 2;\r\nc_correct = 19;\r\nassert(isequal(add_two_numbers(a,b),c_correct))\r\n\r\n\r\n%%\r\na = -5;\r\nb = 2;\r\nc_correct = -3;\r\nassert(isequal(add_two_numbers(a,b),c_correct))\r\n\r\n%%\r\na = randi(1e4);\r\nb = -a;\r\nassert(isequal(add_two_numbers(a,b),0))\r\n\r\n%%\r\na = randi(1e3);\r\nb = a;\r\nassert(isequal(add_two_numbers(a,b),2*a))\r\n","published":true,"deleted":false,"likes_count":306,"comments_count":84,"created_by":1,"edited_by":223089,"edited_at":"2022-12-19T10:49:35.000Z","deleted_by":null,"deleted_at":null,"solvers_count":46847,"test_suite_updated_at":"2022-12-19T10:49:47.000Z","rescore_all_solutions":false,"group_id":2,"created_at":"2012-01-18T01:00:18.000Z","updated_at":"2026-04-06T06:36:31.000Z","published_at":"2012-01-18T01:00:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a and b, return the sum a+b in c.\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":1545,"title":"Return area of square","description":"Side of square=input=a\r\n\r\nArea=output=b","description_html":"\u003cp\u003eSide of square=input=a\u003c/p\u003e\u003cp\u003eArea=output=b\u003c/p\u003e","function_template":"function b = area_square(a)\r\n  b = a;\r\nend","test_suite":"%%\r\nx = 0;\r\ny_correct = 0;\r\nassert(isequal(area_square(x),y_correct))\r\n%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(area_square(x),y_correct))\r\n%%\r\nx = 11;\r\ny_correct = 121;\r\nassert(isequal(area_square(x),y_correct))\r\n%%\r\nx = 101;\r\ny_correct = 10201;\r\nassert(isequal(area_square(x),y_correct))","published":true,"deleted":false,"likes_count":67,"comments_count":12,"created_by":14249,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18180,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-03T09:56:54.000Z","updated_at":"2026-04-06T07:32:14.000Z","published_at":"2013-06-03T09:56:54.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSide of square=input=a\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\u003eArea=output=b\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":2,"title":"Make the vector [1 2 3 4 5 6 7 8 9 10]","description":"In MATLAB, you create a vector by enclosing the elements in square brackets like so:\r\n\r\n x = [1 2 3 4]\r\n\r\nCommas are optional, so you can also type\r\n\r\n x = [1, 2, 3, 4]\r\n\r\nCreate the vector\r\n\r\n x = [1 2 3 4 5 6 7 8 9 10]\r\n\r\nThere's a faster way to do it using MATLAB's \u003chttp://www.mathworks.com/help/techdoc/ref/colon.html colon notation\u003e.","description_html":"\u003cp\u003eIn MATLAB, you create a vector by enclosing the elements in square brackets like so:\u003c/p\u003e\u003cpre\u003e x = [1 2 3 4]\u003c/pre\u003e\u003cp\u003eCommas are optional, so you can also type\u003c/p\u003e\u003cpre\u003e x = [1, 2, 3, 4]\u003c/pre\u003e\u003cp\u003eCreate the vector\u003c/p\u003e\u003cpre\u003e x = [1 2 3 4 5 6 7 8 9 10]\u003c/pre\u003e\u003cp\u003eThere's a faster way to do it using MATLAB's \u003ca href = \"http://www.mathworks.com/help/techdoc/ref/colon.html\"\u003ecolon notation\u003c/a\u003e.\u003c/p\u003e","function_template":"function x = oneToTen\r\n  x = 0;\r\nend","test_suite":"%%\r\nx_correct = [1 2 3 4 5 6 7 8 9 10];\r\nassert(isequal(oneToTen,x_correct))","published":true,"deleted":false,"likes_count":224,"comments_count":56,"created_by":1,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":52932,"test_suite_updated_at":"2012-01-18T01:00:17.000Z","rescore_all_solutions":false,"group_id":2,"created_at":"2012-01-18T01:00:17.000Z","updated_at":"2026-04-06T04:09:08.000Z","published_at":"2012-01-18T01:00:17.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn MATLAB, you create a vector by enclosing the elements in square brackets like so:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x = [1 2 3 4]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCommas are optional, so you can also type\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x = [1, 2, 3, 4]]]\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\u003eCreate the vector\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x = [1 2 3 4 5 6 7 8 9 10]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere's a faster way to do it using 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/techdoc/ref/colon.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ecolon notation\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44943,"title":"Calculate Amount of Cake Frosting","description":"Given two input variables r and h, which stand for the radius and height of a cake, calculate the surface area of the cake you need to put frosting on (all around the sides and the top).\r\nReturn the result in output variable SA.","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: 73px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 36.5px; transform-origin: 407px 36.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42.5px; 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 21.25px; text-align: left; transform-origin: 384px 21.25px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 79px 8px; transform-origin: 79px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven two input variables\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003er\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: 14px 8px; transform-origin: 14px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\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: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003eh\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: 276.5px 8px; transform-origin: 276.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, which stand for the radius and height of a cake, calculate the surface area of the cake you need to put frosting on (all around the sides and the top).\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21.5px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.75px; text-align: left; transform-origin: 384px 10.75px; 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: 109.5px 8px; transform-origin: 109.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn the result in output variable\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 8px 8px; transform-origin: 8px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 8px 8.5px; transform-origin: 8px 8.5px; \"\u003eSA\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function SA = func_frosting(r,h)\r\n  SA = r + h;\r\nend","test_suite":"%%\r\nfiletext = fileread('func_frosting.m');\r\nassert(isempty(strfind(filetext, 'regexp')))\r\nassert(isempty(strfind(filetext, 'else')))\r\nassert(isempty(strfind(filetext, 'switch')))\r\n\r\n%%\r\nr = 3;\r\nh = 2;\r\ny_correct = 65.9734;\r\nassert(abs(func_frosting(r,h) - y_correct) \u003c 1e-4)\r\n\r\n%%\r\nr = 1;\r\nh = 1;\r\ny_correct = 3*pi;\r\nassert(abs(func_frosting(r,h) - y_correct) \u003c 1e-4)\r\n\r\n%%\r\nr = 0.5;\r\nh = 0.25;\r\ny_correct = 1.5708;\r\nassert(abs(func_frosting(r,h) - y_correct) \u003c 1e-4)\r\n","published":true,"deleted":false,"likes_count":223,"comments_count":24,"created_by":162851,"edited_by":223089,"edited_at":"2022-07-06T08:49:20.000Z","deleted_by":null,"deleted_at":null,"solvers_count":29347,"test_suite_updated_at":"2022-07-06T08:49:20.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2019-08-13T19:36:28.000Z","updated_at":"2026-04-05T22:10:21.000Z","published_at":"2019-08-29T18:15:57.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 two input variables\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003er\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eh\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, which stand for the radius and height of a cake, calculate the surface area of the cake you need to put frosting on (all around the sides and the top).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the result in output variable\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSA\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\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":17505,"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-05T22:41:13.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":233,"title":"Reverse the vector","description":"Reverse the vector elements.\r\n\r\nExample:\r\n\r\n Input  x = [1,2,3,4,5,6,7,8,9] \r\n Output y = [9,8,7,6,5,4,3,2,1]","description_html":"\u003cp\u003eReverse the vector elements.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e Input  x = [1,2,3,4,5,6,7,8,9] \r\n Output y = [9,8,7,6,5,4,3,2,1]\u003c/pre\u003e","function_template":"function y = reverseVector(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(reverseVector(x),y_correct))\r\n\r\n%%\r\nx = -10:1;\r\ny_correct = 1:-1:-10;\r\nassert(isequal(reverseVector(x),y_correct))\r\n\r\n%%\r\nx = 'able was i ere i saw elba';\r\ny_correct = 'able was i ere i saw elba';\r\nassert(isequal(reverseVector(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":55,"comments_count":9,"created_by":868,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":16483,"test_suite_updated_at":"2016-10-23T02:09:16.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-02-02T15:28:45.000Z","updated_at":"2026-04-05T22:29:29.000Z","published_at":"2012-02-02T20:11:32.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReverse the vector elements.\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  x = [1,2,3,4,5,6,7,8,9] \\n Output y = [9,8,7,6,5,4,3,2,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":1087,"title":"Magic is simple (for beginners)","description":"Determine for a magic square of order n, the magic sum m. For example m=15 for a magic square of order 3.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 21px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 406.5px 10.5px; transform-origin: 406.5px 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; 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: 350.075px 7.81667px; transform-origin: 350.075px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eDetermine for a magic square of order n, the magic sum m. For example m=15 for a magic square of order 3.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function m = magic_sum(n)\r\n  m=n;\r\nend","test_suite":"%%\r\nfiletext = fileread('magic_sum.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp');\r\nassert(~illegal)\r\n\r\n%%\r\nn = 3;\r\ny_correct = 15;\r\nassert(isequal(magic_sum(n),y_correct))\r\n%%\r\nn = 5;\r\ny_correct = 65;\r\nassert(isequal(magic_sum(n),y_correct))\r\n%%\r\nn = 7;\r\ny_correct = 175;\r\nassert(isequal(magic_sum(n),y_correct))\r\n%%\r\nn = 8;\r\ny_correct = 260;\r\nassert(isequal(magic_sum(n),y_correct))\r\n%%\r\nn = 20;\r\ny_correct = 4010;\r\nassert(isequal(magic_sum(n),y_correct))\r\n%%\r\nn = 100;\r\ny_correct = 500050;\r\nassert(isequal(magic_sum(n),y_correct))\r\n%%\r\nn = 200;\r\ny_correct = 4000100;\r\nassert(isequal(magic_sum(n),y_correct))\r\n%%\r\nn = 1000;\r\ny_correct = 500000500;\r\nassert(isequal(magic_sum(n),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":56,"comments_count":13,"created_by":5390,"edited_by":223089,"edited_at":"2024-06-30T07:10:20.000Z","deleted_by":null,"deleted_at":null,"solvers_count":11217,"test_suite_updated_at":"2024-06-30T07:10:20.000Z","rescore_all_solutions":false,"group_id":18,"created_at":"2012-12-04T00:24:57.000Z","updated_at":"2026-04-05T22:40:24.000Z","published_at":"2012-12-04T00:26:29.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\u003eDetermine for a magic square of order n, the magic sum m. For example m=15 for a magic square of order 3.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":3056,"title":"Chess probability","description":"The difference in the ratings between two players serves as a predictor of the outcome of a match (the \u003chttp://en.wikipedia.org/wiki/Elo_rating_system Elo rating system\u003e)\r\n\r\nIf Player A has a rating of Ra and Player B a rating of Rb, the formula for the expected score of Player A is :\r\n\r\n\u003c\u003chttp://upload.wikimedia.org/math/b/0/3/b0366725c224ee55eab6e2371dc6a0ef.png\u003e\u003e\r\n \r\n* \r\n \r\n\r\nTwo players with equal ratings who play against each other are expected to score an equal number of wins. A player whose rating is 100 points greater than their opponent's is expected to score 64%; if the difference is 200 points, then the expected score for the stronger player is 76%.\r\n\r\nI give you two ELOs, compute the expected score (round to 3 digits), or probability  that the first player wins.\r\n\r\n\r\n","description_html":"\u003cp\u003eThe difference in the ratings between two players serves as a predictor of the outcome of a match (the \u003ca href = \"http://en.wikipedia.org/wiki/Elo_rating_system\"\u003eElo rating system\u003c/a\u003e)\u003c/p\u003e\u003cp\u003eIf Player A has a rating of Ra and Player B a rating of Rb, the formula for the expected score of Player A is :\u003c/p\u003e\u003cimg src = \"http://upload.wikimedia.org/math/b/0/3/b0366725c224ee55eab6e2371dc6a0ef.png\"\u003e\u003cul\u003e\u003cli\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eTwo players with equal ratings who play against each other are expected to score an equal number of wins. A player whose rating is 100 points greater than their opponent's is expected to score 64%; if the difference is 200 points, then the expected score for the stronger player is 76%.\u003c/p\u003e\u003cp\u003eI give you two ELOs, compute the expected score (round to 3 digits), or probability  that the first player wins.\u003c/p\u003e","function_template":"function y = expected_score(elo1,elo2)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1800;\r\ny = 1800;\r\nassert(isequal(expected_score(x,y),0.5))\r\n%%\r\nx = 1900;\r\ny = 1800;\r\nassert(isequal(expected_score(x,y),0.64))\r\n%%\r\nx = 1900;\r\ny = 2000;\r\nassert(isequal(expected_score(x,y),0.36))\r\n%%\r\nx = 1900;\r\ny = 2100;\r\nassert(isequal(expected_score(x,y),0.24))\r\n%% My probability against Maxime Vachier-Lagrave (best french player)\r\nx = 1800;\r\ny = 2775;\r\nassert(isequal(expected_score(x,y),0.004))\r\n%% My probability against Magnus Carlsen (World Chess Champion)\r\nx = 1800;\r\ny = 2865;\r\nassert(isequal(expected_score(x,y),0.002))\r\n%% Magnus against Maxime\r\nx = 2865;\r\ny = 2775;\r\nassert(isequal(expected_score(x,y),0.627))\r\n%% Magnus Carlsen against Garry Kasparov (1999)\r\nx = 2865;\r\ny = 2851;\r\nassert(isequal(expected_score(x,y),0.52))\r\n%% Magnus Carlsen against Fabiano Caruana\r\nx = 2865;\r\ny = 2844;\r\nassert(isequal(expected_score(x,y),0.53))\r\n%% Bobby Fisher (1972) against Magnus Carlsen\r\nx = 2785;\r\ny = 2865;\r\nassert(isequal(expected_score(x,y),0.387))\r\n%% Bobby Fisher (1972) against me\r\nx = 2785;\r\ny = 1800;\r\nassert(isequal(expected_score(x,y),0.997))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":0,"created_by":5390,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":680,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-02-28T22:51:09.000Z","updated_at":"2026-04-05T17:25:47.000Z","published_at":"2015-02-28T22:52:00.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/media/image1.png\"}],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe difference in the ratings between two players serves as a predictor of the outcome of a match (the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Elo_rating_system\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eElo rating system\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf Player A has a rating of Ra and Player B a rating of Rb, the formula for the expected score of Player A 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:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"relationshipId\\\" w:val=\\\"rId1\\\"/\u003e\u003c/w:customXmlPr\u003e\u003c/w:customXml\u003e\u003c/w:p\u003e\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\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\u003eTwo players with equal ratings who play against each other are expected to score an equal number of wins. A player whose rating is 100 points greater than their opponent's is expected to score 64%; if the difference is 200 points, then the expected score for the stronger player is 76%.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eI give you two ELOs, compute the expected score (round to 3 digits), or probability that the first player wins.\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\"},{\"partUri\":\"/media/image1.png\",\"contentType\":\"image/png\",\"content\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAM4AAAArBAMAAADCuKrGAAAAMFBMVEX///90dHQEBAQwMDCenp5QUFAWFhbm5ubMzMyKioq2trZAQEAMDAwiIiJiYmIAAADHPVvyAAAAAXRSTlMAQObYZgAAAuJJREFUeNrtV0toE2EQ/pJs91+TZpuKKZ7aHDxZhKBo8WCNQj14qNHiAxFZRNIHVAPFi0UbFC8qEqh40cOePBUfUAoS0BQPvhByqXqoEK1CaauNXswWu3H+JF03TbV5dHPqwGYzM//u98/881qgOhoscZ29OhjnkRIXOqqCYdvmXqMmtKc2fiuZ1nHWcdZxikmrDU7Xq53hkhbagG8Nz7Cl0WO565xkuxS3/nwEHUinrMfJ9NLdbz2OPYUkVOtD+2GA+S0HEYDAzQ82nyEYe8R/+yxAfoc6671G+dM6If+U0oC4sEyXWSuQHzw5JQ0MdfRnPmxpvGk6Fam9lK5q9kzGQpwSqz4Y+beK71cq2rSDxwC9V6iPlrE/+T/GH6fLVWRPhpx3ia57v4Jl4NyIYv5pV8HODH4kx9ep0uETuOYly9m43dV/N7brShRS50xw9amWCwabaWEboO4f7THrDF4PABv4aKe3PMDn2SSJFFMi2ZSiCvt2JcFLDMNJWdYEHqV/yeB52vvBmtQRiAfjOFvQfybhWF6zWau6gkDuwXlVoD214MK0WWvwGnnHB5ZCH9gLFf1mnKvTGJpY3ivfLIWd2yRI+yAEFsnpKe+sD/fbpwL5RVkeUraeLPpxPRtdH42HS5me3SZBgwcOxRWAlEI7aSJCwhaLxR7nebjI0m76PGBRUW2C+EnBucr6djgCSaHSoSWxSDUjkolnOjo6DuV57KaYe4IDWDg9uekOxF4FxyrD4TVEEVTYPRiWcLHxfT6TcjzqGUUeWZTZuHVOCWOM4XfFc0gaepCdOglvEpvnt+djJMfLvgEIUcYFU7f1fZ344k1Wdj5DUbjjPH+yNAqxICgHvo/DFbGV2QCyOK5Q6Ewo1G+KA7diZHD3UvbnKYijuFX2V+JK9ohBiEk4cyVG1r+2FZiTkCZVDy6vAY6cQINaQV8oa6olgZaGrKwtTtFUywXa8+YdVnVDN2pDjqrf8Af8bczR/4tLjAAAAABJRU5ErkJggg==\"}]}"},{"id":174,"title":"Roll the Dice!","description":"Description\r\nReturn two random integers between 1 and 6, inclusive, to simulate rolling 2 dice.\r\nExample\r\n   [x1,x2] = rollDice();\r\n   x1 = 5;\r\n   x2 = 2;","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 152.312px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407.5px 76.1562px; transform-origin: 407.5px 76.1562px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384.5px 10.5px; text-align: left; transform-origin: 384.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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eDescription\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: 384.5px 10.5px; text-align: left; transform-origin: 384.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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn two random integers between 1 and 6, inclusive, to simulate rolling 2 dice.\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: 384.5px 10.5px; text-align: left; transform-origin: 384.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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eExample\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3125px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404.5px 30.6562px; transform-origin: 404.5px 30.6562px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e   [x1,x2] = rollDice();\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e   x1 = 5;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e   x2 = 2;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [x1,x2] = rollDice()\r\n  x1 = 1;\r\n  x2 = 1;\r\nend","test_suite":"%%\r\nfiletext = fileread('rollDice.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp');\r\nassert(~illegal)\r\n\r\n%%\r\nx1 = zeros(1,6000);\r\nx2 = zeros(1,6000);\r\nfor ii = 1:6000\r\n    [x1(ii),x2(ii)] = rollDice();\r\nend\r\nnumCt = sum( bsxfun( @eq, x1, (1:6)' ), 2 ) + sum( bsxfun( @eq, x2, (1:6)' ), 2 );\r\nassert(all(round(numCt/200) == 10) \u0026\u0026 sum(numCt) == 12000)\r\n","published":true,"deleted":false,"likes_count":62,"comments_count":21,"created_by":134,"edited_by":427930,"edited_at":"2024-08-01T11:35:52.000Z","deleted_by":null,"deleted_at":null,"solvers_count":10718,"test_suite_updated_at":"2012-01-30T07:51:11.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-01-30T07:38:01.000Z","updated_at":"2026-04-05T17:21:21.000Z","published_at":"2024-08-01T11:35:52.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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eDescription\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn two random integers between 1 and 6, inclusive, to simulate rolling 2 dice.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\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[   [x1,x2] = rollDice();\\n   x1 = 5;\\n   x2 = 2;]]\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\"}]}"}],"no_progress_badge":{"id":53,"name":"Unknown","symbol":"unknown","description":"Partially completed groups","description_html":null,"image_location":"/images/responsive/supporting/matlabcentral/cody/badges/problem_groups_unknown_2.png","bonus":null,"players_count":0,"active":false,"created_by":null,"updated_by":null,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"created_at":"2018-01-10T23:20:29.000Z","updated_at":"2018-01-10T23:20:29.000Z","community_badge_id":null,"award_multiples":false}}