{"group":{"group":{"id":52,"name":"Board Games I","lockable":false,"created_at":"2018-08-27T17:29:24.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Utilize Matlab to win all the board games.","is_default":false,"created_by":26769,"badge_id":62,"featured":false,"trending":false,"solution_count_in_trending_period":41,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":466,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eUtilize Matlab to win all the board games.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}","description_html":"\u003cdiv style = \"text-align: start; line-height: normal; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"display: block; min-width: 0px; padding-top: 0px; perspective-origin: 289.5px 10.5px; transform-origin: 289.5px 10.5px; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; white-space: pre-wrap; perspective-origin: 266.5px 10.5px; transform-origin: 266.5px 10.5px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eUtilize Matlab to win all the board games.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","published_at":"2019-07-29T17:07:03.000Z"},"current_player":null},"problems":[{"id":186,"title":"The Tower of Hanoi ","description":"In the \u003chttp://en.wikipedia.org/wiki/Tower_of_Hanoi Tower of Hanoi problem\u003e with 3 rods (1, 2 \u0026 3), the goal is to move a tower of disks from rod #1 to rod #2.\r\nYou can move disks only one by one, on the rods.\r\nYou can't put a disk on a smaller one.\r\n\r\nAt the beginning, all disks are on rod #1, biggest at the bottom, smallest at the top.\r\n\r\nGive the number of moves necessary to solve the problem.","description_html":"\u003cp\u003eIn the \u003ca href = \"http://en.wikipedia.org/wiki/Tower_of_Hanoi\"\u003eTower of Hanoi problem\u003c/a\u003e with 3 rods (1, 2 \u0026 3), the goal is to move a tower of disks from rod #1 to rod #2.\r\nYou can move disks only one by one, on the rods.\r\nYou can't put a disk on a smaller one.\u003c/p\u003e\u003cp\u003eAt the beginning, all disks are on rod #1, biggest at the bottom, smallest at the top.\u003c/p\u003e\u003cp\u003eGive the number of moves necessary to solve the problem.\u003c/p\u003e","function_template":"function y = your_fcn_name(n)\r\n  y = 4;\r\nend","test_suite":"%%\r\nn = 1;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(n),y_correct))\r\n%%\r\nn = 2;\r\ny_correct = 3;\r\nassert(isequal(your_fcn_name(n),y_correct))\r\n%%\r\nn = 3;\r\ny_correct = 7;\r\nassert(isequal(your_fcn_name(n),y_correct))\r\n%%\r\nn = 4;\r\nlol_correct = 15;\r\nassert(isequal(your_fcn_name(n),lol_correct))\r\n%%\r\nn = 5;\r\ny_correct = 31;\r\nassert(isequal(your_fcn_name(n),y_correct))\r\n\r\n%%\r\nn = 6;\r\ny_correct = 63;\r\nassert(isequal(your_fcn_name(n),y_correct))","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":659,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":390,"test_suite_updated_at":"2012-01-31T00:18:45.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-01-30T23:38:24.000Z","updated_at":"2026-03-17T13:03:03.000Z","published_at":"2012-01-31T00:18: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\u003eIn the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Tower_of_Hanoi\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eTower of Hanoi problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e with 3 rods (1, 2 \u0026amp; 3), the goal is to move a tower of disks from rod #1 to rod #2. You can move disks only one by one, on the rods. You can't put a disk on a smaller one.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAt the beginning, all disks are on rod #1, biggest at the bottom, smallest at 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGive the number of moves necessary to solve the problem.\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":44763,"title":"Pumpkin Pie!","description":"It's time for desert at Thanksgiving. You've all gathered at grandma's house, and she's about to start cutting the pumpkin pie. You notice, though, that the same particular routine is always followed:\r\n - each guest tells her what fraction of the remaining pie they want\r\n - there are an arbitrary number of relatives present each year\r\n - you are next to last, since you always sit next to grandpa\r\n - grandpa is last, and will eat whatever is left\r\n    \u003e however, he should only eat up to 1/8 of the total pie, due to health problems\r\n    \u003e but, if you don't leave him 1/8 of the pie, you probably won't get a good Christmas present\r\nSo, you must calculate the fraction of what remains to eat such that 1/8 of the whole pie is left for grandpa. If whatever remains is less than or equal to 1/8, you can 'pass', and grandpa won't hold a grudge.\r\nYou must give grandma a fraction (in character format), though. She despises decimals, but loves to simplify fractions, so just ensure that the fraction you provide is close enough to the decimal value.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; 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: 263px; display: block; min-width: 0px; padding-block-start: 0px; padding-inline-start: 2px; padding-left: 2px; padding-top: 0px; perspective-origin: 408px 131.5px; transform-origin: 408px 131.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; 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: 373.417px 8px; transform-origin: 373.417px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIt's time for desert at Thanksgiving. You've all gathered at grandma's house, and she's about to start cutting the pumpkin pie. You notice, though, that the same particular routine is always followed:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 108px; 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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 404px 54px; transform-origin: 404px 54px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 18px; 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; font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; line-height: 18px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 9px; text-wrap-mode: nowrap; transform-origin: 404px 9px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(33, 33, 33); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(33, 33, 33); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(33, 33, 33); border-left-style: none; border-left-width: 0px; border-right-color: rgb(33, 33, 33); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 261.8px 8.5px; tab-size: 4; transform-origin: 261.8px 8.5px; unicode-bidi: normal; white-space-collapse: preserve; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 53.9px 8.5px; transform-origin: 53.9px 8.5px; \"\u003e - each guest \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(133, 22, 209); border-block-start-color: rgb(133, 22, 209); border-bottom-color: rgb(133, 22, 209); border-inline-end-color: rgb(133, 22, 209); border-inline-start-color: rgb(133, 22, 209); border-left-color: rgb(133, 22, 209); border-right-color: rgb(133, 22, 209); border-top-color: rgb(133, 22, 209); caret-color: rgb(133, 22, 209); color: rgb(133, 22, 209); column-rule-color: rgb(133, 22, 209); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(133, 22, 209); perspective-origin: 207.9px 8.5px; text-decoration-color: rgb(133, 22, 209); text-emphasis-color: rgb(133, 22, 209); transform-origin: 207.9px 8.5px; \"\u003etells her what fraction of the remaining pie they want\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 18px; 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; font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; line-height: 18px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 9px; text-wrap-mode: nowrap; transform-origin: 404px 9px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(33, 33, 33); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(33, 33, 33); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(33, 33, 33); border-left-style: none; border-left-width: 0px; border-right-color: rgb(33, 33, 33); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 242.55px 8.5px; tab-size: 4; transform-origin: 242.55px 8.5px; unicode-bidi: normal; white-space-collapse: preserve; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 50.05px 8.5px; transform-origin: 50.05px 8.5px; \"\u003e - there are \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(133, 22, 209); border-block-start-color: rgb(133, 22, 209); border-bottom-color: rgb(133, 22, 209); border-inline-end-color: rgb(133, 22, 209); border-inline-start-color: rgb(133, 22, 209); border-left-color: rgb(133, 22, 209); border-right-color: rgb(133, 22, 209); border-top-color: rgb(133, 22, 209); caret-color: rgb(133, 22, 209); color: rgb(133, 22, 209); column-rule-color: rgb(133, 22, 209); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(133, 22, 209); perspective-origin: 192.5px 8.5px; text-decoration-color: rgb(133, 22, 209); text-emphasis-color: rgb(133, 22, 209); transform-origin: 192.5px 8.5px; \"\u003ean arbitrary number of relatives present each year\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 18px; 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; font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; line-height: 18px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 9px; text-wrap-mode: nowrap; transform-origin: 404px 9px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(33, 33, 33); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(33, 33, 33); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(33, 33, 33); border-left-style: none; border-left-width: 0px; border-right-color: rgb(33, 33, 33); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 234.85px 8.5px; tab-size: 4; transform-origin: 234.85px 8.5px; unicode-bidi: normal; white-space-collapse: preserve; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 42.35px 8.5px; transform-origin: 42.35px 8.5px; \"\u003e - you are \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(133, 22, 209); border-block-start-color: rgb(133, 22, 209); border-bottom-color: rgb(133, 22, 209); border-inline-end-color: rgb(133, 22, 209); border-inline-start-color: rgb(133, 22, 209); border-left-color: rgb(133, 22, 209); border-right-color: rgb(133, 22, 209); border-top-color: rgb(133, 22, 209); caret-color: rgb(133, 22, 209); color: rgb(133, 22, 209); column-rule-color: rgb(133, 22, 209); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(133, 22, 209); perspective-origin: 46.2px 8.5px; text-decoration-color: rgb(133, 22, 209); text-emphasis-color: rgb(133, 22, 209); transform-origin: 46.2px 8.5px; \"\u003enext to last\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 30.8px 8.5px; transform-origin: 30.8px 8.5px; \"\u003e, since \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(133, 22, 209); border-block-start-color: rgb(133, 22, 209); border-bottom-color: rgb(133, 22, 209); border-inline-end-color: rgb(133, 22, 209); border-inline-start-color: rgb(133, 22, 209); border-left-color: rgb(133, 22, 209); border-right-color: rgb(133, 22, 209); border-top-color: rgb(133, 22, 209); caret-color: rgb(133, 22, 209); color: rgb(133, 22, 209); column-rule-color: rgb(133, 22, 209); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(133, 22, 209); perspective-origin: 115.5px 8.5px; text-decoration-color: rgb(133, 22, 209); text-emphasis-color: rgb(133, 22, 209); transform-origin: 115.5px 8.5px; \"\u003eyou always sit next to grandpa\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 18px; 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; font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; line-height: 18px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 9px; text-wrap-mode: nowrap; transform-origin: 404px 9px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(33, 33, 33); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(33, 33, 33); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(33, 33, 33); border-left-style: none; border-left-width: 0px; border-right-color: rgb(33, 33, 33); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 188.65px 8.5px; tab-size: 4; transform-origin: 188.65px 8.5px; unicode-bidi: normal; white-space-collapse: preserve; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 53.9px 8.5px; transform-origin: 53.9px 8.5px; \"\u003e - grandpa is \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(133, 22, 209); border-block-start-color: rgb(133, 22, 209); border-bottom-color: rgb(133, 22, 209); border-inline-end-color: rgb(133, 22, 209); border-inline-start-color: rgb(133, 22, 209); border-left-color: rgb(133, 22, 209); border-right-color: rgb(133, 22, 209); border-top-color: rgb(133, 22, 209); caret-color: rgb(133, 22, 209); color: rgb(133, 22, 209); column-rule-color: rgb(133, 22, 209); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(133, 22, 209); perspective-origin: 15.4px 8.5px; text-decoration-color: rgb(133, 22, 209); text-emphasis-color: rgb(133, 22, 209); transform-origin: 15.4px 8.5px; \"\u003elast\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 23.1px 8.5px; transform-origin: 23.1px 8.5px; \"\u003e, and \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(133, 22, 209); border-block-start-color: rgb(133, 22, 209); border-bottom-color: rgb(133, 22, 209); border-inline-end-color: rgb(133, 22, 209); border-inline-start-color: rgb(133, 22, 209); border-left-color: rgb(133, 22, 209); border-right-color: rgb(133, 22, 209); border-top-color: rgb(133, 22, 209); caret-color: rgb(133, 22, 209); color: rgb(133, 22, 209); column-rule-color: rgb(133, 22, 209); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(133, 22, 209); perspective-origin: 96.25px 8.5px; text-decoration-color: rgb(133, 22, 209); text-emphasis-color: rgb(133, 22, 209); transform-origin: 96.25px 8.5px; \"\u003ewill eat whatever is left\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 18px; 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; font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; line-height: 18px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 9px; text-wrap-mode: nowrap; transform-origin: 404px 9px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(33, 33, 33); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(33, 33, 33); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(33, 33, 33); border-left-style: none; border-left-width: 0px; border-right-color: rgb(33, 33, 33); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 323.4px 8.5px; tab-size: 4; transform-origin: 323.4px 8.5px; unicode-bidi: normal; white-space-collapse: preserve; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 69.3px 8.5px; transform-origin: 69.3px 8.5px; \"\u003e    \u0026gt; however, he \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(133, 22, 209); border-block-start-color: rgb(133, 22, 209); border-bottom-color: rgb(133, 22, 209); border-inline-end-color: rgb(133, 22, 209); border-inline-start-color: rgb(133, 22, 209); border-left-color: rgb(133, 22, 209); border-right-color: rgb(133, 22, 209); border-top-color: rgb(133, 22, 209); caret-color: rgb(133, 22, 209); color: rgb(133, 22, 209); column-rule-color: rgb(133, 22, 209); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(133, 22, 209); perspective-origin: 161.7px 8.5px; text-decoration-color: rgb(133, 22, 209); text-emphasis-color: rgb(133, 22, 209); transform-origin: 161.7px 8.5px; \"\u003eshould only eat up to 1/8 of the total pie\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 23.1px 8.5px; transform-origin: 23.1px 8.5px; \"\u003e, due \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(133, 22, 209); border-block-start-color: rgb(133, 22, 209); border-bottom-color: rgb(133, 22, 209); border-inline-end-color: rgb(133, 22, 209); border-inline-start-color: rgb(133, 22, 209); border-left-color: rgb(133, 22, 209); border-right-color: rgb(133, 22, 209); border-top-color: rgb(133, 22, 209); caret-color: rgb(133, 22, 209); color: rgb(133, 22, 209); column-rule-color: rgb(133, 22, 209); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(133, 22, 209); perspective-origin: 69.3px 8.5px; text-decoration-color: rgb(133, 22, 209); text-emphasis-color: rgb(133, 22, 209); transform-origin: 69.3px 8.5px; \"\u003eto health problems\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 18px; 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; font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; line-height: 18px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 9px; text-wrap-mode: nowrap; transform-origin: 404px 9px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(33, 33, 33); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(33, 33, 33); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(33, 33, 33); border-left-style: none; border-left-width: 0px; border-right-color: rgb(33, 33, 33); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 373.45px 8.5px; tab-size: 4; transform-origin: 373.45px 8.5px; unicode-bidi: normal; white-space-collapse: preserve; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 42.35px 8.5px; transform-origin: 42.35px 8.5px; \"\u003e    \u0026gt; but, \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(14, 0, 255); border-block-start-color: rgb(14, 0, 255); border-bottom-color: rgb(14, 0, 255); border-inline-end-color: rgb(14, 0, 255); border-inline-start-color: rgb(14, 0, 255); border-left-color: rgb(14, 0, 255); border-right-color: rgb(14, 0, 255); border-top-color: rgb(14, 0, 255); caret-color: rgb(14, 0, 255); color: rgb(14, 0, 255); column-rule-color: rgb(14, 0, 255); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(14, 0, 255); perspective-origin: 11.55px 8.5px; text-decoration-color: rgb(14, 0, 255); text-emphasis-color: rgb(14, 0, 255); transform-origin: 11.55px 8.5px; \"\u003eif \u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 61.6px 8.5px; transform-origin: 61.6px 8.5px; \"\u003eyou don't leave \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(133, 22, 209); border-block-start-color: rgb(133, 22, 209); border-bottom-color: rgb(133, 22, 209); border-inline-end-color: rgb(133, 22, 209); border-inline-start-color: rgb(133, 22, 209); border-left-color: rgb(133, 22, 209); border-right-color: rgb(133, 22, 209); border-top-color: rgb(133, 22, 209); caret-color: rgb(133, 22, 209); color: rgb(133, 22, 209); column-rule-color: rgb(133, 22, 209); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(133, 22, 209); perspective-origin: 69.3px 8.5px; text-decoration-color: rgb(133, 22, 209); text-emphasis-color: rgb(133, 22, 209); transform-origin: 69.3px 8.5px; \"\u003ehim 1/8 of the pie\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 23.1px 8.5px; transform-origin: 23.1px 8.5px; \"\u003e, you \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(133, 22, 209); border-block-start-color: rgb(133, 22, 209); border-bottom-color: rgb(133, 22, 209); border-inline-end-color: rgb(133, 22, 209); border-inline-start-color: rgb(133, 22, 209); border-left-color: rgb(133, 22, 209); border-right-color: rgb(133, 22, 209); border-top-color: rgb(133, 22, 209); caret-color: rgb(133, 22, 209); color: rgb(133, 22, 209); column-rule-color: rgb(133, 22, 209); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(133, 22, 209); perspective-origin: 34.65px 8.5px; text-decoration-color: rgb(133, 22, 209); text-emphasis-color: rgb(133, 22, 209); transform-origin: 34.65px 8.5px; \"\u003eprobably \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(144, 38, 34); border-block-start-color: rgb(144, 38, 34); border-bottom-color: rgb(144, 38, 34); border-inline-end-color: rgb(144, 38, 34); border-inline-start-color: rgb(144, 38, 34); border-left-color: rgb(144, 38, 34); border-right-color: rgb(144, 38, 34); border-top-color: rgb(144, 38, 34); caret-color: rgb(144, 38, 34); color: rgb(144, 38, 34); column-rule-color: rgb(144, 38, 34); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(144, 38, 34); perspective-origin: 130.9px 8.5px; text-decoration-color: rgb(144, 38, 34); text-emphasis-color: rgb(144, 38, 34); transform-origin: 130.9px 8.5px; \"\u003ewon't get a good Christmas present\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 10px; 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: 366.758px 8px; transform-origin: 366.758px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSo, you must calculate the fraction of what remains to eat such that 1/8 of the whole pie is left for grandpa. If whatever remains is less than or equal to 1/8, you can 'pass', and grandpa won't hold a grudge.\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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; 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: 376.25px 8px; transform-origin: 376.25px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou must give grandma a fraction (in character format), though. She despises decimals, but loves to simplify fractions, so just ensure that the fraction you provide is close enough to the decimal value.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function slice_fraction = pumpkin_pie(already_cut_fractions)\r\n    slice_fraction = 'pass';\r\nend","test_suite":"%% not 1/2 of the remainder\r\nalready_cut_fractions = [1/4 1/4 1/4];\r\nslice_fraction = pumpkin_pie(already_cut_fractions);\r\nassert(ischar(slice_fraction))\r\nstr_parts = cellfun(@str2num,regexp(slice_fraction,'/','split'));\r\nassert(numel(str_parts)==2)\r\nslice_dec = str_parts(1) / str_parts(2);\r\nassert(abs(slice_dec - 0.704)\u003c1e-2)\r\nassert(str_parts(2)~=1)\r\n\r\n%% unlucky you (and a few greedy relatives)\r\nalready_cut_fractions = [1/2 1/2 1/2];\r\nslice_fraction = pumpkin_pie(already_cut_fractions);\r\nassert(strcmpi(slice_fraction,'pass'))\r\n\r\n%% unlucky you again (too many relatives this time)\r\nalready_cut_fractions = [1/4 1/4 1/4 1/4 1/4 1/4 1/4 1/4];\r\nslice_fraction = pumpkin_pie(already_cut_fractions);\r\nassert(strcmpi(slice_fraction,'pass'))\r\n\r\n%% Yum!\r\nalready_cut_fractions = [1/8 1/8 1/8 1/8];\r\nslice_fraction = pumpkin_pie(already_cut_fractions);\r\nassert(ischar(slice_fraction))\r\nstr_parts = cellfun(@str2num,regexp(slice_fraction,'/','split'));\r\nassert(numel(str_parts)==2)\r\nslice_dec = str_parts(1) / str_parts(2);\r\nassert(abs(slice_dec - 0.787)\u003c1e-2)\r\nassert(str_parts(2)~=1)\r\n\r\n%% most of your relatives had the flu this year; now don't get sick from eating too much\r\nalready_cut_fractions = [1/16 1/32];\r\nslice_fraction = pumpkin_pie(already_cut_fractions);\r\nassert(ischar(slice_fraction))\r\nstr_parts = cellfun(@str2num,regexp(slice_fraction,'/','split'));\r\nassert(numel(str_parts)==2)\r\nslice_dec = str_parts(1) / str_parts(2);\r\nassert(abs(slice_dec - 0.862)\u003c1e-2)\r\nassert(str_parts(2)~=1)\r\n\r\n%% they're a motley crew\r\nalready_cut_fractions = [1/7 1/5 1/6 1/4 1/8 1/10 1/9];\r\nslice_fraction = pumpkin_pie(already_cut_fractions);\r\nassert(ischar(slice_fraction))\r\nstr_parts = cellfun(@str2num,regexp(slice_fraction,'/','split'));\r\nassert(numel(str_parts)==2)\r\nslice_dec = str_parts(1) / str_parts(2);\r\nassert(abs(slice_dec - 0.583)\u003c1e-2)\r\nassert(str_parts(2)~=1)\r\n\r\n%% death by a thousand paper cuts...and where did all those relatives come from?\r\nalready_cut_fractions = 1/16 * ones(1,33);\r\nslice_fraction = pumpkin_pie(already_cut_fractions);\r\nassert(strcmpi(slice_fraction,'pass'))\r\n\r\n%% all it takes is one jerk to spoil it for everyone else\r\nalready_cut_fractions = 7/8;\r\nslice_fraction = pumpkin_pie(already_cut_fractions);\r\nassert(strcmpi(slice_fraction,'pass'))\r\n\r\n%% quite the odd bunch...\r\nalready_cut_fractions = [1/3 1/5 1/7 1/11 1/13 1/17 1/19 1/23 1/29 1/31];\r\nslice_fraction = pumpkin_pie(already_cut_fractions);\r\nassert(ischar(slice_fraction))\r\nstr_parts = cellfun(@str2num,regexp(slice_fraction,'/','split'));\r\nassert(numel(str_parts)==2)\r\nslice_dec = str_parts(1) / str_parts(2);\r\nassert(abs(slice_dec - 0.591)\u003c1e-2)\r\nassert(str_parts(2)~=1)\r\n\r\n%% something is better than nothing, right?\r\nalready_cut_fractions = [1/3 1/4 1/2 1/3 1/6];\r\nslice_fraction = pumpkin_pie(already_cut_fractions);\r\nassert(ischar(slice_fraction))\r\nstr_parts = cellfun(@str2num,regexp(slice_fraction,'/','split'));\r\nassert(numel(str_parts)==2)\r\nslice_dec = str_parts(1) / str_parts(2);\r\nassert(abs(slice_dec - 0.1)\u003c1e-2)\r\nassert(str_parts(2)~=1)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":26769,"edited_by":223089,"edited_at":"2025-12-29T14:59:09.000Z","deleted_by":null,"deleted_at":null,"solvers_count":21,"test_suite_updated_at":"2025-12-29T14:59:09.000Z","rescore_all_solutions":false,"group_id":52,"created_at":"2018-10-31T14:07:08.000Z","updated_at":"2026-03-30T18:56:15.000Z","published_at":"2018-10-31T14:07:08.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\u003eIt's time for desert at Thanksgiving. You've all gathered at grandma's house, and she's about to start cutting the pumpkin pie. You notice, though, that the same particular routine is always followed:\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[ - each guest tells her what fraction of the remaining pie they want\\n - there are an arbitrary number of relatives present each year\\n - you are next to last, since you always sit next to grandpa\\n - grandpa is last, and will eat whatever is left\\n    \u003e however, he should only eat up to 1/8 of the total pie, due to health problems\\n    \u003e but, if you don't leave him 1/8 of the pie, you probably won't get a good Christmas present]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSo, you must calculate the fraction of what remains to eat such that 1/8 of the whole pie is left for grandpa. If whatever remains is less than or equal to 1/8, you can 'pass', and grandpa won't hold a grudge.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 must give grandma a fraction (in character format), though. She despises decimals, but loves to simplify fractions, so just ensure that the fraction you provide is close enough to the decimal value.\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":199,"title":"hanoi towers II","description":"with 3 rods (1,2 \u0026 3), the goal is to move a tower of n disks from rod #1 to rod #3.\r\nYou can move disks only one by one, on the rods.\r\nYou can't put a disk on a smaller one.\r\n\r\nAt the beginning, all disks are on rod #1, biggest at the bottom, smallest at the top.\r\n\r\nGive the smallest sequence of unused rods for a n disks Hanoi tower problem.","description_html":"\u003cp\u003ewith 3 rods (1,2 \u0026 3), the goal is to move a tower of n disks from rod #1 to rod #3.\r\nYou can move disks only one by one, on the rods.\r\nYou can't put a disk on a smaller one.\u003c/p\u003e\u003cp\u003eAt the beginning, all disks are on rod #1, biggest at the bottom, smallest at the top.\u003c/p\u003e\u003cp\u003eGive the smallest sequence of unused rods for a n disks Hanoi tower problem.\u003c/p\u003e","function_template":"function mytry = unHanoingProblem(n)\r\n  mytry = [2];\r\nend","test_suite":"%%\r\nn = 1;\r\ny_correct = [2];\r\nassert(isequal(unHanoingProblem(n),y_correct))\r\n\r\n%%\r\nn = 3;\r\ny_correct = [1 3 3 7];\r\nassert(isequal(unHanoingProblem(3),[2 3 1 2 3 1 2]))\r\n\r\n%%\r\nn = 6;\r\ny_correct = [2 3 1 2 3 1 2];\r\nassert(isequal(unHanoingProblem(n),[3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1]))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":659,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":80,"test_suite_updated_at":"2012-01-31T16:58:14.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-01-31T16:58:14.000Z","updated_at":"2026-02-15T07:05:56.000Z","published_at":"2012-01-31T16:59:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ewith 3 rods (1,2 \u0026amp; 3), the goal is to move a tower of n disks from rod #1 to rod #3. You can move disks only one by one, on the rods. You can't put a disk on a smaller one.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAt the beginning, all disks are on rod #1, biggest at the bottom, smallest at 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\u003eGive the smallest sequence of unused rods for a n disks Hanoi tower problem.\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":306,"title":"Eight Queens Solution Checker","description":"Write a function to verify whether an arrangement of queens on a chessboard is a valid solution to the classic eight queens problem.\r\nIn the eight queens problem, eight queens must be placed on a chessboard such that no two queens attack each other. That is, no two queens can share the same row, column, or diagonal. The diagram below is one possible solution:\r\n\r\nYour function should take an 8-by-8 matrix of 0s and 1s, where the 1s represent the position of the queens, and return a logical 1 if the solution is valid or a logical 0 otherwise.\r\nEXAMPLE 1\r\n   in1 = [ ...\r\n       0 0 0 1 0 0 0 0\r\n       0 0 0 0 0 0 1 0\r\n       0 0 1 0 0 0 0 0\r\n       0 0 0 0 0 0 0 1\r\n       0 1 0 0 0 0 0 0\r\n       0 0 0 0 1 0 0 0\r\n       1 0 0 0 0 0 0 0\r\n       0 0 0 0 0 1 0 0 ];\r\n\r\n   isEightQueensSolution(in1)\r\nreturns 1.\r\nEXAMPLE 2\r\n   in2 = [ ...\r\n       0 0 0 1 0 0 0 0\r\n       0 0 0 0 0 0 1 0\r\n       0 0 1 0 0 0 0 0\r\n       0 0 0 0 0 0 0 1\r\n       0 1 0 0 0 0 0 0\r\n       1 0 0 0 0 0 0 0\r\n       0 0 0 0 1 0 0 0\r\n       0 0 0 0 0 1 0 0 ];\r\n\r\n   isEightQueensSolution(in2)\r\nreturns 0. (Notice that the queens on the bottom two rows share a diagonal.)","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: 1032.03px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 516.017px; transform-origin: 407px 516.017px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 343.5px 8px; transform-origin: 343.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to verify whether an arrangement of queens on a chessboard is a valid solution to the classic\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=\"\"\u003eeight queens problem\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 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: 377.5px 8px; transform-origin: 377.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIn the eight queens problem, eight queens must be placed on a chessboard such that no two queens attack each other. That is, no two queens can share the same row, column, or diagonal. The diagram below is one possible solution:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 287.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 143.75px; text-align: center; transform-origin: 384px 143.75px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cimg class=\"imageNode\" style=\"vertical-align: baseline\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAARoAAAEaCAIAAABB0Q/tAAAXF0lEQVR42u2de2xVVdrGe6X0tKXtodRS6rHtqYci6MBQoZCGaYDwqcOIgwQQIVSFMioKgToIRjJgIChyB8XCAFViJhnjhcmIcdAQnBj+KF4y/uGFQWIMIpLSeKmkgHxPu5jFbu33TTzdhdOu385mZ593v2vlPH3XL2uvczj7iXuGjY3Npy1O/y5ebLwy+6C6Z6/MjiIUXXlF4IQiFIFTty3VwB2bw2tX6sjgAydK9QsUFa9efu3i+ZHt622kcMXS5H45cXFxOurcxiPPrCt4eJ7ywQmcKFUHe+6MKUkpKcFgMDm3X8m6VSYYGFy6cOHCr776Skedm6Amq6S+2cpUvlqBEzi5XqqBz23oP2dW/7mzzVxUumtrQiD1pZdeam5unjx5cva435i03oWhTZs2Xbx4UUedm6CuKkeZylcrtb3U4dzZ6lMn4ARODpWqdPe2wKCBxcXF4XC4V16u1kVCIj4l5Y033rhw4cLdd9+dVVlh3pUIyczKmjZtmo46N0FdVY4yla9WaqseUsNF6q2kpCQwsGRg7SZwAidXShVauqhfv35nzpw5d+5cXl6eVkEK5ky6LSUlRUgkZWUWr/mTfWN5VTO0dtLRu8RKTE9TpvLVShH1oHu/pqams2fPqmctwMAJnFwp1XXLFmdkZHz++efffPNNdnZ2wYI/mPdQ9MRjWjgFbx3vfWOhJQuEU8HC+71B5ShT+TZH/ai3r7/+Wj2rf3ACJ4dKpRs2QRIfHx8ojXg/BE+NhJNz+nojudMmK1NH70fnmp2U6X3/unuMb93Sf/0r1k7g5FypNLcIkpRQQemft3hxEjyhRx62kcyKUYr0GVlmI5rNFPHipB70Ur3Z+QqcwMm5Umn0C4z+985sh1PGiOE2knLtgJqaml55uaW7t5mIrrbDST0o4mUJnMDJuVJdv3VtXEJCYkZGZNvTFqfa2tqUQOD6TWvMfV18YuInn3ySkJBg7gAV11XlWJzUVj2oH/UGTuDkdKmS+mZrYrFfNAmSt956a8KECdfMnNryocXjj2RnZ1+8eLGgoEDniiiuq8qxOKmtelA/fI0LTq6Xqndx4cSJE9PS04tWLrM41dXVaU3VAs+saePHjxdOOuq85d4vVKCrFie1Ulv1oH7ACZxcL1XGzcNWrVq1bNmy1HCRVkcGp8bGxozMzMIVS7PHVz700EPCacmSJZkVoxRRXFcNTi354aIFCxZs2LBB/YATOLleqn5TJs2cOfO7777Lycnpf+/M1JJiofLTTz/dd999WZUVmot2796tl3v27OmVl6uI4nrZglNJsfLVSm3nzZunfsAJnFwvVf68e8rKyjT/PP/883Gt2/79+48cObJmzRrzcvbs2XPnzq2pqTEvX3zxxc8++0w4mZdqpbZjxoxRP+AETq6X6rpli3v37v3jjz9qzhk+fLj5bjeu7Zafn2/PzdXi4mIdlf9T69avXz/vV1XgBE6OliryzDqBoQlq9erVo0ePNvC88sor69evv/322++66y5NR+fOndu4ceOwYcMGDx68dOlSXe3bt68y58yZs2PHjttuu03n9qN2cAInd0s1cMfmhLRAOBy+s3V74oknTp06pQlHt3A//d/bp59+Wl1dXVpaOmjQILVVDz//uS41AicXSxW8ZdzIkSObm5vFSWNj47Fjx15r3TRBPd52U8RcUo4yla9Waqse+PkgOFGq1v8bseXJxMw+lZWVQ4cOTUtLCwQCupe78cYb/6ejTfDoqnKUqXy1Ulv1AE7gRKku7TmTf6f1z65duz788MMzZ87815s95Rw9enT37t3XXHON2vLjdnCiVJf3wuV/FE66c/vyyy/feeedLVu2bNiwYcWKFTPabvPnz9/Quh04cEDLp6amppSUFLUFJ3CiVJf30l1bhdOAAQPi4+NLS0tvvvnmOXPm3N/RpriuKsd+nm6eFQFO4ESp2uBUV1d34cIF703d/3PLp0zlgxM4Uar2e+jRhQLjhx9+OHLkiCBZuHCh7uumTJlS3nZTRHFdVY4yld/yW8NHF4ITOFGqNs9+EBi9e/c2X+OOGTNm2rRpjz322NNtN0UUv/XWW4uKimx+u2dLgBM4uV6q1HALHs8999wXX3xhvoD6r5syX3jhhZaf5YaLwAmcKNV/Fk67t2VWjIrvlXzDDTfMmzdv48aN+/btq6+v/6qjTXFdXbVq1axZs5Qfl5DQZ2RZh8snagRO7pYqsu3p/Hn3BG8ZlzZkUMqA/IS0QEIgtd3/hVVE8eScvspRpvI7/AIXnMCJUnUwa4XXrvTu9ukrOGiAE6VCEYrACUUo6lKc+AuiCEWd38EJRSgCJwafe4pi3wcVnFAUi4q6qQ8qOKEo5hR1Xx9UcELRVVbUk3xQwQlFV1NRD/NBBScUXU1FPcwHFZxQdDUV9TAfVHBC0VVW1JN8UMEJRVdfUY/xQQUnFMWEop7hgwpOKIoJRT3DBxWcUBQrinqADyo4oShWFPUAH1RwQlGsKOoBPqjghKJYUdQDfFDBCUWxoqgH+KCCE4piRVEP8EEFJxTFiqIe4IMKTiiKFUU9wAcVnFAUQ4q6uw8qOKEohhR1dx9UcEJRbCnq1j6o4ISi2FLUrX1QwQlFsWjc2E19UMEJRbGIUzf1QQUnFMWWom7tgwpOKIotRd3aBxWcUBRbirq1Dyo4oSiGFHV3H1RwQlHMKeq+PqjghKJuoKi7+KCCE4pQBE4MPhTFLE78BVGEos7v4IQiFIGT36Vqajp59Oj7OjL4UAROv6BUH310+PXX/9rY+IWN1NcfLC4ubH3wQKHObbyh4fjLL+9VPoMPReDUwb5+/erU1NRgMFhSUnz8+L9McPz4SmsUqXMT1GQVChUoU/lqxeBDkes4ffvtl7t2bduz51kzFzU3n87KyrRGkQ88MMeklZUNs0aROjdBXbVGkWqltqZD9aY+dcLgQ5FDOJ0/3zB27BhjFBmJhLUuEhLp6WnWKLK6usq8KxGS1WoUqaPOTVBXrVGkWqmteigvLzNGkWPGjP7++xMMPhS5gtPBg3/3GkVqFaTg8uVLjFFkfn7exx/X2ze2ffsGrZ109C6xcnKCxihSrRRRD16jSC3AGHwocgWnQ4f2e40iX331RfMePvjgn1o41dQ85H1jBw68Jpz27fuLN6gcZSrf5niNItU/gw9FDq2ddMNmHhdaWVnh/RC8oqK8sDDkjTz11Epl6uj96FyzkzK97193j8Yo8o47fsvgQ5Fzn+xpbhEkQ4feePbsKS9OgufNN1+xkapWV/Dp0++0Ec1minhxUg96qd7sfMXgQ5FzH5Rr9AuMnTu3tMNp6tTf28hNNw2uqamJRMLnzzeYiK62w0k9KOJlicGHIudwOnXq30lJibm5OadPH7M41dbWav1z4sQn5r4uOTnJGEWaO0DFdVU5Fie1VQ/qR70x+FDk9Ne4oVCBJhb7RZMgMUaRmzc/qZfvvvsPaxSpc0UUN0aRFie1bXm4R6iAwYci13EaMWL4xIkT09PT33vvkMWprq5Oayq93Lp1rTWK1LkiihujSIOTWqW3GkWqHwYfilzHacqUScYosry8TKsjg1NjY2NWVlZ9/cH586utUWRV1QxFFDdGkcpUvloZo0j1w+BDkes4rV693BpF7ty5ZfToEdYosrq6SnORNYqMRMKKWKNIZSrfGkWqHwYfilzHae/eWl+MItUPgw9FruN06NB+X4wivV9VMfhQ5ChODQ3HfTGKtB+1M/hQ5C5OTU0ng8HsThpFqoef/1yXwYciF38+uGjRg500ilQPDD4UgVPLfvLkZ3l5uVEbRaqtemDwoQicLu0rVy6L2ihSbRl8KAKny/vhwweiNopUWwYfisDp8t7cfDpqo0jzrAgGH4rAqQ1O0RlFghOKwKnN/vbbf4vaKFJtGXwoAqc2z36I2iiy3bMlGHwoch2n8vKyqI0i1ZbBhyJwurSfP99QVTUjEEiNwigyKSlx+vQ7O1w+MfhQ5O5DlU+fPrZ3b+2iRQ9OmDB2yJBBwWB2VlZmu/8Lq4jihYUh5ShT+R1+gcvgQxGP/O9g1jp69H3vbp++wuBDETgx+FAETpQKRT0DJ/6CKEJR53dwQhGKwInBh6IuUxS1sys4ochpRf46u4ITitxV5LuzKzihyBVFV8DZFZxQ5ISiK+PsCk4ockLRlXF2BScUOaHoyji7ghOKXFF0BZxdwQlFDinqamdXcEKRW4q61NkVnFDklqIudXYFJxQ5p6jrnF3BCUXOKeo6Z1dwQpFzirrO2RWcUOScoq5zdgUnFDmnqOucXcEJRc4p6jpnV3BCkXOKus7ZFZxQ5JyirnN2BScUuaioi5xdwQlFLirqImdXcEKRo4q6wtkVnFDkqKKucHYFJxQ5qqgrnF3BCUVO4+Svsys4ochRRV3h7ApOKHJUUVc4u4ITihxV1BXOruCEIhcVdZGzKzihyF1Fvju7ghOKUNRm1uqMsys4oQhF+Dsx+FAUszjxF0QRijq/gxOKUOQMTgN3bA6vXakjpUIROP0CYcWrl1+7eH5k+3obKVyxNLlfTlxcnI46t/HIM+sKHp6nfAYfisCpgz13xpSklJRgMJic269k3SoTDAwutbaKOjdBTVZJfbOVqXy1YvChyHWcBj63of+cWf3nzjZzUemurQmBVGurmD3uNyatd2HI2irq3AR11doqqpXaXupw7mz1qRMGH4ocwql097bAoIHGVrFXXq7WRUIiPiXF2ipmVVaYNydCMlttFXXUuQnqqrVVVCu1VQ+p4SJjqxgYWDKwdhODD0Wu4BRaushrq6hVkII5k24ztopJWZnFa/5k319eq9OOjt4lVmJ6mrFVVCtF1IPXVlELMAYfilzB6bpli722igUL/mDeStETj2nhFLx1vPf9hZYsEE4FC+/3BpWjTOXbHK+tovpn8KHIobWTbtjMwzUDpRHvh+CpkXByTl9vJHfaZGXq6P3oXLOTMr0ydPdobBXTf/0rBh+KnPtkT3OLIEkJFZT+eYsXpxbbnEcetpHMilGK9BlZZiOazRTx4qQe9FK92fmKwYci5z4o1+gXGP3vndkOp4wRw20k5doBNTU1vfJyS3dvMxFdbYeTelDEyxKDD0XO4XT91rVxCQmJGRmRbU9bnGpra1MCges3rTH3dfGJicZW0dwBKq6ryrE4qa16UD/qjcGHIqe/xk3qm62JxX7RJEiMreI1M6e2fGjx+CPWVlHniihubBUtTmqrHtQPgw9FruPUu7hw4sSJaenpRSuXWZzq6uq0pmqBZ9Y0a6uo85Z7v1CBsVU0OKlVWqutovph8KHIdZwybh5mbBVTw0VaHRmcGhsbMzIzC1cszR5faW0VMytGKaK4sVVUZkt+uMjYKqofBh+KXMep35RJ1lax/70zU0uKra1iVmWF5iJrq9grL1cRa6uoTOVbW0X1w+BDkes45c+7xxdbRfXD4EOR6zhdt2yxL7aK3q+qGHwochSnyDPrfLFVtB+1M/hQ5C5OA3dsTkgLdNJWUT38/Oe6DD4UufjzweAt4zppq6geGHwoAqfW/xux5cnEzD5R2yqqrXpg8KEInC7tOZN/F7Wtotoy+FAETpf3wuV/jNpWUW0ZfCgCp8t76a6tUdsqmmdFMPhQBE5tcIrOVhGcUARObfbQowujtlVUWwYfisCpzbMforZVbPdsCQYfilzHKTVcFLWtotoy+FAETv9ZOO3ellkxKr5XchS2inEJCX1GlnW4fGLwocjdhypHtj2dP++e4C3j0oYMShmQn5AWSAiktvu/sIoonpzTVznKVH6HX+Ay+FDEI/87mLXCa1d6d/v0FQYfisCJUqEInCgVilD0i3DiL4giFHV+BycUoQicGHz/bccHFZwoVTSK8EEFJ0rljyJ8UMGJUkWpCB9UcAInfxThgwpO4OSbInxQwQmcfFOEDyo4gZOfivBBBSdw8lMRPqjgRKn8VIQPKjhRKt8U4YMKTpTKT0X4oIITpfJNET6o4ESpfFOEDyo4USrfFOGDCk6UyjdF+KCCE6XyTRE+qOBEqXxThA8qOFEq3xThgwpOlMpPRfigghOl8k0RPqjgRKn8VIQPKjhRKt8U4YMKTpTKN0X4oIITpfIZJ3xQwYlS+aAIH1RwolS+KcIHFZwolW+K8EEFJ0rljyJ8UMGJUvmsCB9UcKJUXagIH1RwolQoAidKhSIUtcOJvyCKUNT5HZxQhKKrjVNT08mjR9/XkVKhCEW/AKePPjr8+ut/bWz8wkbq6w8WFxe2PnigUOc23tBw/OWX9yqfUqEInDrY169fnZqaGgwGS0qKjx//lwmOH19pjSJ1boKarEKhAmUqX60oFYpcx+nbb7/ctWvbnj3Pmrmoufl0VlamNYp84IE5Jq2sbJg1itS5CeqqNYpUK7U1Hao39akTSoUih3A6f75h7NgxxigyEglrXSQk0tPTrFFkdXWVeXMiJKvVKFJHnZugrlqjSLVSW/VQXl5mjCLHjBn9/fcnKBWKXMHp4MG/e40itQpScPnyJcYoMj8/7+OP6+372759g9ZOOnqXWDk5QWMUqVaKqAevUaQWYJQKRa7gdOjQfq9R5Kuvvmjeygcf/FMLp5qah7zv78CB14TTvn1/8QaVo0zl2xyvUaT6p1QocmjtpBs287jQysoK74fgFRXlhYUhb+Spp1YqU0fvR+eanZTplaG7R2MUeccdv6VUKHLukz3NLYJk6NAbz5495cVJ8Lz55is2UtXqCj59+p02otlMES9O6kEv1ZudrygVipz7oFyjX2Ds3LmlHU5Tp/7eRm66aXBNTU0kEj5/vsFEdLUdTupBES9LlApFzuF06tS/k5ISc3NzTp8+ZnGqra3V+ufEiU/MfV1ycpIxijR3gIrrqnIsTmqrHtSPeqNUKHL6a9xQqEATi/2iSZAYo8jNm5/Uy3ff/Yc1itS5Ioobo0iLk9q2PNwjVECpUOQ6TiNGDJ84cWJ6evp77x2yONXV1WlNpZdbt661RpE6V0RxYxRpcFKr9FajSPVDqVDkOk5TpkwyRpHl5WVaHRmcGhsbs7Ky6usPzp9fbY0iq6pmKKK4MYpUpvLVyhhFqh9KhSLXcVq9erk1ity5c8vo0SOsUWR1dZXmImsUGYmEFbFGkcpUvjWKVD+UCkWu47R3b60vRpHqh1KhyHWcDh3a74tRpPerKkqFIkdxamg47otRpP2onVKhyF2cmppOBoPZnTSKVA8//7kupUKRiz8fXLTowU4aRaoHSoUicGrZT578LC8vN2qjSLVVD5QKReB0aV+5clnURpFqS6lQBE6X98OHD0RtFKm2lApF4HR5b24+HbVRpHlWBKVCETi1wSk6o0hwQhE4tdnffvtvURtFqi2lQhE4tXn2Q9RGke2eLUGpUOQ6TuXlZVEbRaotpUIROF3az59vqKqaEQikRmEUmZSUOH36nR0unygVitx9qPLp08f27q1dtOjBCRPGDhkyKBjMzsrKbPd/YRVRvLAwpBxlKr/DL3ApFYp45H8Hs9bRo+97d/v0FUqFInDC3wlFKAInBh+KYhMn/oIoQlHnd3BCEYrAicEXM4pwdgUnFEWjCGdXcEKRP4pwdgUnFEWpCGdXcAInfxTh7ApO4OSbIpxdwQmcfFOEsys4gZOfinB2BSdw8lMRzq7gBE5+KsLZFZzAyTdFOLuCEzj5qQhnV3ACJ98U4ewKTuDkmyKcXcEJnHxThLMrOIGTb4pwdgUncPJNEc6u4AROvinC2RWcwMk3RTi7ghM4+akIZ1dwQpFvinB2BScU+akIZ1dwQpFvinB2BScU+aYIZ1dwQpHPOOHsCk4o8kERzq7ghCLfFOHsCk4o8k0Rzq7ghCJ/FOHsCk4o8lkRzq7ghKIuVISzKzihCEXgxOBDUXfBiY2NzZftfwHAyDu2GXeLKAAAAABJRU5ErkJggg==\" data-image-state=\"image-loaded\"\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: 380px 8px; transform-origin: 380px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYour function should take an 8-by-8 matrix of 0s and 1s, where the 1s represent the position of the queens, and return a logical 1 if the solution is valid or a logical 0 otherwise.\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: 39px 8px; transform-origin: 39px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eEXAMPLE 1\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 224.767px; 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 112.383px; transform-origin: 404px 112.383px; 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: 56px 8.5px; tab-size: 4; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 44px 8.5px; transform-origin: 44px 8.5px; \"\u003e   in1 = [ \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(14, 0, 255); border-block-start-color: rgb(14, 0, 255); border-bottom-color: rgb(14, 0, 255); border-inline-end-color: rgb(14, 0, 255); border-inline-start-color: rgb(14, 0, 255); border-left-color: rgb(14, 0, 255); border-right-color: rgb(14, 0, 255); border-top-color: rgb(14, 0, 255); caret-color: rgb(14, 0, 255); color: rgb(14, 0, 255); column-rule-color: rgb(14, 0, 255); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(14, 0, 255); perspective-origin: 12px 8.5px; text-decoration: none; text-decoration-color: rgb(14, 0, 255); text-emphasis-color: rgb(14, 0, 255); transform-origin: 12px 8.5px; \"\u003e...\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: 88px 8.5px; tab-size: 4; transform-origin: 88px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 0 0 1 0 0 0 0\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: 88px 8.5px; tab-size: 4; transform-origin: 88px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 0 0 0 0 0 1 0\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: 88px 8.5px; tab-size: 4; transform-origin: 88px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 0 1 0 0 0 0 0\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: 88px 8.5px; tab-size: 4; transform-origin: 88px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 0 0 0 0 0 0 1\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 88px 8.5px; tab-size: 4; transform-origin: 88px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 1 0 0 0 0 0 0\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: 88px 8.5px; tab-size: 4; transform-origin: 88px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 0 0 0 1 0 0 0\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: 88px 8.5px; tab-size: 4; transform-origin: 88px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       1 0 0 0 0 0 0 0\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: 100px 8.5px; tab-size: 4; transform-origin: 100px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 0 0 0 0 1 0 0 ];\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: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 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: 116px 8.5px; tab-size: 4; transform-origin: 116px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e   isEightQueensSolution(in1)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 30.5px 8px; transform-origin: 30.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ereturns 1.\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: 39px 8px; transform-origin: 39px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eEXAMPLE 2\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 224.767px; 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 112.383px; transform-origin: 404px 112.383px; 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: 56px 8.5px; tab-size: 4; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 44px 8.5px; transform-origin: 44px 8.5px; \"\u003e   in2 = [ \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(14, 0, 255); border-block-start-color: rgb(14, 0, 255); border-bottom-color: rgb(14, 0, 255); border-inline-end-color: rgb(14, 0, 255); border-inline-start-color: rgb(14, 0, 255); border-left-color: rgb(14, 0, 255); border-right-color: rgb(14, 0, 255); border-top-color: rgb(14, 0, 255); caret-color: rgb(14, 0, 255); color: rgb(14, 0, 255); column-rule-color: rgb(14, 0, 255); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(14, 0, 255); perspective-origin: 12px 8.5px; text-decoration: none; text-decoration-color: rgb(14, 0, 255); text-emphasis-color: rgb(14, 0, 255); transform-origin: 12px 8.5px; \"\u003e...\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: 88px 8.5px; tab-size: 4; transform-origin: 88px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 0 0 1 0 0 0 0\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: 88px 8.5px; tab-size: 4; transform-origin: 88px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 0 0 0 0 0 1 0\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: 88px 8.5px; tab-size: 4; transform-origin: 88px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 0 1 0 0 0 0 0\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: 88px 8.5px; tab-size: 4; transform-origin: 88px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 0 0 0 0 0 0 1\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 88px 8.5px; tab-size: 4; transform-origin: 88px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 1 0 0 0 0 0 0\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: 88px 8.5px; tab-size: 4; transform-origin: 88px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       1 0 0 0 0 0 0 0\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: 88px 8.5px; tab-size: 4; transform-origin: 88px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 0 0 0 1 0 0 0\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: 100px 8.5px; tab-size: 4; transform-origin: 100px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       0 0 0 0 0 1 0 0 ];\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: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 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: 116px 8.5px; tab-size: 4; transform-origin: 116px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e   isEightQueensSolution(in2)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 240px 8px; transform-origin: 240px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ereturns 0. (Notice that the queens on the bottom two rows share a diagonal.)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = isEightQueensSolution(x)\r\n  y = x;\r\nend","test_suite":"%% Eight Queens Solution Checker Test Suite\r\n\r\n%%\r\n% Unique solution #6 from \r\n% http://en.wikipedia.org/wiki/Eight_queens_puzzle\r\nin1 = [ ...\r\n    0 0 0 0 1 0 0 0\r\n    0 0 1 0 0 0 0 0\r\n    0 0 0 0 0 0 0 1\r\n    0 0 0 1 0 0 0 0\r\n    0 0 0 0 0 0 1 0\r\n    1 0 0 0 0 0 0 0\r\n    0 0 0 0 0 1 0 0\r\n    0 1 0 0 0 0 0 0 ];\r\nout1 = isEightQueensSolution(in1);\r\nassert(islogical(out1));\r\nassert(isequal(out1, 1));\r\n\r\n%%\r\n% Unique solution #7\r\nin2 = [ ...\r\n    0 0 0 0 1 0 0 0\r\n    0 0 0 0 0 0 1 0\r\n    0 0 0 1 0 0 0 0\r\n    1 0 0 0 0 0 0 0\r\n    0 0 1 0 0 0 0 0\r\n    0 0 0 0 0 0 0 1\r\n    0 0 0 0 0 1 0 0\r\n    0 1 0 0 0 0 0 0 ];\r\nout2 = isEightQueensSolution(in2);\r\nassert(isequal(out2, 1));\r\n\r\n%%\r\n% Unique solution #10\r\nin3 = [ ...\r\n    0 0 0 0 0 1 0 0\r\n    0 1 0 0 0 0 0 0\r\n    0 0 0 0 0 0 1 0\r\n    1 0 0 0 0 0 0 0\r\n    0 0 0 1 0 0 0 0\r\n    0 0 0 0 0 0 0 1\r\n    0 0 0 0 1 0 0 0\r\n    0 0 1 0 0 0 0 0 ];\r\nout3 = isEightQueensSolution(in3);\r\nassert(isequal(out3, 1));\r\n\r\n%%\r\n% Unique solution #11\r\nin4 = [ ...\r\n    0 0 0 1 0 0 0 0\r\n    0 0 0 0 0 0 1 0\r\n    1 0 0 0 0 0 0 0\r\n    0 0 0 0 0 0 0 1\r\n    0 0 0 0 1 0 0 0\r\n    0 1 0 0 0 0 0 0\r\n    0 0 0 0 0 1 0 0\r\n    0 0 1 0 0 0 0 0 ];\r\nout4 = isEightQueensSolution(in4);\r\nassert(isequal(out4, 1));\r\n\r\n%%\r\nin5 = [ ...\r\n    0 0 0 0 1 0 0 0\r\n    0 0 1 0 0 0 0 0\r\n    0 0 0 1 0 0 0 0\r\n    0 0 0 0 0 0 0 1\r\n    0 0 0 0 0 0 1 0\r\n    1 0 0 0 0 0 0 0\r\n    0 0 0 0 0 1 0 0\r\n    0 1 0 0 0 0 0 0 ];\r\nout5 = isEightQueensSolution(in5);\r\nassert(isequal(out5, 0));\r\n\r\n%%\r\nin6 = [ ...\r\n    0 0 1 0 0 0 0 0\r\n    0 0 0 0 0 0 1 0\r\n    0 0 0 1 0 0 0 0\r\n    1 0 0 0 0 0 0 0\r\n    0 0 1 0 0 0 0 0\r\n    0 0 0 0 0 0 0 1\r\n    0 0 0 0 0 1 0 0\r\n    0 1 0 0 0 0 0 0 ];\r\nout6 = isEightQueensSolution(in6);\r\nassert(isequal(out6, 0));\r\n\r\n%%\r\nin7 = [ ...\r\n    0 0 0 0 0 1 0 0\r\n    0 1 0 0 0 0 0 0\r\n    0 0 0 0 0 0 1 0\r\n    1 0 0 0 0 0 0 0\r\n    0 0 0 1 0 0 0 0\r\n    0 0 0 0 0 0 0 1\r\n    0 0 1 0 0 0 0 0\r\n    0 0 0 0 1 0 0 0 ];\r\nout7 = isEightQueensSolution(in7);\r\nassert(isequal(out7, 0));\r\n\r\n%%\r\nin8 = [ ...\r\n    0 0 0 1 0 0 0 0\r\n    0 0 0 0 0 0 1 0\r\n    1 0 0 0 0 0 0 0\r\n    0 0 0 0 1 0 0 1\r\n    0 0 0 0 0 0 0 0\r\n    0 1 0 0 0 0 0 0\r\n    0 0 0 0 0 1 0 0\r\n    0 0 1 0 0 0 0 0 ];\r\nout8 = isEightQueensSolution(in8);\r\nassert(isequal(out8, 0));\r\n\r\n%%\r\n% Only 7 queens\r\nin9 = [ ...\r\n    0 0 0 0 1 0 0 0\r\n    0 0 1 0 0 0 0 0\r\n    0 0 0 0 0 0 0 1\r\n    0 0 0 1 0 0 0 0\r\n    0 0 0 0 0 0 0 0\r\n    1 0 0 0 0 0 0 0\r\n    0 0 0 0 0 1 0 0\r\n    0 1 0 0 0 0 0 0 ];\r\nout9 = isEightQueensSolution(in9);\r\nassert(isequal(out9, 0));\r\n\r\n%%\r\n% Row and column constraint satisfied but \r\n% not diagonal constraint.\r\nin10 = eye(8);\r\nout10 = isEightQueensSolution(in10);\r\nassert(isequal(out10, 0));\r\n\r\n%%\r\n% Row and column constraint satisfied but \r\n% not diagonal constraint.\r\nin10 = flip(eye(8));\r\nout10 = isEightQueensSolution(in10);\r\nassert(isequal(out10, 0));","published":true,"deleted":false,"likes_count":6,"comments_count":2,"created_by":4303371,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":168,"test_suite_updated_at":"2022-01-07T08:34:21.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-02-11T12:21:25.000Z","updated_at":"2026-03-23T21:10:35.000Z","published_at":"2012-02-11T12:55:24.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\u003eWrite a function to verify whether an arrangement of queens on a chessboard is a valid solution to the classic\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\u003eeight queens problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn the eight queens problem, eight queens must be placed on a chessboard such that no two queens attack each other. That is, no two queens can share the same row, column, or diagonal. The diagram below is one possible solution:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"center\\\"/\u003e\u003c/w:pPr\u003e\u003cw:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"verticalAlign\\\" w:val=\\\"baseline\\\"/\u003e\u003cw:attr w:name=\\\"altText\\\" w:val=\\\"\\\"/\u003e\u003cw:attr w:name=\\\"relationshipId\\\" w:val=\\\"rId1\\\"/\u003e\u003c/w:customXmlPr\u003e\u003c/w:customXml\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour function should take an 8-by-8 matrix of 0s and 1s, where the 1s represent the position of the queens, and return a logical 1 if the solution is valid or a logical 0 otherwise.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eEXAMPLE 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   in1 = [ ...\\n       0 0 0 1 0 0 0 0\\n       0 0 0 0 0 0 1 0\\n       0 0 1 0 0 0 0 0\\n       0 0 0 0 0 0 0 1\\n       0 1 0 0 0 0 0 0\\n       0 0 0 0 1 0 0 0\\n       1 0 0 0 0 0 0 0\\n       0 0 0 0 0 1 0 0 ];\\n\\n   isEightQueensSolution(in1)]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ereturns 1.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eEXAMPLE 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   in2 = [ ...\\n       0 0 0 1 0 0 0 0\\n       0 0 0 0 0 0 1 0\\n       0 0 1 0 0 0 0 0\\n       0 0 0 0 0 0 0 1\\n       0 1 0 0 0 0 0 0\\n       1 0 0 0 0 0 0 0\\n       0 0 0 0 1 0 0 0\\n       0 0 0 0 0 1 0 0 ];\\n\\n   isEightQueensSolution(in2)]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ereturns 0. (Notice that the queens on the bottom two rows share a diagonal.)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"target\":\"/media/image1.png\",\"relationshipId\":\"rId1\"}]},{\"partUri\":\"/media/image1.png\",\"contentType\":\"image/png\",\"content\":\"data:image/png;base64,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\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":113,"title":"N-Queens Checker","description":"Picture a chessboard populated with a number of queens (i.e. pieces that can move like a queen in chess). The board is a matrix, a, filled mostly with zeros, while the queens are given as ones. Your job is to verify that the board is a legitimate answer to the \u003chttp://en.wikipedia.org/wiki/Eight_queens_puzzle N-Queens problem\u003e. The board is good only when no queen can \"see\" (and thus capture) another queen.\r\n\r\nExample\r\n\r\nThe matrix below shows two queens on a 3-by-3 chessboard. The queens can't see each other, so the function should return TRUE.\r\n\r\n 1 0 0\r\n 0 0 1\r\n 0 0 0\r\n\r\nHere is a bigger board with more queens. Since the queens on rows 3 and 4 are adjacent along a diagonal, they can see each other and the function should return FALSE.\r\n\r\n 0 0 0 1\r\n 1 0 0 0\r\n 0 0 1 0 \r\n 0 1 0 0\r\n\r\nThe board doesn't have to be square, but it always has 2 or more rows and 2 or more columns. This matrix returns FALSE.\r\n\r\n 1 0 0 0 0 \r\n 0 0 0 1 1\r\n","description_html":"\u003cp\u003ePicture a chessboard populated with a number of queens (i.e. pieces that can move like a queen in chess). The board is a matrix, a, filled mostly with zeros, while the queens are given as ones. Your job is to verify that the board is a legitimate answer to the \u003ca href=\"http://en.wikipedia.org/wiki/Eight_queens_puzzle\"\u003eN-Queens problem\u003c/a\u003e. The board is good only when no queen can \"see\" (and thus capture) another queen.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cp\u003eThe matrix below shows two queens on a 3-by-3 chessboard. The queens can't see each other, so the function should return TRUE.\u003c/p\u003e\u003cpre\u003e 1 0 0\r\n 0 0 1\r\n 0 0 0\u003c/pre\u003e\u003cp\u003eHere is a bigger board with more queens. Since the queens on rows 3 and 4 are adjacent along a diagonal, they can see each other and the function should return FALSE.\u003c/p\u003e\u003cpre\u003e 0 0 0 1\r\n 1 0 0 0\r\n 0 0 1 0 \r\n 0 1 0 0\u003c/pre\u003e\u003cp\u003eThe board doesn't have to be square, but it always has 2 or more rows and 2 or more columns. This matrix returns FALSE.\u003c/p\u003e\u003cpre\u003e 1 0 0 0 0 \r\n 0 0 0 1 1\u003c/pre\u003e","function_template":"function tf = queens(a)\r\n  tf = true;\r\nend","test_suite":"%%\r\n\r\na = [1 0 0; 0 0 1; 0 0 0];\r\ntf_correct = true;\r\nassert(isequal(queens(a),tf_correct))\r\n\r\n%%\r\n\r\na = [0 0 0 1; 1 0 0 0; 0 0 1 0; 0 1 0 0];\r\ntf_correct = false;\r\nassert(isequal(queens(a),tf_correct))\r\n\r\n%%\r\n\r\na = [1 0 0 0 0; 0 0 0 1 1];\r\ntf_correct = false;\r\nassert(isequal(queens(a),tf_correct))\r\n\r\n\r\n%%\r\n\r\na = [ ...\r\n  0 0 1 0 0 0 0 0; 0 0 0 0 0 0 1 0; 0 1 0 0 0 0 0 0; 0 0 0 0 0 0 0 1;\r\n  0 0 0 0 0 1 0 0; 0 0 0 1 0 0 0 0; 1 0 0 0 0 0 0 0; 0 0 0 0 1 0 0 0];\r\ntf_correct = true;\r\nassert(isequal(queens(a),tf_correct))\r\n\r\n%%\r\n\r\na = ones(15,7);\r\ntf_correct = false;\r\nassert(isequal(queens(a),tf_correct))\r\n\r\n%%\r\n\r\na = zeros(20,23);\r\na(1,22) = 1;\r\na(2,23) = 1;\r\ntf_correct = false;\r\nassert(isequal(queens(a),tf_correct))\r\n\r\n%%\r\n\r\na = [1 0; 0 1];\r\ntf_correct = false;\r\nassert(isequal(queens(a),tf_correct))\r\n\r\n%%\r\n\r\na = [1 0 1; 0 0 0; 0 1 0];\r\ntf_correct = false;\r\nassert(isequal(queens(a),tf_correct))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":7,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":311,"test_suite_updated_at":"2017-03-15T16:59:10.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2012-01-26T20:33:45.000Z","updated_at":"2026-03-23T21:08:43.000Z","published_at":"2012-01-30T15:34:35.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePicture a chessboard populated with a number of queens (i.e. pieces that can move like a queen in chess). The board is a matrix, a, filled mostly with zeros, while the queens are given as ones. Your job is to verify that the board is a legitimate answer to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Eight_queens_puzzle\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eN-Queens problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. The board is good only when no queen can \\\"see\\\" (and thus capture) another queen.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe matrix below shows two queens on a 3-by-3 chessboard. The queens can't see each other, so the function should return TRUE.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ 1 0 0\\n 0 0 1\\n 0 0 0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHere is a bigger board with more queens. Since the queens on rows 3 and 4 are adjacent along a diagonal, they can see each other and the function should return FALSE.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ 0 0 0 1\\n 1 0 0 0\\n 0 0 1 0 \\n 0 1 0 0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe board doesn't have to be square, but it always has 2 or more rows and 2 or more columns. This matrix returns FALSE.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ 1 0 0 0 0 \\n 0 0 0 1 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":1172,"title":"Wheat on a chessboard pt 1","description":"If a chessboard were to have wheat placed upon each square such that one grain were placed on the first square and each successive square after had double the amount of grains as the square before. How many grains of wheat would be on the chessboard at the finish?\r\n\r\nAssume the chess board is n by n squares.","description_html":"\u003cp\u003eIf a chessboard were to have wheat placed upon each square such that one grain were placed on the first square and each successive square after had double the amount of grains as the square before. How many grains of wheat would be on the chessboard at the finish?\u003c/p\u003e\u003cp\u003eAssume the chess board is n by n squares.\u003c/p\u003e","function_template":"function y = wheat_chess(n)\r\n  y = n;\r\nend","test_suite":"%%\r\nn = 1;\r\ny_correct = 1;\r\nassert(isequal(wheat_chess(n),y_correct))\r\n\r\n%%\r\nn = 0;\r\ny_correct = 0;\r\nassert(isequal(wheat_chess(n),y_correct))\r\n\r\n%%\r\nn = -1;\r\ny_correct = 'NaN';\r\nassert(isequal(wheat_chess(n),y_correct))\r\n\r\n%%\r\nn = 4;\r\ny_correct = 65535;\r\nassert(isequal(wheat_chess(n),y_correct))\r\n\r\n%%\r\nn = 8;\r\ny_correct = 18446744073709551615;\r\nassert(isequal(wheat_chess(n),y_correct))\r\n\r\n%%\r\nn = 10;\r\ny_correct = 1267650600228229401496703205375;\r\nassert(isequal(wheat_chess(n),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":7,"created_by":9554,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":192,"test_suite_updated_at":"2013-01-08T15:42:28.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-01-04T15:52:05.000Z","updated_at":"2026-03-31T14:13:16.000Z","published_at":"2013-01-04T15:52:05.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf a chessboard were to have wheat placed upon each square such that one grain were placed on the first square and each successive square after had double the amount of grains as the square before. How many grains of wheat would be on the chessboard at the finish?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssume the chess board is n by n squares.\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":1174,"title":"Wheat on a chessboard pt 2","description":"If a chessboard were to have wheat placed upon each square such that x grains were placed on the first square and each successive square after had y times the amount of grains as the square before. How many grains of wheat would be on the chessboard at the finish?\r\n\r\nAssume the chess board is n by n squares.","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: 93px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 46.5px; transform-origin: 407px 46.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf a chessboard were to have wheat placed upon each square such that x grains were placed on the first square and each successive square after had y times the amount of grains as the square before. How many grains of wheat would be on the chessboard at the finish?\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: 136px 8px; transform-origin: 136px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAssume the chess board is n by n squares.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function A = wheat_chess(x,y,n)\r\n  A = x + y + n;\r\nend","test_suite":"%%\r\nx = 56;\r\ny = 1;\r\nn = 1;\r\nA_correct = 56;\r\nassert(isequal(wheat_chess(x,y,n),A_correct))\r\n\r\n%%\r\nx = 1;\r\ny = 2;\r\nn = 8;\r\nA_correct = 18446744073709551615;\r\nassert(isequal(wheat_chess(x,y,n),A_correct))\r\n\r\n\r\n%%\r\nx = 5;\r\ny = 3;\r\nn = 2;\r\nA_correct = 200;\r\nassert(isequal(wheat_chess(x,y,n),A_correct))\r\n\r\n%%\r\nx = 10;\r\ny = 5;\r\nn = 3;\r\nA_correct = 4882810;\r\nassert(isequal(wheat_chess(x,y,n),A_correct))\r\n\r\n%%\r\nx = 1;\r\ny = 0;\r\nn = 1;\r\nA_correct = 1;\r\nassert(isequal(wheat_chess(x,y,n),A_correct))\r\n\r\n\r\n%%\r\nx = 12;\r\ny = 1;\r\nn = 3;\r\nA_correct = 108;\r\nassert(isequal(wheat_chess(x,y,n),A_correct))\r\n\r\n\r\n%%\r\nx = 0;\r\ny = 1e5;\r\nn = 7;\r\nA_correct = 0;\r\nassert(isequal(wheat_chess(x,y,n),A_correct))\r\n\r\n%%\r\nx = 6;\r\ny = 2;\r\nn = 4;\r\nA_correct = 393210;\r\nassert(isequal(wheat_chess(x,y,n),A_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":6,"created_by":9554,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":130,"test_suite_updated_at":"2021-05-05T10:17:41.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-01-04T18:21:52.000Z","updated_at":"2026-02-15T07:12:03.000Z","published_at":"2013-01-04T18:21:52.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\u003eIf a chessboard were to have wheat placed upon each square such that x grains were placed on the first square and each successive square after had y times the amount of grains as the square before. How many grains of wheat would be on the chessboard at the finish?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssume the chess board is n by n squares.\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":1684,"title":"Identify Reachable Points ","description":"Given a vector of 2-D Points and a vector of 2-D Deltas create an array of all Locations that can be reached from the points using the Deltas. The provided Deltas are only positive but the points that can be reached may use Negative Deltas or Y-deltas for X moves, like moves of a Knight dxy [1 2].\r\n\r\n*Input:* [Pts, dxy]\r\n\r\n\r\n*Output:* Mxy\r\n\r\n*Example:* \r\n\r\n  Pts [5 5; 7 9]\r\n\r\n  dxy [0 1]  % Multiple dxy are possible\r\n  \r\n  Mxy =[4 5;5 4;5 6;6 5;6 9;7 8;7 10;8 9]\r\n\r\n*Related Challenges:*\r\n\r\n1) Minimum Sized Circle for N integer points with all unique distances ","description_html":"\u003cp\u003eGiven a vector of 2-D Points and a vector of 2-D Deltas create an array of all Locations that can be reached from the points using the Deltas. The provided Deltas are only positive but the points that can be reached may use Negative Deltas or Y-deltas for X moves, like moves of a Knight dxy [1 2].\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e [Pts, dxy]\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e Mxy\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample:\u003c/b\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ePts [5 5; 7 9]\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003edxy [0 1]  % Multiple dxy are possible\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eMxy =[4 5;5 4;5 6;6 5;6 9;7 8;7 10;8 9]\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eRelated Challenges:\u003c/b\u003e\u003c/p\u003e\u003cp\u003e1) Minimum Sized Circle for N integer points with all unique distances\u003c/p\u003e","function_template":"function Mxy=Knights(Pts,dxy)\r\n  Mxy=Pts;\r\nend","test_suite":"%%\r\nPts=[5 5; 7 9];\r\ndxy=[0 1];\r\nMxy=unique(Knights(Pts,dxy),'rows');\r\n\r\nMxy_exp =[4 5;5 4;5 6;6 5;6 9;7 8;7 10;8 9];\r\nassert(isequal(Mxy,Mxy_exp))\r\n%%\r\nPts=[5 5];\r\ndxy=[0 1;1 2];\r\nMxy=unique(Knights(Pts,dxy),'rows');\r\n\r\nMxy_exp =[3 4;3 6;4 3;4 5;4 7;5 4;5 6;6 3;6 5;6 7;7 4;7 6];\r\nassert(isequal(Mxy,Mxy_exp))\r\n%%\r\npts=randi(20,6,2);\r\ndxy=randi(6,4,2);\r\nMxy=unique(Knights(pts,dxy),'rows');\r\n\r\n nP=size(pts,1);\r\n ndxy=size(dxy,1);\r\n \r\n mxy=[];\r\n for i=1:nP\r\n  mxy=[mxy;\r\n      dxy(:,1)+pts(i,1) dxy(:,2)+pts(i,2);\r\n      -dxy(:,1)+pts(i,1) dxy(:,2)+pts(i,2);\r\n      dxy(:,1)+pts(i,1) -dxy(:,2)+pts(i,2);\r\n      -dxy(:,1)+pts(i,1) -dxy(:,2)+pts(i,2);\r\n       dxy(:,2)+pts(i,1) dxy(:,1)+pts(i,2);\r\n      -dxy(:,2)+pts(i,1) dxy(:,1)+pts(i,2);\r\n      dxy(:,2)+pts(i,1) -dxy(:,1)+pts(i,2);\r\n      -dxy(:,2)+pts(i,1) -dxy(:,1)+pts(i,2)];\r\n end\r\n\r\n Mxy_exp=unique(mxy,'rows');\r\n\r\nassert(isequal(Mxy,Mxy_exp))\r\n\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":48,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-28T03:22:54.000Z","updated_at":"2026-02-15T07:15:08.000Z","published_at":"2013-06-28T03:58:36.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector of 2-D Points and a vector of 2-D Deltas create an array of all Locations that can be reached from the points using the Deltas. The provided Deltas are only positive but the points that can be reached may use Negative Deltas or Y-deltas for X moves, like moves of a Knight dxy [1 2].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e [Pts, dxy]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Mxy\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Pts [5 5; 7 9]\\n\\ndxy [0 1]  % Multiple dxy are possible\\n\\nMxy =[4 5;5 4;5 6;6 5;6 9;7 8;7 10;8 9]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRelated Challenges:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1) Minimum Sized Circle for N integer points with all unique distances\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":315,"title":"Valid Chess Moves","description":"Using standard Algebraic notation ('' for a pawn), given previous move and a next move, output true if it is a valid move or false otherwise. Assume there are no other pieces on the chess board, that the piece can be either black or white (whichever generates a valid result) and the previous move was valid. Examples:\r\nMoving a pawn one space:\r\n('c5','c6') -\u003e true \r\n\r\nMoving a bishop non-diagonally:\r\n('Bb7','Bd7') -\u003e false","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: 175.167px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 87.5833px; transform-origin: 407px 87.5833px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 17.5px 8px; transform-origin: 17.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eUsing\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=\"\"\u003estandard Algebraic notation\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: 276.5px 8px; transform-origin: 276.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e ('' for a pawn), given previous move and a next move, output true if it is a valid move or false otherwise. Assume there are no other pieces on the chess board, that the piece can be either black or white (whichever generates a valid result) and the previous move was valid. Examples:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 102.167px; 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 51.0833px; transform-origin: 404px 51.0833px; 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: 96px 8.5px; tab-size: 4; transform-origin: 96px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 28px 8.5px; transform-origin: 28px 8.5px; \"\u003eMoving \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: 68px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 68px 8.5px; \"\u003ea pawn one space:\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: 80px 8.5px; tab-size: 4; transform-origin: 80px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003e(\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: 16px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 16px 8.5px; \"\u003e'c5'\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003e,\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: 16px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 16px 8.5px; \"\u003e'c6'\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 40px 8.5px; transform-origin: 40px 8.5px; \"\u003e) -\u0026gt; true \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: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 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: 124px 8.5px; tab-size: 4; transform-origin: 124px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 28px 8.5px; transform-origin: 28px 8.5px; \"\u003eMoving \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: 96px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 96px 8.5px; \"\u003ea bishop non-diagonally:\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: 88px 8.5px; tab-size: 4; transform-origin: 88px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003e(\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: 20px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 20px 8.5px; \"\u003e'Bb7'\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003e,\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: 20px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 20px 8.5px; \"\u003e'Bd7'\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 40px 8.5px; transform-origin: 40px 8.5px; \"\u003e) -\u0026gt; false\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function z = chessmove(x,y)\r\n  z = false;\r\nend","test_suite":"%%\r\nx = 'c5';\r\ny = 'c6';\r\nz = true;\r\nassert(isequal(chessmove(x,y),z))\r\n\r\n%%\r\nx = 'a2';\r\ny = 'a5';\r\nz = false;\r\nassert(isequal(chessmove(x,y),z))\r\n\r\n%%\r\nx = 'g3';\r\ny = 'h4';\r\nz = false;\r\nassert(isequal(chessmove(x,y),z))\r\n\r\n%%\r\nx = 'Bb7';\r\ny = 'Bd7';\r\nz = false;\r\nassert(isequal(chessmove(x,y),z))\r\n\r\n%%\r\nx = 'Bg2';\r\ny = 'Bh3';\r\nz = true;\r\nassert(isequal(chessmove(x,y),z))\r\n\r\n%%\r\nx = 'Nf1';\r\ny = 'Ne3';\r\nz = true;\r\nassert(isequal(chessmove(x,y),z))\r\n\r\n%%\r\nx = 'Nc5';\r\ny = 'Nc3';\r\nz = false;\r\nassert(isequal(chessmove(x,y),z))\r\n\r\n%%\r\nx = 'Qb2';\r\ny = 'Qc4';\r\nz = false;\r\nassert(isequal(chessmove(x,y),z))\r\n\r\n%%\r\nx = 'Qa1';\r\ny = 'Qh8';\r\nz = true;\r\nassert(isequal(chessmove(x,y),z))\r\n\r\n%%\r\nx = 'Rh7';\r\ny = 'Rh3';\r\nz = true;\r\nassert(isequal(chessmove(x,y),z))\r\n\r\n%%\r\nx = 'Rb2';\r\ny = 'Rh8';\r\nz = false;\r\nassert(isequal(chessmove(x,y),z))\r\n\r\n%%\r\nx = 'Ke1';\r\ny = 'Ke2';\r\nz = true;\r\nassert(isequal(chessmove(x,y),z))\r\n\r\n%%\r\nx = 'Kf3';\r\ny = 'Kg4';\r\nz = true;\r\nassert(isequal(chessmove(x,y),z))\r\n\r\n%%\r\nx = 'Kb2';\r\ny = 'Kc4';\r\nz = false;\r\nassert(isequal(chessmove(x,y),z))","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":1022,"edited_by":223089,"edited_at":"2022-05-23T10:24:16.000Z","deleted_by":null,"deleted_at":null,"solvers_count":85,"test_suite_updated_at":"2022-05-23T09:39:10.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-02-13T05:34:29.000Z","updated_at":"2026-03-30T18:59:55.000Z","published_at":"2012-02-13T05:35:32.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eUsing\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\u003estandard Algebraic notation\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e ('' for a pawn), given previous move and a next move, output true if it is a valid move or false otherwise. Assume there are no other pieces on the chess board, that the piece can be either black or white (whichever generates a valid result) and the previous move was valid. Examples:\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[Moving a pawn one space:\\n('c5','c6') -\u003e true \\n\\nMoving a bishop non-diagonally:\\n('Bb7','Bd7') -\u003e false]]\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":3056,"title":"Chess probability","description":"The difference in the ratings between two players serves as a predictor of the outcome of a match (the \u003chttp://en.wikipedia.org/wiki/Elo_rating_system Elo rating system\u003e)\r\n\r\nIf Player A has a rating of Ra and Player B a rating of Rb, the formula for the expected score of Player A is :\r\n\r\n\u003c\u003chttp://upload.wikimedia.org/math/b/0/3/b0366725c224ee55eab6e2371dc6a0ef.png\u003e\u003e\r\n \r\n* \r\n \r\n\r\nTwo players with equal ratings who play against each other are expected to score an equal number of wins. A player whose rating is 100 points greater than their opponent's is expected to score 64%; if the difference is 200 points, then the expected score for the stronger player is 76%.\r\n\r\nI give you two ELOs, compute the expected score (round to 3 digits), or probability  that the first player wins.\r\n\r\n\r\n","description_html":"\u003cp\u003eThe difference in the ratings between two players serves as a predictor of the outcome of a match (the \u003ca href = \"http://en.wikipedia.org/wiki/Elo_rating_system\"\u003eElo rating system\u003c/a\u003e)\u003c/p\u003e\u003cp\u003eIf Player A has a rating of Ra and Player B a rating of Rb, the formula for the expected score of Player A is :\u003c/p\u003e\u003cimg src = \"http://upload.wikimedia.org/math/b/0/3/b0366725c224ee55eab6e2371dc6a0ef.png\"\u003e\u003cul\u003e\u003cli\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eTwo players with equal ratings who play against each other are expected to score an equal number of wins. A player whose rating is 100 points greater than their opponent's is expected to score 64%; if the difference is 200 points, then the expected score for the stronger player is 76%.\u003c/p\u003e\u003cp\u003eI give you two ELOs, compute the expected score (round to 3 digits), or probability  that the first player wins.\u003c/p\u003e","function_template":"function y = expected_score(elo1,elo2)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1800;\r\ny = 1800;\r\nassert(isequal(expected_score(x,y),0.5))\r\n%%\r\nx = 1900;\r\ny = 1800;\r\nassert(isequal(expected_score(x,y),0.64))\r\n%%\r\nx = 1900;\r\ny = 2000;\r\nassert(isequal(expected_score(x,y),0.36))\r\n%%\r\nx = 1900;\r\ny = 2100;\r\nassert(isequal(expected_score(x,y),0.24))\r\n%% My probability against Maxime Vachier-Lagrave (best french player)\r\nx = 1800;\r\ny = 2775;\r\nassert(isequal(expected_score(x,y),0.004))\r\n%% My probability against Magnus Carlsen (World Chess Champion)\r\nx = 1800;\r\ny = 2865;\r\nassert(isequal(expected_score(x,y),0.002))\r\n%% Magnus against Maxime\r\nx = 2865;\r\ny = 2775;\r\nassert(isequal(expected_score(x,y),0.627))\r\n%% Magnus Carlsen against Garry Kasparov (1999)\r\nx = 2865;\r\ny = 2851;\r\nassert(isequal(expected_score(x,y),0.52))\r\n%% Magnus Carlsen against Fabiano Caruana\r\nx = 2865;\r\ny = 2844;\r\nassert(isequal(expected_score(x,y),0.53))\r\n%% Bobby Fisher (1972) against Magnus Carlsen\r\nx = 2785;\r\ny = 2865;\r\nassert(isequal(expected_score(x,y),0.387))\r\n%% Bobby Fisher (1972) against me\r\nx = 2785;\r\ny = 1800;\r\nassert(isequal(expected_score(x,y),0.997))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":0,"created_by":5390,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":679,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-02-28T22:51:09.000Z","updated_at":"2026-04-02T13:53:00.000Z","published_at":"2015-02-28T22:52:00.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/media/image1.png\"}],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe difference in the ratings between two players serves as a predictor of the outcome of a match (the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Elo_rating_system\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eElo rating system\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf Player A has a rating of Ra and Player B a rating of Rb, the formula for the expected score of Player A is :\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"relationshipId\\\" w:val=\\\"rId1\\\"/\u003e\u003c/w:customXmlPr\u003e\u003c/w:customXml\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTwo players with equal ratings who play against each other are expected to score an equal number of wins. A player whose rating is 100 points greater than their opponent's is expected to score 64%; if the difference is 200 points, then the expected score for the stronger player is 76%.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eI give you two ELOs, compute the expected score (round to 3 digits), or probability that the first player wins.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"},{\"partUri\":\"/media/image1.png\",\"contentType\":\"image/png\",\"content\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAM4AAAArBAMAAADCuKrGAAAAMFBMVEX///90dHQEBAQwMDCenp5QUFAWFhbm5ubMzMyKioq2trZAQEAMDAwiIiJiYmIAAADHPVvyAAAAAXRSTlMAQObYZgAAAuJJREFUeNrtV0toE2EQ/pJs91+TZpuKKZ7aHDxZhKBo8WCNQj14qNHiAxFZRNIHVAPFi0UbFC8qEqh40cOePBUfUAoS0BQPvhByqXqoEK1CaauNXswWu3H+JF03TbV5dHPqwGYzM//u98/881qgOhoscZ29OhjnkRIXOqqCYdvmXqMmtKc2fiuZ1nHWcdZxikmrDU7Xq53hkhbagG8Nz7Cl0WO565xkuxS3/nwEHUinrMfJ9NLdbz2OPYUkVOtD+2GA+S0HEYDAzQ82nyEYe8R/+yxAfoc6671G+dM6If+U0oC4sEyXWSuQHzw5JQ0MdfRnPmxpvGk6Fam9lK5q9kzGQpwSqz4Y+beK71cq2rSDxwC9V6iPlrE/+T/GH6fLVWRPhpx3ia57v4Jl4NyIYv5pV8HODH4kx9ep0uETuOYly9m43dV/N7brShRS50xw9amWCwabaWEboO4f7THrDF4PABv4aKe3PMDn2SSJFFMi2ZSiCvt2JcFLDMNJWdYEHqV/yeB52vvBmtQRiAfjOFvQfybhWF6zWau6gkDuwXlVoD214MK0WWvwGnnHB5ZCH9gLFf1mnKvTGJpY3ivfLIWd2yRI+yAEFsnpKe+sD/fbpwL5RVkeUraeLPpxPRtdH42HS5me3SZBgwcOxRWAlEI7aSJCwhaLxR7nebjI0m76PGBRUW2C+EnBucr6djgCSaHSoSWxSDUjkolnOjo6DuV57KaYe4IDWDg9uekOxF4FxyrD4TVEEVTYPRiWcLHxfT6TcjzqGUUeWZTZuHVOCWOM4XfFc0gaepCdOglvEpvnt+djJMfLvgEIUcYFU7f1fZ344k1Wdj5DUbjjPH+yNAqxICgHvo/DFbGV2QCyOK5Q6Ewo1G+KA7diZHD3UvbnKYijuFX2V+JK9ohBiEk4cyVG1r+2FZiTkCZVDy6vAY6cQINaQV8oa6olgZaGrKwtTtFUywXa8+YdVnVDN2pDjqrf8Af8bczR/4tLjAAAAABJRU5ErkJggg==\"}]}"},{"id":3057,"title":"Chess performance","description":"After Problems \u003chttp://www.mathworks.com/matlabcentral/cody/problems/3054-chess-elo-rating-system/ 3054\u003e and \u003chttp://www.mathworks.com/matlabcentral/cody/problems/3056-chess-probability/ 3056\u003e\r\n\r\n\r\nIn \u003chttp://en.wikipedia.org/wiki/Elo_rating_system Chess\u003e, performance isn't measured absolutely; it is inferred from wins (1), losses (0), and draws (0.5) against other players. A player's rating depends on the ratings of their opponents, and the results scored against them. The difference in rating between two players determines an estimate for the expected score between them.\r\n\r\nSupposing Player A was expected to score Ea points (but actually scored Sa).\r\n\r\nThe formula for updating his rating is :\r\n\r\n\u003c\u003chttp://upload.wikimedia.org/math/2/3/f/23fbcb658ac1e2565003c2190f28a21e.png\u003e\u003e\r\n\r\n* \r\n* \r\n\r\n\r\nThis update can be performed after each game or each tournament, or after any suitable rating period. \r\n\r\nSuppose Player A has a rating *Ra* of 1613, and plays in a five-round tournament. He (or she) loses to a player rated 1609, draws with a player rated 1477, defeats a player rated 1388, defeats a player rated 1586, and loses to a player rated 1720. The player's actual score *Sa* is (0 + 0.5 + 1 + 1 + 0) = 2.5. The expected score *Ea* , calculated according to the formula see in Problem 3056, was (0.506 + 0.686 + 0.785 + 0.539 + 0.351) = 2.867. Therefore the player's new rating *R'a* is (1613 + 32×(2.5 − 2.867)) = 1601. We assume that the *K* factor is always 32.\r\n\r\nI give you rating of Player A, ratings of their opponents and results. \r\n\r\nCompute the new rating (K = 32).\r\n\r\n\r\n","description_html":"\u003cp\u003eAfter Problems \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/3054-chess-elo-rating-system/\"\u003e3054\u003c/a\u003e and \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/3056-chess-probability/\"\u003e3056\u003c/a\u003e\u003c/p\u003e\u003cp\u003eIn \u003ca href = \"http://en.wikipedia.org/wiki/Elo_rating_system\"\u003eChess\u003c/a\u003e, performance isn't measured absolutely; it is inferred from wins (1), losses (0), and draws (0.5) against other players. A player's rating depends on the ratings of their opponents, and the results scored against them. The difference in rating between two players determines an estimate for the expected score between them.\u003c/p\u003e\u003cp\u003eSupposing Player A was expected to score Ea points (but actually scored Sa).\u003c/p\u003e\u003cp\u003eThe formula for updating his rating is :\u003c/p\u003e\u003cimg src = \"http://upload.wikimedia.org/math/2/3/f/23fbcb658ac1e2565003c2190f28a21e.png\"\u003e\u003cul\u003e\u003cli\u003e\u003c/li\u003e\u003cli\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThis update can be performed after each game or each tournament, or after any suitable rating period.\u003c/p\u003e\u003cp\u003eSuppose Player A has a rating \u003cb\u003eRa\u003c/b\u003e of 1613, and plays in a five-round tournament. He (or she) loses to a player rated 1609, draws with a player rated 1477, defeats a player rated 1388, defeats a player rated 1586, and loses to a player rated 1720. The player's actual score \u003cb\u003eSa\u003c/b\u003e is (0 + 0.5 + 1 + 1 + 0) = 2.5. The expected score \u003cb\u003eEa\u003c/b\u003e , calculated according to the formula see in Problem 3056, was (0.506 + 0.686 + 0.785 + 0.539 + 0.351) = 2.867. Therefore the player's new rating \u003cb\u003eR'a\u003c/b\u003e is (1613 + 32×(2.5 − 2.867)) = 1601. We assume that the \u003cb\u003eK\u003c/b\u003e factor is always 32.\u003c/p\u003e\u003cp\u003eI give you rating of Player A, ratings of their opponents and results.\u003c/p\u003e\u003cp\u003eCompute the new rating (K = 32).\u003c/p\u003e","function_template":"function y = new_elo(opponents_elo,res,elo_playerA)\r\n  y = x;\r\nend","test_suite":"%%\r\nplayera=1613;\r\nelos=[1609 1477 1388 1586 1720];\r\nres=[0 0.5 1 1 0];\r\nassert(isequal(new_elo(elos,res,playera),1601))\r\n%%\r\nplayera=1613;\r\nelos=[1609 1477 1586 1720];\r\nres=[0 1 1 1];\r\nassert(isequal(new_elo(elos,res,playera),1642))\r\n%%\r\nplayera=1613;\r\nelos=[1613 1613 1613 1613 1613];\r\nres=[0.5 0.5 0.5 0.5 0.5];\r\nassert(isequal(new_elo(elos,res,playera),1613))\r\n%%\r\nassert(isequal(new_elo([1800 1900 2000 2100 2200],[1 0 1 0 1],1900),1935))\r\n%% My new ELO\r\nplayera=1800;\r\nelos=[1399 1280 2166 1534 1768 1791 1540];\r\nres=[1 1 0 1 1 0 1];\r\nassert(isequal(new_elo(elos,res,playera),1811))\r\n%% The last game was critical (-32 points if I lost)\r\nplayera=1800;\r\nelos=[1399 1280 2166 1534 1768 1791 1540];\r\nres=[1 1 0 1 1 0 0];\r\nassert(isequal(new_elo(elos,res,playera),1779))\r\n%% Perfect tournament ?\r\nplayera=1800;\r\nelos=[1399 1280 2166 1534 1768 1791 1540];\r\nres=[1 1 1 1 1 1 1];\r\nassert(isequal(new_elo(elos,res,playera),1875))\r\n%% Caruana in 2014 Sinquefield Cup (notice that K=16 for these guys)\r\ncaruana=2801;\r\nelos = [2772 2768 2877 2805 2787  2772 2768 2877 2787 2805];\r\nres = [1 1 1 1 1 1 1 0.5 0.5 0.5];\r\nassert(isequal(new_elo(elos,res,caruana),2913))","published":true,"deleted":false,"likes_count":3,"comments_count":5,"created_by":5390,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":65,"test_suite_updated_at":"2015-03-02T20:49:24.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-02-28T23:49:25.000Z","updated_at":"2026-02-15T07:24:43.000Z","published_at":"2015-02-28T23:53:01.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/media/image1.png\"}],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAfter Problems\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/3054-chess-elo-rating-system/\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e3054\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/3056-chess-probability/\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e3056\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Elo_rating_system\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eChess\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, performance isn't measured absolutely; it is inferred from wins (1), losses (0), and draws (0.5) against other players. A player's rating depends on the ratings of their opponents, and the results scored against them. The difference in rating between two players determines an estimate for the expected score between them.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSupposing Player A was expected to score Ea points (but actually scored Sa).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe formula for updating his rating is :\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"-1\\\"/\u003e\u003cw:attr w:name=\\\"relationshipId\\\" w:val=\\\"rId1\\\"/\u003e\u003c/w:customXmlPr\u003e\u003c/w:customXml\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis update can be performed after each game or each tournament, or after any suitable rating period.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSuppose Player A has a rating\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\u003eRa\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of 1613, and plays in a five-round tournament. He (or she) loses to a player rated 1609, draws with a player rated 1477, defeats a player rated 1388, defeats a player rated 1586, and loses to a player rated 1720. The player's actual score\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\u003eSa\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is (0 + 0.5 + 1 + 1 + 0) = 2.5. The expected score\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\u003eEa\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e , calculated according to the formula see in Problem 3056, was (0.506 + 0.686 + 0.785 + 0.539 + 0.351) = 2.867. Therefore the player's new rating\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\u003eR'a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is (1613 + 32×(2.5 − 2.867)) = 1601. We assume that the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eK\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e factor is always 32.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eI give you rating of Player A, ratings of their opponents and results.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCompute the new rating (K = 32).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"},{\"partUri\":\"/media/image1.png\",\"contentType\":\"image/png\",\"content\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANYAAAAWBAMAAABOJX+pAAAAMFBMVEX///8wMDDMzMwEBASKiooWFhZiYmKenp62trbm5uZQUFBAQEAMDAwiIiJ0dHQAAAB7s/cyAAAAAXRSTlMAQObYZgAAAzpJREFUeNq9VllIVFEY/mZxFmfcSAxCdJSoJKkRCiQhhyAKhZrESerJjBRc6ELQAmJTQRAFjpAPLdaET5EPPmRRJA4aSQulBrYQNiHai+aQozkq2n/uMs7cOSMW1A/33P/cf/nO+ZdzLiCTyYZ/TVqFWXDjv1Hz3+2rak1ayeJG9MBkSo92oiLLz1EZnAhkPxJ4grJiz/mmS279CM0SvUlfa2OVGpp7sDEtlbE/byiZ+gU88/RzNyvA8pIrcABtFIkcloYhGJ5zdExBkvkkPkfO11II6CsL8Vz6PVjcyRU4YeqjSNAyoTuAeZ7SUgI9AVlfkLCMlYBQz01XNUlnI+YD4fgIKPbSu5AeN2Gu5xgbK2jolHiDV8KapZCOPOViHaOVfeEJsmH4xPJGy0QNPXZeiTtRCTmGIb+ElW9D2+gctyF6YX7Hc2MKmd8z62UPDe0foLiMIveAuRNKxdVIdehbHmv8HtawlIjO2tloNYzXdYGbirNZ7D3nIJAzQsFBXnP6O4YveJVJv4S1bdTcvSusMfNgRXt6yH6bV2FYeD01L2Kyip5vvbiXh1XdsvV0eHLtsPginJP8FtR5YRALKUFVG7pe9LDwpcjzQ2xwsiGXUZ74sQgG8VgSjevEfGm7ZbVYyh+QUWqZ4y6X64TLJcLlZ0EQm9QjRgaMN9xn7qYYTYrJfgIdTIqxdG5YtZI+IXaq8uW7B42DzXxpNJbSvuwQQ+wrwDDzEKQh9zPgugs0LrOgToUXak2g7mu4ohi3sm8aSu+M2AMx7ZxJUWJbNlod0TFcR8sLMn+Up2+A+QjxgiqzGrtkIBmnSzGkjOw3++WFqboIQfcd4NyMqvuoCBc1rJCov3YIuL6Z9u4pUzUMuWzzKMYPYX6rt5Rf9QiFeTT/8UYF1bX7xT795URox+vbYwQtiR+3IInWfauodOk4wTvqtkfqWMrrA0erphVj6t+IM9yEjDg3ghHJTtUZJZN5pYcFjK1irPdGfdxUPRgHqxJG+fBIVYseK4wBOLWKcZIt8l5Gyc10PlROFTa8ktiAWjauJCfDpu3wxjduirod4y5sVWJ3xFooKiDaTJs22/vnYHvW9g8gtvNvC0XkMLGLXXkAAAAASUVORK5CYII=\"}]}"},{"id":3054,"title":"Chess ELO rating system","description":"The Elo rating system is a method for calculating the relative chess skill levels of players in competitor-versus-competitor games. ( \u003chttp://en.wikipedia.org/wiki/Elo_rating_system\u003e )\r\n\r\nThe difference in the ratings (rating=ELO) between two players serves as a predictor of the outcome of a match. Two players with equal ratings who play against each other are expected to score an equal number of wins. A player whose rating is 100 points greater than their opponent's is expected to score 64%; if the difference is 200 points, then the expected score for the stronger player is 76%.\r\n\r\nSome chess organizations use the \"algorithm of 400\" to calculate performance rating. According to this algorithm, performance rating for an event is calculated by taking (1) the rating of each player beaten and adding 400, (2) the rating of each player lost to and subtracting 400, (3) the rating of each player drawn, and (4) summing these figures and dividing by the number of games played.\r\n\r\nFind the performance with this algorithm with ELO players and results (0=loss,0.5=draw,1=win) in input.","description_html":"\u003cp\u003eThe Elo rating system is a method for calculating the relative chess skill levels of players in competitor-versus-competitor games. ( \u003ca href = \"http://en.wikipedia.org/wiki/Elo_rating_system\"\u003ehttp://en.wikipedia.org/wiki/Elo_rating_system\u003c/a\u003e )\u003c/p\u003e\u003cp\u003eThe difference in the ratings (rating=ELO) between two players serves as a predictor of the outcome of a match. Two players with equal ratings who play against each other are expected to score an equal number of wins. A player whose rating is 100 points greater than their opponent's is expected to score 64%; if the difference is 200 points, then the expected score for the stronger player is 76%.\u003c/p\u003e\u003cp\u003eSome chess organizations use the \"algorithm of 400\" to calculate performance rating. According to this algorithm, performance rating for an event is calculated by taking (1) the rating of each player beaten and adding 400, (2) the rating of each player lost to and subtracting 400, (3) the rating of each player drawn, and (4) summing these figures and dividing by the number of games played.\u003c/p\u003e\u003cp\u003eFind the performance with this algorithm with ELO players and results (0=loss,0.5=draw,1=win) in input.\u003c/p\u003e","function_template":"function y = algo400(players,result)\r\n  y = x;\r\nend","test_suite":"%%\r\nplayers = 1000;\r\nresult = 1;\r\nassert(isequal(algo400(players,result),1400))\r\n%%\r\nplayers = 1000;\r\nresult = 0.5;\r\nassert(isequal(algo400(players,result),1000))\r\n%%\r\nassert(isequal(algo400([2000 2000],[0.5 0.5]),2000))\r\n%%\r\nplayers = [2000 2000];\r\nresult = [1 1];\r\nassert(isequal(algo400(players,result),2400))\r\n%%\r\nplayers = [2000 2000];\r\nresult = [0.5 1];\r\nassert(isequal(algo400(players,result),2200))\r\n%%\r\nplayers = [2000 2100 2200 2300];\r\nresult = [1 0.5 1 0.5];\r\nassert(isequal(algo400(players,result),2350))\r\n%%\r\nplayers = 1000;\r\nresult = 1;\r\nassert(isequal(algo400(players,result),1400))\r\n%% My last performance (my ELO is 1800)\r\nplayers = [1399 1280 2166 1534 1768 1791 1540];\r\nresult = [1 1 0 1 1 0 1];\r\nassert(isequal(round(algo400(players,result)),1811))\r\n%%\r\nplayers = [2000 2100 2200 2300];\r\nresult = [0.5 0.5 0.5 0.5];\r\nassert(isequal(algo400(players,result),2150))\r\n%% Caruana perfomance in 2014 Sinquefield Cup\r\nplayers = [2772 2768 2877 2805 2787  2772 2768 2877 2787 2805];\r\nresult = [1 1 1 1 1 1 1 0.5 0.5 0.5];\r\nassert(isequal(round(algo400(players,result)),3082))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":5390,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":96,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-02-28T18:02:19.000Z","updated_at":"2026-02-15T07:29:20.000Z","published_at":"2015-02-28T18:03: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\u003eThe Elo rating system is a method for calculating the relative chess skill levels of players in competitor-versus-competitor games. (\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Elo_rating_system\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://en.wikipedia.org/wiki/Elo_rating_system\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e )\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe difference in the ratings (rating=ELO) between two players serves as a predictor of the outcome of a match. Two players with equal ratings who play against each other are expected to score an equal number of wins. A player whose rating is 100 points greater than their opponent's is expected to score 64%; if the difference is 200 points, then the expected score for the stronger player is 76%.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSome chess organizations use the \\\"algorithm of 400\\\" to calculate performance rating. According to this algorithm, performance rating for an event is calculated by taking (1) the rating of each player beaten and adding 400, (2) the rating of each player lost to and subtracting 400, (3) the rating of each player drawn, and (4) summing these figures and dividing by the number of games played.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the performance with this algorithm with ELO players and results (0=loss,0.5=draw,1=win) in input.\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":821,"title":"Pentago: find winning move","description":"\u003chttp://en.wikipedia.org/wiki/Pentago Pentago\u003e is a challenging two-player strategy game. The objective is to be the first player to connect five marbles in a row (horizontally, vertically, or diagonally) on the board. The 6x6 board consists of four 3x3 game blocks, each of which can be twisted in 90-degree intervals (CW/CCW).  During a turn, a player places a marble anywhere on the board and _then_ rotates one of the game blocks 90 degrees in either direction. The marble does not have to be played on the same block that is rotated.\r\n\r\nFor this problem, you are given a 6x6 matrix representing the current board setup, where 0s, 1s, and 2s correspond to empty spaces, Player 1 marbles, and Player 2 marbles, respectively. You are Player 1 and it is your turn. If there is a winning move, return the row and column subscripts of the winning play as well as the required rotation (see below for details). If you can win without rotating a game block, return [] for the second output. If there is no winning move on this turn, both outputs should be []. You may assume that there will be only one winning move, if any.\r\n\r\n*Input:*\r\n\r\n* _board_ - 6x6 matrix of filled with 0-2\r\n\r\n*Output:*\r\n\r\n* _pos_ - 1x2 vector with row and column of winning move (if any).\r\n* _rot_ - 2x2 matrix describing rotation required to win (if any). A CW rotation is indicated by a 1, while a CCW rotation is indicated by a -1. For example,\r\n\r\n  rot = [-1 0\r\n          0 0]   \r\n\r\nmeans the top-left game block was rotated 90 degrees in the counterclockwise direction.\r\n\r\n  rot = [0 0\r\n         0 1]\r\n\r\nmeans the bottom-right game block was rotated 90 degrees in the clockwise direction.\r\n\r\n*Example*\r\n\r\n  board = 0 0 0 0 2 0\r\n          1 1 1 2 1 0\r\n          0 0 0 0 0 0\r\n          0 2 0 2 0 0\r\n          0 1 0 0 0 0\r\n          0 0 0 0 0 0\r\n\r\nshould return\r\n\r\n  pos = [3 5]\r\n  rot = [0 1\r\n         0 0]\r\n\r\nbecause placing a marble at (3,5) yields\r\n\r\n  0 0 0 0 2 0\r\n  1 1 1 2 1 0\r\n  0 0 0 0 1 0\r\n  0 2 0 2 0 0\r\n  0 1 0 0 0 0\r\n  0 0 0 0 0 0\r\n\r\nand then rotating the top-right block CW yields\r\n\r\n\r\n  0 0 0 0 2 0\r\n  1 1 1 1 1 2\r\n  0 0 0 0 0 0\r\n  0 2 0 2 0 0\r\n  0 1 0 0 0 0\r\n  0 0 0 0 0 0\r\n\r\nwhich gives Player 1 the win with 5 in a row (see 2nd row).","description_html":"\u003cp\u003e\u003ca href=\"http://en.wikipedia.org/wiki/Pentago\"\u003ePentago\u003c/a\u003e is a challenging two-player strategy game. The objective is to be the first player to connect five marbles in a row (horizontally, vertically, or diagonally) on the board. The 6x6 board consists of four 3x3 game blocks, each of which can be twisted in 90-degree intervals (CW/CCW).  During a turn, a player places a marble anywhere on the board and \u003ci\u003ethen\u003c/i\u003e rotates one of the game blocks 90 degrees in either direction. The marble does not have to be played on the same block that is rotated.\u003c/p\u003e\u003cp\u003eFor this problem, you are given a 6x6 matrix representing the current board setup, where 0s, 1s, and 2s correspond to empty spaces, Player 1 marbles, and Player 2 marbles, respectively. You are Player 1 and it is your turn. If there is a winning move, return the row and column subscripts of the winning play as well as the required rotation (see below for details). If you can win without rotating a game block, return [] for the second output. If there is no winning move on this turn, both outputs should be []. You may assume that there will be only one winning move, if any.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ci\u003eboard\u003c/i\u003e - 6x6 matrix of filled with 0-2\u003c/li\u003e\u003c/ul\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ci\u003epos\u003c/i\u003e - 1x2 vector with row and column of winning move (if any).\u003c/li\u003e\u003cli\u003e\u003ci\u003erot\u003c/i\u003e - 2x2 matrix describing rotation required to win (if any). A CW rotation is indicated by a 1, while a CCW rotation is indicated by a -1. For example,\u003c/li\u003e\u003c/ul\u003e\u003cpre class=\"language-matlab\"\u003erot = [-1 0\r\n        0 0]   \r\n\u003c/pre\u003e\u003cp\u003emeans the top-left game block was rotated 90 degrees in the counterclockwise direction.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003erot = [0 0\r\n       0 1]\r\n\u003c/pre\u003e\u003cp\u003emeans the bottom-right game block was rotated 90 degrees in the clockwise direction.\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample\u003c/b\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eboard = 0 0 0 0 2 0\r\n        1 1 1 2 1 0\r\n        0 0 0 0 0 0\r\n        0 2 0 2 0 0\r\n        0 1 0 0 0 0\r\n        0 0 0 0 0 0\r\n\u003c/pre\u003e\u003cp\u003eshould return\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003epos = [3 5]\r\nrot = [0 1\r\n       0 0]\r\n\u003c/pre\u003e\u003cp\u003ebecause placing a marble at (3,5) yields\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e0 0 0 0 2 0\r\n1 1 1 2 1 0\r\n0 0 0 0 1 0\r\n0 2 0 2 0 0\r\n0 1 0 0 0 0\r\n0 0 0 0 0 0\r\n\u003c/pre\u003e\u003cp\u003eand then rotating the top-right block CW yields\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e0 0 0 0 2 0\r\n1 1 1 1 1 2\r\n0 0 0 0 0 0\r\n0 2 0 2 0 0\r\n0 1 0 0 0 0\r\n0 0 0 0 0 0\r\n\u003c/pre\u003e\u003cp\u003ewhich gives Player 1 the win with 5 in a row (see 2nd row).\u003c/p\u003e","function_template":"function [pos rot] = pentago_win(board)\r\n  pos = [];\r\n  rot = [];\r\nend","test_suite":"%%\r\nboard =[0 0 0 0 2 1\r\n        1 2 2 2 1 0\r\n        0 0 0 1 0 0\r\n        0 2 1 2 0 0\r\n        0 0 0 0 0 0\r\n        0 0 0 0 0 0];\r\npos_correct = [5 2];\r\nrot_correct = [];\r\n[pos rot] = pentago_win(board);\r\nassert(isequal(pos,pos_correct) \u0026\u0026 isequal(rot,rot_correct))\r\n\r\n%%\r\nboard =[0 0 0 0 1 0\r\n        1 2 2 2 1 0\r\n        0 0 0 1 1 0\r\n        0 2 2 2 0 0\r\n        0 2 0 1 0 0\r\n        0 0 0 0 0 0];\r\npos_correct = [5 5];\r\nrot_correct = [0 0;0 1];\r\n[pos rot] = pentago_win(board);\r\nassert(isequal(pos,pos_correct) \u0026\u0026 isequal(rot,rot_correct))\r\n\r\n%%\r\nboard =[0 0 1 1 1 2\r\n        2 2 0 2 2 0\r\n        0 0 1 0 1 0\r\n        0 2 0 2 0 0\r\n        0 0 0 1 0 0\r\n        0 0 0 0 0 0];\r\npos_correct = [2 3];\r\nrot_correct = [-1 0;0 0];\r\n[pos rot] = pentago_win(board);\r\nassert(isequal(pos,pos_correct) \u0026\u0026 isequal(rot,rot_correct))\r\n\r\n%%\r\nboard =[1 0 2 1 1 2\r\n        2 0 0 2 2 0\r\n        0 0 1 0 1 0\r\n        1 2 0 2 0 0\r\n        0 1 2 1 0 0\r\n        0 0 1 2 0 0];\r\npos_correct = [];\r\nrot_correct = [];\r\n[pos rot] = pentago_win(board);\r\nassert(isequal(pos,pos_correct) \u0026\u0026 isequal(rot,rot_correct))\r\n\r\n%%\r\nboard =[1 0 2 1 2 0\r\n        2 0 0 2 1 0\r\n        0 0 1 1 2 0\r\n        2 2 0 2 0 0\r\n        0 1 2 1 0 0\r\n        0 0 1 2 0 1];\r\npos_correct = [1 6];\r\nrot_correct = [0 0;-1 0];\r\n[pos rot] = pentago_win(board);\r\nassert(isequal(pos,pos_correct) \u0026\u0026 isequal(rot,rot_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":4793,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":35,"test_suite_updated_at":"2012-07-09T21:39:10.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-07-09T20:36:50.000Z","updated_at":"2026-02-15T07:32:20.000Z","published_at":"2012-07-09T21:39:10.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Pentago\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePentago\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is a challenging two-player strategy game. The objective is to be the first player to connect five marbles in a row (horizontally, vertically, or diagonally) on the board. The 6x6 board consists of four 3x3 game blocks, each of which can be twisted in 90-degree intervals (CW/CCW). During a turn, a player places a marble anywhere on the board 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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ethen\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e rotates one of the game blocks 90 degrees in either direction. The marble does not have to be played on the same block that is rotated.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor this problem, you are given a 6x6 matrix representing the current board setup, where 0s, 1s, and 2s correspond to empty spaces, Player 1 marbles, and Player 2 marbles, respectively. You are Player 1 and it is your turn. If there is a winning move, return the row and column subscripts of the winning play as well as the required rotation (see below for details). If you can win without rotating a game block, return [] for the second output. If there is no winning move on this turn, both outputs should be []. You may assume that there will be only one winning move, if any.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eboard\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e - 6x6 matrix of filled with 0-2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003epos\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e - 1x2 vector with row and column of winning move (if any).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003erot\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e - 2x2 matrix describing rotation required to win (if any). A CW rotation is indicated by a 1, while a CCW rotation is indicated by a -1. For example,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[rot = [-1 0\\n        0 0]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003emeans the top-left game block was rotated 90 degrees in the counterclockwise direction.\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[rot = [0 0\\n       0 1]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003emeans the bottom-right game block was rotated 90 degrees in the clockwise direction.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[board = 0 0 0 0 2 0\\n        1 1 1 2 1 0\\n        0 0 0 0 0 0\\n        0 2 0 2 0 0\\n        0 1 0 0 0 0\\n        0 0 0 0 0 0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eshould return\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[pos = [3 5]\\nrot = [0 1\\n       0 0]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ebecause placing a marble at (3,5) yields\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[0 0 0 0 2 0\\n1 1 1 2 1 0\\n0 0 0 0 1 0\\n0 2 0 2 0 0\\n0 1 0 0 0 0\\n0 0 0 0 0 0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eand then rotating the top-right block CW yields\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[0 0 0 0 2 0\\n1 1 1 1 1 2\\n0 0 0 0 0 0\\n0 2 0 2 0 0\\n0 1 0 0 0 0\\n0 0 0 0 0 0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ewhich gives Player 1 the win with 5 in a row (see 2nd row).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1133,"title":"Go-style solver","description":"Consider a variation of the game Go where one player has gone ahead and placed several pieces all at once. Assuming that the second player also gets to place several pieces at once, find the minimum number of pieces that the second player needs to place in order to capture all of the pieces placed by the first player.\r\n\r\nThe first player's pieces will be represented by ones and the empty spaces will be represented by zeros.\r\n\r\nTo capture a piece, it and every piece that touches it need to be surrounded horizontally and vertically. The board won't necessarily be square. If the first player filled the entire board, return 0. \r\n\r\nSo for the board:\r\n\r\n  1 0 0 1\r\n0 0 0 1\r\n0 0 1 0\r\n\r\n\r\nThe resulting board, with the fewest pieces required, would look like\r\n\r\n  1 2 2 1\r\n2 0 2 1\r\n0 2 1 2\r\n\r\nand your program would return 6","description_html":"\u003cp\u003eConsider a variation of the game Go where one player has gone ahead and placed several pieces all at once. Assuming that the second player also gets to place several pieces at once, find the minimum number of pieces that the second player needs to place in order to capture all of the pieces placed by the first player.\u003c/p\u003e\u003cp\u003eThe first player's pieces will be represented by ones and the empty spaces will be represented by zeros.\u003c/p\u003e\u003cp\u003eTo capture a piece, it and every piece that touches it need to be surrounded horizontally and vertically. The board won't necessarily be square. If the first player filled the entire board, return 0.\u003c/p\u003e\u003cp\u003eSo for the board:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e1 0 0 1\r\n0 0 0 1\r\n0 0 1 0\r\n\u003c/pre\u003e\u003cp\u003eThe resulting board, with the fewest pieces required, would look like\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e1 2 2 1\r\n2 0 2 1\r\n0 2 1 2\r\n\u003c/pre\u003e\u003cp\u003eand your program would return 6\u003c/p\u003e","function_template":"function number_of_pieces = taking_liberties(board)\r\n  number_of_pieces=3;\r\nend","test_suite":"%%\r\nboard=[1 0 0 1; 0 0 0 1; 0 0 1 0];\r\ny_correct=6;\r\nassert(isequal(taking_liberties(board),y_correct))\r\n\r\n\r\n%%\r\nboard=eye(7);\r\ny_correct=12;\r\nassert(isequal(taking_liberties(board),y_correct))\r\n\r\n%%\r\nboard=double(magic(4)\u003e12);\r\ny_correct=8;\r\nassert(isequal(taking_liberties(board),y_correct))\r\n\r\n%%\r\nboard=double(hadamard(8)\u003c0);\r\ny_correct=29;\r\nassert(isequal(taking_liberties(board),y_correct))\r\n\r\n%%\r\nboard=ones(4);\r\ny_correct=0;\r\nassert(isequal(taking_liberties(board),y_correct))\r\n\r\n%%\r\nboard=vertcat(eye(5),[1 0 1 0 1]);\r\ny_correct=12;\r\nassert(isequal(taking_liberties(board),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":5065,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-12-21T21:55:47.000Z","updated_at":"2026-03-30T19:01:12.000Z","published_at":"2012-12-21T22:04: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\u003eConsider a variation of the game Go where one player has gone ahead and placed several pieces all at once. Assuming that the second player also gets to place several pieces at once, find the minimum number of pieces that the second player needs to place in order to capture all of the pieces placed by the first player.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe first player's pieces will be represented by ones and the empty spaces will be represented by zeros.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo capture a piece, it and every piece that touches it need to be surrounded horizontally and vertically. The board won't necessarily be square. If the first player filled the entire board, 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\u003eSo for the board:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[1 0 0 1\\n0 0 0 1\\n0 0 1 0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe resulting board, with the fewest pieces required, would look like\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[1 2 2 1\\n2 0 2 1\\n0 2 1 2]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eand your program would return 6\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1481,"title":"Game of Nim","description":"\r\nThe Game of Nim is a famous studied 2 player strategy game. \r\n\u003chttp://en.wikipedia.org/wiki/Nim\u003e\r\n\r\nThere are 3 heaps, and you are given the number of pebbles in each heap.\r\nPlayer 1 and 2 take turns removing pebbles from each heap.  \r\nGame ends when a player cannot remove any pebbles from any heap, and the last player able to do so is the winner.  \r\n \r\nGiven the number of pebbles in each heap, determine if player-1 will win assuming that both player play their optimal strategy, ie their best possible moves.\r\n\r\nProblem 5)\r\nPrev: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1478 1478\u003e\r\nNext: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1482 1482\u003e","description_html":"\u003cp\u003eThe Game of Nim is a famous studied 2 player strategy game.  \u003ca href = \"http://en.wikipedia.org/wiki/Nim\"\u003ehttp://en.wikipedia.org/wiki/Nim\u003c/a\u003e\u003c/p\u003e\u003cp\u003eThere are 3 heaps, and you are given the number of pebbles in each heap.\r\nPlayer 1 and 2 take turns removing pebbles from each heap.  \r\nGame ends when a player cannot remove any pebbles from any heap, and the last player able to do so is the winner.\u003c/p\u003e\u003cp\u003eGiven the number of pebbles in each heap, determine if player-1 will win assuming that both player play their optimal strategy, ie their best possible moves.\u003c/p\u003e\u003cp\u003eProblem 5)\r\nPrev: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1478\"\u003e1478\u003c/a\u003e\r\nNext: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1482\"\u003e1482\u003c/a\u003e\u003c/p\u003e","function_template":"function out = game_nim(hvect)\r\n  heapindex0;\r\n  removecount=0;\r\n  out = [heapindex removecount];\r\nend","test_suite":"%%\r\nx = [3 4 5];\r\ny_correct = [1 2];\r\nassert(isequal(game_nim(x),y_correct))\r\n\r\n%%\r\nx = [0 7 9];\r\ny_correct = [3 2];\r\nassert(isequal(game_nim(x),y_correct))\r\n\r\n%%\r\nx = [7 7 7 ];\r\ny_correct = [1 7];\r\nassert(isequal(game_nim(x),y_correct))\r\n\r\n%%\r\nx = [112 98 99];\r\ny_correct = [1 111];\r\nassert(isequal(game_nim(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":11275,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":38,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-04-30T23:50:29.000Z","updated_at":"2026-02-15T07:35:53.000Z","published_at":"2013-04-30T23:50:29.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe Game of Nim is a famous studied 2 player strategy game. \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/Nim\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://en.wikipedia.org/wiki/Nim\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are 3 heaps, and you are given the number of pebbles in each heap. Player 1 and 2 take turns removing pebbles from each heap. Game ends when a player cannot remove any pebbles from any heap, and the last player able to do so is the winner.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven the number of pebbles in each heap, determine if player-1 will win assuming that both player play their optimal strategy, ie their best possible moves.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 5) Prev:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1478\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1478\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e Next:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1482\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1482\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":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":1301,"title":"RISK Calculator - Large Armies, High Accuracy, Fast","description":"This Challenge is to quickly provide the high precision probability of legal RISK battles up to 100 vs 100.  [ Attack \u003e= 2 and Defense \u003e=1 ].\r\n\r\nRelated to  \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1260-risk-board-game-battle-simulation/solutions/map Cody 1260 RISK Board Game Battle Simulation\u003e\r\n\r\n\u003chttp://en.wikipedia.org/wiki/Risk_%28game%29#Official Link to official Risk Rules\u003e\r\n\r\n*Simplified explanation of the dice play:*\r\n  \r\n  Attacker with 2 armies will throw one die.\r\n  Attacker with 3 armies will throw two die.\r\n  Attacker with 4 or more armies will throw three die.\r\n  \r\n  Defense with 1 army will use one die.\r\n  Defense with 2 or more armies will throw 2 die.\r\n  \r\n  The attacker High is compared to the Defender High.\r\n  If Attacker High \u003e Defender High then defender loses 1 army otherwise Attacker loses 1 army. Tie goes to defender.\r\n  If the Defender threw two die and the Attacker threw 2 or more die then the Second Highest of each is compared. \r\nIf Attack \u003e Defense then Defense loses an army otherwise Attack loses an army.\r\nAttack continues until No defenders remain (Win) or Attack is reduced to 1 army (Lose). \r\n\r\n*Input:* a,d where a is number of attacking armies and d is number defending\r\n\r\n*Output:* pwin, the probability of the Attacker Winning\r\n\r\n*Accuracy:* Accurate to +/- 1e-6\r\n\r\n*Scoring:* Time (msec) to solve 10 Battle Scenarios \r\n\r\n\r\n\u003chttp://recreationalmath.com/Risk/  Risk Calculator\u003e","description_html":"\u003cp\u003eThis Challenge is to quickly provide the high precision probability of legal RISK battles up to 100 vs 100.  [ Attack \u003e= 2 and Defense \u003e=1 ].\u003c/p\u003e\u003cp\u003eRelated to  \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1260-risk-board-game-battle-simulation/solutions/map\"\u003eCody 1260 RISK Board Game Battle Simulation\u003c/a\u003e\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://en.wikipedia.org/wiki/Risk_%28game%29#Official\"\u003eLink to official Risk Rules\u003c/a\u003e\u003c/p\u003e\u003cp\u003e\u003cb\u003eSimplified explanation of the dice play:\u003c/b\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eAttacker with 2 armies will throw one die.\r\nAttacker with 3 armies will throw two die.\r\nAttacker with 4 or more armies will throw three die.\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eDefense with 1 army will use one die.\r\nDefense with 2 or more armies will throw 2 die.\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eThe attacker High is compared to the Defender High.\r\nIf Attacker High \u003e Defender High then defender loses 1 army otherwise Attacker loses 1 army. Tie goes to defender.\r\nIf the Defender threw two die and the Attacker threw 2 or more die then the Second Highest of each is compared. \r\nIf Attack \u003e Defense then Defense loses an army otherwise Attack loses an army.\r\nAttack continues until No defenders remain (Win) or Attack is reduced to 1 army (Lose). \r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e a,d where a is number of attacking armies and d is number defending\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e pwin, the probability of the Attacker Winning\u003c/p\u003e\u003cp\u003e\u003cb\u003eAccuracy:\u003c/b\u003e Accurate to +/- 1e-6\u003c/p\u003e\u003cp\u003e\u003cb\u003eScoring:\u003c/b\u003e Time (msec) to solve 10 Battle Scenarios\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://recreationalmath.com/Risk/\"\u003eRisk Calculator\u003c/a\u003e\u003c/p\u003e","function_template":"function pwin = risk_prob(a, d)\r\n pwin=0;\r\nend","test_suite":"%%\r\nfeval(@assignin,'caller','score',5000); % msec\r\n%%\r\na=[100 99 100 10 9 2 2 10 30 70];\r\nd=[100 100 99 9 10 1 2 2 30 80];\r\ny_c=[0.8079031789315619 0.7888693135658454 0.8230449788340404 0.5580697529719042 0.3798720048109818 0.4166666666666667 0.10609567901234569 0.9901146432872121 0.633266311153744 0.5011352886279803];\r\n\r\ntsum=0;\r\nfor i=1:length(a)\r\n ta=clock;\r\n y=risk_prob(a(i), d(i));\r\n t1=etime(clock,ta)*1000; % time in msec\r\n tsum=tsum+t1;\r\n assert(abs(y - y_c(i)) \u003c= 1e-6,sprintf('A=%i D=%i Expect=%.9f pwin=%.9f',a(i),d(i),y_c(i),y))\r\n fprintf('A %3i  D %3i  Time(msec) %7.3f\\n',a(i),d(i),t1);\r\nend\r\n\r\nfeval(  @assignin,'caller','score',floor(min( 5000,tsum ))  );","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":27,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-02-25T00:07:52.000Z","updated_at":"2026-02-15T07:40:59.000Z","published_at":"2013-02-25T04:24:12.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis Challenge is to quickly provide the high precision probability of legal RISK battles up to 100 vs 100. [ Attack \u0026gt;= 2 and Defense \u0026gt;=1 ].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRelated to \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1260-risk-board-game-battle-simulation/solutions/map\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody 1260 RISK Board Game Battle Simulation\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Risk_%28game%29#Official\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eLink to official Risk Rules\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSimplified explanation of the dice play:\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[Attacker with 2 armies will throw one die.\\nAttacker with 3 armies will throw two die.\\nAttacker with 4 or more armies will throw three die.\\n\\nDefense with 1 army will use one die.\\nDefense with 2 or more armies will throw 2 die.\\n\\nThe attacker High is compared to the Defender High.\\nIf Attacker High \u003e Defender High then defender loses 1 army otherwise Attacker loses 1 army. Tie goes to defender.\\nIf the Defender threw two die and the Attacker threw 2 or more die then the Second Highest of each is compared. \\nIf Attack \u003e Defense then Defense loses an army otherwise Attack loses an army.\\nAttack continues until No defenders remain (Win) or Attack is reduced to 1 army (Lose).]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e a,d where a is number of attacking armies and d is number defending\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e pwin, the probability of the Attacker Winning\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eAccuracy:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Accurate to +/- 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eScoring:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Time (msec) to solve 10 Battle Scenarios\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://recreationalmath.com/Risk/\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRisk Calculator\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"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}}