{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-04-06T14:01:22.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2026-04-06T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":60956,"title":"P(girl likes you | she smiled at you)","description":"Compute the probability\r\n\r\n\r\n\r\nGiven the input probabilities\r\n\r\n\r\n\r\n\r\n\r\n\r\n","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: 401.867px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 408px 200.933px; transform-origin: 408px 200.933px; 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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 80.4833px 8px; transform-origin: 80.4833px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eCompute the probability\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 8px; transform-origin: 0px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 21.7167px; counter-reset: list-item 0; 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: 392px 10.8583px; transform-origin: 392px 10.8583px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"counter-reset: none; 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: 364px 10.8583px; text-align: left; transform-origin: 364px 10.8583px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"vertical-align:-6px\"\u003e\u003cimg src=\"data:image/png;base64,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\" width=\"283.5\" height=\"20\" style=\"width: 283.5px; height: 20px;\"\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 8px; transform-origin: 0px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 94.4667px 8px; transform-origin: 94.4667px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eGiven the input probabilities\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 8px; transform-origin: 0px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 21.7167px; counter-reset: list-item 0; 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: 392px 10.8583px; transform-origin: 392px 10.8583px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"counter-reset: none; 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: 364px 10.8583px; text-align: left; transform-origin: 364px 10.8583px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"vertical-align:-6px\"\u003e\u003cimg src=\"data:image/png;base64,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\" width=\"279\" height=\"20\" style=\"width: 279px; height: 20px;\"\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 8px; transform-origin: 0px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 21.7167px; counter-reset: list-item 0; 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: 392px 10.8583px; transform-origin: 392px 10.8583px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"counter-reset: none; 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: 364px 10.8583px; text-align: left; transform-origin: 364px 10.8583px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"vertical-align:-6px\"\u003e\u003cimg src=\"data:image/png;base64,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\" width=\"142.5\" height=\"20\" style=\"width: 142.5px; height: 20px;\"\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 8px; transform-origin: 0px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 21.7167px; counter-reset: list-item 0; 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: 392px 10.8583px; transform-origin: 392px 10.8583px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"counter-reset: none; 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: 364px 10.8583px; text-align: left; transform-origin: 364px 10.8583px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"vertical-align:-6px\"\u003e\u003cimg src=\"data:image/png;base64,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\" width=\"224\" height=\"20\" style=\"width: 224px; height: 20px;\"\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 8px; transform-origin: 0px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function P_LS = verify_bayes_theorem(P_SL, P_L, P_S)\r\n  P_LS = P_SL;\r\nend","test_suite":"%%\r\nP_SL = 0.99;\r\nP_L  = 1/3;\r\nP_S  = 0.5;\r\nP_LS_correct = 0.66;\r\nP_LS = verify_bayes_theorem(P_SL,P_L,P_S);\r\nassert(abs(P_LS_correct-P_LS) \u003c eps)\r\n\r\n%%\r\nP_SL = 0.75;\r\nP_L  = 1/5;\r\nP_S  = 0.25;\r\nP_LS_correct = 0.6;\r\nP_LS = verify_bayes_theorem(P_SL,P_L,P_S);\r\nassert(abs(P_LS_correct-P_LS) \u003c eps)\r\n\r\n%% Test forbidden functions\r\nfiletext = fileread('verify_bayes_theorem.m');\r\nillegal = contains(filetext, 'regexp') || contains(filetext, 'str2num') || contains(filetext, 'assignin') || contains(filetext, 'echo')\r\nassert(~illegal);","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":149128,"edited_by":149128,"edited_at":"2025-07-10T07:02:07.000Z","deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":"2025-07-10T07:02:07.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2025-07-08T12:54:24.000Z","updated_at":"2026-03-27T11:28:52.000Z","published_at":"2025-07-08T13:17:57.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eCompute the probability\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=\\\"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:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"true\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eP_{LS} = P(girl ~likes ~ you ~ | ~ she ~ smiled ~ at ~ you) \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\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\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\u003eGiven the input probabilities\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=\\\"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:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"true\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eP_{SL} = P(she ~ smiles ~ at ~ you ~ | ~ she ~ likes ~ you)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\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=\\\"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:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"true\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eP_L = P(she ~likes ~ you) \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\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=\\\"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:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"true\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eP_S = P(she ~ just ~ smiles ~ in ~ general) \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\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\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":58688,"title":"Bag of apples","description":"find probabilty of getting red apples from a bag of 'r' red and 'g' green apples.","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: 21px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 10.5px; transform-origin: 407px 10.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003efind probabilty of getting red apples from a bag of 'r' red and 'g' green apples.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(r,g)\r\n  y = x;\r\nend","test_suite":"%%\r\nr = 5;\r\ng = 5\r\ny_correct = 0.5;\r\nassert(isequal(your_fcn_name(r,g),y_correct))\r\n\r\n%%\r\nr = 0;\r\ng = 5\r\ny_correct = 0;\r\nassert(isequal(your_fcn_name(r,g),y_correct))\r\n\r\n%%\r\nr = 5;\r\ng = 0;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(r,g),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":3495088,"edited_by":3495088,"edited_at":"2023-07-18T16:03:10.000Z","deleted_by":null,"deleted_at":null,"solvers_count":54,"test_suite_updated_at":"2023-07-18T16:03:10.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2023-07-18T15:56:56.000Z","updated_at":"2026-04-08T13:01:47.000Z","published_at":"2023-07-18T16:02:08.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003efind probabilty of getting red apples from a bag of 'r' red and 'g' green apples.\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":44005,"title":"Probability of red tulips","description":"I hope to give you bulbs of tulip. But I do not know the color of those petals. I just know that the color is red, white or yellow.\r\n\r\nInput (x): Number of bulbs\r\n\r\nOutput (y): Probability that ALL are RED tulips\r\n","description_html":"\u003cp\u003eI hope to give you bulbs of tulip. But I do not know the color of those petals. I just know that the color is red, white or yellow.\u003c/p\u003e\u003cp\u003eInput (x): Number of bulbs\u003c/p\u003e\u003cp\u003eOutput (y): Probability that ALL are RED tulips\u003c/p\u003e","function_template":"function y = red_tulip(x)\r\n  y = 1/3;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 1/3;\r\nassert(isequal(red_tulip(x),y_correct))\r\n\r\n%%\r\nx = 3;\r\ny_correct = (1/3)^3;\r\nassert(isequal(red_tulip(x),y_correct))\r\n\r\n%%\r\nx = 10;\r\ny_correct = (1/3)^10;\r\nassert(isequal(red_tulip(x),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":102298,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":80,"test_suite_updated_at":"2017-07-07T16:39:42.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-01-16T07:35:21.000Z","updated_at":"2025-12-16T06:35:21.000Z","published_at":"2017-07-07T16:39: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\",\"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 hope to give you bulbs of tulip. But I do not know the color of those petals. I just know that the color is red, white or yellow.\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 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): Probability that ALL are RED tulips\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":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":48945,"title":"Would you win a raffle?","description":null,"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: 42px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 343px 21px; transform-origin: 343px 21px; vertical-align: baseline; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 320px 21px; text-align: left; transform-origin: 320px 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=\"\"\u003eWhat is the probability of win a raffle? You're given your entries and total entries. Round the solution to 4 decimals.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = raffle(e,et)\r\n    y = x;\r\nend","test_suite":"%%\r\ne=5;\r\nte=243;\r\nassert(isequal(raffle(e,te),2.0576))\r\n%%\r\ne=5;\r\nte=20561;\r\nassert(isequal(raffle(e,te),0.0243))\r\n%%\r\ne=1;\r\nte=1005;\r\nassert(isequal(raffle(e,te),0.0995))\r\n%%\r\ne=1;\r\nte=321;\r\nassert(isequal(raffle(e,te),0.3115))","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":698530,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":23,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-12-22T13:59:36.000Z","updated_at":"2026-02-18T10:10:20.000Z","published_at":"2020-12-31T01:15:19.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\u003eWhat is the probability of win a raffle? You're given your entries and total entries. Round the solution to 4 decimals.\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":44272,"title":"Generate one sample of uniform random numbers between -pi and +pi","description":"Generate one sample of uniform random numbers between -pi and +pi.","description_html":"\u003cp\u003eGenerate one sample of uniform random numbers between -pi and +pi.\u003c/p\u003e","function_template":"function y = rndpi(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nw=0;\r\nfor k=1:10^3\r\n    w=w+rndpi(1);\r\nend\r\n    \r\nassert(w\u003c1000)\r\n\r\n%%\r\nw=0;\r\nfor k=1:10^3\r\n    w=w+rndpi(1)^2;\r\nend\r\n    \r\nassert(w\u003e10^3)\r\n\r\n%% \r\nw=0;\r\nfor k=1:10^3\r\n    w=min(w,rndpi(1));\r\nend\r\n\r\nassert(w\u003c-pi*0.9)\r\nassert(w\u003e-pi*1.1)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":"2017-08-02T00:03:53.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-08-01T23:59:01.000Z","updated_at":"2026-04-03T06:50:32.000Z","published_at":"2017-08-01T23:59:07.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\u003eGenerate one sample of uniform random numbers between -pi and +pi.\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":700,"title":"Monty Hall","description":"The classic Monty Hall \"Let's Make a Deal\" final showcase puzzle pits the contestant against three Doors. Behind one Door are dream prizes and behind the other two are Donkeys and Chickens. \r\n\r\nThe contestant picks a Door: 1 2 or 3.\r\n\r\nMonty then reveals a Door that is Not the winner.\r\n\r\nAs the contestant do you stay with your original Door or swap to the other Door?\r\n\r\nYour routine will be called twice. \r\n\r\nThe first time it will see [0 0 0]. You are to select a Door: return an Integer 1,2 or 3.\r\n\r\nThe second time your function will see [1 2 0] or [1 0 2],if you had selected door number 1. The 2 denotes a revealed Losing Door.\r\n\r\nYou may now choose Door 1 (no change) or switch to the available door denoted by the zero. \r\n\r\nReturn an Integer 1, 2, or 3\r\n\r\nExample:\r\n\r\nInput [0 0 0]\r\n\r\nOutput 2\r\n\r\nInput [0 1 2] % Your first selection is denoted by 1. 2 is a losing Door\r\n\r\nOutput 1  % This selects Door 1, swapping from Door 2\r\n\r\nThe Test engine will determine if your final selection is a Winner\r\n\r\nThe routine will run the game 100 times calling your function twice for every game.\r\n\r\nYour Strategy \"Passes\" if it wins \u003e 50% of the time.\r\n\r\nThis is the first in a series of planned interactive Games.\r\n\r\nThis example is also to demonstrate Cody multi-call interactivity capability.\r\n\r\n\r\nLet's Make a Deal","description_html":"\u003cp\u003eThe classic Monty Hall \"Let's Make a Deal\" final showcase puzzle pits the contestant against three Doors. Behind one Door are dream prizes and behind the other two are Donkeys and Chickens.\u003c/p\u003e\u003cp\u003eThe contestant picks a Door: 1 2 or 3.\u003c/p\u003e\u003cp\u003eMonty then reveals a Door that is Not the winner.\u003c/p\u003e\u003cp\u003eAs the contestant do you stay with your original Door or swap to the other Door?\u003c/p\u003e\u003cp\u003eYour routine will be called twice.\u003c/p\u003e\u003cp\u003eThe first time it will see [0 0 0]. You are to select a Door: return an Integer 1,2 or 3.\u003c/p\u003e\u003cp\u003eThe second time your function will see [1 2 0] or [1 0 2],if you had selected door number 1. The 2 denotes a revealed Losing Door.\u003c/p\u003e\u003cp\u003eYou may now choose Door 1 (no change) or switch to the available door denoted by the zero.\u003c/p\u003e\u003cp\u003eReturn an Integer 1, 2, or 3\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003eInput [0 0 0]\u003c/p\u003e\u003cp\u003eOutput 2\u003c/p\u003e\u003cp\u003eInput [0 1 2] % Your first selection is denoted by 1. 2 is a losing Door\u003c/p\u003e\u003cp\u003eOutput 1  % This selects Door 1, swapping from Door 2\u003c/p\u003e\u003cp\u003eThe Test engine will determine if your final selection is a Winner\u003c/p\u003e\u003cp\u003eThe routine will run the game 100 times calling your function twice for every game.\u003c/p\u003e\u003cp\u003eYour Strategy \"Passes\" if it wins \u003e 50% of the time.\u003c/p\u003e\u003cp\u003eThis is the first in a series of planned interactive Games.\u003c/p\u003e\u003cp\u003eThis example is also to demonstrate Cody multi-call interactivity capability.\u003c/p\u003e\u003cp\u003eLet's Make a Deal\u003c/p\u003e","function_template":"function y = Monty(doors)\r\n% First call will see doors=[0 0 0]\r\n% Second call will see a permutation of [0 1 2], depending on first response\r\n% In the second call the \"2\" denotes a revealed Losing door\r\n  y = 1;\r\nend","test_suite":"%%\r\nwin=0;\r\nPass=0;\r\nfor i=1:100\r\n    \r\n prize=randi(3);\r\n doors=[0 0 0];\r\n \r\n pick=Monty(doors);\r\n \r\n pick=floor(pick);\r\n if pick\u003c1 || pick\u003e3\r\n  win=0;\r\n  break;\r\n else\r\n  doors(pick)=1;\r\n end\r\n \r\n if pick==prize\r\n % Random select from other doors\r\n  if rand\u003e0.5\r\n   doors(find(doors==0,1))=2;\r\n  else\r\n   doors(find(doors==0,1,'last'))=2;\r\n  end\r\n else % \r\n % Pick other and not prize door\r\n  reveal=setxor(prize,setxor(pick,[1 2 3]));\r\n  doors(reveal)=2;\r\n end\r\n \r\n pick=Monty(doors);\r\n\r\n pick=floor(pick);\r\n if pick==prize\r\n  win=win+1;\r\n end\r\n \r\n \r\nend % Monty Loops\r\nwin % Display number of wins\r\nif win\u003e50,Pass=1;end\r\nassert(isequal(Pass,1))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-19T08:52:15.000Z","updated_at":"2026-03-24T13:29:28.000Z","published_at":"2012-05-19T08:52:15.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\u003eThe classic Monty Hall \\\"Let's Make a Deal\\\" final showcase puzzle pits the contestant against three Doors. Behind one Door are dream prizes and behind the other two are Donkeys and Chickens.\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 contestant picks a Door: 1 2 or 3.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMonty then reveals a Door that is Not the winner.\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\u003eAs the contestant do you stay with your original Door or swap to the other Door?\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 routine will be called twice.\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 first time it will see [0 0 0]. You are to select a Door: return an Integer 1,2 or 3.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe second time your function will see [1 2 0] or [1 0 2],if you had selected door number 1. The 2 denotes a revealed Losing Door.\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 may now choose Door 1 (no change) or switch to the available door denoted by the zero.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn an Integer 1, 2, or 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput [0 0 0]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput [0 1 2] % Your first selection is denoted by 1. 2 is a losing Door\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 1 % This selects Door 1, swapping from Door 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe Test engine will determine if your final selection is a Winner\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 routine will run the game 100 times calling your function twice for every 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour Strategy \\\"Passes\\\" if it wins \u003e 50% 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is the first in a series of planned interactive 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\u003eThis example is also to demonstrate Cody multi-call interactivity capability.\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\u003eLet's Make a Deal\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":510,"title":"Selecting books on MATLAB for experts and beginners (blindfolded)","description":"* Imagine you have been blindfolded and asked to pick up any two books randomly from the table. \r\n* There are n books suitable for \u003chttp://www.mathworks.com MATLAB\u003e experts and n books suitable for beginners, \r\n* Total 2*n books on the table. \r\n* What is the probability that you will pick up exactly one for experts and one beginners?    ","description_html":"\u003cul\u003e\u003cli\u003eImagine you have been blindfolded and asked to pick up any two books randomly from the table.\u003c/li\u003e\u003cli\u003eThere are n books suitable for \u003ca href=\"http://www.mathworks.com\"\u003eMATLAB\u003c/a\u003e experts and n books suitable for beginners,\u003c/li\u003e\u003cli\u003eTotal 2*n books on the table.\u003c/li\u003e\u003cli\u003eWhat is the probability that you will pick up exactly one for experts and one beginners?\u003c/li\u003e\u003c/ul\u003e","function_template":"function mychance = need2(n)\r\n   mychance=50/50;\r\nend","test_suite":"%%\r\nassert(abs(need2(1)-1)\u003c0.001)\r\n%%\r\nassert(abs(need2(2)-0.6667)\u003c0.001)\r\n%%\r\nassert(abs(need2(10)-0.5263)\u003c0.001)\r\n%%\r\nassert(abs(need2(100)-0.5025)\u003c0.001)\r\n%%\r\nassert(abs(need2(1000)-0.5003)\u003c0.001)\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":82,"test_suite_updated_at":"2012-03-20T07:21:43.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-03-20T07:21:43.000Z","updated_at":"2026-03-19T06:46:04.000Z","published_at":"2012-03-20T07:21: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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eImagine you have been blindfolded and asked to pick up any two books randomly from the table.\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\u003eThere are n books suitable for\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\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eMATLAB\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e experts and n books suitable for beginners,\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\u003eTotal 2*n books on the table.\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\u003eWhat is the probability that you will pick up exactly one for experts and one beginners?\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":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":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":2030,"title":"A Poker Hand","description":"Texas Hold ‘Em is a classical card game. In this problem, we are concerned with determining the probability of attaining a certain type of hand.\r\n\r\nA “Full House” is a five card hand comprised composed of two sets: a set of three of a kind, and a set of two of a kind. Examples include: K-K-K-Q-Q, 10-10-10-5-5, and A-A-A-4-4.\r\n\r\nAssuming that there are 52 cards in a unique, distinguishable deck, find the probability of attaining a “Full House” in any given hand. You may assume that there are 9 players playing on a full table.\r\n","description_html":"\u003cp\u003eTexas Hold ‘Em is a classical card game. In this problem, we are concerned with determining the probability of attaining a certain type of hand.\u003c/p\u003e\u003cp\u003eA “Full House” is a five card hand comprised composed of two sets: a set of three of a kind, and a set of two of a kind. Examples include: K-K-K-Q-Q, 10-10-10-5-5, and A-A-A-4-4.\u003c/p\u003e\u003cp\u003eAssuming that there are 52 cards in a unique, distinguishable deck, find the probability of attaining a “Full House” in any given hand. You may assume that there are 9 players playing on a full table.\u003c/p\u003e","function_template":"function y = fullHouse(x)\r\nx=52; %number of cards in a deck\r\n%siginificant to 7 digits (for luck)\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 0.0144058;\r\nassert(isequal(fullHouse(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":16441,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":30,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-12-02T07:52:42.000Z","updated_at":"2025-06-08T09:16:04.000Z","published_at":"2013-12-02T08:00:04.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\u003eTexas Hold ‘Em is a classical card game. In this problem, we are concerned with determining the probability of attaining a certain type of 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA “Full House” is a five card hand comprised composed of two sets: a set of three of a kind, and a set of two of a kind. Examples include: K-K-K-Q-Q, 10-10-10-5-5, and A-A-A-4-4.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssuming that there are 52 cards in a unique, distinguishable deck, find the probability of attaining a “Full House” in any given hand. You may assume that there are 9 players playing on a full table.\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":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":43126,"title":"Probabilities - Balls and urns - 01","description":"The urn contains B blue balls and R red balls. Each trial consists of drawing one random ball from the urn and observing its color. Then the ball is placed back in the urn.\r\nWhat is the probability that, after N trials, the number of times a red ball is observed is K?","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: 72px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 36px; transform-origin: 407px 36px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 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: 380px 8px; transform-origin: 380px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe urn contains B blue balls and R red balls. Each trial consists of drawing one random ball from the urn and observing its color. Then the ball 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: 42px 8px; transform-origin: 42px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eplaced back\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: 34px 8px; transform-origin: 34px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e in the urn.\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: 280px 8px; transform-origin: 280px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWhat is the probability that, after N trials, the number of times a red ball is observed is K?\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function p = probability(R,B,N,K)\r\n    p = 1;\r\nend","test_suite":"%%\r\nR=4; B=8;\r\nN=50; K=25;\r\np = 0.0059;\r\nassert( abs(probability(R,B,N,K)-p)\u003c1e-04 );\r\n%%\r\nR=22; B=6;\r\nN=32; K=23;\r\np = 0.1042;\r\nassert( abs(probability(R,B,N,K)-p)\u003c1e-04 );\r\n%%\r\nR=2; B=4;\r\nN=25; K=2;\r\np = 0.0030;\r\nassert( abs(probability(R,B,N,K)-p)\u003c1e-04 );\r\n%%\r\nR=0; B=4;\r\nN=25; K=2;\r\nassert( isequal(probability(R,B,N,K),0) );\r\n%%\r\nR=9; B=0;\r\nN=25; K=2;\r\nassert( isequal(probability(R,B,N,K),0) );\r\n%%\r\nR=9; B=0;\r\nN=25; K=25;\r\nassert( isequal(probability(R,B,N,K),1) );","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":85738,"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":"2016-10-06T13:54:47.000Z","updated_at":"2026-01-02T17:59:44.000Z","published_at":"2016-10-06T13:54:47.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 urn contains B blue balls and R red balls. Each trial consists of drawing one random ball from the urn and observing its color. Then the ball 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\u003eplaced back\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in the urn.\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, after N trials, the number of times a red ball is observed is K?\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":52110,"title":"Pick the die most likely to win","description":"After discussing Rock, Paper, Scissors, Lizard, Spock in The Simpsons and their Mathematical Secrets, Simon Singh writes that investor Warren Buffett will challenge people to beat him in a game of dice. He presents three dice and asks the other person to choose one. Then he chooses one, and they roll together. The person with the highest roll wins. \r\nWith standard dice that have one to six pips on their sides, no one has an advantage. However, Mr. Buffett’s dice are different: Although the sum of the numbers on the faces of one die equals the sums for the other dice, the numbers on one die differ from the numbers on the other dice.\r\nFor example, suppose die A has 1, 1, 6, 6, 8, and 8; die B has 3, 3, 5, 5, 7, and 7; and die C has 2, 2, 4, 4, 9, and 9. If the first person chooses die A, then Warren Buffett will choose die C to increase his chances of winning. Write a function that choose the die most likely to win, given the other person’s choice. The input is a matrix with the numbers on the faces of each die in the rows and an index of the die (i.e., row) that the other person chose.","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: 228px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 114px; transform-origin: 407px 114px; vertical-align: baseline; \"\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: 51.3417px 7.79167px; transform-origin: 51.3417px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAfter discussing \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/46072-rock-paper-scissors-lizard-spock\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eRock, Paper, Scissors, Lizard, Spock\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: 9.33333px 7.79167px; transform-origin: 9.33333px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e in \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 143.142px 7.79167px; transform-origin: 143.142px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eThe Simpsons and their Mathematical Secrets\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: 65.45px 7.79167px; transform-origin: 65.45px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, Simon Singh writes that investor Warren Buffett will challenge people to beat him in a game of dice. He presents three dice and asks the other person to choose one. Then he chooses one, and they roll together. The person with the highest roll wins. \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: 362.242px 7.79167px; transform-origin: 362.242px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWith standard dice that have one to six pips on their sides, no one has an advantage. However, Mr. Buffett’s dice are different: Although the sum of the numbers on the faces of one die equals the sums for the other dice, the numbers on one die differ from the numbers on the other dice.\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: 376.833px 7.79167px; transform-origin: 376.833px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, suppose die A has 1, 1, 6, 6, 8, and 8; die B has 3, 3, 5, 5, 7, and 7; and die C has 2, 2, 4, 4, 9, and 9. If the first person chooses die A, then Warren Buffett will choose die C to increase his chances of winning. \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: 64.0417px 7.79167px; transform-origin: 64.0417px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that choose the die most likely to win, given the other person’s choice. The input is a matrix with the numbers on the faces of each die in the rows and an index of the die (i.e., row) that the other person chose.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function d = chooseDie(D,k)\r\n  d = f(D,k);\r\nend","test_suite":"%%\r\nD = [1 1 6 6 8 8; 3 3 5 5 7 7; 2 2 4 4 9 9];\r\nk = 1;\r\nd_correct = 3;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [1 1 6 6 8 8; 3 3 5 5 7 7; 2 2 4 4 9 9];\r\nk = 2;\r\nd_correct = 1;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [1 1 6 6 8 8; 3 3 5 5 7 7; 2 2 4 4 9 9];\r\nk = 3;\r\nd_correct = 2;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 3 4 4 8 8; 1 1 5 5 9 9; 2 2 6 6 7 7];\r\nk = 1;\r\nd_correct = 2;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 3 4 4 8 8; 1 1 5 5 9 9; 2 2 6 6 7 7];\r\nk = 2;\r\nd_correct = 3;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 3 4 4 8 8; 1 1 5 5 9 9; 2 2 6 6 7 7];\r\nk = 3;\r\nd_correct = 1;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [1 6 19 24 26 35; 3 7 21 23 25 32; 2 9 20 22 27 31; 8 10 15 17 28 33; 5 12 14 16 30 34; 4 11 13 18 29 36];\r\nk = 1;\r\nd_correct = 3;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [1 6 19 24 26 35; 3 7 21 23 25 32; 2 9 20 22 27 31; 8 10 15 17 28 33; 5 12 14 16 30 34; 4 11 13 18 29 36];\r\nk = 2;\r\nd_correct = 4;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [1 6 19 24 26 35; 3 7 21 23 25 32; 2 9 20 22 27 31; 8 10 15 17 28 33; 5 12 14 16 30 34; 4 11 13 18 29 36];\r\nk = 3;\r\nd_correct = 2;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [1 6 19 24 26 35; 3 7 21 23 25 32; 2 9 20 22 27 31; 8 10 15 17 28 33; 5 12 14 16 30 34; 4 11 13 18 29 36];\r\nk = 4;\r\nd_correct = 6;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [1 6 19 24 26 35; 3 7 21 23 25 32; 2 9 20 22 27 31; 8 10 15 17 28 33; 5 12 14 16 30 34; 4 11 13 18 29 36];\r\nk = 5;\r\nd_correct = 1;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [1 6 19 24 26 35; 3 7 21 23 25 32; 2 9 20 22 27 31; 8 10 15 17 28 33; 5 12 14 16 30 34; 4 11 13 18 29 36];\r\nk = 6;\r\nd_correct = 5;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 4 8 30 31 35; 1 5 9 28 32 36; 2 6 7 29 33 34; 12 13 17 21 22 26; 10 14 18 19 23 27; 11 15 16 20 24 25];\r\nk = 1;\r\nd_correct = 2;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 4 8 30 31 35; 1 5 9 28 32 36; 2 6 7 29 33 34; 12 13 17 21 22 26; 10 14 18 19 23 27; 11 15 16 20 24 25];\r\nk = 2;\r\nd_correct = 3;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 4 8 30 31 35; 1 5 9 28 32 36; 2 6 7 29 33 34; 12 13 17 21 22 26; 10 14 18 19 23 27; 11 15 16 20 24 25];\r\nk = 3;\r\nd_correct = 1;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 4 8 30 31 35; 1 5 9 28 32 36; 2 6 7 29 33 34; 12 13 17 21 22 26; 10 14 18 19 23 27; 11 15 16 20 24 25];\r\nk = 4;\r\nd_correct = 5;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 4 8 30 31 35; 1 5 9 28 32 36; 2 6 7 29 33 34; 12 13 17 21 22 26; 10 14 18 19 23 27; 11 15 16 20 24 25];\r\nk = 5;\r\nd_correct = 6;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 4 8 30 31 35; 1 5 9 28 32 36; 2 6 7 29 33 34; 12 13 17 21 22 26; 10 14 18 19 23 27; 11 15 16 20 24 25];\r\nk = 6;\r\nd_correct = 4;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":46909,"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":"2021-06-26T14:03:03.000Z","updated_at":"2025-08-26T11:48:35.000Z","published_at":"2021-06-26T14:09:39.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\u003eAfter discussing \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/46072-rock-paper-scissors-lizard-spock\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRock, Paper, Scissors, Lizard, Spock\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eThe Simpsons and their Mathematical Secrets\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, Simon Singh writes that investor Warren Buffett will challenge people to beat him in a game of dice. He presents three dice and asks the other person to choose one. Then he chooses one, and they roll together. The person with the highest roll wins. \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\u003eWith standard dice that have one to six pips on their sides, no one has an advantage. However, Mr. Buffett’s dice are different: Although the sum of the numbers on the faces of one die equals the sums for the other dice, the numbers on one die differ from the numbers on the other dice.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, suppose die A has 1, 1, 6, 6, 8, and 8; die B has 3, 3, 5, 5, 7, and 7; and die C has 2, 2, 4, 4, 9, and 9. If the first person chooses die A, then Warren Buffett will choose die C to increase his chances of winning. \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that choose the die most likely to win, given the other person’s choice. The input is a matrix with the numbers on the faces of each die in the rows and an index of the die (i.e., row) that the other person chose.\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":2267,"title":"Sales Prediction","description":"Miss X is a shopaholic person and every weekend she goes to a mall. There are total of 10 shops. Miss X starts from shop #1 and goes till last shop. Looking at her pattern of shopping from previous week, a shopkeeper wants to predict the probability of her shopping from his shop this weekend.  Can you help the shopkeeper?\r\n\r\nAlso, find the average amount that she spent in last week. \r\n\r\nExample\r\n\r\n item_price = [10 35 2 100 99 87 1 0.5 9 30] \r\n total_items_shopped = [ 2 0 5 10 8 9 1 0 0 1]\r\n\r\n Average spending = $73.22\r\n Probability of shopping from shop# 5 is:0.22\r\n","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: 233px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 116.5px; transform-origin: 407px 116.5px; vertical-align: baseline; \"\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eMiss X is a shopaholic person and every weekend she goes to a mall. There are total of 10 shops. Miss X starts from shop #1 and goes till last shop. Looking at her pattern of shopping from previous week, a shopkeeper wants to predict the probability of her shopping from his shop this weekend. Can you help the shopkeeper?\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=\"\"\u003eAlso, find the average amount that she spent in last week. Round the answer to 2 digits after decimal.\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=\"\"\u003eExample\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 100px; border-bottom-left-radius: 4px; border-bottom-right-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 50px; transform-origin: 404px 50px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20px; border-bottom-left-radius: 0px; border-bottom-right-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-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 10px; transform-origin: 404px 10px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e item_price = [10 35 2 100 99 87 1 0.5 9 30] \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20px; border-bottom-left-radius: 0px; border-bottom-right-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-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 10px; transform-origin: 404px 10px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e total_items_shopped = [ 2 0 5 10 8 9 1 0 0 1]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20px; border-bottom-left-radius: 0px; border-bottom-right-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-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 10px; transform-origin: 404px 10px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20px; border-bottom-left-radius: 0px; border-bottom-right-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-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 10px; transform-origin: 404px 10px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e Average \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); text-decoration: none; text-decoration-color: rgb(170, 4, 249); \"\u003espending = $73.22\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20px; border-bottom-left-radius: 0px; border-bottom-right-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-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 10px; transform-origin: 404px 10px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e Probability \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); text-decoration: none; text-decoration-color: rgb(170, 4, 249); \"\u003eof shopping from shop# 5 is:0.22\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [avg_spending, shop_prob] = Shopping(price, items, shop_no)\r\n  y = x;\r\nend","test_suite":"%%\r\nitem_price = [10 35 2 100 99 87 1 0.5 9 30] ;\r\ntotal_items_shopped = [ 2 0 5 10 8 9 1 0 0 1];\r\nshop_no = 5;\r\n\r\navg_spending =73.22;\r\nshop_prob = 0.22\r\n\r\n[x,y] = Shopping(item_price ,total_items_shopped, shop_no );\r\nassert(isequal([x,y],[avg_spending, shop_prob]))\r\n\r\n\r\n%%\r\n\r\nitem_price = [10 4 22 10 5 7 2 10 95 56] ;\r\ntotal_items_shopped = [ 23 0 0 11 38 0 1 0 0 0];\r\nshop_no = 7;\r\n\r\navg_spending =7.29;\r\n\r\nshop_prob = 0.01\r\n\r\n[x,y] = Shopping(item_price ,total_items_shopped, shop_no );\r\nassert(isequal([x,y],[avg_spending, shop_prob]))\r\n\r\n%%\r\nitem_price = ones(1, 10) ; %dollar shoppie \r\ntotal_items_shopped = [ 1 0 3 4 8 9 0 5 0 10];\r\nshop_no = 10;\r\n\r\navg_spending = 1;\r\n\r\nshop_prob = 0.25;\r\n\r\n[x,y] = Shopping(item_price ,total_items_shopped, shop_no );\r\nassert(isequal([x,y],[avg_spending, shop_prob]))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":26,"test_suite_updated_at":"2014-04-01T22:38:37.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-04-01T21:48:22.000Z","updated_at":"2021-02-21T10:06:23.000Z","published_at":"2014-04-01T22:38:37.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\u003eMiss X is a shopaholic person and every weekend she goes to a mall. There are total of 10 shops. Miss X starts from shop #1 and goes till last shop. Looking at her pattern of shopping from previous week, a shopkeeper wants to predict the probability of her shopping from his shop this weekend. Can you help the shopkeeper?\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\u003eAlso, find the average amount that she spent in last week. Round the answer to 2 digits after decimal.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ item_price = [10 35 2 100 99 87 1 0.5 9 30] \\n total_items_shopped = [ 2 0 5 10 8 9 1 0 0 1]\\n\\n Average spending = $73.22\\n Probability of shopping from shop# 5 is:0.22]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":43166,"title":"Probabilities - Balls and urns - 02","description":"The urn contains B blue balls and R red balls. Each trial consists of drawing one random ball from the urn and observing its color. Then the ball is *discarded*.\r\n\r\nWhat is the probability that, after N trials, the number of red balls is K?","description_html":"\u003cp\u003eThe urn contains B blue balls and R red balls. Each trial consists of drawing one random ball from the urn and observing its color. Then the ball is \u003cb\u003ediscarded\u003c/b\u003e.\u003c/p\u003e\u003cp\u003eWhat is the probability that, after N trials, the number of red balls is K?\u003c/p\u003e","function_template":"function p = probability(R,B,N,K)\r\n    p = 1;\r\nend","test_suite":"%%\r\nR=4; B=8;\r\nN=6; K=2;\r\np = 0.4545;\r\nassert( abs(probability(R,B,N,K)-p)\u003c1e-04 );\r\n%%\r\nR=22; B=6;\r\nN=14; K=12;\r\np = 0.2418;\r\nassert( abs(probability(R,B,N,K)-p)\u003c1e-04 );\r\n%%\r\nR=22; B=60;\r\nN=5; K=0;\r\np = 0.2002;\r\nassert( abs(probability(R,B,N,K)-p)\u003c1e-04 );\r\n%%\r\nR=9; B=0;\r\nN=4; K=4;\r\nassert( isequal(probability(R,B,N,K),1) );\r\n%%\r\nR=1; B=78;\r\nN=78; K=1;\r\np = 0.9873;\r\nassert( abs(probability(R,B,N,K)-p)\u003c1e-04 );","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":85738,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":21,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-07T15:42:59.000Z","updated_at":"2026-01-21T12:49:51.000Z","published_at":"2016-10-07T15:42:59.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe urn contains B blue balls and R red balls. Each trial consists of drawing one random ball from the urn and observing its color. Then the ball 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\u003ediscarded\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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhat is the probability that, after N trials, the number of red balls is K?\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":44315,"title":"Predicting life and death of a memory-less light bulb","description":"*\u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161* \r\n\r\nYou have a light bulb that can fail any moment according to the exponential probability distribution. \r\n\r\nAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant. \r\n\r\nNotice that this probability is very small if N is very large. \r\n\r\nNow suppose, the bulb has already survived N hours. \r\n\r\nPlease calculate the probability of its surviving M more hours.\r\n","description_html":"\u003cp\u003e\u003cb\u003e\u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161\u003c/b\u003e\u003c/p\u003e\u003cp\u003eYou have a light bulb that can fail any moment according to the exponential probability distribution.\u003c/p\u003e\u003cp\u003eAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant.\u003c/p\u003e\u003cp\u003eNotice that this probability is very small if N is very large.\u003c/p\u003e\u003cp\u003eNow suppose, the bulb has already survived N hours.\u003c/p\u003e\u003cp\u003ePlease calculate the probability of its surviving M more hours.\u003c/p\u003e","function_template":"function hope = fate(N,P,M)\r\n  hope=exp(-(N+M)*P);\r\nend","test_suite":"%%\r\nN = 1;\r\nP=1;\r\nM=0;\r\nhope_correct = 1;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN = 1;\r\nP=0;\r\nM=1;\r\nhope_correct = 1;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=1;\r\nP=1;\r\nM=1;\r\nhope_correct = 0.3679;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=2;\r\nP=1;\r\nM=1;\r\nhope_correct = 0.3679;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=2;\r\nP=1;\r\nM=2;\r\nhope_correct = 0.1353;\r\nassert(fate(N,P,M)\u003chope_correct*1.1)\r\n%%\r\nN=2;\r\nP=2;\r\nM=2;\r\nhope_correct = 0.0183;\r\nassert(fate(N,P,M)\u003chope_correct*1.1)\r\n%%","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":336,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-12T02:53:45.000Z","updated_at":"2026-03-25T02:55:11.000Z","published_at":"2017-10-16T01:45:07.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\u003e\u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161\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 have a light bulb that can fail any moment according to the exponential probability distribution.\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\u003eAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant.\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\u003eNotice that this probability is very small if N is very large.\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\u003eNow suppose, the bulb has already survived N hours.\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\u003ePlease calculate the probability of its surviving M more hours.\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":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":53004,"title":"Collect a set of candy wrappers","description":"This past Halloween, the siblings Matilda and Labrun amused (and sometimes confused) their many neighbors with their costumes inspired by “mundane Halloween”, a Japanese tradition started in 2014. As they sifted through and sampled the candy they collected, they noticed something odd as they opened one type of candy, an Oh Leonhard! bar:\r\n“This wrapper has a proof of the infinitude of primes!”, said Matilda.\r\n“I got that one too,” said Labrun. “And here’s one with the Twin Prime Conjecture!”\r\n“Here’s the Pythagorean Theorem. And this one has the Riemann hypothesis.”\r\nThe precocious pair determined that these wrappers were part of the Oh Leonhard! “Great Theorems and Unsolved Problems” promotion. In this promotion, wrappers with one of forty theorems, conjectures, or other famous math problems were distributed evenly among all of the Oh Leonhard! Bars produces. Anyone who collected all wrappers in the set would get a copy of the Handbook of Mathematical Functions by Abramowitz and Stegun. \r\nMatilda and Labrun computed that, on average, they would have to open 172 wrappers to complete a set and win the prize. Their calculation accounted for the contest’s rule that all pieces of the wrapper had to be submitted—that is, no fractional wrappers were allowed.\r\nWrite a function that takes the number of wrappers in a set and compute the expected number of wrappers that would need to be opened to collect the set.","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: 369px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 184.5px; transform-origin: 407px 184.5px; vertical-align: baseline; \"\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: 276.975px 8.05px; transform-origin: 276.975px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis past Halloween, the siblings Matilda and Labrun amused (and sometimes confused) \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/51251\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003etheir many neighbors\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: 31.8917px 8.05px; transform-origin: 31.8917px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e with their costumes inspired by “\u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.spoon-tamago.com/2021/11/01/japan-jimi-mundane-halloween-2021/\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003emundane Halloween\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: 244.658px 8.05px; transform-origin: 244.658px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e”, a Japanese tradition started in 2014. As they sifted through and sampled the candy they collected, they noticed something odd as they opened one type of candy, an Oh Leonhard! bar:\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: 207.317px 8.05px; transform-origin: 207.317px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e“This wrapper has a proof of the infinitude of primes!”, said Matilda.\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: 253.475px 8.05px; transform-origin: 253.475px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e“I got that one too,” said Labrun. “And here’s one with the Twin Prime Conjecture!”\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: 242.983px 8.05px; transform-origin: 242.983px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e“Here’s the Pythagorean Theorem. And this one has the Riemann hypothesis.”\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: 359.025px 8.05px; transform-origin: 359.025px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe precocious pair determined that these wrappers were part of the Oh Leonhard! “Great Theorems and Unsolved Problems” promotion. In this promotion, wrappers with one of forty theorems, conjectures, or other famous math problems were distributed evenly among all of the Oh Leonhard! Bars produces. Anyone who collected all wrappers in the set would get a copy of the\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: 117.475px 8.05px; transform-origin: 117.475px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003e Handbook of Mathematical Functions\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: 89.4583px 8.05px; transform-origin: 89.4583px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e by Abramowitz and Stegun. \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: 383.15px 8.05px; transform-origin: 383.15px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eMatilda and Labrun computed that, on average, they would have to open 172 wrappers to complete a set and win the prize. Their calculation accounted for the contest’s rule that all pieces of the wrapper had to be submitted—that is, no fractional wrappers were allowed.\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: 383px 8.05px; transform-origin: 383px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that takes the number of wrappers in a set and compute the expected number of wrappers that would need to be opened to collect the set.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = collectWrappers(n)\r\n  y = factorial(factorial(n));","test_suite":"%%\r\nn = 5;\r\ny_correct = 12;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 25;\r\ny_correct = 96;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 40;\r\ny_correct = 172;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 250;\r\ny_correct = 1526;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 500;\r\ny_correct = 3397;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 1000:25:1125;\r\ny_correct = [7486 7698 7911 8125 8339 8554];\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 2500;\r\ny_correct = 21004;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 10000;\r\ny_correct = 97877;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 250000;\r\ny_correct = 3251609;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 5e6;\r\ny_correct = 80010822;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 2.5e7;\r\ny_correct = 440290052;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 5e8;\r\ny_correct = 10303667162;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 2.5e9;\r\ny_correct = 55541930585;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%% Anti-lookup\r\nn = [7 17 71 77 117 171 177 711 717 771 777];\r\nyy_correct = [68 276 2216 2478 4393 7308 7647 46281 46777 51268 51779];\r\nindx = randi(11,[1 randi(11)]);\r\nassert(isequal(collectWrappers(collectWrappers(n(indx))),yy_correct(indx)))\r\n\r\n%%\r\nfiletext = fileread('collectWrappers.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp'); \r\nassert(~illegal)","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":46909,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":5,"test_suite_updated_at":"2021-11-06T13:42:54.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2021-11-06T13:09:20.000Z","updated_at":"2026-01-02T17:08:42.000Z","published_at":"2021-11-06T13:12:12.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\u003eThis past Halloween, the siblings Matilda and Labrun amused (and sometimes confused) \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/51251\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003etheir many neighbors\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e with their costumes inspired by “\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.spoon-tamago.com/2021/11/01/japan-jimi-mundane-halloween-2021/\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emundane Halloween\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e”, a Japanese tradition started in 2014. As they sifted through and sampled the candy they collected, they noticed something odd as they opened one type of candy, an Oh Leonhard! bar:\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“This wrapper has a proof of the infinitude of primes!”, said Matilda.\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“I got that one too,” said Labrun. “And here’s one with the Twin Prime Conjecture!”\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“Here’s the Pythagorean Theorem. And this one has the Riemann hypothesis.”\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 precocious pair determined that these wrappers were part of the Oh Leonhard! “Great Theorems and Unsolved Problems” promotion. In this promotion, wrappers with one of forty theorems, conjectures, or other famous math problems were distributed evenly among all of the Oh Leonhard! Bars produces. Anyone who collected all wrappers in the set would get a copy of the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e Handbook of Mathematical Functions\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e by Abramowitz and Stegun. \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\u003eMatilda and Labrun computed that, on average, they would have to open 172 wrappers to complete a set and win the prize. Their calculation accounted for the contest’s rule that all pieces of the wrapper had to be submitted—that is, no fractional wrappers were allowed.\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\u003eWrite a function that takes the number of wrappers in a set and compute the expected number of wrappers that would need to be opened to collect the set.\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":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":57620,"title":"Compute frequency factors for the normal distribution","description":"In frequency analysis in hydrology, the streamflow  corresponding to a specified exceedance probability  (or return period ) can be computed as\r\n\r\nwhere  and  are the mean and standard deviation of the streamflow series, respectively, and  is the frequency factor. \r\nWrite a function to compute the frequency factor for the normal distribution given the exceedance probability as a vector. ","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 135px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 67.5px; transform-origin: 407px 67.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 43px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21.5px; text-align: left; transform-origin: 384px 21.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 156.242px 8px; transform-origin: 156.242px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIn frequency analysis in hydrology, the streamflow \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-6px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACkAAAAoCAYAAABjPNNTAAADB0lEQVRYR+1Yu2pUURSd+QNFSyujhSBERCOINhY+IoidsRaMGqsUiqawMBEU20QDKRW1S6MoFoJGQU0gFoJFtBIrH/ELdC3Ye9hzPI89M9eQgXthce6dex7rrH32406z0QdXsw84NmqSVVmpVnK9KLkJRHYYMgtVEbPzdGPurZjgDHAKGACeyYRD0j5Eexv4UhXhTkhStXHgqix+Gi0J6cX314HzwC/gBFCJsl6Sg1hwDtgDfAb2AT8SSq2Iwux3uApFPSRJ8AWwUUjRxDlTjuL9Xel7A+1Er2YvkaQJ34oyXCs0cWz9A/jxlbwoqe7iXyL5FLMckZkW0e51zGpJsvsu4INjXLJLjuQIRj0wI72LhSSPY44n/4ukOgDn96rIvvZM8vkg0JOXp5QMVTyHhWadasygH8OQXptxk4oErilTJBn/GKy7WchagI6zzcUk0ylF8ifGaMhhRjnqXIjZiMT0uoObC86xyW4xkuFCncS6S1jpplnN62zZfcRI9uKd1tSPsDLPtl5hMVISuOVsVZIMnS3MTOr1PAIvga+ABv3LuH8DXAToC23WS53JP2abnjgXZqZYNKAzzgNalAzj/rGsYzf0Hr9dA1qxNUWSHVlM8PKEHxt2Us4yhblsHuczK6owBnMTY0ArbHniZHi2wrNkzdyJN6sQRcfMpUWbt1NZw3qzp/iwTvRdHooZKUeS52xaDjKL2CvAR5l4C9pJgGeJSreZJ5Q68qzqc97t1rSxsaUqiGMYko7J+eGk74BVgDXmc6CbzwQ9w65E4SFJRe8DLNlKBa8Vgt77KbEJjacepyz+g8HsQ3PS09lSPZr8W0FBei4/HWL1Jyv9ZdmNKyPllKQS9wDN4eFxYeigh2pg5vv9wFmAx4L5Plb9aFB3Fx8xkvpVyHKLIeW3sDskJg/Jhs/MHrcynbTCcoerlJI0Sazk5wb4pbgT2A1sEDJLaF8D/B7K1Y4cr6HHHbI8jlNSzvueYeek2RgjhE2TyXnWkqR3M//0q0l2LV0wsFayVrIqBaqa5y9jXZwpcR/A+gAAAABJRU5ErkJggg==\" alt=\"QT\" style=\"width: 20.5px; height: 20px;\" width=\"20.5\" height=\"20\"\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: 164.95px 8px; transform-origin: 164.95px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e corresponding to a specified exceedance probability \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003ep\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: 32.6667px 8px; transform-origin: 32.6667px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e (or return period \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG8AAAAlCAYAAABMBrdqAAAEZUlEQVR4Xu1aOYsVQRDe/QWekRiImgiC4ploqqKpooKBIHiF4gEegXiAYmTgKhiYeKGRoHiAgYrgBQqCiRoYGHngL9DvY6eWevN6Zrq7uh/71h74eMd0V3fX13V0zYyOlGtoNTA6tDMvEx8p5A3xJijk5SXvEsRfAL7mGKaQl0Or4zKXAO+BBYW8fErOJflMRdy2XAO0Wd4a46Dfc+0447y6us9Hgz/Az66GHfc/4/5x4JZRTmP3JvLE5KXjb3x5Xf1YWO0oufeo4f9s7iKTMkjaQWAfsBT4YBhnI/reB2Yn2ATB5O1Bj8vAbeBozYIe4vf6SuJZfB5T0ukibgJvgZWGxQ+y6ywMdqoiTca1ksdEhdf+nAtpsjya+nRgQ21wLvSH+m8Tvj+otXmD349rpOZcg0U2LWQx8BE4CayohFnJ+wU5Oxy6scy1r28TeX/R0mXy4g5EkKs/LfNi7okn1cK4sMPAuQTk0fvQ8mZmmGOPSJfy6ftXAa5AywyKbpQXY13dMvk/22hXmnsNqeSnIo96+zIIHYSe8+gSxbUcwffzqTQ3CeSkIE/CitXteqkjhLx6vBvIBL1WkaZRCvKY6B0CmJH7XtTrImAuMA24UnWUeMyfL4EXdYEh5Ol4x6NDKp9ONz3Hd6Ut7T7hnuVsloI8eqarioC2ZXHdm4HdAI9VvMaAG8A1gDqeUbt3Qq8xhDwGYZ6BePEIkapyoJVm4dDqCazkkQzGutDzLYshz5VeGZbWAVIP5WFfyF2L7xMWGEKeFrIXQsS8LQpnX26CnVYh6M8zlaUAbCWPidpywJXEtS1PztRsw/Mx+2sPoufVk2f4kie7SiYRursScJNdhJW82HIYs9Ot1epc3kPPq6co4kueVE44Bl1DSEDOrvVEA1jIE9cXUw7jmZpX09FLz2s72k0c4XzJ0/GOQTVr2ScRGaFiLOTFlsN0vGsKRboc2WOZvuSx3MPMh5erJBaqKN1+KmSbseUwXfRwhSJ9POurF/uQV3/CEOMa2sgd9mzTUg6TokeTy9TJTJ/R+JCnBTQNYrG8Yc82GYNoeaGhRFuVq1rF+68AWqTzaOZDns6GplpJTG+6mJhnKYfpokfP+a2alOQZTBBXA30FiC7yfB4BWaxuMvWNIY9e4zQQk33rJLAeiiS7bySOiusiTw/A9j2p6mTSvHEuTJr4DFIqGb4ehjHrDhBToNdFD0lWaCwHAD656ZxDE3nchcsAPpCtX0/xxzcg27sZRiJCupO0XQArI/WL1Rq+CtFUSYoth3EcXfRgHvEO4Hsz84BnwBOgs07bZXkhivjf2nKDbwFiXvfQSaAr3nnpspDnpSZno9hyGIXpJDCag+iO8WueEj3l7Bt75pWih+noVciL20vyjkrMYzFdEutMStqmV8iLIy+2HMZs8jogr04W8uL0H92LlnMPCH2TQJ6cuwa+iz+Dn0UWywvnkNbDd02ClR0+VHuPQl5qjQ5QXiFvgMpOPVQhL7VGByjvH3tR7yYA92EaAAAAAElFTkSuQmCC\" alt=\"T = 1/p\" style=\"width: 55.5px; height: 18.5px;\" width=\"55.5\" height=\"18.5\"\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: 67.2917px 8px; transform-origin: 67.2917px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e) can be computed as\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 22px; 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 11px; text-align: left; transform-origin: 384px 11px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"vertical-align:-6px\"\u003e\u003cimg src=\"data:image/png;base64,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\" alt=\"QT = mu + KT sigma\" style=\"width: 89.5px; height: 20px;\" width=\"89.5\" height=\"20\"\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 22px; 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 11px; text-align: left; transform-origin: 384px 11px; 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: 21.0083px 8px; transform-origin: 21.0083px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ewhere \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\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: 15.5583px 8px; transform-origin: 15.5583px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\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: 249.592px 8px; transform-origin: 249.592px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e are the mean and standard deviation of the streamflow series, respectively, and \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-6px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACcAAAAoCAYAAAB99ePgAAACtElEQVRYR+1XPUsdQRR97x/EmCqlSSCNJKAiBC3SmK8mnV8/wI/CUkFLNaBF0ojGIrUJRKyUWAlGBNFCC7FRf4GanxDPkbnLdZydmV3fbh7hDRzeuntn5sy5d+69Vit1PKp1zK3SIJfXOw3lilKuBQs/Diy+Y753eexO8O0yK8mQW0nuOTAGvLEW78ff3PRIkXuH50llt4nnGUAOkIlfiJwsRlV+q5W7UzYcwvuvxo7kv2diYxnHkuvDvBUz9wy/Tx2bis0ffHutFM3NL5YcFeg1u3zC75S1oyhGNw4CmePLdYJYcleY3GQW+IDfDfPcjN9pYARwkc6tGifGkHsBu0O1yyOjDN+vAk+AtBgsnNw4dpgzu9BtbwFxI+OvBzi/F4uUyTHK/cJcSSN0HZVi/P0AeAkKGzHk/qrdeRMZewdGwZoEftrpQuTeY+K6gxxfDQPLhcmGhUPkZmEjGZ9u3AIkyTLeOoHC1AuR28fm7UYdUerUxB1f1zx9aE/4yLGuUh0ZL/HAOqpdzRgk+dBt9TUFdmQkTYKPnC5ZJPFQraJv8BLej3piT/Ik09AacAx8MYdiqCwArwCmK160DlnLR24RRsz8HDYBuxEQVV0cmRNJUA7AqnJhDHVzwPjmSEqjj5wuWa4OQ5P31VQm8W+AXBwdFlJtSIp2u0DSXqWRs0sWE68dV3ZM6prrUlDeSQa45ULXhDRyui9La5G4nlYvNjFLBpjA/HnfKVzkGBN7ANXi8OUznQdpy9TyWbnQ3lurHWwWbHK8oR+BB9aqdOk2IJ0t7VqBNsfJbVttohvSZ55D3MwJJWGf6nm+SRhENQ1lk5MMEFWXyySnM4Dr9t/xRJnkdIPq+gfpn5KTFBIqdwnJMpRjqRsAmEZksMb+rLfbmumGl6FcJkLauEEur3QN5f5L5a4BNC2HKYDzOZ0AAAAASUVORK5CYII=\" alt=\"KT\" style=\"width: 19.5px; height: 20px;\" width=\"19.5\" height=\"20\"\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: 74.275px 8px; transform-origin: 74.275px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e is the frequency factor. \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: 373.275px 8px; transform-origin: 373.275px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to compute the frequency factor for the normal distribution given the exceedance probability as a vector. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function KT = normFreqFactor(p)\r\n  KT = trapz(QT:inf,exp(-Q.^2));\r\nend","test_suite":"%%\r\np = 0.001;\r\nKT_correct = 3.090;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.002;\r\nKT_correct = 2.878;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.01;\r\nKT_correct = 2.326;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.02;\r\nKT_correct = 2.054;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.04;\r\nKT_correct = 1.751;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.1;\r\nKT_correct = 1.282;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.2;\r\nKT_correct = 0.842;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.3;\r\nKT_correct = 0.524;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.5;\r\nKT_correct = 0;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.8;\r\nKT_correct = -0.842;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\nT = [5 10 20 25 50 100 250 500 1000];\r\nKT_correct = [0.842 1.282 1.645 1.751 2.054 2.326 2.652 2.878 3.090];\r\nassert(all(abs(normFreqFactor(1./T)-KT_correct)\u003c1e-3))\r\n\r\n%%\r\np = rand(1,randi(15));\r\nK1 = normFreqFactor(p);\r\nK2 = normFreqFactor(1-p);\r\nassert(all(abs(K1+K2)\u003c1e-3))\r\n\r\n%%\r\nfiletext = fileread('normFreqFactor.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'assert') || contains(filetext, 'regexp') || contains(filetext, 'interp'); \r\nassert(~illegal)","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":46909,"edited_by":46909,"edited_at":"2023-01-29T19:23:19.000Z","deleted_by":null,"deleted_at":null,"solvers_count":5,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2023-01-29T19:23:11.000Z","updated_at":"2026-01-04T12:13:24.000Z","published_at":"2023-01-29T19:23:20.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 frequency analysis in hydrology, the streamflow \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"QT\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eQ_T\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e corresponding to a specified exceedance probability \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"p\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ep\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e (or return period \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"T = 1/p\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eT = 1/p\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e) can be computed as\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:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"true\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"QT = mu + KT sigma\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eQ_T = \\\\mu + K_T \\\\sigma\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\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\u003ewhere \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"mu\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003e\\\\mu\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e and \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"sigma\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003e\\\\sigma\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e are the mean and standard deviation of the streamflow series, respectively, and \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"KT\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eK_T\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e is the frequency factor. \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\u003eWrite a function to compute the frequency factor for the normal distribution given the exceedance probability as a vector. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":1182,"title":"Hangman (easy)","description":"What is the best letter to start a \u003chttp://en.wikipedia.org/wiki/Hangman_(game) hangman\u003e game with?\r\n\r\nYou are given a cell array with all valid N-letter words. Your output should be the letter that has the highest chance of occurring (at least once) within any randomly chosen word in this dictionary. \r\n\r\nYou can assume that words will always be in all capital letters, and the cell array will always be a row.\r\n\r\n*Example:*\r\n\r\nwords={'AAA','BED','BEG','BAD'};\r\n\r\nYou should return letter='B';\r\n\r\nnote: Letter 'B' occurrs in _three_ different words. Letter 'A', while occurring four times (counting repetitions), only appears in _two_ different words. \r\n\r\n*Follow-up:* \r\n\r\nIf you are going to be losing hours of sleep over the issue of whether choosing the letter with the highest chance of occurring within any randomly chosen word is actually the _best_ 'simple' strategy in a hangman game, then the next problem in this series - \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1184-hangman-strategy Hangman (strategy)\u003e - is for you. Go ahead and test this or a different strategy there, and the contest machinery will score it based on its performance in a series of simulated hangman games. ","description_html":"\u003cp\u003eWhat is the best letter to start a \u003ca href=\"http://en.wikipedia.org/wiki/Hangman_(game)\"\u003ehangman\u003c/a\u003e game with?\u003c/p\u003e\u003cp\u003eYou are given a cell array with all valid N-letter words. Your output should be the letter that has the highest chance of occurring (at least once) within any randomly chosen word in this dictionary.\u003c/p\u003e\u003cp\u003eYou can assume that words will always be in all capital letters, and the cell array will always be a row.\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample:\u003c/b\u003e\u003c/p\u003e\u003cp\u003ewords={'AAA','BED','BEG','BAD'};\u003c/p\u003e\u003cp\u003eYou should return letter='B';\u003c/p\u003e\u003cp\u003enote: Letter 'B' occurrs in \u003ci\u003ethree\u003c/i\u003e different words. Letter 'A', while occurring four times (counting repetitions), only appears in \u003ci\u003etwo\u003c/i\u003e different words.\u003c/p\u003e\u003cp\u003e\u003cb\u003eFollow-up:\u003c/b\u003e\u003c/p\u003e\u003cp\u003eIf you are going to be losing hours of sleep over the issue of whether choosing the letter with the highest chance of occurring within any randomly chosen word is actually the \u003ci\u003ebest\u003c/i\u003e 'simple' strategy in a hangman game, then the next problem in this series - \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/1184-hangman-strategy\"\u003eHangman (strategy)\u003c/a\u003e - is for you. Go ahead and test this or a different strategy there, and the contest machinery will score it based on its performance in a series of simulated hangman games.\u003c/p\u003e","function_template":"function letter = hangman(words)\r\n  letter='S';\r\nend","test_suite":"%%\r\nwords={'AAA','BED','BEG','BAD'};\r\nassert(isequal(hangman(words),'B'));\r\n\r\n%%\r\nwords={'BUZZ','COZY','DOZE','FUZZ','GAZE','HAZE','JAZZ','LAZY','SIZE','ZERO','ZONE'};\r\nassert(isequal(hangman(words),'Z'));\r\n\r\n%%\r\nrng default;\r\nwords=unique(char('A'+randi(26,[100,3])-1),'rows');\r\nassert(isequal(sum(any(words==hangman(cellstr(words)'),2)),max(arrayfun(@(x)sum(any(words==x,2)),'A':'Z'))));\r\n\r\n%%\r\nrng default;\r\nwords=unique(char('A'+randi(26,[200,4])-1),'rows');\r\nassert(isequal(sum(any(words==hangman(cellstr(words)'),2)),max(arrayfun(@(x)sum(any(words==x,2)),'A':'Z'))));\r\n\r\n%%\r\nrng default;\r\nwords=unique(char('A'+randi(26,[500,5])-1),'rows');\r\nassert(isequal(sum(any(words==hangman(cellstr(words)'),2)),max(arrayfun(@(x)sum(any(words==x,2)),'A':'Z'))));\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":43,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":52,"test_suite_updated_at":"2013-01-08T05:17:12.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-01-07T03:59:12.000Z","updated_at":"2025-12-15T20:07:42.000Z","published_at":"2013-01-07T04:03: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:t\u003eWhat is the best letter to start a\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/Hangman_(game)\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehangman\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e game with?\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 are given a cell array with all valid N-letter words. Your output should be the letter that has the highest chance of occurring (at least once) within any randomly chosen word in this dictionary.\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 words will always be in all capital letters, and the cell array will always be a row.\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\u003ewords={'AAA','BED','BEG','BAD'};\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 should return letter='B';\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: Letter 'B' occurrs in\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\u003ethree\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e different words. Letter 'A', while occurring four times (counting repetitions), only appears in\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 different words.\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\u003eFollow-up:\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 are going to be losing hours of sleep over the issue of whether choosing the letter with the highest chance of occurring within any randomly chosen word is actually the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ebest\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 'simple' strategy in a hangman game, then the next problem in this 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/1184-hangman-strategy\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eHangman (strategy)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e - is for you. Go ahead and test this or a different strategy there, and the contest machinery will score it based on its performance in a series of simulated hangman games.\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":42615,"title":"Factorizing a number into a given number of factors","description":"Given a positive integer, n, and another positive integer, b, return a matrix, M, of width b, with the following properties: (a) Each row is sorted in ascending order (b) the rows are unique (c) the product of the integers in each row equals n (d) the columns are sorted in ascending order, such that the primary sorting is based on the first column, secondary on the second column, etc. (e) M contains integer values only\r\n\r\nNote: The number 1 is also considered a valid factor.\r\n\r\nExample 1:\r\n\r\nn = 30\r\n\r\nb = 2\r\n\r\nM = [ 1 30 ; 2 15 ; 3 10 ; 5 6 ]\r\n\r\nExample 2:\r\n\r\nn = 120\r\n\r\nb = 3\r\n\r\nM = [ 1 1 120 ; 1 2 60 ; 1 3 40 ; 1 4 30 ; 1 5 24 ; 1 6 20 ; 1 8 15 ; 1 10 12 ; 2 2 30 ; 2 3 20 ; 2 4 15 ; 2 5 12 ; 2 6 10 ; 3 4 10 ; 3 5 8 ; 4 5 6 ]","description_html":"\u003cp\u003eGiven a positive integer, n, and another positive integer, b, return a matrix, M, of width b, with the following properties: (a) Each row is sorted in ascending order (b) the rows are unique (c) the product of the integers in each row equals n (d) the columns are sorted in ascending order, such that the primary sorting is based on the first column, secondary on the second column, etc. (e) M contains integer values only\u003c/p\u003e\u003cp\u003eNote: The number 1 is also considered a valid factor.\u003c/p\u003e\u003cp\u003eExample 1:\u003c/p\u003e\u003cp\u003en = 30\u003c/p\u003e\u003cp\u003eb = 2\u003c/p\u003e\u003cp\u003eM = [ 1 30 ; 2 15 ; 3 10 ; 5 6 ]\u003c/p\u003e\u003cp\u003eExample 2:\u003c/p\u003e\u003cp\u003en = 120\u003c/p\u003e\u003cp\u003eb = 3\u003c/p\u003e\u003cp\u003eM = [ 1 1 120 ; 1 2 60 ; 1 3 40 ; 1 4 30 ; 1 5 24 ; 1 6 20 ; 1 8 15 ; 1 10 12 ; 2 2 30 ; 2 3 20 ; 2 4 15 ; 2 5 12 ; 2 6 10 ; 3 4 10 ; 3 5 8 ; 4 5 6 ]\u003c/p\u003e","function_template":"function M = LtdFactor(n,b)\r\n  M = [ n b ];\r\nend","test_suite":"%%\r\nn = 30;\r\nb = 1;\r\nA_correct = [ 30 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))\r\n\r\n%%\r\nn = 3135;\r\nb = 2;\r\nA_correct = [ 1 3135 ; 3 1045 ; 5 627 ; 11 285 ; 15 209 ; 19 165 ; 33 95 ; 55 57 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))\r\n\r\n%%\r\nn = 120;\r\nb = 3;\r\nA_correct = [ 1 1 120 ; 1 2 60 ; 1 3 40 ; 1 4 30 ; 1 5 24 ; 1 6 20 ; 1 8 15 ; 1 10 12 ; 2 2 30 ; 2 3 20 ; 2 4 15 ; 2 5 12 ; 2 6 10 ; 3 4 10 ; 3 5 8 ; 4 5 6 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))\r\n\r\n%%\r\nn = 420;\r\nb = 4;\r\nA_correct = [ 1 1 1 420 ; 1 1 2 210 ; 1 1 3 140 ; 1 1 4 105 ; 1 1 5 84 ; 1 1 6 70 ; 1 1 7 60 ; 1 1 10 42 ; 1 1 12 35 ; 1 1 14 30 ; 1 1 15 28 ; 1 1 20 21 ; 1 2 2 105 ; 1 2 3 70 ; 1 2 5 42 ; 1 2 6 35 ; 1 2 7 30 ; 1 2 10 21 ; 1 2 14 15 ; 1 3 4 35 ; 1 3 5 28 ; 1 3 7 20 ; 1 3 10 14 ; 1 4 5 21 ; 1 4 7 15 ; 1 5 6 14 ; 1 5 7 12 ; 1 6 7 10 ; 2 2 3 35 ; 2 2 5 21 ; 2 2 7 15 ; 2 3 5 14 ; 2 3 7 10 ; 2 5 6 7 ; 3 4 5 7 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))\r\n\r\n%%\r\nn = 2025;\r\nb = 3;\r\nA_correct = [ 1 1 2025 ; 1 3 675 ; 1 5 405 ; 1 9 225 ; 1 15 135 ; 1 25 81 ; 1 27 75 ; 1 45 45 ; 3 3 225 ; 3 5 135 ; 3 9 75 ; 3 15 45 ; 3 25 27 ; 5 5 81 ; 5 9 45 ; 5 15 27 ; 9 9 25 ; 9 15 15 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))\r\n\r\n%%\r\nn = 210;\r\nb = 4;\r\nA_correct = [ 1 1 1 210 ; 1 1 2 105 ; 1 1 3 70 ; 1 1 5 42 ; 1 1 6 35 ; 1 1 7 30 ; 1 1 10 21 ; 1 1 14 15 ; 1 2 3 35 ; 1 2 5 21 ; 1 2 7 15 ; 1 3 5 14 ; 1 3 7 10 ; 1 5 6 7 ; 2 3 5 7 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":30,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-09-14T09:47:56.000Z","updated_at":"2025-12-05T13:06:40.000Z","published_at":"2015-09-14T10:33:10.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 positive integer, n, and another positive integer, b, return a matrix, M, of width b, with the following properties: (a) Each row is sorted in ascending order (b) the rows are unique (c) the product of the integers in each row equals n (d) the columns are sorted in ascending order, such that the primary sorting is based on the first column, secondary on the second column, etc. (e) M contains integer values only\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\u003eNote: The number 1 is also considered a valid factor.\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 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en = 30\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eb = 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eM = [ 1 30 ; 2 15 ; 3 10 ; 5 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\u003cw:jc w:val=\\\"left\\\"/\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en = 120\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eb = 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eM = [ 1 1 120 ; 1 2 60 ; 1 3 40 ; 1 4 30 ; 1 5 24 ; 1 6 20 ; 1 8 15 ; 1 10 12 ; 2 2 30 ; 2 3 20 ; 2 4 15 ; 2 5 12 ; 2 6 10 ; 3 4 10 ; 3 5 8 ; 4 5 6 ]\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":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":52323,"title":"Guess the number I'm thinking of (Part 2)","description":"Have you tried the original \"Guess the number I'm thinking of\" (Problem 44630)?  This problem is just like that, except that the range of possible numbers can change, and pre-calculated answers are explicitly disallowed.  Computing all possible permutations on the fly is not disallowed per se, but it is discouraged due to the high computational load involved.  \r\nIn 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 N (inclusive).  N is an integer between 4 and 1000 (inclusive) that will be specified in each test as upperLimit.  I don't provide any other clues about the number that is to be guessed.\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 substantially better than 33.3%.  The success rate is defined as follows.  \r\nsuccess rate = (wins + draws/2) / games\r\nThe precise value of the expected success rate (when guessing with the optimal strategy) depends upon the value of N:  when N = 4 you should be able to achieve a success rate of 17/48 ≈ 35.4% on average, increasing monotonically to above 50% for N ≥ 24, eventually approaching an asymptote of 19/36 ≈ 52.8%.  (See the Test Suite for details of the thresholds applied.) \r\n\r\nRELATED PROBLEM:  \r\nProblem 44630. Guess the number I'm thinking of (Part 1)","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: 691px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 345.5px; transform-origin: 407px 345.5px; vertical-align: baseline; \"\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eHave you tried the original \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://au.mathworks.com/matlabcentral/cody/problems/44630-guess-the-number-i-m-thinking-of\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"font-style: italic; \"\u003e\"Guess the number I'm thinking of\" (Problem 44630)\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-style: italic; \"\u003e?  This problem is just like that, except that the range of possible numbers can change, and pre-calculated answers are explicitly disallowed.  Computing all possible permutations on the fly is not disallowed per se, but it is discouraged due to the high computational load involved.  \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=\"\"\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: 181px; 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 90.5px; transform-origin: 391px 90.5px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 41px; 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 20.5px; text-align: left; transform-origin: 363px 20.5px; 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-style: italic; font-weight: 700; \"\u003eN\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).  \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; font-weight: 700; \"\u003eN\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 is an integer between 4 and 1000 (inclusive) that will be specified in each test as \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-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eupperLimit\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.  I don't provide any other clues about the number that is to be guessed.\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: 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=\"\"\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 substantially better than 33.3%\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.  The success rate is defined as follows.  \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: 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThe precise value of the expected success rate (when guessing with the optimal strategy) depends upon 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-style: italic; \"\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e:  when \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-style: italic; \"\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e = 4 you should be able to achieve a success rate of 17/48 ≈ 35.4% on average, increasing monotonically to above 50% for \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-style: italic; \"\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e ≥ 24, eventually approaching an asymptote of 19/36 ≈ 52.8%.  (See the Test Suite for details of the thresholds applied.) \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/44630\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 44630. Guess the number I'm thinking of (Part 1)\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(upperLimit, guessesOfOpponents)\r\n    y = 42;\r\nend","test_suite":"%% Anti-hacking test.\r\nassessFunctionAbsence({'rng', 'RandStream'}, 'FileName','myGuess.m')\r\n\r\n%% Anti-precalculation test.\r\n% Do not try to get evade the test.  Just follow the clear rule:  DO NOT PRECALCULATE.\r\nassessFunctionAbsence({'sub2ind', 'str2num'}, 'FileName','myGuess.m')\r\n\r\n% And while we're at it, I dislike the practice of using \"ans\" in a script.  \r\nassessFunctionAbsence({'ans'}, 'FileName','myGuess.m')\r\n\r\n% And you don't really need regexp or regexpi eithr.\r\nassessFunctionAbsence({'regexp', 'regexpi'}, 'FileName','myGuess.m')\r\n\r\n%% Ensure unique guesses of integers, which are in-range.\r\nfor j = 1 : 1000\r\n    upperLim = randi([4, 1000]);\r\n    numberToBeGuessed = randi(upperLim);\r\n    gOO = randperm(upperLim, 2);\r\n    mG = myGuess(upperLim, gOO);\r\n    assert( mG \u003e= 1  \u0026  mG \u003c= upperLim , '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%% Check the success rate several times for various values of N.\r\nmaxIts = 50000;    % 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\ntic\r\nfor j = 1 : 12\r\n%for j = 5 : 20 : 1000\r\n    %upperLim = 3 + j;\r\n    if j \u003c= 4,\r\n        % Focus on smaller N.\r\n        upperLim = randi([4, 10]);\r\n    elseif j \u003c= 8,\r\n        % Focus on intermediate N.\r\n        upperLim = randi([11, 40]);\r\n    else\r\n        % Focus on larger N.\r\n        upperLim = randi([41, 1000]);\r\n    end;\r\n    WDL = [0 0 0];\r\n    for itn = 1 : maxIts\r\n        numberToBeGuessed = randi(upperLim);\r\n        gOO = randperm(upperLim, 2);\r\n        diffs = abs( [gOO myGuess(upperLim, 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    minAcceptableSuccessRate = getCutoff(upperLim);\r\n    %[upperLim minAcceptableSuccessRate successRate]\r\n    fprintf('N = %u, Threshold = %5.2f %c, Success rate = %5.2f %c.\\r\\n', upperLim, minAcceptableSuccessRate*100, '%', successRate*100, '%');\r\n    assert( successRate \u003e= minAcceptableSuccessRate )\r\nend;\r\ntoc\r\n\r\n% Define the minimum success rate that must be achieved.  \r\n% Note:  functions must be defined at the end of a script.  See https://au.mathworks.com/help/matlab/ref/function.html?s_tid=doc_ta#description\r\nfunction threshold = getCutoff(N)\r\n    % The success rate as a function of N is fit quite well \r\n    % by an equation of the form  s = sInf – A / N^k\r\n    expectedSuccessRate = 0.527353226 - 0.740005 / N^1.050420528;   \r\n    % (From fitting 310 points recorded to four decimal places.  \r\n    % The coefficients appear to be accurate to at least 3 significant figures.)  \r\n\r\n    % However, practically speaking we need to include a safety margin\r\n    % to avoid failing correct solutions on account of stochastic fluctuations.  \r\n    % A safety margin of 1 percentage point is almost always enough.  \r\n    % (1.5 percentage points would allow even more natural fluctuation, but would also risk passing incorrect 'solutions'.)  \r\n    threshold = expectedSuccessRate - 0.010;\r\nend","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":64439,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":4,"test_suite_updated_at":"2021-07-19T10:43:08.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2021-07-18T11:23:40.000Z","updated_at":"2021-07-25T08:12:28.000Z","published_at":"2021-07-18T15:01:47.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:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eHave you tried the original \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://au.mathworks.com/matlabcentral/cody/problems/44630-guess-the-number-i-m-thinking-of\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Guess the number I'm thinking of\\\" (Problem 44630)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e?  This problem is just like that, except that the range of possible numbers can change, and pre-calculated answers are explicitly disallowed.  Computing all possible permutations on the fly is not disallowed per se, but it is discouraged due to the high computational load involved.  \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 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\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (inclusive).  \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\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is an integer between 4 and 1000 (inclusive) that will be specified in each test as \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\u003eupperLimit\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.  I don't provide any other clues about the number that is to be 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\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 substantially better than 33.3%\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.  The success rate is defined as follows.  \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\u003eThe precise value of the expected success rate (when guessing with the optimal strategy) depends upon the value of \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e:  when \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e = 4 you should be able to achieve a success rate of 17/48 ≈ 35.4% on average, increasing monotonically to above 50% for \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ≥ 24, eventually approaching an asymptote of 19/36 ≈ 52.8%.  (See the Test Suite for details of the thresholds applied.) \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/44630\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44630. Guess the number I'm thinking of (Part 1)\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":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":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":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":42674,"title":"Cody meets Xiangqi: foresee the unseen (Part 1)","description":"This is the first part of the Xiangqi series. The second part in this series is: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42685-cody-meets-xiangqi-foresee-the-unseen-part-2 Cody meets Xiangqi: foresee the unseen (Part 2)\u003e\r\n\r\n\u003chttps://en.wikipedia.org/wiki/Xiangqi Xiangqi\u003e, also known as *Chinese Chess* (and 象棋 in Chinese characters), is one of the most popular board games in China. The modern Xiangqi board contains a middle section which divides two players' sides and is marked the \"Chu River–Han border\", in reference to the Chu–Han Contention between \u003chttps://en.wikipedia.org/wiki/Xiang_Yu Xiang Yu\u003e and \u003chttps://de.wikipedia.org/wiki/Han_Gaozu Liu Bang\u003e, two prominent warlords and opponents who fought thousands of battles against each other for supremacy over China in the late Qin dynasty (206–202 BC). Those interested in the story of the Chu–Han Contention and its relation to Xiangqi are referred to \u003chttps://en.wikipedia.org/wiki/Chu%E2%80%93Han_Contention here\u003e.\r\n\r\nFresh to Xiangqi, Cody becomes interested in Xiangqi by raising a question: _Who is the stronger player of Xiangqi between Xiang Yu and Liu Bang_? To answer this question, Cody designs a match for Xiang Yu and Liu Bang, in which Cody serves as the referee. The smart Cody referee also sets an intelligent rule to determine the winner: \r\n\r\n_In a succession of Xiangqi games, once Xiang Yu wins Na games *consecutively*, whereas Liu Bang has not won Nb games *consecutively*, Cody immediately announces Xiang Yu as the winner. Contrarily, once Liu Bang defeats Xiang Yu Nb times *consecutively*, whereas Xiang Yu has not won Na times *consecutively*, Liu Bang becomes the winner._ \r\n\r\nCody suggests that Na \u003e 1 and Nb \u003e 1, in order to enhance, to some extent, the confidence of the result of the match. Suppose in each individual game, the probability Xiang Yu would win is p, and the probability Liu Bang would win is 1 - p, which implicitly assumes that the probability of a tie is 0 (because they both refuse to draw and will fight to death). Unfortunately, this well-designed match has never taken place. Regretfully, Cody requests us --- active Cody players --- to foresee the outcome of this unseen match using Monte Carlo simulations. Our task is to write a function\r\n\r\n                                sol = Xiangqi(p, Na, Nb)\r\n\r\nwith input: 0 \u003c= p \u003c= 1, Na \u003e 1, Nb \u003e 1, and output: sol --- the probability that Xiang Yu wins. Your solution will be tested against its true value Q (which is computed but hided in the P-file EvaluateSolution.p) according to a hybrid absolute and relative error tolerance criterion:\r\n\r\n                      abs(sol - Q) \u003c= max(AbsTol, RelTol*abs(sol))\r\n\r\nwhere AbsTol and RelTol are absolute and relative error tolerances, respectively, which will be specified in the test suite. You are encouraged to optimize the performance (rather than the usual Cody size) of your code as much as possible, as the score of your solution will be measured based on the *speed* of your code. \r\n\r\nHave fun!\r\n","description_html":"\u003cp\u003eThis is the first part of the Xiangqi series. The second part in this series is: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42685-cody-meets-xiangqi-foresee-the-unseen-part-2\"\u003eCody meets Xiangqi: foresee the unseen (Part 2)\u003c/a\u003e\u003c/p\u003e\u003cp\u003e\u003ca href = \"https://en.wikipedia.org/wiki/Xiangqi\"\u003eXiangqi\u003c/a\u003e, also known as \u003cb\u003eChinese Chess\u003c/b\u003e (and 象棋 in Chinese characters), is one of the most popular board games in China. The modern Xiangqi board contains a middle section which divides two players' sides and is marked the \"Chu River–Han border\", in reference to the Chu–Han Contention between \u003ca href = \"https://en.wikipedia.org/wiki/Xiang_Yu\"\u003eXiang Yu\u003c/a\u003e and \u003ca href = \"https://de.wikipedia.org/wiki/Han_Gaozu\"\u003eLiu Bang\u003c/a\u003e, two prominent warlords and opponents who fought thousands of battles against each other for supremacy over China in the late Qin dynasty (206–202 BC). Those interested in the story of the Chu–Han Contention and its relation to Xiangqi are referred to \u003ca href = \"https://en.wikipedia.org/wiki/Chu%E2%80%93Han_Contention\"\u003ehere\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eFresh to Xiangqi, Cody becomes interested in Xiangqi by raising a question: \u003ci\u003eWho is the stronger player of Xiangqi between Xiang Yu and Liu Bang\u003c/i\u003e? To answer this question, Cody designs a match for Xiang Yu and Liu Bang, in which Cody serves as the referee. The smart Cody referee also sets an intelligent rule to determine the winner:\u003c/p\u003e\u003cp\u003e\u003ci\u003eIn a succession of Xiangqi games, once Xiang Yu wins Na games \u003cb\u003econsecutively\u003c/b\u003e, whereas Liu Bang has not won Nb games \u003cb\u003econsecutively\u003c/b\u003e, Cody immediately announces Xiang Yu as the winner. Contrarily, once Liu Bang defeats Xiang Yu Nb times \u003cb\u003econsecutively\u003c/b\u003e, whereas Xiang Yu has not won Na times \u003cb\u003econsecutively\u003c/b\u003e, Liu Bang becomes the winner.\u003c/i\u003e\u003c/p\u003e\u003cp\u003eCody suggests that Na \u0026gt; 1 and Nb \u0026gt; 1, in order to enhance, to some extent, the confidence of the result of the match. Suppose in each individual game, the probability Xiang Yu would win is p, and the probability Liu Bang would win is 1 - p, which implicitly assumes that the probability of a tie is 0 (because they both refuse to draw and will fight to death). Unfortunately, this well-designed match has never taken place. Regretfully, Cody requests us --- active Cody players --- to foresee the outcome of this unseen match using Monte Carlo simulations. Our task is to write a function\u003c/p\u003e\u003cpre\u003e                                sol = Xiangqi(p, Na, Nb)\u003c/pre\u003e\u003cp\u003ewith input: 0 \u0026lt;= p \u0026lt;= 1, Na \u0026gt; 1, Nb \u0026gt; 1, and output: sol --- the probability that Xiang Yu wins. Your solution will be tested against its true value Q (which is computed but hided in the P-file EvaluateSolution.p) according to a hybrid absolute and relative error tolerance criterion:\u003c/p\u003e\u003cpre\u003e                      abs(sol - Q) \u0026lt;= max(AbsTol, RelTol*abs(sol))\u003c/pre\u003e\u003cp\u003ewhere AbsTol and RelTol are absolute and relative error tolerances, respectively, which will be specified in the test suite. You are encouraged to optimize the performance (rather than the usual Cody size) of your code as much as possible, as the score of your solution will be measured based on the \u003cb\u003espeed\u003c/b\u003e of your code.\u003c/p\u003e\u003cp\u003eHave fun!\u003c/p\u003e","function_template":"function sol = Xiangqi(p, Na, Nb)\r\n  sol = p;\r\nend","test_suite":"%%\r\n% By courtesy of Alfonso Nieto-Castanon\r\nurlwrite('https://sites.google.com/a/alfnie.com/alfnie/software/SetSolutionScore.p?attredirects=0\u0026amp;d=1','SetSolutionScore.p');\r\nrehash path;\r\n\r\n%%\r\nfh = fopen('EvaluateSolution.p','wb');\r\nfwrite(fh, hex2dec(reshape('7630312E30307630302E3030000E601C0AF25FB100000056000000A4000000D6820EB5B30514117A9E6E5DB36898AFFFCC5086DFAF59C2910AEB07B88523DABE546868AC2BDAC3795467A7BCD91A89E2F578F2EDE92D63472A3B8FCA3F216CB3B66B010B5B924A5F514E19B90225B0978A54DA881119917D211CB055361918CAA0670F6D0E8ED17B319492619F4361BFB4C3C31D68E11F4BA084C6456783C358296B3E63E16C78EF2B0279074BCB707265EB4C044BFF7F25BA0A9678B75D36B9ACEE6853',2,[]).')); rehash path; fclose(fh); \r\n\r\n%%\r\np = 0; Na = 2; Nb = 3;\r\nAbsTol = 1e-6; RelTol = 1e-5;\r\nsol = Xiangqi(p, Na, Nb);\r\nassert(EvaluateSolution(p,Na,Nb,sol,AbsTol,RelTol));\r\n\r\n%%\r\np = 1; Na = 3; Nb = 2;\r\nAbsTol = 1e-6; RelTol = 1e-5;\r\nsol = Xiangqi(p, Na, Nb);\r\nassert(EvaluateSolution(p,Na,Nb,sol,AbsTol,RelTol));\r\n\r\n%%\r\np = 0.4; Na = 2; Nb = 3;\r\nAbsTol = 5e-4; RelTol = 5e-4;\r\nsol = Xiangqi(p, Na, Nb);\r\nassert(EvaluateSolution(p,Na,Nb,sol,AbsTol,RelTol));\r\n\r\n%%\r\np = 0.7; Na = 4; Nb = 2;\r\nAbsTol = 5e-4; RelTol = 5e-4;\r\nsol = Xiangqi(p, Na, Nb);\r\nassert(EvaluateSolution(p,Na,Nb,sol,AbsTol,RelTol));\r\n\r\n%%\r\np = 0.15; Na = 4; Nb = 2;\r\nAbsTol = 5e-5; RelTol = 1e-6;\r\nt = builtin('tic');\r\nsol = Xiangqi(p, Na, Nb);\r\nscore = builtin('toc',t);\r\nassert(EvaluateSolution(p,Na,Nb,sol,AbsTol,RelTol));\r\nSetSolutionScore(round(500*score));","published":true,"deleted":false,"likes_count":3,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":9,"test_suite_updated_at":"2015-10-30T08:18:09.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-10-30T05:02:43.000Z","updated_at":"2025-11-30T16:38:45.000Z","published_at":"2015-10-30T05:45:36.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 the first part of the Xiangqi series. The second part in this series is:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42685-cody-meets-xiangqi-foresee-the-unseen-part-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody meets Xiangqi: foresee the unseen (Part 2)\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:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Xiangqi\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eXiangqi\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, also known as\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\u003eChinese Chess\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (and 象棋 in Chinese characters), is one of the most popular board games in China. The modern Xiangqi board contains a middle section which divides two players' sides and is marked the \\\"Chu River–Han border\\\", in reference to the Chu–Han Contention between\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Xiang_Yu\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eXiang Yu\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://de.wikipedia.org/wiki/Han_Gaozu\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eLiu Bang\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, two prominent warlords and opponents who fought thousands of battles against each other for supremacy over China in the late Qin dynasty (206–202 BC). Those interested in the story of the Chu–Han Contention and its relation to Xiangqi are referred 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=\\\"https://en.wikipedia.org/wiki/Chu%E2%80%93Han_Contention\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehere\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\u003eFresh to Xiangqi, Cody becomes interested in Xiangqi by raising a question:\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\u003eWho is the stronger player of Xiangqi between Xiang Yu and Liu Bang\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e? To answer this question, Cody designs a match for Xiang Yu and Liu Bang, in which Cody serves as the referee. The smart Cody referee also sets an intelligent rule to determine the winner:\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\u003eIn a succession of Xiangqi games, once Xiang Yu wins Na games\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\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\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econsecutively\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e, whereas Liu Bang has not won Nb games\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\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\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econsecutively\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e, Cody immediately announces Xiang Yu as the winner. Contrarily, once Liu Bang defeats Xiang Yu Nb times\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\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\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econsecutively\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e, whereas Xiang Yu has not won Na times\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\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\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econsecutively\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e, Liu Bang becomes the winner.\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\u003eCody suggests that Na \u0026gt; 1 and Nb \u0026gt; 1, in order to enhance, to some extent, the confidence of the result of the match. Suppose in each individual game, the probability Xiang Yu would win is p, and the probability Liu Bang would win is 1 - p, which implicitly assumes that the probability of a tie is 0 (because they both refuse to draw and will fight to death). Unfortunately, this well-designed match has never taken place. Regretfully, Cody requests us --- active Cody players --- to foresee the outcome of this unseen match using Monte Carlo simulations. Our task is to 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[                                sol = Xiangqi(p, Na, Nb)]]\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\u003ewith input: 0 \u0026lt;= p \u0026lt;= 1, Na \u0026gt; 1, Nb \u0026gt; 1, and output: sol --- the probability that Xiang Yu wins. Your solution will be tested against its true value Q (which is computed but hided in the P-file EvaluateSolution.p) according to a hybrid absolute and relative error tolerance criterion:\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[                      abs(sol - Q) \u003c= max(AbsTol, RelTol*abs(sol))]]\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\u003ewhere AbsTol and RelTol are absolute and relative error tolerances, respectively, which will be specified in the test suite. You are encouraged to optimize the performance (rather than the usual Cody size) of your code as much as possible, as the score of your solution will be measured based on the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003espeed\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of your code.\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\u003eHave fun!\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":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":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":45389,"title":"Knight's Watch","description":"  \"Night gathers, and now my watch begins\"\r\n\r\nA knight is placed on an n-by-n sized chessboard at the position x. Find the probability that after k steps, the knight will remain within the chessboard.\r\n\r\nAny knight's move that places him outside the board should be considered invalid.\r\n\r\n For simplicity, the knight's position on the chessboard is defined with the numeric\r\n notation instead of algebraic notation. so 'Ka1' is represented as (1,1).\r\n\r\nBrief explanation:\r\n\r\n  Say the knight is placed in pos-(1,1). A knight has 8 possible moves. So in the next move, \r\nthe Knight can go to 8 different positions in the chessboard. But among them, only 2\r\n positions are valid i.e. the knight remains within the chessboard and they are -\r\n(3,2) \u0026 (2,3). So the prob. is 2/8 after 1 move. What will be the probability after k moves?\r\n\r\n","description_html":"\u003cpre class=\"language-matlab\"\u003e\"Night gathers, and now my watch begins\"\r\n\u003c/pre\u003e\u003cp\u003eA knight is placed on an n-by-n sized chessboard at the position x. Find the probability that after k steps, the knight will remain within the chessboard.\u003c/p\u003e\u003cp\u003eAny knight's move that places him outside the board should be considered invalid.\u003c/p\u003e\u003cpre\u003e For simplicity, the knight's position on the chessboard is defined with the numeric\r\n notation instead of algebraic notation. so 'Ka1' is represented as (1,1).\u003c/pre\u003e\u003cp\u003eBrief explanation:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eSay the knight is placed in pos-(1,1). A knight has 8 possible moves. So in the next move, \r\nthe Knight can go to 8 different positions in the chessboard. But among them, only 2\r\npositions are valid i.e. the knight remains within the chessboard and they are -\r\n(3,2) \u0026 (2,3). So the prob. is 2/8 after 1 move. What will be the probability after k moves?\r\n\u003c/pre\u003e","function_template":"function prob = knights_watch(x,n,k)","test_suite":"%%\r\nx =[1,1];\r\nassert(isequal(knights_watch(x,3,2),0.0625))\r\n%%\r\nx =[1,1];\r\nassert(isequal(knights_watch(x,4,4),0.0176))\r\n%%\r\nx =[6,4];\r\nassert(isequal(knights_watch(x,6,9),0.012))\r\n%%\r\nx =[6,4];\r\nassert(isequal(knights_watch(x,8,25),0.0011))\r\n%%\r\nx =[8,8];\r\nassert(isequal(knights_watch(x,8,15),0.0042))\r\n%%\r\nx =[8,8];\r\nassert(isequal(knights_watch(x,16,15),0.4666))\r\n%%\r\nx =[3,1];\r\nassert(isequal(knights_watch(x,16,50),0.0037))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":13,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-03-25T18:55:22.000Z","updated_at":"2026-01-23T12:14:39.000Z","published_at":"2020-03-25T18:55:22.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[\\\"Night gathers, and now my watch begins\\\"]]\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\u003eA knight is placed on an n-by-n sized chessboard at the position x. Find the probability that after k steps, the knight will remain within the chessboard.\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\u003eAny knight's move that places him outside the board should be considered invalid.\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[ For simplicity, the knight's position on the chessboard is defined with the numeric\\n notation instead of algebraic notation. so 'Ka1' is represented as (1,1).]]\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\u003eBrief explanation:\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[Say the knight is placed in pos-(1,1). A knight has 8 possible moves. So in the next move, \\nthe Knight can go to 8 different positions in the chessboard. But among them, only 2\\npositions are valid i.e. the knight remains within the chessboard and they are -\\n(3,2) \u0026 (2,3). So the prob. is 2/8 after 1 move. What will be the probability after k moves?]]\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":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":1260,"title":"RISK board game battle simulation","description":"Given two positive integer inputs, a (attacker army units) and d (defender army units) return the probablity of victory (from 0.000 to 1.000) to +- 0.02 accuracy. The rules are given below for those unfamiliar with the game. \r\n\r\nIn the board game RISK battles are determined by the conflict of armies, namely the attacking army and the defending army. The results is determined as follows: the attacker rolls 3 six-sided die and the defender rolls 2 die. The highest two numbers of each player are compared respectively, and the higher number wins (this means the opposing army loses one unit). In the case of a tie the defender wins. For example:\r\n\r\nAttacker has 10 units\r\nDefender has 10 units\r\n\r\nAttacker rolls [6 3 2]\r\nDefender rolls [4 3]\r\n\r\nThe first comparison is attacker - 6, defender - 4. Since the attacker is higher, the defender loses one unit. Hence Attacker has 10 units, Defender now has 9 units.\r\n\r\nThe first comparison is attacker - 3, defender - 3. Since the defender is higher, the attacker loses one unit. Hence Attacker has 9 units, Defender now has 9 units.\r\n\r\nThis is continued until either the attacker has only one unit left, in which case the defender wins the battle; or the defender has no units left, in which case the attacker wins the battle.\r\n\r\nThis is one further rule: the number of die any player may roll cannot be more than the their units in case of the defender, or their units + 1 in case of the attacker. \r\n\r\nExample:\r\nAttacker has 3 units,\r\nDefender has 1 units.\r\n\r\nAttacker rolls 2 die (3 - 1),\r\nDefender rolls 1 die.","description_html":"\u003cp\u003eGiven two positive integer inputs, a (attacker army units) and d (defender army units) return the probablity of victory (from 0.000 to 1.000) to +- 0.02 accuracy. The rules are given below for those unfamiliar with the game.\u003c/p\u003e\u003cp\u003eIn the board game RISK battles are determined by the conflict of armies, namely the attacking army and the defending army. The results is determined as follows: the attacker rolls 3 six-sided die and the defender rolls 2 die. The highest two numbers of each player are compared respectively, and the higher number wins (this means the opposing army loses one unit). In the case of a tie the defender wins. For example:\u003c/p\u003e\u003cp\u003eAttacker has 10 units\r\nDefender has 10 units\u003c/p\u003e\u003cp\u003eAttacker rolls [6 3 2]\r\nDefender rolls [4 3]\u003c/p\u003e\u003cp\u003eThe first comparison is attacker - 6, defender - 4. Since the attacker is higher, the defender loses one unit. Hence Attacker has 10 units, Defender now has 9 units.\u003c/p\u003e\u003cp\u003eThe first comparison is attacker - 3, defender - 3. Since the defender is higher, the attacker loses one unit. Hence Attacker has 9 units, Defender now has 9 units.\u003c/p\u003e\u003cp\u003eThis is continued until either the attacker has only one unit left, in which case the defender wins the battle; or the defender has no units left, in which case the attacker wins the battle.\u003c/p\u003e\u003cp\u003eThis is one further rule: the number of die any player may roll cannot be more than the their units in case of the defender, or their units + 1 in case of the attacker.\u003c/p\u003e\u003cp\u003eExample:\r\nAttacker has 3 units,\r\nDefender has 1 units.\u003c/p\u003e\u003cp\u003eAttacker rolls 2 die (3 - 1),\r\nDefender rolls 1 die.\u003c/p\u003e","function_template":"function y = risk_prob(a, d)\r\n  y = 0.000;\r\nend","test_suite":"%%\r\na = 3;\r\nd = 0;\r\ny_correct = 1.000;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.01)\r\n\r\n%%\r\na = 1;\r\nd = 5;\r\ny_correct = 0.000;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.01)\r\n\r\n%%\r\na = 5;\r\nd = 3;\r\ny_correct = 0.642;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 4;\r\nd = 6;\r\ny_correct = 0.134;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 10;\r\nd = 10;\r\ny_correct = 0.480;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 7;\r\nd = 8;\r\ny_correct = 0.329;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 8;\r\nd = 7;\r\ny_correct = 0.5355;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 20;\r\nd = 10;\r\ny_correct = 0.965;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 4;\r\nd = 2;\r\ny_correct = 0.656;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 6;\r\nd = 4;\r\ny_correct = 0.638;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 2;\r\nd = 1;\r\ny_correct = 0.417;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 2;\r\nd = 2;\r\ny_correct = 0.104;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":6,"created_by":10338,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":42,"test_suite_updated_at":"2013-02-12T00:28:08.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-02-10T23:10:17.000Z","updated_at":"2026-02-15T07:37:57.000Z","published_at":"2013-02-10T23:10: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\u003eGiven two positive integer inputs, a (attacker army units) and d (defender army units) return the probablity of victory (from 0.000 to 1.000) to +- 0.02 accuracy. The rules are given below for those unfamiliar with 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn the board game RISK battles are determined by the conflict of armies, namely the attacking army and the defending army. The results is determined as follows: the attacker rolls 3 six-sided die and the defender rolls 2 die. The highest two numbers of each player are compared respectively, and the higher number wins (this means the opposing army loses one unit). In the case of a tie the defender wins. For example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAttacker has 10 units Defender has 10 units\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\u003eAttacker rolls [6 3 2] Defender rolls [4 3]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe first comparison is attacker - 6, defender - 4. Since the attacker is higher, the defender loses one unit. Hence Attacker has 10 units, Defender now has 9 units.\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 first comparison is attacker - 3, defender - 3. Since the defender is higher, the attacker loses one unit. Hence Attacker has 9 units, Defender now has 9 units.\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\u003eThis is continued until either the attacker has only one unit left, in which case the defender wins the battle; or the defender has no units left, in which case the attacker wins the battle.\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\u003eThis is one further rule: the number of die any player may roll cannot be more than the their units in case of the defender, or their units + 1 in case of the attacker.\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: Attacker has 3 units, Defender has 1 units.\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\u003eAttacker rolls 2 die (3 - 1), Defender rolls 1 die.\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":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":44885,"title":"Bridge and Torch Problem - Probability","description":"\u003chttps://en.wikipedia.org/wiki/Bridge_and_torch_problem Details of the problem ...\u003e \r\n\r\nThere are four people who wants to cross the bridge. But we don't know exactly who will cross the bridge in which time. However, we know that a person can cross the bridge in n1 minutes (n1 is randomly selected from the range 1:n, n is the first input). All crossing times are integers. They use *Crossing Model* to cross the bridge. In each turn, they randomly select the person(s) who will cross the bridge. What is the probability that they will cross the bridge less than or equal to t minutes (t is the second input).\r\n\r\nLet's assume first input n = 3. That means people will cross the bridge in 1, 2 or 3 minutes. all of them can cross the bridge in 1 minute or maybe all of them can cross the bridge in 3 minutes. Possibilities are listed below.\r\n\r\n  crossingTimeList = [\r\n1\t1\t1\t1\r\n1\t1\t1\t2\r\n1\t1\t1\t3\r\n1\t1\t2\t2\r\n1\t1\t2\t3\r\n1\t1\t3\t3\r\n1\t2\t2\t2\r\n1\t2\t2\t3\r\n1\t2\t3\t3\r\n1\t3\t3\t3\r\n2\t2\t2\t2\r\n2\t2\t2\t3\r\n2\t2\t3\t3\r\n2\t3\t3\t3\r\n3\t3\t3\t3]\r\n\r\nIf first line is the case, all of the people will cross the bridge in 1 minute. There will be 108 cases  ( |108 = 4C2 X 2C1 X 3C2 X 3C1| ) taking 5 minutes. All of them will be less than or equal to 10 minutes (which is input 2). \r\n\r\nIf ninth line is the case, one person will cross the bridge in one minute, one person will cross the bridge in two minutes, and others will cross the bridge in 3 minutes. 8 out of 108 ways will take less than or equal to 10 minutes. \r\n\r\nIf last one is the case, all of them will cross the bridge in three minutes indicates that all of the journeys will take 15 minutes (longer than input2 or 10 minutes).\r\n\r\nResult of the crossingTimeList are as follow\r\n\r\n  result = [\r\n108\t108\r\n108\t108\r\n060\t108\r\n108\t108\r\n054\t108\r\n026\t108\r\n108\t108\r\n304\t108\r\n008\t108\r\n000\t108\r\n108\t108\r\n000\t108\r\n000\t108\r\n000\t108\r\n000\t108]\r\n\r\nAs a result 722 out of 1620 ways will take \u003c= 10 minutes (722/1620=0.4457).\r\n\r\n\r\n*Assumption 1:* for this problem only four people will cross the bridge\r\n\r\n*Assumption 2:* crossing times are integer\r\n\r\n*Crossing Model:* 2 out of 4 people will cross the bridge, one of them will return. two out of 3 people will cross the bridge, one out of three people will return. Remaining two people will cross the bridge.  ","description_html":"\u003cp\u003e\u003ca href = \"https://en.wikipedia.org/wiki/Bridge_and_torch_problem\"\u003eDetails of the problem ...\u003c/a\u003e\u003c/p\u003e\u003cp\u003eThere are four people who wants to cross the bridge. But we don't know exactly who will cross the bridge in which time. However, we know that a person can cross the bridge in n1 minutes (n1 is randomly selected from the range 1:n, n is the first input). All crossing times are integers. They use \u003cb\u003eCrossing Model\u003c/b\u003e to cross the bridge. In each turn, they randomly select the person(s) who will cross the bridge. What is the probability that they will cross the bridge less than or equal to t minutes (t is the second input).\u003c/p\u003e\u003cp\u003eLet's assume first input n = 3. That means people will cross the bridge in 1, 2 or 3 minutes. all of them can cross the bridge in 1 minute or maybe all of them can cross the bridge in 3 minutes. Possibilities are listed below.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ecrossingTimeList = [\r\n1\t1\t1\t1\r\n1\t1\t1\t2\r\n1\t1\t1\t3\r\n1\t1\t2\t2\r\n1\t1\t2\t3\r\n1\t1\t3\t3\r\n1\t2\t2\t2\r\n1\t2\t2\t3\r\n1\t2\t3\t3\r\n1\t3\t3\t3\r\n2\t2\t2\t2\r\n2\t2\t2\t3\r\n2\t2\t3\t3\r\n2\t3\t3\t3\r\n3\t3\t3\t3]\r\n\u003c/pre\u003e\u003cp\u003eIf first line is the case, all of the people will cross the bridge in 1 minute. There will be 108 cases  ( \u003ctt\u003e108 = 4C2 X 2C1 X 3C2 X 3C1\u003c/tt\u003e ) taking 5 minutes. All of them will be less than or equal to 10 minutes (which is input 2).\u003c/p\u003e\u003cp\u003eIf ninth line is the case, one person will cross the bridge in one minute, one person will cross the bridge in two minutes, and others will cross the bridge in 3 minutes. 8 out of 108 ways will take less than or equal to 10 minutes.\u003c/p\u003e\u003cp\u003eIf last one is the case, all of them will cross the bridge in three minutes indicates that all of the journeys will take 15 minutes (longer than input2 or 10 minutes).\u003c/p\u003e\u003cp\u003eResult of the crossingTimeList are as follow\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eresult = [\r\n108\t108\r\n108\t108\r\n060\t108\r\n108\t108\r\n054\t108\r\n026\t108\r\n108\t108\r\n304\t108\r\n008\t108\r\n000\t108\r\n108\t108\r\n000\t108\r\n000\t108\r\n000\t108\r\n000\t108]\r\n\u003c/pre\u003e\u003cp\u003eAs a result 722 out of 1620 ways will take \u0026lt;= 10 minutes (722/1620=0.4457).\u003c/p\u003e\u003cp\u003e\u003cb\u003eAssumption 1:\u003c/b\u003e for this problem only four people will cross the bridge\u003c/p\u003e\u003cp\u003e\u003cb\u003eAssumption 2:\u003c/b\u003e crossing times are integer\u003c/p\u003e\u003cp\u003e\u003cb\u003eCrossing Model:\u003c/b\u003e 2 out of 4 people will cross the bridge, one of them will return. two out of 3 people will cross the bridge, one out of three people will return. Remaining two people will cross the bridge.\u003c/p\u003e","function_template":"function y = bridgeProb(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nfiletext = fileread('bridgeProb.m');\r\nassert(isempty(strfind(filetext, 'assert')))\r\nassert(isempty(strfind(filetext, 'echo')))\r\n%%\r\nx = [3 10];\r\nassert(and( ge(bridgeProb(x), 0.43) , le(bridgeProb(x), 0.45)))\r\n%%\r\nx = [8 5];\r\nassert(and( ge(bridgeProb(x), 0.00) , le(bridgeProb(x), 0.01)))\r\n%%\r\nx = [10 5];\r\nassert(and( ge(bridgeProb(x), 0.00) , le(bridgeProb(x), 0.01)))\r\n%%\r\nx = [8 15];\r\nassert(and( ge(bridgeProb(x), 0.10) , le(bridgeProb(x), 0.12)))\r\n%%\r\nx = [8 17];\r\nassert(and( ge(bridgeProb(x), 0.15) , le(bridgeProb(x), 0.17)))\r\n%%\r\nx = [10 35];\r\nassert(and( ge(bridgeProb(x), 0.60) , le(bridgeProb(x), 0.62)))\r\n%%\r\nx = [10 35];\r\nassert(and( ge(bridgeProb(x), 0.60) , le(bridgeProb(x), 0.62)))\r\n%%\r\nx = [10 40];\r\nassert(and( ge(bridgeProb(x), 0.78) , le(bridgeProb(x), 0.80)))\r\n%%\r\nx = [7 20];\r\nassert(and( ge(bridgeProb(x), 0.35) , le(bridgeProb(x), 0.37)))\r\n%%\r\nx = [8 25];\r\nassert(and( ge(bridgeProb(x), 0.45) , le(bridgeProb(x), 0.47)))\r\n%%\r\nx = [8 10];\r\nassert(and( ge(bridgeProb(x), 0.01) , le(bridgeProb(x), 0.03)))\r\n%%\r\nx = [9 15];\r\nassert(and( ge(bridgeProb(x), 0.06) , le(bridgeProb(x), 0.08)))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":4,"test_suite_updated_at":"2019-04-23T07:16:06.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2019-04-21T08:29:03.000Z","updated_at":"2025-05-02T02:43:56.000Z","published_at":"2019-04-22T12:28:10.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:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Bridge_and_torch_problem\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDetails of the problem ...\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\u003eThere are four people who wants to cross the bridge. But we don't know exactly who will cross the bridge in which time. However, we know that a person can cross the bridge in n1 minutes (n1 is randomly selected from the range 1:n, n is the first input). All crossing times are integers. They use\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eCrossing Model\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e to cross the bridge. In each turn, they randomly select the person(s) who will cross the bridge. What is the probability that they will cross the bridge less than or equal to t minutes (t is the second 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLet's assume first input n = 3. That means people will cross the bridge in 1, 2 or 3 minutes. all of them can cross the bridge in 1 minute or maybe all of them can cross the bridge in 3 minutes. Possibilities are listed below.\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[crossingTimeList = [\\n1  1  1  1\\n1  1  1  2\\n1  1  1  3\\n1  1  2  2\\n1  1  2  3\\n1  1  3  3\\n1  2  2  2\\n1  2  2  3\\n1  2  3  3\\n1  3  3  3\\n2  2  2  2\\n2  2  2  3\\n2  2  3  3\\n2  3  3  3\\n3  3  3  3]]]\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 first line is the case, all of the people will cross the bridge in 1 minute. There will be 108 cases (\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\u003e108 = 4C2 X 2C1 X 3C2 X 3C1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ) taking 5 minutes. All of them will be less than or equal to 10 minutes (which is input 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\u003eIf ninth line is the case, one person will cross the bridge in one minute, one person will cross the bridge in two minutes, and others will cross the bridge in 3 minutes. 8 out of 108 ways will take less than or equal to 10 minutes.\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 last one is the case, all of them will cross the bridge in three minutes indicates that all of the journeys will take 15 minutes (longer than input2 or 10 minutes).\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\u003eResult of the crossingTimeList are as follow\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[result = [\\n108  108\\n108  108\\n060  108\\n108  108\\n054  108\\n026  108\\n108  108\\n304  108\\n008  108\\n000  108\\n108  108\\n000  108\\n000  108\\n000  108\\n000  108]]]\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\u003eAs a result 722 out of 1620 ways will take \u0026lt;= 10 minutes (722/1620=0.4457).\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\u003eAssumption 1:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for this problem only four people will cross the bridge\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\u003eAssumption 2:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e crossing times are integer\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\u003eCrossing Model:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 2 out of 4 people will cross the bridge, one of them will return. two out of 3 people will cross the bridge, one out of three people will return. Remaining two people will cross the bridge.\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":44502,"title":"Anyone for tennis?  Your chances of winning a (standard) game","description":"Imagine you are playing tennis, and for _each point_ played your chance of winning is |x| % (input as a |\u003chttps://au.mathworks.com/help/matlab/ref/uint8.html uint8\u003e|).  Given the \u003chttp://www.itftennis.com/procircuit/about-pro-circuit/rules-regulations.aspx ITF's scoring system for a \"standard game\" of tennis\u003e (excerpted below), please determine your likelihood of winning a game (output as a |\u003chttps://au.mathworks.com/help/matlab/ref/single.html single\u003e|).  \r\n\r\nNote that as |x| is taken to be the same for every point in this problem, it does not matter whether you are serving or not.  \r\n\r\nEXAMPLE\r\n\r\n x = uint8(40)\r\n chance = single(0.2642707692307693)\r\n\r\n-----\r\n\r\n*\"* A standard game is scored as follows with the server’s score being called first:\r\n\r\n* No point - “Love”\r\n* First point - “15”\r\n* Second point - “30”\r\n* Third point - “40”\r\n* Fourth point - “Game”\r\n\r\nexcept that if each player/team has won three points, the score is “Deuce”.\r\nAfter “Deuce”, the score is “Advantage” for the player/team who wins the next point. If that same player/team also wins the next point, that player/team wins the “Game”; if the opposing player/team wins the next point, the score is again “Deuce”. A player/team needs to win two consecutive points immediately after “Deuce” to win the “Game”. *\"*\r\n\r\n-----\r\n\r\nSee also \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44503 Problem 44503. Anyone for tennis? Your chances of winning a tie-break game\u003e.","description_html":"\u003cp\u003eImagine you are playing tennis, and for \u003ci\u003eeach point\u003c/i\u003e played your chance of winning is \u003ctt\u003ex\u003c/tt\u003e % (input as a \u003ctt\u003e\u003ca href = \"https://au.mathworks.com/help/matlab/ref/uint8.html\"\u003euint8\u003c/a\u003e\u003c/tt\u003e).  Given the \u003ca href = \"http://www.itftennis.com/procircuit/about-pro-circuit/rules-regulations.aspx\"\u003eITF's scoring system for a \"standard game\" of tennis\u003c/a\u003e (excerpted below), please determine your likelihood of winning a game (output as a \u003ctt\u003e\u003ca href = \"https://au.mathworks.com/help/matlab/ref/single.html\"\u003esingle\u003c/a\u003e\u003c/tt\u003e).\u003c/p\u003e\u003cp\u003eNote that as \u003ctt\u003ex\u003c/tt\u003e is taken to be the same for every point in this problem, it does not matter whether you are serving or not.\u003c/p\u003e\u003cp\u003eEXAMPLE\u003c/p\u003e\u003cpre\u003e x = uint8(40)\r\n chance = single(0.2642707692307693)\u003c/pre\u003e\u003cp\u003e-----\u003c/p\u003e\u003cp\u003e\u003cb\u003e\"\u003c/b\u003e A standard game is scored as follows with the server’s score being called first:\u003c/p\u003e\u003cul\u003e\u003cli\u003eNo point - “Love”\u003c/li\u003e\u003cli\u003eFirst point - “15”\u003c/li\u003e\u003cli\u003eSecond point - “30”\u003c/li\u003e\u003cli\u003eThird point - “40”\u003c/li\u003e\u003cli\u003eFourth point - “Game”\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eexcept that if each player/team has won three points, the score is “Deuce”.\r\nAfter “Deuce”, the score is “Advantage” for the player/team who wins the next point. If that same player/team also wins the next point, that player/team wins the “Game”; if the opposing player/team wins the next point, the score is again “Deuce”. A player/team needs to win two consecutive points immediately after “Deuce” to win the “Game”. \u003cb\u003e\"\u003c/b\u003e\u003c/p\u003e\u003cp\u003e-----\u003c/p\u003e\u003cp\u003eSee also \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44503\"\u003eProblem 44503. Anyone for tennis? Your chances of winning a tie-break game\u003c/a\u003e.\u003c/p\u003e","function_template":"function chance = standardGame(x)\r\n\r\n    % Your comments \r\n    \r\nend","test_suite":"%% Please do not try to hack the Test Suite.  \r\n% The Test Suite will be updated if inappropriate submissions are received.  \r\n% This includes hard-coded (pre-calculated, externally calculated, manually calculated) 'solutions'.\r\nfiletext = fileread('standardGame.m');\r\nvec = [923273, 144780, 713710, 217788, 507812, 992110, 170355, 264270, 376851, 475014];\r\nmsg = 'Please do not hard-code your ''solution''.';\r\nassert( all( arrayfun(@(z) isempty(strfind(filetext, num2str(z))), vec) ) , msg )\r\n\r\n%% Test self-consistency:  \r\n% There are only two players, so the chances for each should add up to one.  \r\nassert( abs(standardGame(100)+standardGame(0) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(standardGame(90)+standardGame(10) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(standardGame(80)+standardGame(20) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(standardGame(70)+standardGame(30) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(standardGame(60)+standardGame(40) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(standardGame(50)+standardGame(50) - 1)  \u003c 20 * eps(single(1)) )\r\n\r\n%%\r\nx = uint8(50);\r\ny_correct = 0.50;\r\nassert( isequal(standardGame(x), y_correct) )\r\n\r\n%%\r\nx = uint8(0);\r\ny_correct = 0;\r\nassert( isequal(standardGame(x), y_correct) )\r\n\r\n%%\r\nx = uint8(100);\r\ny_correct = 1;\r\nassert( isequal(standardGame(x), y_correct) )\r\n\r\n%%\r\nx = uint8(5);\r\ny_correct = 0.0000923273480663;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(10);\r\ny_correct = 0.0014478048780488;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(15);\r\ny_correct = 0.0071371057046980;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(20);\r\ny_correct = 0.0217788235294118;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(25);\r\ny_correct = 0.0507812500000000;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(30);\r\ny_correct = 0.0992110344827586;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(35);\r\ny_correct = 0.1703553555045871;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(40);\r\ny_correct = 0.2642707692307693;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(45);\r\ny_correct = 0.3768514975247527;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(49);\r\ny_correct = 0.4750149924031987;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%% Test adherence to instructions\r\nfor i = 1:5\r\n    x = uint8( randi(100) );\r\n    assert( isequal(class(standardGame(x)), 'single') )\r\nend;\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":64439,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":4,"test_suite_updated_at":"2018-01-18T10:56:38.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2018-01-18T00:25:34.000Z","updated_at":"2019-07-02T13:23:52.000Z","published_at":"2018-01-18T01:51:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eImagine you are playing tennis, and for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eeach point\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e played your chance of winning 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e % (input as 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://au.mathworks.com/help/matlab/ref/uint8.html\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003euint8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e). Given 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.itftennis.com/procircuit/about-pro-circuit/rules-regulations.aspx\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eITF's scoring system for a \\\"standard game\\\" of tennis\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (excerpted below), please determine your likelihood of winning a game (output as 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://au.mathworks.com/help/matlab/ref/single.html\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esingle\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\u003eNote that as\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\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is taken to be the same for every point in this problem, it does not matter whether you are serving 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEXAMPLE\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x = uint8(40)\\n chance = single(0.2642707692307693)]]\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\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\u003e\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e A standard game is scored as follows with the server’s score being called first:\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\u003eNo point - “Love”\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\u003eFirst point - “15”\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSecond point - “30”\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\u003eThird point - “40”\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFourth point - “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\u003eexcept that if each player/team has won three points, the score is “Deuce”. After “Deuce”, the score is “Advantage” for the player/team who wins the next point. If that same player/team also wins the next point, that player/team wins the “Game”; if the opposing player/team wins the next point, the score is again “Deuce”. A player/team needs to win two consecutive points immediately after “Deuce” to win the “Game”.\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\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\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=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44503\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44503. Anyone for tennis? Your chances of winning a tie-break game\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44503,"title":"Anyone for tennis?  Your chances of winning a tie-break game","description":"Imagine you are playing tennis and the score has reached 'six games all' in a Tie-break Set, so therefore the next game shall be a 'tie-break game', which is now to be played to decide the outcome of this set.  For _each point_ played in the tie-break game your chance of winning is |x| % (input as a |\u003chttps://au.mathworks.com/help/matlab/ref/uint8.html uint8\u003e|).  Given the \u003chttp://www.itftennis.com/procircuit/about-pro-circuit/rules-regulations.aspx ITF's scoring system for a \"tie-break game\" of tennis\u003e (excerpted below), please determine your likelihood of winning the tie-break game (output as a |\u003chttps://au.mathworks.com/help/matlab/ref/single.html single\u003e|).  \r\n\r\nNote that as |x| is taken to be the same for every point in this problem, it does not matter whether you are serving or not.  \r\n\r\nEXAMPLE\r\n\r\n x = uint8(40)\r\n chance = single(0.2125443387076924)\r\n\r\n-----\r\n\r\n*\"* During a tie-break game, points are scored “Zero”, “1”, “2”, “3”, etc. The first player/team to win seven points wins the “Game” and “Set”, provided there is a margin of two points over the opponent(s). If necessary, the tie-break game shall continue until this margin is achieved. *\"*\r\n\r\n-----\r\n\r\nSee also \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44502 Problem 44502. Anyone for tennis? Your chances of winning a (standard) game\u003e.","description_html":"\u003cp\u003eImagine you are playing tennis and the score has reached 'six games all' in a Tie-break Set, so therefore the next game shall be a 'tie-break game', which is now to be played to decide the outcome of this set.  For \u003ci\u003eeach point\u003c/i\u003e played in the tie-break game your chance of winning is \u003ctt\u003ex\u003c/tt\u003e % (input as a \u003ctt\u003e\u003ca href = \"https://au.mathworks.com/help/matlab/ref/uint8.html\"\u003euint8\u003c/a\u003e\u003c/tt\u003e).  Given the \u003ca href = \"http://www.itftennis.com/procircuit/about-pro-circuit/rules-regulations.aspx\"\u003eITF's scoring system for a \"tie-break game\" of tennis\u003c/a\u003e (excerpted below), please determine your likelihood of winning the tie-break game (output as a \u003ctt\u003e\u003ca href = \"https://au.mathworks.com/help/matlab/ref/single.html\"\u003esingle\u003c/a\u003e\u003c/tt\u003e).\u003c/p\u003e\u003cp\u003eNote that as \u003ctt\u003ex\u003c/tt\u003e is taken to be the same for every point in this problem, it does not matter whether you are serving or not.\u003c/p\u003e\u003cp\u003eEXAMPLE\u003c/p\u003e\u003cpre\u003e x = uint8(40)\r\n chance = single(0.2125443387076924)\u003c/pre\u003e\u003cp\u003e-----\u003c/p\u003e\u003cp\u003e\u003cb\u003e\"\u003c/b\u003e During a tie-break game, points are scored “Zero”, “1”, “2”, “3”, etc. The first player/team to win seven points wins the “Game” and “Set”, provided there is a margin of two points over the opponent(s). If necessary, the tie-break game shall continue until this margin is achieved. \u003cb\u003e\"\u003c/b\u003e\u003c/p\u003e\u003cp\u003e-----\u003c/p\u003e\u003cp\u003eSee also \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44502\"\u003eProblem 44502. Anyone for tennis? Your chances of winning a (standard) game\u003c/a\u003e.\u003c/p\u003e","function_template":"function chance = tiebreakGame(x)\r\n\r\n    % Your comments \r\n    \r\nend","test_suite":"%% Please do not try to hack the Test Suite.  \r\n% The Test Suite will be updated if inappropriate submissions are received.  \r\n% This includes hard-coded (pre-calculated, externally calculated, manually calculated) 'solutions'.\r\n\r\n% EDIT (2019-06-24).  Anti-hacking provision\r\n% Ensure builtin function will be called.  (Probably only the second of these will work.)  \r\n! del fileread.m\r\n! rm -v fileread.m\r\n% Disallow certain words  \r\nRE = regexp(fileread('tiebreakGame.m'), '\\w+', 'match');\r\ntabooWords = {'ans', 'assert', 'freepass'};\r\ntestResult = cellfun( @(z) ismember(z, tabooWords), RE );\r\nmsg = ['Please do not do that in your code!' char([10 13]) ...\r\n    'Found: ' strjoin(RE(testResult)) '.' char([10 13]) ...\r\n    'Banned word.' char([10 13])];\r\nassert(~any(  cellfun( @(z) ismember(z, tabooWords), RE )  ), msg)\r\n% END EDIT (2019-06-24)\r\n\r\nfiletext = fileread('tiebreakGame.m');\r\nvec = [5242178 5616877 7920095 4815022 1826772 5089792,5089793 1134259 2125443 3458492 4684486];\r\nmsg = 'Please do not hard-code your ''solution''.';\r\nassert( all( arrayfun(@(z) isempty(strfind(filetext, num2str(z))), vec) ) , msg )\r\n\r\n%% Test self-consistency:  \r\n% There are only two players, so the chances for each should add up to one.  \r\nassert( abs(tiebreakGame(100)+tiebreakGame(0) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(tiebreakGame(90)+tiebreakGame(10) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(tiebreakGame(80)+tiebreakGame(20) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(tiebreakGame(70)+tiebreakGame(30) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(tiebreakGame(60)+tiebreakGame(40) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(tiebreakGame(50)+tiebreakGame(50) - 1)  \u003c 20 * eps(single(1)) )\r\n\r\n%%\r\nx = uint8(50);\r\ny_correct = 0.50;\r\nassert( isequal(tiebreakGame(x), y_correct) )\r\n\r\n%%\r\nx = uint8(0);\r\ny_correct = 0;\r\nassert( isequal(tiebreakGame(x), y_correct) )\r\n\r\n%%\r\nx = uint8(100);\r\ny_correct = 1;\r\nassert( isequal(tiebreakGame(x), y_correct) )\r\n\r\n%%\r\nx = uint8(5);\r\ny_correct = 0.0000005242178465;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(10);\r\ny_correct = 0.0000561687707317;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(15);\r\ny_correct = 0.0007920095157735;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(20);\r\ny_correct = 0.0048150226823529;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(25);\r\ny_correct = 0.0182677268981934;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(30);\r\ny_correct = 0.0508979303379310;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(35);\r\ny_correct = 0.1134259300865006;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(40);\r\ny_correct = 0.2125443387076924;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(45);\r\ny_correct = 0.3458492328206313;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(49);\r\ny_correct = 0.4684486239083455;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%% Test adherence to instructions\r\nfor i = 1:5\r\n    x = uint8( randi(100) );\r\n    assert( isequal(class(tiebreakGame(x)), 'single') )\r\nend;\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":64439,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":4,"test_suite_updated_at":"2019-07-02T13:20:57.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-18T10:19:54.000Z","updated_at":"2019-07-02T13:20:57.000Z","published_at":"2018-01-18T10:57:34.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eImagine you are playing tennis and the score has reached 'six games all' in a Tie-break Set, so therefore the next game shall be a 'tie-break game', which is now to be played to decide the outcome of this set. For\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eeach point\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e played in the tie-break game your chance of winning 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e % (input as 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://au.mathworks.com/help/matlab/ref/uint8.html\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003euint8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e). Given 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.itftennis.com/procircuit/about-pro-circuit/rules-regulations.aspx\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eITF's scoring system for a \\\"tie-break game\\\" of tennis\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (excerpted below), please determine your likelihood of winning the tie-break game (output as 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://au.mathworks.com/help/matlab/ref/single.html\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esingle\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\u003eNote that as\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\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is taken to be the same for every point in this problem, it does not matter whether you are serving 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEXAMPLE\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x = uint8(40)\\n chance = single(0.2125443387076924)]]\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\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\u003e\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e During a tie-break game, points are scored “Zero”, “1”, “2”, “3”, etc. The first player/team to win seven points wins the “Game” and “Set”, provided there is a margin of two points over the opponent(s). If necessary, the tie-break game shall continue until this margin is achieved.\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\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\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=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44502\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44502. Anyone for tennis? Your chances of winning a (standard) game\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":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":42685,"title":"Cody meets Xiangqi: foresee the unseen (Part 2)","description":"This is the second part of the Xiangqi series. The first part in this series is: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42674-cody-meets-xiangqi-foresee-the-unseen Cody meets Xiangqi: foresee the unseen (Part 1)\u003e\r\n\r\nBeing increasingly interested in \u003chttps://en.wikipedia.org/wiki/Xiangqi Xiangqi\u003e (a.k.a., *Chinese Chess*), Mr. Cody has designed a new Xiangqi match for \u003chttps://en.wikipedia.org/wiki/Xiang_Yu Xiang Yu\u003e and \u003chttps://de.wikipedia.org/wiki/Han_Gaozu Liu Bang\u003e by taking into account the likelihood of tie games. The new rule is described as follows:\r\n\r\nOnce\r\n\r\n   1) Xiang Yu wins Na games consecutively,\r\n   2) Liu Bang wins Nb games consecutively, \r\n   3) No ties occur consecutively, \r\n\r\n*whichever comes first*, Mr. Cody announces the outcome accordingly as follows:\r\n\r\n   1) Xiang Yu is the final winner,\r\n   2) Liu Bang is the final winner, \r\n   3) They end up with a final draw.\r\n\r\nAgain, Cody asks us --- active Cody players --- to foresee the outcome of this unseen match using Monte Carlo simulations. Our task is to write the following function\r\n\r\n                         [Pa, Pb, Pc] = Xiangqi2(a, b, Na, Nb, Nc)\r\n\r\nwhere \r\n\r\n* a: the probability that Xiang Yu wins one individual game\r\n* b: the probability that Liu Bang wins one individual game\r\n* Na: # of consecutive wins required for Xiang Yu to become the final winner\r\n* Nb: # of consecutive wins required for Liu Bang to become the final winner\r\n* Nc: # of consecutive ties required to result in a final draw\r\n* Pa: the probability that Xiang Yu wins the match\r\n* Pb: the probability that Liu Bang wins the match\r\n* Pc: the probability of a final draw\r\n\r\nThe main focus of this problem is on *Monte Carlo simulations*, rather than analytical approaches. Your provided solution Xiangqi2.m will be checked by a P-file EvaluateSolution.p, which mainly does 3 things as follows:\r\n\r\n1) Call your function [Pa, Pb, Pc] = Xiangqi2(a, b, Na, Nb, Nc) and then Check if the result P = [Pa, Pb, Pc] is within tolerance of its expected value Q. That is, If norm(P - Q) \u003c tol holds, it means that your solution is accurate enough. If this does not hold, your solution will be rejected. \r\n\r\n2) Check if your solution is based on *pure Monte Carlo simulations* or *analytical approaches*. If it is based on analytical approaches (i.e., using analytical expressions to directly compute the probabilities), then your solution will be rejected. EvaluateSolution.p accomplishes this goal by exploiting a combination of distinct features possessed by analytical solutions, but are generally not shared by Monte Carlo simulations. \r\n\r\n3) If your solution passes the above two checks, then the score of your solution will be determined based on the speed of your code. The faster your solution is, the smaller score you get. \r\n\r\nIf you have any concerns or suggestions on this problem, please feel free to leave me a comment. Thanks. \r\n\r\n ","description_html":"\u003cp\u003eThis is the second part of the Xiangqi series. The first part in this series is: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42674-cody-meets-xiangqi-foresee-the-unseen\"\u003eCody meets Xiangqi: foresee the unseen (Part 1)\u003c/a\u003e\u003c/p\u003e\u003cp\u003eBeing increasingly interested in \u003ca href = \"https://en.wikipedia.org/wiki/Xiangqi\"\u003eXiangqi\u003c/a\u003e (a.k.a., \u003cb\u003eChinese Chess\u003c/b\u003e), Mr. Cody has designed a new Xiangqi match for \u003ca href = \"https://en.wikipedia.org/wiki/Xiang_Yu\"\u003eXiang Yu\u003c/a\u003e and \u003ca href = \"https://de.wikipedia.org/wiki/Han_Gaozu\"\u003eLiu Bang\u003c/a\u003e by taking into account the likelihood of tie games. The new rule is described as follows:\u003c/p\u003e\u003cp\u003eOnce\u003c/p\u003e\u003cpre\u003e   1) Xiang Yu wins Na games consecutively,\r\n   2) Liu Bang wins Nb games consecutively, \r\n   3) No ties occur consecutively, \u003c/pre\u003e\u003cp\u003e\u003cb\u003ewhichever comes first\u003c/b\u003e, Mr. Cody announces the outcome accordingly as follows:\u003c/p\u003e\u003cpre\u003e   1) Xiang Yu is the final winner,\r\n   2) Liu Bang is the final winner, \r\n   3) They end up with a final draw.\u003c/pre\u003e\u003cp\u003eAgain, Cody asks us --- active Cody players --- to foresee the outcome of this unseen match using Monte Carlo simulations. Our task is to write the following function\u003c/p\u003e\u003cpre\u003e                         [Pa, Pb, Pc] = Xiangqi2(a, b, Na, Nb, Nc)\u003c/pre\u003e\u003cp\u003ewhere\u003c/p\u003e\u003cul\u003e\u003cli\u003ea: the probability that Xiang Yu wins one individual game\u003c/li\u003e\u003cli\u003eb: the probability that Liu Bang wins one individual game\u003c/li\u003e\u003cli\u003eNa: # of consecutive wins required for Xiang Yu to become the final winner\u003c/li\u003e\u003cli\u003eNb: # of consecutive wins required for Liu Bang to become the final winner\u003c/li\u003e\u003cli\u003eNc: # of consecutive ties required to result in a final draw\u003c/li\u003e\u003cli\u003ePa: the probability that Xiang Yu wins the match\u003c/li\u003e\u003cli\u003ePb: the probability that Liu Bang wins the match\u003c/li\u003e\u003cli\u003ePc: the probability of a final draw\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe main focus of this problem is on \u003cb\u003eMonte Carlo simulations\u003c/b\u003e, rather than analytical approaches. Your provided solution Xiangqi2.m will be checked by a P-file EvaluateSolution.p, which mainly does 3 things as follows:\u003c/p\u003e\u003cp\u003e1) Call your function [Pa, Pb, Pc] = Xiangqi2(a, b, Na, Nb, Nc) and then Check if the result P = [Pa, Pb, Pc] is within tolerance of its expected value Q. That is, If norm(P - Q) \u0026lt; tol holds, it means that your solution is accurate enough. If this does not hold, your solution will be rejected.\u003c/p\u003e\u003cp\u003e2) Check if your solution is based on \u003cb\u003epure Monte Carlo simulations\u003c/b\u003e or \u003cb\u003eanalytical approaches\u003c/b\u003e. If it is based on analytical approaches (i.e., using analytical expressions to directly compute the probabilities), then your solution will be rejected. EvaluateSolution.p accomplishes this goal by exploiting a combination of distinct features possessed by analytical solutions, but are generally not shared by Monte Carlo simulations.\u003c/p\u003e\u003cp\u003e3) If your solution passes the above two checks, then the score of your solution will be determined based on the speed of your code. The faster your solution is, the smaller score you get.\u003c/p\u003e\u003cp\u003eIf you have any concerns or suggestions on this problem, please feel free to leave me a comment. Thanks.\u003c/p\u003e","function_template":"function [Pa, Pb, Pc] = Xiangqi2(a, b, Na, Nb, Nc)\r\n% a: the probability that Xiang Yu wins one individual game\r\n% b: the probability that Liu Bang wins one individual game\r\n% Na: # of consecutive wins required for Xiang Yu to become the final winner\r\n% Nb: # of consecutive wins required for Liu Bang to become the final winner\r\n% Nc: # of consecutive ties required to result in a final draw\r\n% Pa: the probability that Xiang Yu wins the match\r\n% Pb: the probability that Liu Bang wins the match\r\n% Pc: the probability of a final draw\r\n    Pa = ;\r\n    Pb = ;\r\n    Pc = ;\r\nend","test_suite":"%%\r\n% Thanks to Alfonso Nieto-Castanon\r\nurlwrite('https://sites.google.com/a/alfnie.com/alfnie/software/SetSolutionScore.p?attredirects=0\u0026amp;d=1','SetSolutionScore.p');\r\nrehash path;\r\n\r\n%%\r\nfh = fopen('EvaluateSolution.p','wb');\r\nfwrite(fh, hex2dec(reshape('7630312E30307630302E3030000C701C97F61FB1000002D5000001CF000004E73DD68930A391F7C60A534B45A03EAF72EB08941F39EE01BF25BAE04DF43CF342FC1A763DF6B8F26BBED0BD4F2ABBB5927B1EEBAE8795E487F6E4EF2737CBB6646BC4DF145E14664B3A4DACCD7CB01C4EC2328AD76F196231D2CA02CDC2B15466FBA5BDDF9E6C0E5DE12CF07B2AAA50BD2F04FFB92E9BECBE232E01031340A8EDCA5C10DAC01BBE43685ED0AB79D9C6F2A090FB4E0E75CAA236D3D73AD659E0705C42792BC77D85951B2FC49DE856FB97AFD74C1DB66C874EDF5517BCFA14C6706CA5E61DE60F2771B64F6D634B858A1A30AD7C49778534CCCE7551C637DC53846B02140046F729C5EB2DC9C65F16C2FC4F34EA9F03A2056B8218ACAB9A9A8BC5DC8F2F3312740F86626ABA38E00903CE76846DEE175BEE04DC0815E050E4CD95BA8E5BD27A0B57F2413B71A0E4837FB0F86328AA82732C584F1F55C6CCD79CBC69D052011BA93357AAE3568E0086F159C083D665645A38584955283925F900254A6562F0C755323C40805328D04F27FD863E8B774B52E27FC3AA30CE689AC57DEFEE274DBBC2A4D9D320CF19AD873AA0AE806721EE78496F7ADA99EA48060F26FDEE7ED5E9F85B27F79AE176A6E8EAC4DD5127299122FF88139BC4B56A2ED3C5338A72676C4C99AD6DEBCD8BB5EB09',2,[]).')); rehash path; fclose(fh);\r\n\r\n%%\r\nfid = fopen('Xiangqi2.m');\r\ndelim = {' ', '\\n', ',', '.', ';', '''', '@', '+', '-', '*', '/', '\\', '^', '\u003e', '\u003c', '=', '\u0026', '|', '~', '{', '}', '[', ']', '(', ')'};\r\nfile = textscan(fid, '%s', 'CommentStyle', '%', 'MultipleDelimsAsOne', 1, 'Delimiter', delim); fclose(fid); \r\nassert(~any(ismember({'rng','RandStream','seed','state','twister','shufle','default'},file{1})));\r\n\r\n%%\r\na = 0; b = 0; Na = 2; Nb = 3; Nc = 2; tol = 1e-6;\r\nEvaluateSolution(a, b, Na, Nb, Nc, tol); \r\n\r\n%%\r\na = 0; b = 1; Na = 1; Nb = 2; Nc = 1; tol = 1e-6;\r\nEvaluateSolution(a, b, Na, Nb, Nc, tol); \r\n\r\n%%\r\na = 1; b = 0; Na = 3; Nb = 2; Nc = 1; tol = 1e-6;\r\nEvaluateSolution(a, b, Na, Nb, Nc, tol); \r\n\r\n%%\r\na = 0.15; b = 0.85; Na = 4; Nb = 2; Nc = 1; tol = 1e-4;\r\nEvaluateSolution(a, b, Na, Nb, Nc, tol);\r\n\r\n%%\r\na = 0.9; b = 0; Na = 3; Nb = 1; Nc = 2; tol = 1e-3;\r\nEvaluateSolution(a, b, Na, Nb, Nc, tol);\r\n\r\n%%\r\na = 0.65; b = 0.3; Na = 3; Nb = 2; Nc = 2; tol = 1e-3;\r\nEvaluateSolution(a, b, Na, Nb, Nc, tol);\r\n\r\n%%\r\nNa = 3; Nb = 2; Nc = 1; tol = 2e-3; \r\np = sort(rand(2,30)); \r\np = sort([p(1,:);diff(p);1-p(2,:)]);\r\nfor k = size(p,2):-1:1\r\n    a = p(3,k); b = p(2,k);\r\n    score(k) = EvaluateSolution(a, b, Na, Nb, Nc, tol);    \r\nend\r\nSetSolutionScore(round(mean(score)));","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":5,"test_suite_updated_at":"2015-11-12T00:41:35.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2015-11-08T20:51:55.000Z","updated_at":"2015-11-12T03:39:15.000Z","published_at":"2015-11-10T00:22:37.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 the second part of the Xiangqi series. The first part in this series is:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42674-cody-meets-xiangqi-foresee-the-unseen\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody meets Xiangqi: foresee the unseen (Part 1)\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\u003eBeing increasingly interested in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Xiangqi\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eXiangqi\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (a.k.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\u003eChinese Chess\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e), Mr. Cody has designed a new Xiangqi match for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Xiang_Yu\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eXiang Yu\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://de.wikipedia.org/wiki/Han_Gaozu\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eLiu Bang\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e by taking into account the likelihood of tie games. The new rule is described as follows:\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\u003eOnce\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   1) Xiang Yu wins Na games consecutively,\\n   2) Liu Bang wins Nb games consecutively, \\n   3) No ties occur consecutively,]]\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\u003ewhichever comes first\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, Mr. Cody announces the outcome accordingly as follows:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   1) Xiang Yu is the final winner,\\n   2) Liu Bang is the final winner, \\n   3) They end up with a final draw.]]\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\u003eAgain, Cody asks us --- active Cody players --- to foresee the outcome of this unseen match using Monte Carlo simulations. Our task is to write the following 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[                         [Pa, Pb, Pc] = Xiangqi2(a, b, Na, Nb, Nc)]]\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\u003ewhere\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: the probability that Xiang Yu wins one individual game\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\u003eb: the probability that Liu Bang wins one individual game\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\u003eNa: # of consecutive wins required for Xiang Yu to become the final winner\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\u003eNb: # of consecutive wins required for Liu Bang to become the final winner\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\u003eNc: # of consecutive ties required to result in a final draw\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\u003ePa: the probability that Xiang Yu wins the match\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\u003ePb: the probability that Liu Bang wins the match\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\u003ePc: the probability of a final draw\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 main focus of this problem is on\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\u003eMonte Carlo simulations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, rather than analytical approaches. Your provided solution Xiangqi2.m will be checked by a P-file EvaluateSolution.p, which mainly does 3 things as follows:\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) Call your function [Pa, Pb, Pc] = Xiangqi2(a, b, Na, Nb, Nc) and then Check if the result P = [Pa, Pb, Pc] is within tolerance of its expected value Q. That is, If norm(P - Q) \u0026lt; tol holds, it means that your solution is accurate enough. If this does not hold, your solution will be rejected.\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) Check if your solution is based on\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\u003epure Monte Carlo simulations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eanalytical approaches\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. If it is based on analytical approaches (i.e., using analytical expressions to directly compute the probabilities), then your solution will be rejected. EvaluateSolution.p accomplishes this goal by exploiting a combination of distinct features possessed by analytical solutions, but are generally not shared by Monte Carlo simulations.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e3) If your solution passes the above two checks, then the score of your solution will be determined based on the speed of your code. The faster your solution is, the smaller score you 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf you have any concerns or suggestions on this problem, please feel free to leave me a comment. Thanks.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":60956,"title":"P(girl likes you | she smiled at you)","description":"Compute the probability\r\n\r\n\r\n\r\nGiven the input probabilities\r\n\r\n\r\n\r\n\r\n\r\n\r\n","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: 401.867px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 408px 200.933px; transform-origin: 408px 200.933px; 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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 80.4833px 8px; transform-origin: 80.4833px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eCompute the probability\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 8px; transform-origin: 0px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 21.7167px; counter-reset: list-item 0; 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: 392px 10.8583px; transform-origin: 392px 10.8583px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"counter-reset: none; 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: 364px 10.8583px; text-align: left; transform-origin: 364px 10.8583px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"vertical-align:-6px\"\u003e\u003cimg src=\"data:image/png;base64,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\" width=\"283.5\" height=\"20\" style=\"width: 283.5px; height: 20px;\"\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 8px; transform-origin: 0px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 94.4667px 8px; transform-origin: 94.4667px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eGiven the input probabilities\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 8px; transform-origin: 0px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 21.7167px; counter-reset: list-item 0; 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: 392px 10.8583px; transform-origin: 392px 10.8583px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"counter-reset: none; 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: 364px 10.8583px; text-align: left; transform-origin: 364px 10.8583px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"vertical-align:-6px\"\u003e\u003cimg src=\"data:image/png;base64,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\" width=\"279\" height=\"20\" style=\"width: 279px; height: 20px;\"\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 8px; transform-origin: 0px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 21.7167px; counter-reset: list-item 0; 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: 392px 10.8583px; transform-origin: 392px 10.8583px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"counter-reset: none; 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: 364px 10.8583px; text-align: left; transform-origin: 364px 10.8583px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"vertical-align:-6px\"\u003e\u003cimg src=\"data:image/png;base64,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\" width=\"142.5\" height=\"20\" style=\"width: 142.5px; height: 20px;\"\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 8px; transform-origin: 0px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 21.7167px; counter-reset: list-item 0; 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: 392px 10.8583px; transform-origin: 392px 10.8583px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"counter-reset: none; 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: 364px 10.8583px; text-align: left; transform-origin: 364px 10.8583px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"vertical-align:-6px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcAAAAAoCAYAAABpRSooAAASbElEQVR4Xu2dW8h26RjHZ87J7mgcIByY7LObiAPZlEjIZob01ciuJE00JH05GLJJmjKI+hJjF9JI2YSIGGQfB+gjcWQX59y/Wv/6d3Xv1rPWep9nve/91N37ft+z1r2u+39d97W/13vtNeMzEBgIDAQGAgOBC4jAtRdwzWPJA4GBwEBgIDAQuGYYwCEEA4GBwEBgIHAhERgG8EKyfSx6IDAQGAgMBIYBPL4MPCGR8OA0Pnt8UgYFA4GBwEBglwg8JFH9+Ll6dBjA4/Ia43d7Gs9J4x/HJWU8fSAwEBgI7BqB9yTqH5jGS3tXMQxgL1LrX4fx+0QaT9nI+N03zYtX9OP1SR8zXhAEnpXWSXbisdN6X3NB1j2WedoIKGv2uETm09K4wchVJq3LCLYMIBvgljT4Wfv8KH355TQ+spEyPwV2sLbnpXFdhZi/pe++l8bH0/h65TqM05/SeFHjujnrxtihoB6dxiMnOuGLC8ec+Y517WvTg9+bxlfT6BLiYxF6Dp6Lx/zmND4XsJYsvcLk/aOTfO1p2T9MxD4pjdel8eE9ET5oLSKAzGL04Cuf36Vxfbgavl/p4XnLAGpelP+rp3/8N/2U4kaR3zptIl37xPTLeY06WO/fDWwUB5uL9CVOwgfTeNj0PQbw2QU2wiAM4BYKXkqNR2NI3lKg4VT/+39G2MvS76M2uh2nHGtkNTptyOdnpsfvjRfsx68ZdL26bju0x8xrIeB6OOeYESF+K43HpPGH2kN7hcKVai6q8O8xkPdca6UnOE9NaSiyu8dE99vSz3eFNWhjPrTFnAPXTgR1x3TvHp0ROVt4dlulhw+E9tzdhnPxkjRKWLvje7903Z7q1OzF76eBQxoj3HPHyAu2oB7HDNmmHljNgPUaQKUSwDkXVZAy+b0xYW/eYq/8uFeJoQfgqBSkVJizFJ5vFf3xTD2fdOwjdqa0evlwlte9NT0sOjFn+fytn4W3XMrY/HYyIDk53pquteavrW+tZ4x5zhaBHsdMuroaBPQawFaqhOX7NbnI52wh2uZprUiYp9aiYTbj3Wls6SD8J81PBDq83uUygPFDlnOOzvLZT3sGTzPtMZV+2ugO6pYgIMes1ePw1/QQejKKpaYeA9gT9UQDuKWCXwLc0ntbkXA0gNFzlueyVTpJBhY6RuF/GbeVSq7Vcpc94bTv9jRTrj542tQP6s4rAnMcM7JhHDErluR6DKCHmyVlEFOge6w9tQQmNsCU1ugp0IgXnguf2LXUenbv90Qst00Xb1Vj7KVl7nXIEOMZaRBxvS+NOc1U8IeDsHx+ksah9Srm+XQa6nw+r9kM1kcbOY0COQ9Z+76U6p/L37O8XrKALPHZWyPYWWK1t2fNccykD4v2qMcAKtwEqJIyiKnB83iw24Ev1ddiE0yMhEkTt8J2F0jmo6HlqWn8e/riz9PPq+lnPJdF1xuKzSNPjMqHTKG3IkOeybzPn55DuzE0vyGNOQZpzsbSAVYaMvRRlCx67pO+oP35AWnclVl7qy4A/96UxsPT+E0a90rju2nclIZSnC7Hkf41U8o8hyM10ABfGb+Y1odzJAUuAwV9XKumIO84xkB5t5tergDfcnIKTuCobuVSA0xvmgmcoOfmCUf4g8eN3OYMTw8fIva9/0bWcQDZLzqu5HxzJ4vjQpIl0QlfdPRjqyYsaOB58EAfePvJNL45/Qedi7nuRd0L7dyjBh91oufkhinVCAL2l6f7kJunp1Hb0726gGwJ50WFKc9EVvkgB+zrKKd8p1ME7AXpN/YkH/iArotNLHMcM2UvizqvZQB7IjtPu/WAOq1v9g9PP86+ebphSYdqLbITPTJA/DsqTOE0p56iNfs9oiPnjKgOq9ZgBPMdaWAwXOmV+K4zeH9J178yDTaHBG6O4T6UP+TsUVwxdRyjslxKTvfm6NRGwCCgHFEuapWmZhqbhdyRWLsTVUaW7MCNaRCpxnSrFJmfwc3xVEeT/DudoZQzkWsT97JGzrD3ppm4jvOaGFvkEVnho6NCkU9z+XCoHLkj48oPA4BTwf+pU5voAHmgY1TOiKL/OXu1h1btL659VRo64uO6he9yPNM+hF9gDc1yUkQnMv3iNDAocnCkJ3gGso8ukNzU9vQcXQBeOKg6MqPjYerCFTYeEMCLj6XhuobrXIfm8J/rmDFfkY8tA+gt9TEVIrA5SMsH5XIpjdoB8B4hKV1zbAMoBQt9DihK4JlpXDahQ4AJvz0Np83fu6ncsXDBkVMSo0tXaigePLI3piFDpk3W6l6Nnq/uOwsDGA24y4I2Ro5+j85z+OYiY+ZmbY9KI6akt2wk0txRySFfMbL1/ec8fW66FgUovFBy/wz81nc5PHzenHfck2aSA4Eh8TncaY4GcC4fDtUXblBypQDpEmQdLL+SBm9lotvX99Ga6W+fN2LuBjvq5NpxDumkyGOfj/WrLKJIUbJRKmkJv7m6QPPynEtpEM19Pg3O5CH3cj4lf8Lfo12nPaYuex0zlxtoKmZvWgbQBQkDF9+CwgJ+mca3p4ccWnc5VNDP6r4YCUcsUMqk1cTwXFphiQGMDMQLkhIUBhIcvajgigkc10jx5lra/V5Pp7Hun6eBktu6sammIKC/FuG5nOaiQ/cqXSGi6F+YhtfAtm4kEh+QofubAOPh/ywNf2OJp3twNHFoxPeIV+m7HB6OV64hS8/tSfVHQ+4Zg1gKmcOHJXu7lEnQnO4ckF7+VxoqJ7hzsGYdXWsvpaUVlUV+yFjjgDqeclJyqUW/Bz1wye51XZZzfg7VBS6PyMSD0lCGw3kpfHN0c52en8PJHbPePpNq2allALVZIaxVO1oisKd+rzeXHFobmGsAXenze6sTz1MD1DYQekXjrtSjwoqCK0UQPU95j1vxKnqt7hX6po1euX9Xim5dqbUiWadji25dNz6tbEDkqTxoeCCZRFHwcX7XlIjLVel8nwxIKUKQgo1KzJVb7jV/c/hwqJy5PPSkfzGAblhkwA/d5yW6ZXRz0Yj4HJW+y6I7oB5910oh8I/XIrrcuBGJBn6JLnCZAwN/pjBxPVSKriVbOZy0d+accT7YADqxLGBNb+hQ4T7WfbXaXi9NhxhAF9ZaN17sUI2K1Q14NKTafK7MVDtkbe9Mw6OS3vXOvc7TUrHu5oozen5uUGrGzZu5aobH6Yip0blryl3vUTXflxwb5ym8IQJ0PrhMRkWvNeQMmO/r1kstckrKZVLPVfMJdUevUeXW38uHQ7GuyTpzysDxey4KkfHPGc9DaeK+Unq/ZLBdThT9Mc+taeCMknGivh9LTs4fro+ZG09vRvleogucryXsJJe1zILqx7mAq+WYRf5oDxV5WYsAY9SzRBkwF7UounrodqNb6GoaNGYsmXeJQM651yPhQ1OBEvSW1x/pcgVf8thd6GOqhPlK9TP3+BBKDo1SE4NPX0oDZXZWae1a3a3k+cXUdK1m415zTjEI91rtbI7M1K51g851uUjTr0HJxXSSp1JjE4/XBqlr+adlIGrOBvN4LR75UIcq6X+aGlqdwr18OBTrWq2YOV1R17IJrYzLXPpEV4xsvC7qZQ2P/tjTNOiQ2aHk9MU02BO5jxv4nANUqhsu0QXRWcu9g7OntnpoFqjEi2bQUTOALuhzlbYTpEW5RddxgTvThbGVv7SYYzXBOOOWnomaewwCLDwVyb9zSt6NZM5AS1nGDRG75f6Y5t+qiammMFp1N23aXC0UxUAXIp9WXSA2dcUDsj3NH3MVX+l651lOUfn3cV01ZeLf5fBoGYhWmknGFaVMBFJq2a/h1OLDEowl67lsgDtMOUfRU7hrv/3HDb86T3FOqP1By8snLLV2TzOTTqbJqeVccK/2Si66rTUoLdEFzs9StOXynMsm+hGyXPq55ZjlZEZ7oRi0lAxgTKkt8YYkkHHRMPhKGr3ptWMZQPeoWvWj1sZlDXhx3vwQ74FpUdhdqeVo8KJ/TB/WjItjukW9q4WHvveoJMpJqWjPhkVJ3TsN8MmlVZg3RkC+5ijX3nSypgJkDfGvVcczo3EvuiKPzSTeqBDp1HelGlbJGRIvammmUo2oxee5fGjNV/q+VWNyJZpzJOUclGqfh9Kl+9T6T/qSD+8EJpr7Rhox0yJHo5T1ydHieyW3Bq8bx6zBEl1Qc9aiXJXk0vVszoi2HLMcHtoLxfJdyQD21p56BMJbY2OHGwRW/1xFzwM2vmbNmoUEsGZspNi9M5Elio64IVzoc5G6nqnolbkwCkTePUKPUuHT430eygpPA9XqfxJkFDF/eoprUSJ0qWrDo+QUySJ7UfhdtqNnGM8YiQeldFPveqH3ShrR8fFN7zLRSheJzpySi00EjkfOQCBv754UcM7Z4H7+IC7y0msAucf3+lw+9OIar3NHStEvGCvL1Ip+5RzIODIfWYc1dJSMb665I7feHgOIfLrxbKW3o4GHn5zfQ76X6IJa1K211dYDNpfSUCZH2ULWA/9wDmIWSC98uKEiLKyXJqBiwFEygK088hwBde/gmFHGHJp1be/rz3rnloLJFXg1B4LI20piek4CGo1cKzUQhZ55PjAJvW+YkvHkjTAxPdO73t7ravU/yaIMP4LPH1+GLjaG/goJmGL4aNohYiLiYu3R05cSj+ls5zX38FaO26e5ltZB5YnGlKT+P0b1vv96I2Jh7Q6n48EaYqTN+dUXpHHjhKXLEs8Fk4iBeJUrByDfn5r4o8hbePfyoVdmctdFR+qOdBEOkt70Uot+Y3dkxGYJXdwbO+pb9XWthXtjpgK+gC/ZD+Re8ql7ctkQl2/u+WkanH1U3fFQXdCKuoWbp2ZdtyFzHOGBltumi/3sInyJjhnY8QKG1tup2AvV8l3OAMbUTK/HUhIQr2EtraEtFcK593tenHvX6ITFAPEpeS45Qychyx0crQm9bzw2xa/S+M60efgux2v+mr0O0VNf29r4tep/7pkiixg3tdjH1DDpZbVflwyd8CopZHAhssJzxMiuEfnmDB3Y/zoNlEE8MhAjUZfbaKQ8OnEsMap8nH8uz2BJw1Op8QJ8UDARA58DmcLhwNDePGGPwfS081w++Frn/u51sx+kmznfJwPRkrMWNnNpidd7IKDvhF+uDOSyzfXwA6PF+015TdhdaWC03DmrOZI+n+T7UrpfNf9DdUGtccUx8OvQY9BPEySvdEMGidL1UhWdLxfvYuaB+8gA1cpn2idVnR0NIETqXXhOPCC938CaKwxeAN6DEQRwNrS/m5I1Qzte5ZKX64qZJcYgxDyD2g4KCiNERIjHwyaI6Zia0EOzlEJps6mFXe9PVDdordNsLv9r18eoJK4PQcaL4wMG/pJsGZHr0v+rKUMbGlmm25iuY71rEAMJnrnNE9vOW97lHAzgAXTwYfOKpyjpuK9qZx65v5Yu9jVg4KK8+Pfg9PogT3xPJzB48v3b08g5ADFlBfZE5bl04Vw+zME1Xqsojn16ZxpuIFqKuoXdErqUskfuSCcjj2CsT6kuxn23pPHkNEjzc12p29aNRCnD5I5V7gjFIbrASzO11wYqar3J1gIeioSh/wtpoM94L6rS8sJIegwMLqfRKktoz1WbLFsH4ZcwPd7rRhAlW2sEWfO5pzgXKS6Ucy1/fYp0b0FTTaFv8bwx50DgLBFgr6P0Y5SPwid6Vt2r1D15lrSel2ep2ajZyLalAcSbiN68eylLOkv3ziilhVth/N7X2UN/bDzouWdcMxDYAwJKw+U6TkW/O4DX72FRJ06jUrnR4ciSvaUBJATN1Y8UMtcaQU4c41XIU/purTrTKkRtPAlrpjlFaUpPWeUOz25Mzph+ILApAkrb1V6eoaBgq6MXmy7wBCcH8ytpdB2v29IA0vUTC+LgJQPYOrR8gtiuThIGoaebafUHH2lC8V6dWWoMWPKihSMtZTx2INBEQPJdiwBVmzz0DVNNIi7QBeDNH2boMn7gsqUBpAU1NrzI21naWXqeeBqjovO0trgWT3dyzODuNJAFb+U+z+sfa7tYCHjfQ67kQ5MOxpH2//jChouF1PLVUnJDl87q2t7KAKp7yd/7yZkVipJ0iw1mL2f4HmdQNxytz7xvlI622O21x3UNmgcCJQRQzHSN0/RGN7feAkMn8NU0et6fOtDdCIGtDOBG5I5pBwIDgYHAQGAgsA4CwwCug+OYZSAwEBgIDAR2hsAwgDtj2CB3IDAQGAgMBNZBYBjAdXAcswwEBgIDgYHAzhAYBnBnDBvkDgQGAgOBgcA6CAwDuA6OY5aBwEBgIDAQ2BkCwwDujGGD3IHAQGAgMBBYB4H/AyQYDIOKAuzsAAAAAElFTkSuQmCC\" width=\"224\" height=\"20\" style=\"width: 224px; height: 20px;\"\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 8px; transform-origin: 0px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function P_LS = verify_bayes_theorem(P_SL, P_L, P_S)\r\n  P_LS = P_SL;\r\nend","test_suite":"%%\r\nP_SL = 0.99;\r\nP_L  = 1/3;\r\nP_S  = 0.5;\r\nP_LS_correct = 0.66;\r\nP_LS = verify_bayes_theorem(P_SL,P_L,P_S);\r\nassert(abs(P_LS_correct-P_LS) \u003c eps)\r\n\r\n%%\r\nP_SL = 0.75;\r\nP_L  = 1/5;\r\nP_S  = 0.25;\r\nP_LS_correct = 0.6;\r\nP_LS = verify_bayes_theorem(P_SL,P_L,P_S);\r\nassert(abs(P_LS_correct-P_LS) \u003c eps)\r\n\r\n%% Test forbidden functions\r\nfiletext = fileread('verify_bayes_theorem.m');\r\nillegal = contains(filetext, 'regexp') || contains(filetext, 'str2num') || contains(filetext, 'assignin') || contains(filetext, 'echo')\r\nassert(~illegal);","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":149128,"edited_by":149128,"edited_at":"2025-07-10T07:02:07.000Z","deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":"2025-07-10T07:02:07.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2025-07-08T12:54:24.000Z","updated_at":"2026-03-27T11:28:52.000Z","published_at":"2025-07-08T13:17:57.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eCompute the probability\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=\\\"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:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"true\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eP_{LS} = P(girl ~likes ~ you ~ | ~ she ~ smiled ~ at ~ you) \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\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\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\u003eGiven the input probabilities\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=\\\"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:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"true\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eP_{SL} = P(she ~ smiles ~ at ~ you ~ | ~ she ~ likes ~ you)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\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=\\\"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:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"true\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eP_L = P(she ~likes ~ you) \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\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=\\\"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:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"true\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eP_S = P(she ~ just ~ smiles ~ in ~ general) \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\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\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":58688,"title":"Bag of apples","description":"find probabilty of getting red apples from a bag of 'r' red and 'g' green apples.","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: 21px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 10.5px; transform-origin: 407px 10.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003efind probabilty of getting red apples from a bag of 'r' red and 'g' green apples.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(r,g)\r\n  y = x;\r\nend","test_suite":"%%\r\nr = 5;\r\ng = 5\r\ny_correct = 0.5;\r\nassert(isequal(your_fcn_name(r,g),y_correct))\r\n\r\n%%\r\nr = 0;\r\ng = 5\r\ny_correct = 0;\r\nassert(isequal(your_fcn_name(r,g),y_correct))\r\n\r\n%%\r\nr = 5;\r\ng = 0;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(r,g),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":3495088,"edited_by":3495088,"edited_at":"2023-07-18T16:03:10.000Z","deleted_by":null,"deleted_at":null,"solvers_count":54,"test_suite_updated_at":"2023-07-18T16:03:10.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2023-07-18T15:56:56.000Z","updated_at":"2026-04-08T13:01:47.000Z","published_at":"2023-07-18T16:02:08.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003efind probabilty of getting red apples from a bag of 'r' red and 'g' green apples.\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":44005,"title":"Probability of red tulips","description":"I hope to give you bulbs of tulip. But I do not know the color of those petals. I just know that the color is red, white or yellow.\r\n\r\nInput (x): Number of bulbs\r\n\r\nOutput (y): Probability that ALL are RED tulips\r\n","description_html":"\u003cp\u003eI hope to give you bulbs of tulip. But I do not know the color of those petals. I just know that the color is red, white or yellow.\u003c/p\u003e\u003cp\u003eInput (x): Number of bulbs\u003c/p\u003e\u003cp\u003eOutput (y): Probability that ALL are RED tulips\u003c/p\u003e","function_template":"function y = red_tulip(x)\r\n  y = 1/3;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 1/3;\r\nassert(isequal(red_tulip(x),y_correct))\r\n\r\n%%\r\nx = 3;\r\ny_correct = (1/3)^3;\r\nassert(isequal(red_tulip(x),y_correct))\r\n\r\n%%\r\nx = 10;\r\ny_correct = (1/3)^10;\r\nassert(isequal(red_tulip(x),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":102298,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":80,"test_suite_updated_at":"2017-07-07T16:39:42.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-01-16T07:35:21.000Z","updated_at":"2025-12-16T06:35:21.000Z","published_at":"2017-07-07T16:39: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\",\"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 hope to give you bulbs of tulip. But I do not know the color of those petals. I just know that the color is red, white or yellow.\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 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): Probability that ALL are RED tulips\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":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":48945,"title":"Would you win a raffle?","description":null,"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: 42px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 343px 21px; transform-origin: 343px 21px; vertical-align: baseline; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 320px 21px; text-align: left; transform-origin: 320px 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=\"\"\u003eWhat is the probability of win a raffle? You're given your entries and total entries. Round the solution to 4 decimals.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = raffle(e,et)\r\n    y = x;\r\nend","test_suite":"%%\r\ne=5;\r\nte=243;\r\nassert(isequal(raffle(e,te),2.0576))\r\n%%\r\ne=5;\r\nte=20561;\r\nassert(isequal(raffle(e,te),0.0243))\r\n%%\r\ne=1;\r\nte=1005;\r\nassert(isequal(raffle(e,te),0.0995))\r\n%%\r\ne=1;\r\nte=321;\r\nassert(isequal(raffle(e,te),0.3115))","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":698530,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":23,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-12-22T13:59:36.000Z","updated_at":"2026-02-18T10:10:20.000Z","published_at":"2020-12-31T01:15:19.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\u003eWhat is the probability of win a raffle? You're given your entries and total entries. Round the solution to 4 decimals.\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":44272,"title":"Generate one sample of uniform random numbers between -pi and +pi","description":"Generate one sample of uniform random numbers between -pi and +pi.","description_html":"\u003cp\u003eGenerate one sample of uniform random numbers between -pi and +pi.\u003c/p\u003e","function_template":"function y = rndpi(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nw=0;\r\nfor k=1:10^3\r\n    w=w+rndpi(1);\r\nend\r\n    \r\nassert(w\u003c1000)\r\n\r\n%%\r\nw=0;\r\nfor k=1:10^3\r\n    w=w+rndpi(1)^2;\r\nend\r\n    \r\nassert(w\u003e10^3)\r\n\r\n%% \r\nw=0;\r\nfor k=1:10^3\r\n    w=min(w,rndpi(1));\r\nend\r\n\r\nassert(w\u003c-pi*0.9)\r\nassert(w\u003e-pi*1.1)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":"2017-08-02T00:03:53.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-08-01T23:59:01.000Z","updated_at":"2026-04-03T06:50:32.000Z","published_at":"2017-08-01T23:59:07.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\u003eGenerate one sample of uniform random numbers between -pi and +pi.\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":700,"title":"Monty Hall","description":"The classic Monty Hall \"Let's Make a Deal\" final showcase puzzle pits the contestant against three Doors. Behind one Door are dream prizes and behind the other two are Donkeys and Chickens. \r\n\r\nThe contestant picks a Door: 1 2 or 3.\r\n\r\nMonty then reveals a Door that is Not the winner.\r\n\r\nAs the contestant do you stay with your original Door or swap to the other Door?\r\n\r\nYour routine will be called twice. \r\n\r\nThe first time it will see [0 0 0]. You are to select a Door: return an Integer 1,2 or 3.\r\n\r\nThe second time your function will see [1 2 0] or [1 0 2],if you had selected door number 1. The 2 denotes a revealed Losing Door.\r\n\r\nYou may now choose Door 1 (no change) or switch to the available door denoted by the zero. \r\n\r\nReturn an Integer 1, 2, or 3\r\n\r\nExample:\r\n\r\nInput [0 0 0]\r\n\r\nOutput 2\r\n\r\nInput [0 1 2] % Your first selection is denoted by 1. 2 is a losing Door\r\n\r\nOutput 1  % This selects Door 1, swapping from Door 2\r\n\r\nThe Test engine will determine if your final selection is a Winner\r\n\r\nThe routine will run the game 100 times calling your function twice for every game.\r\n\r\nYour Strategy \"Passes\" if it wins \u003e 50% of the time.\r\n\r\nThis is the first in a series of planned interactive Games.\r\n\r\nThis example is also to demonstrate Cody multi-call interactivity capability.\r\n\r\n\r\nLet's Make a Deal","description_html":"\u003cp\u003eThe classic Monty Hall \"Let's Make a Deal\" final showcase puzzle pits the contestant against three Doors. Behind one Door are dream prizes and behind the other two are Donkeys and Chickens.\u003c/p\u003e\u003cp\u003eThe contestant picks a Door: 1 2 or 3.\u003c/p\u003e\u003cp\u003eMonty then reveals a Door that is Not the winner.\u003c/p\u003e\u003cp\u003eAs the contestant do you stay with your original Door or swap to the other Door?\u003c/p\u003e\u003cp\u003eYour routine will be called twice.\u003c/p\u003e\u003cp\u003eThe first time it will see [0 0 0]. You are to select a Door: return an Integer 1,2 or 3.\u003c/p\u003e\u003cp\u003eThe second time your function will see [1 2 0] or [1 0 2],if you had selected door number 1. The 2 denotes a revealed Losing Door.\u003c/p\u003e\u003cp\u003eYou may now choose Door 1 (no change) or switch to the available door denoted by the zero.\u003c/p\u003e\u003cp\u003eReturn an Integer 1, 2, or 3\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003eInput [0 0 0]\u003c/p\u003e\u003cp\u003eOutput 2\u003c/p\u003e\u003cp\u003eInput [0 1 2] % Your first selection is denoted by 1. 2 is a losing Door\u003c/p\u003e\u003cp\u003eOutput 1  % This selects Door 1, swapping from Door 2\u003c/p\u003e\u003cp\u003eThe Test engine will determine if your final selection is a Winner\u003c/p\u003e\u003cp\u003eThe routine will run the game 100 times calling your function twice for every game.\u003c/p\u003e\u003cp\u003eYour Strategy \"Passes\" if it wins \u003e 50% of the time.\u003c/p\u003e\u003cp\u003eThis is the first in a series of planned interactive Games.\u003c/p\u003e\u003cp\u003eThis example is also to demonstrate Cody multi-call interactivity capability.\u003c/p\u003e\u003cp\u003eLet's Make a Deal\u003c/p\u003e","function_template":"function y = Monty(doors)\r\n% First call will see doors=[0 0 0]\r\n% Second call will see a permutation of [0 1 2], depending on first response\r\n% In the second call the \"2\" denotes a revealed Losing door\r\n  y = 1;\r\nend","test_suite":"%%\r\nwin=0;\r\nPass=0;\r\nfor i=1:100\r\n    \r\n prize=randi(3);\r\n doors=[0 0 0];\r\n \r\n pick=Monty(doors);\r\n \r\n pick=floor(pick);\r\n if pick\u003c1 || pick\u003e3\r\n  win=0;\r\n  break;\r\n else\r\n  doors(pick)=1;\r\n end\r\n \r\n if pick==prize\r\n % Random select from other doors\r\n  if rand\u003e0.5\r\n   doors(find(doors==0,1))=2;\r\n  else\r\n   doors(find(doors==0,1,'last'))=2;\r\n  end\r\n else % \r\n % Pick other and not prize door\r\n  reveal=setxor(prize,setxor(pick,[1 2 3]));\r\n  doors(reveal)=2;\r\n end\r\n \r\n pick=Monty(doors);\r\n\r\n pick=floor(pick);\r\n if pick==prize\r\n  win=win+1;\r\n end\r\n \r\n \r\nend % Monty Loops\r\nwin % Display number of wins\r\nif win\u003e50,Pass=1;end\r\nassert(isequal(Pass,1))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-19T08:52:15.000Z","updated_at":"2026-03-24T13:29:28.000Z","published_at":"2012-05-19T08:52:15.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\u003eThe classic Monty Hall \\\"Let's Make a Deal\\\" final showcase puzzle pits the contestant against three Doors. Behind one Door are dream prizes and behind the other two are Donkeys and Chickens.\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 contestant picks a Door: 1 2 or 3.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMonty then reveals a Door that is Not the winner.\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\u003eAs the contestant do you stay with your original Door or swap to the other Door?\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 routine will be called twice.\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 first time it will see [0 0 0]. You are to select a Door: return an Integer 1,2 or 3.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe second time your function will see [1 2 0] or [1 0 2],if you had selected door number 1. The 2 denotes a revealed Losing Door.\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 may now choose Door 1 (no change) or switch to the available door denoted by the zero.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn an Integer 1, 2, or 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput [0 0 0]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput [0 1 2] % Your first selection is denoted by 1. 2 is a losing Door\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 1 % This selects Door 1, swapping from Door 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe Test engine will determine if your final selection is a Winner\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 routine will run the game 100 times calling your function twice for every 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour Strategy \\\"Passes\\\" if it wins \u003e 50% 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is the first in a series of planned interactive 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\u003eThis example is also to demonstrate Cody multi-call interactivity capability.\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\u003eLet's Make a Deal\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":510,"title":"Selecting books on MATLAB for experts and beginners (blindfolded)","description":"* Imagine you have been blindfolded and asked to pick up any two books randomly from the table. \r\n* There are n books suitable for \u003chttp://www.mathworks.com MATLAB\u003e experts and n books suitable for beginners, \r\n* Total 2*n books on the table. \r\n* What is the probability that you will pick up exactly one for experts and one beginners?    ","description_html":"\u003cul\u003e\u003cli\u003eImagine you have been blindfolded and asked to pick up any two books randomly from the table.\u003c/li\u003e\u003cli\u003eThere are n books suitable for \u003ca href=\"http://www.mathworks.com\"\u003eMATLAB\u003c/a\u003e experts and n books suitable for beginners,\u003c/li\u003e\u003cli\u003eTotal 2*n books on the table.\u003c/li\u003e\u003cli\u003eWhat is the probability that you will pick up exactly one for experts and one beginners?\u003c/li\u003e\u003c/ul\u003e","function_template":"function mychance = need2(n)\r\n   mychance=50/50;\r\nend","test_suite":"%%\r\nassert(abs(need2(1)-1)\u003c0.001)\r\n%%\r\nassert(abs(need2(2)-0.6667)\u003c0.001)\r\n%%\r\nassert(abs(need2(10)-0.5263)\u003c0.001)\r\n%%\r\nassert(abs(need2(100)-0.5025)\u003c0.001)\r\n%%\r\nassert(abs(need2(1000)-0.5003)\u003c0.001)\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":82,"test_suite_updated_at":"2012-03-20T07:21:43.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-03-20T07:21:43.000Z","updated_at":"2026-03-19T06:46:04.000Z","published_at":"2012-03-20T07:21: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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eImagine you have been blindfolded and asked to pick up any two books randomly from the table.\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\u003eThere are n books suitable for\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\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eMATLAB\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e experts and n books suitable for beginners,\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\u003eTotal 2*n books on the table.\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\u003eWhat is the probability that you will pick up exactly one for experts and one beginners?\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":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":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":2030,"title":"A Poker Hand","description":"Texas Hold ‘Em is a classical card game. In this problem, we are concerned with determining the probability of attaining a certain type of hand.\r\n\r\nA “Full House” is a five card hand comprised composed of two sets: a set of three of a kind, and a set of two of a kind. Examples include: K-K-K-Q-Q, 10-10-10-5-5, and A-A-A-4-4.\r\n\r\nAssuming that there are 52 cards in a unique, distinguishable deck, find the probability of attaining a “Full House” in any given hand. You may assume that there are 9 players playing on a full table.\r\n","description_html":"\u003cp\u003eTexas Hold ‘Em is a classical card game. In this problem, we are concerned with determining the probability of attaining a certain type of hand.\u003c/p\u003e\u003cp\u003eA “Full House” is a five card hand comprised composed of two sets: a set of three of a kind, and a set of two of a kind. Examples include: K-K-K-Q-Q, 10-10-10-5-5, and A-A-A-4-4.\u003c/p\u003e\u003cp\u003eAssuming that there are 52 cards in a unique, distinguishable deck, find the probability of attaining a “Full House” in any given hand. You may assume that there are 9 players playing on a full table.\u003c/p\u003e","function_template":"function y = fullHouse(x)\r\nx=52; %number of cards in a deck\r\n%siginificant to 7 digits (for luck)\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 0.0144058;\r\nassert(isequal(fullHouse(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":16441,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":30,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-12-02T07:52:42.000Z","updated_at":"2025-06-08T09:16:04.000Z","published_at":"2013-12-02T08:00:04.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\u003eTexas Hold ‘Em is a classical card game. In this problem, we are concerned with determining the probability of attaining a certain type of 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA “Full House” is a five card hand comprised composed of two sets: a set of three of a kind, and a set of two of a kind. Examples include: K-K-K-Q-Q, 10-10-10-5-5, and A-A-A-4-4.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssuming that there are 52 cards in a unique, distinguishable deck, find the probability of attaining a “Full House” in any given hand. You may assume that there are 9 players playing on a full table.\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":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":43126,"title":"Probabilities - Balls and urns - 01","description":"The urn contains B blue balls and R red balls. Each trial consists of drawing one random ball from the urn and observing its color. Then the ball is placed back in the urn.\r\nWhat is the probability that, after N trials, the number of times a red ball is observed is K?","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: 72px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 36px; transform-origin: 407px 36px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 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: 380px 8px; transform-origin: 380px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe urn contains B blue balls and R red balls. Each trial consists of drawing one random ball from the urn and observing its color. Then the ball 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: 42px 8px; transform-origin: 42px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eplaced back\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: 34px 8px; transform-origin: 34px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e in the urn.\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: 280px 8px; transform-origin: 280px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWhat is the probability that, after N trials, the number of times a red ball is observed is K?\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function p = probability(R,B,N,K)\r\n    p = 1;\r\nend","test_suite":"%%\r\nR=4; B=8;\r\nN=50; K=25;\r\np = 0.0059;\r\nassert( abs(probability(R,B,N,K)-p)\u003c1e-04 );\r\n%%\r\nR=22; B=6;\r\nN=32; K=23;\r\np = 0.1042;\r\nassert( abs(probability(R,B,N,K)-p)\u003c1e-04 );\r\n%%\r\nR=2; B=4;\r\nN=25; K=2;\r\np = 0.0030;\r\nassert( abs(probability(R,B,N,K)-p)\u003c1e-04 );\r\n%%\r\nR=0; B=4;\r\nN=25; K=2;\r\nassert( isequal(probability(R,B,N,K),0) );\r\n%%\r\nR=9; B=0;\r\nN=25; K=2;\r\nassert( isequal(probability(R,B,N,K),0) );\r\n%%\r\nR=9; B=0;\r\nN=25; K=25;\r\nassert( isequal(probability(R,B,N,K),1) );","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":85738,"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":"2016-10-06T13:54:47.000Z","updated_at":"2026-01-02T17:59:44.000Z","published_at":"2016-10-06T13:54:47.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 urn contains B blue balls and R red balls. Each trial consists of drawing one random ball from the urn and observing its color. Then the ball 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\u003eplaced back\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in the urn.\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, after N trials, the number of times a red ball is observed is K?\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":52110,"title":"Pick the die most likely to win","description":"After discussing Rock, Paper, Scissors, Lizard, Spock in The Simpsons and their Mathematical Secrets, Simon Singh writes that investor Warren Buffett will challenge people to beat him in a game of dice. He presents three dice and asks the other person to choose one. Then he chooses one, and they roll together. The person with the highest roll wins. \r\nWith standard dice that have one to six pips on their sides, no one has an advantage. However, Mr. Buffett’s dice are different: Although the sum of the numbers on the faces of one die equals the sums for the other dice, the numbers on one die differ from the numbers on the other dice.\r\nFor example, suppose die A has 1, 1, 6, 6, 8, and 8; die B has 3, 3, 5, 5, 7, and 7; and die C has 2, 2, 4, 4, 9, and 9. If the first person chooses die A, then Warren Buffett will choose die C to increase his chances of winning. Write a function that choose the die most likely to win, given the other person’s choice. The input is a matrix with the numbers on the faces of each die in the rows and an index of the die (i.e., row) that the other person chose.","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: 228px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 114px; transform-origin: 407px 114px; vertical-align: baseline; \"\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: 51.3417px 7.79167px; transform-origin: 51.3417px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAfter discussing \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/46072-rock-paper-scissors-lizard-spock\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eRock, Paper, Scissors, Lizard, Spock\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: 9.33333px 7.79167px; transform-origin: 9.33333px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e in \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 143.142px 7.79167px; transform-origin: 143.142px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eThe Simpsons and their Mathematical Secrets\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: 65.45px 7.79167px; transform-origin: 65.45px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, Simon Singh writes that investor Warren Buffett will challenge people to beat him in a game of dice. He presents three dice and asks the other person to choose one. Then he chooses one, and they roll together. The person with the highest roll wins. \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: 362.242px 7.79167px; transform-origin: 362.242px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWith standard dice that have one to six pips on their sides, no one has an advantage. However, Mr. Buffett’s dice are different: Although the sum of the numbers on the faces of one die equals the sums for the other dice, the numbers on one die differ from the numbers on the other dice.\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: 376.833px 7.79167px; transform-origin: 376.833px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, suppose die A has 1, 1, 6, 6, 8, and 8; die B has 3, 3, 5, 5, 7, and 7; and die C has 2, 2, 4, 4, 9, and 9. If the first person chooses die A, then Warren Buffett will choose die C to increase his chances of winning. \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: 64.0417px 7.79167px; transform-origin: 64.0417px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that choose the die most likely to win, given the other person’s choice. The input is a matrix with the numbers on the faces of each die in the rows and an index of the die (i.e., row) that the other person chose.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function d = chooseDie(D,k)\r\n  d = f(D,k);\r\nend","test_suite":"%%\r\nD = [1 1 6 6 8 8; 3 3 5 5 7 7; 2 2 4 4 9 9];\r\nk = 1;\r\nd_correct = 3;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [1 1 6 6 8 8; 3 3 5 5 7 7; 2 2 4 4 9 9];\r\nk = 2;\r\nd_correct = 1;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [1 1 6 6 8 8; 3 3 5 5 7 7; 2 2 4 4 9 9];\r\nk = 3;\r\nd_correct = 2;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 3 4 4 8 8; 1 1 5 5 9 9; 2 2 6 6 7 7];\r\nk = 1;\r\nd_correct = 2;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 3 4 4 8 8; 1 1 5 5 9 9; 2 2 6 6 7 7];\r\nk = 2;\r\nd_correct = 3;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 3 4 4 8 8; 1 1 5 5 9 9; 2 2 6 6 7 7];\r\nk = 3;\r\nd_correct = 1;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [1 6 19 24 26 35; 3 7 21 23 25 32; 2 9 20 22 27 31; 8 10 15 17 28 33; 5 12 14 16 30 34; 4 11 13 18 29 36];\r\nk = 1;\r\nd_correct = 3;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [1 6 19 24 26 35; 3 7 21 23 25 32; 2 9 20 22 27 31; 8 10 15 17 28 33; 5 12 14 16 30 34; 4 11 13 18 29 36];\r\nk = 2;\r\nd_correct = 4;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [1 6 19 24 26 35; 3 7 21 23 25 32; 2 9 20 22 27 31; 8 10 15 17 28 33; 5 12 14 16 30 34; 4 11 13 18 29 36];\r\nk = 3;\r\nd_correct = 2;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [1 6 19 24 26 35; 3 7 21 23 25 32; 2 9 20 22 27 31; 8 10 15 17 28 33; 5 12 14 16 30 34; 4 11 13 18 29 36];\r\nk = 4;\r\nd_correct = 6;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [1 6 19 24 26 35; 3 7 21 23 25 32; 2 9 20 22 27 31; 8 10 15 17 28 33; 5 12 14 16 30 34; 4 11 13 18 29 36];\r\nk = 5;\r\nd_correct = 1;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [1 6 19 24 26 35; 3 7 21 23 25 32; 2 9 20 22 27 31; 8 10 15 17 28 33; 5 12 14 16 30 34; 4 11 13 18 29 36];\r\nk = 6;\r\nd_correct = 5;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 4 8 30 31 35; 1 5 9 28 32 36; 2 6 7 29 33 34; 12 13 17 21 22 26; 10 14 18 19 23 27; 11 15 16 20 24 25];\r\nk = 1;\r\nd_correct = 2;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 4 8 30 31 35; 1 5 9 28 32 36; 2 6 7 29 33 34; 12 13 17 21 22 26; 10 14 18 19 23 27; 11 15 16 20 24 25];\r\nk = 2;\r\nd_correct = 3;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 4 8 30 31 35; 1 5 9 28 32 36; 2 6 7 29 33 34; 12 13 17 21 22 26; 10 14 18 19 23 27; 11 15 16 20 24 25];\r\nk = 3;\r\nd_correct = 1;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 4 8 30 31 35; 1 5 9 28 32 36; 2 6 7 29 33 34; 12 13 17 21 22 26; 10 14 18 19 23 27; 11 15 16 20 24 25];\r\nk = 4;\r\nd_correct = 5;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 4 8 30 31 35; 1 5 9 28 32 36; 2 6 7 29 33 34; 12 13 17 21 22 26; 10 14 18 19 23 27; 11 15 16 20 24 25];\r\nk = 5;\r\nd_correct = 6;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n\r\n%%\r\nD = [3 4 8 30 31 35; 1 5 9 28 32 36; 2 6 7 29 33 34; 12 13 17 21 22 26; 10 14 18 19 23 27; 11 15 16 20 24 25];\r\nk = 6;\r\nd_correct = 4;\r\nassert(isequal(chooseDie(D,k),d_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":46909,"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":"2021-06-26T14:03:03.000Z","updated_at":"2025-08-26T11:48:35.000Z","published_at":"2021-06-26T14:09:39.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\u003eAfter discussing \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/46072-rock-paper-scissors-lizard-spock\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRock, Paper, Scissors, Lizard, Spock\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e in \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eThe Simpsons and their Mathematical Secrets\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, Simon Singh writes that investor Warren Buffett will challenge people to beat him in a game of dice. He presents three dice and asks the other person to choose one. Then he chooses one, and they roll together. The person with the highest roll wins. \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\u003eWith standard dice that have one to six pips on their sides, no one has an advantage. However, Mr. Buffett’s dice are different: Although the sum of the numbers on the faces of one die equals the sums for the other dice, the numbers on one die differ from the numbers on the other dice.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, suppose die A has 1, 1, 6, 6, 8, and 8; die B has 3, 3, 5, 5, 7, and 7; and die C has 2, 2, 4, 4, 9, and 9. If the first person chooses die A, then Warren Buffett will choose die C to increase his chances of winning. \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that choose the die most likely to win, given the other person’s choice. The input is a matrix with the numbers on the faces of each die in the rows and an index of the die (i.e., row) that the other person chose.\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":2267,"title":"Sales Prediction","description":"Miss X is a shopaholic person and every weekend she goes to a mall. There are total of 10 shops. Miss X starts from shop #1 and goes till last shop. Looking at her pattern of shopping from previous week, a shopkeeper wants to predict the probability of her shopping from his shop this weekend.  Can you help the shopkeeper?\r\n\r\nAlso, find the average amount that she spent in last week. \r\n\r\nExample\r\n\r\n item_price = [10 35 2 100 99 87 1 0.5 9 30] \r\n total_items_shopped = [ 2 0 5 10 8 9 1 0 0 1]\r\n\r\n Average spending = $73.22\r\n Probability of shopping from shop# 5 is:0.22\r\n","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: 233px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 116.5px; transform-origin: 407px 116.5px; vertical-align: baseline; \"\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eMiss X is a shopaholic person and every weekend she goes to a mall. There are total of 10 shops. Miss X starts from shop #1 and goes till last shop. Looking at her pattern of shopping from previous week, a shopkeeper wants to predict the probability of her shopping from his shop this weekend. Can you help the shopkeeper?\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=\"\"\u003eAlso, find the average amount that she spent in last week. Round the answer to 2 digits after decimal.\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=\"\"\u003eExample\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 100px; border-bottom-left-radius: 4px; border-bottom-right-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 50px; transform-origin: 404px 50px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20px; border-bottom-left-radius: 0px; border-bottom-right-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-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 10px; transform-origin: 404px 10px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e item_price = [10 35 2 100 99 87 1 0.5 9 30] \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20px; border-bottom-left-radius: 0px; border-bottom-right-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-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 10px; transform-origin: 404px 10px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e total_items_shopped = [ 2 0 5 10 8 9 1 0 0 1]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20px; border-bottom-left-radius: 0px; border-bottom-right-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-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 10px; transform-origin: 404px 10px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20px; border-bottom-left-radius: 0px; border-bottom-right-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-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 10px; transform-origin: 404px 10px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e Average \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); text-decoration: none; text-decoration-color: rgb(170, 4, 249); \"\u003espending = $73.22\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20px; border-bottom-left-radius: 0px; border-bottom-right-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-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 10px; transform-origin: 404px 10px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e Probability \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); text-decoration: none; text-decoration-color: rgb(170, 4, 249); \"\u003eof shopping from shop# 5 is:0.22\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [avg_spending, shop_prob] = Shopping(price, items, shop_no)\r\n  y = x;\r\nend","test_suite":"%%\r\nitem_price = [10 35 2 100 99 87 1 0.5 9 30] ;\r\ntotal_items_shopped = [ 2 0 5 10 8 9 1 0 0 1];\r\nshop_no = 5;\r\n\r\navg_spending =73.22;\r\nshop_prob = 0.22\r\n\r\n[x,y] = Shopping(item_price ,total_items_shopped, shop_no );\r\nassert(isequal([x,y],[avg_spending, shop_prob]))\r\n\r\n\r\n%%\r\n\r\nitem_price = [10 4 22 10 5 7 2 10 95 56] ;\r\ntotal_items_shopped = [ 23 0 0 11 38 0 1 0 0 0];\r\nshop_no = 7;\r\n\r\navg_spending =7.29;\r\n\r\nshop_prob = 0.01\r\n\r\n[x,y] = Shopping(item_price ,total_items_shopped, shop_no );\r\nassert(isequal([x,y],[avg_spending, shop_prob]))\r\n\r\n%%\r\nitem_price = ones(1, 10) ; %dollar shoppie \r\ntotal_items_shopped = [ 1 0 3 4 8 9 0 5 0 10];\r\nshop_no = 10;\r\n\r\navg_spending = 1;\r\n\r\nshop_prob = 0.25;\r\n\r\n[x,y] = Shopping(item_price ,total_items_shopped, shop_no );\r\nassert(isequal([x,y],[avg_spending, shop_prob]))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":26,"test_suite_updated_at":"2014-04-01T22:38:37.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-04-01T21:48:22.000Z","updated_at":"2021-02-21T10:06:23.000Z","published_at":"2014-04-01T22:38:37.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\u003eMiss X is a shopaholic person and every weekend she goes to a mall. There are total of 10 shops. Miss X starts from shop #1 and goes till last shop. Looking at her pattern of shopping from previous week, a shopkeeper wants to predict the probability of her shopping from his shop this weekend. Can you help the shopkeeper?\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\u003eAlso, find the average amount that she spent in last week. Round the answer to 2 digits after decimal.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ item_price = [10 35 2 100 99 87 1 0.5 9 30] \\n total_items_shopped = [ 2 0 5 10 8 9 1 0 0 1]\\n\\n Average spending = $73.22\\n Probability of shopping from shop# 5 is:0.22]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":43166,"title":"Probabilities - Balls and urns - 02","description":"The urn contains B blue balls and R red balls. Each trial consists of drawing one random ball from the urn and observing its color. Then the ball is *discarded*.\r\n\r\nWhat is the probability that, after N trials, the number of red balls is K?","description_html":"\u003cp\u003eThe urn contains B blue balls and R red balls. Each trial consists of drawing one random ball from the urn and observing its color. Then the ball is \u003cb\u003ediscarded\u003c/b\u003e.\u003c/p\u003e\u003cp\u003eWhat is the probability that, after N trials, the number of red balls is K?\u003c/p\u003e","function_template":"function p = probability(R,B,N,K)\r\n    p = 1;\r\nend","test_suite":"%%\r\nR=4; B=8;\r\nN=6; K=2;\r\np = 0.4545;\r\nassert( abs(probability(R,B,N,K)-p)\u003c1e-04 );\r\n%%\r\nR=22; B=6;\r\nN=14; K=12;\r\np = 0.2418;\r\nassert( abs(probability(R,B,N,K)-p)\u003c1e-04 );\r\n%%\r\nR=22; B=60;\r\nN=5; K=0;\r\np = 0.2002;\r\nassert( abs(probability(R,B,N,K)-p)\u003c1e-04 );\r\n%%\r\nR=9; B=0;\r\nN=4; K=4;\r\nassert( isequal(probability(R,B,N,K),1) );\r\n%%\r\nR=1; B=78;\r\nN=78; K=1;\r\np = 0.9873;\r\nassert( abs(probability(R,B,N,K)-p)\u003c1e-04 );","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":85738,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":21,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-07T15:42:59.000Z","updated_at":"2026-01-21T12:49:51.000Z","published_at":"2016-10-07T15:42:59.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe urn contains B blue balls and R red balls. Each trial consists of drawing one random ball from the urn and observing its color. Then the ball 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\u003ediscarded\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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhat is the probability that, after N trials, the number of red balls is K?\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":44315,"title":"Predicting life and death of a memory-less light bulb","description":"*\u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161* \r\n\r\nYou have a light bulb that can fail any moment according to the exponential probability distribution. \r\n\r\nAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant. \r\n\r\nNotice that this probability is very small if N is very large. \r\n\r\nNow suppose, the bulb has already survived N hours. \r\n\r\nPlease calculate the probability of its surviving M more hours.\r\n","description_html":"\u003cp\u003e\u003cb\u003e\u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161 \u0026#128161\u003c/b\u003e\u003c/p\u003e\u003cp\u003eYou have a light bulb that can fail any moment according to the exponential probability distribution.\u003c/p\u003e\u003cp\u003eAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant.\u003c/p\u003e\u003cp\u003eNotice that this probability is very small if N is very large.\u003c/p\u003e\u003cp\u003eNow suppose, the bulb has already survived N hours.\u003c/p\u003e\u003cp\u003ePlease calculate the probability of its surviving M more hours.\u003c/p\u003e","function_template":"function hope = fate(N,P,M)\r\n  hope=exp(-(N+M)*P);\r\nend","test_suite":"%%\r\nN = 1;\r\nP=1;\r\nM=0;\r\nhope_correct = 1;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN = 1;\r\nP=0;\r\nM=1;\r\nhope_correct = 1;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=1;\r\nP=1;\r\nM=1;\r\nhope_correct = 0.3679;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=2;\r\nP=1;\r\nM=1;\r\nhope_correct = 0.3679;\r\nassert(fate(N,P,M)\u003ehope_correct*0.999)\r\n%%\r\nN=2;\r\nP=1;\r\nM=2;\r\nhope_correct = 0.1353;\r\nassert(fate(N,P,M)\u003chope_correct*1.1)\r\n%%\r\nN=2;\r\nP=2;\r\nM=2;\r\nhope_correct = 0.0183;\r\nassert(fate(N,P,M)\u003chope_correct*1.1)\r\n%%","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":336,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":34,"created_at":"2017-09-12T02:53:45.000Z","updated_at":"2026-03-25T02:55:11.000Z","published_at":"2017-10-16T01:45:07.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\u003e\u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161 \u0026amp;#128161\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 have a light bulb that can fail any moment according to the exponential probability distribution.\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\u003eAt any moment, the probability that it will survive just N hours = exp(-N*P), where P is a constant.\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\u003eNotice that this probability is very small if N is very large.\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\u003eNow suppose, the bulb has already survived N hours.\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\u003ePlease calculate the probability of its surviving M more hours.\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":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":53004,"title":"Collect a set of candy wrappers","description":"This past Halloween, the siblings Matilda and Labrun amused (and sometimes confused) their many neighbors with their costumes inspired by “mundane Halloween”, a Japanese tradition started in 2014. As they sifted through and sampled the candy they collected, they noticed something odd as they opened one type of candy, an Oh Leonhard! bar:\r\n“This wrapper has a proof of the infinitude of primes!”, said Matilda.\r\n“I got that one too,” said Labrun. “And here’s one with the Twin Prime Conjecture!”\r\n“Here’s the Pythagorean Theorem. And this one has the Riemann hypothesis.”\r\nThe precocious pair determined that these wrappers were part of the Oh Leonhard! “Great Theorems and Unsolved Problems” promotion. In this promotion, wrappers with one of forty theorems, conjectures, or other famous math problems were distributed evenly among all of the Oh Leonhard! Bars produces. Anyone who collected all wrappers in the set would get a copy of the Handbook of Mathematical Functions by Abramowitz and Stegun. \r\nMatilda and Labrun computed that, on average, they would have to open 172 wrappers to complete a set and win the prize. Their calculation accounted for the contest’s rule that all pieces of the wrapper had to be submitted—that is, no fractional wrappers were allowed.\r\nWrite a function that takes the number of wrappers in a set and compute the expected number of wrappers that would need to be opened to collect the set.","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: 369px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 184.5px; transform-origin: 407px 184.5px; vertical-align: baseline; \"\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: 276.975px 8.05px; transform-origin: 276.975px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis past Halloween, the siblings Matilda and Labrun amused (and sometimes confused) \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/51251\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003etheir many neighbors\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: 31.8917px 8.05px; transform-origin: 31.8917px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e with their costumes inspired by “\u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.spoon-tamago.com/2021/11/01/japan-jimi-mundane-halloween-2021/\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003emundane Halloween\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: 244.658px 8.05px; transform-origin: 244.658px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e”, a Japanese tradition started in 2014. As they sifted through and sampled the candy they collected, they noticed something odd as they opened one type of candy, an Oh Leonhard! bar:\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: 207.317px 8.05px; transform-origin: 207.317px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e“This wrapper has a proof of the infinitude of primes!”, said Matilda.\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: 253.475px 8.05px; transform-origin: 253.475px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e“I got that one too,” said Labrun. “And here’s one with the Twin Prime Conjecture!”\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: 242.983px 8.05px; transform-origin: 242.983px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e“Here’s the Pythagorean Theorem. And this one has the Riemann hypothesis.”\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: 359.025px 8.05px; transform-origin: 359.025px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe precocious pair determined that these wrappers were part of the Oh Leonhard! “Great Theorems and Unsolved Problems” promotion. In this promotion, wrappers with one of forty theorems, conjectures, or other famous math problems were distributed evenly among all of the Oh Leonhard! Bars produces. Anyone who collected all wrappers in the set would get a copy of the\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: 117.475px 8.05px; transform-origin: 117.475px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003e Handbook of Mathematical Functions\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: 89.4583px 8.05px; transform-origin: 89.4583px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e by Abramowitz and Stegun. \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: 383.15px 8.05px; transform-origin: 383.15px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eMatilda and Labrun computed that, on average, they would have to open 172 wrappers to complete a set and win the prize. Their calculation accounted for the contest’s rule that all pieces of the wrapper had to be submitted—that is, no fractional wrappers were allowed.\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: 383px 8.05px; transform-origin: 383px 8.05px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that takes the number of wrappers in a set and compute the expected number of wrappers that would need to be opened to collect the set.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = collectWrappers(n)\r\n  y = factorial(factorial(n));","test_suite":"%%\r\nn = 5;\r\ny_correct = 12;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 25;\r\ny_correct = 96;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 40;\r\ny_correct = 172;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 250;\r\ny_correct = 1526;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 500;\r\ny_correct = 3397;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 1000:25:1125;\r\ny_correct = [7486 7698 7911 8125 8339 8554];\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 2500;\r\ny_correct = 21004;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 10000;\r\ny_correct = 97877;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 250000;\r\ny_correct = 3251609;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 5e6;\r\ny_correct = 80010822;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 2.5e7;\r\ny_correct = 440290052;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 5e8;\r\ny_correct = 10303667162;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%%\r\nn = 2.5e9;\r\ny_correct = 55541930585;\r\nassert(isequal(collectWrappers(n),y_correct))\r\n\r\n%% Anti-lookup\r\nn = [7 17 71 77 117 171 177 711 717 771 777];\r\nyy_correct = [68 276 2216 2478 4393 7308 7647 46281 46777 51268 51779];\r\nindx = randi(11,[1 randi(11)]);\r\nassert(isequal(collectWrappers(collectWrappers(n(indx))),yy_correct(indx)))\r\n\r\n%%\r\nfiletext = fileread('collectWrappers.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp'); \r\nassert(~illegal)","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":46909,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":5,"test_suite_updated_at":"2021-11-06T13:42:54.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2021-11-06T13:09:20.000Z","updated_at":"2026-01-02T17:08:42.000Z","published_at":"2021-11-06T13:12:12.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\u003eThis past Halloween, the siblings Matilda and Labrun amused (and sometimes confused) \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/51251\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003etheir many neighbors\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e with their costumes inspired by “\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.spoon-tamago.com/2021/11/01/japan-jimi-mundane-halloween-2021/\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emundane Halloween\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e”, a Japanese tradition started in 2014. As they sifted through and sampled the candy they collected, they noticed something odd as they opened one type of candy, an Oh Leonhard! bar:\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“This wrapper has a proof of the infinitude of primes!”, said Matilda.\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“I got that one too,” said Labrun. “And here’s one with the Twin Prime Conjecture!”\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“Here’s the Pythagorean Theorem. And this one has the Riemann hypothesis.”\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 precocious pair determined that these wrappers were part of the Oh Leonhard! “Great Theorems and Unsolved Problems” promotion. In this promotion, wrappers with one of forty theorems, conjectures, or other famous math problems were distributed evenly among all of the Oh Leonhard! Bars produces. Anyone who collected all wrappers in the set would get a copy of the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e Handbook of Mathematical Functions\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e by Abramowitz and Stegun. \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\u003eMatilda and Labrun computed that, on average, they would have to open 172 wrappers to complete a set and win the prize. Their calculation accounted for the contest’s rule that all pieces of the wrapper had to be submitted—that is, no fractional wrappers were allowed.\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\u003eWrite a function that takes the number of wrappers in a set and compute the expected number of wrappers that would need to be opened to collect the set.\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":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":57620,"title":"Compute frequency factors for the normal distribution","description":"In frequency analysis in hydrology, the streamflow  corresponding to a specified exceedance probability  (or return period ) can be computed as\r\n\r\nwhere  and  are the mean and standard deviation of the streamflow series, respectively, and  is the frequency factor. \r\nWrite a function to compute the frequency factor for the normal distribution given the exceedance probability as a vector. ","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 135px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 67.5px; transform-origin: 407px 67.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 43px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21.5px; text-align: left; transform-origin: 384px 21.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 156.242px 8px; transform-origin: 156.242px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIn frequency analysis in hydrology, the streamflow \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-6px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACkAAAAoCAYAAABjPNNTAAADB0lEQVRYR+1Yu2pUURSd+QNFSyujhSBERCOINhY+IoidsRaMGqsUiqawMBEU20QDKRW1S6MoFoJGQU0gFoJFtBIrH/ELdC3Ye9hzPI89M9eQgXthce6dex7rrH32406z0QdXsw84NmqSVVmpVnK9KLkJRHYYMgtVEbPzdGPurZjgDHAKGACeyYRD0j5Eexv4UhXhTkhStXHgqix+Gi0J6cX314HzwC/gBFCJsl6Sg1hwDtgDfAb2AT8SSq2Iwux3uApFPSRJ8AWwUUjRxDlTjuL9Xel7A+1Er2YvkaQJ34oyXCs0cWz9A/jxlbwoqe7iXyL5FLMckZkW0e51zGpJsvsu4INjXLJLjuQIRj0wI72LhSSPY44n/4ukOgDn96rIvvZM8vkg0JOXp5QMVTyHhWadasygH8OQXptxk4oErilTJBn/GKy7WchagI6zzcUk0ylF8ifGaMhhRjnqXIjZiMT0uoObC86xyW4xkuFCncS6S1jpplnN62zZfcRI9uKd1tSPsDLPtl5hMVISuOVsVZIMnS3MTOr1PAIvga+ABv3LuH8DXAToC23WS53JP2abnjgXZqZYNKAzzgNalAzj/rGsYzf0Hr9dA1qxNUWSHVlM8PKEHxt2Us4yhblsHuczK6owBnMTY0ArbHniZHi2wrNkzdyJN6sQRcfMpUWbt1NZw3qzp/iwTvRdHooZKUeS52xaDjKL2CvAR5l4C9pJgGeJSreZJ5Q68qzqc97t1rSxsaUqiGMYko7J+eGk74BVgDXmc6CbzwQ9w65E4SFJRe8DLNlKBa8Vgt77KbEJjacepyz+g8HsQ3PS09lSPZr8W0FBei4/HWL1Jyv9ZdmNKyPllKQS9wDN4eFxYeigh2pg5vv9wFmAx4L5Plb9aFB3Fx8xkvpVyHKLIeW3sDskJg/Jhs/MHrcynbTCcoerlJI0Sazk5wb4pbgT2A1sEDJLaF8D/B7K1Y4cr6HHHbI8jlNSzvueYeek2RgjhE2TyXnWkqR3M//0q0l2LV0wsFayVrIqBaqa5y9jXZwpcR/A+gAAAABJRU5ErkJggg==\" alt=\"QT\" style=\"width: 20.5px; height: 20px;\" width=\"20.5\" height=\"20\"\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: 164.95px 8px; transform-origin: 164.95px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e corresponding to a specified exceedance probability \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003ep\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: 32.6667px 8px; transform-origin: 32.6667px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e (or return period \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG8AAAAlCAYAAABMBrdqAAAEZUlEQVR4Xu1aOYsVQRDe/QWekRiImgiC4ploqqKpooKBIHiF4gEegXiAYmTgKhiYeKGRoHiAgYrgBQqCiRoYGHngL9DvY6eWevN6Zrq7uh/71h74eMd0V3fX13V0zYyOlGtoNTA6tDMvEx8p5A3xJijk5SXvEsRfAL7mGKaQl0Or4zKXAO+BBYW8fErOJflMRdy2XAO0Wd4a46Dfc+0447y6us9Hgz/Az66GHfc/4/5x4JZRTmP3JvLE5KXjb3x5Xf1YWO0oufeo4f9s7iKTMkjaQWAfsBT4YBhnI/reB2Yn2ATB5O1Bj8vAbeBozYIe4vf6SuJZfB5T0ukibgJvgZWGxQ+y6ywMdqoiTca1ksdEhdf+nAtpsjya+nRgQ21wLvSH+m8Tvj+otXmD349rpOZcg0U2LWQx8BE4CayohFnJ+wU5Oxy6scy1r28TeX/R0mXy4g5EkKs/LfNi7okn1cK4sMPAuQTk0fvQ8mZmmGOPSJfy6ftXAa5AywyKbpQXY13dMvk/22hXmnsNqeSnIo96+zIIHYSe8+gSxbUcwffzqTQ3CeSkIE/CitXteqkjhLx6vBvIBL1WkaZRCvKY6B0CmJH7XtTrImAuMA24UnWUeMyfL4EXdYEh5Ol4x6NDKp9ONz3Hd6Ut7T7hnuVsloI8eqarioC2ZXHdm4HdAI9VvMaAG8A1gDqeUbt3Qq8xhDwGYZ6BePEIkapyoJVm4dDqCazkkQzGutDzLYshz5VeGZbWAVIP5WFfyF2L7xMWGEKeFrIXQsS8LQpnX26CnVYh6M8zlaUAbCWPidpywJXEtS1PztRsw/Mx+2sPoufVk2f4kie7SiYRursScJNdhJW82HIYs9Ot1epc3kPPq6co4kueVE44Bl1DSEDOrvVEA1jIE9cXUw7jmZpX09FLz2s72k0c4XzJ0/GOQTVr2ScRGaFiLOTFlsN0vGsKRboc2WOZvuSx3MPMh5erJBaqKN1+KmSbseUwXfRwhSJ9POurF/uQV3/CEOMa2sgd9mzTUg6TokeTy9TJTJ/R+JCnBTQNYrG8Yc82GYNoeaGhRFuVq1rF+68AWqTzaOZDns6GplpJTG+6mJhnKYfpokfP+a2alOQZTBBXA30FiC7yfB4BWaxuMvWNIY9e4zQQk33rJLAeiiS7bySOiusiTw/A9j2p6mTSvHEuTJr4DFIqGb4ehjHrDhBToNdFD0lWaCwHAD656ZxDE3nchcsAPpCtX0/xxzcg27sZRiJCupO0XQArI/WL1Rq+CtFUSYoth3EcXfRgHvEO4Hsz84BnwBOgs07bZXkhivjf2nKDbwFiXvfQSaAr3nnpspDnpSZno9hyGIXpJDCag+iO8WueEj3l7Bt75pWih+noVciL20vyjkrMYzFdEutMStqmV8iLIy+2HMZs8jogr04W8uL0H92LlnMPCH2TQJ6cuwa+iz+Dn0UWywvnkNbDd02ClR0+VHuPQl5qjQ5QXiFvgMpOPVQhL7VGByjvH3tR7yYA92EaAAAAAElFTkSuQmCC\" alt=\"T = 1/p\" style=\"width: 55.5px; height: 18.5px;\" width=\"55.5\" height=\"18.5\"\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: 67.2917px 8px; transform-origin: 67.2917px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e) can be computed as\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 22px; 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 11px; text-align: left; transform-origin: 384px 11px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"vertical-align:-6px\"\u003e\u003cimg src=\"data:image/png;base64,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\" alt=\"QT = mu + KT sigma\" style=\"width: 89.5px; height: 20px;\" width=\"89.5\" height=\"20\"\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 22px; 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 11px; text-align: left; transform-origin: 384px 11px; 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: 21.0083px 8px; transform-origin: 21.0083px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ewhere \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\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: 15.5583px 8px; transform-origin: 15.5583px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\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: 249.592px 8px; transform-origin: 249.592px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e are the mean and standard deviation of the streamflow series, respectively, and \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-6px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACcAAAAoCAYAAAB99ePgAAACtElEQVRYR+1XPUsdQRR97x/EmCqlSSCNJKAiBC3SmK8mnV8/wI/CUkFLNaBF0ojGIrUJRKyUWAlGBNFCC7FRf4GanxDPkbnLdZydmV3fbh7hDRzeuntn5sy5d+69Vit1PKp1zK3SIJfXOw3lilKuBQs/Diy+Y753eexO8O0yK8mQW0nuOTAGvLEW78ff3PRIkXuH50llt4nnGUAOkIlfiJwsRlV+q5W7UzYcwvuvxo7kv2diYxnHkuvDvBUz9wy/Tx2bis0ffHutFM3NL5YcFeg1u3zC75S1oyhGNw4CmePLdYJYcleY3GQW+IDfDfPcjN9pYARwkc6tGifGkHsBu0O1yyOjDN+vAk+AtBgsnNw4dpgzu9BtbwFxI+OvBzi/F4uUyTHK/cJcSSN0HZVi/P0AeAkKGzHk/qrdeRMZewdGwZoEftrpQuTeY+K6gxxfDQPLhcmGhUPkZmEjGZ9u3AIkyTLeOoHC1AuR28fm7UYdUerUxB1f1zx9aE/4yLGuUh0ZL/HAOqpdzRgk+dBt9TUFdmQkTYKPnC5ZJPFQraJv8BLej3piT/Ik09AacAx8MYdiqCwArwCmK160DlnLR24RRsz8HDYBuxEQVV0cmRNJUA7AqnJhDHVzwPjmSEqjj5wuWa4OQ5P31VQm8W+AXBwdFlJtSIp2u0DSXqWRs0sWE68dV3ZM6prrUlDeSQa45ULXhDRyui9La5G4nlYvNjFLBpjA/HnfKVzkGBN7ANXi8OUznQdpy9TyWbnQ3lurHWwWbHK8oR+BB9aqdOk2IJ0t7VqBNsfJbVttohvSZ55D3MwJJWGf6nm+SRhENQ1lk5MMEFWXyySnM4Dr9t/xRJnkdIPq+gfpn5KTFBIqdwnJMpRjqRsAmEZksMb+rLfbmumGl6FcJkLauEEur3QN5f5L5a4BNC2HKYDzOZ0AAAAASUVORK5CYII=\" alt=\"KT\" style=\"width: 19.5px; height: 20px;\" width=\"19.5\" height=\"20\"\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: 74.275px 8px; transform-origin: 74.275px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e is the frequency factor. \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: 373.275px 8px; transform-origin: 373.275px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to compute the frequency factor for the normal distribution given the exceedance probability as a vector. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function KT = normFreqFactor(p)\r\n  KT = trapz(QT:inf,exp(-Q.^2));\r\nend","test_suite":"%%\r\np = 0.001;\r\nKT_correct = 3.090;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.002;\r\nKT_correct = 2.878;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.01;\r\nKT_correct = 2.326;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.02;\r\nKT_correct = 2.054;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.04;\r\nKT_correct = 1.751;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.1;\r\nKT_correct = 1.282;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.2;\r\nKT_correct = 0.842;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.3;\r\nKT_correct = 0.524;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.5;\r\nKT_correct = 0;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\np = 0.8;\r\nKT_correct = -0.842;\r\nassert(abs(normFreqFactor(p)-KT_correct)\u003c1e-3)\r\n\r\n%%\r\nT = [5 10 20 25 50 100 250 500 1000];\r\nKT_correct = [0.842 1.282 1.645 1.751 2.054 2.326 2.652 2.878 3.090];\r\nassert(all(abs(normFreqFactor(1./T)-KT_correct)\u003c1e-3))\r\n\r\n%%\r\np = rand(1,randi(15));\r\nK1 = normFreqFactor(p);\r\nK2 = normFreqFactor(1-p);\r\nassert(all(abs(K1+K2)\u003c1e-3))\r\n\r\n%%\r\nfiletext = fileread('normFreqFactor.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'assert') || contains(filetext, 'regexp') || contains(filetext, 'interp'); \r\nassert(~illegal)","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":46909,"edited_by":46909,"edited_at":"2023-01-29T19:23:19.000Z","deleted_by":null,"deleted_at":null,"solvers_count":5,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2023-01-29T19:23:11.000Z","updated_at":"2026-01-04T12:13:24.000Z","published_at":"2023-01-29T19:23:20.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 frequency analysis in hydrology, the streamflow \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"QT\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eQ_T\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e corresponding to a specified exceedance probability \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"p\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ep\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e (or return period \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"T = 1/p\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eT = 1/p\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e) can be computed as\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:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"true\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"QT = mu + KT sigma\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eQ_T = \\\\mu + K_T \\\\sigma\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\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\u003ewhere \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"mu\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003e\\\\mu\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e and \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"sigma\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003e\\\\sigma\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e are the mean and standard deviation of the streamflow series, respectively, and \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"KT\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eK_T\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e is the frequency factor. \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\u003eWrite a function to compute the frequency factor for the normal distribution given the exceedance probability as a vector. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":1182,"title":"Hangman (easy)","description":"What is the best letter to start a \u003chttp://en.wikipedia.org/wiki/Hangman_(game) hangman\u003e game with?\r\n\r\nYou are given a cell array with all valid N-letter words. Your output should be the letter that has the highest chance of occurring (at least once) within any randomly chosen word in this dictionary. \r\n\r\nYou can assume that words will always be in all capital letters, and the cell array will always be a row.\r\n\r\n*Example:*\r\n\r\nwords={'AAA','BED','BEG','BAD'};\r\n\r\nYou should return letter='B';\r\n\r\nnote: Letter 'B' occurrs in _three_ different words. Letter 'A', while occurring four times (counting repetitions), only appears in _two_ different words. \r\n\r\n*Follow-up:* \r\n\r\nIf you are going to be losing hours of sleep over the issue of whether choosing the letter with the highest chance of occurring within any randomly chosen word is actually the _best_ 'simple' strategy in a hangman game, then the next problem in this series - \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1184-hangman-strategy Hangman (strategy)\u003e - is for you. Go ahead and test this or a different strategy there, and the contest machinery will score it based on its performance in a series of simulated hangman games. ","description_html":"\u003cp\u003eWhat is the best letter to start a \u003ca href=\"http://en.wikipedia.org/wiki/Hangman_(game)\"\u003ehangman\u003c/a\u003e game with?\u003c/p\u003e\u003cp\u003eYou are given a cell array with all valid N-letter words. Your output should be the letter that has the highest chance of occurring (at least once) within any randomly chosen word in this dictionary.\u003c/p\u003e\u003cp\u003eYou can assume that words will always be in all capital letters, and the cell array will always be a row.\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample:\u003c/b\u003e\u003c/p\u003e\u003cp\u003ewords={'AAA','BED','BEG','BAD'};\u003c/p\u003e\u003cp\u003eYou should return letter='B';\u003c/p\u003e\u003cp\u003enote: Letter 'B' occurrs in \u003ci\u003ethree\u003c/i\u003e different words. Letter 'A', while occurring four times (counting repetitions), only appears in \u003ci\u003etwo\u003c/i\u003e different words.\u003c/p\u003e\u003cp\u003e\u003cb\u003eFollow-up:\u003c/b\u003e\u003c/p\u003e\u003cp\u003eIf you are going to be losing hours of sleep over the issue of whether choosing the letter with the highest chance of occurring within any randomly chosen word is actually the \u003ci\u003ebest\u003c/i\u003e 'simple' strategy in a hangman game, then the next problem in this series - \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/1184-hangman-strategy\"\u003eHangman (strategy)\u003c/a\u003e - is for you. Go ahead and test this or a different strategy there, and the contest machinery will score it based on its performance in a series of simulated hangman games.\u003c/p\u003e","function_template":"function letter = hangman(words)\r\n  letter='S';\r\nend","test_suite":"%%\r\nwords={'AAA','BED','BEG','BAD'};\r\nassert(isequal(hangman(words),'B'));\r\n\r\n%%\r\nwords={'BUZZ','COZY','DOZE','FUZZ','GAZE','HAZE','JAZZ','LAZY','SIZE','ZERO','ZONE'};\r\nassert(isequal(hangman(words),'Z'));\r\n\r\n%%\r\nrng default;\r\nwords=unique(char('A'+randi(26,[100,3])-1),'rows');\r\nassert(isequal(sum(any(words==hangman(cellstr(words)'),2)),max(arrayfun(@(x)sum(any(words==x,2)),'A':'Z'))));\r\n\r\n%%\r\nrng default;\r\nwords=unique(char('A'+randi(26,[200,4])-1),'rows');\r\nassert(isequal(sum(any(words==hangman(cellstr(words)'),2)),max(arrayfun(@(x)sum(any(words==x,2)),'A':'Z'))));\r\n\r\n%%\r\nrng default;\r\nwords=unique(char('A'+randi(26,[500,5])-1),'rows');\r\nassert(isequal(sum(any(words==hangman(cellstr(words)'),2)),max(arrayfun(@(x)sum(any(words==x,2)),'A':'Z'))));\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":43,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":52,"test_suite_updated_at":"2013-01-08T05:17:12.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-01-07T03:59:12.000Z","updated_at":"2025-12-15T20:07:42.000Z","published_at":"2013-01-07T04:03: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:t\u003eWhat is the best letter to start a\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/Hangman_(game)\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehangman\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e game with?\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 are given a cell array with all valid N-letter words. Your output should be the letter that has the highest chance of occurring (at least once) within any randomly chosen word in this dictionary.\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 words will always be in all capital letters, and the cell array will always be a row.\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\u003ewords={'AAA','BED','BEG','BAD'};\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 should return letter='B';\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: Letter 'B' occurrs in\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\u003ethree\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e different words. Letter 'A', while occurring four times (counting repetitions), only appears in\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 different words.\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\u003eFollow-up:\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 are going to be losing hours of sleep over the issue of whether choosing the letter with the highest chance of occurring within any randomly chosen word is actually the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ebest\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 'simple' strategy in a hangman game, then the next problem in this 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/1184-hangman-strategy\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eHangman (strategy)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e - is for you. Go ahead and test this or a different strategy there, and the contest machinery will score it based on its performance in a series of simulated hangman games.\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":42615,"title":"Factorizing a number into a given number of factors","description":"Given a positive integer, n, and another positive integer, b, return a matrix, M, of width b, with the following properties: (a) Each row is sorted in ascending order (b) the rows are unique (c) the product of the integers in each row equals n (d) the columns are sorted in ascending order, such that the primary sorting is based on the first column, secondary on the second column, etc. (e) M contains integer values only\r\n\r\nNote: The number 1 is also considered a valid factor.\r\n\r\nExample 1:\r\n\r\nn = 30\r\n\r\nb = 2\r\n\r\nM = [ 1 30 ; 2 15 ; 3 10 ; 5 6 ]\r\n\r\nExample 2:\r\n\r\nn = 120\r\n\r\nb = 3\r\n\r\nM = [ 1 1 120 ; 1 2 60 ; 1 3 40 ; 1 4 30 ; 1 5 24 ; 1 6 20 ; 1 8 15 ; 1 10 12 ; 2 2 30 ; 2 3 20 ; 2 4 15 ; 2 5 12 ; 2 6 10 ; 3 4 10 ; 3 5 8 ; 4 5 6 ]","description_html":"\u003cp\u003eGiven a positive integer, n, and another positive integer, b, return a matrix, M, of width b, with the following properties: (a) Each row is sorted in ascending order (b) the rows are unique (c) the product of the integers in each row equals n (d) the columns are sorted in ascending order, such that the primary sorting is based on the first column, secondary on the second column, etc. (e) M contains integer values only\u003c/p\u003e\u003cp\u003eNote: The number 1 is also considered a valid factor.\u003c/p\u003e\u003cp\u003eExample 1:\u003c/p\u003e\u003cp\u003en = 30\u003c/p\u003e\u003cp\u003eb = 2\u003c/p\u003e\u003cp\u003eM = [ 1 30 ; 2 15 ; 3 10 ; 5 6 ]\u003c/p\u003e\u003cp\u003eExample 2:\u003c/p\u003e\u003cp\u003en = 120\u003c/p\u003e\u003cp\u003eb = 3\u003c/p\u003e\u003cp\u003eM = [ 1 1 120 ; 1 2 60 ; 1 3 40 ; 1 4 30 ; 1 5 24 ; 1 6 20 ; 1 8 15 ; 1 10 12 ; 2 2 30 ; 2 3 20 ; 2 4 15 ; 2 5 12 ; 2 6 10 ; 3 4 10 ; 3 5 8 ; 4 5 6 ]\u003c/p\u003e","function_template":"function M = LtdFactor(n,b)\r\n  M = [ n b ];\r\nend","test_suite":"%%\r\nn = 30;\r\nb = 1;\r\nA_correct = [ 30 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))\r\n\r\n%%\r\nn = 3135;\r\nb = 2;\r\nA_correct = [ 1 3135 ; 3 1045 ; 5 627 ; 11 285 ; 15 209 ; 19 165 ; 33 95 ; 55 57 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))\r\n\r\n%%\r\nn = 120;\r\nb = 3;\r\nA_correct = [ 1 1 120 ; 1 2 60 ; 1 3 40 ; 1 4 30 ; 1 5 24 ; 1 6 20 ; 1 8 15 ; 1 10 12 ; 2 2 30 ; 2 3 20 ; 2 4 15 ; 2 5 12 ; 2 6 10 ; 3 4 10 ; 3 5 8 ; 4 5 6 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))\r\n\r\n%%\r\nn = 420;\r\nb = 4;\r\nA_correct = [ 1 1 1 420 ; 1 1 2 210 ; 1 1 3 140 ; 1 1 4 105 ; 1 1 5 84 ; 1 1 6 70 ; 1 1 7 60 ; 1 1 10 42 ; 1 1 12 35 ; 1 1 14 30 ; 1 1 15 28 ; 1 1 20 21 ; 1 2 2 105 ; 1 2 3 70 ; 1 2 5 42 ; 1 2 6 35 ; 1 2 7 30 ; 1 2 10 21 ; 1 2 14 15 ; 1 3 4 35 ; 1 3 5 28 ; 1 3 7 20 ; 1 3 10 14 ; 1 4 5 21 ; 1 4 7 15 ; 1 5 6 14 ; 1 5 7 12 ; 1 6 7 10 ; 2 2 3 35 ; 2 2 5 21 ; 2 2 7 15 ; 2 3 5 14 ; 2 3 7 10 ; 2 5 6 7 ; 3 4 5 7 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))\r\n\r\n%%\r\nn = 2025;\r\nb = 3;\r\nA_correct = [ 1 1 2025 ; 1 3 675 ; 1 5 405 ; 1 9 225 ; 1 15 135 ; 1 25 81 ; 1 27 75 ; 1 45 45 ; 3 3 225 ; 3 5 135 ; 3 9 75 ; 3 15 45 ; 3 25 27 ; 5 5 81 ; 5 9 45 ; 5 15 27 ; 9 9 25 ; 9 15 15 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))\r\n\r\n%%\r\nn = 210;\r\nb = 4;\r\nA_correct = [ 1 1 1 210 ; 1 1 2 105 ; 1 1 3 70 ; 1 1 5 42 ; 1 1 6 35 ; 1 1 7 30 ; 1 1 10 21 ; 1 1 14 15 ; 1 2 3 35 ; 1 2 5 21 ; 1 2 7 15 ; 1 3 5 14 ; 1 3 7 10 ; 1 5 6 7 ; 2 3 5 7 ];\r\nassert(isequal(LtdFactor(n,b),A_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":30,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-09-14T09:47:56.000Z","updated_at":"2025-12-05T13:06:40.000Z","published_at":"2015-09-14T10:33:10.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 positive integer, n, and another positive integer, b, return a matrix, M, of width b, with the following properties: (a) Each row is sorted in ascending order (b) the rows are unique (c) the product of the integers in each row equals n (d) the columns are sorted in ascending order, such that the primary sorting is based on the first column, secondary on the second column, etc. (e) M contains integer values only\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\u003eNote: The number 1 is also considered a valid factor.\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 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en = 30\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eb = 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eM = [ 1 30 ; 2 15 ; 3 10 ; 5 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\u003cw:jc w:val=\\\"left\\\"/\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en = 120\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eb = 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eM = [ 1 1 120 ; 1 2 60 ; 1 3 40 ; 1 4 30 ; 1 5 24 ; 1 6 20 ; 1 8 15 ; 1 10 12 ; 2 2 30 ; 2 3 20 ; 2 4 15 ; 2 5 12 ; 2 6 10 ; 3 4 10 ; 3 5 8 ; 4 5 6 ]\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":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":52323,"title":"Guess the number I'm thinking of (Part 2)","description":"Have you tried the original \"Guess the number I'm thinking of\" (Problem 44630)?  This problem is just like that, except that the range of possible numbers can change, and pre-calculated answers are explicitly disallowed.  Computing all possible permutations on the fly is not disallowed per se, but it is discouraged due to the high computational load involved.  \r\nIn 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 N (inclusive).  N is an integer between 4 and 1000 (inclusive) that will be specified in each test as upperLimit.  I don't provide any other clues about the number that is to be guessed.\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 substantially better than 33.3%.  The success rate is defined as follows.  \r\nsuccess rate = (wins + draws/2) / games\r\nThe precise value of the expected success rate (when guessing with the optimal strategy) depends upon the value of N:  when N = 4 you should be able to achieve a success rate of 17/48 ≈ 35.4% on average, increasing monotonically to above 50% for N ≥ 24, eventually approaching an asymptote of 19/36 ≈ 52.8%.  (See the Test Suite for details of the thresholds applied.) \r\n\r\nRELATED PROBLEM:  \r\nProblem 44630. Guess the number I'm thinking of (Part 1)","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: 691px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 345.5px; transform-origin: 407px 345.5px; vertical-align: baseline; \"\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eHave you tried the original \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://au.mathworks.com/matlabcentral/cody/problems/44630-guess-the-number-i-m-thinking-of\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"font-style: italic; \"\u003e\"Guess the number I'm thinking of\" (Problem 44630)\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-style: italic; \"\u003e?  This problem is just like that, except that the range of possible numbers can change, and pre-calculated answers are explicitly disallowed.  Computing all possible permutations on the fly is not disallowed per se, but it is discouraged due to the high computational load involved.  \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=\"\"\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: 181px; 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 90.5px; transform-origin: 391px 90.5px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 41px; 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 20.5px; text-align: left; transform-origin: 363px 20.5px; 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-style: italic; font-weight: 700; \"\u003eN\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).  \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; font-weight: 700; \"\u003eN\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 is an integer between 4 and 1000 (inclusive) that will be specified in each test as \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-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eupperLimit\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.  I don't provide any other clues about the number that is to be guessed.\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: 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=\"\"\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 substantially better than 33.3%\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.  The success rate is defined as follows.  \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: 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThe precise value of the expected success rate (when guessing with the optimal strategy) depends upon 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-style: italic; \"\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e:  when \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-style: italic; \"\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e = 4 you should be able to achieve a success rate of 17/48 ≈ 35.4% on average, increasing monotonically to above 50% for \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-style: italic; \"\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e ≥ 24, eventually approaching an asymptote of 19/36 ≈ 52.8%.  (See the Test Suite for details of the thresholds applied.) \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/44630\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 44630. Guess the number I'm thinking of (Part 1)\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(upperLimit, guessesOfOpponents)\r\n    y = 42;\r\nend","test_suite":"%% Anti-hacking test.\r\nassessFunctionAbsence({'rng', 'RandStream'}, 'FileName','myGuess.m')\r\n\r\n%% Anti-precalculation test.\r\n% Do not try to get evade the test.  Just follow the clear rule:  DO NOT PRECALCULATE.\r\nassessFunctionAbsence({'sub2ind', 'str2num'}, 'FileName','myGuess.m')\r\n\r\n% And while we're at it, I dislike the practice of using \"ans\" in a script.  \r\nassessFunctionAbsence({'ans'}, 'FileName','myGuess.m')\r\n\r\n% And you don't really need regexp or regexpi eithr.\r\nassessFunctionAbsence({'regexp', 'regexpi'}, 'FileName','myGuess.m')\r\n\r\n%% Ensure unique guesses of integers, which are in-range.\r\nfor j = 1 : 1000\r\n    upperLim = randi([4, 1000]);\r\n    numberToBeGuessed = randi(upperLim);\r\n    gOO = randperm(upperLim, 2);\r\n    mG = myGuess(upperLim, gOO);\r\n    assert( mG \u003e= 1  \u0026  mG \u003c= upperLim , '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%% Check the success rate several times for various values of N.\r\nmaxIts = 50000;    % 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\ntic\r\nfor j = 1 : 12\r\n%for j = 5 : 20 : 1000\r\n    %upperLim = 3 + j;\r\n    if j \u003c= 4,\r\n        % Focus on smaller N.\r\n        upperLim = randi([4, 10]);\r\n    elseif j \u003c= 8,\r\n        % Focus on intermediate N.\r\n        upperLim = randi([11, 40]);\r\n    else\r\n        % Focus on larger N.\r\n        upperLim = randi([41, 1000]);\r\n    end;\r\n    WDL = [0 0 0];\r\n    for itn = 1 : maxIts\r\n        numberToBeGuessed = randi(upperLim);\r\n        gOO = randperm(upperLim, 2);\r\n        diffs = abs( [gOO myGuess(upperLim, 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    minAcceptableSuccessRate = getCutoff(upperLim);\r\n    %[upperLim minAcceptableSuccessRate successRate]\r\n    fprintf('N = %u, Threshold = %5.2f %c, Success rate = %5.2f %c.\\r\\n', upperLim, minAcceptableSuccessRate*100, '%', successRate*100, '%');\r\n    assert( successRate \u003e= minAcceptableSuccessRate )\r\nend;\r\ntoc\r\n\r\n% Define the minimum success rate that must be achieved.  \r\n% Note:  functions must be defined at the end of a script.  See https://au.mathworks.com/help/matlab/ref/function.html?s_tid=doc_ta#description\r\nfunction threshold = getCutoff(N)\r\n    % The success rate as a function of N is fit quite well \r\n    % by an equation of the form  s = sInf – A / N^k\r\n    expectedSuccessRate = 0.527353226 - 0.740005 / N^1.050420528;   \r\n    % (From fitting 310 points recorded to four decimal places.  \r\n    % The coefficients appear to be accurate to at least 3 significant figures.)  \r\n\r\n    % However, practically speaking we need to include a safety margin\r\n    % to avoid failing correct solutions on account of stochastic fluctuations.  \r\n    % A safety margin of 1 percentage point is almost always enough.  \r\n    % (1.5 percentage points would allow even more natural fluctuation, but would also risk passing incorrect 'solutions'.)  \r\n    threshold = expectedSuccessRate - 0.010;\r\nend","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":64439,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":4,"test_suite_updated_at":"2021-07-19T10:43:08.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2021-07-18T11:23:40.000Z","updated_at":"2021-07-25T08:12:28.000Z","published_at":"2021-07-18T15:01:47.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:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eHave you tried the original \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://au.mathworks.com/matlabcentral/cody/problems/44630-guess-the-number-i-m-thinking-of\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\\\"Guess the number I'm thinking of\\\" (Problem 44630)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e?  This problem is just like that, except that the range of possible numbers can change, and pre-calculated answers are explicitly disallowed.  Computing all possible permutations on the fly is not disallowed per se, but it is discouraged due to the high computational load involved.  \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 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\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (inclusive).  \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\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is an integer between 4 and 1000 (inclusive) that will be specified in each test as \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\u003eupperLimit\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.  I don't provide any other clues about the number that is to be 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\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 substantially better than 33.3%\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.  The success rate is defined as follows.  \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\u003eThe precise value of the expected success rate (when guessing with the optimal strategy) depends upon the value of \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e:  when \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e = 4 you should be able to achieve a success rate of 17/48 ≈ 35.4% on average, increasing monotonically to above 50% for \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ≥ 24, eventually approaching an asymptote of 19/36 ≈ 52.8%.  (See the Test Suite for details of the thresholds applied.) \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/44630\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44630. Guess the number I'm thinking of (Part 1)\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":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":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":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":42674,"title":"Cody meets Xiangqi: foresee the unseen (Part 1)","description":"This is the first part of the Xiangqi series. The second part in this series is: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42685-cody-meets-xiangqi-foresee-the-unseen-part-2 Cody meets Xiangqi: foresee the unseen (Part 2)\u003e\r\n\r\n\u003chttps://en.wikipedia.org/wiki/Xiangqi Xiangqi\u003e, also known as *Chinese Chess* (and 象棋 in Chinese characters), is one of the most popular board games in China. The modern Xiangqi board contains a middle section which divides two players' sides and is marked the \"Chu River–Han border\", in reference to the Chu–Han Contention between \u003chttps://en.wikipedia.org/wiki/Xiang_Yu Xiang Yu\u003e and \u003chttps://de.wikipedia.org/wiki/Han_Gaozu Liu Bang\u003e, two prominent warlords and opponents who fought thousands of battles against each other for supremacy over China in the late Qin dynasty (206–202 BC). Those interested in the story of the Chu–Han Contention and its relation to Xiangqi are referred to \u003chttps://en.wikipedia.org/wiki/Chu%E2%80%93Han_Contention here\u003e.\r\n\r\nFresh to Xiangqi, Cody becomes interested in Xiangqi by raising a question: _Who is the stronger player of Xiangqi between Xiang Yu and Liu Bang_? To answer this question, Cody designs a match for Xiang Yu and Liu Bang, in which Cody serves as the referee. The smart Cody referee also sets an intelligent rule to determine the winner: \r\n\r\n_In a succession of Xiangqi games, once Xiang Yu wins Na games *consecutively*, whereas Liu Bang has not won Nb games *consecutively*, Cody immediately announces Xiang Yu as the winner. Contrarily, once Liu Bang defeats Xiang Yu Nb times *consecutively*, whereas Xiang Yu has not won Na times *consecutively*, Liu Bang becomes the winner._ \r\n\r\nCody suggests that Na \u003e 1 and Nb \u003e 1, in order to enhance, to some extent, the confidence of the result of the match. Suppose in each individual game, the probability Xiang Yu would win is p, and the probability Liu Bang would win is 1 - p, which implicitly assumes that the probability of a tie is 0 (because they both refuse to draw and will fight to death). Unfortunately, this well-designed match has never taken place. Regretfully, Cody requests us --- active Cody players --- to foresee the outcome of this unseen match using Monte Carlo simulations. Our task is to write a function\r\n\r\n                                sol = Xiangqi(p, Na, Nb)\r\n\r\nwith input: 0 \u003c= p \u003c= 1, Na \u003e 1, Nb \u003e 1, and output: sol --- the probability that Xiang Yu wins. Your solution will be tested against its true value Q (which is computed but hided in the P-file EvaluateSolution.p) according to a hybrid absolute and relative error tolerance criterion:\r\n\r\n                      abs(sol - Q) \u003c= max(AbsTol, RelTol*abs(sol))\r\n\r\nwhere AbsTol and RelTol are absolute and relative error tolerances, respectively, which will be specified in the test suite. You are encouraged to optimize the performance (rather than the usual Cody size) of your code as much as possible, as the score of your solution will be measured based on the *speed* of your code. \r\n\r\nHave fun!\r\n","description_html":"\u003cp\u003eThis is the first part of the Xiangqi series. The second part in this series is: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42685-cody-meets-xiangqi-foresee-the-unseen-part-2\"\u003eCody meets Xiangqi: foresee the unseen (Part 2)\u003c/a\u003e\u003c/p\u003e\u003cp\u003e\u003ca href = \"https://en.wikipedia.org/wiki/Xiangqi\"\u003eXiangqi\u003c/a\u003e, also known as \u003cb\u003eChinese Chess\u003c/b\u003e (and 象棋 in Chinese characters), is one of the most popular board games in China. The modern Xiangqi board contains a middle section which divides two players' sides and is marked the \"Chu River–Han border\", in reference to the Chu–Han Contention between \u003ca href = \"https://en.wikipedia.org/wiki/Xiang_Yu\"\u003eXiang Yu\u003c/a\u003e and \u003ca href = \"https://de.wikipedia.org/wiki/Han_Gaozu\"\u003eLiu Bang\u003c/a\u003e, two prominent warlords and opponents who fought thousands of battles against each other for supremacy over China in the late Qin dynasty (206–202 BC). Those interested in the story of the Chu–Han Contention and its relation to Xiangqi are referred to \u003ca href = \"https://en.wikipedia.org/wiki/Chu%E2%80%93Han_Contention\"\u003ehere\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eFresh to Xiangqi, Cody becomes interested in Xiangqi by raising a question: \u003ci\u003eWho is the stronger player of Xiangqi between Xiang Yu and Liu Bang\u003c/i\u003e? To answer this question, Cody designs a match for Xiang Yu and Liu Bang, in which Cody serves as the referee. The smart Cody referee also sets an intelligent rule to determine the winner:\u003c/p\u003e\u003cp\u003e\u003ci\u003eIn a succession of Xiangqi games, once Xiang Yu wins Na games \u003cb\u003econsecutively\u003c/b\u003e, whereas Liu Bang has not won Nb games \u003cb\u003econsecutively\u003c/b\u003e, Cody immediately announces Xiang Yu as the winner. Contrarily, once Liu Bang defeats Xiang Yu Nb times \u003cb\u003econsecutively\u003c/b\u003e, whereas Xiang Yu has not won Na times \u003cb\u003econsecutively\u003c/b\u003e, Liu Bang becomes the winner.\u003c/i\u003e\u003c/p\u003e\u003cp\u003eCody suggests that Na \u0026gt; 1 and Nb \u0026gt; 1, in order to enhance, to some extent, the confidence of the result of the match. Suppose in each individual game, the probability Xiang Yu would win is p, and the probability Liu Bang would win is 1 - p, which implicitly assumes that the probability of a tie is 0 (because they both refuse to draw and will fight to death). Unfortunately, this well-designed match has never taken place. Regretfully, Cody requests us --- active Cody players --- to foresee the outcome of this unseen match using Monte Carlo simulations. Our task is to write a function\u003c/p\u003e\u003cpre\u003e                                sol = Xiangqi(p, Na, Nb)\u003c/pre\u003e\u003cp\u003ewith input: 0 \u0026lt;= p \u0026lt;= 1, Na \u0026gt; 1, Nb \u0026gt; 1, and output: sol --- the probability that Xiang Yu wins. Your solution will be tested against its true value Q (which is computed but hided in the P-file EvaluateSolution.p) according to a hybrid absolute and relative error tolerance criterion:\u003c/p\u003e\u003cpre\u003e                      abs(sol - Q) \u0026lt;= max(AbsTol, RelTol*abs(sol))\u003c/pre\u003e\u003cp\u003ewhere AbsTol and RelTol are absolute and relative error tolerances, respectively, which will be specified in the test suite. You are encouraged to optimize the performance (rather than the usual Cody size) of your code as much as possible, as the score of your solution will be measured based on the \u003cb\u003espeed\u003c/b\u003e of your code.\u003c/p\u003e\u003cp\u003eHave fun!\u003c/p\u003e","function_template":"function sol = Xiangqi(p, Na, Nb)\r\n  sol = p;\r\nend","test_suite":"%%\r\n% By courtesy of Alfonso Nieto-Castanon\r\nurlwrite('https://sites.google.com/a/alfnie.com/alfnie/software/SetSolutionScore.p?attredirects=0\u0026amp;d=1','SetSolutionScore.p');\r\nrehash path;\r\n\r\n%%\r\nfh = fopen('EvaluateSolution.p','wb');\r\nfwrite(fh, hex2dec(reshape('7630312E30307630302E3030000E601C0AF25FB100000056000000A4000000D6820EB5B30514117A9E6E5DB36898AFFFCC5086DFAF59C2910AEB07B88523DABE546868AC2BDAC3795467A7BCD91A89E2F578F2EDE92D63472A3B8FCA3F216CB3B66B010B5B924A5F514E19B90225B0978A54DA881119917D211CB055361918CAA0670F6D0E8ED17B319492619F4361BFB4C3C31D68E11F4BA084C6456783C358296B3E63E16C78EF2B0279074BCB707265EB4C044BFF7F25BA0A9678B75D36B9ACEE6853',2,[]).')); rehash path; fclose(fh); \r\n\r\n%%\r\np = 0; Na = 2; Nb = 3;\r\nAbsTol = 1e-6; RelTol = 1e-5;\r\nsol = Xiangqi(p, Na, Nb);\r\nassert(EvaluateSolution(p,Na,Nb,sol,AbsTol,RelTol));\r\n\r\n%%\r\np = 1; Na = 3; Nb = 2;\r\nAbsTol = 1e-6; RelTol = 1e-5;\r\nsol = Xiangqi(p, Na, Nb);\r\nassert(EvaluateSolution(p,Na,Nb,sol,AbsTol,RelTol));\r\n\r\n%%\r\np = 0.4; Na = 2; Nb = 3;\r\nAbsTol = 5e-4; RelTol = 5e-4;\r\nsol = Xiangqi(p, Na, Nb);\r\nassert(EvaluateSolution(p,Na,Nb,sol,AbsTol,RelTol));\r\n\r\n%%\r\np = 0.7; Na = 4; Nb = 2;\r\nAbsTol = 5e-4; RelTol = 5e-4;\r\nsol = Xiangqi(p, Na, Nb);\r\nassert(EvaluateSolution(p,Na,Nb,sol,AbsTol,RelTol));\r\n\r\n%%\r\np = 0.15; Na = 4; Nb = 2;\r\nAbsTol = 5e-5; RelTol = 1e-6;\r\nt = builtin('tic');\r\nsol = Xiangqi(p, Na, Nb);\r\nscore = builtin('toc',t);\r\nassert(EvaluateSolution(p,Na,Nb,sol,AbsTol,RelTol));\r\nSetSolutionScore(round(500*score));","published":true,"deleted":false,"likes_count":3,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":9,"test_suite_updated_at":"2015-10-30T08:18:09.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-10-30T05:02:43.000Z","updated_at":"2025-11-30T16:38:45.000Z","published_at":"2015-10-30T05:45:36.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 the first part of the Xiangqi series. The second part in this series is:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42685-cody-meets-xiangqi-foresee-the-unseen-part-2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody meets Xiangqi: foresee the unseen (Part 2)\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:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Xiangqi\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eXiangqi\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, also known as\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\u003eChinese Chess\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (and 象棋 in Chinese characters), is one of the most popular board games in China. The modern Xiangqi board contains a middle section which divides two players' sides and is marked the \\\"Chu River–Han border\\\", in reference to the Chu–Han Contention between\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Xiang_Yu\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eXiang Yu\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://de.wikipedia.org/wiki/Han_Gaozu\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eLiu Bang\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, two prominent warlords and opponents who fought thousands of battles against each other for supremacy over China in the late Qin dynasty (206–202 BC). Those interested in the story of the Chu–Han Contention and its relation to Xiangqi are referred 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=\\\"https://en.wikipedia.org/wiki/Chu%E2%80%93Han_Contention\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehere\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\u003eFresh to Xiangqi, Cody becomes interested in Xiangqi by raising a question:\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\u003eWho is the stronger player of Xiangqi between Xiang Yu and Liu Bang\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e? To answer this question, Cody designs a match for Xiang Yu and Liu Bang, in which Cody serves as the referee. The smart Cody referee also sets an intelligent rule to determine the winner:\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\u003eIn a succession of Xiangqi games, once Xiang Yu wins Na games\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\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\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econsecutively\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e, whereas Liu Bang has not won Nb games\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\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\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econsecutively\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e, Cody immediately announces Xiang Yu as the winner. Contrarily, once Liu Bang defeats Xiang Yu Nb times\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\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\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econsecutively\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e, whereas Xiang Yu has not won Na times\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\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\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003econsecutively\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e, Liu Bang becomes the winner.\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\u003eCody suggests that Na \u0026gt; 1 and Nb \u0026gt; 1, in order to enhance, to some extent, the confidence of the result of the match. Suppose in each individual game, the probability Xiang Yu would win is p, and the probability Liu Bang would win is 1 - p, which implicitly assumes that the probability of a tie is 0 (because they both refuse to draw and will fight to death). Unfortunately, this well-designed match has never taken place. Regretfully, Cody requests us --- active Cody players --- to foresee the outcome of this unseen match using Monte Carlo simulations. Our task is to 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[                                sol = Xiangqi(p, Na, Nb)]]\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\u003ewith input: 0 \u0026lt;= p \u0026lt;= 1, Na \u0026gt; 1, Nb \u0026gt; 1, and output: sol --- the probability that Xiang Yu wins. Your solution will be tested against its true value Q (which is computed but hided in the P-file EvaluateSolution.p) according to a hybrid absolute and relative error tolerance criterion:\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[                      abs(sol - Q) \u003c= max(AbsTol, RelTol*abs(sol))]]\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\u003ewhere AbsTol and RelTol are absolute and relative error tolerances, respectively, which will be specified in the test suite. You are encouraged to optimize the performance (rather than the usual Cody size) of your code as much as possible, as the score of your solution will be measured based on the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003espeed\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of your code.\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\u003eHave fun!\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":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":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":45389,"title":"Knight's Watch","description":"  \"Night gathers, and now my watch begins\"\r\n\r\nA knight is placed on an n-by-n sized chessboard at the position x. Find the probability that after k steps, the knight will remain within the chessboard.\r\n\r\nAny knight's move that places him outside the board should be considered invalid.\r\n\r\n For simplicity, the knight's position on the chessboard is defined with the numeric\r\n notation instead of algebraic notation. so 'Ka1' is represented as (1,1).\r\n\r\nBrief explanation:\r\n\r\n  Say the knight is placed in pos-(1,1). A knight has 8 possible moves. So in the next move, \r\nthe Knight can go to 8 different positions in the chessboard. But among them, only 2\r\n positions are valid i.e. the knight remains within the chessboard and they are -\r\n(3,2) \u0026 (2,3). So the prob. is 2/8 after 1 move. What will be the probability after k moves?\r\n\r\n","description_html":"\u003cpre class=\"language-matlab\"\u003e\"Night gathers, and now my watch begins\"\r\n\u003c/pre\u003e\u003cp\u003eA knight is placed on an n-by-n sized chessboard at the position x. Find the probability that after k steps, the knight will remain within the chessboard.\u003c/p\u003e\u003cp\u003eAny knight's move that places him outside the board should be considered invalid.\u003c/p\u003e\u003cpre\u003e For simplicity, the knight's position on the chessboard is defined with the numeric\r\n notation instead of algebraic notation. so 'Ka1' is represented as (1,1).\u003c/pre\u003e\u003cp\u003eBrief explanation:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eSay the knight is placed in pos-(1,1). A knight has 8 possible moves. So in the next move, \r\nthe Knight can go to 8 different positions in the chessboard. But among them, only 2\r\npositions are valid i.e. the knight remains within the chessboard and they are -\r\n(3,2) \u0026 (2,3). So the prob. is 2/8 after 1 move. What will be the probability after k moves?\r\n\u003c/pre\u003e","function_template":"function prob = knights_watch(x,n,k)","test_suite":"%%\r\nx =[1,1];\r\nassert(isequal(knights_watch(x,3,2),0.0625))\r\n%%\r\nx =[1,1];\r\nassert(isequal(knights_watch(x,4,4),0.0176))\r\n%%\r\nx =[6,4];\r\nassert(isequal(knights_watch(x,6,9),0.012))\r\n%%\r\nx =[6,4];\r\nassert(isequal(knights_watch(x,8,25),0.0011))\r\n%%\r\nx =[8,8];\r\nassert(isequal(knights_watch(x,8,15),0.0042))\r\n%%\r\nx =[8,8];\r\nassert(isequal(knights_watch(x,16,15),0.4666))\r\n%%\r\nx =[3,1];\r\nassert(isequal(knights_watch(x,16,50),0.0037))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":13,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-03-25T18:55:22.000Z","updated_at":"2026-01-23T12:14:39.000Z","published_at":"2020-03-25T18:55:22.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[\\\"Night gathers, and now my watch begins\\\"]]\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\u003eA knight is placed on an n-by-n sized chessboard at the position x. Find the probability that after k steps, the knight will remain within the chessboard.\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\u003eAny knight's move that places him outside the board should be considered invalid.\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[ For simplicity, the knight's position on the chessboard is defined with the numeric\\n notation instead of algebraic notation. so 'Ka1' is represented as (1,1).]]\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\u003eBrief explanation:\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[Say the knight is placed in pos-(1,1). A knight has 8 possible moves. So in the next move, \\nthe Knight can go to 8 different positions in the chessboard. But among them, only 2\\npositions are valid i.e. the knight remains within the chessboard and they are -\\n(3,2) \u0026 (2,3). So the prob. is 2/8 after 1 move. What will be the probability after k moves?]]\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":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":1260,"title":"RISK board game battle simulation","description":"Given two positive integer inputs, a (attacker army units) and d (defender army units) return the probablity of victory (from 0.000 to 1.000) to +- 0.02 accuracy. The rules are given below for those unfamiliar with the game. \r\n\r\nIn the board game RISK battles are determined by the conflict of armies, namely the attacking army and the defending army. The results is determined as follows: the attacker rolls 3 six-sided die and the defender rolls 2 die. The highest two numbers of each player are compared respectively, and the higher number wins (this means the opposing army loses one unit). In the case of a tie the defender wins. For example:\r\n\r\nAttacker has 10 units\r\nDefender has 10 units\r\n\r\nAttacker rolls [6 3 2]\r\nDefender rolls [4 3]\r\n\r\nThe first comparison is attacker - 6, defender - 4. Since the attacker is higher, the defender loses one unit. Hence Attacker has 10 units, Defender now has 9 units.\r\n\r\nThe first comparison is attacker - 3, defender - 3. Since the defender is higher, the attacker loses one unit. Hence Attacker has 9 units, Defender now has 9 units.\r\n\r\nThis is continued until either the attacker has only one unit left, in which case the defender wins the battle; or the defender has no units left, in which case the attacker wins the battle.\r\n\r\nThis is one further rule: the number of die any player may roll cannot be more than the their units in case of the defender, or their units + 1 in case of the attacker. \r\n\r\nExample:\r\nAttacker has 3 units,\r\nDefender has 1 units.\r\n\r\nAttacker rolls 2 die (3 - 1),\r\nDefender rolls 1 die.","description_html":"\u003cp\u003eGiven two positive integer inputs, a (attacker army units) and d (defender army units) return the probablity of victory (from 0.000 to 1.000) to +- 0.02 accuracy. The rules are given below for those unfamiliar with the game.\u003c/p\u003e\u003cp\u003eIn the board game RISK battles are determined by the conflict of armies, namely the attacking army and the defending army. The results is determined as follows: the attacker rolls 3 six-sided die and the defender rolls 2 die. The highest two numbers of each player are compared respectively, and the higher number wins (this means the opposing army loses one unit). In the case of a tie the defender wins. For example:\u003c/p\u003e\u003cp\u003eAttacker has 10 units\r\nDefender has 10 units\u003c/p\u003e\u003cp\u003eAttacker rolls [6 3 2]\r\nDefender rolls [4 3]\u003c/p\u003e\u003cp\u003eThe first comparison is attacker - 6, defender - 4. Since the attacker is higher, the defender loses one unit. Hence Attacker has 10 units, Defender now has 9 units.\u003c/p\u003e\u003cp\u003eThe first comparison is attacker - 3, defender - 3. Since the defender is higher, the attacker loses one unit. Hence Attacker has 9 units, Defender now has 9 units.\u003c/p\u003e\u003cp\u003eThis is continued until either the attacker has only one unit left, in which case the defender wins the battle; or the defender has no units left, in which case the attacker wins the battle.\u003c/p\u003e\u003cp\u003eThis is one further rule: the number of die any player may roll cannot be more than the their units in case of the defender, or their units + 1 in case of the attacker.\u003c/p\u003e\u003cp\u003eExample:\r\nAttacker has 3 units,\r\nDefender has 1 units.\u003c/p\u003e\u003cp\u003eAttacker rolls 2 die (3 - 1),\r\nDefender rolls 1 die.\u003c/p\u003e","function_template":"function y = risk_prob(a, d)\r\n  y = 0.000;\r\nend","test_suite":"%%\r\na = 3;\r\nd = 0;\r\ny_correct = 1.000;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.01)\r\n\r\n%%\r\na = 1;\r\nd = 5;\r\ny_correct = 0.000;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.01)\r\n\r\n%%\r\na = 5;\r\nd = 3;\r\ny_correct = 0.642;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 4;\r\nd = 6;\r\ny_correct = 0.134;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 10;\r\nd = 10;\r\ny_correct = 0.480;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 7;\r\nd = 8;\r\ny_correct = 0.329;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 8;\r\nd = 7;\r\ny_correct = 0.5355;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 20;\r\nd = 10;\r\ny_correct = 0.965;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 4;\r\nd = 2;\r\ny_correct = 0.656;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 6;\r\nd = 4;\r\ny_correct = 0.638;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 2;\r\nd = 1;\r\ny_correct = 0.417;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 2;\r\nd = 2;\r\ny_correct = 0.104;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":6,"created_by":10338,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":42,"test_suite_updated_at":"2013-02-12T00:28:08.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-02-10T23:10:17.000Z","updated_at":"2026-02-15T07:37:57.000Z","published_at":"2013-02-10T23:10: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\u003eGiven two positive integer inputs, a (attacker army units) and d (defender army units) return the probablity of victory (from 0.000 to 1.000) to +- 0.02 accuracy. The rules are given below for those unfamiliar with 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn the board game RISK battles are determined by the conflict of armies, namely the attacking army and the defending army. The results is determined as follows: the attacker rolls 3 six-sided die and the defender rolls 2 die. The highest two numbers of each player are compared respectively, and the higher number wins (this means the opposing army loses one unit). In the case of a tie the defender wins. For example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAttacker has 10 units Defender has 10 units\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\u003eAttacker rolls [6 3 2] Defender rolls [4 3]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe first comparison is attacker - 6, defender - 4. Since the attacker is higher, the defender loses one unit. Hence Attacker has 10 units, Defender now has 9 units.\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 first comparison is attacker - 3, defender - 3. Since the defender is higher, the attacker loses one unit. Hence Attacker has 9 units, Defender now has 9 units.\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\u003eThis is continued until either the attacker has only one unit left, in which case the defender wins the battle; or the defender has no units left, in which case the attacker wins the battle.\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\u003eThis is one further rule: the number of die any player may roll cannot be more than the their units in case of the defender, or their units + 1 in case of the attacker.\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: Attacker has 3 units, Defender has 1 units.\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\u003eAttacker rolls 2 die (3 - 1), Defender rolls 1 die.\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":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":44885,"title":"Bridge and Torch Problem - Probability","description":"\u003chttps://en.wikipedia.org/wiki/Bridge_and_torch_problem Details of the problem ...\u003e \r\n\r\nThere are four people who wants to cross the bridge. But we don't know exactly who will cross the bridge in which time. However, we know that a person can cross the bridge in n1 minutes (n1 is randomly selected from the range 1:n, n is the first input). All crossing times are integers. They use *Crossing Model* to cross the bridge. In each turn, they randomly select the person(s) who will cross the bridge. What is the probability that they will cross the bridge less than or equal to t minutes (t is the second input).\r\n\r\nLet's assume first input n = 3. That means people will cross the bridge in 1, 2 or 3 minutes. all of them can cross the bridge in 1 minute or maybe all of them can cross the bridge in 3 minutes. Possibilities are listed below.\r\n\r\n  crossingTimeList = [\r\n1\t1\t1\t1\r\n1\t1\t1\t2\r\n1\t1\t1\t3\r\n1\t1\t2\t2\r\n1\t1\t2\t3\r\n1\t1\t3\t3\r\n1\t2\t2\t2\r\n1\t2\t2\t3\r\n1\t2\t3\t3\r\n1\t3\t3\t3\r\n2\t2\t2\t2\r\n2\t2\t2\t3\r\n2\t2\t3\t3\r\n2\t3\t3\t3\r\n3\t3\t3\t3]\r\n\r\nIf first line is the case, all of the people will cross the bridge in 1 minute. There will be 108 cases  ( |108 = 4C2 X 2C1 X 3C2 X 3C1| ) taking 5 minutes. All of them will be less than or equal to 10 minutes (which is input 2). \r\n\r\nIf ninth line is the case, one person will cross the bridge in one minute, one person will cross the bridge in two minutes, and others will cross the bridge in 3 minutes. 8 out of 108 ways will take less than or equal to 10 minutes. \r\n\r\nIf last one is the case, all of them will cross the bridge in three minutes indicates that all of the journeys will take 15 minutes (longer than input2 or 10 minutes).\r\n\r\nResult of the crossingTimeList are as follow\r\n\r\n  result = [\r\n108\t108\r\n108\t108\r\n060\t108\r\n108\t108\r\n054\t108\r\n026\t108\r\n108\t108\r\n304\t108\r\n008\t108\r\n000\t108\r\n108\t108\r\n000\t108\r\n000\t108\r\n000\t108\r\n000\t108]\r\n\r\nAs a result 722 out of 1620 ways will take \u003c= 10 minutes (722/1620=0.4457).\r\n\r\n\r\n*Assumption 1:* for this problem only four people will cross the bridge\r\n\r\n*Assumption 2:* crossing times are integer\r\n\r\n*Crossing Model:* 2 out of 4 people will cross the bridge, one of them will return. two out of 3 people will cross the bridge, one out of three people will return. Remaining two people will cross the bridge.  ","description_html":"\u003cp\u003e\u003ca href = \"https://en.wikipedia.org/wiki/Bridge_and_torch_problem\"\u003eDetails of the problem ...\u003c/a\u003e\u003c/p\u003e\u003cp\u003eThere are four people who wants to cross the bridge. But we don't know exactly who will cross the bridge in which time. However, we know that a person can cross the bridge in n1 minutes (n1 is randomly selected from the range 1:n, n is the first input). All crossing times are integers. They use \u003cb\u003eCrossing Model\u003c/b\u003e to cross the bridge. In each turn, they randomly select the person(s) who will cross the bridge. What is the probability that they will cross the bridge less than or equal to t minutes (t is the second input).\u003c/p\u003e\u003cp\u003eLet's assume first input n = 3. That means people will cross the bridge in 1, 2 or 3 minutes. all of them can cross the bridge in 1 minute or maybe all of them can cross the bridge in 3 minutes. Possibilities are listed below.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ecrossingTimeList = [\r\n1\t1\t1\t1\r\n1\t1\t1\t2\r\n1\t1\t1\t3\r\n1\t1\t2\t2\r\n1\t1\t2\t3\r\n1\t1\t3\t3\r\n1\t2\t2\t2\r\n1\t2\t2\t3\r\n1\t2\t3\t3\r\n1\t3\t3\t3\r\n2\t2\t2\t2\r\n2\t2\t2\t3\r\n2\t2\t3\t3\r\n2\t3\t3\t3\r\n3\t3\t3\t3]\r\n\u003c/pre\u003e\u003cp\u003eIf first line is the case, all of the people will cross the bridge in 1 minute. There will be 108 cases  ( \u003ctt\u003e108 = 4C2 X 2C1 X 3C2 X 3C1\u003c/tt\u003e ) taking 5 minutes. All of them will be less than or equal to 10 minutes (which is input 2).\u003c/p\u003e\u003cp\u003eIf ninth line is the case, one person will cross the bridge in one minute, one person will cross the bridge in two minutes, and others will cross the bridge in 3 minutes. 8 out of 108 ways will take less than or equal to 10 minutes.\u003c/p\u003e\u003cp\u003eIf last one is the case, all of them will cross the bridge in three minutes indicates that all of the journeys will take 15 minutes (longer than input2 or 10 minutes).\u003c/p\u003e\u003cp\u003eResult of the crossingTimeList are as follow\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eresult = [\r\n108\t108\r\n108\t108\r\n060\t108\r\n108\t108\r\n054\t108\r\n026\t108\r\n108\t108\r\n304\t108\r\n008\t108\r\n000\t108\r\n108\t108\r\n000\t108\r\n000\t108\r\n000\t108\r\n000\t108]\r\n\u003c/pre\u003e\u003cp\u003eAs a result 722 out of 1620 ways will take \u0026lt;= 10 minutes (722/1620=0.4457).\u003c/p\u003e\u003cp\u003e\u003cb\u003eAssumption 1:\u003c/b\u003e for this problem only four people will cross the bridge\u003c/p\u003e\u003cp\u003e\u003cb\u003eAssumption 2:\u003c/b\u003e crossing times are integer\u003c/p\u003e\u003cp\u003e\u003cb\u003eCrossing Model:\u003c/b\u003e 2 out of 4 people will cross the bridge, one of them will return. two out of 3 people will cross the bridge, one out of three people will return. Remaining two people will cross the bridge.\u003c/p\u003e","function_template":"function y = bridgeProb(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nfiletext = fileread('bridgeProb.m');\r\nassert(isempty(strfind(filetext, 'assert')))\r\nassert(isempty(strfind(filetext, 'echo')))\r\n%%\r\nx = [3 10];\r\nassert(and( ge(bridgeProb(x), 0.43) , le(bridgeProb(x), 0.45)))\r\n%%\r\nx = [8 5];\r\nassert(and( ge(bridgeProb(x), 0.00) , le(bridgeProb(x), 0.01)))\r\n%%\r\nx = [10 5];\r\nassert(and( ge(bridgeProb(x), 0.00) , le(bridgeProb(x), 0.01)))\r\n%%\r\nx = [8 15];\r\nassert(and( ge(bridgeProb(x), 0.10) , le(bridgeProb(x), 0.12)))\r\n%%\r\nx = [8 17];\r\nassert(and( ge(bridgeProb(x), 0.15) , le(bridgeProb(x), 0.17)))\r\n%%\r\nx = [10 35];\r\nassert(and( ge(bridgeProb(x), 0.60) , le(bridgeProb(x), 0.62)))\r\n%%\r\nx = [10 35];\r\nassert(and( ge(bridgeProb(x), 0.60) , le(bridgeProb(x), 0.62)))\r\n%%\r\nx = [10 40];\r\nassert(and( ge(bridgeProb(x), 0.78) , le(bridgeProb(x), 0.80)))\r\n%%\r\nx = [7 20];\r\nassert(and( ge(bridgeProb(x), 0.35) , le(bridgeProb(x), 0.37)))\r\n%%\r\nx = [8 25];\r\nassert(and( ge(bridgeProb(x), 0.45) , le(bridgeProb(x), 0.47)))\r\n%%\r\nx = [8 10];\r\nassert(and( ge(bridgeProb(x), 0.01) , le(bridgeProb(x), 0.03)))\r\n%%\r\nx = [9 15];\r\nassert(and( ge(bridgeProb(x), 0.06) , le(bridgeProb(x), 0.08)))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":4,"test_suite_updated_at":"2019-04-23T07:16:06.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2019-04-21T08:29:03.000Z","updated_at":"2025-05-02T02:43:56.000Z","published_at":"2019-04-22T12:28:10.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:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Bridge_and_torch_problem\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDetails of the problem ...\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\u003eThere are four people who wants to cross the bridge. But we don't know exactly who will cross the bridge in which time. However, we know that a person can cross the bridge in n1 minutes (n1 is randomly selected from the range 1:n, n is the first input). All crossing times are integers. They use\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eCrossing Model\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e to cross the bridge. In each turn, they randomly select the person(s) who will cross the bridge. What is the probability that they will cross the bridge less than or equal to t minutes (t is the second 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLet's assume first input n = 3. That means people will cross the bridge in 1, 2 or 3 minutes. all of them can cross the bridge in 1 minute or maybe all of them can cross the bridge in 3 minutes. Possibilities are listed below.\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[crossingTimeList = [\\n1  1  1  1\\n1  1  1  2\\n1  1  1  3\\n1  1  2  2\\n1  1  2  3\\n1  1  3  3\\n1  2  2  2\\n1  2  2  3\\n1  2  3  3\\n1  3  3  3\\n2  2  2  2\\n2  2  2  3\\n2  2  3  3\\n2  3  3  3\\n3  3  3  3]]]\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 first line is the case, all of the people will cross the bridge in 1 minute. There will be 108 cases (\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\u003e108 = 4C2 X 2C1 X 3C2 X 3C1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e ) taking 5 minutes. All of them will be less than or equal to 10 minutes (which is input 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\u003eIf ninth line is the case, one person will cross the bridge in one minute, one person will cross the bridge in two minutes, and others will cross the bridge in 3 minutes. 8 out of 108 ways will take less than or equal to 10 minutes.\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 last one is the case, all of them will cross the bridge in three minutes indicates that all of the journeys will take 15 minutes (longer than input2 or 10 minutes).\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\u003eResult of the crossingTimeList are as follow\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[result = [\\n108  108\\n108  108\\n060  108\\n108  108\\n054  108\\n026  108\\n108  108\\n304  108\\n008  108\\n000  108\\n108  108\\n000  108\\n000  108\\n000  108\\n000  108]]]\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\u003eAs a result 722 out of 1620 ways will take \u0026lt;= 10 minutes (722/1620=0.4457).\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\u003eAssumption 1:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for this problem only four people will cross the bridge\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\u003eAssumption 2:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e crossing times are integer\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\u003eCrossing Model:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 2 out of 4 people will cross the bridge, one of them will return. two out of 3 people will cross the bridge, one out of three people will return. Remaining two people will cross the bridge.\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":44502,"title":"Anyone for tennis?  Your chances of winning a (standard) game","description":"Imagine you are playing tennis, and for _each point_ played your chance of winning is |x| % (input as a |\u003chttps://au.mathworks.com/help/matlab/ref/uint8.html uint8\u003e|).  Given the \u003chttp://www.itftennis.com/procircuit/about-pro-circuit/rules-regulations.aspx ITF's scoring system for a \"standard game\" of tennis\u003e (excerpted below), please determine your likelihood of winning a game (output as a |\u003chttps://au.mathworks.com/help/matlab/ref/single.html single\u003e|).  \r\n\r\nNote that as |x| is taken to be the same for every point in this problem, it does not matter whether you are serving or not.  \r\n\r\nEXAMPLE\r\n\r\n x = uint8(40)\r\n chance = single(0.2642707692307693)\r\n\r\n-----\r\n\r\n*\"* A standard game is scored as follows with the server’s score being called first:\r\n\r\n* No point - “Love”\r\n* First point - “15”\r\n* Second point - “30”\r\n* Third point - “40”\r\n* Fourth point - “Game”\r\n\r\nexcept that if each player/team has won three points, the score is “Deuce”.\r\nAfter “Deuce”, the score is “Advantage” for the player/team who wins the next point. If that same player/team also wins the next point, that player/team wins the “Game”; if the opposing player/team wins the next point, the score is again “Deuce”. A player/team needs to win two consecutive points immediately after “Deuce” to win the “Game”. *\"*\r\n\r\n-----\r\n\r\nSee also \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44503 Problem 44503. Anyone for tennis? Your chances of winning a tie-break game\u003e.","description_html":"\u003cp\u003eImagine you are playing tennis, and for \u003ci\u003eeach point\u003c/i\u003e played your chance of winning is \u003ctt\u003ex\u003c/tt\u003e % (input as a \u003ctt\u003e\u003ca href = \"https://au.mathworks.com/help/matlab/ref/uint8.html\"\u003euint8\u003c/a\u003e\u003c/tt\u003e).  Given the \u003ca href = \"http://www.itftennis.com/procircuit/about-pro-circuit/rules-regulations.aspx\"\u003eITF's scoring system for a \"standard game\" of tennis\u003c/a\u003e (excerpted below), please determine your likelihood of winning a game (output as a \u003ctt\u003e\u003ca href = \"https://au.mathworks.com/help/matlab/ref/single.html\"\u003esingle\u003c/a\u003e\u003c/tt\u003e).\u003c/p\u003e\u003cp\u003eNote that as \u003ctt\u003ex\u003c/tt\u003e is taken to be the same for every point in this problem, it does not matter whether you are serving or not.\u003c/p\u003e\u003cp\u003eEXAMPLE\u003c/p\u003e\u003cpre\u003e x = uint8(40)\r\n chance = single(0.2642707692307693)\u003c/pre\u003e\u003cp\u003e-----\u003c/p\u003e\u003cp\u003e\u003cb\u003e\"\u003c/b\u003e A standard game is scored as follows with the server’s score being called first:\u003c/p\u003e\u003cul\u003e\u003cli\u003eNo point - “Love”\u003c/li\u003e\u003cli\u003eFirst point - “15”\u003c/li\u003e\u003cli\u003eSecond point - “30”\u003c/li\u003e\u003cli\u003eThird point - “40”\u003c/li\u003e\u003cli\u003eFourth point - “Game”\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eexcept that if each player/team has won three points, the score is “Deuce”.\r\nAfter “Deuce”, the score is “Advantage” for the player/team who wins the next point. If that same player/team also wins the next point, that player/team wins the “Game”; if the opposing player/team wins the next point, the score is again “Deuce”. A player/team needs to win two consecutive points immediately after “Deuce” to win the “Game”. \u003cb\u003e\"\u003c/b\u003e\u003c/p\u003e\u003cp\u003e-----\u003c/p\u003e\u003cp\u003eSee also \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44503\"\u003eProblem 44503. Anyone for tennis? Your chances of winning a tie-break game\u003c/a\u003e.\u003c/p\u003e","function_template":"function chance = standardGame(x)\r\n\r\n    % Your comments \r\n    \r\nend","test_suite":"%% Please do not try to hack the Test Suite.  \r\n% The Test Suite will be updated if inappropriate submissions are received.  \r\n% This includes hard-coded (pre-calculated, externally calculated, manually calculated) 'solutions'.\r\nfiletext = fileread('standardGame.m');\r\nvec = [923273, 144780, 713710, 217788, 507812, 992110, 170355, 264270, 376851, 475014];\r\nmsg = 'Please do not hard-code your ''solution''.';\r\nassert( all( arrayfun(@(z) isempty(strfind(filetext, num2str(z))), vec) ) , msg )\r\n\r\n%% Test self-consistency:  \r\n% There are only two players, so the chances for each should add up to one.  \r\nassert( abs(standardGame(100)+standardGame(0) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(standardGame(90)+standardGame(10) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(standardGame(80)+standardGame(20) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(standardGame(70)+standardGame(30) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(standardGame(60)+standardGame(40) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(standardGame(50)+standardGame(50) - 1)  \u003c 20 * eps(single(1)) )\r\n\r\n%%\r\nx = uint8(50);\r\ny_correct = 0.50;\r\nassert( isequal(standardGame(x), y_correct) )\r\n\r\n%%\r\nx = uint8(0);\r\ny_correct = 0;\r\nassert( isequal(standardGame(x), y_correct) )\r\n\r\n%%\r\nx = uint8(100);\r\ny_correct = 1;\r\nassert( isequal(standardGame(x), y_correct) )\r\n\r\n%%\r\nx = uint8(5);\r\ny_correct = 0.0000923273480663;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(10);\r\ny_correct = 0.0014478048780488;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(15);\r\ny_correct = 0.0071371057046980;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(20);\r\ny_correct = 0.0217788235294118;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(25);\r\ny_correct = 0.0507812500000000;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(30);\r\ny_correct = 0.0992110344827586;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(35);\r\ny_correct = 0.1703553555045871;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(40);\r\ny_correct = 0.2642707692307693;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(45);\r\ny_correct = 0.3768514975247527;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(49);\r\ny_correct = 0.4750149924031987;\r\nassert( abs( standardGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%% Test adherence to instructions\r\nfor i = 1:5\r\n    x = uint8( randi(100) );\r\n    assert( isequal(class(standardGame(x)), 'single') )\r\nend;\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":64439,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":4,"test_suite_updated_at":"2018-01-18T10:56:38.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2018-01-18T00:25:34.000Z","updated_at":"2019-07-02T13:23:52.000Z","published_at":"2018-01-18T01:51:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eImagine you are playing tennis, and for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eeach point\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e played your chance of winning 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e % (input as 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://au.mathworks.com/help/matlab/ref/uint8.html\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003euint8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e). Given 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.itftennis.com/procircuit/about-pro-circuit/rules-regulations.aspx\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eITF's scoring system for a \\\"standard game\\\" of tennis\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (excerpted below), please determine your likelihood of winning a game (output as 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://au.mathworks.com/help/matlab/ref/single.html\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esingle\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\u003eNote that as\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\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is taken to be the same for every point in this problem, it does not matter whether you are serving 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEXAMPLE\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x = uint8(40)\\n chance = single(0.2642707692307693)]]\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\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\u003e\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e A standard game is scored as follows with the server’s score being called first:\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\u003eNo point - “Love”\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\u003eFirst point - “15”\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSecond point - “30”\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\u003eThird point - “40”\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFourth point - “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\u003eexcept that if each player/team has won three points, the score is “Deuce”. After “Deuce”, the score is “Advantage” for the player/team who wins the next point. If that same player/team also wins the next point, that player/team wins the “Game”; if the opposing player/team wins the next point, the score is again “Deuce”. A player/team needs to win two consecutive points immediately after “Deuce” to win the “Game”.\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\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\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=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44503\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44503. Anyone for tennis? Your chances of winning a tie-break game\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44503,"title":"Anyone for tennis?  Your chances of winning a tie-break game","description":"Imagine you are playing tennis and the score has reached 'six games all' in a Tie-break Set, so therefore the next game shall be a 'tie-break game', which is now to be played to decide the outcome of this set.  For _each point_ played in the tie-break game your chance of winning is |x| % (input as a |\u003chttps://au.mathworks.com/help/matlab/ref/uint8.html uint8\u003e|).  Given the \u003chttp://www.itftennis.com/procircuit/about-pro-circuit/rules-regulations.aspx ITF's scoring system for a \"tie-break game\" of tennis\u003e (excerpted below), please determine your likelihood of winning the tie-break game (output as a |\u003chttps://au.mathworks.com/help/matlab/ref/single.html single\u003e|).  \r\n\r\nNote that as |x| is taken to be the same for every point in this problem, it does not matter whether you are serving or not.  \r\n\r\nEXAMPLE\r\n\r\n x = uint8(40)\r\n chance = single(0.2125443387076924)\r\n\r\n-----\r\n\r\n*\"* During a tie-break game, points are scored “Zero”, “1”, “2”, “3”, etc. The first player/team to win seven points wins the “Game” and “Set”, provided there is a margin of two points over the opponent(s). If necessary, the tie-break game shall continue until this margin is achieved. *\"*\r\n\r\n-----\r\n\r\nSee also \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44502 Problem 44502. Anyone for tennis? Your chances of winning a (standard) game\u003e.","description_html":"\u003cp\u003eImagine you are playing tennis and the score has reached 'six games all' in a Tie-break Set, so therefore the next game shall be a 'tie-break game', which is now to be played to decide the outcome of this set.  For \u003ci\u003eeach point\u003c/i\u003e played in the tie-break game your chance of winning is \u003ctt\u003ex\u003c/tt\u003e % (input as a \u003ctt\u003e\u003ca href = \"https://au.mathworks.com/help/matlab/ref/uint8.html\"\u003euint8\u003c/a\u003e\u003c/tt\u003e).  Given the \u003ca href = \"http://www.itftennis.com/procircuit/about-pro-circuit/rules-regulations.aspx\"\u003eITF's scoring system for a \"tie-break game\" of tennis\u003c/a\u003e (excerpted below), please determine your likelihood of winning the tie-break game (output as a \u003ctt\u003e\u003ca href = \"https://au.mathworks.com/help/matlab/ref/single.html\"\u003esingle\u003c/a\u003e\u003c/tt\u003e).\u003c/p\u003e\u003cp\u003eNote that as \u003ctt\u003ex\u003c/tt\u003e is taken to be the same for every point in this problem, it does not matter whether you are serving or not.\u003c/p\u003e\u003cp\u003eEXAMPLE\u003c/p\u003e\u003cpre\u003e x = uint8(40)\r\n chance = single(0.2125443387076924)\u003c/pre\u003e\u003cp\u003e-----\u003c/p\u003e\u003cp\u003e\u003cb\u003e\"\u003c/b\u003e During a tie-break game, points are scored “Zero”, “1”, “2”, “3”, etc. The first player/team to win seven points wins the “Game” and “Set”, provided there is a margin of two points over the opponent(s). If necessary, the tie-break game shall continue until this margin is achieved. \u003cb\u003e\"\u003c/b\u003e\u003c/p\u003e\u003cp\u003e-----\u003c/p\u003e\u003cp\u003eSee also \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44502\"\u003eProblem 44502. Anyone for tennis? Your chances of winning a (standard) game\u003c/a\u003e.\u003c/p\u003e","function_template":"function chance = tiebreakGame(x)\r\n\r\n    % Your comments \r\n    \r\nend","test_suite":"%% Please do not try to hack the Test Suite.  \r\n% The Test Suite will be updated if inappropriate submissions are received.  \r\n% This includes hard-coded (pre-calculated, externally calculated, manually calculated) 'solutions'.\r\n\r\n% EDIT (2019-06-24).  Anti-hacking provision\r\n% Ensure builtin function will be called.  (Probably only the second of these will work.)  \r\n! del fileread.m\r\n! rm -v fileread.m\r\n% Disallow certain words  \r\nRE = regexp(fileread('tiebreakGame.m'), '\\w+', 'match');\r\ntabooWords = {'ans', 'assert', 'freepass'};\r\ntestResult = cellfun( @(z) ismember(z, tabooWords), RE );\r\nmsg = ['Please do not do that in your code!' char([10 13]) ...\r\n    'Found: ' strjoin(RE(testResult)) '.' char([10 13]) ...\r\n    'Banned word.' char([10 13])];\r\nassert(~any(  cellfun( @(z) ismember(z, tabooWords), RE )  ), msg)\r\n% END EDIT (2019-06-24)\r\n\r\nfiletext = fileread('tiebreakGame.m');\r\nvec = [5242178 5616877 7920095 4815022 1826772 5089792,5089793 1134259 2125443 3458492 4684486];\r\nmsg = 'Please do not hard-code your ''solution''.';\r\nassert( all( arrayfun(@(z) isempty(strfind(filetext, num2str(z))), vec) ) , msg )\r\n\r\n%% Test self-consistency:  \r\n% There are only two players, so the chances for each should add up to one.  \r\nassert( abs(tiebreakGame(100)+tiebreakGame(0) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(tiebreakGame(90)+tiebreakGame(10) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(tiebreakGame(80)+tiebreakGame(20) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(tiebreakGame(70)+tiebreakGame(30) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(tiebreakGame(60)+tiebreakGame(40) - 1)  \u003c 20 * eps(single(1)) )\r\nassert( abs(tiebreakGame(50)+tiebreakGame(50) - 1)  \u003c 20 * eps(single(1)) )\r\n\r\n%%\r\nx = uint8(50);\r\ny_correct = 0.50;\r\nassert( isequal(tiebreakGame(x), y_correct) )\r\n\r\n%%\r\nx = uint8(0);\r\ny_correct = 0;\r\nassert( isequal(tiebreakGame(x), y_correct) )\r\n\r\n%%\r\nx = uint8(100);\r\ny_correct = 1;\r\nassert( isequal(tiebreakGame(x), y_correct) )\r\n\r\n%%\r\nx = uint8(5);\r\ny_correct = 0.0000005242178465;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(10);\r\ny_correct = 0.0000561687707317;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(15);\r\ny_correct = 0.0007920095157735;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(20);\r\ny_correct = 0.0048150226823529;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(25);\r\ny_correct = 0.0182677268981934;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(30);\r\ny_correct = 0.0508979303379310;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(35);\r\ny_correct = 0.1134259300865006;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(40);\r\ny_correct = 0.2125443387076924;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(45);\r\ny_correct = 0.3458492328206313;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%%\r\nx = uint8(49);\r\ny_correct = 0.4684486239083455;\r\nassert( abs( tiebreakGame(x) - y_correct ) \u003c 10 * eps(single(y_correct)) )\r\n\r\n%% Test adherence to instructions\r\nfor i = 1:5\r\n    x = uint8( randi(100) );\r\n    assert( isequal(class(tiebreakGame(x)), 'single') )\r\nend;\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":64439,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":4,"test_suite_updated_at":"2019-07-02T13:20:57.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-18T10:19:54.000Z","updated_at":"2019-07-02T13:20:57.000Z","published_at":"2018-01-18T10:57:34.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eImagine you are playing tennis and the score has reached 'six games all' in a Tie-break Set, so therefore the next game shall be a 'tie-break game', which is now to be played to decide the outcome of this set. For\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eeach point\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e played in the tie-break game your chance of winning 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e % (input as 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://au.mathworks.com/help/matlab/ref/uint8.html\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003euint8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e). Given 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.itftennis.com/procircuit/about-pro-circuit/rules-regulations.aspx\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eITF's scoring system for a \\\"tie-break game\\\" of tennis\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (excerpted below), please determine your likelihood of winning the tie-break game (output as 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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://au.mathworks.com/help/matlab/ref/single.html\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esingle\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\u003eNote that as\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\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is taken to be the same for every point in this problem, it does not matter whether you are serving 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEXAMPLE\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x = uint8(40)\\n chance = single(0.2125443387076924)]]\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\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\u003e\\\"\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e During a tie-break game, points are scored “Zero”, “1”, “2”, “3”, etc. The first player/team to win seven points wins the “Game” and “Set”, provided there is a margin of two points over the opponent(s). If necessary, the tie-break game shall continue until this margin is achieved.\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\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\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=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44502\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44502. Anyone for tennis? Your chances of winning a (standard) game\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":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":42685,"title":"Cody meets Xiangqi: foresee the unseen (Part 2)","description":"This is the second part of the Xiangqi series. The first part in this series is: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42674-cody-meets-xiangqi-foresee-the-unseen Cody meets Xiangqi: foresee the unseen (Part 1)\u003e\r\n\r\nBeing increasingly interested in \u003chttps://en.wikipedia.org/wiki/Xiangqi Xiangqi\u003e (a.k.a., *Chinese Chess*), Mr. Cody has designed a new Xiangqi match for \u003chttps://en.wikipedia.org/wiki/Xiang_Yu Xiang Yu\u003e and \u003chttps://de.wikipedia.org/wiki/Han_Gaozu Liu Bang\u003e by taking into account the likelihood of tie games. The new rule is described as follows:\r\n\r\nOnce\r\n\r\n   1) Xiang Yu wins Na games consecutively,\r\n   2) Liu Bang wins Nb games consecutively, \r\n   3) No ties occur consecutively, \r\n\r\n*whichever comes first*, Mr. Cody announces the outcome accordingly as follows:\r\n\r\n   1) Xiang Yu is the final winner,\r\n   2) Liu Bang is the final winner, \r\n   3) They end up with a final draw.\r\n\r\nAgain, Cody asks us --- active Cody players --- to foresee the outcome of this unseen match using Monte Carlo simulations. Our task is to write the following function\r\n\r\n                         [Pa, Pb, Pc] = Xiangqi2(a, b, Na, Nb, Nc)\r\n\r\nwhere \r\n\r\n* a: the probability that Xiang Yu wins one individual game\r\n* b: the probability that Liu Bang wins one individual game\r\n* Na: # of consecutive wins required for Xiang Yu to become the final winner\r\n* Nb: # of consecutive wins required for Liu Bang to become the final winner\r\n* Nc: # of consecutive ties required to result in a final draw\r\n* Pa: the probability that Xiang Yu wins the match\r\n* Pb: the probability that Liu Bang wins the match\r\n* Pc: the probability of a final draw\r\n\r\nThe main focus of this problem is on *Monte Carlo simulations*, rather than analytical approaches. Your provided solution Xiangqi2.m will be checked by a P-file EvaluateSolution.p, which mainly does 3 things as follows:\r\n\r\n1) Call your function [Pa, Pb, Pc] = Xiangqi2(a, b, Na, Nb, Nc) and then Check if the result P = [Pa, Pb, Pc] is within tolerance of its expected value Q. That is, If norm(P - Q) \u003c tol holds, it means that your solution is accurate enough. If this does not hold, your solution will be rejected. \r\n\r\n2) Check if your solution is based on *pure Monte Carlo simulations* or *analytical approaches*. If it is based on analytical approaches (i.e., using analytical expressions to directly compute the probabilities), then your solution will be rejected. EvaluateSolution.p accomplishes this goal by exploiting a combination of distinct features possessed by analytical solutions, but are generally not shared by Monte Carlo simulations. \r\n\r\n3) If your solution passes the above two checks, then the score of your solution will be determined based on the speed of your code. The faster your solution is, the smaller score you get. \r\n\r\nIf you have any concerns or suggestions on this problem, please feel free to leave me a comment. Thanks. \r\n\r\n ","description_html":"\u003cp\u003eThis is the second part of the Xiangqi series. The first part in this series is: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42674-cody-meets-xiangqi-foresee-the-unseen\"\u003eCody meets Xiangqi: foresee the unseen (Part 1)\u003c/a\u003e\u003c/p\u003e\u003cp\u003eBeing increasingly interested in \u003ca href = \"https://en.wikipedia.org/wiki/Xiangqi\"\u003eXiangqi\u003c/a\u003e (a.k.a., \u003cb\u003eChinese Chess\u003c/b\u003e), Mr. Cody has designed a new Xiangqi match for \u003ca href = \"https://en.wikipedia.org/wiki/Xiang_Yu\"\u003eXiang Yu\u003c/a\u003e and \u003ca href = \"https://de.wikipedia.org/wiki/Han_Gaozu\"\u003eLiu Bang\u003c/a\u003e by taking into account the likelihood of tie games. The new rule is described as follows:\u003c/p\u003e\u003cp\u003eOnce\u003c/p\u003e\u003cpre\u003e   1) Xiang Yu wins Na games consecutively,\r\n   2) Liu Bang wins Nb games consecutively, \r\n   3) No ties occur consecutively, \u003c/pre\u003e\u003cp\u003e\u003cb\u003ewhichever comes first\u003c/b\u003e, Mr. Cody announces the outcome accordingly as follows:\u003c/p\u003e\u003cpre\u003e   1) Xiang Yu is the final winner,\r\n   2) Liu Bang is the final winner, \r\n   3) They end up with a final draw.\u003c/pre\u003e\u003cp\u003eAgain, Cody asks us --- active Cody players --- to foresee the outcome of this unseen match using Monte Carlo simulations. Our task is to write the following function\u003c/p\u003e\u003cpre\u003e                         [Pa, Pb, Pc] = Xiangqi2(a, b, Na, Nb, Nc)\u003c/pre\u003e\u003cp\u003ewhere\u003c/p\u003e\u003cul\u003e\u003cli\u003ea: the probability that Xiang Yu wins one individual game\u003c/li\u003e\u003cli\u003eb: the probability that Liu Bang wins one individual game\u003c/li\u003e\u003cli\u003eNa: # of consecutive wins required for Xiang Yu to become the final winner\u003c/li\u003e\u003cli\u003eNb: # of consecutive wins required for Liu Bang to become the final winner\u003c/li\u003e\u003cli\u003eNc: # of consecutive ties required to result in a final draw\u003c/li\u003e\u003cli\u003ePa: the probability that Xiang Yu wins the match\u003c/li\u003e\u003cli\u003ePb: the probability that Liu Bang wins the match\u003c/li\u003e\u003cli\u003ePc: the probability of a final draw\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe main focus of this problem is on \u003cb\u003eMonte Carlo simulations\u003c/b\u003e, rather than analytical approaches. Your provided solution Xiangqi2.m will be checked by a P-file EvaluateSolution.p, which mainly does 3 things as follows:\u003c/p\u003e\u003cp\u003e1) Call your function [Pa, Pb, Pc] = Xiangqi2(a, b, Na, Nb, Nc) and then Check if the result P = [Pa, Pb, Pc] is within tolerance of its expected value Q. That is, If norm(P - Q) \u0026lt; tol holds, it means that your solution is accurate enough. If this does not hold, your solution will be rejected.\u003c/p\u003e\u003cp\u003e2) Check if your solution is based on \u003cb\u003epure Monte Carlo simulations\u003c/b\u003e or \u003cb\u003eanalytical approaches\u003c/b\u003e. If it is based on analytical approaches (i.e., using analytical expressions to directly compute the probabilities), then your solution will be rejected. EvaluateSolution.p accomplishes this goal by exploiting a combination of distinct features possessed by analytical solutions, but are generally not shared by Monte Carlo simulations.\u003c/p\u003e\u003cp\u003e3) If your solution passes the above two checks, then the score of your solution will be determined based on the speed of your code. The faster your solution is, the smaller score you get.\u003c/p\u003e\u003cp\u003eIf you have any concerns or suggestions on this problem, please feel free to leave me a comment. Thanks.\u003c/p\u003e","function_template":"function [Pa, Pb, Pc] = Xiangqi2(a, b, Na, Nb, Nc)\r\n% a: the probability that Xiang Yu wins one individual game\r\n% b: the probability that Liu Bang wins one individual game\r\n% Na: # of consecutive wins required for Xiang Yu to become the final winner\r\n% Nb: # of consecutive wins required for Liu Bang to become the final winner\r\n% Nc: # of consecutive ties required to result in a final draw\r\n% Pa: the probability that Xiang Yu wins the match\r\n% Pb: the probability that Liu Bang wins the match\r\n% Pc: the probability of a final draw\r\n    Pa = ;\r\n    Pb = ;\r\n    Pc = ;\r\nend","test_suite":"%%\r\n% Thanks to Alfonso Nieto-Castanon\r\nurlwrite('https://sites.google.com/a/alfnie.com/alfnie/software/SetSolutionScore.p?attredirects=0\u0026amp;d=1','SetSolutionScore.p');\r\nrehash path;\r\n\r\n%%\r\nfh = fopen('EvaluateSolution.p','wb');\r\nfwrite(fh, hex2dec(reshape('7630312E30307630302E3030000C701C97F61FB1000002D5000001CF000004E73DD68930A391F7C60A534B45A03EAF72EB08941F39EE01BF25BAE04DF43CF342FC1A763DF6B8F26BBED0BD4F2ABBB5927B1EEBAE8795E487F6E4EF2737CBB6646BC4DF145E14664B3A4DACCD7CB01C4EC2328AD76F196231D2CA02CDC2B15466FBA5BDDF9E6C0E5DE12CF07B2AAA50BD2F04FFB92E9BECBE232E01031340A8EDCA5C10DAC01BBE43685ED0AB79D9C6F2A090FB4E0E75CAA236D3D73AD659E0705C42792BC77D85951B2FC49DE856FB97AFD74C1DB66C874EDF5517BCFA14C6706CA5E61DE60F2771B64F6D634B858A1A30AD7C49778534CCCE7551C637DC53846B02140046F729C5EB2DC9C65F16C2FC4F34EA9F03A2056B8218ACAB9A9A8BC5DC8F2F3312740F86626ABA38E00903CE76846DEE175BEE04DC0815E050E4CD95BA8E5BD27A0B57F2413B71A0E4837FB0F86328AA82732C584F1F55C6CCD79CBC69D052011BA93357AAE3568E0086F159C083D665645A38584955283925F900254A6562F0C755323C40805328D04F27FD863E8B774B52E27FC3AA30CE689AC57DEFEE274DBBC2A4D9D320CF19AD873AA0AE806721EE78496F7ADA99EA48060F26FDEE7ED5E9F85B27F79AE176A6E8EAC4DD5127299122FF88139BC4B56A2ED3C5338A72676C4C99AD6DEBCD8BB5EB09',2,[]).')); rehash path; fclose(fh);\r\n\r\n%%\r\nfid = fopen('Xiangqi2.m');\r\ndelim = {' ', '\\n', ',', '.', ';', '''', '@', '+', '-', '*', '/', '\\', '^', '\u003e', '\u003c', '=', '\u0026', '|', '~', '{', '}', '[', ']', '(', ')'};\r\nfile = textscan(fid, '%s', 'CommentStyle', '%', 'MultipleDelimsAsOne', 1, 'Delimiter', delim); fclose(fid); \r\nassert(~any(ismember({'rng','RandStream','seed','state','twister','shufle','default'},file{1})));\r\n\r\n%%\r\na = 0; b = 0; Na = 2; Nb = 3; Nc = 2; tol = 1e-6;\r\nEvaluateSolution(a, b, Na, Nb, Nc, tol); \r\n\r\n%%\r\na = 0; b = 1; Na = 1; Nb = 2; Nc = 1; tol = 1e-6;\r\nEvaluateSolution(a, b, Na, Nb, Nc, tol); \r\n\r\n%%\r\na = 1; b = 0; Na = 3; Nb = 2; Nc = 1; tol = 1e-6;\r\nEvaluateSolution(a, b, Na, Nb, Nc, tol); \r\n\r\n%%\r\na = 0.15; b = 0.85; Na = 4; Nb = 2; Nc = 1; tol = 1e-4;\r\nEvaluateSolution(a, b, Na, Nb, Nc, tol);\r\n\r\n%%\r\na = 0.9; b = 0; Na = 3; Nb = 1; Nc = 2; tol = 1e-3;\r\nEvaluateSolution(a, b, Na, Nb, Nc, tol);\r\n\r\n%%\r\na = 0.65; b = 0.3; Na = 3; Nb = 2; Nc = 2; tol = 1e-3;\r\nEvaluateSolution(a, b, Na, Nb, Nc, tol);\r\n\r\n%%\r\nNa = 3; Nb = 2; Nc = 1; tol = 2e-3; \r\np = sort(rand(2,30)); \r\np = sort([p(1,:);diff(p);1-p(2,:)]);\r\nfor k = size(p,2):-1:1\r\n    a = p(3,k); b = p(2,k);\r\n    score(k) = EvaluateSolution(a, b, Na, Nb, Nc, tol);    \r\nend\r\nSetSolutionScore(round(mean(score)));","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":5,"test_suite_updated_at":"2015-11-12T00:41:35.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2015-11-08T20:51:55.000Z","updated_at":"2015-11-12T03:39:15.000Z","published_at":"2015-11-10T00:22:37.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 the second part of the Xiangqi series. The first part in this series is:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42674-cody-meets-xiangqi-foresee-the-unseen\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody meets Xiangqi: foresee the unseen (Part 1)\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\u003eBeing increasingly interested in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Xiangqi\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eXiangqi\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (a.k.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\u003eChinese Chess\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e), Mr. Cody has designed a new Xiangqi match for\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Xiang_Yu\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eXiang Yu\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://de.wikipedia.org/wiki/Han_Gaozu\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eLiu Bang\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e by taking into account the likelihood of tie games. The new rule is described as follows:\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\u003eOnce\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   1) Xiang Yu wins Na games consecutively,\\n   2) Liu Bang wins Nb games consecutively, \\n   3) No ties occur consecutively,]]\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\u003ewhichever comes first\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, Mr. Cody announces the outcome accordingly as follows:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   1) Xiang Yu is the final winner,\\n   2) Liu Bang is the final winner, \\n   3) They end up with a final draw.]]\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\u003eAgain, Cody asks us --- active Cody players --- to foresee the outcome of this unseen match using Monte Carlo simulations. Our task is to write the following 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[                         [Pa, Pb, Pc] = Xiangqi2(a, b, Na, Nb, Nc)]]\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\u003ewhere\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: the probability that Xiang Yu wins one individual game\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\u003eb: the probability that Liu Bang wins one individual game\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\u003eNa: # of consecutive wins required for Xiang Yu to become the final winner\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\u003eNb: # of consecutive wins required for Liu Bang to become the final winner\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\u003eNc: # of consecutive ties required to result in a final draw\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\u003ePa: the probability that Xiang Yu wins the match\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\u003ePb: the probability that Liu Bang wins the match\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\u003ePc: the probability of a final draw\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 main focus of this problem is on\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\u003eMonte Carlo simulations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, rather than analytical approaches. Your provided solution Xiangqi2.m will be checked by a P-file EvaluateSolution.p, which mainly does 3 things as follows:\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) Call your function [Pa, Pb, Pc] = Xiangqi2(a, b, Na, Nb, Nc) and then Check if the result P = [Pa, Pb, Pc] is within tolerance of its expected value Q. That is, If norm(P - Q) \u0026lt; tol holds, it means that your solution is accurate enough. If this does not hold, your solution will be rejected.\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) Check if your solution is based on\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\u003epure Monte Carlo simulations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eanalytical approaches\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. If it is based on analytical approaches (i.e., using analytical expressions to directly compute the probabilities), then your solution will be rejected. EvaluateSolution.p accomplishes this goal by exploiting a combination of distinct features possessed by analytical solutions, but are generally not shared by Monte Carlo simulations.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e3) If your solution passes the above two checks, then the score of your solution will be determined based on the speed of your code. The faster your solution is, the smaller score you 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf you have any concerns or suggestions on this problem, please feel free to leave me a comment. Thanks.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"tag:\"probability\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"probability\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"probability\"","","\"","probability","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f03d365b548\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f03d365b408\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f03d365aaa8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f03d365b7c8\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f03d365b728\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f03d365b688\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f03d365b5e8\u003e":"tag:\"probability\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f03d365b5e8\u003e":"tag:\"probability\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"cody-search","password":"78X075ddcV44","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"probability\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"probability\"","","\"","probability","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f03d365b548\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f03d365b408\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f03d365aaa8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f03d365b7c8\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f03d365b728\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f03d365b688\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f03d365b5e8\u003e":"tag:\"probability\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f03d365b5e8\u003e":"tag:\"probability\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":60956,"difficulty_rating":"easy"},{"id":58688,"difficulty_rating":"easy"},{"id":44005,"difficulty_rating":"easy"},{"id":44254,"difficulty_rating":"easy"},{"id":48945,"difficulty_rating":"easy"},{"id":44272,"difficulty_rating":"easy"},{"id":700,"difficulty_rating":"easy"},{"id":510,"difficulty_rating":"easy"},{"id":2770,"difficulty_rating":"easy"},{"id":1268,"difficulty_rating":"easy"},{"id":2030,"difficulty_rating":"easy"},{"id":1287,"difficulty_rating":"easy-medium"},{"id":43126,"difficulty_rating":"easy-medium"},{"id":52110,"difficulty_rating":"easy-medium"},{"id":2267,"difficulty_rating":"easy-medium"},{"id":43166,"difficulty_rating":"easy-medium"},{"id":44315,"difficulty_rating":"easy-medium"},{"id":2591,"difficulty_rating":"easy-medium"},{"id":53004,"difficulty_rating":"easy-medium"},{"id":3006,"difficulty_rating":"easy-medium"},{"id":57620,"difficulty_rating":"easy-medium"},{"id":1182,"difficulty_rating":"easy-medium"},{"id":1267,"difficulty_rating":"easy-medium"},{"id":42615,"difficulty_rating":"easy-medium"},{"id":2356,"difficulty_rating":"easy-medium"},{"id":1159,"difficulty_rating":"easy-medium"},{"id":52323,"difficulty_rating":"medium"},{"id":42670,"difficulty_rating":"medium"},{"id":2995,"difficulty_rating":"medium"},{"id":1272,"difficulty_rating":"medium"},{"id":597,"difficulty_rating":"medium"},{"id":42674,"difficulty_rating":"medium"},{"id":44288,"difficulty_rating":"medium"},{"id":44630,"difficulty_rating":"medium"},{"id":226,"difficulty_rating":"medium"},{"id":45389,"difficulty_rating":"medium"},{"id":42503,"difficulty_rating":"medium-hard"},{"id":1260,"difficulty_rating":"medium-hard"},{"id":3009,"difficulty_rating":"medium-hard"},{"id":44885,"difficulty_rating":"hard"},{"id":44502,"difficulty_rating":"hard"},{"id":44503,"difficulty_rating":"hard"},{"id":331,"difficulty_rating":"hard"},{"id":42685,"difficulty_rating":"unrated"}]}}