{"group":{"group":{"id":68,"name":"Probability \u0026 Stats","lockable":false,"created_at":"2020-01-09T13:32:53.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"It is probable that someone likes these problems.","is_default":false,"created_by":26769,"badge_id":62,"featured":false,"trending":false,"solution_count_in_trending_period":144,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":593,"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":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIt is probable that someone likes these problems.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}","description_html":"\u003cdiv style = \"text-align: start; line-height: normal; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"display: block; min-width: 0px; padding-top: 0px; perspective-origin: 289.5px 10.5px; transform-origin: 289.5px 10.5px; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; white-space: pre-wrap; perspective-origin: 266.5px 10.5px; transform-origin: 266.5px 10.5px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eIt is probable that someone likes these problems.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","published_at":"2020-01-16T15:30:19.000Z"},"current_player":null},"problems":[{"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":597,"title":"The Birthday Phenomenon","description":"First off, leap years are not being considered for this. In fact the year that people are born shouldn't be taken into consideration, for simplicity.\r\n\r\nThe basic question is given an input, a single integer representing the number of people in the room (X \u003e= 1).  Return the probability that 2 or more people share the same birthday.\r\n\r\nThe return from the function should be a value between 0 and 1, inclusive.  It should also be rounded out to the 10 thousandth decimal point (4 after the decimal point).  There should be no trailing zeros included.\r\n","description_html":"\u003cp\u003eFirst off, leap years are not being considered for this. In fact the year that people are born shouldn't be taken into consideration, for simplicity.\u003c/p\u003e\u003cp\u003eThe basic question is given an input, a single integer representing the number of people in the room (X \u0026gt;= 1).  Return the probability that 2 or more people share the same birthday.\u003c/p\u003e\u003cp\u003eThe return from the function should be a value between 0 and 1, inclusive.  It should also be rounded out to the 10 thousandth decimal point (4 after the decimal point).  There should be no trailing zeros included.\u003c/p\u003e","function_template":"function y = bday_phenom(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 0;\r\nassert(isequal(bday_phenom(x),y_correct))\r\n\r\n%%\r\nx = 2;\r\ny_correct = 0.0027;\r\nassert(isequal(bday_phenom(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = 0.0271;\r\nassert(isequal(bday_phenom(x),y_correct))\r\n\r\n%%\r\nx = 10;\r\ny_correct = 0.1169;\r\nassert(isequal(bday_phenom(x),y_correct))\r\n\r\n%%\r\nx = 20;\r\ny_correct = 0.4114;\r\nassert(isequal(bday_phenom(x),y_correct))\r\n\r\n%%\r\nx = 30;\r\ny_correct = 0.7063;\r\nassert(isequal(bday_phenom(x),y_correct))\r\n\r\n%%\r\nx = 50;\r\ny_correct = 0.9703;\r\nassert(isequal(bday_phenom(x),y_correct))\r\n\r\n%%\r\nx = 366;\r\ny_correct = 1;\r\nassert(isequal(bday_phenom(x),y_correct))\r\n\r\n%%\r\nx = 4873;\r\ny_correct = 1;\r\nassert(isequal(bday_phenom(x),y_correct))","published":true,"deleted":false,"likes_count":6,"comments_count":8,"created_by":3296,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":254,"test_suite_updated_at":"2012-04-20T15:35:29.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-18T19:30:11.000Z","updated_at":"2026-04-02T16:44:27.000Z","published_at":"2012-04-19T16:28:12.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\u003eFirst off, leap years are not being considered for this. In fact the year that people are born shouldn't be taken into consideration, for simplicity.\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 basic question is given an input, a single integer representing the number of people in the room (X \u0026gt;= 1). Return the probability that 2 or more people share the same birthday.\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 return from the function should be a value between 0 and 1, inclusive. It should also be rounded out to the 10 thousandth decimal point (4 after the decimal point). There should be no trailing zeros included.\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":1267,"title":"Calculate the probability that at least two people in a group share the same birthday.","description":"Calculate the probability that at least two people in a group share the same birthday. Given an integer input n, return to 0.015 (1.5%) precision the probability of this being the case. Assume that every day is equally probable as a birthday and ignore the leap year. \r\n\r\nExample:\r\n\r\n  Input: 1\r\n  Output: 0.00\r\n  \r\n  Input: 366\r\n  Output: 1.00","description_html":"\u003cp\u003eCalculate the probability that at least two people in a group share the same birthday. Given an integer input n, return to 0.015 (1.5%) precision the probability of this being the case. Assume that every day is equally probable as a birthday and ignore the leap year.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput: 1\r\nOutput: 0.00\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eInput: 366\r\nOutput: 1.00\r\n\u003c/pre\u003e","function_template":"function y = birthday_prob(n)\r\n  y = n;\r\nend","test_suite":"%%\r\nn = 1;\r\ny_correct = 0.00;\r\nassert(abs(birthday_prob(n)-y_correct) \u003c= 0.015)\r\n\r\n\r\n%%\r\nn = 366;\r\ny_correct = 1.00;\r\nassert(abs(birthday_prob(n)-y_correct) \u003c= 0.015)\r\n\r\n\r\n%%\r\nn = 0;\r\ny_correct = 0.00;\r\nassert(abs(birthday_prob(n)-y_correct) \u003c= 0.015)\r\n\r\n\r\n%%\r\nn = 23;\r\ny_correct = 0.5073;\r\nassert(abs(birthday_prob(n)-y_correct) \u003c= 0.015)\r\n\r\n%%\r\nn = 50;\r\ny_correct = 0.9704;\r\nassert(abs(birthday_prob(n)-y_correct) \u003c= 0.015)\r\n\r\n%%\r\nn = 100;\r\ny_correct = 1.0000;\r\nassert(abs(birthday_prob(n)-y_correct) \u003c= 0.015)\r\n\r\n%%\r\nn = 10\r\ny_correct = 0.1169;\r\nassert(abs(birthday_prob(n)-y_correct) \u003c= 0.015)\r\n\r\n%%\r\nn = 13\r\ny_correct = 0.1944;\r\nassert(abs(birthday_prob(n)-y_correct) \u003c= 0.015)\r\n\r\n\r\n%%\r\nn = 2;\r\ny_correct = 1/365;\r\nassert(abs(birthday_prob(n)-y_correct) \u003c= 0.015)\r\n\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":3,"created_by":10338,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":103,"test_suite_updated_at":"2013-02-13T03:38:16.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-02-13T03:31:33.000Z","updated_at":"2025-12-22T13:07:57.000Z","published_at":"2013-02-13T03:31:33.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCalculate the probability that at least two people in a group share the same birthday. Given an integer input n, return to 0.015 (1.5%) precision the probability of this being the case. Assume that every day is equally probable as a birthday and ignore the leap 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input: 1\\nOutput: 0.00\\n\\nInput: 366\\nOutput: 1.00]]\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":1272,"title":"The almost-birthday problem.","description":"This is a harder version of the birthday problem. Now, you will have to determine the probability that two or more people in a randomly assembled group of *n* people are having their birthdays within *d* days of each other. As usual, ignore the leap year and assume that every day is equally probable.","description_html":"\u003cp\u003eThis is a harder version of the birthday problem. Now, you will have to determine the probability that two or more people in a randomly assembled group of \u003cb\u003en\u003c/b\u003e people are having their birthdays within \u003cb\u003ed\u003c/b\u003e days of each other. As usual, ignore the leap year and assume that every day is equally probable.\u003c/p\u003e","function_template":"function p = almostBirthday(n,d)\r\n  p = 0.5;\r\nend","test_suite":"%%\r\nn = 10;\r\nd = 1;\r\ny_correct = 0.3147;\r\nassert(abs(almostBirthday(n,d)-y_correct) \u003c= 0.0001)\r\n\r\n%%\r\nn = 14;\r\nd = 1;\r\ny_correct = 0.5375;\r\nassert(abs(almostBirthday(n,d)-y_correct) \u003c= 0.0001)\r\n\r\n%%\r\nn = 20;\r\nd = 1;\r\ny_correct = 0.8045;\r\nassert(abs(almostBirthday(n,d)-y_correct) \u003c= 0.0001)\r\n\r\n%%\r\nn = 25;\r\nd = 1;\r\ny_correct = 0.9263;\r\nassert(abs(almostBirthday(n,d)-y_correct) \u003c= 0.0001)\r\n\r\n%%\r\nn = 30;\r\nd = 1;\r\ny_correct = 0.9782;\r\nassert(abs(almostBirthday(n,d)-y_correct) \u003c= 0.0001)\r\n\r\n%%\r\nn = 35;\r\nd = 1;\r\ny_correct = 0.9950;\r\nassert(abs(almostBirthday(n,d)-y_correct) \u003c= 0.0001)\r\n\r\n%%\r\nn = 10;\r\nd = 2;\r\ny_correct = 0.4721;\r\nassert(abs(almostBirthday(n,d)-y_correct) \u003c= 0.0001)\r\n\r\n%%\r\nn = 14;\r\nd = 2;\r\ny_correct = 0.7305;\r\nassert(abs(almostBirthday(n,d)-y_correct) \u003c= 0.0001)\r\n\r\n%%\r\nn = 20;\r\nd = 2;\r\ny_correct = 0.9393;\r\nassert(abs(almostBirthday(n,d)-y_correct) \u003c= 0.0001)\r\n\r\n%%\r\nn = 25;\r\nd = 2;\r\ny_correct = 0.9890;\r\nassert(abs(almostBirthday(n,d)-y_correct) \u003c= 0.0001)\r\n\r\n%%\r\nn = 30;\r\nd = 2;\r\ny_correct = 0.9987;\r\nassert(abs(almostBirthday(n,d)-y_correct) \u003c= 0.0001)\r\n\r\n%%\r\nn = 10;\r\nd = 3;\r\ny_correct = 0.5965;\r\nassert(abs(almostBirthday(n,d)-y_correct) \u003c= 0.0001)\r\n\r\n%%\r\nn = 14;\r\nd = 3;\r\ny_correct = 0.8466;\r\nassert(abs(almostBirthday(n,d)-y_correct) \u003c= 0.0001)\r\n\r\n%%\r\nn = 20;\r\nd = 3;\r\ny_correct = 0.9826;\r\nassert(abs(almostBirthday(n,d)-y_correct) \u003c= 0.0001)\r\n\r\n%%\r\nn = 25;\r\nd = 3;\r\ny_correct = 0.9986;\r\nassert(abs(almostBirthday(n,d)-y_correct) \u003c= 0.0001)","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":810,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":26,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-02-14T19:58:50.000Z","updated_at":"2025-12-10T23:49:03.000Z","published_at":"2013-02-14T20:16:17.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a harder version of the birthday problem. Now, you will have to determine the probability that two or more people in a randomly assembled group of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e people are having their birthdays within\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ed\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e days of each other. As usual, ignore the leap year and assume that every day is equally probable.\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":1159,"title":"Coin Tossing: Probability of Same Heads for N tosses","description":"A pair of physicists toss a coin n times each.\r\nWhat is the probability that they tossed the same number of heads?\r\nInput: N % number of tosses\r\nOutput: P\r\nExamples:\r\nN=1 P=0.5;\r\nN=2 P=0.375\r\nTest Suite will round to 6 places","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: 231px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 115.5px; transform-origin: 407px 115.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 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: 139px 8px; transform-origin: 139px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA pair of physicists toss a coin n times each.\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: 213px 8px; transform-origin: 213px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWhat is the probability that they tossed the same number of heads?\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: 20px 8px; transform-origin: 20px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eInput:\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: 71px 8px; transform-origin: 71px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e N % number of tosses\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: 26px 8px; transform-origin: 26px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eOutput:\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: 6.5px 8px; transform-origin: 6.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e P\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: 35.5px 8px; transform-origin: 35.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eExamples:\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: 35px 8px; transform-origin: 35px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eN=1 P=0.5;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 41px 8px; transform-origin: 41px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eN=2 P=0.375\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: 99px 8px; transform-origin: 99px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eTest Suite will round to 6 places\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function P = coin_head_match(N)\r\n  P = 0;\r\nend","test_suite":"%%\r\nassert(isequal(.5, round(1e6*coin_head_match(1))/1e6))\r\n%%\r\nassert(isequal(.375, round(1e6*coin_head_match(2))/1e6))\r\n%%\r\nassert(isequal(.3125, round(1e6*coin_head_match(3))/1e6))\r\n%%\r\nassert(isequal(.273438, round(1e6*coin_head_match(4))/1e6))\r\n%%\r\nassert(isequal(.246094, round(1e6*coin_head_match(5))/1e6))\r\n%%\r\nassert(isequal(.225586, round(1e6*coin_head_match(6))/1e6))\r\n%%\r\nassert(isequal(.139950, round(1e6*coin_head_match(16))/1e6))\r\n%%\r\nassert(isequal(.125371, round(1e6*coin_head_match(20))/1e6))\r\n%%\r\nassert(isequal(.114567, round(1e6*coin_head_match(24))/1e6))\r\n%%\r\nassert(~isequal(0,coin_head_match(0)))\r\n%%\r\nassert(isequal(.099347, round(1e6*coin_head_match(32))/1e6))\r\n%%\r\nassert(isequal(.070386, round(1e6*coin_head_match(64))/1e6))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":3097,"edited_by":223089,"edited_at":"2023-02-02T11:33:29.000Z","deleted_by":null,"deleted_at":null,"solvers_count":55,"test_suite_updated_at":"2023-02-02T11:33:29.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-01-01T19:48:56.000Z","updated_at":"2025-12-10T23:53:10.000Z","published_at":"2013-01-01T20:30:15.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 pair of physicists toss a coin n times each.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhat is the probability that they tossed the same number of heads?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e N % number of tosses\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e P\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExamples:\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\u003eN=1 P=0.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\u003eN=2 P=0.375\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\u003eTest Suite will round to 6 places\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":2591,"title":"Does the coin touch the line?","description":"If we throw a coin that has a diameter of d, its center will land in a grid n x m.\r\n\r\nWhat is the probability that the coin lands without touching the sides of the grid?\r\n","description_html":"\u003cp\u003eIf we throw a coin that has a diameter of d, its center will land in a grid n x m.\u003c/p\u003e\u003cp\u003eWhat is the probability that the coin lands without touching the sides of the grid?\u003c/p\u003e","function_template":"function y = your_fcn_name(d,n,m)\r\n  y = x;\r\nend","test_suite":"%%\r\nd = 1;\r\nn=2;\r\nm=2;\r\ny_correct = 0.25;\r\nassert(isequal(your_fcn_name(d,n,m),y_correct))\r\n%%\r\nd = 1;\r\nn=1;\r\nm=1;\r\ny_correct = 0;\r\nassert(isequal(your_fcn_name(d,n,m),y_correct))\r\n%%\r\nd = 1;\r\nn=3;\r\nm=4;\r\ny_correct = 0.5;\r\nassert(isequal(your_fcn_name(d,n,m),y_correct))\r\n%%\r\nd = 2;\r\nn=1;\r\nm=1;\r\ny_correct = 0;\r\nassert(isequal(your_fcn_name(d,n,m),y_correct))\r\n%%\r\nd = 0.5;\r\nn=2;\r\nm=3;\r\ny_correct = 0.625;\r\nassert(isequal(your_fcn_name(d,n,m),y_correct))\r\n%%\r\nd = 2;\r\nn=1;\r\nm=4;\r\ny_correct = 0;\r\nassert(isequal(your_fcn_name(d,n,m),y_correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":2,"created_by":28155,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":41,"test_suite_updated_at":"2014-10-30T14:32:17.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2014-09-16T12:30:17.000Z","updated_at":"2026-01-07T00:44:15.000Z","published_at":"2014-09-16T12:30:17.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eIf we throw a coin that has a diameter of d, its center will land in a grid n x m.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhat is the probability that the coin lands without touching the sides of the grid?\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":1240,"title":"Coin change combinations.","description":"Using only pennies (1), nickels (5), dimes (10), quarters (25), half dollars (50), and dollars (100), how many different combinations can be made from a given amount in cents.\r\n\r\nExample 1: \r\n\r\n\u003e\u003echange(17)\r\n\r\n%Output will be the the number of combinations of coins to make 17 cents.\r\n\r\nc =\r\n\r\n   6 \r\n\r\nThere are 6 combinations: \r\n\r\n17 pennies\r\n\r\n12 pennies and 1 nickel\r\n\r\n7 pennies and 2 nickels\r\n\r\n2 pennies and 3 nickels\r\n\r\n7 pennies and 1 dime\r\n\r\n2 pennies, 1 nickel, and 1 dime.\r\n\r\nExample 2:\r\n\r\n\u003e\u003echange(100)\r\n\r\nc =\r\n\r\n    293","description_html":"\u003cp\u003eUsing only pennies (1), nickels (5), dimes (10), quarters (25), half dollars (50), and dollars (100), how many different combinations can be made from a given amount in cents.\u003c/p\u003e\u003cp\u003eExample 1:\u003c/p\u003e\u003cp\u003e\u003e\u003echange(17)\u003c/p\u003e\u003cp\u003e%Output will be the the number of combinations of coins to make 17 cents.\u003c/p\u003e\u003cp\u003ec =\u003c/p\u003e\u003cpre\u003e   6 \u003c/pre\u003e\u003cp\u003eThere are 6 combinations:\u003c/p\u003e\u003cp\u003e17 pennies\u003c/p\u003e\u003cp\u003e12 pennies and 1 nickel\u003c/p\u003e\u003cp\u003e7 pennies and 2 nickels\u003c/p\u003e\u003cp\u003e2 pennies and 3 nickels\u003c/p\u003e\u003cp\u003e7 pennies and 1 dime\u003c/p\u003e\u003cp\u003e2 pennies, 1 nickel, and 1 dime.\u003c/p\u003e\u003cp\u003eExample 2:\u003c/p\u003e\u003cp\u003e\u003e\u003echange(100)\u003c/p\u003e\u003cp\u003ec =\u003c/p\u003e\u003cpre\u003e    293\u003c/pre\u003e","function_template":"function c = change(x)\r\n  c = x;\r\nend","test_suite":"%%\r\nx = 28;\r\ny_correct = 13;\r\nassert(isequal(change(x),y_correct));\r\n\r\n%%\r\nx = 62;\r\ny_correct = 77;\r\nassert(isequal(change(x),y_correct));\r\n\r\n%%\r\nx = 2;\r\ny_correct = 1;\r\nassert(isequal(change(x),y_correct));\r\n\r\n%%\r\nx = 87;\r\ny_correct = 187;\r\nassert(isequal(change(x),y_correct));","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":9887,"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-02-01T18:31:20.000Z","updated_at":"2025-12-02T22:15:40.000Z","published_at":"2013-02-01T18:35:57.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\u003eUsing only pennies (1), nickels (5), dimes (10), quarters (25), half dollars (50), and dollars (100), how many different combinations can be made from a given amount in cents.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 1:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\u0026gt;change(17)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e%Output will be the the number of combinations of coins to make 17 cents.\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\u003ec =\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[   6]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are 6 combinations:\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\u003e17 pennies\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\u003e12 pennies and 1 nickel\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\u003e7 pennies and 2 nickels\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 pennies and 3 nickels\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\u003e7 pennies and 1 dime\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 pennies, 1 nickel, and 1 dime.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 2:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\u0026gt;change(100)\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\u003ec =\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[    293]]\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":1268,"title":"Penny flipping - calculate winning probability (easy)","description":"Two players are playing a fair penny flipping game. For each flip, the winner adds one penny from the loser's collection to his/her collection. This continues until one player runs out of pennies and loses the game. \r\n\r\nCalculate the probability of winning for the first player, given the first player's number of coins, m, and the second player's number of coins, n.\r\n\r\nExample:\r\n\r\n  Input: m = 1, n =1\r\n  Output: 0.50","description_html":"\u003cp\u003eTwo players are playing a fair penny flipping game. For each flip, the winner adds one penny from the loser's collection to his/her collection. This continues until one player runs out of pennies and loses the game.\u003c/p\u003e\u003cp\u003eCalculate the probability of winning for the first player, given the first player's number of coins, m, and the second player's number of coins, n.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput: m = 1, n =1\r\nOutput: 0.50\r\n\u003c/pre\u003e","function_template":"function y = penny_flip(m, n)\r\n  y = m-n;\r\nend","test_suite":"%%\r\nm = 1;\r\nn = 1;\r\ny_correct = 0.50;\r\nassert(isequal(penny_flip(m, n),y_correct))\r\n\r\n%%\r\nm = 2;\r\nn = 2;\r\ny_correct = 0.50;\r\nassert(isequal(penny_flip(m, n),y_correct))\r\n\r\n%%\r\nm = 1e6;\r\nn = 1e6;\r\ny_correct = 0.50;\r\nassert(isequal(penny_flip(m, n),y_correct))\r\n\r\n%%\r\nm = 4;\r\nn = 2;\r\ny_correct = 2/3;\r\nassert(abs(penny_flip(m, n)-y_correct) \u003c= 0.01)\r\n\r\n%%\r\nm = 2;\r\nn = 4;\r\ny_correct = 1/3;\r\nassert(abs(penny_flip(m, n)-y_correct) \u003c= 0.01)\r\n\r\n%%\r\nm = 106;\r\nn = 47;\r\ny_correct = 0.6928;\r\nassert(abs(penny_flip(m, n)-y_correct) \u003c= 0.01)\r\n\r\n%%\r\nm = 3;\r\nn = 4;\r\ny_correct = 0.4286;\r\nassert(abs(penny_flip(m, n)-y_correct) \u003c= 0.01)\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":2,"created_by":10338,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":196,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-02-13T03:59:39.000Z","updated_at":"2026-02-25T10:33:14.000Z","published_at":"2013-02-13T03:59:39.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTwo players are playing a fair penny flipping game. For each flip, the winner adds one penny from the loser's collection to his/her collection. This continues until one player runs out of pennies and loses the game.\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\u003eCalculate the probability of winning for the first player, given the first player's number of coins, m, and the second player's number of coins, n.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input: m = 1, n =1\\nOutput: 0.50]]\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":1959,"title":"German tank problem","description":"The German tank problem is a well-known statistical problem that attempts to estimate the maximum of a discrete distribution from a limited number of samples (you may know it from some of its far reaching implications...)\r\nYou do not know how many tanks are in circulation (let's call this number N), but you know that they have been assigned serial numbers sequentially starting at 1 (ranging from 1 to N). You manage to observe a random subset of k tanks, and find that, among the observed tanks, the maximum serial number is n. Your job is to predict N, the total number of tanks in circulation, from this observation alone (from the values of k and n).\r\nExample:\r\nYou observe the serial number of 3 tanks, which are 36, 77, and 28. You know that there must be at least 77 tanks in circulation (although it seems unlikely that there were only 77). What is your best estimate of the total number of tanks in circulation?\r\nDetails:\r\nYour function takes the values n and k and must return your best estimate of the value of N.\r\nTo pass this problem you must be exactly correct in at least 10% of the testsuite cases.\r\nTest suite checks 10,000 cases, with N values ranging from 10 to 100, and k values ranging from 1 to 10.\r\nHints: (why my solution is not working? this formula is on wikipedia!!!)\r\nIn a typical scenario you may not really care about being \"exactly correct\" in at least 10% of all possible cases (i.e. with relatively high likelihood). This problem is intended to have you thinking about frequentist approaches, Bayesian, and maximum likelihood estimators","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: 459px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 229.5px; transform-origin: 407px 229.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 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: 12.5px 8px; transform-origin: 12.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eGerman tank problem\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 273px 8px; transform-origin: 273px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e is a well-known statistical problem that attempts to estimate the maximum of a discrete distribution from a limited number of samples (you may know it from some of its\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003efar reaching implications\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 8.5px 8px; transform-origin: 8.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e...)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 84px; 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 42px; text-align: left; transform-origin: 384px 42px; 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: 227px 8px; transform-origin: 227px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou do not know how many tanks are in circulation (let's call this number\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 5px 8px; transform-origin: 5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eN\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: 145.5px 8px; transform-origin: 145.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e), but you know that they have been assigned serial numbers sequentially starting at 1 (ranging from 1 to N). You manage to observe a random subset 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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ek\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: 37px 8px; transform-origin: 37px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e tanks, and find that, among the observed tanks, the maximum serial number is\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4.5px 8px; transform-origin: 4.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003en\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: 68.5px 8px; transform-origin: 68.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. Your job is to predict\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 5px 8px; transform-origin: 5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eN\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: 91.5px 8px; transform-origin: 91.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, the total number of tanks in circulation, from this observation alone (from the values 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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ek\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 14px 8px; transform-origin: 14px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4.5px 8px; transform-origin: 4.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003en\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: 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: 31.5px 8px; transform-origin: 31.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eExample:\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: 305px 8px; transform-origin: 305px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou observe the serial number of 3 tanks, which are 36, 77, and 28. You know that there must be\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 23px 8px; transform-origin: 23px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eat least\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: 38.5px 8px; transform-origin: 38.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e 77 tanks in circulation (although it seems unlikely that there were\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 13px 8px; transform-origin: 13px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eonly\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: 198px 8px; transform-origin: 198px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e 77). What is your best estimate of the total number of tanks in circulation?\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: 26px 8px; transform-origin: 26px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eDetails:\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: 95px 8px; transform-origin: 95px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYour function takes the values\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4.5px 8px; transform-origin: 4.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003en\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 14px 8px; transform-origin: 14px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ek\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: 159px 8px; transform-origin: 159px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and must return your best estimate of the value 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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 5px 8px; transform-origin: 5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eN\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: 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: 105.5px 8px; transform-origin: 105.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eTo pass this problem you must be\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 52px 8px; transform-origin: 52px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eexactly correct\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: 119.5px 8px; transform-origin: 119.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e in at least 10% of the testsuite cases.\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: 329.5px 8px; transform-origin: 329.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eTest suite checks 10,000 cases, with N values ranging from 10 to 100, and k values ranging from 1 to 10.\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: 20px 8px; transform-origin: 20px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eHints:\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: 199px 8px; transform-origin: 199px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e (why my solution is not working? this formula is on wikipedia!!!)\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: 374px 8px; transform-origin: 374px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIn a typical scenario you may not really care about being \"exactly correct\" in at least 10% of all possible cases (i.e. with relatively high likelihood). This problem is intended to have you thinking about frequentist approaches, Bayesian, and maximum likelihood estimators\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function N = tank_problem(k,m)\r\n% k: number of observations\r\n% m: maximum observed serial number\r\n% N: estimated number of tanks\r\n\r\nN=1;\r\nend","test_suite":"%%\r\n    Ntest=1e4;\r\n    N=randi([10,100],Ntest,1);\r\n    K=randi([1 10],Ntest,1);\r\n    M=arrayfun(@(N,K)max(randi(N,1,K)),N,K);\r\n    N_hat=arrayfun(@tank_problem,K,M);\r\n    rate=mean(N==N_hat);\r\n    assert(rate\u003e=.1,sprintf('hit rate too low (%0.2f)',rate*100));\r\n    fprintf('hit rate  = %0.2f\\n',rate*100);\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":1,"created_by":43,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":33,"test_suite_updated_at":"2022-01-15T07:59:10.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-10-25T21:34:05.000Z","updated_at":"2026-03-02T17:47:43.000Z","published_at":"2013-10-25T22:07:25.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGerman tank problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is a well-known statistical problem that attempts to estimate the maximum of a discrete distribution from a limited number of samples (you may know it from some of its\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efar reaching implications\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e...)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou do not know how many tanks are in circulation (let's call this number\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e), but you know that they have been assigned serial numbers sequentially starting at 1 (ranging from 1 to N). You manage to observe a random subset of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ek\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e tanks, and find that, among the observed tanks, the maximum serial number is\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Your job is to predict\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, the total number of tanks in circulation, from this observation alone (from the values of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ek\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou observe the serial number of 3 tanks, which are 36, 77, and 28. You know that there must be\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eat least\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 77 tanks in circulation (although it seems unlikely that there were\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\u003eonly\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 77). What is your best estimate of the total number of tanks in circulation?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eDetails:\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\u003eYour function takes the values\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ek\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and must return your best estimate of the value of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eTo pass this problem you must be\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eexactly correct\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in at least 10% of the testsuite cases.\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\u003eTest suite checks 10,000 cases, with N values ranging from 10 to 100, and k values ranging from 1 to 10.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eHints:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (why my solution is not working? this formula is on wikipedia!!!)\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\u003eIn a typical scenario you may not really care about being \\\"exactly correct\\\" in at least 10% of all possible cases (i.e. with relatively high likelihood). This problem is intended to have you thinking about frequentist approaches, Bayesian, and maximum likelihood estimators\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":1287,"title":"Unique dice configurations","description":"Given a number of dice N and the number of sides on each die S, write a MATLAB function that will output how many unique permutations you will get.\r\n\r\nFor example, unique_dice(2,6) will roll two six-sided dice, and should output 21.  Although there are 36 possible combinations for two six-sided dice, (1,2) and (2,1) are equivalent, so (1,2) only counts once.\r\n\r\nAssume that the dice are fair, and have an equal chance of rolling any number.  Good luck!","description_html":"\u003cp\u003eGiven a number of dice N and the number of sides on each die S, write a MATLAB function that will output how many unique permutations you will get.\u003c/p\u003e\u003cp\u003eFor example, unique_dice(2,6) will roll two six-sided dice, and should output 21.  Although there are 36 possible combinations for two six-sided dice, (1,2) and (2,1) are equivalent, so (1,2) only counts once.\u003c/p\u003e\u003cp\u003eAssume that the dice are fair, and have an equal chance of rolling any number.  Good luck!\u003c/p\u003e","function_template":"function configs=unique_dice(N,S)\r\n\r\n% Number of unique combinations of die rolls you get by\r\n% rolling number sided-side die.\r\n%\r\n% For example, unique_dice(2,6) should output 21, as there are\r\n% 21 unique configurations of the two six-sided dice.\r\n\r\nconfigs=42;\r\n\r\nend","test_suite":"%%\r\nassert(isequal(unique_dice(2,6),21))\r\n%%\r\nassert(isequal(unique_dice(6,8),1716))\r\n%%\r\nassert(isequal(unique_dice(10,12),352716))\r\n%%\r\nassert(isequal(unique_dice(20,20),68923264410))\r\n%%\r\nassert(isequal(unique_dice(4,100),4421275))\r\n%%\r\nassert(isequal(unique_dice(100,4),176851))\r\n%%\r\nx=ceil(10000*rand);\r\nassert(isequal(unique_dice(1,x),x))","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":31,"test_suite_updated_at":"2013-02-21T17:56:19.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-02-21T17:50:02.000Z","updated_at":"2026-03-17T21:31:50.000Z","published_at":"2013-02-21T17:56:19.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 number of dice N and the number of sides on each die S, write a MATLAB function that will output how many unique permutations you will get.\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, unique_dice(2,6) will roll two six-sided dice, and should output 21. Although there are 36 possible combinations for two six-sided dice, (1,2) and (2,1) are equivalent, so (1,2) only counts once.\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\u003eAssume that the dice are fair, and have an equal chance of rolling any number. Good luck!\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":44288,"title":"Throwing Dice - Will You Be Eaten By The Dragon?","description":"You and a dragon have agreed to let dice rolls determine whether it eats you or not.\r\nThe dragon will roll a single die, of x sides. You will roll several dice, of y sides each. The total number of sides on your dice add to x.\r\nThe dragon will let you go uneaten if your total throw matches or exceeds theirs.\r\nWhat are your chances of survival?","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: 132px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 66px; transform-origin: 407px 66px; 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: 263.5px 8px; transform-origin: 263.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou and a dragon have agreed to let dice rolls determine whether it eats you or not.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 373.5px 8px; transform-origin: 373.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe dragon will roll a single die, of x sides. You will roll several dice, of y sides each. The total number of sides on your dice add to x.\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: 251.5px 8px; transform-origin: 251.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe dragon will let you go uneaten if your total throw matches or exceeds theirs.\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: 111.5px 8px; transform-origin: 111.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWhat are your chances of survival?\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function p = survival(x,y)\r\n  p = x/y;\r\nend","test_suite":"%%\r\nx = 6;\r\ny = 3;\r\np_correct = 2/3;\r\nassert(abs(survival(x,y)-p_correct)\u003c1e-6)\r\n%%\r\nx = 15;\r\ny = 5;\r\np_correct = 3/5;\r\nassert(abs(survival(x,y)-p_correct)\u003c1e-6)\r\n%%\r\nx = 30;\r\ny = 6;\r\np_correct = 35/60;\r\nassert(abs(survival(x,y)-p_correct)\u003c1e-6)\r\n%%\r\nx = 21;\r\ny = 7;\r\np_correct = 4/7;\r\nassert(abs(survival(x,y)-p_correct)\u003c1e-6)\r\n%%\r\nx = 54;\r\ny = 9;\r\np_correct = 5/9;\r\nassert(abs(survival(x,y)-p_correct)\u003c1e-6)\r\n%%\r\nx = randi(100);\r\ny = 1;\r\nassert(abs(survival(x,y)-y)\u003c1e-6)\r\n%%\r\nx = randi([10 100],1,10);\r\ny = 5;\r\nout=arrayfun(@(a) survival(a,y), x);\r\nassert(isequal(unique(round(out,1)),0.6))\r\n","published":true,"deleted":false,"likes_count":11,"comments_count":13,"created_by":13840,"edited_by":223089,"edited_at":"2023-03-21T14:10:58.000Z","deleted_by":null,"deleted_at":null,"solvers_count":172,"test_suite_updated_at":"2023-03-21T14:10:58.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-08-24T09:19:28.000Z","updated_at":"2026-04-02T14:01:43.000Z","published_at":"2017-08-24T10:04:09.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\u003eYou and a dragon have agreed to let dice rolls determine whether it eats you or not.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe dragon will roll a single die, of x sides. You will roll several dice, of y sides each. The total number of sides on your dice add to x.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe dragon will let you go uneaten if your total throw matches or exceeds theirs.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhat are your chances of survival?\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":2770,"title":"Probability of Choosing a Red Ball","description":"Given two jars of red and blue balls, find the probability of choosing a red ball from Jar 1 after going through the steps. \r\n\r\n  Step 1: Choose a random ball from Jar 2 and add it to Jar 1\r\n\r\n  Step 2: Choose a random ball from Jar 1\r\n\r\n  Step 3: Calculate the probability of the final ball being red\r\n\r\n*Example:* \r\n\r\nGiven inputs for Jar 1 and Jar 2\r\n\r\nJar 1: (r1,b1) = (2,7)\r\n\r\nJar 2: (r2,b2) = (5,5)\r\n\r\nChoose a ball from Jar 2 and add it to Jar 1. \r\n  \r\n   _Note: Jar 1 could now have either 3 blue and 7 red or 2 blue and 8 red._ \r\n\r\nTaking into consideration both possibilities, the likelihood of the final ball being red is *0.25* . ","description_html":"\u003cp\u003eGiven two jars of red and blue balls, find the probability of choosing a red ball from Jar 1 after going through the steps.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eStep 1: Choose a random ball from Jar 2 and add it to Jar 1\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eStep 2: Choose a random ball from Jar 1\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eStep 3: Calculate the probability of the final ball being red\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eExample:\u003c/b\u003e\u003c/p\u003e\u003cp\u003eGiven inputs for Jar 1 and Jar 2\u003c/p\u003e\u003cp\u003eJar 1: (r1,b1) = (2,7)\u003c/p\u003e\u003cp\u003eJar 2: (r2,b2) = (5,5)\u003c/p\u003e\u003cp\u003eChoose a ball from Jar 2 and add it to Jar 1.\u003c/p\u003e\u003cpre\u003e   _Note: Jar 1 could now have either 3 blue and 7 red or 2 blue and 8 red._ \u003c/pre\u003e\u003cp\u003eTaking into consideration both possibilities, the likelihood of the final ball being red is \u003cb\u003e0.25\u003c/b\u003e .\u003c/p\u003e","function_template":"function prob = probRedBall(r1,b1,r2,b2)\r\n  prob = r1/(r1+b1);\r\nend","test_suite":"%%\r\nr1 = 2; b1 = 7; r2 = 5; b2 = 5; \r\nprob_correct = 0.2500;\r\nassert(isequal(probRedBall(r1,b1,r2,b2),prob_correct))\r\n\r\n%%\r\nr1 = 0; b1 = 5; r2 = 0; b2 = 5; \r\nprob_correct = 0.0000;\r\nassert(isequal(probRedBall(r1,b1,r2,b2),prob_correct))\r\n\r\n%%\r\nr1 = 0; b1 = 3; r2 = 1; b2 = 3; \r\nprob_correct = 0.0625;\r\nassert(isequal(probRedBall(r1,b1,r2,b2),prob_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":32736,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":66,"test_suite_updated_at":"2014-12-10T17:44:29.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2014-12-10T17:13:21.000Z","updated_at":"2026-03-05T15:56:58.000Z","published_at":"2014-12-10T17:35:42.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven two jars of red and blue balls, find the probability of choosing a red ball from Jar 1 after going through the steps.\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[Step 1: Choose a random ball from Jar 2 and add it to Jar 1\\n\\nStep 2: Choose a random ball from Jar 1\\n\\nStep 3: Calculate the probability of the final ball being red]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven inputs for Jar 1 and Jar 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eJar 1: (r1,b1) = (2,7)\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\u003eJar 2: (r2,b2) = (5,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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eChoose a ball from Jar 2 and add it to Jar 1.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   _Note: Jar 1 could now have either 3 blue and 7 red or 2 blue and 8 red._]]\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\u003eTaking into consideration both possibilities, the likelihood of the final ball being red is\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0.25\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e .\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"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":226,"title":"What are the odds?","description":"Two numbers, A and B are drawn randomly and uniformly on [-R,R].  What is the probability that A*B \u003c A+B.  Your function should take one variable, R, and return the probability to within 100*eps.  For example, if R = 1/2, then the probability should be:\r\n\r\n0.560930216216329 ","description_html":"\u003cp\u003eTwo numbers, A and B are drawn randomly and uniformly on [-R,R].  What is the probability that A*B \u0026lt; A+B.  Your function should take one variable, R, and return the probability to within 100*eps.  For example, if R = 1/2, then the probability should be:\u003c/p\u003e\u003cp\u003e0.560930216216329\u003c/p\u003e","function_template":"function y = prob_puzz(x)\r\n  y = 1 - rand;\r\nend","test_suite":"%%\r\nassert(abs(prob_puzz(1/3)-0.544569326033014)\u003c100*eps)\r\n%%\r\nassert(abs(prob_puzz(1)-0.596573590279973)\u003c100*eps)\r\n%%\r\nassert(abs(prob_puzz(2)-0.637326536083514)\u003c100*eps)\r\n%%\r\nHINT = fzero(@(x)((x.^2-1)*log(x+1)+(x.^2-1)*log(x-1)-x.^2)./(x.^3-x.^5),2);\r\nassert(abs(prob_puzz(HINT)-0.639232271380537)\u003c100*eps)\r\n%%\r\nassert(abs(prob_puzz(10)-0.522975599250673)\u003c100*eps)\r\n%%\r\nassert(abs(prob_puzz(flintmax)-0.5)\u003c100*eps)","published":true,"deleted":false,"likes_count":3,"comments_count":4,"created_by":459,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":28,"test_suite_updated_at":"2018-08-29T17:47:00.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-02-02T05:11:30.000Z","updated_at":"2025-08-19T10:43:43.000Z","published_at":"2012-02-02T05:11:30.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\u003eTwo numbers, A and B are drawn randomly and uniformly on [-R,R]. What is the probability that A*B \u0026lt; A+B. Your function should take one variable, R, and return the probability to within 100*eps. For example, if R = 1/2, then the probability should be:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e0.560930216216329\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":2356,"title":"Simulating the selection of a state with given probabilities","description":"Lets say we have 3 different states [1,2,3] with the probabilities of occurrences of each state is given as [0.5 0.2 0.3]. Which means 50% state 1 will be selected among others. Generate randomly selected states with the probabilities given\r\n\r\nOutput array will be consisting of state numbers based on the probabilities given as input. \r\n\r\nExample:\r\n(Quick tip: The higher simulation sampling sizes the more robust results)","description_html":"\u003cp\u003eLets say we have 3 different states [1,2,3] with the probabilities of occurrences of each state is given as [0.5 0.2 0.3]. Which means 50% state 1 will be selected among others. Generate randomly selected states with the probabilities given\u003c/p\u003e\u003cp\u003eOutput array will be consisting of state numbers based on the probabilities given as input.\u003c/p\u003e\u003cp\u003eExample:\r\n(Quick tip: The higher simulation sampling sizes the more robust results)\u003c/p\u003e","function_template":"function states = select_state(probs)\r\n  states = 0;\r\nend","test_suite":"%%\r\nprobs = rand;\r\nwhile sum(probs) \u003c 1\r\n    a = rand;\r\n    if a + sum(probs) \u003e 1\r\n        probs = [probs 1-sum(probs)];\r\n        break;\r\n    else\r\n        probs = [probs a];\r\n    end\r\nend\r\n\r\nstates = 1:length(probs);\r\nfor i = 1:100\r\n    y{i,1} = select_state(probs);\r\n    [nelements,centers] = hist(y{i},states);\r\n    probs_result{i} = nelements/length(y{i});\r\n    error(i,1) = sum(abs(probs-probs_result{i}));\r\nend\r\n\r\nassert(mean(error) \u003c= 0.05 \u0026 mean(error) \u003e 0);","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":27005,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":29,"test_suite_updated_at":"2014-06-11T14:25:30.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2014-06-11T00:57:51.000Z","updated_at":"2025-11-21T18:44:38.000Z","published_at":"2014-06-11T01:00:06.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eLets say we have 3 different states [1,2,3] with the probabilities of occurrences of each state is given as [0.5 0.2 0.3]. Which means 50% state 1 will be selected among others. Generate randomly selected states with the probabilities given\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 array will be consisting of state numbers based on the probabilities given as input.\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: (Quick tip: The higher simulation sampling sizes the more robust results)\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":42503,"title":"Generating random matrix with given probability mass function","description":"Inspired by \u003chttp://www.mathworks.com/matlabcentral/cody/problems/2356-simulating-the-selection-of-a-state-with-given-probabilities Problem 2356. Simulating the selection of a state with given probabilities\u003e, let's consider a similar yet more useful problem. Write a function\r\n\r\n                             x = rndsampling(m,n,prob)\r\n\r\nto generate an m-by-n matrix x, whose entries are drawn independently from integer symbols 1:numel(prob) according to the given probability mass function prob. Specifically, symbol k occurs with probability prob(k), k = 1, 2, ..., numel(prob), where all(prob\u003e0) == 1 and sum(prob) == 1.","description_html":"\u003cp\u003eInspired by \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/2356-simulating-the-selection-of-a-state-with-given-probabilities\"\u003eProblem 2356. Simulating the selection of a state with given probabilities\u003c/a\u003e, let's consider a similar yet more useful problem. Write a function\u003c/p\u003e\u003cpre\u003e                             x = rndsampling(m,n,prob)\u003c/pre\u003e\u003cp\u003eto generate an m-by-n matrix x, whose entries are drawn independently from integer symbols 1:numel(prob) according to the given probability mass function prob. Specifically, symbol k occurs with probability prob(k), k = 1, 2, ..., numel(prob), where all(prob\u0026gt;0) == 1 and sum(prob) == 1.\u003c/p\u003e","function_template":"function x = rndsampling(m,n,prob);\r\n  x = rand(m,n)\r\nend","test_suite":"%%\r\nrnd = sort(rand(randi([10,20]),1));\r\nprob = vertcat(rnd(1,:),diff(rnd,1,1),1-rnd(end,:));\r\nsz = [1 1e5;1e5 1;1e3 1e2;randi([100 200], 100, 2)];\r\nsz = sz(randi(size(sz,1)),:);\r\nx = rndsampling(sz(1),sz(2),prob);\r\nprob_est = histcounts(x,1:numel(prob)+1,'Normalization','probability').';\r\nerr = mean(abs(prob_est - prob))\r\nassert(err \u003c 0.005 \u0026\u0026 isequal(size(x),sz) \u0026\u0026 all(~isnan(x(:))));\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":107,"test_suite_updated_at":"2015-08-13T18:44:59.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-08-11T19:26:49.000Z","updated_at":"2026-02-02T05:18:21.000Z","published_at":"2015-08-11T19:26: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\u003eInspired by\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/2356-simulating-the-selection-of-a-state-with-given-probabilities\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 2356. Simulating the selection of a state with given probabilities\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, let's consider a similar yet more useful problem. Write a function\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 = rndsampling(m,n,prob)]]\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 generate an m-by-n matrix x, whose entries are drawn independently from integer symbols 1:numel(prob) according to the given probability mass function prob. Specifically, symbol k occurs with probability prob(k), k = 1, 2, ..., numel(prob), where all(prob\u0026gt;0) == 1 and sum(prob) == 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":42670,"title":"If you prick us, do we not bleed?","description":"While doing some quick sewing to fix up your child's Halloween costume, you accidentally jab your finger with the needle.  Reflexively, you drop the needle on the hardwood floor.  To take your mind off of the pain, you notice that the needle has a length of L cm, and the boards in your floor are all T cm apart.\r\n\r\nTaking a break from your sewing, you decide to write out (you can't type very well just yet, since your finger still hurts!) a MATLAB script that will determine the probability of a dropped needle touches at least one line between two of your floorboards.\r\n\r\nThe inputs to your script are L (the length of the needle) and T (the thickness of the planks that make up your hardwood floor.)  The output should be the probability that needle intersects at least one line between your floorboards.","description_html":"\u003cp\u003eWhile doing some quick sewing to fix up your child's Halloween costume, you accidentally jab your finger with the needle.  Reflexively, you drop the needle on the hardwood floor.  To take your mind off of the pain, you notice that the needle has a length of L cm, and the boards in your floor are all T cm apart.\u003c/p\u003e\u003cp\u003eTaking a break from your sewing, you decide to write out (you can't type very well just yet, since your finger still hurts!) a MATLAB script that will determine the probability of a dropped needle touches at least one line between two of your floorboards.\u003c/p\u003e\u003cp\u003eThe inputs to your script are L (the length of the needle) and T (the thickness of the planks that make up your hardwood floor.)  The output should be the probability that needle intersects at least one line between your floorboards.\u003c/p\u003e","function_template":"function y =  Belonephobia(L,T)\r\n  y = L*T;\r\nend","test_suite":"%%\r\nL=3; T=3; y_correct = 0.63661977236758;\r\nb=abs(Belonephobia(L,T)-y_correct)\r\nassert(b\u003c1e-7)\r\n%%\r\nL=4; T=1; y_correct = 0.92000006671399;\r\nb=abs(Belonephobia(L,T)-y_correct)\r\nassert(b\u003c1e-7)\r\n%%\r\nL=20; T=12; y_correct = 0.80254106139093;\r\nb=abs(Belonephobia(L,T)-y_correct)\r\nassert(b\u003c1e-7)\r\n%%\r\nL=12; T=20; y_correct = 0.38197186342055;\r\nb=abs(Belonephobia(L,T)-y_correct)\r\nassert(b\u003c1e-7)\r\n%%\r\nL=1; T=4; y_correct = 0.1591549430919;\r\nb=abs(Belonephobia(L,T)-y_correct)\r\nassert(b\u003c1e-7)\r\n%%\r\nL=2; T=ceil(rand*10);\r\ny_correct=[0.83724842055825 0.63661977236758 0.42441318157839 0.31830988618379 0.25464790894703 0.21220659078919 0.18189136353359 0.15915494309190 0.14147106052613 0.12732395447352];\r\nb=abs(Belonephobia(L,T)-y_correct(T))\r\nassert(b\u003c1e-7)\r\n%%\r\nL=ceil(rand*10); T=2;\r\ny_correct=[0.31830988618379 0.63661977236758 0.77860806073666 0.83724842055825 0.87089052216005 0.89287978884975 0.90841991082367 0.92000006671399 0.92896896682647 0.93612322320525];\r\nb=abs(Belonephobia(L,T)-y_correct(L))\r\nassert(b\u003c1e-7)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-10-23T15:27:44.000Z","updated_at":"2025-11-21T18:49:10.000Z","published_at":"2015-10-23T15:28:32.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eWhile doing some quick sewing to fix up your child's Halloween costume, you accidentally jab your finger with the needle. Reflexively, you drop the needle on the hardwood floor. To take your mind off of the pain, you notice that the needle has a length of L cm, and the boards in your floor are all T cm apart.\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\u003eTaking a break from your sewing, you decide to write out (you can't type very well just yet, since your finger still hurts!) a MATLAB script that will determine the probability of a dropped needle touches at least one line between two of your floorboards.\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 inputs to your script are L (the length of the needle) and T (the thickness of the planks that make up your hardwood floor.) The output should be the probability that needle intersects at least one line between your floorboards.\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":2995,"title":"Test Driven Solution - Probability Problem 1","description":"*Problem:* Without any Cody cheats, write code that passes the test suite.\r\n\r\n*Hint:* The test suite gets samples from the probability distribution represented by your code.  A cumulative distribution function is then built from the samples.  This is the empirical distribution, which is compared against the theoretical distribution you must infer from the test suite.\r\n\r\n*See also:* \u003chttp://en.wikipedia.org/wiki/Cumulative_distribution_function Cumulative Distribution Function\u003e\r\n\r\n*Problems in Series:* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/3006-test-driven-solution-probability-problem-2 Probability Problem 2\u003e, \u003chttp://www.mathworks.com/matlabcentral/cody/problems/3009-test-driven-solution-probability-problem-3 Probability Problem 3\u003e","description_html":"\u003cp\u003e\u003cb\u003eProblem:\u003c/b\u003e Without any Cody cheats, write code that passes the test suite.\u003c/p\u003e\u003cp\u003e\u003cb\u003eHint:\u003c/b\u003e The test suite gets samples from the probability distribution represented by your code.  A cumulative distribution function is then built from the samples.  This is the empirical distribution, which is compared against the theoretical distribution you must infer from the test suite.\u003c/p\u003e\u003cp\u003e\u003cb\u003eSee also:\u003c/b\u003e \u003ca href = \"http://en.wikipedia.org/wiki/Cumulative_distribution_function\"\u003eCumulative Distribution Function\u003c/a\u003e\u003c/p\u003e\u003cp\u003e\u003cb\u003eProblems in Series:\u003c/b\u003e \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/3006-test-driven-solution-probability-problem-2\"\u003eProbability Problem 2\u003c/a\u003e, \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/3009-test-driven-solution-probability-problem-3\"\u003eProbability Problem 3\u003c/a\u003e\u003c/p\u003e","function_template":"function vec = fcn(len)\r\n  vec = nan(len, 1);\r\nend","test_suite":"%%\r\n% test for correct size\r\nfor iter = 1:10\r\n  vectorLength = randi([1 100]);\r\n  result       = fcn(vectorLength);\r\n  assert(isequal([vectorLength, 1], size(result)));\r\nend\r\n\r\n%%\r\n% get large sample\r\nvectorLength = 10000;\r\nresult       = fcn(vectorLength);\r\n\r\n% build empirical cumulative distribution function\r\nxEmpirical = sort(result);                       % x-axis\r\nyEmpirical = (1:vectorLength).' ./ vectorLength; % y-axis\r\n\r\n% build theoretical cumulative distribution function\r\nxTheoretical = xEmpirical;       % x-axis\r\nyTheoretical = 0.5*xTheoretical; % y-axis\r\n\r\n% compute statistics on diff between empirical and theoretical\r\nerrorList = abs(yEmpirical - yTheoretical);\r\nerrorMax  = max(errorList);\r\nerrorMean = mean(errorList);\r\nerrorStd  = std(errorList);\r\n      \r\n% if fcn is correct, this should pass at least 99.9% of the time\r\nassert(errorMax  \u003c .02);\r\nassert(errorMean \u003c .012);\r\nassert(errorMean \u003e .0008);\r\nassert(errorStd  \u003e .0007);","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":692,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":"2015-02-12T17:42:40.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-02-10T14:53:38.000Z","updated_at":"2025-11-21T18:53:27.000Z","published_at":"2015-02-10T15:01:03.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eProblem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Without any Cody cheats, write code that passes the test suite.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eHint:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e The test suite gets samples from the probability distribution represented by your code. A cumulative distribution function is then built from the samples. This is the empirical distribution, which is compared against the theoretical distribution you must infer from the test suite.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSee also:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Cumulative_distribution_function\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCumulative Distribution Function\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eProblems in Series:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/3006-test-driven-solution-probability-problem-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProbability Problem 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/3009-test-driven-solution-probability-problem-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProbability Problem 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":3006,"title":"Test Driven Solution - Probability Problem 2","description":"*Problem:* Without any Cody cheats, write code that passes the test suite.\r\n\r\n*Hint:* The test suite gets samples from the probability distribution represented by your code.  A cumulative distribution function is then built from the samples.  This is the empirical distribution, which is compared against the theoretical distribution you must infer from the test suite.\r\n\r\n*See also:* \u003chttp://en.wikipedia.org/wiki/Cumulative_distribution_function Cumulative Distribution Function\u003e\r\n\r\n*Problems in Series:* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/2995-test-driven-solution-probability-problem-1 Probability Problem 1\u003e, \u003chttp://www.mathworks.com/matlabcentral/cody/problems/3009-test-driven-solution-probability-problem-3 Probability Problem 3\u003e","description_html":"\u003cp\u003e\u003cb\u003eProblem:\u003c/b\u003e Without any Cody cheats, write code that passes the test suite.\u003c/p\u003e\u003cp\u003e\u003cb\u003eHint:\u003c/b\u003e The test suite gets samples from the probability distribution represented by your code.  A cumulative distribution function is then built from the samples.  This is the empirical distribution, which is compared against the theoretical distribution you must infer from the test suite.\u003c/p\u003e\u003cp\u003e\u003cb\u003eSee also:\u003c/b\u003e \u003ca href = \"http://en.wikipedia.org/wiki/Cumulative_distribution_function\"\u003eCumulative Distribution Function\u003c/a\u003e\u003c/p\u003e\u003cp\u003e\u003cb\u003eProblems in Series:\u003c/b\u003e \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/2995-test-driven-solution-probability-problem-1\"\u003eProbability Problem 1\u003c/a\u003e, \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/3009-test-driven-solution-probability-problem-3\"\u003eProbability Problem 3\u003c/a\u003e\u003c/p\u003e","function_template":"function vec = fcn(len)\r\n  vec = nan(len, 1);\r\nend","test_suite":"%%\r\n% test for correct size\r\nfor iter = 1:10\r\n  vectorLength = randi([1 100]);\r\n  result       = fcn(vectorLength);\r\n  assert(isequal([vectorLength, 1], size(result)));\r\nend\r\n\r\n%%\r\n% get large sample\r\nvectorLength = 10000;\r\nresult       = fcn(vectorLength);\r\n\r\n% build empirical cumulative distribution function\r\nxEmpirical = sort(result);                       % x-axis\r\nyEmpirical = (1:vectorLength).' ./ vectorLength; % y-axis\r\n\r\n% build theoretical cumulative distribution function\r\nxTheoretical = xEmpirical; % x-axis\r\nerfInput     = sqrt(0.5) / pi * (xTheoretical - exp(1));\r\nyTheoretical = 0.5*erf(erfInput) + 0.5; % y-axis\r\n\r\n% compute statistics on diff between empirical and theoretical\r\nerrorList = abs(yEmpirical - yTheoretical);\r\nerrorMax  = max(errorList);\r\nerrorSum  = sum(errorList);\r\nerrorStd  = std(errorList);\r\n\r\n% if fcn is correct, this should pass at least 99.9% of the time\r\nassert(errorMax \u003c .02);\r\nassert(errorSum \u003e 10.1);\r\nassert(errorStd \u003e .00075);","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":692,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":15,"test_suite_updated_at":"2015-02-11T19:01:30.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-02-11T17:31:57.000Z","updated_at":"2025-11-21T18:40:33.000Z","published_at":"2015-02-11T17:33:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eProblem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Without any Cody cheats, write code that passes the test suite.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eHint:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e The test suite gets samples from the probability distribution represented by your code. A cumulative distribution function is then built from the samples. This is the empirical distribution, which is compared against the theoretical distribution you must infer from the test suite.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSee also:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Cumulative_distribution_function\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCumulative Distribution Function\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eProblems in Series:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/2995-test-driven-solution-probability-problem-1\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProbability Problem 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/3009-test-driven-solution-probability-problem-3\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProbability Problem 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":3009,"title":"Test Driven Solution - Probability Problem 3","description":"*Problem:* Without any Cody cheats, write code that passes the test suite.\r\n\r\n*Hint:* The test suite gets samples from the probability distribution represented by your code.  A cumulative distribution function is then built from the samples.  This is the empirical distribution, which is compared against the theoretical distribution you must infer from the test suite.\r\n\r\n*See also:* \u003chttp://en.wikipedia.org/wiki/Cumulative_distribution_function Cumulative Distribution Function\u003e\r\n\r\n*Problems in Series:* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/2995-test-driven-solution-probability-problem-1 Probability Problem 1\u003e, \u003chttp://www.mathworks.com/matlabcentral/cody/problems/3006-test-driven-solution-probability-problem-2 Probability Problem 2\u003e","description_html":"\u003cp\u003e\u003cb\u003eProblem:\u003c/b\u003e Without any Cody cheats, write code that passes the test suite.\u003c/p\u003e\u003cp\u003e\u003cb\u003eHint:\u003c/b\u003e The test suite gets samples from the probability distribution represented by your code.  A cumulative distribution function is then built from the samples.  This is the empirical distribution, which is compared against the theoretical distribution you must infer from the test suite.\u003c/p\u003e\u003cp\u003e\u003cb\u003eSee also:\u003c/b\u003e \u003ca href = \"http://en.wikipedia.org/wiki/Cumulative_distribution_function\"\u003eCumulative Distribution Function\u003c/a\u003e\u003c/p\u003e\u003cp\u003e\u003cb\u003eProblems in Series:\u003c/b\u003e \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/2995-test-driven-solution-probability-problem-1\"\u003eProbability Problem 1\u003c/a\u003e, \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/3006-test-driven-solution-probability-problem-2\"\u003eProbability Problem 2\u003c/a\u003e\u003c/p\u003e","function_template":"function vec = fcn(len)\r\n  vec = nan(len, 1);\r\nend","test_suite":"%%\r\n% test for correct size\r\nfor iter = 1:10\r\n  vectorLength = randi([1 100]);\r\n  result       = fcn(vectorLength);\r\n  assert(isequal([vectorLength, 1], size(result)));\r\nend\r\n\r\n%%\r\n% get large sample\r\nvectorLength = 10000;\r\nresult       = fcn(vectorLength);\r\n\r\n% built empirical cumulative distribution function\r\nxEmpirical = 0:10;                     % x-axis\r\ncounts     = accumarray(result+1, 1);\r\ndensity    = counts ./ sum(counts);\r\nyEmpirical = cumsum(density);          % y-axis\r\n\r\n% build theoretical cumulative distribution function\r\nxTheoretical = xEmpirical; % x-axis\r\nfor k = xTheoretical\r\n  yTheoretical(k+1, 1) = betainc(exp(-1), 10-k, k+1); % y-axis\r\nend\r\n\r\n% compute statistics on diff between empirical and theoretical\r\nerrorList = abs(yEmpirical - yTheoretical);\r\nerrorMax  = max(errorList);\r\nerrorSum  = sum(errorList);\r\nerrorStd  = std(errorList);\r\n\r\n% if fcn is correct, this should pass at least 99.9% of the time\r\nassert(errorMax \u003c .018);\r\nassert(errorSum \u003e .0045);\r\nassert(errorStd \u003e .0004);","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":692,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":12,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-02-12T17:08:10.000Z","updated_at":"2025-10-20T15:59:08.000Z","published_at":"2015-02-12T17:08:43.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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eProblem:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Without any Cody cheats, write code that passes the test suite.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eHint:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e The test suite gets samples from the probability distribution represented by your code. A cumulative distribution function is then built from the samples. This is the empirical distribution, which is compared against the theoretical distribution you must infer from the test suite.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSee also:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Cumulative_distribution_function\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCumulative Distribution Function\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eProblems in Series:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/2995-test-driven-solution-probability-problem-1\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProbability Problem 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/3006-test-driven-solution-probability-problem-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProbability Problem 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":43575,"title":"Probabilities - More brains than luck","description":"This problem is related to \u003chttp://it.mathworks.com/matlabcentral/cody/problems/596-more-luck-than-brains Problem 596. More luck than brains\u003e\r\nwhere the test suite checks 3 times if the outcome of the solution is a random number between 1 and 6. \r\n\r\nUsing brain, the \"solver\" would be interested in computing the probability of passing a general test (with some other interesting probabilities) where the suite checks C times if the outcome of the solution is a random number between 1 and N.\r\n\r\nSo, here is the problem:\r\n\r\n# Each test in the suite checks if a random number between 1 and N is guessed. \r\n# There are C tests in the suite.\r\n\r\nOutput these values, given inputs N,C,K:\r\n\r\n# P = the probability of passing the test suite.\r\n# XK = the probability that the number of times the function must be run to get a success (passing the test suite) is K.\r\n# M = the mean number of times the function must be run to get a success.\r\n\r\nYou will see that, for N=6 and C=3, then M=216. ","description_html":"\u003cp\u003eThis problem is related to \u003ca href = \"http://it.mathworks.com/matlabcentral/cody/problems/596-more-luck-than-brains\"\u003eProblem 596. More luck than brains\u003c/a\u003e\r\nwhere the test suite checks 3 times if the outcome of the solution is a random number between 1 and 6.\u003c/p\u003e\u003cp\u003eUsing brain, the \"solver\" would be interested in computing the probability of passing a general test (with some other interesting probabilities) where the suite checks C times if the outcome of the solution is a random number between 1 and N.\u003c/p\u003e\u003cp\u003eSo, here is the problem:\u003c/p\u003e\u003col\u003e\u003cli\u003eEach test in the suite checks if a random number between 1 and N is guessed.\u003c/li\u003e\u003cli\u003eThere are C tests in the suite.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eOutput these values, given inputs N,C,K:\u003c/p\u003e\u003col\u003e\u003cli\u003eP = the probability of passing the test suite.\u003c/li\u003e\u003cli\u003eXK = the probability that the number of times the function must be run to get a success (passing the test suite) is K.\u003c/li\u003e\u003cli\u003eM = the mean number of times the function must be run to get a success.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eYou will see that, for N=6 and C=3, then M=216.\u003c/p\u003e","function_template":"function [P,XK,M] = test_suite_prob(N,C,K)\r\n  P=1;\r\n  XK=K;\r\n  M=1;\r\nend","test_suite":"%%\r\nC=1; N=6; K=2;\r\n[P,XK,M] = test_suite_prob(N,C,K);\r\nPc=0.166666; XKc=0.138888; Mc=6;\r\ntol=1e-6;\r\nassert( (abs(P-Pc)\u003ctol)\u0026(abs(XK-XKc)\u003ctol)\u0026(abs(M-Mc)\u003ctol) );\r\n%%\r\nC=3; N=6; K=2;\r\n[P,XK,M] = test_suite_prob(N,C,K);\r\nPc=0.004629; XKc=0.004608; Mc=216;\r\ntol=1e-6;\r\nassert( (abs(P-Pc)\u003ctol)\u0026(abs(XK-XKc)\u003ctol)\u0026(abs(M-Mc)\u003ctol) );\r\n%%\r\nC=2; N=6; K=6;\r\n[P,XK,M] = test_suite_prob(N,C,K);\r\nPc=0.027777; XKc=0.024128; Mc=36;\r\ntol=1e-6;\r\nassert( (abs(P-Pc)\u003ctol)\u0026(abs(XK-XKc)\u003ctol)\u0026(abs(M-Mc)\u003ctol) );\r\n%%\r\nC=8; N=2; K=20;\r\n[P,XK,M] = test_suite_prob(N,C,K);\r\nPc=0.003906; XKc=0.003626; Mc=256;\r\ntol=1e-6;\r\nassert( (abs(P-Pc)\u003ctol)\u0026(abs(XK-XKc)\u003ctol)\u0026(abs(M-Mc)\u003ctol) );\r\n%%\r\nC=4; N=5; K=7;\r\n[P,XK,M] = test_suite_prob(N,C,K);\r\nPc=0.001600; XKc=0.001584; Mc=625;\r\ntol=1e-6;\r\nassert( (abs(P-Pc)\u003ctol)\u0026(abs(XK-XKc)\u003ctol)\u0026(abs(M-Mc)\u003ctol) );\r\n%%\r\nC=5; N=1; K=2;\r\n[P,XK,M] = test_suite_prob(N,C,K);\r\nPc=1; XKc=0; Mc=1;\r\ntol=1e-6;\r\nassert( (abs(P-Pc)\u003ctol)\u0026(abs(XK-XKc)\u003ctol)\u0026(abs(M-Mc)\u003ctol) );","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":85738,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":19,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-18T15:58:33.000Z","updated_at":"2025-11-21T18:42:36.000Z","published_at":"2016-10-18T15:58:33.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis problem is related to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://it.mathworks.com/matlabcentral/cody/problems/596-more-luck-than-brains\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 596. More luck than brains\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e where the test suite checks 3 times if the outcome of the solution is a random number between 1 and 6.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eUsing brain, the \\\"solver\\\" would be interested in computing the probability of passing a general test (with some other interesting probabilities) where the suite checks C times if the outcome of the solution is a random number between 1 and N.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSo, here is the problem:\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\u003eEach test in the suite checks if a random number between 1 and N is guessed.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are C tests in the suite.\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\u003eOutput these values, given inputs N,C,K:\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\u003eP = the probability of passing the test suite.\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\u003eXK = the probability that the number of times the function must be run to get a success (passing the test suite) is K.\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\u003eM = the mean number of times the function must be run to get a success.\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 will see that, for N=6 and C=3, then M=216.\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":331,"title":"Compute Area from Fixed Sum Cumulative Probability","description":"In Matlab the code\r\n v = rand(1,3);\r\n v = v/sum(v);\r\nis sometimes suggested as a convenient means of generating three random variables, whose ranges are restricted to [0,1], which have a fixed sum of one. However, this procedure has the property that the area-wise density distribution of the three values, considered as cartesian coordinates in 3D space, is widely variable throughout the planar region of possible locations of v. For any given density value in the range of this density distribution, let A be the corresponding area of the subregion of all points whose density is less than or equal to this given value, and let P be the corresponding probability that v would lie in this subregion. The task is to write a function 'fixedsumarea' which receives P as an input and gives A as an output:\r\n A = fixedsumarea(P);\r\nYou should assume that initially 'rand(1,3)' perfectly generates three independent random variables each uniformly distributed on [0,1], but subsequently each is modified by being divided by their mutual sum.","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: 311.3px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 155.65px; transform-origin: 407px 155.65px; 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: 58px 8px; transform-origin: 58px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIn Matlab the code\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 40.8667px; 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 20.4333px; transform-origin: 404px 20.4333px; 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: 60px 8.5px; tab-size: 4; transform-origin: 60px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e v = rand(1,3);\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: 56px 8.5px; tab-size: 4; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e v = v/sum(v);\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 147px; 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 73.5px; text-align: left; transform-origin: 384px 73.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: 371.5px 8px; transform-origin: 371.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eis sometimes suggested as a convenient means of generating three random variables, whose ranges are restricted to [0,1], which have a fixed sum of one. However, this procedure has the property that the area-wise density distribution of the three values, considered as cartesian coordinates in 3D space, is widely variable throughout the planar region of possible locations of v. For any given density value in the range of this density distribution, let A be the corresponding area of the subregion of all points whose density is less than or equal to this given value, and let P be the corresponding probability that v would lie in this subregion. The task is to write a function 'fixedsumarea' which receives P as an input and gives A as an output:\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: 84px 8.5px; tab-size: 4; transform-origin: 84px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e A = fixedsumarea(P);\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 362.5px 8px; transform-origin: 362.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou should assume that initially 'rand(1,3)' perfectly generates three independent random variables each uniformly distributed on [0,1], but subsequently each is modified by being divided by their mutual sum.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function A = fixedsumarea(P)\r\n  P = 1/2;\r\n  A = 0;\r\nend","test_suite":"%%\r\nfiletext = fileread('fixedsumarea.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp') || ...\r\n          contains(filetext, 'elseif') || contains(filetext, 'switch ');\r\nassert(~illegal)\r\n\r\n%%\r\nP = pi/4;\r\nA_correct = 0.7984235067141288;\r\nassert(abs(fixedsumarea(P)-A_correct)\u003c100*eps)\r\n%%\r\nP = 1/sqrt(11);\r\nA_correct = 0.4964013344766580;\r\nassert(abs(fixedsumarea(P)-A_correct)\u003c100*eps)\r\n%%\r\nP = exp(-3);\r\nA_correct = 0.1494793760894695;\r\nassert(abs(fixedsumarea(P)-A_correct)\u003c100*eps)\r\n%%\r\nP = (1/27)^(1/5);\r\nA_correct = 0.6605992894366502;\r\nassert(abs(fixedsumarea(P)-A_correct)\u003c100*eps)\r\n%%\r\nP = sin(sqrt(2));\r\nA_correct = 0.8634048022602919;\r\nassert(abs(fixedsumarea(P)-A_correct)\u003c100*eps)\r\n%%\r\nP = 68/137;\r\nA_correct = 0.6471420329484348;\r\nassert(abs(fixedsumarea(P)-A_correct)\u003c100*eps)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":7,"created_by":28,"edited_by":223089,"edited_at":"2023-02-21T09:48:12.000Z","deleted_by":null,"deleted_at":null,"solvers_count":5,"test_suite_updated_at":"2023-02-21T09:48:12.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-02-17T05:58:59.000Z","updated_at":"2025-10-20T16:39:20.000Z","published_at":"2012-02-17T18:47:40.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\u003eIn Matlab the code\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 = rand(1,3);\\n v = v/sum(v);]]\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\u003eis sometimes suggested as a convenient means of generating three random variables, whose ranges are restricted to [0,1], which have a fixed sum of one. However, this procedure has the property that the area-wise density distribution of the three values, considered as cartesian coordinates in 3D space, is widely variable throughout the planar region of possible locations of v. For any given density value in the range of this density distribution, let A be the corresponding area of the subregion of all points whose density is less than or equal to this given value, and let P be the corresponding probability that v would lie in this subregion. The task is to write a function 'fixedsumarea' which receives P as an input and gives A as an output:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ A = fixedsumarea(P);]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou should assume that initially 'rand(1,3)' perfectly generates three independent random variables each uniformly distributed on [0,1], but subsequently each is modified by being divided by their mutual sum.\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":44254,"title":"Probability of red tulips (at both ends of a row)","description":"I planted tulip bulbs in a row on my flower bed.\r\nI thought that I had planted white tulips all. However, later, it turned out that two RED tulip bulbs had been mixed in the planted bulbs!\r\n\r\nInput (x): Number of all bulbs\r\n\r\nOutput (y): The probability that RED tulips will bloom at BOTH ENDs of the row.","description_html":"\u003cp\u003eI planted tulip bulbs in a row on my flower bed.\r\nI thought that I had planted white tulips all. However, later, it turned out that two RED tulip bulbs had been mixed in the planted bulbs!\u003c/p\u003e\u003cp\u003eInput (x): Number of all bulbs\u003c/p\u003e\u003cp\u003eOutput (y): The probability that RED tulips will bloom at BOTH ENDs of the row.\u003c/p\u003e","function_template":"function y = redT(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 3;\r\ny_correct = 1/3;\r\nassert(isequal(redT(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = 1/10;\r\nassert(isequal(redT(x),y_correct))\r\n\r\n%%\r\nx= 8;\r\ny_correct = 1/28;\r\nassert(isequal(redT(x),y_correct))\r\n\r\n%%\r\nx= 30;\r\ny_correct = 1/435;\r\nassert(isequal(redT(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":102298,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":65,"test_suite_updated_at":"2017-07-09T06:48:35.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-07-09T06:18:32.000Z","updated_at":"2026-03-16T09:51:51.000Z","published_at":"2017-07-09T06:48: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\u003eI planted tulip bulbs in a row on my flower bed. I thought that I had planted white tulips all. However, later, it turned out that two RED tulip bulbs had been mixed in the planted bulbs!\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\u003eInput (x): Number of all bulbs\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 (y): The probability that RED tulips will bloom at BOTH ENDs of the row.\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":648,"title":"Cumulative probability of finding an unlikely combination","description":"This is a supplemental problem to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition CryptoMath\u003e problem.  If you solve the problem methodically or randomly matters for expected solution time.  This calculates the difference in techniques.  My reference solution has some commented out graphics code to visualize the timing differences.\r\n\r\n---\r\n\r\nIf you have N possible combinations to a lock you can calculate the likelihood of opening the lock as a percentage given X attempts.\r\n\r\nThere are two ways to figure out the combination to try:\r\n\r\n* Try a random one, possibly trying an old one again\r\n* Methodically doing them in order\r\n\r\nChoosing a random combination is very fast and easy.  No record keeping needed.  Choosing a methodical way of trying them all is a little slower on each attempt, and incurs a fix cost before the first attempt is made.\r\n\r\nIf you have:\r\n\r\n* Goal of *G%* cumulative probability of opening the lock\r\n* Fixed cost of *F* seconds to start the methodical style\r\n* *TR* seconds per random attempt\r\n* *TM* seconds per methodical attempt\r\n* *N* equally likely combinations\r\n\r\nWhich technique should you use to get to your goal chance fastest?\r\n\r\n* *0* for random\r\n* *1* for methodical\r\n\r\n---\r\nNote for the curious:  The really short solution is gaming the system and just choosing randomly.  Eventually one of the solutions will guess right on all the test suite.","description_html":"\u003cp\u003eThis is a supplemental problem to the \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\"\u003eCryptoMath\u003c/a\u003e problem.  If you solve the problem methodically or randomly matters for expected solution time.  This calculates the difference in techniques.  My reference solution has some commented out graphics code to visualize the timing differences.\u003c/p\u003e\u003cp\u003e---\u003c/p\u003e\u003cp\u003eIf you have N possible combinations to a lock you can calculate the likelihood of opening the lock as a percentage given X attempts.\u003c/p\u003e\u003cp\u003eThere are two ways to figure out the combination to try:\u003c/p\u003e\u003cul\u003e\u003cli\u003eTry a random one, possibly trying an old one again\u003c/li\u003e\u003cli\u003eMethodically doing them in order\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eChoosing a random combination is very fast and easy.  No record keeping needed.  Choosing a methodical way of trying them all is a little slower on each attempt, and incurs a fix cost before the first attempt is made.\u003c/p\u003e\u003cp\u003eIf you have:\u003c/p\u003e\u003cul\u003e\u003cli\u003eGoal of \u003cb\u003eG%\u003c/b\u003e cumulative probability of opening the lock\u003c/li\u003e\u003cli\u003eFixed cost of \u003cb\u003eF\u003c/b\u003e seconds to start the methodical style\u003c/li\u003e\u003cli\u003e\u003cb\u003eTR\u003c/b\u003e seconds per random attempt\u003c/li\u003e\u003cli\u003e\u003cb\u003eTM\u003c/b\u003e seconds per methodical attempt\u003c/li\u003e\u003cli\u003e\u003cb\u003eN\u003c/b\u003e equally likely combinations\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eWhich technique should you use to get to your goal chance fastest?\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003cb\u003e0\u003c/b\u003e for random\u003c/li\u003e\u003cli\u003e\u003cb\u003e1\u003c/b\u003e for methodical\u003c/li\u003e\u003c/ul\u003e\u003cp\u003e---\r\nNote for the curious:  The really short solution is gaming the system and just choosing randomly.  Eventually one of the solutions will guess right on all the test suite.\u003c/p\u003e","function_template":"function choice = chaosOrOrder(g,f,tr,tm, n)\r\n  y = 0;\r\nend","test_suite":"%%\r\ng  =  0.9;\r\nf  = 10;\r\ntr =  1;\r\ntm =  2;\r\nn  = 10;\r\nout = 0;\r\n\r\nassert(isequal(chaosOrOrder(g,f,tr,tm,n),out))\r\n\r\n%%\r\ng  =  0.9;\r\nf  = 10;\r\ntr =  1;\r\ntm =  2;\r\nn  = 100;\r\nout = 1;\r\n\r\nassert(isequal(chaosOrOrder(g,f,tr,tm,n),out))\r\n\r\n%%\r\ng  =  0.9;\r\nf  = 10;\r\ntr =  .1;\r\ntm =  2;\r\nn  = 10000;\r\nout = 0;\r\n\r\nassert(isequal(chaosOrOrder(g,f,tr,tm,n),out))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":35,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-01T17:58:41.000Z","updated_at":"2025-11-27T17:33:42.000Z","published_at":"2012-05-01T19:29:40.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a supplemental problem to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCryptoMath\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e problem. If you solve the problem methodically or randomly matters for expected solution time. This calculates the difference in techniques. My reference solution has some commented out graphics code to visualize the timing differences.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e---\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf you have N possible combinations to a lock you can calculate the likelihood of opening the lock as a percentage given X attempts.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are two ways to figure out the combination to try:\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\u003eTry a random one, possibly trying an old one again\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\u003eMethodically doing them in order\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\u003eChoosing a random combination is very fast and easy. No record keeping needed. Choosing a methodical way of trying them all is a little slower on each attempt, and incurs a fix cost before the first attempt is made.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf you have:\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\u003eGoal of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eG%\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e cumulative probability of opening the lock\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\u003eFixed cost of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eF\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e seconds to start the methodical style\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTR\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e seconds per random attempt\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTM\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e seconds per methodical attempt\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e equally likely combinations\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\u003eWhich technique should you use to get to your goal chance fastest?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for random\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for methodical\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e--- Note for the curious: The really short solution is gaming the system and just choosing randomly. Eventually one of the solutions will guess right on all the test suite.\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":3056,"title":"Chess probability","description":"The difference in the ratings between two players serves as a predictor of the outcome of a match (the \u003chttp://en.wikipedia.org/wiki/Elo_rating_system Elo rating system\u003e)\r\n\r\nIf Player A has a rating of Ra and Player B a rating of Rb, the formula for the expected score of Player A is :\r\n\r\n\u003c\u003chttp://upload.wikimedia.org/math/b/0/3/b0366725c224ee55eab6e2371dc6a0ef.png\u003e\u003e\r\n \r\n* \r\n \r\n\r\nTwo players with equal ratings who play against each other are expected to score an equal number of wins. A player whose rating is 100 points greater than their opponent's is expected to score 64%; if the difference is 200 points, then the expected score for the stronger player is 76%.\r\n\r\nI give you two ELOs, compute the expected score (round to 3 digits), or probability  that the first player wins.\r\n\r\n\r\n","description_html":"\u003cp\u003eThe difference in the ratings between two players serves as a predictor of the outcome of a match (the \u003ca href = \"http://en.wikipedia.org/wiki/Elo_rating_system\"\u003eElo rating system\u003c/a\u003e)\u003c/p\u003e\u003cp\u003eIf Player A has a rating of Ra and Player B a rating of Rb, the formula for the expected score of Player A is :\u003c/p\u003e\u003cimg src = \"http://upload.wikimedia.org/math/b/0/3/b0366725c224ee55eab6e2371dc6a0ef.png\"\u003e\u003cul\u003e\u003cli\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eTwo players with equal ratings who play against each other are expected to score an equal number of wins. A player whose rating is 100 points greater than their opponent's is expected to score 64%; if the difference is 200 points, then the expected score for the stronger player is 76%.\u003c/p\u003e\u003cp\u003eI give you two ELOs, compute the expected score (round to 3 digits), or probability  that the first player wins.\u003c/p\u003e","function_template":"function y = expected_score(elo1,elo2)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1800;\r\ny = 1800;\r\nassert(isequal(expected_score(x,y),0.5))\r\n%%\r\nx = 1900;\r\ny = 1800;\r\nassert(isequal(expected_score(x,y),0.64))\r\n%%\r\nx = 1900;\r\ny = 2000;\r\nassert(isequal(expected_score(x,y),0.36))\r\n%%\r\nx = 1900;\r\ny = 2100;\r\nassert(isequal(expected_score(x,y),0.24))\r\n%% My probability against Maxime Vachier-Lagrave (best french player)\r\nx = 1800;\r\ny = 2775;\r\nassert(isequal(expected_score(x,y),0.004))\r\n%% My probability against Magnus Carlsen (World Chess Champion)\r\nx = 1800;\r\ny = 2865;\r\nassert(isequal(expected_score(x,y),0.002))\r\n%% Magnus against Maxime\r\nx = 2865;\r\ny = 2775;\r\nassert(isequal(expected_score(x,y),0.627))\r\n%% Magnus Carlsen against Garry Kasparov (1999)\r\nx = 2865;\r\ny = 2851;\r\nassert(isequal(expected_score(x,y),0.52))\r\n%% Magnus Carlsen against Fabiano Caruana\r\nx = 2865;\r\ny = 2844;\r\nassert(isequal(expected_score(x,y),0.53))\r\n%% Bobby Fisher (1972) against Magnus Carlsen\r\nx = 2785;\r\ny = 2865;\r\nassert(isequal(expected_score(x,y),0.387))\r\n%% Bobby Fisher (1972) against me\r\nx = 2785;\r\ny = 1800;\r\nassert(isequal(expected_score(x,y),0.997))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":0,"created_by":5390,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":679,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-02-28T22:51:09.000Z","updated_at":"2026-04-02T13:53:00.000Z","published_at":"2015-02-28T22:52:00.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/media/image1.png\"}],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe difference in the ratings between two players serves as a predictor of the outcome of a match (the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Elo_rating_system\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eElo rating system\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf Player A has a rating of Ra and Player B a rating of Rb, the formula for the expected score of Player A is :\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"relationshipId\\\" w:val=\\\"rId1\\\"/\u003e\u003c/w:customXmlPr\u003e\u003c/w:customXml\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTwo players with equal ratings who play against each other are expected to score an equal number of wins. A player whose rating is 100 points greater than their opponent's is expected to score 64%; if the difference is 200 points, then the expected score for the stronger player is 76%.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eI give you two ELOs, compute the expected score (round to 3 digits), or probability that the first player wins.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"},{\"partUri\":\"/media/image1.png\",\"contentType\":\"image/png\",\"content\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAM4AAAArBAMAAADCuKrGAAAAMFBMVEX///90dHQEBAQwMDCenp5QUFAWFhbm5ubMzMyKioq2trZAQEAMDAwiIiJiYmIAAADHPVvyAAAAAXRSTlMAQObYZgAAAuJJREFUeNrtV0toE2EQ/pJs91+TZpuKKZ7aHDxZhKBo8WCNQj14qNHiAxFZRNIHVAPFi0UbFC8qEqh40cOePBUfUAoS0BQPvhByqXqoEK1CaauNXswWu3H+JF03TbV5dHPqwGYzM//u98/881qgOhoscZ29OhjnkRIXOqqCYdvmXqMmtKc2fiuZ1nHWcdZxikmrDU7Xq53hkhbagG8Nz7Cl0WO565xkuxS3/nwEHUinrMfJ9NLdbz2OPYUkVOtD+2GA+S0HEYDAzQ82nyEYe8R/+yxAfoc6671G+dM6If+U0oC4sEyXWSuQHzw5JQ0MdfRnPmxpvGk6Fam9lK5q9kzGQpwSqz4Y+beK71cq2rSDxwC9V6iPlrE/+T/GH6fLVWRPhpx3ia57v4Jl4NyIYv5pV8HODH4kx9ep0uETuOYly9m43dV/N7brShRS50xw9amWCwabaWEboO4f7THrDF4PABv4aKe3PMDn2SSJFFMi2ZSiCvt2JcFLDMNJWdYEHqV/yeB52vvBmtQRiAfjOFvQfybhWF6zWau6gkDuwXlVoD214MK0WWvwGnnHB5ZCH9gLFf1mnKvTGJpY3ivfLIWd2yRI+yAEFsnpKe+sD/fbpwL5RVkeUraeLPpxPRtdH42HS5me3SZBgwcOxRWAlEI7aSJCwhaLxR7nebjI0m76PGBRUW2C+EnBucr6djgCSaHSoSWxSDUjkolnOjo6DuV57KaYe4IDWDg9uekOxF4FxyrD4TVEEVTYPRiWcLHxfT6TcjzqGUUeWZTZuHVOCWOM4XfFc0gaepCdOglvEpvnt+djJMfLvgEIUcYFU7f1fZ344k1Wdj5DUbjjPH+yNAqxICgHvo/DFbGV2QCyOK5Q6Ewo1G+KA7diZHD3UvbnKYijuFX2V+JK9ohBiEk4cyVG1r+2FZiTkCZVDy6vAY6cQINaQV8oa6olgZaGrKwtTtFUywXa8+YdVnVDN2pDjqrf8Af8bczR/4tLjAAAAABJRU5ErkJggg==\"}]}"},{"id":44630,"title":"Guess the number I'm thinking of (Part 1)","description":"In this game you are competing against two other people to guess the number that I'm thinking of.\r\nI randomly choose an integer between one and ten (inclusive). I don't provide any clues about the number.\r\nYour first opponent tries to guess the number. They guess randomly.\r\nYour second opponent tries to guess the number. They also guess randomly.\r\nYou try to guess the number. But you guess strategically.\r\nThe winner is the person who guesses my chosen number, or the person who guesses closest to my chosen number. This represents a \"win\".\r\nIf two contestants are equally close, they may share the win, with such a result being declared a \"draw\". (It is a loss for the remaining contestant.) A draw is worth half as much as a win.\r\nEach person hears the guesses stated by any preceding competitors, so you will be aware of the two prior guesses (provided to you as the vector guessesOfOpponents). Moreover, each guess must be unique.\r\nIf everyone guessed randomly, each person should have an equal chance of winning.\r\nIt might seem that you're at a disadvantage, having the last opportunity to guess. But actually you have the advantage of extra knowledge.\r\nBy guessing strategically, you should be able to achieve a success rate of 45% or more, in which\r\nsuccess rate = (wins + draws/2) / games\r\n\r\nRELATED PROBLEM:  \r\nProblem 52323. Guess the number I'm thinking of (Part 2)","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 484px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 242px; transform-origin: 407px 242px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eIn this game you are competing against two other people to guess the number that I'm thinking of.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 160px; font-family: Helvetica, Arial, sans-serif; list-style-type: decimal; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 80px; transform-origin: 391px 80px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20px; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10px; text-align: left; transform-origin: 363px 10px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eI randomly choose an\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003einteger\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e between\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eone\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e and\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eten\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e (inclusive). I don't provide any clues about the number.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20px; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10px; text-align: left; transform-origin: 363px 10px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eYour first opponent tries to guess the number. They guess randomly.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20px; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10px; text-align: left; transform-origin: 363px 10px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eYour second opponent tries to guess the number. They also guess randomly.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20px; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10px; text-align: left; transform-origin: 363px 10px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eYou try to guess the number. But you guess\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-style: italic; \"\u003estrategically\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 40px; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 20px; text-align: left; transform-origin: 363px 20px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThe winner is the person who guesses my chosen number, or the person who guesses closest to my chosen number. This represents a \"win\".\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 40px; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 20px; text-align: left; transform-origin: 363px 20px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eIf two contestants are equally close, they may share the win, with such a result being declared a \"draw\". (It is a loss for the remaining contestant.) A draw is worth half as much as a win.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eEach person hears the guesses stated by any preceding competitors, so you will be aware of the two prior guesses (provided to you as 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eguessesOfOpponents\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e). Moreover, each guess must be unique.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eIf everyone guessed randomly, each person should have an equal chance of winning.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eIt might seem that you're at a disadvantage, having the last opportunity to guess. But actually you have the advantage of extra knowledge.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eBy guessing strategically, you should be able to\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eachieve a success rate of 45% or more\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e, in which\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003esuccess rate = (wins + draws/2) / games\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eRELATED PROBLEM:  \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 20px; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 10px; transform-origin: 391px 10px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10px; text-align: left; transform-origin: 363px 10px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/52323\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 52323. Guess the number I'm thinking of (Part 2)\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = myGuess(guessesOfOpponents)\r\n    y = 42;\r\nend","test_suite":"%% Anti-hacking test\r\nassessFunctionAbsence({'rng', 'RandStream'}, 'FileName','myGuess.m')\r\n\r\n%% Ensure unique guesses of integers, which are in-range\r\nfor j = 1 : 1000\r\n    numberToBeGuessed = randi(10);\r\n    gOO = randperm(10, 2);\r\n    mG = myGuess(gOO);\r\n    assert( mG \u003e= 1  \u0026  mG \u003c= 10 , 'Out of requested range.' )\r\n    u = unique( floor([gOO mG]) );\r\n    assert( length(u) == 3 , 'Your guess must not have been already chosen.' )\r\nend;\r\n\r\n%% maxIts: 20000 = Too small; 30000 = Not quite big enough; 35000 = Just big enough (usually!); 50000 = Big enough (usually!); 100000 = Big enough, plus safety margin \u0026 efficiency incentive (but waste of resources)\r\nmaxIts = 100000;    \r\ntic\r\nfor j = 1 : 10\r\n    WDL = [0 0 0];\r\n    for itn = 1 : maxIts\r\n        numberToBeGuessed = randi(10);\r\n        gOO = randperm(10, 2);\r\n        diffs = abs( [gOO myGuess(gOO)] - numberToBeGuessed );\r\n        winningContestant = find( min(diffs)==diffs );\r\n        if any( winningContestant == 3 ),\r\n            if length(winningContestant) == 1,\r\n                % Win\r\n                WDL(1) = WDL(1) + 1;  \r\n            else\r\n                % Draw\r\n                WDL(2) = WDL(2) + 1;  \r\n            end;\r\n        else\r\n            % Loss\r\n            WDL(3) = WDL(3) + 1;  \r\n        end;\r\n    end;\r\n    successRate = (WDL(1) + WDL(2)/2) / maxIts\r\n    assert( successRate \u003e= 0.45 )\r\nend;\r\ntoc","published":true,"deleted":false,"likes_count":13,"comments_count":6,"created_by":64439,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":69,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-05-04T14:00:17.000Z","updated_at":"2026-02-06T20:26:39.000Z","published_at":"2018-05-05T12:29:22.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn this game you are competing against two other people to guess the number that I'm thinking of.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eI randomly choose an\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003einteger\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e between\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eone\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eten\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (inclusive). I don't provide any clues about the number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour first opponent tries to guess the number. They guess randomly.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour second opponent tries to guess the number. They also guess randomly.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou try to guess the number. But you guess\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\u003estrategically\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe winner is the person who guesses my chosen number, or the person who guesses closest to my chosen number. This represents a \\\"win\\\".\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf two contestants are equally close, they may share the win, with such a result being declared a \\\"draw\\\". (It is a loss for the remaining contestant.) A draw is worth half as much as a win.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEach person hears the guesses stated by any preceding competitors, so you will be aware of the two prior guesses (provided to you as the vector\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eguessesOfOpponents\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e). Moreover, each guess must be unique.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf everyone guessed randomly, each person should have an equal chance of winning.\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\u003eIt might seem that you're at a disadvantage, having the last opportunity to guess. But actually you have the advantage of extra knowledge.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBy guessing strategically, you should be able to\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eachieve a success rate of 45% or more\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, in which\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\u003esuccess rate = (wins + draws/2) / games\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRELATED PROBLEM:  \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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/52323\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 52323. Guess the number I'm thinking of (Part 2)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":42485,"title":"Eliminate Outliers Using Interquartile Range","description":"Given a vector with your \"data\" find the outliers and remove them.\r\n\r\nTo determine whether data contains an outlier:\r\n\r\n# Identify the point furthest from the mean of the data.\r\n# Determine whether that point is further than 1.5*IQR away from the mean.\r\n# If so, that point is an outlier and should be eliminated from the data resulting in a new set of data.\r\n# Repeat steps to determine if new data set contains an outlier until dataset no longer contains outlier.\r\n\r\nIQR: Interquartile Range is the range between the median of the upper half and the median of the lower half of data: http://www.wikihow.com/Find-the-IQR\r\n\r\nTo find an outlier by hand:\r\n\r\nData:  [ 53 55 51 50 60 52 ] we will check for outliers.\r\n\r\nSorted: [ 50 *51* 52 53 *55* 60 ]   where the mean is 53.5 and 60 is the furthest away (60-53.5 \u003e 53.5-50).\r\n\r\n1.5 * IQR = 1.5 * (55-51) = 6\r\n\r\nSince 60-53.5 = 6.5 \u003e 6, 60 is an outlier.\r\n\r\nNew Data: [ 53 55 51 50 52 ] we will check for outliers.\r\n\r\nNew Data Sorted: [ *50 51* 52 *53 55* ] where the mean is 52.2 and 55 is the furthest away.\r\n\r\n1.5* IQR = 1.5 * (54-50.5) = 4.5\r\n\r\nSince 55-52.2 = 2.8 \u003c 4.5, 55 is NOT an outlier.\r\n\r\nOur original data had one outlier, which was 60.\r\n\r\nExample:\r\n\r\n  Input data = [53 55 51 50 60 52]\r\n  \r\n  Output new_data = [53 55 51 50 52]\r\n\r\nsince 60 is an outlier, it is removed\r\n\r\n**Note: A number may be repeated within a dataset that is an outlier. You should not remove all instances, but remove only the first instance and check the new dataset to determine whether this number is still an outlier (see 5th test suite).**","description_html":"\u003cp\u003eGiven a vector with your \"data\" find the outliers and remove them.\u003c/p\u003e\u003cp\u003eTo determine whether data contains an outlier:\u003c/p\u003e\u003col\u003e\u003cli\u003eIdentify the point furthest from the mean of the data.\u003c/li\u003e\u003cli\u003eDetermine whether that point is further than 1.5*IQR away from the mean.\u003c/li\u003e\u003cli\u003eIf so, that point is an outlier and should be eliminated from the data resulting in a new set of data.\u003c/li\u003e\u003cli\u003eRepeat steps to determine if new data set contains an outlier until dataset no longer contains outlier.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eIQR: Interquartile Range is the range between the median of the upper half and the median of the lower half of data: \u003ca href = \"http://www.wikihow.com/Find-the-IQR\"\u003ehttp://www.wikihow.com/Find-the-IQR\u003c/a\u003e\u003c/p\u003e\u003cp\u003eTo find an outlier by hand:\u003c/p\u003e\u003cp\u003eData:  [ 53 55 51 50 60 52 ] we will check for outliers.\u003c/p\u003e\u003cp\u003eSorted: [ 50 \u003cb\u003e51\u003c/b\u003e 52 53 \u003cb\u003e55\u003c/b\u003e 60 ]   where the mean is 53.5 and 60 is the furthest away (60-53.5 \u0026gt; 53.5-50).\u003c/p\u003e\u003cp\u003e1.5 * IQR = 1.5 * (55-51) = 6\u003c/p\u003e\u003cp\u003eSince 60-53.5 = 6.5 \u0026gt; 6, 60 is an outlier.\u003c/p\u003e\u003cp\u003eNew Data: [ 53 55 51 50 52 ] we will check for outliers.\u003c/p\u003e\u003cp\u003eNew Data Sorted: [ \u003cb\u003e50 51\u003c/b\u003e 52 \u003cb\u003e53 55\u003c/b\u003e ] where the mean is 52.2 and 55 is the furthest away.\u003c/p\u003e\u003cp\u003e1.5* IQR = 1.5 * (54-50.5) = 4.5\u003c/p\u003e\u003cp\u003eSince 55-52.2 = 2.8 \u0026lt; 4.5, 55 is NOT an outlier.\u003c/p\u003e\u003cp\u003eOur original data had one outlier, which was 60.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput data = [53 55 51 50 60 52]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eOutput new_data = [53 55 51 50 52]\r\n\u003c/pre\u003e\u003cp\u003esince 60 is an outlier, it is removed\u003c/p\u003e\u003cp\u003e\u003cb\u003e*Note: A number may be repeated within a dataset that is an outlier. You should not remove all instances, but remove only the first instance and check the new dataset to determine whether this number is still an outlier (see 5th test suite).*\u003c/b\u003e\u003c/p\u003e","function_template":"function new_data = remove_outlier(data)\r\n  new_data = data;\r\nend","test_suite":"%%\r\ndata = [53,55,51,50,60,52];\r\ncorrect_data = [53,55,51,50,52];\r\nassert(isequal(remove_outlier(data),correct_data))\r\n\r\n%%\r\ndata = [0,0,0,0,0];\r\ncorrect_data = [0,0,0,0,0];\r\nassert(isequal(remove_outlier(data),correct_data))\r\n\r\n%%\r\ndata = [1,2,3,4,5,100,100,6,7,8];\r\ncorrect_data = [1,2,3,4,5,6,7,8];\r\nassert(isequal(remove_outlier(data),correct_data))\r\n\r\n%%\r\ndata = [-54,-30,-45,-40,0,-33];\r\ncorrect_data = [-54,-30,-45,-40,-33];\r\nassert(isequal(remove_outlier(data),correct_data))\r\n\r\n%%\r\ndata = [63,64,64,63,53,61,65,63,52,50,65,61,68,137,62,60,64,67,65,63,63,63];\r\ncorrect_data = [63,64,64,63,65,63,65,62,64,65,63,63,63];\r\nassert(isequal(remove_outlier(data),correct_data))\r\n\r\n%%\r\ndata = [1,2,3,4,5,6,7];\r\ncorrect_data = [1,2,3,4,5,6,7];\r\nassert(isequal(remove_outlier(data),correct_data))","published":true,"deleted":false,"likes_count":3,"comments_count":7,"created_by":47261,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":28,"test_suite_updated_at":"2015-08-04T14:24:26.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-08-03T19:32:53.000Z","updated_at":"2025-11-21T18:38:11.000Z","published_at":"2015-08-03T19:41:30.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 vector with your \\\"data\\\" find the outliers and remove them.\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 determine whether data contains an outlier:\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\u003eIdentify the point furthest from the mean of the data.\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\u003eDetermine whether that point is further than 1.5*IQR away from the mean.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf so, that point is an outlier and should be eliminated from the data resulting in a new set of data.\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\u003eRepeat steps to determine if new data set contains an outlier until dataset no longer contains outlier.\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\u003eIQR: Interquartile Range is the range between the median of the upper half and the median of the lower half of data:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.wikihow.com/Find-the-IQR\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://www.wikihow.com/Find-the-IQR\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo find an outlier by hand:\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\u003eData: [ 53 55 51 50 60 52 ] we will check for outliers.\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\u003eSorted: [ 50\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e51\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 52 53\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e55\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 60 ] where the mean is 53.5 and 60 is the furthest away (60-53.5 \u0026gt; 53.5-50).\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.5 * IQR = 1.5 * (55-51) = 6\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSince 60-53.5 = 6.5 \u0026gt; 6, 60 is an outlier.\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\u003eNew Data: [ 53 55 51 50 52 ] we will check for outliers.\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\u003eNew Data Sorted: [\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e50 51\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 52\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e53 55\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ] where the mean is 52.2 and 55 is the furthest away.\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.5* IQR = 1.5 * (54-50.5) = 4.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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSince 55-52.2 = 2.8 \u0026lt; 4.5, 55 is NOT an outlier.\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\u003eOur original data had one outlier, which was 60.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input data = [53 55 51 50 60 52]\\n\\nOutput new_data = [53 55 51 50 52]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003esince 60 is an outlier, it is removed\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e*Note: A number may be repeated within a dataset that is an outlier. You should not remove all instances, but remove only the first instance and check the new dataset to determine whether this number is still an outlier (see 5th test suite).\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e*\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"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":44277,"title":"Given n, create n random numbers such that their standard deviation is also n.","description":"Given n, create n random numbers such that their standard deviation is also n.","description_html":"\u003cp\u003eGiven n, create n random numbers such that their standard deviation is also n.\u003c/p\u003e","function_template":"function y = randpro(n)\r\n  y = n+3;\r\nend","test_suite":"%%\r\nx = 10;\r\nassert(length(randpro(x))==10)\r\nassert(std(randpro(x))\u003e9)\r\nassert(std(randpro(x))\u003c11)\r\n\r\n%%\r\nx = 17;\r\nassert(length(randpro(x))==17)\r\nassert(std(randpro(x))\u003e16)\r\nassert(std(randpro(x))\u003c18)\r\n\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":204,"test_suite_updated_at":"2017-08-06T19:53:33.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-08-06T19:46:05.000Z","updated_at":"2026-02-11T03:12:53.000Z","published_at":"2017-08-06T19:53:33.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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 n, create n random numbers such that their standard deviation is also n.\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":44451,"title":"Rate of event occurence:  find percentiles of the distribution  (for smallish rates)","description":"*In this problem you need to find the 5th and 95th percentiles of a Poisson distribution defined by parameter _μ_ (the mean rate parameter).*\r\n\r\n_What follows is just a longer introduction to the concepts, including two examples._  \r\n\r\nSay that you manage the inventory of a business for which orders *on average* come in at a known rate (daily, say), but for any given period the number of orders can be somewhat above or somewhat below the expected value.  If it helps your motivation, you can imagine you're running a stall selling vegan sausages, or in booth handing out free beer, or at a barbecue serving pancakes, ....  \r\n\r\nThe variable of interest, N, is the number of customers/orders within a given period — one day, let's say.  The average rate multiplied by the period of interest yields the mean of the distribution (in this problem), which is the 'expected value', or average.  \r\n\r\nIn this problem, N follows a *\u003chttps://www.britannica.com/topic/Poisson-distribution Poisson distribution\u003e* :\r\nN ~ Poisson(μ).  \r\nSo there is no influence of any external factors (weather, trends, etc.).  The only parameter having a deterministic effect is μ.  \r\n\r\nThen the probability of having k customers in a period, given the expected number of customers in that period being equal to μ, is given by:  \r\nPr(N=k) = μ^k × exp(−μ) / k!\r\n\r\nThe caret (^) represents the power operator, and the exclamation mark (!) represents the factorial operation.  \r\n\r\nIf μ and k are given, it is therefore straightforward to compute the probability, Pr(N=k), using the above formula.  \r\n\r\nHowever, in this problem you will be given μ, representing the mean ('expected') daily rate, and you thereby need to determine _two_ values of k:\r\n\r\n* A _lower_ limit on the number of customers, k, for which a lower demand will not be faced more than 5% of the time\r\n* An _upper_ limit on the number of customers, k, that will not be exceeded more than 5% of the time\r\n\r\nHence, you will be sure that, in the long run, the number of customers you see each day will not often (no more than 10% of the time) be outside the range specified by the above two limits.  \r\n\r\nEXAMPLE 1:\r\n\r\n  % Input\r\n  mu = 10\r\n  % Output\r\n  lowerLimit = 4\r\n  upperLimit = 15\r\n  safeLimits = [lowerLimit upperLimit]\r\n\r\nNote that the outputs shall be integers, because there is no physical meaning to 'half a customer'.  \r\n\r\nEXAMPLE 2:\r\n\r\n  % Input\r\n  mu = 100\r\n  % Output\r\n  lowerLimit = 83\r\n  upperLimit = 117\r\n  safeLimits = [lowerLimit upperLimit]\r\n\r\nNOTE:  the two limits are returned as the vector safeLimits, as shown.\r\n\r\n|NOTE:  Toolbox functions are generally not available from within Cody.|","description_html":"\u003cp\u003e\u003cb\u003eIn this problem you need to find the 5th and 95th percentiles of a Poisson distribution defined by parameter \u003ci\u003eμ\u003c/i\u003e (the mean rate parameter).\u003c/b\u003e\u003c/p\u003e\u003cp\u003e\u003ci\u003eWhat follows is just a longer introduction to the concepts, including two examples.\u003c/i\u003e\u003c/p\u003e\u003cp\u003eSay that you manage the inventory of a business for which orders \u003cb\u003eon average\u003c/b\u003e come in at a known rate (daily, say), but for any given period the number of orders can be somewhat above or somewhat below the expected value.  If it helps your motivation, you can imagine you're running a stall selling vegan sausages, or in booth handing out free beer, or at a barbecue serving pancakes, ....\u003c/p\u003e\u003cp\u003eThe variable of interest, N, is the number of customers/orders within a given period — one day, let's say.  The average rate multiplied by the period of interest yields the mean of the distribution (in this problem), which is the 'expected value', or average.\u003c/p\u003e\u003cp\u003eIn this problem, N follows a \u003cb\u003e\u003ca href = \"https://www.britannica.com/topic/Poisson-distribution\"\u003ePoisson distribution\u003c/a\u003e\u003c/b\u003e :\r\nN ~ Poisson(μ).  \r\nSo there is no influence of any external factors (weather, trends, etc.).  The only parameter having a deterministic effect is μ.\u003c/p\u003e\u003cp\u003eThen the probability of having k customers in a period, given the expected number of customers in that period being equal to μ, is given by:  \r\nPr(N=k) = μ^k × exp(−μ) / k!\u003c/p\u003e\u003cp\u003eThe caret (^) represents the power operator, and the exclamation mark (!) represents the factorial operation.\u003c/p\u003e\u003cp\u003eIf μ and k are given, it is therefore straightforward to compute the probability, Pr(N=k), using the above formula.\u003c/p\u003e\u003cp\u003eHowever, in this problem you will be given μ, representing the mean ('expected') daily rate, and you thereby need to determine \u003ci\u003etwo\u003c/i\u003e values of k:\u003c/p\u003e\u003cul\u003e\u003cli\u003eA \u003ci\u003elower\u003c/i\u003e limit on the number of customers, k, for which a lower demand will not be faced more than 5% of the time\u003c/li\u003e\u003cli\u003eAn \u003ci\u003eupper\u003c/i\u003e limit on the number of customers, k, that will not be exceeded more than 5% of the time\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eHence, you will be sure that, in the long run, the number of customers you see each day will not often (no more than 10% of the time) be outside the range specified by the above two limits.\u003c/p\u003e\u003cp\u003eEXAMPLE 1:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e% Input\r\nmu = 10\r\n% Output\r\nlowerLimit = 4\r\nupperLimit = 15\r\nsafeLimits = [lowerLimit upperLimit]\r\n\u003c/pre\u003e\u003cp\u003eNote that the outputs shall be integers, because there is no physical meaning to 'half a customer'.\u003c/p\u003e\u003cp\u003eEXAMPLE 2:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e% Input\r\nmu = 100\r\n% Output\r\nlowerLimit = 83\r\nupperLimit = 117\r\nsafeLimits = [lowerLimit upperLimit]\r\n\u003c/pre\u003e\u003cp\u003eNOTE:  the two limits are returned as the vector safeLimits, as shown.\u003c/p\u003e\u003cp\u003e\u003ctt\u003eNOTE:  Toolbox functions are generally not available from within Cody.\u003c/tt\u003e\u003c/p\u003e","function_template":"% Here you can describe your strategy.\r\nfunction safeLimits = getLimits(mu)\r\n    % Here you can write your code.\r\nend","test_suite":"%% From EXAMPLE 1\r\nmu = 10;\r\nsafeLimits = [4 15];\r\nassert(isequal(getLimits(mu), safeLimits))\r\n\r\n%% From EXAMPLE 2:\r\nmu = 100;\r\nsafeLimits = [83 117];\r\nassert(isequal(getLimits(mu), safeLimits))\r\n\r\n%% Handle lower limit of zero:\r\nmu = 3;\r\nsafeLimits = [0 6];\r\nassert(isequal(getLimits(mu), safeLimits))\r\n\r\n%%\r\nmu = 30;\r\nsafeLimits = [20 39];\r\nassert(isequal(getLimits(mu), safeLimits))\r\n\r\n%%\r\nmu = 4;\r\nsafeLimits = [0 8];\r\nassert(isequal(getLimits(mu), safeLimits))\r\n\r\n%%\r\nmu = 40;\r\nsafeLimits = [29 51];\r\nassert(isequal(getLimits(mu), safeLimits))\r\n\r\n%%\r\nmu = 11;\r\nsafeLimits = [5 17];\r\nassert(isequal(getLimits(mu), safeLimits))\r\n\r\n%%\r\nmu = 12;\r\nsafeLimits = [6 18];\r\nassert(isequal(getLimits(mu), safeLimits))\r\n\r\n%%\r\nmu = 13;\r\nsafeLimits = [6 19];\r\nassert(isequal(getLimits(mu), safeLimits))\r\n\r\n%%\r\nmu = 14;\r\nsafeLimits = [7 20];\r\nassert(isequal(getLimits(mu), safeLimits))\r\n\r\n%%\r\nmu = 15;\r\nsafeLimits = [8 22];\r\nassert(isequal(getLimits(mu), safeLimits))\r\n\r\n%%\r\nmu = 20;\r\nsafeLimits = [12 28];\r\nassert(isequal(getLimits(mu), safeLimits))\r\n\r\n%%\r\nmu = 110;\r\nsafeLimits = [92 128];\r\nassert(isequal(getLimits(mu), safeLimits))\r\n\r\n%%\r\nmu = 120;\r\nsafeLimits = [101 138];\r\nassert(isequal(getLimits(mu), safeLimits))\r\n\r\n\r\n%% High rates\r\n% Not asserted in this problem\r\n\r\nmu = 150;\r\nsafeLimits = [129 170];\r\n%assert(isequal(getLimits(mu), safeLimits))\r\n\r\nmu = 200;\r\nsafeLimits = [176 224];\r\n%assert(isequal(getLimits(mu), safeLimits))\r\n\r\nmu = 300;\r\nsafeLimits = [271 329];\r\n%assert(isequal(getLimits(mu), safeLimits))\r\n\r\nmu = 1000;\r\nsafeLimits = [947 1052];\r\n%assert(isequal(getLimits(mu), safeLimits))","published":true,"deleted":false,"likes_count":2,"comments_count":5,"created_by":64439,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":12,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-13T04:58:52.000Z","updated_at":"2025-11-21T18:54:27.000Z","published_at":"2017-12-13T07:41:31.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eIn this problem you need to find the 5th and 95th percentiles of a Poisson distribution defined by parameter\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eμ\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e (the mean rate parameter).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eWhat follows is just a longer introduction to the concepts, including two examples.\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\u003eSay that you manage the inventory of a business for which orders\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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eon average\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e come in at a known rate (daily, say), but for any given period the number of orders can be somewhat above or somewhat below the expected value. If it helps your motivation, you can imagine you're running a stall selling vegan sausages, or in booth handing out free beer, or at a barbecue serving pancakes, ....\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 variable of interest, N, is the number of customers/orders within a given period — one day, let's say. The average rate multiplied by the period of interest yields the mean of the distribution (in this problem), which is the 'expected value', or average.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn this problem, N follows a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.britannica.com/topic/Poisson-distribution\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ePoisson distribution\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e : N ~ Poisson(μ). So there is no influence of any external factors (weather, trends, etc.). The only parameter having a deterministic effect is μ.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThen the probability of having k customers in a period, given the expected number of customers in that period being equal to μ, is given by: Pr(N=k) = μ^k × exp(−μ) / k!\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 caret (^) represents the power operator, and the exclamation mark (!) represents the factorial operation.\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 μ and k are given, it is therefore straightforward to compute the probability, Pr(N=k), using the above formula.\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\u003eHowever, in this problem you will be given μ, representing the mean ('expected') daily rate, and you thereby need to determine\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\u003etwo\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e values of k:\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\u003eA\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\u003elower\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e limit on the number of customers, k, for which a lower demand will not be faced more than 5% of the time\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\u003eAn\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\u003eupper\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e limit on the number of customers, k, that will not be exceeded more than 5% of the time\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\u003eHence, you will be sure that, in the long run, the number of customers you see each day will not often (no more than 10% of the time) be outside the range specified by the above two limits.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEXAMPLE 1:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[% Input\\nmu = 10\\n% Output\\nlowerLimit = 4\\nupperLimit = 15\\nsafeLimits = [lowerLimit upperLimit]]]\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\u003eNote that the outputs shall be integers, because there is no physical meaning to 'half a customer'.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEXAMPLE 2:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[% Input\\nmu = 100\\n% Output\\nlowerLimit = 83\\nupperLimit = 117\\nsafeLimits = [lowerLimit upperLimit]]]\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\u003eNOTE: the two limits are returned as the vector safeLimits, as shown.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNOTE: Toolbox functions are generally not available from within Cody.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"no_progress_badge":{"id":53,"name":"Unknown","symbol":"unknown","description":"Partially completed groups","description_html":null,"image_location":"/images/responsive/supporting/matlabcentral/cody/badges/problem_groups_unknown_2.png","bonus":null,"players_count":0,"active":false,"created_by":null,"updated_by":null,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"created_at":"2018-01-10T23:20:29.000Z","updated_at":"2018-01-10T23:20:29.000Z","community_badge_id":null,"award_multiples":false}}