{"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":44634,"title":"Basic matrix operations using standard MATLAB commands","description":"Create the matrix:\r\n\r\n 1.0e+15 *\r\n\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0001    0.0010    0.0100    0.1000    1.0000\r\n\r\nFind the row vector of all column means\r\n\r\nHint: Use _logspace_ to create the matrix. Avoid looking at the test suite before writing a solution","description_html":"\u003cp\u003eCreate the matrix:\u003c/p\u003e\u003cpre\u003e 1.0e+15 *\u003c/pre\u003e\u003cpre\u003e    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0001    0.0010    0.0100    0.1000    1.0000\u003c/pre\u003e\u003cp\u003eFind the row vector of all column means\u003c/p\u003e\u003cp\u003eHint: Use \u003ci\u003elogspace\u003c/i\u003e to create the matrix. Avoid looking at the test suite before writing a solution\u003c/p\u003e","function_template":"function y = matrix_ls_means()\r\n  y = x;\r\nend","test_suite":"%%\r\ny_correct = mean([logspace(1,5,5);logspace(6,10,5);logspace(11,15,5)]);\r\nassert(isequal(matrix_ls_means(),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":"2018-05-09T05:37:01.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-05-09T05:32:41.000Z","updated_at":"2026-02-17T08:19:25.000Z","published_at":"2018-05-09T05:35: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\u003eCreate the matrix:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ 1.0e+15 *\\n\\n    0.0000    0.0000    0.0000    0.0000    0.0000\\n    0.0000    0.0000    0.0000    0.0000    0.0000\\n    0.0001    0.0010    0.0100    0.1000    1.0000]]\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\u003eFind the row vector of all column means\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\u003eHint: Use\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\u003elogspace\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e to create the matrix. Avoid looking at the test suite before writing a solution\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":44333,"title":"Vector indexing: lower than mean","description":"Find indices of values in a vector lower than the mean of the vector","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: 211px 8px; transform-origin: 211px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFind indices of values in a vector lower than the mean of the vector\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  y = ...;\r\nend","test_suite":"%%\r\nx = [10     8    10     7     1];\r\ny_correct = [4 5];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 1:5;\r\ny_correct = [1 2];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":12852,"edited_by":223089,"edited_at":"2022-10-27T16:19:17.000Z","deleted_by":null,"deleted_at":null,"solvers_count":93,"test_suite_updated_at":"2022-10-10T12:52:57.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-09-14T17:47:39.000Z","updated_at":"2026-02-09T13:57:48.000Z","published_at":"2017-09-14T17:47:39.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\u003eFind indices of values in a vector lower than the mean of the vector\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":44301,"title":"Find the mean of two vectors","description":"Take two vectors, and output the mean of them (bonus if you don't use the in-built mean function)","description_html":"\u003cp\u003eTake two vectors, and output the mean of them (bonus if you don't use the in-built mean function)\u003c/p\u003e","function_template":"function out_mean = your_fcn_name(x,y)\r\n  out_mean = ...;\r\nend","test_suite":"%%\r\nx = [1 2 3 4 5];\r\ny = [6 7 8 9 10];\r\nout_mean = [3.5000    4.5000    5.5000    6.5000    7.5000];\r\nassert(isequal(your_fcn_name(x,y),out_mean))\r\n\r\n%%\r\nx = [1 1 2 3 5 8 13 21];\r\ny = ones(1,8);\r\nout_mean = [1 1 1.5 2 3 4.5 7 11];\r\nassert(isequal(your_fcn_name(x,y),out_mean))\r\n\r\n%%\r\nx = ones(1,100);\r\ny = 7*ones(1,100);\r\nout_mean = 4*ones(1,100);\r\nassert(isequal(your_fcn_name(x,y),out_mean))\r\n\r\n%%\r\nx = [5 3 8 1 6 7 9 4 2];\r\ny = [3 7 5 6 1 2 9 8 4];\r\nout_mean = [4 5 6.5 3.5 3.5 4.5 9 6 3];\r\nassert(isequal(your_fcn_name(x,y),out_mean))\r\n\r\n%%\r\nx = 5:-1:1;\r\ny = 1:5;\r\nout_mean = 3*ones(1,5);\r\nassert(isequal(your_fcn_name(x,y),out_mean))\r\n\r\n%%\r\nx = 42;\r\ny = -42;\r\nout_mean = 0;\r\nassert(isequal(your_fcn_name(x,y),out_mean))","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":12852,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":116,"test_suite_updated_at":"2017-09-08T19:42:49.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-09-06T01:16:44.000Z","updated_at":"2026-02-11T18:35:03.000Z","published_at":"2017-09-06T01:16:46.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\u003eTake two vectors, and output the mean of them (bonus if you don't use the in-built mean function)\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":42351,"title":"Average valid values of arrays","description":"Given a 1D array (column or row vector), compute the average of valid values. Valid values are defined via two thresholds: minValue and maxValue.\r\nExample:\r\n\r\n  x = [-1 -5.4 14.6 20.9 25.5 -22.4 18 15.5 -33.7 -38.1];\r\n  minValue = -10;\r\n  maxValue = 10;\r\n  y = validAverage(x, minValue, maxValue) = -3.2\r\n\r\nTo keep it simple, let's assume minValue and maxValue are within the array range.","description_html":"\u003cp\u003eGiven a 1D array (column or row vector), compute the average of valid values. Valid values are defined via two thresholds: minValue and maxValue.\r\nExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = [-1 -5.4 14.6 20.9 25.5 -22.4 18 15.5 -33.7 -38.1];\r\nminValue = -10;\r\nmaxValue = 10;\r\ny = validAverage(x, minValue, maxValue) = -3.2\r\n\u003c/pre\u003e\u003cp\u003eTo keep it simple, let's assume minValue and maxValue are within the array range.\u003c/p\u003e","function_template":"function y = validAverage(x, minV, maxV)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\nminV = -10;\r\nmaxV = 10;\r\ny_correct = 1;\r\nassert(isequal(round(validAverage(x,minV, maxV),4),y_correct))\r\n\r\n%%\r\nx = [-1 -5.4 14.6 20.9 25.5 -22.4 18 15.5 -33.7 -38.1];\r\nminV = -10;\r\nmaxV = 10;\r\ny_correct = -3.2;\r\nassert(isequal(round(validAverage(x,minV, maxV),4),y_correct))\r\n\r\n%%\r\nx=1:100;\r\nminV=20;\r\nmaxV=80;\r\ny_correct = 50;\r\nassert(isequal(round(validAverage(x,minV, maxV),4),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":44306,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":61,"test_suite_updated_at":"2015-06-01T21:37:45.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-06-01T21:16:24.000Z","updated_at":"2026-02-17T15:29:50.000Z","published_at":"2015-06-01T21:25: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\u003eGiven a 1D array (column or row vector), compute the average of valid values. Valid values are defined via two thresholds: minValue and maxValue. 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[x = [-1 -5.4 14.6 20.9 25.5 -22.4 18 15.5 -33.7 -38.1];\\nminValue = -10;\\nmaxValue = 10;\\ny = validAverage(x, minValue, maxValue) = -3.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\u003eTo keep it simple, let's assume minValue and maxValue are within the array range.\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":44639,"title":"Calculate mean value of any pair in a vector.","description":"Given a vector A, calculate the mean of 2 number in the vector one by one. \r\nexample:\r\ninput:\r\n   A=[1, 5, 6, 8, 9, 15]\r\noutput:\r\n   B=[3, 5.5, 7, 8.5, 12] \r\n\r\nexample:\r\ninput:\r\n   A=[4 5 21 6 2 1 6 63]\r\noutput:\r\n   B=[4.5, 13, 13.5, 4, 1.5, 3.5, 34.5] ","description_html":"\u003cp\u003eGiven a vector A, calculate the mean of 2 number in the vector one by one. \r\nexample:\r\ninput:\r\n   A=[1, 5, 6, 8, 9, 15]\r\noutput:\r\n   B=[3, 5.5, 7, 8.5, 12]\u003c/p\u003e\u003cp\u003eexample:\r\ninput:\r\n   A=[4 5 21 6 2 1 6 63]\r\noutput:\r\n   B=[4.5, 13, 13.5, 4, 1.5, 3.5, 34.5]\u003c/p\u003e","function_template":"function y = pair_mean(A)\r\n  y = A;\r\nend","test_suite":"%%\r\nx = [1, 5, 6, 8, 9, 15];\r\ny_correct = [3, 5.5, 7, 8.5, 12] ;\r\nassert(isequal(pair_mean(x),y_correct))\r\n%%\r\nx = [4 5 21 6 2 1 6 63];\r\ny_correct = [4.5, 13, 13.5, 4, 1.5, 3.5, 34.5] ;\r\nassert(isequal(pair_mean(x),y_correct))\r\n%%\r\nx = [1 1 1 0 0 1 0 1];\r\ny_correct = [1.0000    1.0000    0.5000     0    0.5000    0.5000    0.5000] ;\r\nassert(isequal(pair_mean(x),y_correct))\r\n%%\r\nx = [1 100 1000 10000];\r\ny_correct = [0.0505    0.5500    5.5000] *1000;\r\nassert(isequal(pair_mean(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":218677,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":60,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-05-17T15:37:38.000Z","updated_at":"2026-03-29T19:44:26.000Z","published_at":"2018-05-17T15:37:38.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eGiven a vector A, calculate the mean of 2 number in the vector one by one. example: input: A=[1, 5, 6, 8, 9, 15] output: B=[3, 5.5, 7, 8.5, 12]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eexample: input: A=[4 5 21 6 2 1 6 63] output: B=[4.5, 13, 13.5, 4, 1.5, 3.5, 34.5]\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":2235,"title":"Back to basics - mean of corner elements of a matrix","description":"Calculate the mean of corner elements of a matrix.\r\n\r\ne.g. a=[1 2 3;\r\n        4 5 6;\r\n        7 8 9;]\r\n\r\nMean = (1+3+7+9)/4 = 5","description_html":"\u003cp\u003eCalculate the mean of corner elements of a matrix.\u003c/p\u003e\u003cp\u003ee.g. a=[1 2 3;\r\n        4 5 6;\r\n        7 8 9;]\u003c/p\u003e\u003cp\u003eMean = (1+3+7+9)/4 = 5\u003c/p\u003e","function_template":"function y = MeanCorner(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2 3; 4 5 6; 7 8 9]\r\ny_correct = 5;\r\nassert(isequal(MeanCorner(x),y_correct))\r\n\r\n\r\n%%\r\nx = magic(4)\r\ny_correct = 8.5;\r\nassert(isequal(MeanCorner(x),y_correct))\r\n\r\n\r\n%%\r\nx = eye(4)\r\ny_correct = 0.5;\r\nassert(isequal(MeanCorner(x),y_correct))\r\n\r\n\r\n%%\r\nx = repmat(5, 4,4);\r\ny_correct = 5;\r\nassert(isequal(MeanCorner(x),y_correct))\r\n\r\n%%\r\nx = [1:10];\r\ny_correct = 5.5;\r\nassert(isequal(MeanCorner(x),y_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":462,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2014-03-04T20:59:30.000Z","updated_at":"2026-02-26T15:47:13.000Z","published_at":"2014-03-04T21:00:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eCalculate the mean of corner elements of a 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ee.g. a=[1 2 3; 4 5 6; 7 8 9;]\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\u003eMean = (1+3+7+9)/4 = 5\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":1216,"title":"Mean ignoring NaNs","description":"Define a function that behaves in the same way as mean(x) and mean(x,d) except that it ignores NaNs (unless all of the values being averaged are NaNs, in which case the result for those values should be NaN).","description_html":"\u003cp\u003eDefine a function that behaves in the same way as mean(x) and mean(x,d) except that it ignores NaNs (unless all of the values being averaged are NaNs, in which case the result for those values should be NaN).\u003c/p\u003e","function_template":"function y=average(x,d)\r\ny=0;\r\n","test_suite":"%%\r\nx=[1 5 9;2 6 10;3 nan 11;nan nan nan];\r\ny_correct=[2 5.5 10];\r\ny=average(x);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny=average(x,1);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=[5;6;7;nan];\r\ny=average(x,2);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=x;\r\ny=average(x,3);\r\nassert(isequalwithequalnans(y,y_correct))\r\n%%\r\nx=cat(3,[1 5 9;NaN 6 10;NaN 7 NaN;4 8 12],...\r\n [13 17 21;14 18 22;15 19 NaN;16 20 24]);\r\ny_correct=cat(3,[15 39 62]/6,[87 111 134]/6);\r\ny=average(x);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny=average(x,1);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=cat(3,[5;8;7;8],[17;18;17;20]);\r\ny=average(x,2);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=[7 11 15;14 12 16;15 13 NaN;10 14 18];\r\ny=average(x,3);\r\nassert(isequalwithequalnans(y,y_correct))\r\n%%\r\nx=zeros(2,1,0);\r\ny_correct=mean(x);\r\ny=average(x);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny=average(x,1);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=mean(x,2);\r\ny=average(x,2);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=mean(x,3);\r\ny=average(x,3);\r\nassert(isequalwithequalnans(y,y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":245,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":52,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-01-19T20:54:55.000Z","updated_at":"2026-03-05T14:17:40.000Z","published_at":"2013-01-19T21:44: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\",\"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\u003eDefine a function that behaves in the same way as mean(x) and mean(x,d) except that it ignores NaNs (unless all of the values being averaged are NaNs, in which case the result for those values should be NaN).\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":44279,"title":"Find the mean of a 2-D matrix after excluding elements of specified sub-matrix","description":"You need to find the mean of a 2-D matrix after excluding elements which form an inner sub-matrix. e.g. If the input 2-D matrix A is of size 6x6 and if we want to exclude the elements A(2,2), A(2,3), A(3,2), A(3,3), we just specify r1=1, r2=4, c1=1, c1=4. i.e. we want to exclude elements A(r1+1:r2-1, c1+1:c2-1). ","description_html":"\u003cp\u003eYou need to find the mean of a 2-D matrix after excluding elements which form an inner sub-matrix. e.g. If the input 2-D matrix A is of size 6x6 and if we want to exclude the elements A(2,2), A(2,3), A(3,2), A(3,3), we just specify r1=1, r2=4, c1=1, c1=4. i.e. we want to exclude elements A(r1+1:r2-1, c1+1:c2-1).\u003c/p\u003e","function_template":"function y = mean2d_excl(A,r1,r2,c1,c2)\r\n    y = 0;\r\nend","test_suite":"%%\r\nAx = [1 2 3 4 5 6; 11 12 13 14 15 16; 21 22 23 24 25 26; 31 32 33 34 35 36; 41 42 43 44 45 46; 51 52 53 54 55 56];\r\nr1x = 0; r2x = 4; c1x = 1; c2x = 4;\r\ny_correct = 31.7;\r\nassert(isequal(mean2d_excl(Ax,r1x,r2x,c1x,c2x),y_correct));\r\n\r\n%%\r\nAx = [1 2 3 4 5 6; 11 12 13 14 15 16; 21 22 23 24 25 26; 31 32 33 34 35 36; 41 42 43 44 45 46; 51 52 53 54 55 56];\r\nr1x = 1; r2x = 4; c1x = 1; c2x = 4;\r\ny_correct = 29.875;\r\nassert(isequal(mean2d_excl(Ax,r1x,r2x,c1x,c2x),y_correct));\r\n\r\n%%\r\nAx = [1 2 3 ; 12 13 14; 24 25 26];\r\nr1x = 1; r2x = 4; c1x = 1; c2x = 4;\r\ny_correct = 8.4;\r\nassert(isequal(mean2d_excl(Ax,r1x,r2x,c1x,c2x),y_correct));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":107204,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":33,"test_suite_updated_at":"2017-08-09T07:32:03.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-08-09T07:27:38.000Z","updated_at":"2026-03-11T08:38:00.000Z","published_at":"2017-08-09T07:32:03.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eYou need to find the mean of a 2-D matrix after excluding elements which form an inner sub-matrix. e.g. If the input 2-D matrix A is of size 6x6 and if we want to exclude the elements A(2,2), A(2,3), A(3,2), A(3,3), we just specify r1=1, r2=4, c1=1, c1=4. i.e. we want to exclude elements A(r1+1:r2-1, c1+1:c2-1).\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":44852,"title":"Mean number of letters per word (Easy)","description":"Given a character array, s, representing a sentence, return a, the arithmetic mean of the number of letters per word in the given sentence. Round your answer to three decimal digits.\r\n\r\nYou may make the following assumptions:\r\n\r\n1. All characters in the array are either letters or spaces.\r\n\r\n2. There are no redundant spaces.\r\n\r\n3. Except for spaces, there is no punctuation in the sentence.\r\n\r\n4. There will always be at least two words in the sentence.\r\n\r\nExample:\r\n\r\n  c = 'The quick brown fox jumps over the lazy dog';\r\n  \r\n  a = 3.889;\r\n\r\nExample:\r\n\r\n  c = 'Another one bites the dust';\r\n  \r\n  a = 4.400;\r\n\r\nThe next problem in this series is \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44853-mean-number-of-letters-per-word-hard Problem 44853\u003e.","description_html":"\u003cp\u003eGiven a character array, s, representing a sentence, return a, the arithmetic mean of the number of letters per word in the given sentence. Round your answer to three decimal digits.\u003c/p\u003e\u003cp\u003eYou may make the following assumptions:\u003c/p\u003e\u003cp\u003e1. All characters in the array are either letters or spaces.\u003c/p\u003e\u003cp\u003e2. There are no redundant spaces.\u003c/p\u003e\u003cp\u003e3. Except for spaces, there is no punctuation in the sentence.\u003c/p\u003e\u003cp\u003e4. There will always be at least two words in the sentence.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = 'The quick brown fox jumps over the lazy dog';\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ea = 3.889;\r\n\u003c/pre\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = 'Another one bites the dust';\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ea = 4.400;\r\n\u003c/pre\u003e\u003cp\u003eThe next problem in this series is \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44853-mean-number-of-letters-per-word-hard\"\u003eProblem 44853\u003c/a\u003e.\u003c/p\u003e","function_template":"function a = your_fcn_name(c)\r\n    a = 0;\r\nend","test_suite":"%%\r\nfiletext = fileread('your_fcn_name.m');\r\nassert(isempty(strfind(filetext,'eval')))\r\nassert(isempty(strfind(filetext,'echo')))\r\nassert(isempty(strfind(filetext,'switch')))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('Hello world'),5.000))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('The quick brown fox jumps over the lazy dog'),3.889))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('Another one bites the dust'),4.400))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('Antidisestablishmentarianism is the longest nonscientific word in the English language'),7.700))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('I ate pudding'),3.667))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('I hate pudding'),4.000))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":36,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":65,"created_at":"2019-02-16T20:34:25.000Z","updated_at":"2026-03-24T12:02:15.000Z","published_at":"2019-02-16T21:25:09.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 character array, s, representing a sentence, return a, the arithmetic mean of the number of letters per word in the given sentence. Round your answer to three decimal digits.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may make the following assumptions:\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. All characters in the array are either letters or spaces.\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\u003e2. There are no redundant spaces.\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\u003e3. Except for spaces, there is no punctuation in the sentence.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4. There will always be at least two words in the sentence.\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[c = 'The quick brown fox jumps over the lazy dog';\\n\\na = 3.889;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\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 = 'Another one bites the dust';\\n\\na = 4.400;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe next problem in this series is\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44853-mean-number-of-letters-per-word-hard\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44853\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":2234,"title":"Find and replace the zero array in a matrix","description":"Find the zero array in the matrix and replace it with average of surrounding (adjacent) arrays.\r\nExample:\r\nA =\r\n     3     5     7    90     1\r\n     5     1    -1     0     2\r\n     1     2     3     4    70\r\n    23     1     2     3     5\r\nOutput is:\r\nB=23.75;","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: 233.733px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 116.867px; transform-origin: 407px 116.867px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 293px 8px; transform-origin: 293px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFind the zero array in the matrix and replace it with average of surrounding (adjacent) arrays.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 28.5px 8px; transform-origin: 28.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 10.5px 8px; transform-origin: 10.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA =\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.7333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 40.8667px; transform-origin: 404px 40.8667px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 120px 8.5px; tab-size: 4; transform-origin: 120px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     3     5     7    90     1\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 120px 8.5px; tab-size: 4; transform-origin: 120px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     5     1    -1     0     2\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 120px 8.5px; tab-size: 4; transform-origin: 120px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     1     2     3     4    70\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 120px 8.5px; tab-size: 4; transform-origin: 120px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    23     1     2     3     5\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 30.5px 8px; transform-origin: 30.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eOutput is:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 28.5px 8px; transform-origin: 28.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eB=23.75;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function B = adjacent_averaging(A)\r\n  B = A;\r\nend","test_suite":"%%\r\nA=[3,5,7,90,1;5,1,-1,0,2;1,2,3,4,70;23,1,2,3,5];\r\nB= 23.75;\r\ntolerance = 1e-4 ; \r\nassert(abs(adjacent_averaging(A)-B)\u003ctolerance);\r\n%%\r\nA=[1,1,0,1,1;2,2,2,2,2;3,3,3,3,3;4,4,4,4,4];\r\nB= 1.3333;\r\ntolerance = 1e-4 ; \r\nassert(abs(adjacent_averaging(A)-B)\u003ctolerance);\r\n%%\r\nA=[3,3,3,90,2;5,3,-1,6,4;2,0,5,6,80;12,9,12,13,15];\r\nB= 4.75;\r\ntolerance = 1e-4 ; \r\nassert(abs(adjacent_averaging(A)-B)\u003ctolerance);\r\n%%\r\nA=magic(3);\r\nA(2,2)=0;\r\nB= 5;\r\ntolerance = 1e-4 ; \r\nassert(abs(adjacent_averaging(A)-B)\u003ctolerance);\r\n%%\r\nA=ones(5);\r\nA(2,3)=0;\r\nB= 1;\r\ntolerance = 1e-4 ; \r\nassert(abs(adjacent_averaging(A)-B)\u003ctolerance);\r\n%%\r\nx=randi(100);\r\nA=x*ones(6);\r\nA(3,4)=0;\r\nB= x;\r\ntolerance = 1e-4 ; \r\nassert(abs(adjacent_averaging(A)-B)\u003ctolerance);\r\n%%\r\nA=spiral(7);\r\nA(1,end)=0;\r\nB= 37;\r\ntolerance = 1e-4 ; \r\nassert(abs(adjacent_averaging(A)-B)\u003ctolerance);","published":true,"deleted":false,"likes_count":1,"comments_count":5,"created_by":9199,"edited_by":223089,"edited_at":"2023-01-07T08:27:44.000Z","deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":"2023-01-07T08:27:44.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-03-04T14:08:13.000Z","updated_at":"2025-12-02T08:24:31.000Z","published_at":"2014-03-04T14:08:25.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\u003eFind the zero array in the matrix and replace it with average of surrounding (adjacent) arrays.\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\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA =\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[     3     5     7    90     1\\n     5     1    -1     0     2\\n     1     2     3     4    70\\n    23     1     2     3     5]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eB=23.75;\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":147,"title":"Too mean-spirited","description":"Find the mean of each consecutive pair of numbers in the input row vector. For example,\r\n\r\nx=[1 2 3] ----\u003e y = [1.5 2.5]\r\n\r\nx=[100 0 0 0 100] ----\u003e y = [50 0 0 50]\r\n","description_html":"\u003cp\u003eFind the mean of each consecutive pair of numbers in the input row vector. For example,\u003c/p\u003e\u003cp\u003ex=[1 2 3] ----\u003e y = [1.5 2.5]\u003c/p\u003e\u003cp\u003ex=[100 0 0 0 100] ----\u003e y = [50 0 0 50]\u003c/p\u003e","function_template":"function y = two_mean(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2 3];\r\ny_correct = [1.5 2.5];\r\nassert(isequal(two_mean(x),y_correct))\r\n%%\r\nx = [10 0 0 0 100];\r\ny_correct = [5 0 0 50];\r\nassert(isequal(two_mean(x),y_correct))\r\n%%\r\nx = [1 2 4];\r\ny_correct = [1.5 3];\r\nassert(isequal(two_mean(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":0,"created_by":39,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1912,"test_suite_updated_at":"2014-07-30T18:54:13.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2012-01-28T16:50:21.000Z","updated_at":"2026-02-15T09:18:04.000Z","published_at":"2012-01-28T16:50:35.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\u003eFind the mean of each consecutive pair of numbers in the input row vector. For example,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex=[1 2 3] ----\u003e y = [1.5 2.5]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex=[100 0 0 0 100] ----\u003e y = [50 0 0 50]\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":56170,"title":"Dartboard Average I","description":"A dartboard arranges the numbers 1 to 20 such that each value is typically flanked by quite different values - for example, 20 is flanked by 1 and 5, 16 by 8 and 7, and so on.\r\nGiven a vector v representing the arrangement of the values 1 to 20, and a target value t, return the average of t and the two values on either side of it in the vector v. Note that a dartboard is circular, so the values in v are assumed to wrap.\r\nFor example, a standard dartboard is represented by\r\nv = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\r\nIf t = 6, your function should return mean([13 6 10]) = 9.6667.\r\nIf t = 20, it should return mean([5 20 1]) = 8.6667.\r\nThe vector v will always be a permutation of the values 1:20.","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: 246.933px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 123.467px; transform-origin: 407px 123.467px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA dartboard arranges the numbers 1 to 20 such that each value is typically flanked by quite different values - for example, 20 is flanked by 1 and 5, 16 by 8 and 7, and so on.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 43px; 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.5px; text-align: left; transform-origin: 384px 21.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: 48px 8px; transform-origin: 48px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a vector \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; \"\u003ev\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: 226.5px 8px; transform-origin: 226.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e representing the arrangement of the values 1 to 20, and a target value \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; \"\u003et\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: 73px 8px; transform-origin: 73px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, return the average 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: 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; \"\u003et\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: 16px 8px; transform-origin: 16px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and the two values on either side of it in the vector \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; \"\u003ev\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: 158.5px 8px; transform-origin: 158.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. Note that a dartboard is circular, so the values in \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; \"\u003ev\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: 70px 8px; transform-origin: 70px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e are assumed to wrap.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 167px 8px; transform-origin: 167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, a standard dartboard is represented by\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 228px 8.5px; tab-size: 4; transform-origin: 228px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ev = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.75px; text-align: left; transform-origin: 384px 10.75px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 5.5px 8px; transform-origin: 5.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf \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: 20px 8px; transform-origin: 20px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 20px 8.5px; transform-origin: 20px 8.5px; \"\u003et = 6\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: 91px 8px; transform-origin: 91px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, your function should return \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: 96px 8px; transform-origin: 96px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 96px 8.5px; transform-origin: 96px 8.5px; \"\u003emean([13 6 10]) = 9.6667\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\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: 5.5px 8px; transform-origin: 5.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf \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: 24px 8px; transform-origin: 24px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 24px 8.5px; transform-origin: 24px 8.5px; \"\u003et = 20\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: 53.5px 8px; transform-origin: 53.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, it should return \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: 92px 8px; transform-origin: 92px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 92px 8.5px; transform-origin: 92px 8.5px; \"\u003emean([5 20 1]) = 8.6667\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\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: 36px 8px; transform-origin: 36px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe vector \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; \"\u003ev\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: 150px 8px; transform-origin: 150px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e will always be a permutation of the values 1:20.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function m = avgdart(v,t)\r\n\r\nm = t;\r\n\r\nend","test_suite":"%% Standard dartboard with t = 5\r\nv = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\r\nassert( abs(avgdart(v,5) - 12.3333) \u003c 1e-3 )\r\n%% Standard dartboard with t = 9\r\nv = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\r\nassert( abs(avgdart(v,9) - 11.6667) \u003c 1e-3 )\r\n%% Standard dartboard with t = 18\r\nv = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\r\nassert( abs(avgdart(v,18) - 7.6667) \u003c 1e-3 )\r\n%% Standard dartboard with t = 6\r\nv = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\r\nassert( abs(avgdart(v,6) - 9.6667) \u003c 1e-3 )\r\n%% Standard dartboard with t = 14\r\nv = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\r\nassert( abs(avgdart(v,14) - 11.3333) \u003c 1e-3 )\r\n%% Random dartboard with t = 20\r\nv = [4 20 18 9 16 7 2 1 15 3 11 17 8 12 13 6 14 19 10 5];\r\nassert( abs(avgdart(v,20) - 14) \u003c 1e-3 )\r\n%% Random dartboard with t = 17\r\nv = [15 10 18 4 5 14 8 12 16 19 3 11 17 20 13 1 9 6 2 7];\r\nassert( abs(avgdart(v,17) - 16) \u003c 1e-3 )\r\n%% Random dartboard with t = 6\r\nv = [9 5 14 8 13 7 12 1 10 17 2 11 18 20 19 4 6 16 3 15];\r\nassert( abs(avgdart(v,6) - 8.6667) \u003c 1e-3 )\r\n%% Random dartboard with t = 8\r\nv = [4 18 20 8 2 11 17 5 16 15 10 12 7 6 19 3 14 13 9 1];\r\nassert( abs(avgdart(v,8) - 10) \u003c 1e-3 )\r\n%% Random dartboard with t = 1\r\nv = [17 3 20 16 9 10 6 5 13 1 7 12 18 8 4 19 2 15 14 11];\r\nassert( abs(avgdart(v,1) - 7) \u003c 1e-3 )\r\n%% Random dartboard with t = 4\r\nv = [4 18 8 10 13 17 9 3 11 1 2 12 5 19 16 15 14 7 6 20];\r\nassert( abs(avgdart(v,4) - 14) \u003c 1e-3 )\r\n%% Random dartboard with t = 8\r\nv = [12 8 1 20 16 6 7 15 3 14 11 18 9 17 19 10 5 4 2 13];\r\nassert( abs(avgdart(v,8) - 7) \u003c 1e-3 )\r\n%% Random dartboard with t = 10\r\nv = [5 20 1 12 19 4 3 7 8 13 15 11 10 6 16 2 9 18 14 17];\r\nassert( abs(avgdart(v,10) - 9) \u003c 1e-3 )\r\n%% Random dartboard with t = 20\r\nv = [1 4 10 5 19 6 17 9 2 15 13 20 12 16 8 7 18 11 14 3];\r\nassert( abs(avgdart(v,20) - 15) \u003c 1e-3 )\r\n%% Random dartboard with t = 19\r\nv = [5 13 19 3 4 7 16 8 15 6 2 11 1 10 17 14 20 12 9 18];\r\nassert( abs(avgdart(v,19) - 11.6667) \u003c 1e-3 )","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":287,"edited_by":287,"edited_at":"2022-10-24T13:10:42.000Z","deleted_by":null,"deleted_at":null,"solvers_count":174,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2022-09-30T17:43:10.000Z","updated_at":"2026-04-01T14:49:22.000Z","published_at":"2022-10-24T13:10:42.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\u003eA dartboard arranges the numbers 1 to 20 such that each value is typically flanked by quite different values - for example, 20 is flanked by 1 and 5, 16 by 8 and 7, and so on.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector \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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e representing the arrangement of the values 1 to 20, and a target value \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\u003et\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return the average of \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\u003et\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and the two values on either side of it in the vector \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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Note that a dartboard is circular, so the values in \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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are assumed to wrap.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, a standard dartboard is represented by\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[v = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf \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\u003et = 6\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, your function should return \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\u003emean([13 6 10]) = 9.6667\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf \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\u003et = 20\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, it should return \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\u003emean([5 20 1]) = 8.6667\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe vector \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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e will always be a permutation of the values 1:20.\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":56175,"title":"Dartboard Average II","description":"A dartboard arranges the numbers 1 to 20 such that each value is typically flanked by quite different values - for example, 20 is flanked by 1 and 5, 16 by 8 and 7, and so on.\r\nAssuming a player of questionable skill aiming for a particular value will hit that value or the value on either side with equal probability, what is the best and worst value to aim at? That is, what value has the highest and lowest average with the two values on either side?\r\nGiven a vector v representing the arrangement of the values 1 to 20, return the values with the maximum and minimum average with the values on either side. Note that a dartboard is circular, so the values in v are assumed to wrap.\r\nFor example, a standard dartboard is represented by\r\nv = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\r\nFor this v, your function should return 7 and 17 (in that order). The target value 7 has the highest average (mean([19 7 16]) = 14). Similarly, 17 has the lowest average (mean([2 17 3]) = 7.3333).\r\nIf there are multiple values with the highest or lowest average, your function should return the first of them. (For example, if v = [12  10  20  8  14  1  7...], both 10 and 8 have an average of 14. Your function should return 10 in this case.)\r\nThe vector v will always be a permutation of the values 1:20.","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: 382.433px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 191.217px; transform-origin: 407px 191.217px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA dartboard arranges the numbers 1 to 20 such that each value is typically flanked by quite different values - for example, 20 is flanked by 1 and 5, 16 by 8 and 7, and so on.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 63px; 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 31.5px; text-align: left; transform-origin: 384px 31.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: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAssuming a player of questionable skill aiming for a particular value will hit that value or the value on either side with equal probability, what is the best and worst value to aim at? That is, what value has the highest and lowest average with the two values on either side?\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 43px; 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.5px; text-align: left; transform-origin: 384px 21.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: 48px 8px; transform-origin: 48px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a vector \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; \"\u003ev\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: 323px 8px; transform-origin: 323px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e representing the arrangement of the values 1 to 20, return the values with the maximum and minimum average with the values on either side. Note that a dartboard is circular, so the values in \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; \"\u003ev\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: 70px 8px; transform-origin: 70px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e are assumed to wrap.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 167px 8px; transform-origin: 167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, a standard dartboard is represented by\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 228px 8.5px; tab-size: 4; transform-origin: 228px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ev = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 43px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 21.5px; text-align: left; transform-origin: 384px 21.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 26px 8px; transform-origin: 26px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor this \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; \"\u003ev\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: 309.5px 8px; transform-origin: 309.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, your function should return 7 and 17 (in that order). The target value 7 has the highest average (\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: 44px 8px; transform-origin: 44px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 44px 8.5px; transform-origin: 44px 8.5px; \"\u003emean([19 7 16]) = 14\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: 123.5px 8px; transform-origin: 123.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e). Similarly, 17 has the lowest average (\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: 92px 8px; transform-origin: 92px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 92px 8.5px; transform-origin: 92px 8.5px; \"\u003emean([2 17 3]) = 7.3333\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: 4.5px 8px; transform-origin: 4.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e).\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 63.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 31.75px; text-align: left; transform-origin: 384px 31.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: 381.5px 8px; transform-origin: 381.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf there are multiple values with the highest or lowest average, your function should return the first of them. (For example, if \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: 128px 8px; transform-origin: 128px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 128px 8.5px; transform-origin: 128px 8.5px; \"\u003ev = [12  10  20  8  14  1  7...]\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: 243.5px 8px; transform-origin: 243.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, both 10 and 8 have an average of 14. Your function should return 10 in this case.)\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: 36px 8px; transform-origin: 36px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe vector \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; \"\u003ev\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: 150px 8px; transform-origin: 150px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e will always be a permutation of the values 1:20.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [mx,mn] = bestworsttargets(v)\r\nmx = max(v);\r\nmn = min(v);\r\nend","test_suite":"%% Random dartboard #1\r\nv = [10 16 2 14 1 5 11 19 12 17 13 20 8 15 7 18 4 3 6 9];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 13) \u0026\u0026 (w == 3) )\r\n%% Random dartboard #2\r\nv = [4 20 1 11 7 6 14 5 3 19 10 9 15 8 2 16 12 13 18 17];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 18) \u0026\u0026 (w == 11) )\r\n%% Random dartboard #3\r\nv = [10 18 2 3 19 17 15 20 14 4 13 16 9 6 7 12 1 11 5 8];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 15) \u0026\u0026 (w == 11) )\r\n%% Random dartboard #4\r\nv = [11 16 1 9 13 14 15 19 17 20 2 12 6 8 5 4 3 7 18 10];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 17) \u0026\u0026 (w == 4) )\r\n%% Random dartboard #5\r\nv = [16 17 9 7 13 3 20 19 10 1 11 12 2 14 6 8 4 18 15 5];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 19) \u0026\u0026 (w == 8) )\r\n%% Random dartboard #6\r\nv = [19 5 4 13 17 6 11 10 7 18 8 14 16 2 20 1 15 9 3 12];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 8) \u0026\u0026 (w == 4) )\r\n%% Random dartboard #7\r\nv = [9 6 8 18 11 5 2 15 12 1 4 10 7 20 13 19 14 3 17 16];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 13) \u0026\u0026 (w == 4) )\r\n%% Random dartboard #8\r\nv = [7 17 12 6 20 10 13 5 18 8 11 2 9 14 3 4 16 19 15 1];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 19) \u0026\u0026 (w == 11) )\r\n%% Random dartboard #9\r\nv = [8 20 17 3 13 9 7 10 16 19 6 2 11 5 14 18 4 15 1 12];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 20) \u0026\u0026 (w == 11) )\r\n%% Random dartboard #10\r\nv = [5 6 12 3 18 17 9 19 15 10 16 2 8 14 13 11 1 4 20 7];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 9) \u0026\u0026 (w == 1) )\r\n%% Random dartboard #11\r\nv = [14 4 20 16 19 1 17 10 3 2 9 15 5 11 8 6 12 18 7 13];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 16) \u0026\u0026 (w == 2) )\r\n%% Random dartboard #12\r\nv = [15 9 20 2 13 18 14 3 7 17 1 12 10 8 11 6 19 4 16 5];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 18) \u0026\u0026 (w == 12) )\r\n%% Random dartboard #13\r\nv = [16 17 20 18 4 5 7 11 8 13 12 9 19 2 1 3 6 15 14 10];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 20) \u0026\u0026 (w == 1) )\r\n%% Random dartboard #14\r\nv = [17 12 3 9 15 18 20 13 10 19 14 11 8 7 16 2 4 5 6 1];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 18) \u0026\u0026 (w == 4) )\r\n%% Random dartboard #15\r\nv = [20 3 11 14 18 15 2 12 10 1 5 6 7 8 17 13 9 4 16 19];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 19) \u0026\u0026 (w == 5) )\r\n%% Random dartboard #16\r\nv = [13 4 12 8 15 10 11 9 3 2 5 1 14 17 20 6 16 18 19 7];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 18) \u0026\u0026 (w == 5) )\r\n%% Random dartboard #17\r\nv = [7 13 10 1 14 16 15 12 5 19 20 3 6 9 11 17 18 4 8 2];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 17) \u0026\u0026 (w == 8) )\r\n%% Random dartboard #18\r\nv = [14 13 15 7 19 9 18 17 6 4 10 1 3 12 11 20 16 5 8 2];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 20) \u0026\u0026 (w == 1) )\r\n%% Random dartboard #19\r\nv = [19 3 17 8 6 10 4 20 7 12 5 15 1 2 11 13 9 18 16 14];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 14) \u0026\u0026 (w == 2) )\r\n%% Random dartboard #20\r\nv = [19 1 12 17 4 3 5 7 8 18 13 10 15 14 6 9 2 16 11 20];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 20) \u0026\u0026 (w == 3) )","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":287,"edited_by":287,"edited_at":"2022-10-25T13:23:49.000Z","deleted_by":null,"deleted_at":null,"solvers_count":111,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2022-09-30T17:50:06.000Z","updated_at":"2026-04-01T14:51:31.000Z","published_at":"2022-10-24T13:11:57.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\u003eA dartboard arranges the numbers 1 to 20 such that each value is typically flanked by quite different values - for example, 20 is flanked by 1 and 5, 16 by 8 and 7, and so on.\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\u003eAssuming a player of questionable skill aiming for a particular value will hit that value or the value on either side with equal probability, what is the best and worst value to aim at? That is, what value has the highest and lowest average with the two values on either side?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector \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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e representing the arrangement of the values 1 to 20, return the values with the maximum and minimum average with the values on either side. Note that a dartboard is circular, so the values in \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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are assumed to wrap.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, a standard dartboard is represented by\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[v = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor this \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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, your function should return 7 and 17 (in that order). The target value 7 has the highest average (\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\u003emean([19 7 16]) = 14\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e). Similarly, 17 has the lowest average (\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\u003emean([2 17 3]) = 7.3333\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf there are multiple values with the highest or lowest average, your function should return the first of them. (For example, if \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\u003ev = [12  10  20  8  14  1  7...]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, both 10 and 8 have an average of 14. Your function should return 10 in this case.)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe vector \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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e will always be a permutation of the values 1:20.\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":44853,"title":"Mean number of letters per word (Hard)","description":"The previous problem in this series is \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44852-mean-number-of-letters-per-word-easy 44852\u003e.\r\n\r\nGiven a character array, s, representing a sentence, return a and g, the arithmetic and geometric means, respectively, of the number of letters per word in the given sentence. Round your answer to three decimal digits.\r\n\r\nYou may make the following assumptions:\r\n\r\n1. Not all characters in the array are either letters or spaces. There may also be numeric characters, as well as punctuation.\r\n\r\n2. There may be redundant spaces in the sentence.\r\n\r\n3. Punctuation does not count as a letter and cannot constitute a word in itself. Numbers also do not count as letters, but can constitute a word.\r\n\r\n4. There can be any number of characters and/or words in the sentence, including zero. When there are zero words in the sentence, return empty matrices for a and g.\r\n\r\nExample:\r\n\r\n  c = 'The quick brown fox jumps over the lazy dog';\r\n  \r\n  a = 3.889;\r\n  g = 3.792\r\n\r\nExample:\r\n\r\n  c = 'Another one bites the dust';\r\n  \r\n  a = 4.400;\r\n  g = 4.169","description_html":"\u003cp\u003eThe previous problem in this series is \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44852-mean-number-of-letters-per-word-easy\"\u003e44852\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven a character array, s, representing a sentence, return a and g, the arithmetic and geometric means, respectively, of the number of letters per word in the given sentence. Round your answer to three decimal digits.\u003c/p\u003e\u003cp\u003eYou may make the following assumptions:\u003c/p\u003e\u003cp\u003e1. Not all characters in the array are either letters or spaces. There may also be numeric characters, as well as punctuation.\u003c/p\u003e\u003cp\u003e2. There may be redundant spaces in the sentence.\u003c/p\u003e\u003cp\u003e3. Punctuation does not count as a letter and cannot constitute a word in itself. Numbers also do not count as letters, but can constitute a word.\u003c/p\u003e\u003cp\u003e4. There can be any number of characters and/or words in the sentence, including zero. When there are zero words in the sentence, return empty matrices for a and g.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = 'The quick brown fox jumps over the lazy dog';\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ea = 3.889;\r\ng = 3.792\r\n\u003c/pre\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = 'Another one bites the dust';\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ea = 4.400;\r\ng = 4.169\r\n\u003c/pre\u003e","function_template":"function [a,g] = your_fcn_name(c)\r\n    a = 0;\r\n    g = 0;\r\nend","test_suite":"%%\r\nfiletext = fileread('your_fcn_name.m');\r\nassert(isempty(strfind(filetext,'eval')))\r\nassert(isempty(strfind(filetext,'echo')))\r\nassert(isempty(strfind(filetext,'switch')))\r\n\r\n%%\r\n[a,g] = your_fcn_name('');\r\nassert(isempty(a))\r\nassert(isempty(g))\r\n\r\n%%\r\n[a,g] = your_fcn_name(' ');\r\nassert(isempty(a))\r\nassert(isempty(g))\r\n\r\n%%\r\n[a,g] = your_fcn_name(' ,\u0026 ');\r\nassert(isempty(a))\r\nassert(isempty(g))\r\n\r\n%%\r\n[a,g] = your_fcn_name([]);\r\nassert(isempty(a))\r\nassert(isempty(g))\r\n\r\n%%\r\n[a,g] = your_fcn_name('23');\r\nassert(isequal(a,0.000))\r\nassert(isequal(g,0.000))\r\n\r\n%%\r\n[a,g] = your_fcn_name(' The quick, brown fox jumps over the lazy dog.');\r\nassert(isequal(a,3.889))\r\nassert(isequal(g,3.792))\r\n\r\n%%\r\n[a,g] = your_fcn_name('...another 1 bites the dust...');\r\nassert(isequal(a,3.800))\r\nassert(isequal(g,0.000))\r\n\r\n%%\r\n[a,g] = your_fcn_name('Is ''antidisestablishmentarianism'' the longest (nonscientific) word in the English language ?');\r\nassert(isequal(a,7.700))\r\nassert(isequal(g,5.386))\r\n\r\n%%\r\n[a,g] = your_fcn_name('I ate pudding :-)');\r\nassert(isequal(a,3.667))\r\nassert(isequal(g,2.759))\r\n\r\n%%\r\n[a,g] = your_fcn_name('I hate pudding!');\r\nassert(isequal(a,4.000))\r\nassert(isequal(g,3.037))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":13,"test_suite_updated_at":"2019-02-16T21:25:35.000Z","rescore_all_solutions":false,"group_id":65,"created_at":"2019-02-16T21:17:39.000Z","updated_at":"2019-05-02T15:18:33.000Z","published_at":"2019-02-16T21:25:35.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 previous problem in this series is\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44852-mean-number-of-letters-per-word-easy\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e44852\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\u003eGiven a character array, s, representing a sentence, return a and g, the arithmetic and geometric means, respectively, of the number of letters per word in the given sentence. Round your answer to three decimal digits.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may make the following assumptions:\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. Not all characters in the array are either letters or spaces. There may also be numeric characters, as well as punctuation.\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\u003e2. There may be redundant spaces in the sentence.\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\u003e3. Punctuation does not count as a letter and cannot constitute a word in itself. Numbers also do not count as letters, but can constitute a word.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4. There can be any number of characters and/or words in the sentence, including zero. When there are zero words in the sentence, return empty matrices for a and g.\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[c = 'The quick brown fox jumps over the lazy dog';\\n\\na = 3.889;\\ng = 3.792]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\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 = 'Another one bites the dust';\\n\\na = 4.400;\\ng = 4.169]]\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":44779,"title":"Don't be mean.  Be nice!","description":"For this problem, you will be given a range of single digits R, and a separate number K.  You job is to calculate the mean of all K digit numbers that contain only distinct digits from the range R.\r\n\r\nFor example, if R=1:4 and K=2, you should calculate the mean of 12, 13, 14, 21, 23, 24, 31, 32, 34, 41, 42, and 43, as these are all of the two digit numbers that contain two distinct numbers from the range 1:4.  The numbers 11, 22, 33 and 44 are not included, as they contain multiple copies of the same digit.\r\n\r\nIf 0 is included in R, it should not be a leading digit for any of the numbers, so an R of 0:2 and K=3 would include:\r\n\r\n* 120\r\n* 210\r\n* 201\r\n* 102\r\n\r\nbut not 012 or 021 for the purposes of this calculation.\r\n\r\nYou can assume that R will always have at least K digits, and there will be no repeating digits in R.","description_html":"\u003cp\u003eFor this problem, you will be given a range of single digits R, and a separate number K.  You job is to calculate the mean of all K digit numbers that contain only distinct digits from the range R.\u003c/p\u003e\u003cp\u003eFor example, if R=1:4 and K=2, you should calculate the mean of 12, 13, 14, 21, 23, 24, 31, 32, 34, 41, 42, and 43, as these are all of the two digit numbers that contain two distinct numbers from the range 1:4.  The numbers 11, 22, 33 and 44 are not included, as they contain multiple copies of the same digit.\u003c/p\u003e\u003cp\u003eIf 0 is included in R, it should not be a leading digit for any of the numbers, so an R of 0:2 and K=3 would include:\u003c/p\u003e\u003cul\u003e\u003cli\u003e120\u003c/li\u003e\u003cli\u003e210\u003c/li\u003e\u003cli\u003e201\u003c/li\u003e\u003cli\u003e102\u003c/li\u003e\u003c/ul\u003e\u003cp\u003ebut not 012 or 021 for the purposes of this calculation.\u003c/p\u003e\u003cp\u003eYou can assume that R will always have at least K digits, and there will be no repeating digits in R.\u003c/p\u003e","function_template":"function y = dont_be_mean(R,k)\r\n  y = k.^R;\r\nend","test_suite":"%%\r\nR=1:4;k=2;y_correct = 27.5;\r\na=dont_be_mean(R,k)\r\nassert(abs(a-y_correct)\u003c1e-10)\r\n%%\r\nR=0:8;k=3;y_correct = 493.3125;\r\na=dont_be_mean(R,k)\r\nassert(abs(a-y_correct)\u003c1e-10)\r\n%%\r\nR=[1 2 4 6 8];k=4;y_correct = 4666.2;\r\na=dont_be_mean(R,k)\r\nassert(abs(a-y_correct)\u003c1e-10)\r\n%%\r\nR=[2 8 6 7 4 5];k=1;y_correct = 5.33333333333333;\r\na=dont_be_mean(R,k)\r\nassert(abs(a-y_correct)\u003c1e-10)\r\n%%\r\nR=0:9;\r\ny=0;\r\nfor k=1:8\r\n    y=y+dont_be_mean(R,k);\r\nend\r\ny_correct=61042519.44444444;\r\nassert(abs(y-y_correct)\u003c1e-3)\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":37,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":68,"created_at":"2018-11-07T18:32:08.000Z","updated_at":"2026-03-07T15:13:39.000Z","published_at":"2018-11-07T18:32:08.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor this problem, you will be given a range of single digits R, and a separate number K. You job is to calculate the mean of all K digit numbers that contain only distinct digits from the range R.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, if R=1:4 and K=2, you should calculate the mean of 12, 13, 14, 21, 23, 24, 31, 32, 34, 41, 42, and 43, as these are all of the two digit numbers that contain two distinct numbers from the range 1:4. The numbers 11, 22, 33 and 44 are not included, as they contain multiple copies of the same digit.\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 0 is included in R, it should not be a leading digit for any of the numbers, so an R of 0:2 and K=3 would include:\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\u003e120\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\u003e210\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\u003e201\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\u003e102\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\u003ebut not 012 or 021 for the purposes of this calculation.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou can assume that R will always have at least K digits, and there will be no repeating digits in R.\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":44676,"title":"Mean = Standard Deviation","description":"Create a series with following properties;\r\n\r\n# All of the members should be positive integer\r\n# Mean of the series should be integer\r\n# Standard deviation of the series should be integer (use a normalization factor of N instead of N-1)\r\n# Mean should be equal to standard deviation\r\n\r\nFor example if input is 6, you can return the following series;\r\n\r\n  out = [12 44 2 24 2 6]\r\n\r\n  mean(out) = 15;\r\n  std(out,1) = 15;\r\n  \r\nAnother example; if input is 4, a possible solution;\r\n\r\n  out = [24 2 2 48];\r\n  mean(out) = 19;\r\n  std(out,1) = 19;\r\n\r\n  ","description_html":"\u003cp\u003eCreate a series with following properties;\u003c/p\u003e\u003col\u003e\u003cli\u003eAll of the members should be positive integer\u003c/li\u003e\u003cli\u003eMean of the series should be integer\u003c/li\u003e\u003cli\u003eStandard deviation of the series should be integer (use a normalization factor of N instead of N-1)\u003c/li\u003e\u003cli\u003eMean should be equal to standard deviation\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eFor example if input is 6, you can return the following series;\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eout = [12 44 2 24 2 6]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003emean(out) = 15;\r\nstd(out,1) = 15;\r\n\u003c/pre\u003e\u003cp\u003eAnother example; if input is 4, a possible solution;\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eout = [24 2 2 48];\r\nmean(out) = 19;\r\nstd(out,1) = 19;\r\n\u003c/pre\u003e","function_template":"function y = meanEqualsStd(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nfor idx = 5:50\r\n    x = idx;\r\n    Series = meanEqualsStd(x);\r\n    mSeries = mean(Series);\r\n    sSeries = std(Series,1);\r\n    assert(length(Series)==x);\r\n    assert(round(mSeries)==mSeries);\r\n    assert(round(sSeries)==sSeries);\r\n    assert(all(round(Series) == Series));\r\n    assert(all(round(Series) \u003e= 1));\r\n    assert(mSeries == sSeries);\r\nend\r\n\r\n%%\r\nfiletext = fileread('meanEqualsStd.m');\r\nassert(isempty(strfind(filetext, 'echo')))\r\nassert(isempty(strfind(filetext, 'assert')))","published":true,"deleted":false,"likes_count":5,"comments_count":11,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":9,"test_suite_updated_at":"2018-06-14T07:03:27.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2018-06-07T01:30:24.000Z","updated_at":"2025-11-14T13:50:04.000Z","published_at":"2018-06-07T01:30:24.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\u003eCreate a series with following properties;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAll of the members should be positive integer\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMean of the series should be integer\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eStandard deviation of the series should be integer (use a normalization factor of N instead of N-1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMean should be equal to standard deviation\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example if input is 6, you can return the following 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[out = [12 44 2 24 2 6]\\n\\nmean(out) = 15;\\nstd(out,1) = 15;]]\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\u003eAnother example; if input is 4, a possible solution;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[out = [24 2 2 48];\\nmean(out) = 19;\\nstd(out,1) = 19;]]\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":1772,"title":"Stock Data NETFLIX 2011","description":"Analyze a set of data for Netflix's stock for 2011\r\n\r\nminNetflix =  Find the minimum value that the stock reached over the year. \r\n\r\nmaxNetflix =  Find the maximum value that the stock reached over the year.\r\n\r\nmeanNetflix =  What is the arithmetic mean of the stock price?\r\n\r\nstdNetflix = What is the standard deviation?\r\n\r\nplotNetflix = The plot of closing price vs day (1 to the number of closing prices you have)","description_html":"\u003cp\u003eAnalyze a set of data for Netflix's stock for 2011\u003c/p\u003e\u003cp\u003eminNetflix =  Find the minimum value that the stock reached over the year.\u003c/p\u003e\u003cp\u003emaxNetflix =  Find the maximum value that the stock reached over the year.\u003c/p\u003e\u003cp\u003emeanNetflix =  What is the arithmetic mean of the stock price?\u003c/p\u003e\u003cp\u003estdNetflix = What is the standard deviation?\u003c/p\u003e\u003cp\u003eplotNetflix = The plot of closing price vs day (1 to the number of closing prices you have)\u003c/p\u003e","function_template":"function [minNetflix maxNetflix stdNetflix meanNetflix plotNetflix histNetflix]= stockAnalysis\r\n      % First minimum value\r\n    minNetflix = \r\n\r\n    % Maximum\r\n    maxNetflix = \r\n\r\n    %Standard Deviation\r\n    stdNetflix = \r\n\r\n    % Arithmetic Mean\r\n    meanNetflix = \r\n\r\n    % Plot\r\n    plotNetflix = (plot command)\r\nend","test_suite":"[minNetflix maxNetflix stdNetflix meanNetflix plotNetflix]= stockAnalysis;\r\nurlwrite('http://nodejstesting.s3.amazonaws.com/stockAnalysisProtected.p', './stockAnalysisProtected.p');\r\naddpath('./');\r\nasserts = stockAnalysisProtected(minNetflix, maxNetflix, stdNetflix, meanNetflix, plotNetflix);\r\nassert(isequal(asserts, ones(1,length(asserts))));","published":true,"deleted":false,"likes_count":0,"comments_count":7,"created_by":15424,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":9,"test_suite_updated_at":"2013-08-02T20:28:25.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-08-02T19:28:09.000Z","updated_at":"2025-05-04T21:39:49.000Z","published_at":"2013-08-02T19:28:09.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\u003eAnalyze a set of data for Netflix's stock for 2011\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\u003eminNetflix = Find the minimum value that the stock reached over the year.\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\u003emaxNetflix = Find the maximum value that the stock reached over the year.\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\u003emeanNetflix = What is the arithmetic mean of the stock price?\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\u003estdNetflix = What is the standard deviation?\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\u003eplotNetflix = The plot of closing price vs day (1 to the number of closing prices you have)\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":44634,"title":"Basic matrix operations using standard MATLAB commands","description":"Create the matrix:\r\n\r\n 1.0e+15 *\r\n\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0001    0.0010    0.0100    0.1000    1.0000\r\n\r\nFind the row vector of all column means\r\n\r\nHint: Use _logspace_ to create the matrix. Avoid looking at the test suite before writing a solution","description_html":"\u003cp\u003eCreate the matrix:\u003c/p\u003e\u003cpre\u003e 1.0e+15 *\u003c/pre\u003e\u003cpre\u003e    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0001    0.0010    0.0100    0.1000    1.0000\u003c/pre\u003e\u003cp\u003eFind the row vector of all column means\u003c/p\u003e\u003cp\u003eHint: Use \u003ci\u003elogspace\u003c/i\u003e to create the matrix. Avoid looking at the test suite before writing a solution\u003c/p\u003e","function_template":"function y = matrix_ls_means()\r\n  y = x;\r\nend","test_suite":"%%\r\ny_correct = mean([logspace(1,5,5);logspace(6,10,5);logspace(11,15,5)]);\r\nassert(isequal(matrix_ls_means(),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":"2018-05-09T05:37:01.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-05-09T05:32:41.000Z","updated_at":"2026-02-17T08:19:25.000Z","published_at":"2018-05-09T05:35: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\u003eCreate the matrix:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ 1.0e+15 *\\n\\n    0.0000    0.0000    0.0000    0.0000    0.0000\\n    0.0000    0.0000    0.0000    0.0000    0.0000\\n    0.0001    0.0010    0.0100    0.1000    1.0000]]\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\u003eFind the row vector of all column means\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\u003eHint: Use\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\u003elogspace\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e to create the matrix. Avoid looking at the test suite before writing a solution\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":44333,"title":"Vector indexing: lower than mean","description":"Find indices of values in a vector lower than the mean of the vector","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: 211px 8px; transform-origin: 211px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFind indices of values in a vector lower than the mean of the vector\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  y = ...;\r\nend","test_suite":"%%\r\nx = [10     8    10     7     1];\r\ny_correct = [4 5];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 1:5;\r\ny_correct = [1 2];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":12852,"edited_by":223089,"edited_at":"2022-10-27T16:19:17.000Z","deleted_by":null,"deleted_at":null,"solvers_count":93,"test_suite_updated_at":"2022-10-10T12:52:57.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-09-14T17:47:39.000Z","updated_at":"2026-02-09T13:57:48.000Z","published_at":"2017-09-14T17:47:39.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\u003eFind indices of values in a vector lower than the mean of the vector\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":44301,"title":"Find the mean of two vectors","description":"Take two vectors, and output the mean of them (bonus if you don't use the in-built mean function)","description_html":"\u003cp\u003eTake two vectors, and output the mean of them (bonus if you don't use the in-built mean function)\u003c/p\u003e","function_template":"function out_mean = your_fcn_name(x,y)\r\n  out_mean = ...;\r\nend","test_suite":"%%\r\nx = [1 2 3 4 5];\r\ny = [6 7 8 9 10];\r\nout_mean = [3.5000    4.5000    5.5000    6.5000    7.5000];\r\nassert(isequal(your_fcn_name(x,y),out_mean))\r\n\r\n%%\r\nx = [1 1 2 3 5 8 13 21];\r\ny = ones(1,8);\r\nout_mean = [1 1 1.5 2 3 4.5 7 11];\r\nassert(isequal(your_fcn_name(x,y),out_mean))\r\n\r\n%%\r\nx = ones(1,100);\r\ny = 7*ones(1,100);\r\nout_mean = 4*ones(1,100);\r\nassert(isequal(your_fcn_name(x,y),out_mean))\r\n\r\n%%\r\nx = [5 3 8 1 6 7 9 4 2];\r\ny = [3 7 5 6 1 2 9 8 4];\r\nout_mean = [4 5 6.5 3.5 3.5 4.5 9 6 3];\r\nassert(isequal(your_fcn_name(x,y),out_mean))\r\n\r\n%%\r\nx = 5:-1:1;\r\ny = 1:5;\r\nout_mean = 3*ones(1,5);\r\nassert(isequal(your_fcn_name(x,y),out_mean))\r\n\r\n%%\r\nx = 42;\r\ny = -42;\r\nout_mean = 0;\r\nassert(isequal(your_fcn_name(x,y),out_mean))","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":12852,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":116,"test_suite_updated_at":"2017-09-08T19:42:49.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-09-06T01:16:44.000Z","updated_at":"2026-02-11T18:35:03.000Z","published_at":"2017-09-06T01:16:46.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\u003eTake two vectors, and output the mean of them (bonus if you don't use the in-built mean function)\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":42351,"title":"Average valid values of arrays","description":"Given a 1D array (column or row vector), compute the average of valid values. Valid values are defined via two thresholds: minValue and maxValue.\r\nExample:\r\n\r\n  x = [-1 -5.4 14.6 20.9 25.5 -22.4 18 15.5 -33.7 -38.1];\r\n  minValue = -10;\r\n  maxValue = 10;\r\n  y = validAverage(x, minValue, maxValue) = -3.2\r\n\r\nTo keep it simple, let's assume minValue and maxValue are within the array range.","description_html":"\u003cp\u003eGiven a 1D array (column or row vector), compute the average of valid values. Valid values are defined via two thresholds: minValue and maxValue.\r\nExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = [-1 -5.4 14.6 20.9 25.5 -22.4 18 15.5 -33.7 -38.1];\r\nminValue = -10;\r\nmaxValue = 10;\r\ny = validAverage(x, minValue, maxValue) = -3.2\r\n\u003c/pre\u003e\u003cp\u003eTo keep it simple, let's assume minValue and maxValue are within the array range.\u003c/p\u003e","function_template":"function y = validAverage(x, minV, maxV)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\nminV = -10;\r\nmaxV = 10;\r\ny_correct = 1;\r\nassert(isequal(round(validAverage(x,minV, maxV),4),y_correct))\r\n\r\n%%\r\nx = [-1 -5.4 14.6 20.9 25.5 -22.4 18 15.5 -33.7 -38.1];\r\nminV = -10;\r\nmaxV = 10;\r\ny_correct = -3.2;\r\nassert(isequal(round(validAverage(x,minV, maxV),4),y_correct))\r\n\r\n%%\r\nx=1:100;\r\nminV=20;\r\nmaxV=80;\r\ny_correct = 50;\r\nassert(isequal(round(validAverage(x,minV, maxV),4),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":44306,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":61,"test_suite_updated_at":"2015-06-01T21:37:45.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-06-01T21:16:24.000Z","updated_at":"2026-02-17T15:29:50.000Z","published_at":"2015-06-01T21:25: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\u003eGiven a 1D array (column or row vector), compute the average of valid values. Valid values are defined via two thresholds: minValue and maxValue. 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[x = [-1 -5.4 14.6 20.9 25.5 -22.4 18 15.5 -33.7 -38.1];\\nminValue = -10;\\nmaxValue = 10;\\ny = validAverage(x, minValue, maxValue) = -3.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\u003eTo keep it simple, let's assume minValue and maxValue are within the array range.\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":44639,"title":"Calculate mean value of any pair in a vector.","description":"Given a vector A, calculate the mean of 2 number in the vector one by one. \r\nexample:\r\ninput:\r\n   A=[1, 5, 6, 8, 9, 15]\r\noutput:\r\n   B=[3, 5.5, 7, 8.5, 12] \r\n\r\nexample:\r\ninput:\r\n   A=[4 5 21 6 2 1 6 63]\r\noutput:\r\n   B=[4.5, 13, 13.5, 4, 1.5, 3.5, 34.5] ","description_html":"\u003cp\u003eGiven a vector A, calculate the mean of 2 number in the vector one by one. \r\nexample:\r\ninput:\r\n   A=[1, 5, 6, 8, 9, 15]\r\noutput:\r\n   B=[3, 5.5, 7, 8.5, 12]\u003c/p\u003e\u003cp\u003eexample:\r\ninput:\r\n   A=[4 5 21 6 2 1 6 63]\r\noutput:\r\n   B=[4.5, 13, 13.5, 4, 1.5, 3.5, 34.5]\u003c/p\u003e","function_template":"function y = pair_mean(A)\r\n  y = A;\r\nend","test_suite":"%%\r\nx = [1, 5, 6, 8, 9, 15];\r\ny_correct = [3, 5.5, 7, 8.5, 12] ;\r\nassert(isequal(pair_mean(x),y_correct))\r\n%%\r\nx = [4 5 21 6 2 1 6 63];\r\ny_correct = [4.5, 13, 13.5, 4, 1.5, 3.5, 34.5] ;\r\nassert(isequal(pair_mean(x),y_correct))\r\n%%\r\nx = [1 1 1 0 0 1 0 1];\r\ny_correct = [1.0000    1.0000    0.5000     0    0.5000    0.5000    0.5000] ;\r\nassert(isequal(pair_mean(x),y_correct))\r\n%%\r\nx = [1 100 1000 10000];\r\ny_correct = [0.0505    0.5500    5.5000] *1000;\r\nassert(isequal(pair_mean(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":218677,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":60,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-05-17T15:37:38.000Z","updated_at":"2026-03-29T19:44:26.000Z","published_at":"2018-05-17T15:37:38.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eGiven a vector A, calculate the mean of 2 number in the vector one by one. example: input: A=[1, 5, 6, 8, 9, 15] output: B=[3, 5.5, 7, 8.5, 12]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eexample: input: A=[4 5 21 6 2 1 6 63] output: B=[4.5, 13, 13.5, 4, 1.5, 3.5, 34.5]\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":2235,"title":"Back to basics - mean of corner elements of a matrix","description":"Calculate the mean of corner elements of a matrix.\r\n\r\ne.g. a=[1 2 3;\r\n        4 5 6;\r\n        7 8 9;]\r\n\r\nMean = (1+3+7+9)/4 = 5","description_html":"\u003cp\u003eCalculate the mean of corner elements of a matrix.\u003c/p\u003e\u003cp\u003ee.g. a=[1 2 3;\r\n        4 5 6;\r\n        7 8 9;]\u003c/p\u003e\u003cp\u003eMean = (1+3+7+9)/4 = 5\u003c/p\u003e","function_template":"function y = MeanCorner(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2 3; 4 5 6; 7 8 9]\r\ny_correct = 5;\r\nassert(isequal(MeanCorner(x),y_correct))\r\n\r\n\r\n%%\r\nx = magic(4)\r\ny_correct = 8.5;\r\nassert(isequal(MeanCorner(x),y_correct))\r\n\r\n\r\n%%\r\nx = eye(4)\r\ny_correct = 0.5;\r\nassert(isequal(MeanCorner(x),y_correct))\r\n\r\n\r\n%%\r\nx = repmat(5, 4,4);\r\ny_correct = 5;\r\nassert(isequal(MeanCorner(x),y_correct))\r\n\r\n%%\r\nx = [1:10];\r\ny_correct = 5.5;\r\nassert(isequal(MeanCorner(x),y_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":462,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2014-03-04T20:59:30.000Z","updated_at":"2026-02-26T15:47:13.000Z","published_at":"2014-03-04T21:00:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eCalculate the mean of corner elements of a 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ee.g. a=[1 2 3; 4 5 6; 7 8 9;]\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\u003eMean = (1+3+7+9)/4 = 5\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":1216,"title":"Mean ignoring NaNs","description":"Define a function that behaves in the same way as mean(x) and mean(x,d) except that it ignores NaNs (unless all of the values being averaged are NaNs, in which case the result for those values should be NaN).","description_html":"\u003cp\u003eDefine a function that behaves in the same way as mean(x) and mean(x,d) except that it ignores NaNs (unless all of the values being averaged are NaNs, in which case the result for those values should be NaN).\u003c/p\u003e","function_template":"function y=average(x,d)\r\ny=0;\r\n","test_suite":"%%\r\nx=[1 5 9;2 6 10;3 nan 11;nan nan nan];\r\ny_correct=[2 5.5 10];\r\ny=average(x);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny=average(x,1);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=[5;6;7;nan];\r\ny=average(x,2);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=x;\r\ny=average(x,3);\r\nassert(isequalwithequalnans(y,y_correct))\r\n%%\r\nx=cat(3,[1 5 9;NaN 6 10;NaN 7 NaN;4 8 12],...\r\n [13 17 21;14 18 22;15 19 NaN;16 20 24]);\r\ny_correct=cat(3,[15 39 62]/6,[87 111 134]/6);\r\ny=average(x);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny=average(x,1);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=cat(3,[5;8;7;8],[17;18;17;20]);\r\ny=average(x,2);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=[7 11 15;14 12 16;15 13 NaN;10 14 18];\r\ny=average(x,3);\r\nassert(isequalwithequalnans(y,y_correct))\r\n%%\r\nx=zeros(2,1,0);\r\ny_correct=mean(x);\r\ny=average(x);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny=average(x,1);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=mean(x,2);\r\ny=average(x,2);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=mean(x,3);\r\ny=average(x,3);\r\nassert(isequalwithequalnans(y,y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":245,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":52,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-01-19T20:54:55.000Z","updated_at":"2026-03-05T14:17:40.000Z","published_at":"2013-01-19T21:44: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\",\"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\u003eDefine a function that behaves in the same way as mean(x) and mean(x,d) except that it ignores NaNs (unless all of the values being averaged are NaNs, in which case the result for those values should be NaN).\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":44279,"title":"Find the mean of a 2-D matrix after excluding elements of specified sub-matrix","description":"You need to find the mean of a 2-D matrix after excluding elements which form an inner sub-matrix. e.g. If the input 2-D matrix A is of size 6x6 and if we want to exclude the elements A(2,2), A(2,3), A(3,2), A(3,3), we just specify r1=1, r2=4, c1=1, c1=4. i.e. we want to exclude elements A(r1+1:r2-1, c1+1:c2-1). ","description_html":"\u003cp\u003eYou need to find the mean of a 2-D matrix after excluding elements which form an inner sub-matrix. e.g. If the input 2-D matrix A is of size 6x6 and if we want to exclude the elements A(2,2), A(2,3), A(3,2), A(3,3), we just specify r1=1, r2=4, c1=1, c1=4. i.e. we want to exclude elements A(r1+1:r2-1, c1+1:c2-1).\u003c/p\u003e","function_template":"function y = mean2d_excl(A,r1,r2,c1,c2)\r\n    y = 0;\r\nend","test_suite":"%%\r\nAx = [1 2 3 4 5 6; 11 12 13 14 15 16; 21 22 23 24 25 26; 31 32 33 34 35 36; 41 42 43 44 45 46; 51 52 53 54 55 56];\r\nr1x = 0; r2x = 4; c1x = 1; c2x = 4;\r\ny_correct = 31.7;\r\nassert(isequal(mean2d_excl(Ax,r1x,r2x,c1x,c2x),y_correct));\r\n\r\n%%\r\nAx = [1 2 3 4 5 6; 11 12 13 14 15 16; 21 22 23 24 25 26; 31 32 33 34 35 36; 41 42 43 44 45 46; 51 52 53 54 55 56];\r\nr1x = 1; r2x = 4; c1x = 1; c2x = 4;\r\ny_correct = 29.875;\r\nassert(isequal(mean2d_excl(Ax,r1x,r2x,c1x,c2x),y_correct));\r\n\r\n%%\r\nAx = [1 2 3 ; 12 13 14; 24 25 26];\r\nr1x = 1; r2x = 4; c1x = 1; c2x = 4;\r\ny_correct = 8.4;\r\nassert(isequal(mean2d_excl(Ax,r1x,r2x,c1x,c2x),y_correct));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":107204,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":33,"test_suite_updated_at":"2017-08-09T07:32:03.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-08-09T07:27:38.000Z","updated_at":"2026-03-11T08:38:00.000Z","published_at":"2017-08-09T07:32:03.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eYou need to find the mean of a 2-D matrix after excluding elements which form an inner sub-matrix. e.g. If the input 2-D matrix A is of size 6x6 and if we want to exclude the elements A(2,2), A(2,3), A(3,2), A(3,3), we just specify r1=1, r2=4, c1=1, c1=4. i.e. we want to exclude elements A(r1+1:r2-1, c1+1:c2-1).\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":44852,"title":"Mean number of letters per word (Easy)","description":"Given a character array, s, representing a sentence, return a, the arithmetic mean of the number of letters per word in the given sentence. Round your answer to three decimal digits.\r\n\r\nYou may make the following assumptions:\r\n\r\n1. All characters in the array are either letters or spaces.\r\n\r\n2. There are no redundant spaces.\r\n\r\n3. Except for spaces, there is no punctuation in the sentence.\r\n\r\n4. There will always be at least two words in the sentence.\r\n\r\nExample:\r\n\r\n  c = 'The quick brown fox jumps over the lazy dog';\r\n  \r\n  a = 3.889;\r\n\r\nExample:\r\n\r\n  c = 'Another one bites the dust';\r\n  \r\n  a = 4.400;\r\n\r\nThe next problem in this series is \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44853-mean-number-of-letters-per-word-hard Problem 44853\u003e.","description_html":"\u003cp\u003eGiven a character array, s, representing a sentence, return a, the arithmetic mean of the number of letters per word in the given sentence. Round your answer to three decimal digits.\u003c/p\u003e\u003cp\u003eYou may make the following assumptions:\u003c/p\u003e\u003cp\u003e1. All characters in the array are either letters or spaces.\u003c/p\u003e\u003cp\u003e2. There are no redundant spaces.\u003c/p\u003e\u003cp\u003e3. Except for spaces, there is no punctuation in the sentence.\u003c/p\u003e\u003cp\u003e4. There will always be at least two words in the sentence.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = 'The quick brown fox jumps over the lazy dog';\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ea = 3.889;\r\n\u003c/pre\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = 'Another one bites the dust';\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ea = 4.400;\r\n\u003c/pre\u003e\u003cp\u003eThe next problem in this series is \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44853-mean-number-of-letters-per-word-hard\"\u003eProblem 44853\u003c/a\u003e.\u003c/p\u003e","function_template":"function a = your_fcn_name(c)\r\n    a = 0;\r\nend","test_suite":"%%\r\nfiletext = fileread('your_fcn_name.m');\r\nassert(isempty(strfind(filetext,'eval')))\r\nassert(isempty(strfind(filetext,'echo')))\r\nassert(isempty(strfind(filetext,'switch')))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('Hello world'),5.000))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('The quick brown fox jumps over the lazy dog'),3.889))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('Another one bites the dust'),4.400))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('Antidisestablishmentarianism is the longest nonscientific word in the English language'),7.700))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('I ate pudding'),3.667))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('I hate pudding'),4.000))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":36,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":65,"created_at":"2019-02-16T20:34:25.000Z","updated_at":"2026-03-24T12:02:15.000Z","published_at":"2019-02-16T21:25:09.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 character array, s, representing a sentence, return a, the arithmetic mean of the number of letters per word in the given sentence. Round your answer to three decimal digits.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may make the following assumptions:\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. All characters in the array are either letters or spaces.\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\u003e2. There are no redundant spaces.\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\u003e3. Except for spaces, there is no punctuation in the sentence.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4. There will always be at least two words in the sentence.\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[c = 'The quick brown fox jumps over the lazy dog';\\n\\na = 3.889;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\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 = 'Another one bites the dust';\\n\\na = 4.400;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe next problem in this series is\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44853-mean-number-of-letters-per-word-hard\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44853\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":2234,"title":"Find and replace the zero array in a matrix","description":"Find the zero array in the matrix and replace it with average of surrounding (adjacent) arrays.\r\nExample:\r\nA =\r\n     3     5     7    90     1\r\n     5     1    -1     0     2\r\n     1     2     3     4    70\r\n    23     1     2     3     5\r\nOutput is:\r\nB=23.75;","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: 233.733px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 116.867px; transform-origin: 407px 116.867px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 293px 8px; transform-origin: 293px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFind the zero array in the matrix and replace it with average of surrounding (adjacent) arrays.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 28.5px 8px; transform-origin: 28.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 10.5px 8px; transform-origin: 10.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA =\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.7333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 40.8667px; transform-origin: 404px 40.8667px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 120px 8.5px; tab-size: 4; transform-origin: 120px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     3     5     7    90     1\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 120px 8.5px; tab-size: 4; transform-origin: 120px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     5     1    -1     0     2\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 120px 8.5px; tab-size: 4; transform-origin: 120px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     1     2     3     4    70\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 120px 8.5px; tab-size: 4; transform-origin: 120px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    23     1     2     3     5\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 30.5px 8px; transform-origin: 30.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eOutput is:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 28.5px 8px; transform-origin: 28.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eB=23.75;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function B = adjacent_averaging(A)\r\n  B = A;\r\nend","test_suite":"%%\r\nA=[3,5,7,90,1;5,1,-1,0,2;1,2,3,4,70;23,1,2,3,5];\r\nB= 23.75;\r\ntolerance = 1e-4 ; \r\nassert(abs(adjacent_averaging(A)-B)\u003ctolerance);\r\n%%\r\nA=[1,1,0,1,1;2,2,2,2,2;3,3,3,3,3;4,4,4,4,4];\r\nB= 1.3333;\r\ntolerance = 1e-4 ; \r\nassert(abs(adjacent_averaging(A)-B)\u003ctolerance);\r\n%%\r\nA=[3,3,3,90,2;5,3,-1,6,4;2,0,5,6,80;12,9,12,13,15];\r\nB= 4.75;\r\ntolerance = 1e-4 ; \r\nassert(abs(adjacent_averaging(A)-B)\u003ctolerance);\r\n%%\r\nA=magic(3);\r\nA(2,2)=0;\r\nB= 5;\r\ntolerance = 1e-4 ; \r\nassert(abs(adjacent_averaging(A)-B)\u003ctolerance);\r\n%%\r\nA=ones(5);\r\nA(2,3)=0;\r\nB= 1;\r\ntolerance = 1e-4 ; \r\nassert(abs(adjacent_averaging(A)-B)\u003ctolerance);\r\n%%\r\nx=randi(100);\r\nA=x*ones(6);\r\nA(3,4)=0;\r\nB= x;\r\ntolerance = 1e-4 ; \r\nassert(abs(adjacent_averaging(A)-B)\u003ctolerance);\r\n%%\r\nA=spiral(7);\r\nA(1,end)=0;\r\nB= 37;\r\ntolerance = 1e-4 ; \r\nassert(abs(adjacent_averaging(A)-B)\u003ctolerance);","published":true,"deleted":false,"likes_count":1,"comments_count":5,"created_by":9199,"edited_by":223089,"edited_at":"2023-01-07T08:27:44.000Z","deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":"2023-01-07T08:27:44.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-03-04T14:08:13.000Z","updated_at":"2025-12-02T08:24:31.000Z","published_at":"2014-03-04T14:08:25.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\u003eFind the zero array in the matrix and replace it with average of surrounding (adjacent) arrays.\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\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA =\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[     3     5     7    90     1\\n     5     1    -1     0     2\\n     1     2     3     4    70\\n    23     1     2     3     5]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eB=23.75;\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":147,"title":"Too mean-spirited","description":"Find the mean of each consecutive pair of numbers in the input row vector. For example,\r\n\r\nx=[1 2 3] ----\u003e y = [1.5 2.5]\r\n\r\nx=[100 0 0 0 100] ----\u003e y = [50 0 0 50]\r\n","description_html":"\u003cp\u003eFind the mean of each consecutive pair of numbers in the input row vector. For example,\u003c/p\u003e\u003cp\u003ex=[1 2 3] ----\u003e y = [1.5 2.5]\u003c/p\u003e\u003cp\u003ex=[100 0 0 0 100] ----\u003e y = [50 0 0 50]\u003c/p\u003e","function_template":"function y = two_mean(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2 3];\r\ny_correct = [1.5 2.5];\r\nassert(isequal(two_mean(x),y_correct))\r\n%%\r\nx = [10 0 0 0 100];\r\ny_correct = [5 0 0 50];\r\nassert(isequal(two_mean(x),y_correct))\r\n%%\r\nx = [1 2 4];\r\ny_correct = [1.5 3];\r\nassert(isequal(two_mean(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":0,"created_by":39,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1912,"test_suite_updated_at":"2014-07-30T18:54:13.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2012-01-28T16:50:21.000Z","updated_at":"2026-02-15T09:18:04.000Z","published_at":"2012-01-28T16:50:35.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\u003eFind the mean of each consecutive pair of numbers in the input row vector. For example,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex=[1 2 3] ----\u003e y = [1.5 2.5]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex=[100 0 0 0 100] ----\u003e y = [50 0 0 50]\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":56170,"title":"Dartboard Average I","description":"A dartboard arranges the numbers 1 to 20 such that each value is typically flanked by quite different values - for example, 20 is flanked by 1 and 5, 16 by 8 and 7, and so on.\r\nGiven a vector v representing the arrangement of the values 1 to 20, and a target value t, return the average of t and the two values on either side of it in the vector v. Note that a dartboard is circular, so the values in v are assumed to wrap.\r\nFor example, a standard dartboard is represented by\r\nv = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\r\nIf t = 6, your function should return mean([13 6 10]) = 9.6667.\r\nIf t = 20, it should return mean([5 20 1]) = 8.6667.\r\nThe vector v will always be a permutation of the values 1:20.","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: 246.933px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 123.467px; transform-origin: 407px 123.467px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA dartboard arranges the numbers 1 to 20 such that each value is typically flanked by quite different values - for example, 20 is flanked by 1 and 5, 16 by 8 and 7, and so on.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 43px; 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.5px; text-align: left; transform-origin: 384px 21.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: 48px 8px; transform-origin: 48px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a vector \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; \"\u003ev\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: 226.5px 8px; transform-origin: 226.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e representing the arrangement of the values 1 to 20, and a target value \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; \"\u003et\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: 73px 8px; transform-origin: 73px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, return the average 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: 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; \"\u003et\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: 16px 8px; transform-origin: 16px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and the two values on either side of it in the vector \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; \"\u003ev\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: 158.5px 8px; transform-origin: 158.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. Note that a dartboard is circular, so the values in \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; \"\u003ev\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: 70px 8px; transform-origin: 70px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e are assumed to wrap.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 167px 8px; transform-origin: 167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, a standard dartboard is represented by\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 228px 8.5px; tab-size: 4; transform-origin: 228px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ev = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.75px; text-align: left; transform-origin: 384px 10.75px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 5.5px 8px; transform-origin: 5.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf \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: 20px 8px; transform-origin: 20px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 20px 8.5px; transform-origin: 20px 8.5px; \"\u003et = 6\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: 91px 8px; transform-origin: 91px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, your function should return \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: 96px 8px; transform-origin: 96px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 96px 8.5px; transform-origin: 96px 8.5px; \"\u003emean([13 6 10]) = 9.6667\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\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: 5.5px 8px; transform-origin: 5.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf \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: 24px 8px; transform-origin: 24px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 24px 8.5px; transform-origin: 24px 8.5px; \"\u003et = 20\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: 53.5px 8px; transform-origin: 53.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, it should return \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: 92px 8px; transform-origin: 92px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 92px 8.5px; transform-origin: 92px 8.5px; \"\u003emean([5 20 1]) = 8.6667\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\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: 36px 8px; transform-origin: 36px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe vector \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; \"\u003ev\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: 150px 8px; transform-origin: 150px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e will always be a permutation of the values 1:20.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function m = avgdart(v,t)\r\n\r\nm = t;\r\n\r\nend","test_suite":"%% Standard dartboard with t = 5\r\nv = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\r\nassert( abs(avgdart(v,5) - 12.3333) \u003c 1e-3 )\r\n%% Standard dartboard with t = 9\r\nv = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\r\nassert( abs(avgdart(v,9) - 11.6667) \u003c 1e-3 )\r\n%% Standard dartboard with t = 18\r\nv = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\r\nassert( abs(avgdart(v,18) - 7.6667) \u003c 1e-3 )\r\n%% Standard dartboard with t = 6\r\nv = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\r\nassert( abs(avgdart(v,6) - 9.6667) \u003c 1e-3 )\r\n%% Standard dartboard with t = 14\r\nv = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\r\nassert( abs(avgdart(v,14) - 11.3333) \u003c 1e-3 )\r\n%% Random dartboard with t = 20\r\nv = [4 20 18 9 16 7 2 1 15 3 11 17 8 12 13 6 14 19 10 5];\r\nassert( abs(avgdart(v,20) - 14) \u003c 1e-3 )\r\n%% Random dartboard with t = 17\r\nv = [15 10 18 4 5 14 8 12 16 19 3 11 17 20 13 1 9 6 2 7];\r\nassert( abs(avgdart(v,17) - 16) \u003c 1e-3 )\r\n%% Random dartboard with t = 6\r\nv = [9 5 14 8 13 7 12 1 10 17 2 11 18 20 19 4 6 16 3 15];\r\nassert( abs(avgdart(v,6) - 8.6667) \u003c 1e-3 )\r\n%% Random dartboard with t = 8\r\nv = [4 18 20 8 2 11 17 5 16 15 10 12 7 6 19 3 14 13 9 1];\r\nassert( abs(avgdart(v,8) - 10) \u003c 1e-3 )\r\n%% Random dartboard with t = 1\r\nv = [17 3 20 16 9 10 6 5 13 1 7 12 18 8 4 19 2 15 14 11];\r\nassert( abs(avgdart(v,1) - 7) \u003c 1e-3 )\r\n%% Random dartboard with t = 4\r\nv = [4 18 8 10 13 17 9 3 11 1 2 12 5 19 16 15 14 7 6 20];\r\nassert( abs(avgdart(v,4) - 14) \u003c 1e-3 )\r\n%% Random dartboard with t = 8\r\nv = [12 8 1 20 16 6 7 15 3 14 11 18 9 17 19 10 5 4 2 13];\r\nassert( abs(avgdart(v,8) - 7) \u003c 1e-3 )\r\n%% Random dartboard with t = 10\r\nv = [5 20 1 12 19 4 3 7 8 13 15 11 10 6 16 2 9 18 14 17];\r\nassert( abs(avgdart(v,10) - 9) \u003c 1e-3 )\r\n%% Random dartboard with t = 20\r\nv = [1 4 10 5 19 6 17 9 2 15 13 20 12 16 8 7 18 11 14 3];\r\nassert( abs(avgdart(v,20) - 15) \u003c 1e-3 )\r\n%% Random dartboard with t = 19\r\nv = [5 13 19 3 4 7 16 8 15 6 2 11 1 10 17 14 20 12 9 18];\r\nassert( abs(avgdart(v,19) - 11.6667) \u003c 1e-3 )","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":287,"edited_by":287,"edited_at":"2022-10-24T13:10:42.000Z","deleted_by":null,"deleted_at":null,"solvers_count":174,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2022-09-30T17:43:10.000Z","updated_at":"2026-04-01T14:49:22.000Z","published_at":"2022-10-24T13:10:42.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\u003eA dartboard arranges the numbers 1 to 20 such that each value is typically flanked by quite different values - for example, 20 is flanked by 1 and 5, 16 by 8 and 7, and so on.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector \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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e representing the arrangement of the values 1 to 20, and a target value \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\u003et\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return the average of \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\u003et\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and the two values on either side of it in the vector \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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Note that a dartboard is circular, so the values in \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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are assumed to wrap.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, a standard dartboard is represented by\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[v = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf \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\u003et = 6\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, your function should return \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\u003emean([13 6 10]) = 9.6667\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf \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\u003et = 20\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, it should return \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\u003emean([5 20 1]) = 8.6667\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe vector \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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e will always be a permutation of the values 1:20.\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":56175,"title":"Dartboard Average II","description":"A dartboard arranges the numbers 1 to 20 such that each value is typically flanked by quite different values - for example, 20 is flanked by 1 and 5, 16 by 8 and 7, and so on.\r\nAssuming a player of questionable skill aiming for a particular value will hit that value or the value on either side with equal probability, what is the best and worst value to aim at? That is, what value has the highest and lowest average with the two values on either side?\r\nGiven a vector v representing the arrangement of the values 1 to 20, return the values with the maximum and minimum average with the values on either side. Note that a dartboard is circular, so the values in v are assumed to wrap.\r\nFor example, a standard dartboard is represented by\r\nv = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\r\nFor this v, your function should return 7 and 17 (in that order). The target value 7 has the highest average (mean([19 7 16]) = 14). Similarly, 17 has the lowest average (mean([2 17 3]) = 7.3333).\r\nIf there are multiple values with the highest or lowest average, your function should return the first of them. (For example, if v = [12  10  20  8  14  1  7...], both 10 and 8 have an average of 14. Your function should return 10 in this case.)\r\nThe vector v will always be a permutation of the values 1:20.","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: 382.433px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 191.217px; transform-origin: 407px 191.217px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA dartboard arranges the numbers 1 to 20 such that each value is typically flanked by quite different values - for example, 20 is flanked by 1 and 5, 16 by 8 and 7, and so on.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 63px; 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 31.5px; text-align: left; transform-origin: 384px 31.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: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAssuming a player of questionable skill aiming for a particular value will hit that value or the value on either side with equal probability, what is the best and worst value to aim at? That is, what value has the highest and lowest average with the two values on either side?\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 43px; 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.5px; text-align: left; transform-origin: 384px 21.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: 48px 8px; transform-origin: 48px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a vector \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; \"\u003ev\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: 323px 8px; transform-origin: 323px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e representing the arrangement of the values 1 to 20, return the values with the maximum and minimum average with the values on either side. Note that a dartboard is circular, so the values in \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; \"\u003ev\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: 70px 8px; transform-origin: 70px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e are assumed to wrap.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 167px 8px; transform-origin: 167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, a standard dartboard is represented by\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 228px 8.5px; tab-size: 4; transform-origin: 228px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ev = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 43px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 21.5px; text-align: left; transform-origin: 384px 21.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 26px 8px; transform-origin: 26px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor this \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; \"\u003ev\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: 309.5px 8px; transform-origin: 309.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, your function should return 7 and 17 (in that order). The target value 7 has the highest average (\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: 44px 8px; transform-origin: 44px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 44px 8.5px; transform-origin: 44px 8.5px; \"\u003emean([19 7 16]) = 14\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: 123.5px 8px; transform-origin: 123.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e). Similarly, 17 has the lowest average (\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: 92px 8px; transform-origin: 92px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 92px 8.5px; transform-origin: 92px 8.5px; \"\u003emean([2 17 3]) = 7.3333\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: 4.5px 8px; transform-origin: 4.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e).\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 63.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 31.75px; text-align: left; transform-origin: 384px 31.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: 381.5px 8px; transform-origin: 381.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf there are multiple values with the highest or lowest average, your function should return the first of them. (For example, if \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: 128px 8px; transform-origin: 128px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 128px 8.5px; transform-origin: 128px 8.5px; \"\u003ev = [12  10  20  8  14  1  7...]\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: 243.5px 8px; transform-origin: 243.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, both 10 and 8 have an average of 14. Your function should return 10 in this case.)\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: 36px 8px; transform-origin: 36px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe vector \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; \"\u003ev\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: 150px 8px; transform-origin: 150px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e will always be a permutation of the values 1:20.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [mx,mn] = bestworsttargets(v)\r\nmx = max(v);\r\nmn = min(v);\r\nend","test_suite":"%% Random dartboard #1\r\nv = [10 16 2 14 1 5 11 19 12 17 13 20 8 15 7 18 4 3 6 9];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 13) \u0026\u0026 (w == 3) )\r\n%% Random dartboard #2\r\nv = [4 20 1 11 7 6 14 5 3 19 10 9 15 8 2 16 12 13 18 17];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 18) \u0026\u0026 (w == 11) )\r\n%% Random dartboard #3\r\nv = [10 18 2 3 19 17 15 20 14 4 13 16 9 6 7 12 1 11 5 8];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 15) \u0026\u0026 (w == 11) )\r\n%% Random dartboard #4\r\nv = [11 16 1 9 13 14 15 19 17 20 2 12 6 8 5 4 3 7 18 10];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 17) \u0026\u0026 (w == 4) )\r\n%% Random dartboard #5\r\nv = [16 17 9 7 13 3 20 19 10 1 11 12 2 14 6 8 4 18 15 5];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 19) \u0026\u0026 (w == 8) )\r\n%% Random dartboard #6\r\nv = [19 5 4 13 17 6 11 10 7 18 8 14 16 2 20 1 15 9 3 12];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 8) \u0026\u0026 (w == 4) )\r\n%% Random dartboard #7\r\nv = [9 6 8 18 11 5 2 15 12 1 4 10 7 20 13 19 14 3 17 16];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 13) \u0026\u0026 (w == 4) )\r\n%% Random dartboard #8\r\nv = [7 17 12 6 20 10 13 5 18 8 11 2 9 14 3 4 16 19 15 1];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 19) \u0026\u0026 (w == 11) )\r\n%% Random dartboard #9\r\nv = [8 20 17 3 13 9 7 10 16 19 6 2 11 5 14 18 4 15 1 12];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 20) \u0026\u0026 (w == 11) )\r\n%% Random dartboard #10\r\nv = [5 6 12 3 18 17 9 19 15 10 16 2 8 14 13 11 1 4 20 7];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 9) \u0026\u0026 (w == 1) )\r\n%% Random dartboard #11\r\nv = [14 4 20 16 19 1 17 10 3 2 9 15 5 11 8 6 12 18 7 13];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 16) \u0026\u0026 (w == 2) )\r\n%% Random dartboard #12\r\nv = [15 9 20 2 13 18 14 3 7 17 1 12 10 8 11 6 19 4 16 5];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 18) \u0026\u0026 (w == 12) )\r\n%% Random dartboard #13\r\nv = [16 17 20 18 4 5 7 11 8 13 12 9 19 2 1 3 6 15 14 10];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 20) \u0026\u0026 (w == 1) )\r\n%% Random dartboard #14\r\nv = [17 12 3 9 15 18 20 13 10 19 14 11 8 7 16 2 4 5 6 1];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 18) \u0026\u0026 (w == 4) )\r\n%% Random dartboard #15\r\nv = [20 3 11 14 18 15 2 12 10 1 5 6 7 8 17 13 9 4 16 19];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 19) \u0026\u0026 (w == 5) )\r\n%% Random dartboard #16\r\nv = [13 4 12 8 15 10 11 9 3 2 5 1 14 17 20 6 16 18 19 7];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 18) \u0026\u0026 (w == 5) )\r\n%% Random dartboard #17\r\nv = [7 13 10 1 14 16 15 12 5 19 20 3 6 9 11 17 18 4 8 2];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 17) \u0026\u0026 (w == 8) )\r\n%% Random dartboard #18\r\nv = [14 13 15 7 19 9 18 17 6 4 10 1 3 12 11 20 16 5 8 2];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 20) \u0026\u0026 (w == 1) )\r\n%% Random dartboard #19\r\nv = [19 3 17 8 6 10 4 20 7 12 5 15 1 2 11 13 9 18 16 14];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 14) \u0026\u0026 (w == 2) )\r\n%% Random dartboard #20\r\nv = [19 1 12 17 4 3 5 7 8 18 13 10 15 14 6 9 2 16 11 20];\r\n[b,w] = bestworsttargets(v);\r\nassert( (b == 20) \u0026\u0026 (w == 3) )","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":287,"edited_by":287,"edited_at":"2022-10-25T13:23:49.000Z","deleted_by":null,"deleted_at":null,"solvers_count":111,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2022-09-30T17:50:06.000Z","updated_at":"2026-04-01T14:51:31.000Z","published_at":"2022-10-24T13:11:57.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\u003eA dartboard arranges the numbers 1 to 20 such that each value is typically flanked by quite different values - for example, 20 is flanked by 1 and 5, 16 by 8 and 7, and so on.\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\u003eAssuming a player of questionable skill aiming for a particular value will hit that value or the value on either side with equal probability, what is the best and worst value to aim at? That is, what value has the highest and lowest average with the two values on either side?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector \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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e representing the arrangement of the values 1 to 20, return the values with the maximum and minimum average with the values on either side. Note that a dartboard is circular, so the values in \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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are assumed to wrap.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, a standard dartboard is represented by\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[v = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor this \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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, your function should return 7 and 17 (in that order). The target value 7 has the highest average (\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\u003emean([19 7 16]) = 14\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e). Similarly, 17 has the lowest average (\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\u003emean([2 17 3]) = 7.3333\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf there are multiple values with the highest or lowest average, your function should return the first of them. (For example, if \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\u003ev = [12  10  20  8  14  1  7...]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, both 10 and 8 have an average of 14. Your function should return 10 in this case.)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe vector \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\u003ev\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e will always be a permutation of the values 1:20.\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":44853,"title":"Mean number of letters per word (Hard)","description":"The previous problem in this series is \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44852-mean-number-of-letters-per-word-easy 44852\u003e.\r\n\r\nGiven a character array, s, representing a sentence, return a and g, the arithmetic and geometric means, respectively, of the number of letters per word in the given sentence. Round your answer to three decimal digits.\r\n\r\nYou may make the following assumptions:\r\n\r\n1. Not all characters in the array are either letters or spaces. There may also be numeric characters, as well as punctuation.\r\n\r\n2. There may be redundant spaces in the sentence.\r\n\r\n3. Punctuation does not count as a letter and cannot constitute a word in itself. Numbers also do not count as letters, but can constitute a word.\r\n\r\n4. There can be any number of characters and/or words in the sentence, including zero. When there are zero words in the sentence, return empty matrices for a and g.\r\n\r\nExample:\r\n\r\n  c = 'The quick brown fox jumps over the lazy dog';\r\n  \r\n  a = 3.889;\r\n  g = 3.792\r\n\r\nExample:\r\n\r\n  c = 'Another one bites the dust';\r\n  \r\n  a = 4.400;\r\n  g = 4.169","description_html":"\u003cp\u003eThe previous problem in this series is \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44852-mean-number-of-letters-per-word-easy\"\u003e44852\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven a character array, s, representing a sentence, return a and g, the arithmetic and geometric means, respectively, of the number of letters per word in the given sentence. Round your answer to three decimal digits.\u003c/p\u003e\u003cp\u003eYou may make the following assumptions:\u003c/p\u003e\u003cp\u003e1. Not all characters in the array are either letters or spaces. There may also be numeric characters, as well as punctuation.\u003c/p\u003e\u003cp\u003e2. There may be redundant spaces in the sentence.\u003c/p\u003e\u003cp\u003e3. Punctuation does not count as a letter and cannot constitute a word in itself. Numbers also do not count as letters, but can constitute a word.\u003c/p\u003e\u003cp\u003e4. There can be any number of characters and/or words in the sentence, including zero. When there are zero words in the sentence, return empty matrices for a and g.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = 'The quick brown fox jumps over the lazy dog';\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ea = 3.889;\r\ng = 3.792\r\n\u003c/pre\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = 'Another one bites the dust';\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ea = 4.400;\r\ng = 4.169\r\n\u003c/pre\u003e","function_template":"function [a,g] = your_fcn_name(c)\r\n    a = 0;\r\n    g = 0;\r\nend","test_suite":"%%\r\nfiletext = fileread('your_fcn_name.m');\r\nassert(isempty(strfind(filetext,'eval')))\r\nassert(isempty(strfind(filetext,'echo')))\r\nassert(isempty(strfind(filetext,'switch')))\r\n\r\n%%\r\n[a,g] = your_fcn_name('');\r\nassert(isempty(a))\r\nassert(isempty(g))\r\n\r\n%%\r\n[a,g] = your_fcn_name(' ');\r\nassert(isempty(a))\r\nassert(isempty(g))\r\n\r\n%%\r\n[a,g] = your_fcn_name(' ,\u0026 ');\r\nassert(isempty(a))\r\nassert(isempty(g))\r\n\r\n%%\r\n[a,g] = your_fcn_name([]);\r\nassert(isempty(a))\r\nassert(isempty(g))\r\n\r\n%%\r\n[a,g] = your_fcn_name('23');\r\nassert(isequal(a,0.000))\r\nassert(isequal(g,0.000))\r\n\r\n%%\r\n[a,g] = your_fcn_name(' The quick, brown fox jumps over the lazy dog.');\r\nassert(isequal(a,3.889))\r\nassert(isequal(g,3.792))\r\n\r\n%%\r\n[a,g] = your_fcn_name('...another 1 bites the dust...');\r\nassert(isequal(a,3.800))\r\nassert(isequal(g,0.000))\r\n\r\n%%\r\n[a,g] = your_fcn_name('Is ''antidisestablishmentarianism'' the longest (nonscientific) word in the English language ?');\r\nassert(isequal(a,7.700))\r\nassert(isequal(g,5.386))\r\n\r\n%%\r\n[a,g] = your_fcn_name('I ate pudding :-)');\r\nassert(isequal(a,3.667))\r\nassert(isequal(g,2.759))\r\n\r\n%%\r\n[a,g] = your_fcn_name('I hate pudding!');\r\nassert(isequal(a,4.000))\r\nassert(isequal(g,3.037))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":13,"test_suite_updated_at":"2019-02-16T21:25:35.000Z","rescore_all_solutions":false,"group_id":65,"created_at":"2019-02-16T21:17:39.000Z","updated_at":"2019-05-02T15:18:33.000Z","published_at":"2019-02-16T21:25:35.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 previous problem in this series is\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44852-mean-number-of-letters-per-word-easy\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e44852\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\u003eGiven a character array, s, representing a sentence, return a and g, the arithmetic and geometric means, respectively, of the number of letters per word in the given sentence. Round your answer to three decimal digits.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may make the following assumptions:\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. Not all characters in the array are either letters or spaces. There may also be numeric characters, as well as punctuation.\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\u003e2. There may be redundant spaces in the sentence.\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\u003e3. Punctuation does not count as a letter and cannot constitute a word in itself. Numbers also do not count as letters, but can constitute a word.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4. There can be any number of characters and/or words in the sentence, including zero. When there are zero words in the sentence, return empty matrices for a and g.\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[c = 'The quick brown fox jumps over the lazy dog';\\n\\na = 3.889;\\ng = 3.792]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\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 = 'Another one bites the dust';\\n\\na = 4.400;\\ng = 4.169]]\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":44779,"title":"Don't be mean.  Be nice!","description":"For this problem, you will be given a range of single digits R, and a separate number K.  You job is to calculate the mean of all K digit numbers that contain only distinct digits from the range R.\r\n\r\nFor example, if R=1:4 and K=2, you should calculate the mean of 12, 13, 14, 21, 23, 24, 31, 32, 34, 41, 42, and 43, as these are all of the two digit numbers that contain two distinct numbers from the range 1:4.  The numbers 11, 22, 33 and 44 are not included, as they contain multiple copies of the same digit.\r\n\r\nIf 0 is included in R, it should not be a leading digit for any of the numbers, so an R of 0:2 and K=3 would include:\r\n\r\n* 120\r\n* 210\r\n* 201\r\n* 102\r\n\r\nbut not 012 or 021 for the purposes of this calculation.\r\n\r\nYou can assume that R will always have at least K digits, and there will be no repeating digits in R.","description_html":"\u003cp\u003eFor this problem, you will be given a range of single digits R, and a separate number K.  You job is to calculate the mean of all K digit numbers that contain only distinct digits from the range R.\u003c/p\u003e\u003cp\u003eFor example, if R=1:4 and K=2, you should calculate the mean of 12, 13, 14, 21, 23, 24, 31, 32, 34, 41, 42, and 43, as these are all of the two digit numbers that contain two distinct numbers from the range 1:4.  The numbers 11, 22, 33 and 44 are not included, as they contain multiple copies of the same digit.\u003c/p\u003e\u003cp\u003eIf 0 is included in R, it should not be a leading digit for any of the numbers, so an R of 0:2 and K=3 would include:\u003c/p\u003e\u003cul\u003e\u003cli\u003e120\u003c/li\u003e\u003cli\u003e210\u003c/li\u003e\u003cli\u003e201\u003c/li\u003e\u003cli\u003e102\u003c/li\u003e\u003c/ul\u003e\u003cp\u003ebut not 012 or 021 for the purposes of this calculation.\u003c/p\u003e\u003cp\u003eYou can assume that R will always have at least K digits, and there will be no repeating digits in R.\u003c/p\u003e","function_template":"function y = dont_be_mean(R,k)\r\n  y = k.^R;\r\nend","test_suite":"%%\r\nR=1:4;k=2;y_correct = 27.5;\r\na=dont_be_mean(R,k)\r\nassert(abs(a-y_correct)\u003c1e-10)\r\n%%\r\nR=0:8;k=3;y_correct = 493.3125;\r\na=dont_be_mean(R,k)\r\nassert(abs(a-y_correct)\u003c1e-10)\r\n%%\r\nR=[1 2 4 6 8];k=4;y_correct = 4666.2;\r\na=dont_be_mean(R,k)\r\nassert(abs(a-y_correct)\u003c1e-10)\r\n%%\r\nR=[2 8 6 7 4 5];k=1;y_correct = 5.33333333333333;\r\na=dont_be_mean(R,k)\r\nassert(abs(a-y_correct)\u003c1e-10)\r\n%%\r\nR=0:9;\r\ny=0;\r\nfor k=1:8\r\n    y=y+dont_be_mean(R,k);\r\nend\r\ny_correct=61042519.44444444;\r\nassert(abs(y-y_correct)\u003c1e-3)\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":37,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":68,"created_at":"2018-11-07T18:32:08.000Z","updated_at":"2026-03-07T15:13:39.000Z","published_at":"2018-11-07T18:32:08.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor this problem, you will be given a range of single digits R, and a separate number K. You job is to calculate the mean of all K digit numbers that contain only distinct digits from the range R.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, if R=1:4 and K=2, you should calculate the mean of 12, 13, 14, 21, 23, 24, 31, 32, 34, 41, 42, and 43, as these are all of the two digit numbers that contain two distinct numbers from the range 1:4. The numbers 11, 22, 33 and 44 are not included, as they contain multiple copies of the same digit.\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 0 is included in R, it should not be a leading digit for any of the numbers, so an R of 0:2 and K=3 would include:\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\u003e120\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\u003e210\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\u003e201\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\u003e102\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\u003ebut not 012 or 021 for the purposes of this calculation.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou can assume that R will always have at least K digits, and there will be no repeating digits in R.\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":44676,"title":"Mean = Standard Deviation","description":"Create a series with following properties;\r\n\r\n# All of the members should be positive integer\r\n# Mean of the series should be integer\r\n# Standard deviation of the series should be integer (use a normalization factor of N instead of N-1)\r\n# Mean should be equal to standard deviation\r\n\r\nFor example if input is 6, you can return the following series;\r\n\r\n  out = [12 44 2 24 2 6]\r\n\r\n  mean(out) = 15;\r\n  std(out,1) = 15;\r\n  \r\nAnother example; if input is 4, a possible solution;\r\n\r\n  out = [24 2 2 48];\r\n  mean(out) = 19;\r\n  std(out,1) = 19;\r\n\r\n  ","description_html":"\u003cp\u003eCreate a series with following properties;\u003c/p\u003e\u003col\u003e\u003cli\u003eAll of the members should be positive integer\u003c/li\u003e\u003cli\u003eMean of the series should be integer\u003c/li\u003e\u003cli\u003eStandard deviation of the series should be integer (use a normalization factor of N instead of N-1)\u003c/li\u003e\u003cli\u003eMean should be equal to standard deviation\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eFor example if input is 6, you can return the following series;\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eout = [12 44 2 24 2 6]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003emean(out) = 15;\r\nstd(out,1) = 15;\r\n\u003c/pre\u003e\u003cp\u003eAnother example; if input is 4, a possible solution;\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eout = [24 2 2 48];\r\nmean(out) = 19;\r\nstd(out,1) = 19;\r\n\u003c/pre\u003e","function_template":"function y = meanEqualsStd(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nfor idx = 5:50\r\n    x = idx;\r\n    Series = meanEqualsStd(x);\r\n    mSeries = mean(Series);\r\n    sSeries = std(Series,1);\r\n    assert(length(Series)==x);\r\n    assert(round(mSeries)==mSeries);\r\n    assert(round(sSeries)==sSeries);\r\n    assert(all(round(Series) == Series));\r\n    assert(all(round(Series) \u003e= 1));\r\n    assert(mSeries == sSeries);\r\nend\r\n\r\n%%\r\nfiletext = fileread('meanEqualsStd.m');\r\nassert(isempty(strfind(filetext, 'echo')))\r\nassert(isempty(strfind(filetext, 'assert')))","published":true,"deleted":false,"likes_count":5,"comments_count":11,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":9,"test_suite_updated_at":"2018-06-14T07:03:27.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2018-06-07T01:30:24.000Z","updated_at":"2025-11-14T13:50:04.000Z","published_at":"2018-06-07T01:30:24.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\u003eCreate a series with following properties;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAll of the members should be positive integer\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMean of the series should be integer\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eStandard deviation of the series should be integer (use a normalization factor of N instead of N-1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMean should be equal to standard deviation\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example if input is 6, you can return the following 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[out = [12 44 2 24 2 6]\\n\\nmean(out) = 15;\\nstd(out,1) = 15;]]\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\u003eAnother example; if input is 4, a possible solution;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[out = [24 2 2 48];\\nmean(out) = 19;\\nstd(out,1) = 19;]]\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":1772,"title":"Stock Data NETFLIX 2011","description":"Analyze a set of data for Netflix's stock for 2011\r\n\r\nminNetflix =  Find the minimum value that the stock reached over the year. \r\n\r\nmaxNetflix =  Find the maximum value that the stock reached over the year.\r\n\r\nmeanNetflix =  What is the arithmetic mean of the stock price?\r\n\r\nstdNetflix = What is the standard deviation?\r\n\r\nplotNetflix = The plot of closing price vs day (1 to the number of closing prices you have)","description_html":"\u003cp\u003eAnalyze a set of data for Netflix's stock for 2011\u003c/p\u003e\u003cp\u003eminNetflix =  Find the minimum value that the stock reached over the year.\u003c/p\u003e\u003cp\u003emaxNetflix =  Find the maximum value that the stock reached over the year.\u003c/p\u003e\u003cp\u003emeanNetflix =  What is the arithmetic mean of the stock price?\u003c/p\u003e\u003cp\u003estdNetflix = What is the standard deviation?\u003c/p\u003e\u003cp\u003eplotNetflix = The plot of closing price vs day (1 to the number of closing prices you have)\u003c/p\u003e","function_template":"function [minNetflix maxNetflix stdNetflix meanNetflix plotNetflix histNetflix]= stockAnalysis\r\n      % First minimum value\r\n    minNetflix = \r\n\r\n    % Maximum\r\n    maxNetflix = \r\n\r\n    %Standard Deviation\r\n    stdNetflix = \r\n\r\n    % Arithmetic Mean\r\n    meanNetflix = \r\n\r\n    % Plot\r\n    plotNetflix = (plot command)\r\nend","test_suite":"[minNetflix maxNetflix stdNetflix meanNetflix plotNetflix]= stockAnalysis;\r\nurlwrite('http://nodejstesting.s3.amazonaws.com/stockAnalysisProtected.p', './stockAnalysisProtected.p');\r\naddpath('./');\r\nasserts = stockAnalysisProtected(minNetflix, maxNetflix, stdNetflix, meanNetflix, plotNetflix);\r\nassert(isequal(asserts, ones(1,length(asserts))));","published":true,"deleted":false,"likes_count":0,"comments_count":7,"created_by":15424,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":9,"test_suite_updated_at":"2013-08-02T20:28:25.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-08-02T19:28:09.000Z","updated_at":"2025-05-04T21:39:49.000Z","published_at":"2013-08-02T19:28:09.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\u003eAnalyze a set of data for Netflix's stock for 2011\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\u003eminNetflix = Find the minimum value that the stock reached over the year.\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\u003emaxNetflix = Find the maximum value that the stock reached over the year.\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\u003emeanNetflix = What is the arithmetic mean of the stock price?\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\u003estdNetflix = What is the standard deviation?\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\u003eplotNetflix = The plot of closing price vs day (1 to the number of closing prices you have)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"tag:\"mean\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"mean\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"mean\"","","\"","mean","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f49e28d29e8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f49e28d2948\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f49e28d2088\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f49e28d2c68\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f49e28d2bc8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f49e28d2b28\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f49e28d2a88\u003e":"tag:\"mean\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f49e28d2a88\u003e":"tag:\"mean\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"mean\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"mean\"","","\"","mean","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f49e28d29e8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f49e28d2948\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f49e28d2088\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f49e28d2c68\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f49e28d2bc8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f49e28d2b28\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f49e28d2a88\u003e":"tag:\"mean\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f49e28d2a88\u003e":"tag:\"mean\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":44634,"difficulty_rating":"easy"},{"id":44333,"difficulty_rating":"easy"},{"id":44301,"difficulty_rating":"easy"},{"id":42351,"difficulty_rating":"easy"},{"id":44639,"difficulty_rating":"easy"},{"id":2235,"difficulty_rating":"easy"},{"id":1216,"difficulty_rating":"easy"},{"id":44279,"difficulty_rating":"easy"},{"id":44852,"difficulty_rating":"easy"},{"id":2234,"difficulty_rating":"easy-medium"},{"id":147,"difficulty_rating":"easy-medium"},{"id":56170,"difficulty_rating":"easy-medium"},{"id":56175,"difficulty_rating":"easy-medium"},{"id":44853,"difficulty_rating":"medium"},{"id":44779,"difficulty_rating":"medium"},{"id":44676,"difficulty_rating":"medium-hard"},{"id":1772,"difficulty_rating":"hard"}]}}