{"group":{"group":{"id":96932,"name":"CODY Bells 2025","lockable":false,"created_at":"2025-11-25T18:38:25.000Z","updated_at":"2026-04-26T00:14:02.000Z","description":"Coding competition. For more information and leaderboard please visit the Teams Channel or email brendanm@mathworks.com. Contest runs from 12/8/25 thru 12/18/25.","is_default":false,"created_by":2140854,"badge_id":62,"featured":false,"trending":false,"solution_count_in_trending_period":552,"trending_last_calculated":"2026-04-26T00:00:00.000Z","image_id":7156,"published":false,"community_created":true,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCoding competition. For more information and leaderboard please visit the Teams Channel or email brendanm@mathworks.com. Contest runs from 12/8/25 thru 12/18/25.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 63px; display: block; min-width: 0px; padding-block-start: 0px; padding-inline-start: 2px; padding-left: 2px; padding-top: 0px; perspective-origin: 289.5px 31.5px; transform-origin: 289.5px 31.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 265.5px 31.5px; text-align: left; transform-origin: 265.5px 31.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-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=\"\"\u003eCoding competition. For more information and leaderboard please visit the Teams Channel or email brendanm@mathworks.com. Contest runs from 12/8/25 thru 12/18/25.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","published_at":null},"current_player":null},"problems":[{"id":44943,"title":"Calculate Amount of Cake Frosting","description":"Given two input variables r and h, which stand for the radius and height of a cake, calculate the surface area of the cake you need to put frosting on (all around the sides and the top).\r\nReturn the result in output variable SA.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 73px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 36.5px; transform-origin: 407px 36.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42.5px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21.25px; text-align: left; transform-origin: 384px 21.25px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 79px 8px; transform-origin: 79px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven two input variables\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003er\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 14px 8px; transform-origin: 14px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003eh\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 276.5px 8px; transform-origin: 276.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, which stand for the radius and height of a cake, calculate the surface area of the cake you need to put frosting on (all around the sides and the top).\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21.5px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.75px; text-align: left; transform-origin: 384px 10.75px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 109.5px 8px; transform-origin: 109.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn the result in output variable\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 8px 8px; transform-origin: 8px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 8px 8.5px; transform-origin: 8px 8.5px; \"\u003eSA\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function SA = func_frosting(r,h)\r\n  SA = r + h;\r\nend","test_suite":"%%\r\nfiletext = fileread('func_frosting.m');\r\nassert(isempty(strfind(filetext, 'regexp')))\r\nassert(isempty(strfind(filetext, 'else')))\r\nassert(isempty(strfind(filetext, 'switch')))\r\n\r\n%%\r\nr = 3;\r\nh = 2;\r\ny_correct = 65.9734;\r\nassert(abs(func_frosting(r,h) - y_correct) \u003c 1e-4)\r\n\r\n%%\r\nr = 1;\r\nh = 1;\r\ny_correct = 3*pi;\r\nassert(abs(func_frosting(r,h) - y_correct) \u003c 1e-4)\r\n\r\n%%\r\nr = 0.5;\r\nh = 0.25;\r\ny_correct = 1.5708;\r\nassert(abs(func_frosting(r,h) - y_correct) \u003c 1e-4)\r\n","published":true,"deleted":false,"likes_count":223,"comments_count":24,"created_by":162851,"edited_by":223089,"edited_at":"2022-07-06T08:49:20.000Z","deleted_by":null,"deleted_at":null,"solvers_count":29560,"test_suite_updated_at":"2022-07-06T08:49:20.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2019-08-13T19:36:28.000Z","updated_at":"2026-04-30T20:12:05.000Z","published_at":"2019-08-29T18:15:57.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven two input variables\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003er\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eh\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, which stand for the radius and height of a cake, calculate the surface area of the cake you need to put frosting on (all around the sides and the top).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the result in output variable\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSA\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":1260,"title":"RISK board game battle simulation","description":"Given two positive integer inputs, a (attacker army units) and d (defender army units) return the probablity of victory (from 0.000 to 1.000) to +- 0.02 accuracy. The rules are given below for those unfamiliar with the game. \r\n\r\nIn the board game RISK battles are determined by the conflict of armies, namely the attacking army and the defending army. The results is determined as follows: the attacker rolls 3 six-sided die and the defender rolls 2 die. The highest two numbers of each player are compared respectively, and the higher number wins (this means the opposing army loses one unit). In the case of a tie the defender wins. For example:\r\n\r\nAttacker has 10 units\r\nDefender has 10 units\r\n\r\nAttacker rolls [6 3 2]\r\nDefender rolls [4 3]\r\n\r\nThe first comparison is attacker - 6, defender - 4. Since the attacker is higher, the defender loses one unit. Hence Attacker has 10 units, Defender now has 9 units.\r\n\r\nThe first comparison is attacker - 3, defender - 3. Since the defender is higher, the attacker loses one unit. Hence Attacker has 9 units, Defender now has 9 units.\r\n\r\nThis is continued until either the attacker has only one unit left, in which case the defender wins the battle; or the defender has no units left, in which case the attacker wins the battle.\r\n\r\nThis is one further rule: the number of die any player may roll cannot be more than the their units in case of the defender, or their units + 1 in case of the attacker. \r\n\r\nExample:\r\nAttacker has 3 units,\r\nDefender has 1 units.\r\n\r\nAttacker rolls 2 die (3 - 1),\r\nDefender rolls 1 die.","description_html":"\u003cp\u003eGiven two positive integer inputs, a (attacker army units) and d (defender army units) return the probablity of victory (from 0.000 to 1.000) to +- 0.02 accuracy. The rules are given below for those unfamiliar with the game.\u003c/p\u003e\u003cp\u003eIn the board game RISK battles are determined by the conflict of armies, namely the attacking army and the defending army. The results is determined as follows: the attacker rolls 3 six-sided die and the defender rolls 2 die. The highest two numbers of each player are compared respectively, and the higher number wins (this means the opposing army loses one unit). In the case of a tie the defender wins. For example:\u003c/p\u003e\u003cp\u003eAttacker has 10 units\r\nDefender has 10 units\u003c/p\u003e\u003cp\u003eAttacker rolls [6 3 2]\r\nDefender rolls [4 3]\u003c/p\u003e\u003cp\u003eThe first comparison is attacker - 6, defender - 4. Since the attacker is higher, the defender loses one unit. Hence Attacker has 10 units, Defender now has 9 units.\u003c/p\u003e\u003cp\u003eThe first comparison is attacker - 3, defender - 3. Since the defender is higher, the attacker loses one unit. Hence Attacker has 9 units, Defender now has 9 units.\u003c/p\u003e\u003cp\u003eThis is continued until either the attacker has only one unit left, in which case the defender wins the battle; or the defender has no units left, in which case the attacker wins the battle.\u003c/p\u003e\u003cp\u003eThis is one further rule: the number of die any player may roll cannot be more than the their units in case of the defender, or their units + 1 in case of the attacker.\u003c/p\u003e\u003cp\u003eExample:\r\nAttacker has 3 units,\r\nDefender has 1 units.\u003c/p\u003e\u003cp\u003eAttacker rolls 2 die (3 - 1),\r\nDefender rolls 1 die.\u003c/p\u003e","function_template":"function y = risk_prob(a, d)\r\n  y = 0.000;\r\nend","test_suite":"%%\r\na = 3;\r\nd = 0;\r\ny_correct = 1.000;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.01)\r\n\r\n%%\r\na = 1;\r\nd = 5;\r\ny_correct = 0.000;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.01)\r\n\r\n%%\r\na = 5;\r\nd = 3;\r\ny_correct = 0.642;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 4;\r\nd = 6;\r\ny_correct = 0.134;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 10;\r\nd = 10;\r\ny_correct = 0.480;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 7;\r\nd = 8;\r\ny_correct = 0.329;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 8;\r\nd = 7;\r\ny_correct = 0.5355;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 20;\r\nd = 10;\r\ny_correct = 0.965;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 4;\r\nd = 2;\r\ny_correct = 0.656;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 6;\r\nd = 4;\r\ny_correct = 0.638;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 2;\r\nd = 1;\r\ny_correct = 0.417;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n%%\r\na = 2;\r\nd = 2;\r\ny_correct = 0.104;\r\nassert(abs(risk_prob(a, d) - y_correct) \u003c= 0.02)\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":6,"created_by":10338,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":42,"test_suite_updated_at":"2013-02-12T00:28:08.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-02-10T23:10:17.000Z","updated_at":"2026-02-15T07:37:57.000Z","published_at":"2013-02-10T23:10:17.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven two positive integer inputs, a (attacker army units) and d (defender army units) return the probablity of victory (from 0.000 to 1.000) to +- 0.02 accuracy. The rules are given below for those unfamiliar with the game.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn the board game RISK battles are determined by the conflict of armies, namely the attacking army and the defending army. The results is determined as follows: the attacker rolls 3 six-sided die and the defender rolls 2 die. The highest two numbers of each player are compared respectively, and the higher number wins (this means the opposing army loses one unit). In the case of a tie the defender wins. For example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAttacker has 10 units Defender has 10 units\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAttacker rolls [6 3 2] Defender rolls [4 3]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe first comparison is attacker - 6, defender - 4. Since the attacker is higher, the defender loses one unit. Hence Attacker has 10 units, Defender now has 9 units.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe first comparison is attacker - 3, defender - 3. Since the defender is higher, the attacker loses one unit. Hence Attacker has 9 units, Defender now has 9 units.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is continued until either the attacker has only one unit left, in which case the defender wins the battle; or the defender has no units left, in which case the attacker wins the battle.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is one further rule: the number of die any player may roll cannot be more than the their units in case of the defender, or their units + 1 in case of the attacker.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample: Attacker has 3 units, Defender has 1 units.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAttacker rolls 2 die (3 - 1), Defender rolls 1 die.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":33,"title":"Create times-tables","description":"At one time or another, we all had to memorize boring times tables. 5 times 5 is 25. 5 times 6 is 30. 12 times 12 is way more than you think.\r\n\r\nWith MATLAB, times tables should be easy! Write a function that outputs times tables up to the size requested. \r\n\r\nExample:\r\n\r\n Input n = 5\r\n Output m is [ 1     2     3     4     5\r\n               2     4     6     8    10\r\n               3     6     9    12    15\r\n               4     8    12    16    20\r\n               5    10    15    20    25 ]\r\n","description_html":"\u003cp\u003eAt one time or another, we all had to memorize boring times tables. 5 times 5 is 25. 5 times 6 is 30. 12 times 12 is way more than you think.\u003c/p\u003e\u003cp\u003eWith MATLAB, times tables should be easy! Write a function that outputs times tables up to the size requested.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e Input n = 5\r\n Output m is [ 1     2     3     4     5\r\n               2     4     6     8    10\r\n               3     6     9    12    15\r\n               4     8    12    16    20\r\n               5    10    15    20    25 ]\u003c/pre\u003e","function_template":"function m = timestables(n)\r\n  m = 0;\r\nend","test_suite":"%%\r\nx = 2;\r\ny_correct = [1 2; 2 4];\r\nassert(isequal(timestables(x),y_correct))\r\n\r\n%%\r\nx = 3;\r\ny_correct = [1 2 3; 2 4 6; 3 6 9];\r\nassert(isequal(timestables(x),y_correct))\r\n\r\n%%\r\nx = 5;\r\ny_correct = [1 2 3 4 5; 2 4 6 8 10; 3 6 9 12 15; 4 8 12 16 20; 5 10 15 20 25];\r\nassert(isequal(timestables(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":113,"comments_count":28,"created_by":1,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":19470,"test_suite_updated_at":"2015-07-31T20:52:53.000Z","rescore_all_solutions":false,"group_id":2,"created_at":"2012-01-18T01:00:21.000Z","updated_at":"2026-05-01T05:41:45.000Z","published_at":"2012-01-18T01:00:21.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\u003eAt one time or another, we all had to memorize boring times tables. 5 times 5 is 25. 5 times 6 is 30. 12 times 12 is way more than you think.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWith MATLAB, times tables should be easy! Write a function that outputs times tables up to the size requested.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ Input n = 5\\n Output m is [ 1     2     3     4     5\\n               2     4     6     8    10\\n               3     6     9    12    15\\n               4     8    12    16    20\\n               5    10    15    20    25 ]]]\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":60,"title":"The Goldbach Conjecture","description":"The Goldbach conjecture asserts that every even integer greater than 2 can be expressed as the sum of two primes.\r\nGiven the even integer n, return primes p1 and p2 that satisfy the condition n = p1 + p2. Note that the primes are not always unique. The test is not sensitive to order or uniqueness. You just need to meet the appropriate conditions.\r\nExample:\r\n Input  n = 286\r\n Output (any of the following is acceptable) \r\n        [  3 283]\r\n        [283   3]\r\n        [  5 281]\r\n        [107 179]\r\n        [137 149]","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: 255.033px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 127.517px; transform-origin: 407px 127.517px; 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: 12.5px 8px; transform-origin: 12.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eGoldbach conjecture\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: 287px 8px; transform-origin: 287px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e asserts that every even integer greater than 2 can be expressed as the sum of two primes.\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: 368.5px 8px; transform-origin: 368.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven the even integer n, return primes p1 and p2 that satisfy the condition n = p1 + p2. Note that the primes are not always unique. The test is not sensitive to order or uniqueness. You just need to meet the appropriate conditions.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 28.5px 8px; transform-origin: 28.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 143.033px; 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 71.5167px; transform-origin: 404px 71.5167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 60px 8.5px; tab-size: 4; transform-origin: 60px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 32px 8.5px; transform-origin: 32px 8.5px; \"\u003e Input  \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 28px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 28px 8.5px; \"\u003en = 286\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 180px 8.5px; tab-size: 4; transform-origin: 180px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e Output (any of the following is acceptable) \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 68px 8.5px; tab-size: 4; transform-origin: 68px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        [  3 283]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 68px 8.5px; tab-size: 4; transform-origin: 68px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        [283   3]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 68px 8.5px; tab-size: 4; transform-origin: 68px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        [  5 281]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 68px 8.5px; tab-size: 4; transform-origin: 68px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        [107 179]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 68px 8.5px; tab-size: 4; transform-origin: 68px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        [137 149]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [p1,p2] = goldbach(n)\r\n  p1 = n;\r\n  p2 = n;\r\nend","test_suite":"%%\r\nfiletext = fileread('goldbach.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp'); \r\nassert(~illegal)\r\n\r\n%%\r\nnList = 28:6:76;\r\nfor i = 1:length(nList)\r\n  n = nList(i);\r\n  [p1,p2] = goldbach(n)\r\n  assert(isprime(p1) \u0026\u0026 isprime(p2) \u0026\u0026 (p1+p2==n));\r\nend\r\n\r\n%%\r\nnList = [18 20 22 100 102 114 1000 2000 36 3600];\r\nfor i = 1:length(nList)\r\n  n = nList(i);\r\n  [p1,p2] = goldbach(n)\r\n  assert(isprime(p1) \u0026\u0026 isprime(p2) \u0026\u0026 (p1+p2==n));\r\nend","published":true,"deleted":false,"likes_count":60,"comments_count":17,"created_by":1,"edited_by":223089,"edited_at":"2023-06-05T15:48:22.000Z","deleted_by":null,"deleted_at":null,"solvers_count":5976,"test_suite_updated_at":"2023-06-05T15:48:22.000Z","rescore_all_solutions":false,"group_id":2,"created_at":"2012-01-18T01:00:25.000Z","updated_at":"2026-04-25T20:45:05.000Z","published_at":"2012-01-18T01:00:25.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGoldbach conjecture\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e asserts that every even integer greater than 2 can be expressed as the sum of two primes.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven the even integer n, return primes p1 and p2 that satisfy the condition n = p1 + p2. Note that the primes are not always unique. The test is not sensitive to order or uniqueness. You just need to meet the appropriate conditions.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ Input  n = 286\\n Output (any of the following is acceptable) \\n        [  3 283]\\n        [283   3]\\n        [  5 281]\\n        [107 179]\\n        [137 149]]]\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":1286,"title":"MatCAT - Reconstruct X from Its X-rays","description":"Consider a matrix x\r\n\r\n x = [ 1 2 0\r\n       0 5 0 \r\n       3 0 8 ]\r\n\r\nIf we sum x along the rows we get\r\n\r\n row_sums = [3 5 11]\r\n\r\nSumming along the columns gives \r\n\r\n col_sums = [4 7 8]\r\n\r\nMetaphorically, we might call these sums \"x-rays\". Your job is to take these x-rays and reconstruct the matrix x being x-rayed, in the fashion of a \u003chttp://en.wikipedia.org/wiki/X-ray_computed_tomography CAT scan\u003e. Can you put all the bones in the right place?\r\n\r\nAll matrix elements must be non-negative integers. There is no guarantee of a unique answer. I will only check that the row and column sums match the supplied matrix, and that your elements are non-negative integers.\r\n\r\nBonus question: Under what circumstances does the answer become unique? Discuss.","description_html":"\u003cp\u003eConsider a matrix x\u003c/p\u003e\u003cpre\u003e x = [ 1 2 0\r\n       0 5 0 \r\n       3 0 8 ]\u003c/pre\u003e\u003cp\u003eIf we sum x along the rows we get\u003c/p\u003e\u003cpre\u003e row_sums = [3 5 11]\u003c/pre\u003e\u003cp\u003eSumming along the columns gives\u003c/p\u003e\u003cpre\u003e col_sums = [4 7 8]\u003c/pre\u003e\u003cp\u003eMetaphorically, we might call these sums \"x-rays\". Your job is to take these x-rays and reconstruct the matrix x being x-rayed, in the fashion of a \u003ca href = \"http://en.wikipedia.org/wiki/X-ray_computed_tomography\"\u003eCAT scan\u003c/a\u003e. Can you put all the bones in the right place?\u003c/p\u003e\u003cp\u003eAll matrix elements must be non-negative integers. There is no guarantee of a unique answer. I will only check that the row and column sums match the supplied matrix, and that your elements are non-negative integers.\u003c/p\u003e\u003cp\u003eBonus question: Under what circumstances does the answer become unique? Discuss.\u003c/p\u003e","function_template":"function x = matcat(row_sums,col_sums)\r\n  x = 0;\r\nend","test_suite":"%%\r\nrow_sums = [3 5 11];\r\ncol_sums = [4 7 8];\r\nx = matcat(row_sums,col_sums);\r\nassert(all(x(:)\u003e=0))\r\nassert(isequal(floor(x),x))\r\nassert(isequal(sum(x,2)',row_sums))\r\nassert(isequal(sum(x,1),col_sums))\r\n\r\n%%\r\nrow_sums = [2 2 2 2 2 6];\r\ncol_sums = [2 3 3 3 3 2];\r\nx = matcat(row_sums,col_sums);\r\nassert(all(x(:)\u003e=0))\r\nassert(isequal(floor(x),x))\r\nassert(isequal(sum(x,2)',row_sums))\r\nassert(isequal(sum(x,1),col_sums))\r\n\r\n%%\r\nrow_sums = [65 65 65 65 65];\r\ncol_sums = [65 65 65 65 65];\r\nx = matcat(row_sums,col_sums);\r\nassert(all(x(:)\u003e=0))\r\nassert(isequal(floor(x),x))\r\nassert(isequal(sum(x,2)',row_sums))\r\nassert(isequal(sum(x,1),col_sums))\r\n\r\n%%\r\nrow_sums = [22 34 33];\r\ncol_sums = [15 23 18 21 12];\r\nx = matcat(row_sums,col_sums);\r\nassert(all(x(:)\u003e=0))\r\nassert(isequal(floor(x),x))\r\nassert(isequal(sum(x,2)',row_sums))\r\nassert(isequal(sum(x,1),col_sums))\r\n\r\n%%\r\nrow_sums = 55;\r\ncol_sums = [1 2 3 4 5 6 7 8 9 10];\r\nx = matcat(row_sums,col_sums);\r\nassert(all(x(:)\u003e=0))\r\nassert(isequal(floor(x),x))\r\nassert(isequal(sum(x,2)',row_sums))\r\nassert(isequal(sum(x,1),col_sums))\r\n","published":true,"deleted":false,"likes_count":10,"comments_count":4,"created_by":7,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":148,"test_suite_updated_at":"2013-02-21T17:46:45.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2013-02-21T17:25:12.000Z","updated_at":"2026-04-22T11:32:22.000Z","published_at":"2013-02-21T17:46:45.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\u003eConsider a matrix x\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x = [ 1 2 0\\n       0 5 0 \\n       3 0 8 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf we sum x along the rows we get\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[ row_sums = [3 5 11]]]\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\u003eSumming along the columns gives\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[ col_sums = [4 7 8]]]\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\u003eMetaphorically, we might call these sums \\\"x-rays\\\". Your job is to take these x-rays and reconstruct the matrix x being x-rayed, in the fashion of a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/X-ray_computed_tomography\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCAT scan\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Can you put all the bones in the right place?\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eAll matrix elements must be non-negative integers. There is no guarantee of a unique answer. I will only check that the row and column sums match the supplied matrix, and that your elements are non-negative integers.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eBonus question: Under what circumstances does the answer become unique? Discuss.\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":42915,"title":"How Far Can You Throw Something?","description":"As you probably learned in your high school physics class, throwing an object at a 45 degree angle will give you the maximum range.  This assumes you are throwing it at ground level, however.  If you are throwing it 10, 20 or 50 meters above the ground, 45 degrees will not give you the maximum range; the maximum range is a function of both height and speed.\r\n\r\nGiven an initial speed V m/sec and a starting height of h meters, calculate both the angle (in degrees) that will give you the longest range, and what that range is (in meters).  Use g=9.81 m/sec^2.  You can neglect air resistance, and assume that your starting height will always be positive.  The angle is measured from the vertical, so an angle of 0 is straight up, 90 degrees is parallel to the ground, and 180 is straight down.  Your angle should be between 0-180 degrees.  Your values for both speed and angle should be correct to a tolerance of 1e-6.\r\n\r\nFor example, with an initial speed of 100 m/sec thrown at ground level (h=0), the maximum range for your projectile is approximately 1019.367 meters, and the angle is 45 degrees.  If you have h=50 m with the same speed, it can travel a maximum of 1068.198 meters, but only if you throw it at 46.339 degrees.\r\n\r\nGood luck!","description_html":"\u003cp\u003eAs you probably learned in your high school physics class, throwing an object at a 45 degree angle will give you the maximum range.  This assumes you are throwing it at ground level, however.  If you are throwing it 10, 20 or 50 meters above the ground, 45 degrees will not give you the maximum range; the maximum range is a function of both height and speed.\u003c/p\u003e\u003cp\u003eGiven an initial speed V m/sec and a starting height of h meters, calculate both the angle (in degrees) that will give you the longest range, and what that range is (in meters).  Use g=9.81 m/sec^2.  You can neglect air resistance, and assume that your starting height will always be positive.  The angle is measured from the vertical, so an angle of 0 is straight up, 90 degrees is parallel to the ground, and 180 is straight down.  Your angle should be between 0-180 degrees.  Your values for both speed and angle should be correct to a tolerance of 1e-6.\u003c/p\u003e\u003cp\u003eFor example, with an initial speed of 100 m/sec thrown at ground level (h=0), the maximum range for your projectile is approximately 1019.367 meters, and the angle is 45 degrees.  If you have h=50 m with the same speed, it can travel a maximum of 1068.198 meters, but only if you throw it at 46.339 degrees.\u003c/p\u003e\u003cp\u003eGood luck!\u003c/p\u003e","function_template":"function [long_d thetamax]=ballistics(hstart,vstart)\r\n  long_d=0;\r\n  thetamax=pi;\r\nend","test_suite":"%%\r\nformat compact\r\nhstart=0;vstart=50;\r\n[long_d thetamax]=ballistics(hstart,vstart)\r\ndl=abs(long_d-254.841997961264)\r\ndt=abs(thetamax-45)\r\nassert(and(dl\u003c1e-6,dt\u003c1e-6))\r\n%%\r\nhstart=100;vstart=20;\r\n[long_d thetamax]=ballistics(hstart,vstart)\r\ndl=abs(long_d-99.08340778978895)\r\ndt=abs(thetamax-67.63189529197281)\r\nassert(and(dl\u003c1e-6,dt\u003c1e-6))\r\n%%\r\nhstart=100;vstart=50;\r\n[long_d thetamax]=ballistics(hstart,vstart)\r\ndl=abs(long_d-340.4597531532057)\r\ndt=abs(thetamax-53.1842963916761)\r\nassert(and(dl\u003c1e-6,dt\u003c1e-6))\r\n%%\r\nhstart=50;vstart=100;\r\n[long_d thetamax]=ballistics(hstart,vstart)\r\ndl=abs(long_d-1068.198437549283)\r\ndt=abs(thetamax-46.33996589024096)\r\nassert(and(dl\u003c1e-6,dt\u003c1e-6))\r\n%%\r\nhstart=30;vstart=30;\r\n[long_d thetamax]=ballistics(hstart,vstart)\r\ndl=abs(long_d-117.9889278221855)\r\ndt=abs(thetamax-52.13289838740581)\r\nassert(and(dl\u003c1e-6,dt\u003c1e-6))","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":90,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-07-25T18:42:20.000Z","updated_at":"2026-04-18T08:37:11.000Z","published_at":"2016-07-25T18:42:20.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eAs you probably learned in your high school physics class, throwing an object at a 45 degree angle will give you the maximum range. This assumes you are throwing it at ground level, however. If you are throwing it 10, 20 or 50 meters above the ground, 45 degrees will not give you the maximum range; the maximum range is a function of both height and speed.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an initial speed V m/sec and a starting height of h meters, calculate both the angle (in degrees) that will give you the longest range, and what that range is (in meters). Use g=9.81 m/sec^2. You can neglect air resistance, and assume that your starting height will always be positive. The angle is measured from the vertical, so an angle of 0 is straight up, 90 degrees is parallel to the ground, and 180 is straight down. Your angle should be between 0-180 degrees. Your values for both speed and angle should be correct to a tolerance of 1e-6.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, with an initial speed of 100 m/sec thrown at ground level (h=0), the maximum range for your projectile is approximately 1019.367 meters, and the angle is 45 degrees. If you have h=50 m with the same speed, it can travel a maximum of 1068.198 meters, but only if you throw it at 46.339 degrees.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGood 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":45494,"title":"SatCom #3: Free Space Path Loss","description":"*Satellite and Space Engineering - Problem #3*\r\n\r\n_This is part of a series of problems looking at topics in satellite and space communications and systems engineering._\r\n\r\nDetermine the \"Free Space Path Loss\" (dB) between a transmit and receive antenna. (Note that \"Free Space Path Loss\" is *not* the same as \"Spreading Loss\" (inverse-square loss), as it is defined as the loss between the input port of a transmitting isotropic antenna and the output port of a receiving isotropic antenna. As it contains (hidden inside the formula) also the formulas for the transmitting and receiving isotropic antenna gains, \"Free Space Path Loss\" has, perhaps surprisingly at first thought, a frequency-dependent term).\r\n\r\nYou are given the distance between the transmitting and receiving antennas in a satellite link (in m) and the frequency of operation (in Hz). Calculate the \"Free Space Loss\" (in dB).\r\n\r\nYou should take the speed of light to be 299,792,458 m/s.\r\n\r\nHint: See \u003chttps://en.wikipedia.org/wiki/Free-space_path_loss#Free-space_path_loss_formula\u003e - but don't forget to convert to dB!\r\n\r\nExample: The Free Space Path Loss from an antenna on the ground to a Geostationary satellite directly overhead (roughly 35,786 km altitude) at 10 GHz is around 203.5 dB.\r\n\r\n_Some future problems in this series will build on work done in previous problems, so if you get a working solution I suggest you hang onto the code!_","description_html":"\u003cp\u003e\u003cb\u003eSatellite and Space Engineering - Problem #3\u003c/b\u003e\u003c/p\u003e\u003cp\u003e\u003ci\u003eThis is part of a series of problems looking at topics in satellite and space communications and systems engineering.\u003c/i\u003e\u003c/p\u003e\u003cp\u003eDetermine the \"Free Space Path Loss\" (dB) between a transmit and receive antenna. (Note that \"Free Space Path Loss\" is \u003cb\u003enot\u003c/b\u003e the same as \"Spreading Loss\" (inverse-square loss), as it is defined as the loss between the input port of a transmitting isotropic antenna and the output port of a receiving isotropic antenna. As it contains (hidden inside the formula) also the formulas for the transmitting and receiving isotropic antenna gains, \"Free Space Path Loss\" has, perhaps surprisingly at first thought, a frequency-dependent term).\u003c/p\u003e\u003cp\u003eYou are given the distance between the transmitting and receiving antennas in a satellite link (in m) and the frequency of operation (in Hz). Calculate the \"Free Space Loss\" (in dB).\u003c/p\u003e\u003cp\u003eYou should take the speed of light to be 299,792,458 m/s.\u003c/p\u003e\u003cp\u003eHint: See \u003ca href = \"https://en.wikipedia.org/wiki/Free-space_path_loss#Free-space_path_loss_formula\"\u003ehttps://en.wikipedia.org/wiki/Free-space_path_loss#Free-space_path_loss_formula\u003c/a\u003e - but don't forget to convert to dB!\u003c/p\u003e\u003cp\u003eExample: The Free Space Path Loss from an antenna on the ground to a Geostationary satellite directly overhead (roughly 35,786 km altitude) at 10 GHz is around 203.5 dB.\u003c/p\u003e\u003cp\u003e\u003ci\u003eSome future problems in this series will build on work done in previous problems, so if you get a working solution I suggest you hang onto the code!\u003c/i\u003e\u003c/p\u003e","function_template":"function loss = FSPL(dist,freq)\r\n  loss = dist+freq;\r\nend","test_suite":"%%\r\nd = 35786000;\r\nf = 10e9;\r\ny_correct = 2.035220463738069e+02;\r\nassert(abs(FSPL(d,f)-y_correct)\u003c10*eps(y_correct))\r\n\r\n%%\r\nd = 41950000;\r\nf = 1.98e9;\r\ny_correct = 1.908357263304084e+02;\r\nassert(abs(FSPL(d,f)-y_correct)\u003c10*eps(y_correct))\r\n\r\n%%\r\ns=importdata('FSPL.m');\r\ny_correct=false;\r\nassert(isequal(sum(contains(s,'regexp')),y_correct))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":437780,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":133,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-05-04T17:11:35.000Z","updated_at":"2026-04-28T18:58:21.000Z","published_at":"2020-05-04T17:15:31.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSatellite and Space Engineering - Problem #3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eThis is part of a series of problems looking at topics in satellite and space communications and systems engineering.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eDetermine the \\\"Free Space Path Loss\\\" (dB) between a transmit and receive antenna. (Note that \\\"Free Space Path Loss\\\" is\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003enot\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e the same as \\\"Spreading Loss\\\" (inverse-square loss), as it is defined as the loss between the input port of a transmitting isotropic antenna and the output port of a receiving isotropic antenna. As it contains (hidden inside the formula) also the formulas for the transmitting and receiving isotropic antenna gains, \\\"Free Space Path Loss\\\" has, perhaps surprisingly at first thought, a frequency-dependent term).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou are given the distance between the transmitting and receiving antennas in a satellite link (in m) and the frequency of operation (in Hz). Calculate the \\\"Free Space Loss\\\" (in dB).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou should take the speed of light to be 299,792,458 m/s.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHint: See\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Free-space_path_loss#Free-space_path_loss_formula\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://en.wikipedia.org/wiki/Free-space_path_loss#Free-space_path_loss_formula\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt; - but don't forget to convert to dB!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample: The Free Space Path Loss from an antenna on the ground to a Geostationary satellite directly overhead (roughly 35,786 km altitude) at 10 GHz is around 203.5 dB.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSome future problems in this series will build on work done in previous problems, so if you get a working solution I suggest you hang onto the code!\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":45803,"title":"SatCom #7: Thermal Noise in a Receiver ","description":"Satellite and Space Engineering - Problem #7\r\nThis is part of a series of problems looking at topics in satellite and space communications and systems engineering.\r\nDetermine the thermal (Gaussian) noise power (dBW) in a radio receiver (in this case we are thinking of a satellite receiver, but the approach is generic to all radio receivers).\r\nYou are given the bandwidth of the receiver (in Hz) and the receiving system noise temperature (in Kelvin).\r\nYou should take Boltzmann's constant to be 1.380649×10^−23 J/K.\r\nHint: See https://en.wikipedia.org/wiki/Noise_figure#General - but don't forget to convert to dB!\r\nExample: The thermal noise power in a satellite receiver with a bandwidth of 2 MHz and a receiving system noise temperature of 200 K is around -142.6 dB.\r\nSome future problems in this series will build on work done in previous problems, so if you get a working solution I suggest you hang onto the code!","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: 294px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 147px; transform-origin: 407px 147px; 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: 157.5px 8px; transform-origin: 157.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eSatellite and Space Engineering - Problem #7\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: 366.5px 8px; transform-origin: 366.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eThis is part of a series of problems looking at topics in satellite and space communications and systems engineering.\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: 359.5px 8px; transform-origin: 359.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eDetermine the thermal (Gaussian) noise power (dBW) in a radio receiver (in this case we are thinking of a satellite receiver, but the approach is generic to all radio receivers).\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: 334.5px 8px; transform-origin: 334.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou are given the bandwidth of the receiver (in Hz) and the receiving system noise temperature (in Kelvin).\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: 209px 8px; transform-origin: 209px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou should take Boltzmann's constant to be 1.380649×10^−23 J/K.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 28.5px 8px; transform-origin: 28.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eHint: See\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://en.wikipedia.org/wiki/Noise_figure#General\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehttps://en.wikipedia.org/wiki/Noise_figure#General\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: 109px 8px; transform-origin: 109px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e - but don't forget to convert to dB!\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: 354px 8px; transform-origin: 354px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample: The thermal noise power in a satellite receiver with a bandwidth of 2 MHz and a receiving system noise temperature of 200 K is around -142.6 dB.\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 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eSome future problems in this series will build on work done in previous problems, so if you get a working solution I suggest you hang onto the code!\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function power = thermal_noise_power(Bandwidth, Noise_Temp)\r\n  power = Bandwidth+Noise_Temp;\r\nend","test_suite":"%%\r\nBandwidth = 2e6;\r\nNoise_Temp = 200;\r\nN_Power=thermal_noise_power(Bandwidth, Noise_Temp)\r\ny_correct = -142.5786;\r\nassert(abs(N_Power-y_correct)\u003c0.001)\r\n\r\n%%\r\nBandwidth = 20e6;\r\nNoise_Temp = 120;\r\nN_Power=thermal_noise_power(Bandwidth, Noise_Temp)\r\ny_correct = -134.7971;\r\nassert(abs(N_Power-y_correct)\u003c0.001)\r\n\r\n%%\r\nBandwidth = 1;\r\nNoise_Temp = 290;\r\nN_Power=thermal_noise_power(Bandwidth, Noise_Temp)\r\ny_correct = -203.9752;\r\nassert(abs(N_Power-y_correct)\u003c0.001)\r\n\r\n%%\r\ns=fileread('thermal_noise_power.m');\r\ny_correct=false;\r\nassert(isequal(sum(contains(s,'regexp')),y_correct))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":3,"created_by":437780,"edited_by":223089,"edited_at":"2023-03-01T17:32:20.000Z","deleted_by":null,"deleted_at":null,"solvers_count":86,"test_suite_updated_at":"2023-03-01T17:32:20.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-06-09T20:05:50.000Z","updated_at":"2026-04-28T19:03:44.000Z","published_at":"2020-09-25T16:48:19.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\u003eSatellite and Space Engineering - Problem #7\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\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\u003eThis is part of a series of problems looking at topics in satellite and space communications and systems engineering.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDetermine the thermal (Gaussian) noise power (dBW) in a radio receiver (in this case we are thinking of a satellite receiver, but the approach is generic to all radio receivers).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 are given the bandwidth of the receiver (in Hz) and the receiving system noise temperature (in Kelvin).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 take Boltzmann's constant to be 1.380649×10^−23 J/K.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHint: See\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Noise_figure#General\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttps://en.wikipedia.org/wiki/Noise_figure#General\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e - but don't forget to convert to dB!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample: The thermal noise power in a satellite receiver with a bandwidth of 2 MHz and a receiving system noise temperature of 200 K is around -142.6 dB.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\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\u003eSome future problems in this series will build on work done in previous problems, so if you get a working solution I suggest you hang onto the code!\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":58,"title":"Tic Tac Toe FTW","description":"Given a tic tac toe board:\r\n\r\n* 1 represents X\r\n* 0 represents empty.\r\n* -1 represents O\r\n \r\nIt is X's move. If there is an immediate win possibility, choose a square for an immediate win. Otherwise return 0.\r\n\r\nReturn absolute index of the square of choice. If multiple square are valid, return them in order.\r\n\r\nExample:\r\n\r\n Input  a = [ 1  0  1\r\n             -1  1  0\r\n              0 -1 -1]\r\n Output wins is [3 4]\r\n\r\n","description_html":"\u003cp\u003eGiven a tic tac toe board:\u003c/p\u003e\u003cul\u003e\u003cli\u003e1 represents X\u003c/li\u003e\u003cli\u003e0 represents empty.\u003c/li\u003e\u003cli\u003e-1 represents O\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIt is X's move. If there is an immediate win possibility, choose a square for an immediate win. Otherwise return 0.\u003c/p\u003e\u003cp\u003eReturn absolute index of the square of choice. If multiple square are valid, return them in order.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e Input  a = [ 1  0  1\r\n             -1  1  0\r\n              0 -1 -1]\r\n Output wins is [3 4]\u003c/pre\u003e","function_template":"function wins = ticTacToe(a)","test_suite":"%%\r\na = [ 1  0  1\r\n      0 -1  0\r\n     -1 -1  1];\r\n \r\nb = [4 8];\r\nout = ticTacToe(a);\r\nassert(isequal(out(:), b(:)))\r\n\r\n%%\r\na = [ 1  0  0\r\n      0 -1  0\r\n     -1  0  1];\r\n \r\nb = [0];\r\nout = ticTacToe(a);\r\nassert(isequal(out(:), b(:)))\r\n\r\n%%\r\n\r\na = [ 1  0  0\r\n      0  1 -1\r\n      1 -1 -1];\r\n \r\nb = [2 7];\r\nout = ticTacToe(a);\r\nassert(isequal(out(:), b(:)))\r\n\r\n%%\r\na = [ 1  0  0\r\n     -1  1 -1\r\n      1 -1  0];\r\n \r\nb = [7 9];\r\nout = ticTacToe(a);\r\nassert(isequal(out(:), b(:)))","published":true,"deleted":false,"likes_count":21,"comments_count":16,"created_by":1,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1842,"test_suite_updated_at":"2019-06-14T15:17:48.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-01-18T01:00:25.000Z","updated_at":"2026-04-30T21:40:06.000Z","published_at":"2012-01-18T01:00:25.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a tic tac toe board:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1 represents X\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e0 represents empty.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e-1 represents O\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eIt is X's move. If there is an immediate win possibility, choose a square for an immediate win. Otherwise return 0.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn absolute index of the square of choice. If multiple square are valid, return them in order.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ Input  a = [ 1  0  1\\n             -1  1  0\\n              0 -1 -1]\\n Output wins is [3 4]]]\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":37,"title":"Pascal's Triangle","description":"Given an integer n \u003e= 0, generate the length n+1 row vector representing the n-th row of \u003chttp://en.wikipedia.org/wiki/Pascals_triangle Pascal's Triangle\u003e.\r\n\r\nExamples:\r\n\r\n pascalTri(0)\r\n ans =\r\n     1\r\n\r\n pascalTri(1)\r\n ans =\r\n     1     1\r\n\r\n pascalTri(2)\r\n ans =\r\n     1     2     1\r\n","description_html":"\u003cp\u003eGiven an integer n \u003e= 0, generate the length n+1 row vector representing the n-th row of \u003ca href=\"http://en.wikipedia.org/wiki/Pascals_triangle\"\u003ePascal's Triangle\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre\u003e pascalTri(0)\r\n ans =\r\n     1\u003c/pre\u003e\u003cpre\u003e pascalTri(1)\r\n ans =\r\n     1     1\u003c/pre\u003e\u003cpre\u003e pascalTri(2)\r\n ans =\r\n     1     2     1\u003c/pre\u003e","function_template":"function y = pascalTri(n)\r\ny = n;\r\nend","test_suite":"%%\r\nn = 0;\r\ncorrect = [1];\r\nassert(isequal(pascalTri(n),correct))\r\n\r\n\r\n%%\r\nn = 1;\r\ncorrect = [1 1];\r\nassert(isequal(pascalTri(n),correct))\r\n\r\n\r\n%%\r\nn = 2;\r\ncorrect = [1 2 1];\r\nassert(isequal(pascalTri(n),correct))\r\n\r\n\r\n%%\r\nn = 3;\r\ncorrect = [1 3 3 1];\r\nassert(isequal(pascalTri(n),correct))\r\n\r\n\r\n%%\r\nn = 10;\r\ncorrect = [1 10 45 120 210 252 210 120 45 10 1];\r\nassert(isequal(pascalTri(n),correct))\r\n\r\n","published":true,"deleted":false,"likes_count":26,"comments_count":5,"created_by":1,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":4511,"test_suite_updated_at":"2012-01-26T14:20:57.000Z","rescore_all_solutions":false,"group_id":2,"created_at":"2012-01-18T01:00:22.000Z","updated_at":"2026-04-28T07:53:10.000Z","published_at":"2012-01-18T01:00:22.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an integer n \u0026gt;= 0, generate the length n+1 row vector representing the n-th row of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Pascals_triangle\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePascal's Triangle\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\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[ pascalTri(0)\\n ans =\\n     1\\n\\n pascalTri(1)\\n ans =\\n     1     1\\n\\n pascalTri(2)\\n ans =\\n     1     2     1]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":59,"title":"Pattern matching","description":"Given a matrix, m-by-n, find all the rows that have the same \"increase, decrease, or stay same\" pattern going across the columns as the first row does.  Do not list the row as a match to itself.\r\n\r\nExample:\r\n\r\n Input  a = [1 2 3 0\r\n             5 6 7 9\r\n             2 7 8 7]\r\n Output b is 3\r\n\r\nsince the third column follows the increase-increase-decrease pattern used in vector a.\r\n ","description_html":"\u003cp\u003eGiven a matrix, m-by-n, find all the rows that have the same \"increase, decrease, or stay same\" pattern going across the columns as the first row does.  Do not list the row as a match to itself.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e Input  a = [1 2 3 0\r\n             5 6 7 9\r\n             2 7 8 7]\r\n Output b is 3\u003c/pre\u003e\u003cp\u003esince the third column follows the increase-increase-decrease pattern used in vector a.\u003c/p\u003e","function_template":"function b = matchPattern(a)\r\n\r\n  b = [];\r\n\r\nend","test_suite":"%%\r\na = [0 1 1 0 -1 1 0 1\r\n     0 1 1 0 -1 1 0 1\r\n     0 1 0 0 -1 1 0 1\r\n     1 2 2 1  0 2 1 2];  \r\n \r\nb = [2 4];\r\nout = matchPattern(a);\r\nassert(isequal(out(:), b(:)))\r\n\r\n%%\r\na = [0 1 2 3 4 5 6 7\r\n     1 2 3 4 5 6 7 8\r\n     0 2 3 4 5 7 8 0\r\n     0 0 2 3 4 5 6 7];\r\n \r\nb = [2];\r\nout = matchPattern(a);\r\nassert(isequal(out(:), b(:)))\r\n\r\n%%\r\na = [0 0 2 3 4 5 6 7\r\n     1 2 3 4 5 6 7 8\r\n     0 2 3 4 5 7 8 0\r\n     0 0 2 3 4 5 6 7];\r\n \r\nb = [4];\r\nout = matchPattern(a);\r\nassert(isequal(out(:), b(:)))\r\n\r\n\r\n%%\r\na = [0 0 2 3 4 5 6 7\r\n     1 2 3 4 5 6 7 8\r\n     0 2 3 4 5 7 8 0\r\n     0 0 12 13 140 150 160 1700];\r\n \r\nb = [4];\r\nout = matchPattern(a);\r\nassert(isequal(out(:), b(:)))\r\n\r\n%%\r\na = [0 1 1 0\r\n     1 2 3 4\r\n     1 5 5 3\r\n     2 3 4 5\r\n     6 7 7 9\r\n     -4 -1 -1 -12\r\n     5 6 9 10];\r\nb = [3 6];\r\nout = matchPattern(a);\r\nassert(isequal(out(:), b(:)))\r\n","published":true,"deleted":false,"likes_count":16,"comments_count":2,"created_by":1,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":2821,"test_suite_updated_at":"2014-06-05T16:50:29.000Z","rescore_all_solutions":false,"group_id":2,"created_at":"2012-01-18T01:00:25.000Z","updated_at":"2026-04-27T23:01:40.000Z","published_at":"2012-01-18T01:00:25.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix, m-by-n, find all the rows that have the same \\\"increase, decrease, or stay same\\\" pattern going across the columns as the first row does. Do not list the row as a match to itself.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ Input  a = [1 2 3 0\\n             5 6 7 9\\n             2 7 8 7]\\n Output b is 3]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003esince the third column follows the increase-increase-decrease pattern used in vector a.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"no_progress_badge":{"id":53,"name":"Unknown","symbol":"unknown","description":"Partially completed groups","description_html":null,"image_location":"/images/responsive/supporting/matlabcentral/cody/badges/problem_groups_unknown_2.png","bonus":null,"players_count":0,"active":false,"created_by":null,"updated_by":null,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"created_at":"2018-01-10T23:20:29.000Z","updated_at":"2018-01-10T23:20:29.000Z","community_badge_id":null,"award_multiples":false}}