{"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":1067,"title":"The Dark Side of the Die","description":"It is well-known that opposite sides of a classic hexahedral die add to 7. Given a vector of dice rolls, calculate the sum of the hidden face. That is, the sum of the values opposite the rolled value.\r\n\r\nFor example, if we roll a 2 and then a 6, we calculate that the opposite side of the dice were 5 and 1. Therefore, the answer is 6. This can also be calculated another way: since we know we rolled 2 dice, the total sum of the front and back faces of the dice must be 14 (7x2). If we then subtract the sum of the rolled values (2+6=8) from our total sum, we get the correct final answer (14-8=6)!","description_html":"\u003cp\u003eIt is well-known that opposite sides of a classic hexahedral die add to 7. Given a vector of dice rolls, calculate the sum of the hidden face. That is, the sum of the values opposite the rolled value.\u003c/p\u003e\u003cp\u003eFor example, if we roll a 2 and then a 6, we calculate that the opposite side of the dice were 5 and 1. Therefore, the answer is 6. This can also be calculated another way: since we know we rolled 2 dice, the total sum of the front and back faces of the dice must be 14 (7x2). If we then subtract the sum of the rolled values (2+6=8) from our total sum, we get the correct final answer (14-8=6)!\u003c/p\u003e","function_template":"function darksum = dark_dice(rolls)\r\n  darksum = 7;\r\nend","test_suite":"%%\r\nassert(isequal(dark_dice(5),2))\r\n\r\n%%\r\nassert(isequal(dark_dice([5 1]),8))\r\n\r\n%%\r\nassert(isequal(dark_dice([3 4 3]),11))\r\n\r\n%%\r\nassert(isequal(dark_dice([4 4 2 3]),15))\r\n\r\n%%\r\nassert(isequal(dark_dice([1 6 2 1 3]),22))\r\n\r\n%%\r\nassert(isequal(dark_dice([2 3 3 6 6 1]),21))\r\n\r\n%%\r\nassert(isequal(dark_dice([5 2 3 4 6 3 6]),20))\r\n\r\n%%\r\nassert(isequal(dark_dice([2 5 4 4 5 4 2 1]),29))\r\n\r\n%%\r\nassert(isequal(dark_dice([6 2 1 4 6 5 2 3 3]),31))\r\n\r\n%%\r\nassert(isequal(dark_dice([6 1 6 4 3 2 3 3 1 4]),37))\r\n\r\n%%\r\nassert(isequal(dark_dice([2 3 4 2 2 4 2 5 6 5 3]),39))\r\n\r\n%%\r\nassert(isequal(dark_dice([4 1 6 6 5 2 4 1 3 2 1 2]),47))\r\n\r\n%%\r\nassert(isequal(dark_dice([3 1 4 3 5 5 4 1 1 2 4 4 3]),51))\r\n\r\n%%\r\nassert(isequal(dark_dice([5 5 6 4 2 1 4 5 3 1 2 1 2 3]),54))\r\n\r\n%%\r\nassert(isequal(dark_dice([4 3 6 4 6 4 6 2 5 2 5 5 1 2 2]),48))\r\n\r\n%%\r\nassert(isequal(dark_dice([5 6 3 5 5 1 4 3 6 1 3 3 3 5 2 5]),52))\r\n\r\n%%\r\nassert(isequal(dark_dice([3 1 2 5 3 1 3 4 2 5 2 6 2 5 2 2 1]),70))\r\n\r\n%%\r\nassert(isequal(dark_dice([4 5 4 3 4 4 5 4 6 2 5 2 1 4 3 3 4 5]),58))\r\n\r\n%%\r\nassert(isequal(dark_dice([3 4 3 6 5 2 4 4 4 6 2 2 1 6 4 3 4 4 4]),62))\r\n\r\n%%\r\nassert(isequal(dark_dice([4 5 4 6 2 1 1 1 3 3 3 5 4 5 6 6 2 1 5 1]),72))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":134,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":144,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-11-27T06:30:17.000Z","updated_at":"2026-02-18T09:47:04.000Z","published_at":"2012-12-05T06:26: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\u003eIt is well-known that opposite sides of a classic hexahedral die add to 7. Given a vector of dice rolls, calculate the sum of the hidden face. That is, the sum of the values opposite the rolled value.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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, if we roll a 2 and then a 6, we calculate that the opposite side of the dice were 5 and 1. Therefore, the answer is 6. This can also be calculated another way: since we know we rolled 2 dice, the total sum of the front and back faces of the dice must be 14 (7x2). If we then subtract the sum of the rolled values (2+6=8) from our total sum, we get the correct final answer (14-8=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":42381,"title":"Dice roll - lateral faces","description":"For this problem, you will be provided with the values of a dice roll (regular six-sided dice). The number of dice will be at least one. Your function should return the sum of the lateral faces of the dice. See the test suite for examples.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 42px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 21px; transform-origin: 407px 21px; vertical-align: baseline; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 377px 8px; transform-origin: 377px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor this problem, you will be provided with the values of a dice roll (regular six-sided dice). The number of dice will be at least one. Your function should return the sum of the lateral faces of the dice. See the test suite for examples.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = dice_roll_lateral_faces(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = sum([2 3 4 5]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = 2;\r\ny_correct = sum([1 3 4 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = 3;\r\ny_correct = sum([1 2 5 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = 4;\r\ny_correct = sum([1 2 5 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = sum([1 3 4 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = 6;\r\ny_correct = sum([2 3 4 5]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = [1,3];\r\ny_correct = sum([2 3 4 5  1 2 5 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = [4,4];\r\ny_correct = sum([1 2 5 6  1 2 5 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = [6,4,3];\r\ny_correct = sum([2 3 4 5  1 2 5 6  1 2 5 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = [5,5,2];\r\ny_correct = sum([1 3 4 6  1 3 4 6  1 3 4 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = [3,1,6];\r\ny_correct = sum([1 2 5 6  2 3 4 5  2 3 4 5]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = [5,4,3];\r\ny_correct = sum([1 3 4 6  1 2 5 6  1 2 5 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = [3,1,2,6,1,5];\r\ny_correct = sum([1 2 5 6  2 3 4 5  1 3 4 6  2 3 4 5  2 3 4 5  1 3 4 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":45,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-06-16T16:59:37.000Z","updated_at":"2026-03-02T15:13:47.000Z","published_at":"2015-06-16T16:59: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\u003eFor this problem, you will be provided with the values of a dice roll (regular six-sided dice). The number of dice will be at least one. Your function should return the sum of the lateral faces of the dice. See the test suite for examples.\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":42380,"title":"Dice roll - opposite faces","description":"For this problem, you will be provided with the values of a dice roll (regular six-sided dice). The number of dice will be at least one. Your function should return the values on the opposite faces of the dice and in the same order. See the test suite for examples.","description_html":"\u003cp\u003eFor this problem, you will be provided with the values of a dice roll (regular six-sided dice). The number of dice will be at least one. Your function should return the values on the opposite faces of the dice and in the same order. See the test suite for examples.\u003c/p\u003e","function_template":"function y = dice_roll_opposite_face(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 6;\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = 2;\r\ny_correct = 5;\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = 3;\r\ny_correct = 4;\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = 4;\r\ny_correct = 3;\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = 2;\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = 6;\r\ny_correct = 1;\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = 1:6;\r\ny_correct = 6:-1:1;\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = [6,4,3];\r\ny_correct = [1,3,4];\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = [5,5,2];\r\ny_correct = [2,2,5];\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = [3,1,6];\r\ny_correct = [4,6,1];\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = [5,4,3];\r\ny_correct = [2,3,4];\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = [3,1,2,6,1,5,4,6,1,3];\r\ny_correct = [4,6,5,1,6,2,3,1,6,4];\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = [1,6,1,5,5,6,1,3,2,5];\r\ny_correct = [6,1,6,2,2,1,6,4,5,2];\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = [3,6,2,2,1,1,6,4,4,1];\r\ny_correct = [4,1,5,5,6,6,1,3,3,6];\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":97,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-06-16T16:42:56.000Z","updated_at":"2026-03-04T15:36:22.000Z","published_at":"2015-06-16T16:42:56.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\u003eFor this problem, you will be provided with the values of a dice roll (regular six-sided dice). The number of dice will be at least one. Your function should return the values on the opposite faces of the dice and in the same order. See the test suite for examples.\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":2289,"title":"サイコロを作ろう","description":"1から6までの独立かつランダムな数値を返すような関数を作成しましょう。\r\n\r\n例：\r\n\r\n  \u003e\u003e [x1,x2] = rollDice();\r\n\r\nと入力すると\r\n\r\n  x1 = 5\r\n  x2 = 2\r\n\r\nのような解を返します。","description_html":"\u003cp\u003e1から6までの独立かつランダムな数値を返すような関数を作成しましょう。\u003c/p\u003e\u003cp\u003e例：\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e\u0026gt;\u0026gt; [x1,x2] = rollDice();\r\n\u003c/pre\u003e\u003cp\u003eと入力すると\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex1 = 5\r\nx2 = 2\r\n\u003c/pre\u003e\u003cp\u003eのような解を返します。\u003c/p\u003e","function_template":"function [x1 x2] = rollDice(x)\r\n  x1 = x;\r\n  x2 = x;\r\nend","test_suite":"%%\r\nx1 = zeros(1,6000);\r\nx2 = zeros(1,6000);\r\nfor ii = 1:6000\r\n    [x1(ii),x2(ii)] = rollDice();\r\nend\r\nnumCt = sum( bsxfun( @eq, x1, (1:6)' ), 2 ) + sum( bsxfun( @eq, x2, (1:6)' ), 2 );\r\nassert(all(round(numCt/200) == 10) \u0026\u0026 sum(numCt) == 12000)","published":true,"deleted":false,"likes_count":6,"comments_count":4,"created_by":11824,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":404,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":36,"created_at":"2014-04-16T07:43:57.000Z","updated_at":"2026-03-16T19:03:50.000Z","published_at":"2014-04-16T07:48: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\u003e1から6までの独立かつランダムな数値を返すような関数を作成しましょう。\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e例：\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[\u003e\u003e [x1,x2] = rollDice();]]\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=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[x1 = 5\\nx2 = 2]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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":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":53850,"title":"Backgammon #4 - Dice Probabilities","description":"Previous problems in this series have looked at how a backgammon board might be represented, and board positions manipulated and displayed. In this problem we take a break from looking at backgammon boards, and turn our attention to dice throws.\r\nBackgammon is played with two standard six-sided dice.\r\nSometimes it is necessary to understand the chances of obtaining a particular dice throw, for example when trying to determine the risks of leaving a blot (a single stone), or when considering whether to offer or accept a double. \r\nIn this problem you are given a 'required' throw from two dice as an input vector - for example if you need to throw a 3 and a 6, the input vector will be: \r\n[3,6]\r\nYou have to return the probablility (between 0 and 1) of obtaining such a throw.\r\nSometimes you only care about the value of one of the dice, so in that case the value of the other dice will be set to zero - for example if you need to throw at least one 2 on the two dice, and don't care what the other dice is, the input vector will be one of:\r\n[2,0], [0,2]\r\nAgain you have to return the probablility (between 0 and 1) of obtaining such a throw.\r\nIf the input is not a valid throw, such as:\r\n[0,0], [4,8], [-2,5]\r\nyou should return NaN.\r\nPrevious problem in series: Problem 53840. Backgammon #3 - Display a Board Position\r\nNext problem in series: Problem 53780. Backgammon #5 - Valid Move?\r\nRegexp cheats and other cheats are not appreciated and will be blocked if you use them.","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: 571.3px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 285.65px; transform-origin: 407px 285.65px; 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: 365.667px 7.75px; transform-origin: 365.667px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ePrevious problems in this series have looked at how a backgammon board might be represented, and board positions manipulated and displayed. In this problem we take a break from looking at backgammon boards, and turn our attention to dice throws.\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: 175.05px 7.75px; transform-origin: 175.05px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eBackgammon is played with two standard six-sided dice.\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: 361.742px 7.75px; transform-origin: 361.742px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSometimes it is necessary to understand the chances of obtaining a particular dice throw, for example when trying to determine the risks of leaving a blot (a single stone), or when considering whether to offer or accept a double. \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: 384px 7.75px; transform-origin: 384px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIn this problem you are given a 'required' throw from two dice as an input vector - for example if you need to throw a 3 and a 6, the input vector will be: \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: 19.25px 8.25px; tab-size: 4; transform-origin: 19.25px 8.25px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e[3,6]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 243.642px 7.75px; transform-origin: 243.642px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou have to return the probablility (between 0 and 1) of obtaining such a throw.\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: 377.667px 7.75px; transform-origin: 377.667px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSometimes you only care about the value of one of the dice, so in that case the value of the other dice will be set to zero - for example if you need to throw at least one 2 on the two dice, and don't care what the other dice is, the input vector will be one of:\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: 46.2px 8.25px; tab-size: 4; transform-origin: 46.2px 8.25px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e[2,0], [0,2]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 262.958px 7.75px; transform-origin: 262.958px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAgain you have to return the probablility (between 0 and 1) of obtaining such a throw.\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: 122.117px 7.75px; transform-origin: 122.117px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf the input is not a valid throw, such as:\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: 77px 8.25px; tab-size: 4; transform-origin: 77px 8.25px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e[0,0], [4,8], [-2,5]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 71.9667px 7.75px; transform-origin: 71.9667px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eyou should return NaN.\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: 86.3583px 7.75px; transform-origin: 86.3583px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ePrevious problem in series: \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/53840\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 53840. Backgammon #3 - Display a Board Position\u003c/span\u003e\u003c/span\u003e\u003c/a\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: 73.5167px 7.75px; transform-origin: 73.5167px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eNext problem in series: \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/53780\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 53780. Backgammon #5 - Valid Move?\u003c/span\u003e\u003c/span\u003e\u003c/a\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: 275.408px 7.75px; transform-origin: 275.408px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eRegexp cheats and other cheats are not appreciated and will be blocked if you use them.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function prob = diceprob(throw)\r\n    prob=1;\r\nend","test_suite":"%%\r\nthrow=[6,6];\r\nprob=diceprob(throw);\r\ncorrect=str2num(char([48,46,48,50,55,55,55,55,55,55,55,55,55,55,55,55,56]));\r\nassert(abs(correct-prob)\u003c0.00001);\r\n\r\n%%\r\nthrow=[3,4];\r\nprob=diceprob(throw);\r\ncorrect=str2num(char([48,46,48,53,53,53,53,53,53,53,53,53,53,53,53,53,54]));\r\nassert(abs(correct-prob)\u003c0.00001);\r\n\r\n%%\r\nthrow=[5,0];\r\nprob=diceprob(throw);\r\ncorrect=str2num(char([48,46,51,48,53,53,53,53,53,53,53,53,53,53,53,53,54]));\r\nassert(abs(correct-prob)\u003c0.00001);\r\n\r\n%%\r\nthrow=[0,1];\r\nprob=diceprob(throw);\r\ncorrect=str2num(char([48,46,51,48,53,53,53,53,53,53,53,53,53,53,53,53,54]));\r\nassert(abs(correct-prob)\u003c0.00001);\r\n\r\n%%\r\nthrow=[0,0];\r\nprob=diceprob(throw);\r\nassert(isnan(prob));\r\n\r\n%%\r\nthrow=[7,5];\r\nprob=diceprob(throw);\r\nassert(isnan(prob));\r\n\r\n%%\r\nthrow=[4,8];\r\nprob=diceprob(throw);\r\nassert(isnan(prob));\r\n\r\n%%\r\nthrow=[3,-1];\r\nprob=diceprob(throw);\r\nassert(isnan(prob));\r\n\r\n%%\r\ns=fileread('diceprob.m');\r\ny_correct=false;\r\nassert(isequal(sum(contains(s,'regexp')),y_correct),'Regexp is forbidden')\r\nassert(isequal(sum(contains(s,'assert')),y_correct),'Assert is forbidden')","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":437780,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":14,"test_suite_updated_at":"2022-01-18T11:30:27.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2022-01-12T19:50:23.000Z","updated_at":"2026-03-05T10:54:58.000Z","published_at":"2022-01-13T15:07:27.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\u003ePrevious problems in this series have looked at how a backgammon board might be represented, and board positions manipulated and displayed. In this problem we take a break from looking at backgammon boards, and turn our attention to dice throws.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBackgammon is played with two standard six-sided 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\u003eSometimes it is necessary to understand the chances of obtaining a particular dice throw, for example when trying to determine the risks of leaving a blot (a single stone), or when considering whether to offer or accept a double. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 problem you are given a 'required' throw from two dice as an input vector - for example if you need to throw a 3 and a 6, the input vector will be: \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[[3,6]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou have to return the probablility (between 0 and 1) of obtaining such a throw.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSometimes you only care about the value of one of the dice, so in that case the value of the other dice will be set to zero - for example if you need to throw at least one 2 on the two dice, and don't care what the other dice is, the input vector will be one of:\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[[2,0], [0,2]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAgain you have to return the probablility (between 0 and 1) of obtaining such a throw.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 the input is not a valid throw, such as:\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[[0,0], [4,8], [-2,5]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eyou should return NaN.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem in series: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/53840\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 53840. Backgammon #3 - Display a Board Position\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNext problem in series: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/53780\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 53780. Backgammon #5 - Valid Move?\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\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\u003eRegexp cheats and other cheats are not appreciated and will be blocked if you use them.\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":1719,"title":"Dice face matrix!","description":"This is dice simulator, but instead of making a random die number, you will receive an \"pre-rolled\" number in and spit out a matrix of 1 and 0 that looks like a dice face of the given number. So for example:\r\n\r\n  rollnum = 1;\r\n\r\nThen the output will be:\r\n\r\n  diceFace =\r\n  \r\n       0     0     0\r\n       0     1     0\r\n       0     0     0\r\n\r\nAnother example:\r\n\r\n  rollnum = 5;\r\n\r\nThen the output will be:\r\n\r\n  diceFace =\r\n  \r\n       1     0     1\r\n       0     1     0\r\n       1     0     1\r\nAnd so on for 1-6, well that is it!\r\nJust note the 1 and 0 are numbers not char's or strings...\r\nGood luck!","description_html":"\u003cp\u003eThis is dice simulator, but instead of making a random die number, you will receive an \"pre-rolled\" number in and spit out a matrix of 1 and 0 that looks like a dice face of the given number. So for example:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003erollnum = 1;\r\n\u003c/pre\u003e\u003cp\u003eThen the output will be:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ediceFace =\r\n\u003c/pre\u003e\u003cpre\u003e       0     0     0\r\n       0     1     0\r\n       0     0     0\u003c/pre\u003e\u003cp\u003eAnother example:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003erollnum = 5;\r\n\u003c/pre\u003e\u003cp\u003eThen the output will be:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ediceFace =\r\n\u003c/pre\u003e\u003cpre\u003e       1     0     1\r\n       0     1     0\r\n       1     0     1\r\nAnd so on for 1-6, well that is it!\r\nJust note the 1 and 0 are numbers not char's or strings...\r\nGood luck!\u003c/pre\u003e","function_template":"function diceFace = rollADie(rollnum)\r\n  diceFace = rollnum;\r\nend","test_suite":"%%\r\nrollnum = 1;\r\ndiceFace = [0 0 0; 0 1 0; 0 0 0];\r\nassert(isequal(rollADie(rollnum),diceFace))\r\n%%\r\nrollnum = 2;\r\ndiceFace = [0 0 1; 0 0 0; 1 0 0];\r\nassert(isequal(rollADie(rollnum),diceFace))\r\n%%\r\nrollnum = 3;\r\ndiceFace = [0 0 1; 0 1 0; 1 0 0];\r\nassert(isequal(rollADie(rollnum),diceFace))\r\n%%\r\nrollnum = 4;\r\ndiceFace = [1 0 1; 0 0 0; 1 0 1];\r\nassert(isequal(rollADie(rollnum),diceFace))\r\n%%\r\nrollnum = 5;\r\ndiceFace = [1 0 1; 0 1 0; 1 0 1];\r\nassert(isequal(rollADie(rollnum),diceFace))\r\n%%\r\nrollnum = 6;\r\ndiceFace = [1 0 1; 1 0 1; 1 0 1];\r\nassert(isequal(rollADie(rollnum),diceFace))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":15013,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":136,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":41,"created_at":"2013-07-16T15:48:23.000Z","updated_at":"2026-04-03T02:36:03.000Z","published_at":"2013-07-16T15:48:30.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is dice simulator, but instead of making a random die number, you will receive an \\\"pre-rolled\\\" number in and spit out a matrix of 1 and 0 that looks like a dice face of the given number. So for example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[rollnum = 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\u003eThen the output will be:\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[diceFace =\\n\\n       0     0     0\\n       0     1     0\\n       0     0     0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAnother example:\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[rollnum = 5;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThen the output will be:\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[diceFace =\\n\\n       1     0     1\\n       0     1     0\\n       1     0     1\\nAnd so on for 1-6, well that is it!\\nJust note the 1 and 0 are numbers not char's or strings...\\nGood luck!]]\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":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":174,"title":"Roll the Dice!","description":"Description\r\nReturn two random integers between 1 and 6, inclusive, to simulate rolling 2 dice.\r\nExample\r\n   [x1,x2] = rollDice();\r\n   x1 = 5;\r\n   x2 = 2;","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 152.312px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407.5px 76.1562px; transform-origin: 407.5px 76.1562px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eDescription\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn two random integers between 1 and 6, inclusive, to simulate rolling 2 dice.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eExample\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3125px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404.5px 30.6562px; transform-origin: 404.5px 30.6562px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e   [x1,x2] = rollDice();\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e   x1 = 5;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e   x2 = 2;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [x1,x2] = rollDice()\r\n  x1 = 1;\r\n  x2 = 1;\r\nend","test_suite":"%%\r\nfiletext = fileread('rollDice.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp');\r\nassert(~illegal)\r\n\r\n%%\r\nx1 = zeros(1,6000);\r\nx2 = zeros(1,6000);\r\nfor ii = 1:6000\r\n    [x1(ii),x2(ii)] = rollDice();\r\nend\r\nnumCt = sum( bsxfun( @eq, x1, (1:6)' ), 2 ) + sum( bsxfun( @eq, x2, (1:6)' ), 2 );\r\nassert(all(round(numCt/200) == 10) \u0026\u0026 sum(numCt) == 12000)\r\n","published":true,"deleted":false,"likes_count":62,"comments_count":21,"created_by":134,"edited_by":427930,"edited_at":"2024-08-01T11:35:52.000Z","deleted_by":null,"deleted_at":null,"solvers_count":10721,"test_suite_updated_at":"2012-01-30T07:51:11.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-01-30T07:38:01.000Z","updated_at":"2026-04-11T17:26:42.000Z","published_at":"2024-08-01T11:35:52.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eDescription\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn two random integers between 1 and 6, inclusive, to simulate rolling 2 dice.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   [x1,x2] = rollDice();\\n   x1 = 5;\\n   x2 = 2;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"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\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":1067,"title":"The Dark Side of the Die","description":"It is well-known that opposite sides of a classic hexahedral die add to 7. Given a vector of dice rolls, calculate the sum of the hidden face. That is, the sum of the values opposite the rolled value.\r\n\r\nFor example, if we roll a 2 and then a 6, we calculate that the opposite side of the dice were 5 and 1. Therefore, the answer is 6. This can also be calculated another way: since we know we rolled 2 dice, the total sum of the front and back faces of the dice must be 14 (7x2). If we then subtract the sum of the rolled values (2+6=8) from our total sum, we get the correct final answer (14-8=6)!","description_html":"\u003cp\u003eIt is well-known that opposite sides of a classic hexahedral die add to 7. Given a vector of dice rolls, calculate the sum of the hidden face. That is, the sum of the values opposite the rolled value.\u003c/p\u003e\u003cp\u003eFor example, if we roll a 2 and then a 6, we calculate that the opposite side of the dice were 5 and 1. Therefore, the answer is 6. This can also be calculated another way: since we know we rolled 2 dice, the total sum of the front and back faces of the dice must be 14 (7x2). If we then subtract the sum of the rolled values (2+6=8) from our total sum, we get the correct final answer (14-8=6)!\u003c/p\u003e","function_template":"function darksum = dark_dice(rolls)\r\n  darksum = 7;\r\nend","test_suite":"%%\r\nassert(isequal(dark_dice(5),2))\r\n\r\n%%\r\nassert(isequal(dark_dice([5 1]),8))\r\n\r\n%%\r\nassert(isequal(dark_dice([3 4 3]),11))\r\n\r\n%%\r\nassert(isequal(dark_dice([4 4 2 3]),15))\r\n\r\n%%\r\nassert(isequal(dark_dice([1 6 2 1 3]),22))\r\n\r\n%%\r\nassert(isequal(dark_dice([2 3 3 6 6 1]),21))\r\n\r\n%%\r\nassert(isequal(dark_dice([5 2 3 4 6 3 6]),20))\r\n\r\n%%\r\nassert(isequal(dark_dice([2 5 4 4 5 4 2 1]),29))\r\n\r\n%%\r\nassert(isequal(dark_dice([6 2 1 4 6 5 2 3 3]),31))\r\n\r\n%%\r\nassert(isequal(dark_dice([6 1 6 4 3 2 3 3 1 4]),37))\r\n\r\n%%\r\nassert(isequal(dark_dice([2 3 4 2 2 4 2 5 6 5 3]),39))\r\n\r\n%%\r\nassert(isequal(dark_dice([4 1 6 6 5 2 4 1 3 2 1 2]),47))\r\n\r\n%%\r\nassert(isequal(dark_dice([3 1 4 3 5 5 4 1 1 2 4 4 3]),51))\r\n\r\n%%\r\nassert(isequal(dark_dice([5 5 6 4 2 1 4 5 3 1 2 1 2 3]),54))\r\n\r\n%%\r\nassert(isequal(dark_dice([4 3 6 4 6 4 6 2 5 2 5 5 1 2 2]),48))\r\n\r\n%%\r\nassert(isequal(dark_dice([5 6 3 5 5 1 4 3 6 1 3 3 3 5 2 5]),52))\r\n\r\n%%\r\nassert(isequal(dark_dice([3 1 2 5 3 1 3 4 2 5 2 6 2 5 2 2 1]),70))\r\n\r\n%%\r\nassert(isequal(dark_dice([4 5 4 3 4 4 5 4 6 2 5 2 1 4 3 3 4 5]),58))\r\n\r\n%%\r\nassert(isequal(dark_dice([3 4 3 6 5 2 4 4 4 6 2 2 1 6 4 3 4 4 4]),62))\r\n\r\n%%\r\nassert(isequal(dark_dice([4 5 4 6 2 1 1 1 3 3 3 5 4 5 6 6 2 1 5 1]),72))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":134,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":144,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-11-27T06:30:17.000Z","updated_at":"2026-02-18T09:47:04.000Z","published_at":"2012-12-05T06:26: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\u003eIt is well-known that opposite sides of a classic hexahedral die add to 7. Given a vector of dice rolls, calculate the sum of the hidden face. That is, the sum of the values opposite the rolled value.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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, if we roll a 2 and then a 6, we calculate that the opposite side of the dice were 5 and 1. Therefore, the answer is 6. This can also be calculated another way: since we know we rolled 2 dice, the total sum of the front and back faces of the dice must be 14 (7x2). If we then subtract the sum of the rolled values (2+6=8) from our total sum, we get the correct final answer (14-8=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":42381,"title":"Dice roll - lateral faces","description":"For this problem, you will be provided with the values of a dice roll (regular six-sided dice). The number of dice will be at least one. Your function should return the sum of the lateral faces of the dice. See the test suite for examples.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 42px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 21px; transform-origin: 407px 21px; vertical-align: baseline; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 377px 8px; transform-origin: 377px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor this problem, you will be provided with the values of a dice roll (regular six-sided dice). The number of dice will be at least one. Your function should return the sum of the lateral faces of the dice. See the test suite for examples.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = dice_roll_lateral_faces(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = sum([2 3 4 5]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = 2;\r\ny_correct = sum([1 3 4 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = 3;\r\ny_correct = sum([1 2 5 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = 4;\r\ny_correct = sum([1 2 5 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = sum([1 3 4 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = 6;\r\ny_correct = sum([2 3 4 5]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = [1,3];\r\ny_correct = sum([2 3 4 5  1 2 5 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = [4,4];\r\ny_correct = sum([1 2 5 6  1 2 5 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = [6,4,3];\r\ny_correct = sum([2 3 4 5  1 2 5 6  1 2 5 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = [5,5,2];\r\ny_correct = sum([1 3 4 6  1 3 4 6  1 3 4 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = [3,1,6];\r\ny_correct = sum([1 2 5 6  2 3 4 5  2 3 4 5]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = [5,4,3];\r\ny_correct = sum([1 3 4 6  1 2 5 6  1 2 5 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n\r\n%%\r\nx = [3,1,2,6,1,5];\r\ny_correct = sum([1 2 5 6  2 3 4 5  1 3 4 6  2 3 4 5  2 3 4 5  1 3 4 6]);\r\nassert(isequal(dice_roll_lateral_faces(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":45,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-06-16T16:59:37.000Z","updated_at":"2026-03-02T15:13:47.000Z","published_at":"2015-06-16T16:59: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\u003eFor this problem, you will be provided with the values of a dice roll (regular six-sided dice). The number of dice will be at least one. Your function should return the sum of the lateral faces of the dice. See the test suite for examples.\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":42380,"title":"Dice roll - opposite faces","description":"For this problem, you will be provided with the values of a dice roll (regular six-sided dice). The number of dice will be at least one. Your function should return the values on the opposite faces of the dice and in the same order. See the test suite for examples.","description_html":"\u003cp\u003eFor this problem, you will be provided with the values of a dice roll (regular six-sided dice). The number of dice will be at least one. Your function should return the values on the opposite faces of the dice and in the same order. See the test suite for examples.\u003c/p\u003e","function_template":"function y = dice_roll_opposite_face(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 6;\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = 2;\r\ny_correct = 5;\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = 3;\r\ny_correct = 4;\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = 4;\r\ny_correct = 3;\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = 2;\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = 6;\r\ny_correct = 1;\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = 1:6;\r\ny_correct = 6:-1:1;\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = [6,4,3];\r\ny_correct = [1,3,4];\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = [5,5,2];\r\ny_correct = [2,2,5];\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = [3,1,6];\r\ny_correct = [4,6,1];\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = [5,4,3];\r\ny_correct = [2,3,4];\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = [3,1,2,6,1,5,4,6,1,3];\r\ny_correct = [4,6,5,1,6,2,3,1,6,4];\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = [1,6,1,5,5,6,1,3,2,5];\r\ny_correct = [6,1,6,2,2,1,6,4,5,2];\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n\r\n%%\r\nx = [3,6,2,2,1,1,6,4,4,1];\r\ny_correct = [4,1,5,5,6,6,1,3,3,6];\r\nassert(isequal(dice_roll_opposite_face(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":97,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-06-16T16:42:56.000Z","updated_at":"2026-03-04T15:36:22.000Z","published_at":"2015-06-16T16:42:56.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\u003eFor this problem, you will be provided with the values of a dice roll (regular six-sided dice). The number of dice will be at least one. Your function should return the values on the opposite faces of the dice and in the same order. See the test suite for examples.\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":2289,"title":"サイコロを作ろう","description":"1から6までの独立かつランダムな数値を返すような関数を作成しましょう。\r\n\r\n例：\r\n\r\n  \u003e\u003e [x1,x2] = rollDice();\r\n\r\nと入力すると\r\n\r\n  x1 = 5\r\n  x2 = 2\r\n\r\nのような解を返します。","description_html":"\u003cp\u003e1から6までの独立かつランダムな数値を返すような関数を作成しましょう。\u003c/p\u003e\u003cp\u003e例：\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e\u0026gt;\u0026gt; [x1,x2] = rollDice();\r\n\u003c/pre\u003e\u003cp\u003eと入力すると\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex1 = 5\r\nx2 = 2\r\n\u003c/pre\u003e\u003cp\u003eのような解を返します。\u003c/p\u003e","function_template":"function [x1 x2] = rollDice(x)\r\n  x1 = x;\r\n  x2 = x;\r\nend","test_suite":"%%\r\nx1 = zeros(1,6000);\r\nx2 = zeros(1,6000);\r\nfor ii = 1:6000\r\n    [x1(ii),x2(ii)] = rollDice();\r\nend\r\nnumCt = sum( bsxfun( @eq, x1, (1:6)' ), 2 ) + sum( bsxfun( @eq, x2, (1:6)' ), 2 );\r\nassert(all(round(numCt/200) == 10) \u0026\u0026 sum(numCt) == 12000)","published":true,"deleted":false,"likes_count":6,"comments_count":4,"created_by":11824,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":404,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":36,"created_at":"2014-04-16T07:43:57.000Z","updated_at":"2026-03-16T19:03:50.000Z","published_at":"2014-04-16T07:48: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\u003e1から6までの独立かつランダムな数値を返すような関数を作成しましょう。\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e例：\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[\u003e\u003e [x1,x2] = rollDice();]]\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=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[x1 = 5\\nx2 = 2]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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":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":53850,"title":"Backgammon #4 - Dice Probabilities","description":"Previous problems in this series have looked at how a backgammon board might be represented, and board positions manipulated and displayed. In this problem we take a break from looking at backgammon boards, and turn our attention to dice throws.\r\nBackgammon is played with two standard six-sided dice.\r\nSometimes it is necessary to understand the chances of obtaining a particular dice throw, for example when trying to determine the risks of leaving a blot (a single stone), or when considering whether to offer or accept a double. \r\nIn this problem you are given a 'required' throw from two dice as an input vector - for example if you need to throw a 3 and a 6, the input vector will be: \r\n[3,6]\r\nYou have to return the probablility (between 0 and 1) of obtaining such a throw.\r\nSometimes you only care about the value of one of the dice, so in that case the value of the other dice will be set to zero - for example if you need to throw at least one 2 on the two dice, and don't care what the other dice is, the input vector will be one of:\r\n[2,0], [0,2]\r\nAgain you have to return the probablility (between 0 and 1) of obtaining such a throw.\r\nIf the input is not a valid throw, such as:\r\n[0,0], [4,8], [-2,5]\r\nyou should return NaN.\r\nPrevious problem in series: Problem 53840. Backgammon #3 - Display a Board Position\r\nNext problem in series: Problem 53780. Backgammon #5 - Valid Move?\r\nRegexp cheats and other cheats are not appreciated and will be blocked if you use them.","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: 571.3px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 285.65px; transform-origin: 407px 285.65px; 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: 365.667px 7.75px; transform-origin: 365.667px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ePrevious problems in this series have looked at how a backgammon board might be represented, and board positions manipulated and displayed. In this problem we take a break from looking at backgammon boards, and turn our attention to dice throws.\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: 175.05px 7.75px; transform-origin: 175.05px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eBackgammon is played with two standard six-sided dice.\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: 361.742px 7.75px; transform-origin: 361.742px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSometimes it is necessary to understand the chances of obtaining a particular dice throw, for example when trying to determine the risks of leaving a blot (a single stone), or when considering whether to offer or accept a double. \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: 384px 7.75px; transform-origin: 384px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIn this problem you are given a 'required' throw from two dice as an input vector - for example if you need to throw a 3 and a 6, the input vector will be: \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: 19.25px 8.25px; tab-size: 4; transform-origin: 19.25px 8.25px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e[3,6]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 243.642px 7.75px; transform-origin: 243.642px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou have to return the probablility (between 0 and 1) of obtaining such a throw.\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: 377.667px 7.75px; transform-origin: 377.667px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSometimes you only care about the value of one of the dice, so in that case the value of the other dice will be set to zero - for example if you need to throw at least one 2 on the two dice, and don't care what the other dice is, the input vector will be one of:\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: 46.2px 8.25px; tab-size: 4; transform-origin: 46.2px 8.25px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e[2,0], [0,2]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 262.958px 7.75px; transform-origin: 262.958px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAgain you have to return the probablility (between 0 and 1) of obtaining such a throw.\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: 122.117px 7.75px; transform-origin: 122.117px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf the input is not a valid throw, such as:\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: 77px 8.25px; tab-size: 4; transform-origin: 77px 8.25px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e[0,0], [4,8], [-2,5]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 71.9667px 7.75px; transform-origin: 71.9667px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eyou should return NaN.\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: 86.3583px 7.75px; transform-origin: 86.3583px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ePrevious problem in series: \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/53840\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 53840. Backgammon #3 - Display a Board Position\u003c/span\u003e\u003c/span\u003e\u003c/a\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: 73.5167px 7.75px; transform-origin: 73.5167px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eNext problem in series: \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/53780\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 53780. Backgammon #5 - Valid Move?\u003c/span\u003e\u003c/span\u003e\u003c/a\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: 275.408px 7.75px; transform-origin: 275.408px 7.75px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eRegexp cheats and other cheats are not appreciated and will be blocked if you use them.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function prob = diceprob(throw)\r\n    prob=1;\r\nend","test_suite":"%%\r\nthrow=[6,6];\r\nprob=diceprob(throw);\r\ncorrect=str2num(char([48,46,48,50,55,55,55,55,55,55,55,55,55,55,55,55,56]));\r\nassert(abs(correct-prob)\u003c0.00001);\r\n\r\n%%\r\nthrow=[3,4];\r\nprob=diceprob(throw);\r\ncorrect=str2num(char([48,46,48,53,53,53,53,53,53,53,53,53,53,53,53,53,54]));\r\nassert(abs(correct-prob)\u003c0.00001);\r\n\r\n%%\r\nthrow=[5,0];\r\nprob=diceprob(throw);\r\ncorrect=str2num(char([48,46,51,48,53,53,53,53,53,53,53,53,53,53,53,53,54]));\r\nassert(abs(correct-prob)\u003c0.00001);\r\n\r\n%%\r\nthrow=[0,1];\r\nprob=diceprob(throw);\r\ncorrect=str2num(char([48,46,51,48,53,53,53,53,53,53,53,53,53,53,53,53,54]));\r\nassert(abs(correct-prob)\u003c0.00001);\r\n\r\n%%\r\nthrow=[0,0];\r\nprob=diceprob(throw);\r\nassert(isnan(prob));\r\n\r\n%%\r\nthrow=[7,5];\r\nprob=diceprob(throw);\r\nassert(isnan(prob));\r\n\r\n%%\r\nthrow=[4,8];\r\nprob=diceprob(throw);\r\nassert(isnan(prob));\r\n\r\n%%\r\nthrow=[3,-1];\r\nprob=diceprob(throw);\r\nassert(isnan(prob));\r\n\r\n%%\r\ns=fileread('diceprob.m');\r\ny_correct=false;\r\nassert(isequal(sum(contains(s,'regexp')),y_correct),'Regexp is forbidden')\r\nassert(isequal(sum(contains(s,'assert')),y_correct),'Assert is forbidden')","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":437780,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":14,"test_suite_updated_at":"2022-01-18T11:30:27.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2022-01-12T19:50:23.000Z","updated_at":"2026-03-05T10:54:58.000Z","published_at":"2022-01-13T15:07:27.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\u003ePrevious problems in this series have looked at how a backgammon board might be represented, and board positions manipulated and displayed. In this problem we take a break from looking at backgammon boards, and turn our attention to dice throws.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBackgammon is played with two standard six-sided 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\u003eSometimes it is necessary to understand the chances of obtaining a particular dice throw, for example when trying to determine the risks of leaving a blot (a single stone), or when considering whether to offer or accept a double. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 problem you are given a 'required' throw from two dice as an input vector - for example if you need to throw a 3 and a 6, the input vector will be: \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[[3,6]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou have to return the probablility (between 0 and 1) of obtaining such a throw.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSometimes you only care about the value of one of the dice, so in that case the value of the other dice will be set to zero - for example if you need to throw at least one 2 on the two dice, and don't care what the other dice is, the input vector will be one of:\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[[2,0], [0,2]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAgain you have to return the probablility (between 0 and 1) of obtaining such a throw.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 the input is not a valid throw, such as:\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[[0,0], [4,8], [-2,5]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eyou should return NaN.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePrevious problem in series: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/53840\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 53840. Backgammon #3 - Display a Board Position\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNext problem in series: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/53780\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 53780. Backgammon #5 - Valid Move?\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\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\u003eRegexp cheats and other cheats are not appreciated and will be blocked if you use them.\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":1719,"title":"Dice face matrix!","description":"This is dice simulator, but instead of making a random die number, you will receive an \"pre-rolled\" number in and spit out a matrix of 1 and 0 that looks like a dice face of the given number. So for example:\r\n\r\n  rollnum = 1;\r\n\r\nThen the output will be:\r\n\r\n  diceFace =\r\n  \r\n       0     0     0\r\n       0     1     0\r\n       0     0     0\r\n\r\nAnother example:\r\n\r\n  rollnum = 5;\r\n\r\nThen the output will be:\r\n\r\n  diceFace =\r\n  \r\n       1     0     1\r\n       0     1     0\r\n       1     0     1\r\nAnd so on for 1-6, well that is it!\r\nJust note the 1 and 0 are numbers not char's or strings...\r\nGood luck!","description_html":"\u003cp\u003eThis is dice simulator, but instead of making a random die number, you will receive an \"pre-rolled\" number in and spit out a matrix of 1 and 0 that looks like a dice face of the given number. So for example:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003erollnum = 1;\r\n\u003c/pre\u003e\u003cp\u003eThen the output will be:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ediceFace =\r\n\u003c/pre\u003e\u003cpre\u003e       0     0     0\r\n       0     1     0\r\n       0     0     0\u003c/pre\u003e\u003cp\u003eAnother example:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003erollnum = 5;\r\n\u003c/pre\u003e\u003cp\u003eThen the output will be:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ediceFace =\r\n\u003c/pre\u003e\u003cpre\u003e       1     0     1\r\n       0     1     0\r\n       1     0     1\r\nAnd so on for 1-6, well that is it!\r\nJust note the 1 and 0 are numbers not char's or strings...\r\nGood luck!\u003c/pre\u003e","function_template":"function diceFace = rollADie(rollnum)\r\n  diceFace = rollnum;\r\nend","test_suite":"%%\r\nrollnum = 1;\r\ndiceFace = [0 0 0; 0 1 0; 0 0 0];\r\nassert(isequal(rollADie(rollnum),diceFace))\r\n%%\r\nrollnum = 2;\r\ndiceFace = [0 0 1; 0 0 0; 1 0 0];\r\nassert(isequal(rollADie(rollnum),diceFace))\r\n%%\r\nrollnum = 3;\r\ndiceFace = [0 0 1; 0 1 0; 1 0 0];\r\nassert(isequal(rollADie(rollnum),diceFace))\r\n%%\r\nrollnum = 4;\r\ndiceFace = [1 0 1; 0 0 0; 1 0 1];\r\nassert(isequal(rollADie(rollnum),diceFace))\r\n%%\r\nrollnum = 5;\r\ndiceFace = [1 0 1; 0 1 0; 1 0 1];\r\nassert(isequal(rollADie(rollnum),diceFace))\r\n%%\r\nrollnum = 6;\r\ndiceFace = [1 0 1; 1 0 1; 1 0 1];\r\nassert(isequal(rollADie(rollnum),diceFace))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":15013,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":136,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":41,"created_at":"2013-07-16T15:48:23.000Z","updated_at":"2026-04-03T02:36:03.000Z","published_at":"2013-07-16T15:48:30.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is dice simulator, but instead of making a random die number, you will receive an \\\"pre-rolled\\\" number in and spit out a matrix of 1 and 0 that looks like a dice face of the given number. So for example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[rollnum = 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\u003eThen the output will be:\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[diceFace =\\n\\n       0     0     0\\n       0     1     0\\n       0     0     0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAnother example:\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[rollnum = 5;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThen the output will be:\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[diceFace =\\n\\n       1     0     1\\n       0     1     0\\n       1     0     1\\nAnd so on for 1-6, well that is it!\\nJust note the 1 and 0 are numbers not char's or strings...\\nGood luck!]]\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":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":174,"title":"Roll the Dice!","description":"Description\r\nReturn two random integers between 1 and 6, inclusive, to simulate rolling 2 dice.\r\nExample\r\n   [x1,x2] = rollDice();\r\n   x1 = 5;\r\n   x2 = 2;","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 152.312px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407.5px 76.1562px; transform-origin: 407.5px 76.1562px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eDescription\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn two random integers between 1 and 6, inclusive, to simulate rolling 2 dice.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eExample\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3125px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404.5px 30.6562px; transform-origin: 404.5px 30.6562px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e   [x1,x2] = rollDice();\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e   x1 = 5;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 0px; tab-size: 4; transform-origin: 0px 0px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e   x2 = 2;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [x1,x2] = rollDice()\r\n  x1 = 1;\r\n  x2 = 1;\r\nend","test_suite":"%%\r\nfiletext = fileread('rollDice.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp');\r\nassert(~illegal)\r\n\r\n%%\r\nx1 = zeros(1,6000);\r\nx2 = zeros(1,6000);\r\nfor ii = 1:6000\r\n    [x1(ii),x2(ii)] = rollDice();\r\nend\r\nnumCt = sum( bsxfun( @eq, x1, (1:6)' ), 2 ) + sum( bsxfun( @eq, x2, (1:6)' ), 2 );\r\nassert(all(round(numCt/200) == 10) \u0026\u0026 sum(numCt) == 12000)\r\n","published":true,"deleted":false,"likes_count":62,"comments_count":21,"created_by":134,"edited_by":427930,"edited_at":"2024-08-01T11:35:52.000Z","deleted_by":null,"deleted_at":null,"solvers_count":10721,"test_suite_updated_at":"2012-01-30T07:51:11.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-01-30T07:38:01.000Z","updated_at":"2026-04-11T17:26:42.000Z","published_at":"2024-08-01T11:35:52.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eDescription\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn two random integers between 1 and 6, inclusive, to simulate rolling 2 dice.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   [x1,x2] = rollDice();\\n   x1 = 5;\\n   x2 = 2;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"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\"}]}"}],"term":"tag:\"dice\"","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:\"dice\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"dice\"","","\"","dice","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f64e62326c8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f64e6232628\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f64e6231cc8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f64e6232948\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f64e62328a8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f64e6232808\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f64e6232768\u003e":"tag:\"dice\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f64e6232768\u003e":"tag:\"dice\""},"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:\"dice\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"dice\"","","\"","dice","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f64e62326c8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f64e6232628\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f64e6231cc8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f64e6232948\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f64e62328a8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f64e6232808\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f64e6232768\u003e":"tag:\"dice\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f64e6232768\u003e":"tag:\"dice\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":1067,"difficulty_rating":"easy"},{"id":42381,"difficulty_rating":"easy"},{"id":42380,"difficulty_rating":"easy"},{"id":2289,"difficulty_rating":"easy"},{"id":1287,"difficulty_rating":"easy-medium"},{"id":53850,"difficulty_rating":"easy-medium"},{"id":1719,"difficulty_rating":"easy-medium"},{"id":52110,"difficulty_rating":"easy-medium"},{"id":174,"difficulty_rating":"easy-medium"},{"id":44288,"difficulty_rating":"medium"}]}}