{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-04-26T00:14:02.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2026-04-26T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":44311,"title":"Number of Even Elements in Fibonacci Sequence","description":"Find how many even Fibonacci numbers are available in the first d numbers.\r\n\r\nConsider the following first 14 numbers\r\n\r\n  1 1 2 3 5 8 13 21 34 55 89 144 233 377 ...\r\n\r\n4 of them are even. ","description_html":"\u003cp\u003eFind how many even Fibonacci numbers are available in the first d numbers.\u003c/p\u003e\u003cp\u003eConsider the following first 14 numbers\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e1 1 2 3 5 8 13 21 34 55 89 144 233 377 ...\r\n\u003c/pre\u003e\u003cp\u003e4 of them are even.\u003c/p\u003e","function_template":"function y = evenFibo(d)\r\n  y = x;\r\nend","test_suite":"%%\r\nd = 14;\r\ny_correct = 4;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 20;\r\ny_correct = 6;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 50;\r\ny_correct = 16;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 100;\r\ny_correct = 33;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 150;\r\ny_correct = 50;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 200;\r\ny_correct = 66;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 500;\r\ny_correct = 166;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 1000;\r\ny_correct = 333;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 1e4;\r\ny_correct = 3333;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 2e4;\r\ny_correct = 6666;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 3e5;\r\ny_correct = 1e5;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 6e6;\r\ny_correct = 2e6;\r\nassert(isequal(evenFibo(d),y_correct))\r\n% \r\n% %%\r\n% d = 9223372036854775807;\r\n% y_correct = 3074457345618258432;\r\n% assert(isequal(evenFibo(d),y_correct))\r\n","published":true,"deleted":false,"likes_count":21,"comments_count":9,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1667,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-11T12:36:15.000Z","updated_at":"2026-04-28T16:23:13.000Z","published_at":"2017-10-16T01:50:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind how many even Fibonacci numbers are available in the first d numbers.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eConsider the following first 14 numbers\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 1 2 3 5 8 13 21 34 55 89 144 233 377 ...]]\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\u003e4 of them are even.\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":44364,"title":"Is this a valid Tic Tac Toe State?","description":"For the game of \u003chttps://en.wikipedia.org/wiki/Tic-tac-toe Tic Tac Toe\u003e we will be storing the state of the game in a matrix M.\r\n\r\nFor this game: \r\n\r\n\u003c\u003chttps://upload.wikimedia.org/wikipedia/commons/3/32/Tic_tac_toe.svg\u003e\u003e\r\n\r\nWe would store the state as this:\r\n\r\n  -1  1  1 \r\n   1 -1 -1\r\n   1 -1 -1\r\n\r\nIf there were any blanks squares, they would be 0;\r\n\r\nFor this challenge, X goes first. Neither side is compelled to take a win if possible. The game stops when either player wins.\r\n\r\nFor this challenge, is the the given board state\r\n 0: legal \r\n 1: this state can not occur in a game\r\n\r\nThe example in the image would return 0 because if X goes first there can never be more O than X. The state matrix will only hold [-1 0 1], so we are only checking for logic of the game.","description_html":"\u003cp\u003eFor the game of \u003ca href = \"https://en.wikipedia.org/wiki/Tic-tac-toe\"\u003eTic Tac Toe\u003c/a\u003e we will be storing the state of the game in a matrix M.\u003c/p\u003e\u003cp\u003eFor this game:\u003c/p\u003e\u003cimg src = \"https://upload.wikimedia.org/wikipedia/commons/3/32/Tic_tac_toe.svg\"\u003e\u003cp\u003eWe would store the state as this:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e-1  1  1 \r\n 1 -1 -1\r\n 1 -1 -1\r\n\u003c/pre\u003e\u003cp\u003eIf there were any blanks squares, they would be 0;\u003c/p\u003e\u003cp\u003eFor this challenge, X goes first. Neither side is compelled to take a win if possible. The game stops when either player wins.\u003c/p\u003e\u003cp\u003eFor this challenge, is the the given board state\r\n 0: legal \r\n 1: this state can not occur in a game\u003c/p\u003e\u003cp\u003eThe example in the image would return 0 because if X goes first there can never be more O than X. The state matrix will only hold [-1 0 1], so we are only checking for logic of the game.\u003c/p\u003e","function_template":"function y = isLegalTicTacToeState(M)\r\n  y = round(rand);\r\nend","test_suite":"%%\r\nx = [1 1 0\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [0 0 0\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 1;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [  -1  1  1 \r\n        1 -1 -1\r\n        1 -1 -1];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [ 0 -1 1\r\n     -1  1 0\r\n      1  0 0];\r\ny_correct = 1;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [ 1  1  1\r\n     -1 -1 -1\r\n      0  0  0];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [-1 1 1\r\n     0 -1 1\r\n     1 0 -1];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [-1 1 0\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 1;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [-1 0 0\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [-1 1 0\r\n     0 1 0\r\n     0 1 0];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [1  1  1\r\n     -1 1 -1\r\n     -1 1 -1];\r\ny_correct = 1;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":6,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":133,"test_suite_updated_at":"2017-10-20T22:46:06.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-09T23:21:35.000Z","updated_at":"2026-04-18T14:02:29.000Z","published_at":"2017-10-20T22:46:06.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor the game of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Tic-tac-toe\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eTic Tac Toe\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e we will be storing the state of the game in a matrix M.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor this game:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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\u003eWe would store the state as this:\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  1  1 \\n 1 -1 -1\\n 1 -1 -1]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf there were any blanks squares, they would be 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\u003eFor this challenge, X goes first. Neither side is compelled to take a win if possible. The game stops when either player wins.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor this challenge, is the the given board state 0: legal 1: this state can not occur in a game\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe example in the image would return 0 because if X goes first there can never be more O than X. The state matrix will only hold [-1 0 1], so we are only checking for logic of the game.\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":44365,"title":"An asteroid and a spacecraft","description":"\r\n\u0026#128640 Imagine a non-relativistic simple situation. \r\n\r\nAssume positions p0, p1, p2, and p3 are three dimensional Cartesian coordinates.\r\n\r\nYour spacecraft started from the position p0 at time t0. \r\n\r\nYour spacecraft is moving with a constant velocity.\r\n\r\nYour spacecraft is expected to reach a star at the location p1 at time t1.\r\n\r\nYou just heard over the radio that an asteroid has been identified at the location p2 at time t0.\r\n\r\nThe asteroid is moving with a constant velocity.\r\n\r\nThe asteroid is expected to reach another star at the location p3 at time t1. \r\n\r\nYou need to write a code 'safetrip' in MATLAB to return true if the minimum distance between your spacecraft and the asteroid will be more than the distance d during the time interval between t0 and t1, otherwise return false.","description_html":"\u003cp\u003e\u0026#128640 Imagine a non-relativistic simple situation.\u003c/p\u003e\u003cp\u003eAssume positions p0, p1, p2, and p3 are three dimensional Cartesian coordinates.\u003c/p\u003e\u003cp\u003eYour spacecraft started from the position p0 at time t0.\u003c/p\u003e\u003cp\u003eYour spacecraft is moving with a constant velocity.\u003c/p\u003e\u003cp\u003eYour spacecraft is expected to reach a star at the location p1 at time t1.\u003c/p\u003e\u003cp\u003eYou just heard over the radio that an asteroid has been identified at the location p2 at time t0.\u003c/p\u003e\u003cp\u003eThe asteroid is moving with a constant velocity.\u003c/p\u003e\u003cp\u003eThe asteroid is expected to reach another star at the location p3 at time t1.\u003c/p\u003e\u003cp\u003eYou need to write a code 'safetrip' in MATLAB to return true if the minimum distance between your spacecraft and the asteroid will be more than the distance d during the time interval between t0 and t1, otherwise return false.\u003c/p\u003e","function_template":"function ok = safetrip(d, t0, t1, p0, p1, p2, p3)\r\n    if d\u003e1000000000\r\n        ok = true;\r\n    end\r\nend","test_suite":"%%\r\np0 = [0 0 0];\r\np1 = [1 1 1];\r\np2 = [2 2 2];\r\np3 = [3 3 3];\r\nt0 = 0; \r\nt1 = 1;\r\nd = 1;\r\nok = true;\r\nassert(isequal(safetrip(d, t0, t1, p0, p1, p2, p3), ok))\r\n\r\n%%\r\np0 = [3 3 3];\r\np1 = [2 2 2];\r\np2 = [2 2 2];\r\np3 = [3 3 3];\r\nt0 = 0; \r\nt1 = 1;\r\nd = 1;\r\nok = false;\r\nassert(isequal(safetrip(d, t0, t1, p0, p1, p2, p3), ok))\r\n\r\n%%\r\np0 = [1 2 3];\r\np1 = [4 5 6];\r\np2 = [3 2 1];\r\np3 = [6 5 4];\r\nt0 = 10; \r\nt1 = 20;\r\nd = 2;\r\nok = true;\r\nassert(isequal(safetrip(d, t0, t1, p0, p1, p2, p3), ok))\r\n\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":8,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":180,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-10T02:30:44.000Z","updated_at":"2026-04-18T10:51:25.000Z","published_at":"2017-10-16T01:51: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\",\"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\u003e\u0026amp;#128640 Imagine a non-relativistic simple situation.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 positions p0, p1, p2, and p3 are three dimensional Cartesian coordinates.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 spacecraft started from the position p0 at time t0.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 spacecraft is moving with a constant velocity.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 spacecraft is expected to reach a star at the location p1 at time t1.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 just heard over the radio that an asteroid has been identified at the location p2 at time t0.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 asteroid is moving with a constant velocity.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 asteroid is expected to reach another star at the location p3 at time t1.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 need to write a code 'safetrip' in MATLAB to return true if the minimum distance between your spacecraft and the asteroid will be more than the distance d during the time interval between t0 and t1, otherwise return false.\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":44381,"title":"Cache me Outside","description":"The test suite includes a simple recursive Fibonacci sequence generator, but it's terribly inefficient. One simple method for improving its performance is using a technique called memoization. Write a function that takes a function_handle that we wish to memoize and returns a function_handle to a memoized version of the initial handle.","description_html":"\u003cp\u003eThe test suite includes a simple recursive Fibonacci sequence generator, but it's terribly inefficient. One simple method for improving its performance is using a technique called memoization. Write a function that takes a function_handle that we wish to memoize and returns a function_handle to a memoized version of the initial handle.\u003c/p\u003e","function_template":"function memfcn = memoize_this(fcn)\r\n    memfcn = fcn;\r\nend","test_suite":"%%\r\nmemfib = memoize_this(@fib);\r\n\r\n[seq, n1] = fib(1, memfib);\r\nassert(n1 == 1);\r\n\r\n[seq, n2] = fib(20, memfib);\r\nassert(n2 - n1 == 19);\r\n\r\n[seq, n3] = fib(100, memfib);\r\nassert(n3 - n2 == 81);\r\n\r\n\r\nfunction [seq, n] = fib(n, memfib)\r\n    persistent num\r\n    if isempty(num)\r\n        num = 1;\r\n    else\r\n        num = num + 1;\r\n    end\r\n    \r\n    if n \u003c 3\r\n        seq = ones(1, n);\r\n    else\r\n        seq = memfib(n-1, memfib);\r\n        seq = [seq, seq(end-1) + seq(end)];\r\n    end\r\n    \r\n    n = num;\r\nend","published":true,"deleted":false,"likes_count":5,"comments_count":6,"created_by":134,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":114,"test_suite_updated_at":"2017-10-17T21:30:35.000Z","rescore_all_solutions":true,"group_id":35,"created_at":"2017-10-12T20:12:52.000Z","updated_at":"2026-04-18T11:45:33.000Z","published_at":"2017-10-16T01:51:02.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe test suite includes a simple recursive Fibonacci sequence generator, but it's terribly inefficient. One simple method for improving its performance is using a technique called memoization. Write a function that takes a function_handle that we wish to memoize and returns a function_handle to a memoized version of the initial handle.\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":281,"title":"Acid and water","description":"\u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878;\r\n\r\nAssume that there is a 100 liter tank. \r\n\r\nIt is initially filled with just distilled water. \r\n\r\nIt is continuously drained at R liters per minute. \r\n\r\nThis tank is always maintained full and homogeneous by continuously adding and stirring R liters per minute of an unknown acid (or some fancy oil if it helps you solving this problem). \r\n\r\nHow many liters W of water will be in the tank after M minutes?\r\n\r\nNeglect any expansion or contraction when the acid is mixed with water. ","description_html":"\u003cp\u003e\u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878;\u003c/p\u003e\u003cp\u003eAssume that there is a 100 liter tank.\u003c/p\u003e\u003cp\u003eIt is initially filled with just distilled water.\u003c/p\u003e\u003cp\u003eIt is continuously drained at R liters per minute.\u003c/p\u003e\u003cp\u003eThis tank is always maintained full and homogeneous by continuously adding and stirring R liters per minute of an unknown acid (or some fancy oil if it helps you solving this problem).\u003c/p\u003e\u003cp\u003eHow many liters W of water will be in the tank after M minutes?\u003c/p\u003e\u003cp\u003eNeglect any expansion or contraction when the acid is mixed with water.\u003c/p\u003e","function_template":"function W = tank(R,M)\r\n  W = 100 * R * M;\r\nend","test_suite":"%%\r\nR=1; \r\nM=1;\r\nW=99;\r\nassert(tank(R,M)\u003eW)\r\n%%\r\nR=2; \r\nM=2;\r\nW=96;\r\nassert(tank(R,M)\u003eW)\r\n%%\r\nR=10; \r\nM=10;\r\nW=36;\r\nassert(tank(R,M)\u003eW)\r\n%%\r\nR=15; \r\nM=20;\r\nW=5;\r\nassert(tank(R,M)\u003cW)\r\n%%\r\nR=7; \r\nM=8;\r\nW=58;\r\nassert(tank(R,M)\u003cW)\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":13,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":284,"test_suite_updated_at":"2012-02-07T16:08:37.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2012-02-07T16:08:37.000Z","updated_at":"2026-04-18T10:50:56.000Z","published_at":"2017-10-16T01:50:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003e\u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssume that there is a 100 liter tank.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIt is initially filled with just distilled water.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIt is continuously drained at R liters per minute.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 tank is always maintained full and homogeneous by continuously adding and stirring R liters per minute of an unknown acid (or some fancy oil if it helps you solving this problem).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHow many liters W of water will be in the tank after M minutes?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNeglect any expansion or contraction when the acid is mixed with water.\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":44344,"title":"The 5th Root","description":"Write a function to find the 5th root of a number.\r\n\r\nIt sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method to solve the problem.","description_html":"\u003cp\u003eWrite a function to find the 5th root of a number.\u003c/p\u003e\u003cp\u003eIt sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method to solve the problem.\u003c/p\u003e","function_template":"function f = fifth_root(n)\r\n f = n^(1/5)\r\nend","test_suite":"%%\r\nfiletext = fileread('fifth_root.m');\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'power')),'power() forbidden')\r\nassert(isempty(strfind(filetext, 'mpower')),'mpower() forbidden')\r\nassert(isempty(strfind(filetext, 'realpow')),'realpow() forbidden')\r\nassert(isempty(strfind(filetext, 'nthroot')),'nthroot() forbidden')\r\nassert(isempty(strfind(filetext, 'roots')),'roots() forbidden')\r\n\r\n%%\r\nn = 1/9765625;\r\nassert(abs(fifth_root(n)-1/25)\u003c1e-5)\r\n\r\n%%\r\nn = 1/5555;\r\nassert(abs(fifth_root(n)-0.178263811215444)\u003c1e-5)\r\n\r\n%%\r\nn = 1/3125;\r\nassert(abs(fifth_root(n)-1/5)\u003c1e-5)\r\n\r\n%%\r\nn = 1/125;\r\nassert(abs(fifth_root(n)-0.380730787743176)\u003c1e-5)\r\n\r\n%%\r\nn = 1/5;\r\nassert(abs(fifth_root(n)-0.724779663677696)\u003c1e-5)\r\n\r\n%%\r\nn = 1;\r\nassert(abs(fifth_root(n)-1)\u003c1e-5)\r\n\r\n%%\r\nn = 5;\r\nassert(abs(fifth_root(n)-1.37972966146121)\u003c1e-5)\r\n\r\n%%\r\nn = 25;\r\nassert(abs(fifth_root(n)-1.90365393871588)\u003c1e-5)\r\n\r\n%%\r\nn = 50;\r\nassert(abs(fifth_root(n)-2.18672414788656)\u003c1e-5)\r\n\r\n%%\r\nn = 500;\r\nassert(abs(fifth_root(n)-3.46572421577573)\u003c1e-5)\r\n\r\n%%\r\nn = 3125;\r\nassert(abs(fifth_root(n)-5)\u003c1e-5)\r\n\r\n%%\r\nn = 759375;\r\nassert(abs(fifth_root(n)-15)\u003c1e-5)\r\n\r\n%%\r\nn = 9765625;\r\nassert(abs(fifth_root(n)-25)\u003c1e-5)\r\n\r\n%%\r\nn = 312500000;\r\nassert(abs(fifth_root(n)-50)\u003c1e-5)\r\n\r\n%%\r\nn = 75937500000;\r\nassert(abs(fifth_root(n)-150)\u003c1e-5)\r\n\r\n%%\r\nn = 31250000000000;\r\nassert(abs(fifth_root(n)-500)\u003c1e-5)\r\n\r\n%%\r\nn = 52658067346875;\r\nassert(abs(fifth_root(n)-555)\u003c1e-5)","published":true,"deleted":false,"likes_count":13,"comments_count":3,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":566,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-22T16:03:40.000Z","updated_at":"2026-04-18T14:10:29.000Z","published_at":"2017-10-16T01:50:59.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eWrite a function to find the 5th root of a number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method 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":44367,"title":"Inscribed Pentagon? 2","description":"Your function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon may or may not be centered on the circle. The function should return one of the following values:\r\n\r\n -1: the pentagon is not centered on the circle (within 5% of r)^\r\n  0: the pentagon is completely enclosed within the circle but is not inscribed\r\n  1: the pentagon is inscribed in the circle (within ±0.02)\r\n  2: the vertices of the pentagon extend beyond the circle\r\n\r\nPoints will be rounded to the nearest hundredth. See the test cases for examples. (There will not be a case where some vertices are within the circle and others without.)\r\n\r\n^ Due to the asymmetric nature of the pentagon, its centroid does not coincide with center of its inscribing circle, hence the ±5% tolerance window. ","description_html":"\u003cp\u003eYour function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon may or may not be centered on the circle. The function should return one of the following values:\u003c/p\u003e\u003cpre\u003e -1: the pentagon is not centered on the circle (within 5% of r)^\r\n  0: the pentagon is completely enclosed within the circle but is not inscribed\r\n  1: the pentagon is inscribed in the circle (within ±0.02)\r\n  2: the vertices of the pentagon extend beyond the circle\u003c/pre\u003e\u003cp\u003ePoints will be rounded to the nearest hundredth. See the test cases for examples. (There will not be a case where some vertices are within the circle and others without.)\u003c/p\u003e\u003cp\u003e^ Due to the asymmetric nature of the pentagon, its centroid does not coincide with center of its inscribing circle, hence the ±5% tolerance window.\u003c/p\u003e","function_template":"function y = inscribed_pentagon2(p,cp,r)\r\n y = -1;\r\nend","test_suite":"%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,6.58; 6.42,1.92; 3.97,-5.63; -3.97,-5.63; -6.42,1.92];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,4.55; 4.28,1.44; 2.65,-3.59; -2.65,-3.59; -4.28,1.44];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0.5];\r\nr = 8.75;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [1.98,-0.47];\r\nr = 8.75;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,6.58; 6.42,1.92; 3.97,-5.63; -3.97,-5.63; -6.42,1.92] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,4.55; 4.28,1.44; 2.65,-3.59; -2.65,-3.59; -4.28,1.44] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp_temp = [20,8];\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55] + repmat(cp_temp,[5,1]);\r\ncp = [19.5,9.08];\r\nr = 2.5;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp_temp = [20,8];\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55] + repmat(cp_temp,[5,1]);\r\ncp = [19.86,7.19];\r\nr = 7.5;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [25.01,12.47; 25.98,4.58; 18.78,1.23; 13.37,7.03; 17.22,13.97];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.27,11.12; 23.92,5.87; 19.12,3.63; 15.52,7.50; 18.08,12.13];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [32.54,38.78; 38.84,26.41; 29.02,16.59; 16.65,22.89; 18.83,36.61];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.49,35.54; 34.69,27.29; 28.14,20.74; 19.89,24.95; 21.34,34.09];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [26.41,29.04];\r\nr = 6.13;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [27.07,27.66];\r\nr = 9.63;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":97,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-10T15:28:54.000Z","updated_at":"2026-04-18T10:53:19.000Z","published_at":"2017-10-16T01:51: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\":[],\"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\u003eYour function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon may or may not be centered on the circle. The function should return one of the following values:\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: the pentagon is not centered on the circle (within 5% of r)^\\n  0: the pentagon is completely enclosed within the circle but is not inscribed\\n  1: the pentagon is inscribed in the circle (within ±0.02)\\n  2: the vertices of the pentagon extend beyond the circle]]\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\u003ePoints will be rounded to the nearest hundredth. See the test cases for examples. (There will not be a case where some vertices are within the circle and others without.)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e^ Due to the asymmetric nature of the pentagon, its centroid does not coincide with center of its inscribing circle, hence the ±5% tolerance window.\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":44359,"title":"5th Time's a Charm","description":"Write a function that will return the input value. However, your function must fail the first four times, only functioning properly every fifth time. Furthermore, the first four times the function is called, successively closer, but not correct, values must be supplied by the function.\r\n\r\nFor example, if x = 10, you may return any number not equal to 10 the first function call. Here, we will return 27. Then, the second function call must return a value between 27 and 10, but not equal to either, and so on, until 10 is returned the fifth time.","description_html":"\u003cp\u003eWrite a function that will return the input value. However, your function must fail the first four times, only functioning properly every fifth time. Furthermore, the first four times the function is called, successively closer, but not correct, values must be supplied by the function.\u003c/p\u003e\u003cp\u003eFor example, if x = 10, you may return any number not equal to 10 the first function call. Here, we will return 27. Then, the second function call must return a value between 27 and 10, but not equal to either, and so on, until 10 is returned the fifth time.\u003c/p\u003e","function_template":"function y = fifth_times_a_charm(x)\r\n y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny1 = fifth_times_a_charm(x);\r\nassert(~isequal(y1,x))\r\n\r\ny2 = fifth_times_a_charm(x);\r\nassert(~isequal(y2,x))\r\nassert(abs(x-y2)\u003cabs(x-y1))\r\n\r\ny3 = fifth_times_a_charm(x);\r\nassert(~isequal(y3,x))\r\nassert(abs(x-y3)\u003cabs(x-y2))\r\n\r\ny4 = fifth_times_a_charm(x);\r\nassert(~isequal(y4,x))\r\nassert(abs(x-y4)\u003cabs(x-y3))\r\n\r\ny5 = fifth_times_a_charm(x);\r\nassert(isequal(y5,x))\r\n\r\n%%\r\nx = -1;\r\ny1 = fifth_times_a_charm(x);\r\nassert(~isequal(y1,x))\r\n\r\ny2 = fifth_times_a_charm(x);\r\nassert(~isequal(y2,x))\r\nassert(abs(x-y2)\u003cabs(x-y1))\r\n\r\ny3 = fifth_times_a_charm(x);\r\nassert(~isequal(y3,x))\r\nassert(abs(x-y3)\u003cabs(x-y2))\r\n\r\ny4 = fifth_times_a_charm(x);\r\nassert(~isequal(y4,x))\r\nassert(abs(x-y4)\u003cabs(x-y3))\r\n\r\ny5 = fifth_times_a_charm(x);\r\nassert(isequal(y5,x))\r\n\r\n%%\r\nx = 42;\r\ny1 = fifth_times_a_charm(x);\r\nassert(~isequal(y1,x))\r\n\r\ny2 = fifth_times_a_charm(x);\r\nassert(~isequal(y2,x))\r\nassert(abs(x-y2)\u003cabs(x-y1))\r\n\r\ny3 = fifth_times_a_charm(x);\r\nassert(~isequal(y3,x))\r\nassert(abs(x-y3)\u003cabs(x-y2))\r\n\r\ny4 = fifth_times_a_charm(x);\r\nassert(~isequal(y4,x))\r\nassert(abs(x-y4)\u003cabs(x-y3))\r\n\r\ny5 = fifth_times_a_charm(x);\r\nassert(isequal(y5,x))\r\n\r\n%%\r\nx = i;\r\ny1 = fifth_times_a_charm(x);\r\nassert(~isequal(y1,x))\r\n\r\ny2 = fifth_times_a_charm(x);\r\nassert(~isequal(y2,x))\r\nassert(abs(x-y2)\u003cabs(x-y1))\r\n\r\ny3 = fifth_times_a_charm(x);\r\nassert(~isequal(y3,x))\r\nassert(abs(x-y3)\u003cabs(x-y2))\r\n\r\ny4 = fifth_times_a_charm(x);\r\nassert(~isequal(y4,x))\r\nassert(abs(x-y4)\u003cabs(x-y3))\r\n\r\ny5 = fifth_times_a_charm(x);\r\nassert(isequal(y5,x))","published":true,"deleted":false,"likes_count":7,"comments_count":5,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":206,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-03T17:35:55.000Z","updated_at":"2026-04-18T10:56:18.000Z","published_at":"2017-10-16T01:51: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\",\"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\u003eWrite a function that will return the input value. However, your function must fail the first four times, only functioning properly every fifth time. Furthermore, the first four times the function is called, successively closer, but not correct, values must be supplied by the function.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, if x = 10, you may return any number not equal to 10 the first function call. Here, we will return 27. Then, the second function call must return a value between 27 and 10, but not equal to either, and so on, until 10 is returned the fifth time.\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":44337,"title":"Sums of Distinct Powers","description":"You will be given three numbers: base, nstart, and nend.  Write a MATLAB script that will compute the sum of a sequence of both the distinct powers of base as well as sums of distinct powers of base.  Your sequence should start with the 'nstart'th term and end with the 'nend'th term.  For example:\r\n\r\n* base=4\r\n* nstart=2\r\n* nend=6\r\n\r\nThe first several sums of the distinct powers of 4 are:\r\n\r\n* 1 (4^0)\r\n* 4 (4^1)\r\n* 5 (4^1 + 4^0)\r\n* 16 (4^2)\r\n* 17 (4^2 + 4^0)\r\n* 20 (4^2 + 4^1)\r\n* 21 (4^2 + 4^1 + 4^0)\r\n* 64 (4^3)\r\n* 65 (4^3 + 4^0)\r\n\r\nSince nstart=2 and nend=6 in this example, you take the second through the sixth terms of this sequence.  The correct output would be 4+5+16+17+20, or 62.  Notice that the number 8 does not occur in this pattern.  While 8 is a multiple of 4, 8=4^1+4^1.  Because there are two 4^1 terms in the sum, 8 does not qualify as a sum of *distinct* powers of 4.  You can assume that all three will be integers, base\u003e1, and that nstart\u003cnend.  Good luck!","description_html":"\u003cp\u003eYou will be given three numbers: base, nstart, and nend.  Write a MATLAB script that will compute the sum of a sequence of both the distinct powers of base as well as sums of distinct powers of base.  Your sequence should start with the 'nstart'th term and end with the 'nend'th term.  For example:\u003c/p\u003e\u003cul\u003e\u003cli\u003ebase=4\u003c/li\u003e\u003cli\u003enstart=2\u003c/li\u003e\u003cli\u003enend=6\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe first several sums of the distinct powers of 4 are:\u003c/p\u003e\u003cul\u003e\u003cli\u003e1 (4^0)\u003c/li\u003e\u003cli\u003e4 (4^1)\u003c/li\u003e\u003cli\u003e5 (4^1 + 4^0)\u003c/li\u003e\u003cli\u003e16 (4^2)\u003c/li\u003e\u003cli\u003e17 (4^2 + 4^0)\u003c/li\u003e\u003cli\u003e20 (4^2 + 4^1)\u003c/li\u003e\u003cli\u003e21 (4^2 + 4^1 + 4^0)\u003c/li\u003e\u003cli\u003e64 (4^3)\u003c/li\u003e\u003cli\u003e65 (4^3 + 4^0)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eSince nstart=2 and nend=6 in this example, you take the second through the sixth terms of this sequence.  The correct output would be 4+5+16+17+20, or 62.  Notice that the number 8 does not occur in this pattern.  While 8 is a multiple of 4, 8=4^1+4^1.  Because there are two 4^1 terms in the sum, 8 does not qualify as a sum of \u003cb\u003edistinct\u003c/b\u003e powers of 4.  You can assume that all three will be integers, base\u0026gt;1, and that nstart\u0026lt;nend.  Good luck!\u003c/p\u003e","function_template":"function y = sum_distinct_powers(base,nstart,nend)\r\n  y = base*nstart*nend;\r\nend","test_suite":"%%\r\nbase=4;nstart=2;nend=6;y_correct=62;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=5;nstart=1;nend=1000;y_correct=1193853250;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=3;nstart=1;nend=1000;y_correct=14438162;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=3;nstart=100;nend=1000;y_correct=14397354;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=2;nstart=1;nend=2017;y_correct=2035153;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=7;nstart=1234;nend=2345;y_correct=843569026324;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=7;nstart=1;nend=10;y_correct=1265;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nnstart=1;nend=50;\r\njunk=arrayfun(@(base) sum_distinct_powers(base,nstart,nend),2:10);\r\ny_correct=[1275 7120 26365 75000 178591 374560 714465 1266280 2116675];\r\nassert(isequal(junk,y_correct))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":9,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":170,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-18T16:30:15.000Z","updated_at":"2026-04-18T10:51:36.000Z","published_at":"2017-10-16T01:50:59.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou will be given three numbers: base, nstart, and nend. Write a MATLAB script that will compute the sum of a sequence of both the distinct powers of base as well as sums of distinct powers of base. Your sequence should start with the 'nstart'th term and end with the 'nend'th term. For example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ebase=4\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003enstart=2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003enend=6\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe first several sums of the distinct powers of 4 are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1 (4^0)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4 (4^1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e5 (4^1 + 4^0)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e16 (4^2)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e17 (4^2 + 4^0)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e20 (4^2 + 4^1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e21 (4^2 + 4^1 + 4^0)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e64 (4^3)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e65 (4^3 + 4^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\u003eSince nstart=2 and nend=6 in this example, you take the second through the sixth terms of this sequence. The correct output would be 4+5+16+17+20, or 62. Notice that the number 8 does not occur in this pattern. While 8 is a multiple of 4, 8=4^1+4^1. Because there are two 4^1 terms in the sum, 8 does not qualify as a sum of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003edistinct\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e powers of 4. You can assume that all three will be integers, base\u0026gt;1, and that nstart\u0026lt;nend. Good luck!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44340,"title":"Recaman Sequence - III","description":"I want to create a Recaman sequence where there is a \"1\" in the n-th position. So from which integer should I start the Recaman sequence? If there are more than one starting integer that generates a sequence with a 1 in the n-th position, return the lowest one.\r\nFor example if I want to place the digit 1 in the 7th place in the sequence then I should start the sequence from six as follow;\r\nseq = [6 5 3 6 2 7 1 8 16]\r\nYou can also start the sequence with 12 and obtain a series where there is a 1 in 7th position;\r\nseq = [12 11 9 6 2 7 1]\r\nRelated Challenges :\r\nRecaman Sequence - I\r\nRecaman Sequence - II\r\nRecaman Sequence - III","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: 308.167px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 154.083px; transform-origin: 407px 154.083px; 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: 371.5px 8px; transform-origin: 371.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eI want to create a Recaman sequence where there is a \"1\" in the n-th position. So from which integer should I start the Recaman sequence? If there are more than one starting integer that generates a sequence with a 1 in the n-th position, return the lowest one.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 368.5px 8px; transform-origin: 368.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example if I want to place the digit 1 in the 7th place in the sequence then I should start the sequence from six as follow;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 104px 8.5px; tab-size: 4; transform-origin: 104px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eseq = [6 5 3 6 2 7 1 8 16]\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: 294.5px 8px; transform-origin: 294.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou can also start the sequence with 12 and obtain a series where there is a 1 in 7th position;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 92px 8.5px; tab-size: 4; transform-origin: 92px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eseq = [12 11 9 6 2 7 1]\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: 72.5px 8px; transform-origin: 72.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eRelated Challenges :\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 61.3px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: decimal; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 30.65px; transform-origin: 391px 30.65px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/44338\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eRecaman Sequence - I\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/44339\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eRecaman Sequence - II\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 75px 8px; transform-origin: 75px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eRecaman Sequence - III\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function startPoint = RecamanIII(onesplace)\r\n\r\nend","test_suite":"%%\r\nfiletext = fileread('RecamanIII.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'str2num'); \r\nassert(~illegal)\r\n\r\n%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 2;\r\ny_correct = 0;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 3;\r\ny_correct = 4;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 9;\r\ny_correct = 13;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 13;\r\ny_correct = 15;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 15;\r\ny_correct = 26;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 26;\r\ny_correct = 54;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 54;\r\ny_correct = 208;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 208;\r\ny_correct = 2485;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":12,"created_by":8703,"edited_by":223089,"edited_at":"2022-10-11T07:22:46.000Z","deleted_by":null,"deleted_at":null,"solvers_count":103,"test_suite_updated_at":"2022-10-11T07:22:46.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-19T07:36:19.000Z","updated_at":"2026-04-23T02:19:14.000Z","published_at":"2017-10-16T01:50:59.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\u003eI want to create a Recaman sequence where there is a \\\"1\\\" in the n-th position. So from which integer should I start the Recaman sequence? If there are more than one starting integer that generates a sequence with a 1 in the n-th position, return the lowest 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\u003eFor example if I want to place the digit 1 in the 7th place in the sequence then I should start the sequence from six as follow;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[seq = [6 5 3 6 2 7 1 8 16]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou can also start the sequence with 12 and obtain a series where there is a 1 in 7th position;\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[seq = [12 11 9 6 2 7 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\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\u003eRelated Challenges :\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44338\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - I\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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44339\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - II\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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - III\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":44353,"title":"Group-wise Euclidean distance","description":"*Input*:\r\n \r\n* *x* —— An array of size *n-by-d*, where each row vector denotes a point in a d-dimensional space;\r\n* *g* —— A grouping (index) vector g of size *n-by-1*, which divides the points in x into groups. Specifically, the rows in x corresponding to the same group index in g belong to the same group. \r\n\r\n*Output*: \r\n\r\n* *y* —— The group-wise Euclidean distance matrix associated with the points in x. Suppose that m = max(g), then y will be an *m-by-m* matrix, where each element y(i,j) is the Euclidean distance between group i and group j, which is defined as the minimum of the Euclidean distances between any points in group i and any other points in group j. \r\n\r\n*Example*:\r\n\r\nExample 1: n = 6, d = 1\r\n\r\n  g = [2   1   3  2  1].';\r\n  x = [3  10  15  8  5].';\r\n  y = [0   2   5            % y(1,2) = y(2,1) = min(10-3,5-3,10-8,8-5) = 2\r\n       2   0   7            % y(1,3) = y(3,1) = min(15-10,15-5) = 5\r\n       5   7   0];          % y(2,3) = y(3,2) = min(15-3,15-8) = 7\r\n\r\nExample 2: n = 3, d = 2\r\n\r\n  g = [1 2 2].';\r\n  x = [0   0\r\n       5  12\r\n       3   4];\r\n  y = [0  5;\r\n       5  0];    % y(1,2) = y(2,1) = min(sqrt(5^2+12^2),sqrt(3^2+4^2)) = 5\r\n  \r\n*Testing*:\r\n\r\nThe test suite will focus mainly on the large-scale problem dimensions (e.g., large n and/or d). The purpose is to direct attention towards efficient runtime speed of execution. Note that your solution may run into a time-out error if it is not sufficiently efficient (which is why this problem falls into the \u003chttps://www.mathworks.com/matlabcentral/cody/groups/35 Cody5:Hard\u003e category).\r\n\r\n*Scoring*:\r\n\r\nWe have modified Cody's default size-based scoring function into a performance-based scoring system (implemented by our fellow Cody player \u003chttps://www.mathworks.com/matlabcentral/cody/players/3021298-ly-cao LY Cao\u003e), in which the score of your submission equals 5 times the execution time of your solution (which reprents a score resolution of 0.2 seconds and allows for more room for performance improvement). Please ignore the code size and focus only on improving the code performance, as our test suite will reject any submissions running longer than 20 seconds (in contrast to Cody's default 40 seconds timeout limit).  \r\n\r\nPlease be advised that an amazingly fast solution would earn a score \u003c 5, meaning that it completes execution of all test cases within a second!\r\n\r\n*Update* (11/21/2017):\r\nAdditional test cases are added to ban cheater solutions (e.g., hard-coded submissions 1351541, 1351007, 1350563, 1349442, all came from \u003chttps://www.mathworks.com/matlabcentral/cody/players/3931805-marco-tullio Marco Tullio\u003e).\r\n","description_html":"\u003cp\u003e\u003cb\u003eInput\u003c/b\u003e:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003cb\u003ex\u003c/b\u003e —— An array of size \u003cb\u003en-by-d\u003c/b\u003e, where each row vector denotes a point in a d-dimensional space;\u003c/li\u003e\u003cli\u003e\u003cb\u003eg\u003c/b\u003e —— A grouping (index) vector g of size \u003cb\u003en-by-1\u003c/b\u003e, which divides the points in x into groups. Specifically, the rows in x corresponding to the same group index in g belong to the same group.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003e\u003cb\u003eOutput\u003c/b\u003e:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003cb\u003ey\u003c/b\u003e —— The group-wise Euclidean distance matrix associated with the points in x. Suppose that m = max(g), then y will be an \u003cb\u003em-by-m\u003c/b\u003e matrix, where each element y(i,j) is the Euclidean distance between group i and group j, which is defined as the minimum of the Euclidean distances between any points in group i and any other points in group j.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003e\u003cb\u003eExample\u003c/b\u003e:\u003c/p\u003e\u003cp\u003eExample 1: n = 6, d = 1\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eg = [2   1   3  2  1].';\r\nx = [3  10  15  8  5].';\r\ny = [0   2   5            % y(1,2) = y(2,1) = min(10-3,5-3,10-8,8-5) = 2\r\n     2   0   7            % y(1,3) = y(3,1) = min(15-10,15-5) = 5\r\n     5   7   0];          % y(2,3) = y(3,2) = min(15-3,15-8) = 7\r\n\u003c/pre\u003e\u003cp\u003eExample 2: n = 3, d = 2\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eg = [1 2 2].';\r\nx = [0   0\r\n     5  12\r\n     3   4];\r\ny = [0  5;\r\n     5  0];    % y(1,2) = y(2,1) = min(sqrt(5^2+12^2),sqrt(3^2+4^2)) = 5\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eTesting\u003c/b\u003e:\u003c/p\u003e\u003cp\u003eThe test suite will focus mainly on the large-scale problem dimensions (e.g., large n and/or d). The purpose is to direct attention towards efficient runtime speed of execution. Note that your solution may run into a time-out error if it is not sufficiently efficient (which is why this problem falls into the \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/groups/35\"\u003eCody5:Hard\u003c/a\u003e category).\u003c/p\u003e\u003cp\u003e\u003cb\u003eScoring\u003c/b\u003e:\u003c/p\u003e\u003cp\u003eWe have modified Cody's default size-based scoring function into a performance-based scoring system (implemented by our fellow Cody player \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/players/3021298-ly-cao\"\u003eLY Cao\u003c/a\u003e), in which the score of your submission equals 5 times the execution time of your solution (which reprents a score resolution of 0.2 seconds and allows for more room for performance improvement). Please ignore the code size and focus only on improving the code performance, as our test suite will reject any submissions running longer than 20 seconds (in contrast to Cody's default 40 seconds timeout limit).\u003c/p\u003e\u003cp\u003ePlease be advised that an amazingly fast solution would earn a score \u0026lt; 5, meaning that it completes execution of all test cases within a second!\u003c/p\u003e\u003cp\u003e\u003cb\u003eUpdate\u003c/b\u003e (11/21/2017):\r\nAdditional test cases are added to ban cheater solutions (e.g., hard-coded submissions 1351541, 1351007, 1350563, 1349442, all came from \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/players/3931805-marco-tullio\"\u003eMarco Tullio\u003c/a\u003e).\u003c/p\u003e","function_template":"function y = groupDist(x,g)\r\n  y = x;\r\nend","test_suite":"%%\r\nassessFunctionAbsence({'regexp','regexpi','regexprep','str2num','tic','toc','persistent','global','rng','assert','!','system','unix','noCheater'},'FileName','groupDist.m')\r\n\r\n%%\r\nfid = fopen('noCheater.p','Wb');\r\nfwrite(fid, hex2dec(reshape([\r\n    '7630312E30307630302E30300007701CAB777FB100000015000000740000007E3D5C20F'...'\r\n    '5319EEB8B0D3D9C9C87C18B91C13D7310D9D8E837C95E62D49A3FE08B071790DBC222B5'...\r\n    '839E9A19EA6AA7CF3785A7E7CEC1CFE46E0E9A5DB7C82D69A4FAB7BF308D0871C342A5F'...\r\n    'EF9AF61623F1D97F80207388D54ABA3CB3D551617DA33AA3F5040CD425FC9B29E2A4233'...\r\n    'AE7C5ADEF399'],2,[]).')); rehash path; \r\nfclose(fid); \r\nassert(noCheater(),'Cheater detected!')\r\n\r\n%%\r\ng = [2   1   3  2  1].';\r\nx = [3  10  15  8  5].';\r\ny_correct = [0   2   5            \r\n             2   0   7      \r\n             5   7   0]; \r\nassert(isequaln(y_correct,groupDist(x,g)))\r\n\r\n%%\r\ng = [1 2 2].';\r\nx = [0   0\r\n     5  12\r\n     3   4];\r\ny_correct = [0  5;\r\n             5  0];    \r\nassert(isequal(y_correct,groupDist(x,g)))\r\n\r\n%%\r\ng = [2 2 3 3 3 1].';\r\nx = [-5   12\r\n      3    4\r\n     -7  -24\r\n     25    4\r\n      9   40\r\n      0    0];\r\ny_correct = [0    5   25;\r\n             5    0   22\r\n             25  22    0];  \r\nassert(isequal(y_correct,groupDist(x,g)))\r\n\r\n%% Randomized case to disallow hard-coded solution\r\ng = randperm(10).';\r\nx = rand(10,1);\r\na = sortrows([g,x]);\r\ny_correct = abs(a(:,2)-a(:,2).');\r\nassert(isequal(round(y_correct,10),round(groupDist(x,g),10))) \r\n\r\n%% Additional test case to disallow hard-coded solution\r\ng = [1,2,3].';\r\nx = [2,5,10].';\r\ny_correct = [0   3   8            \r\n             3   0   5      \r\n             8   5   0]; \r\nassert(isequaln(y_correct,groupDist(x,g)))\r\n\r\n%%\r\nglobal t\r\nt = zeros(1,3); \r\nrng(923,'twister');\r\nn = 5e3; d = 3; m = 5;\r\nx = rand(n,d);\r\ng = randi(m,n,1); \r\ny_correct = [0,0.00653919638188362,0.00319052186150122,0.00858841434457234,0.00359654235965771\r\n             0.00653919638188362,0,0.00855286615862212,0.00589790293838067,0.00484910151004134\r\n             0.00319052186150122,0.00855286615862212,0,0.00591041083080696,0.00483607360689871\r\n             0.00858841434457234,0.00589790293838067,0.00591041083080696,0,0.00695738487959094\r\n             0.00359654235965771,0.00484910151004134,0.00483607360689871,0.00695738487959094,0];\r\ntic, y = groupDist(x,g); t(1) = toc;\r\nassert(isequal(round(y_correct,10),round(y,10))) \r\n\r\n%%\r\nglobal t\r\nrng(123) \r\nrng(max('cody5'),'combRecursive');\r\nn = 5e3; d = 3; m = 100;\r\nx = 10*rand(n,d);\r\ng = randi(m,n,1); \r\ntic, y = groupDist(x,g); t(2) = toc;\r\nassert(norm(y-y.') \u003c 1e-11 \u0026\u0026 all(~diag(y)) \u0026\u0026 all(size(y)==m) \u0026\u0026 abs(det(y)-0.030846735888559)\u003c1e-8 \u0026\u0026...\r\n    abs(cond(y)-1.606720826682107e+04) \u003c 1e-6 \u0026\u0026 abs(max(nonzeros(y))-1.058563379304832)\u003c1e-10 \u0026\u0026...\r\n    abs(mean(nonzeros(y))-0.419901913602729)\u003c1e-8)\r\n\r\n%%\r\nglobal t \r\nrng(sum('Cody5, Oct. 16, 2017'),'multFibonacci') \r\nn = 5e3; d = 1e2;  m = 100;\r\nx = 5*randn(n,d) + 20;\r\ng = randi(m,n,1); \r\ntic, y = groupDist(x,g); t(3) = toc;\r\nassert(norm(y-y.') \u003c 1e-11 \u0026\u0026 all(~diag(y)) \u0026\u0026 all(size(y)==m) \u0026\u0026 ...\r\n    abs(cond(y)-2.024633860688276e+02) \u003c 1e-8 \u0026\u0026 abs(max(nonzeros(y))-57.768463869822135)\u003c1e-10 \u0026\u0026...\r\n    abs(mean(nonzeros(y))-53.852605466762945)\u003c1e-8) \r\n \r\n%%\r\nglobal t\r\nfid = fopen('score.p','Wb');\r\nfwrite(fid,uint8(sscanf([...\r\n     '7630312E30307630302E3030000B901C454EFFB100000031000001330000018D483A60'...\r\n     '366BC9545F84AE26323B67424D4E8A7A2E5B7D8ACAA45A1C3C5C8B33E245C95243E3CB'...\r\n     'AF5D0D993BDA70B7AB5DA365A83E8CA87FFC45265E23EF80943784C5F48E6E53D5DA34'...\r\n     'F1F2ECD34683EABE3B7461DC9E8004CC50B2A79D73495F6F625B5365602B2E6C6093D2'...\r\n     '997D371DA457CE82327E686AF512A507B2CB62A375BFD1B283DDD2C01EDEF2771EDAA3'...\r\n     '6ABB4852BA4061E20149688E812EB41A9AF8627EF35755492D2830EB8718BCFE88027E'...\r\n     '6EA960B63A3B3E26E0451B1DCF14F3C20E70D9D93B08E7FF4AE8D82E7CC38042FD38F7'...\r\n     'A14D312EF5652823FEB7E8B52AF5C69F5E7D16B116B5F979EDA77459D6BB61B7971A51'...\r\n     '041227DD601319D667DF62E8DA5E381FDD07A2806FE835BD2569E5315CDFC19C6B6A2B'...\r\n     '4F0FF6BA803F1759ACAB133CCFAB6D5A5D002FC2C5F381F0'],'%2X')));\r\nfclose(fid);\r\nscore(round(5*sum(t)))\r\nfprintf('The execution time of test case %d is %.5f seconds \\n',[5:7;t])\r\nfprintf('The total execution time is %.5f seconds \\n',sum(t))\r\nassert(sum(t)\u003c20, 'Sorry, your solution is too slow. The execution time must not exceed 20 seconds.')\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":4,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":85,"test_suite_updated_at":"2017-11-21T22:49:00.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-01T04:33:43.000Z","updated_at":"2026-04-18T14:03:45.000Z","published_at":"2017-10-16T01:51: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\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e —— An array of size\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en-by-d\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, where each row vector denotes a point in a d-dimensional space;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eg\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e —— A grouping (index) vector g of size\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en-by-1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, which divides the points in x into groups. Specifically, the rows in x corresponding to the same group index in g belong to the same group.\u003c/w:t\u003e\u003c/w:r\u003e\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:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e —— The group-wise Euclidean distance matrix associated with the points in x. Suppose that m = max(g), then y will be an\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003em-by-m\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix, where each element y(i,j) is the Euclidean distance between group i and group j, which is defined as the minimum of the Euclidean distances between any points in group i and any other points in group j.\u003c/w:t\u003e\u003c/w:r\u003e\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\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\u003eExample 1: n = 6, d = 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[g = [2   1   3  2  1].';\\nx = [3  10  15  8  5].';\\ny = [0   2   5            % y(1,2) = y(2,1) = min(10-3,5-3,10-8,8-5) = 2\\n     2   0   7            % y(1,3) = y(3,1) = min(15-10,15-5) = 5\\n     5   7   0];          % y(2,3) = y(3,2) = min(15-3,15-8) = 7]]\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\u003eExample 2: n = 3, d = 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[g = [1 2 2].';\\nx = [0   0\\n     5  12\\n     3   4];\\ny = [0  5;\\n     5  0];    % y(1,2) = y(2,1) = min(sqrt(5^2+12^2),sqrt(3^2+4^2)) = 5]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTesting\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe test suite will focus mainly on the large-scale problem dimensions (e.g., large n and/or d). The purpose is to direct attention towards efficient runtime speed of execution. Note that your solution may run into a time-out error if it is not sufficiently efficient (which is why this problem falls into 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=\\\"https://www.mathworks.com/matlabcentral/cody/groups/35\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody5:Hard\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e category).\u003c/w:t\u003e\u003c/w:r\u003e\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:\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eWe have modified Cody's default size-based scoring function into a performance-based scoring system (implemented by our fellow Cody player\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/players/3021298-ly-cao\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eLY Cao\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e), in which the score of your submission equals 5 times the execution time of your solution (which reprents a score resolution of 0.2 seconds and allows for more room for performance improvement). Please ignore the code size and focus only on improving the code performance, as our test suite will reject any submissions running longer than 20 seconds (in contrast to Cody's default 40 seconds timeout limit).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePlease be advised that an amazingly fast solution would earn a score \u0026lt; 5, meaning that it completes execution of all test cases within a second!\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eUpdate\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (11/21/2017): Additional test cases are added to ban cheater solutions (e.g., hard-coded submissions 1351541, 1351007, 1350563, 1349442, all came from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/players/3931805-marco-tullio\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eMarco Tullio\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44310,"title":"Digit concentration in Champernowne's constant","description":"Consider the first 50 digits of Champernowne's constant\r\n \r\n    0.12345678910111213141516171819202122232425262728293...\r\n  \r\nThere are two zeros (do not count the left side of \".\" (integer part) ) in this series. So the digit concentration for 0 for the first 50 digits is = 2 / 50 = 0.04.\r\n\r\nAlso the number of '2' (x) digit is counted as 13. So the digit concentration of number '2' for the first 50 (d) digit is = 13/50 = 0.26\r\n\r\nCalculate the digit concentration of number x for the first d digit of constant.\r\n","description_html":"\u003cp\u003eConsider the first 50 digits of Champernowne's constant\u003c/p\u003e\u003cpre\u003e    0.12345678910111213141516171819202122232425262728293...\u003c/pre\u003e\u003cp\u003eThere are two zeros (do not count the left side of \".\" (integer part) ) in this series. So the digit concentration for 0 for the first 50 digits is = 2 / 50 = 0.04.\u003c/p\u003e\u003cp\u003eAlso the number of '2' (x) digit is counted as 13. So the digit concentration of number '2' for the first 50 (d) digit is = 13/50 = 0.26\u003c/p\u003e\u003cp\u003eCalculate the digit concentration of number x for the first d digit of constant.\u003c/p\u003e","function_template":"function concentration = digitCon(d,x)\r\n  y = x;\r\nend","test_suite":"%%\r\nd = 1;\r\nx = 1;\r\ny_correct = 1;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 10;\r\nx = 5;\r\ny_correct = 0.1000;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 10;\r\nx = 1;\r\ny_correct = 0.2000;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 20;\r\nx = 9;\r\ny_correct = 0.0500;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n\r\n%%\r\nd = 50;\r\nx = 0;\r\ny_correct = 0.0400;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 50;\r\nx = 2;\r\ny_correct = 0.2600;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1000;\r\nx = 9;\r\ny_correct = 0.0670;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1e4;\r\nx = 8;\r\ny_correct = 0.0747;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1e5;\r\nx = 7;\r\ny_correct = 0.0864;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1e6;\r\nx = 6;\r\ny_correct = 0.0935;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1e6;\r\nx = 5;\r\ny_correct = 0.0937;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 2e6;\r\nx = 4;\r\ny_correct = 0.0903;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 2000124;\r\nx = 3;\r\ny_correct = 0.1162;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)","published":true,"deleted":false,"likes_count":5,"comments_count":1,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":143,"test_suite_updated_at":"2017-10-25T07:12:47.000Z","rescore_all_solutions":true,"group_id":35,"created_at":"2017-09-11T10:35:46.000Z","updated_at":"2026-04-18T10:53:53.000Z","published_at":"2017-10-16T01:50:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eConsider the first 50 digits of Champernowne's constant\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.12345678910111213141516171819202122232425262728293...]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are two zeros (do not count the left side of \\\".\\\" (integer part) ) in this series. So the digit concentration for 0 for the first 50 digits is = 2 / 50 = 0.04.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eAlso the number of '2' (x) digit is counted as 13. So the digit concentration of number '2' for the first 50 (d) digit is = 13/50 = 0.26\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCalculate the digit concentration of number x for the first d digit of constant.\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":44341,"title":"Hexagonal numbers on a spiral matrix","description":"Put hexagonal numbers in a ( m x m ) spiral matrix and return the sum of its diagonal elements.\r\n\r\nFormula of hexagonal numbers h(n) = 2n^2 - n\r\n\r\nIf m = 5;\r\n\r\n  spiral(5) =   \r\n    21    22    23    24    25\r\n    20     7     8     9    10\r\n    19     6     1     2    11\r\n    18     5     4     3    12\r\n    17    16    15    14    13\r\n\r\nFirst 5x5=25 hexagonal numbers are;\r\n\r\n  h = [1 6 15 28 45 66 91 120 153 190 231 276 325 378 435 496 561 630 703 780 861 946 1035 1128 1225]\r\n\r\nWe put them in a spiral format;\r\n\r\n   spiralHex = [\r\n861\t946\t1035\t1128\t1225\r\n780\t91\t120\t153\t190\r\n703\t66\t1\t6\t231\r\n630\t45\t28\t15\t276\r\n561\t496\t435\t378\t325\r\n\r\nAnd sum its diag = 861 + 91 + 1 + 15 + 325 = 1293.\r\n\r\nReturn the output as char.","description_html":"\u003cp\u003ePut hexagonal numbers in a ( m x m ) spiral matrix and return the sum of its diagonal elements.\u003c/p\u003e\u003cp\u003eFormula of hexagonal numbers h(n) = 2n^2 - n\u003c/p\u003e\u003cp\u003eIf m = 5;\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003espiral(5) =   \r\n  21    22    23    24    25\r\n  20     7     8     9    10\r\n  19     6     1     2    11\r\n  18     5     4     3    12\r\n  17    16    15    14    13\r\n\u003c/pre\u003e\u003cp\u003eFirst 5x5=25 hexagonal numbers are;\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eh = [1 6 15 28 45 66 91 120 153 190 231 276 325 378 435 496 561 630 703 780 861 946 1035 1128 1225]\r\n\u003c/pre\u003e\u003cp\u003eWe put them in a spiral format;\u003c/p\u003e\u003cpre\u003e   spiralHex = [\r\n861\t946\t1035\t1128\t1225\r\n780\t91\t120\t153\t190\r\n703\t66\t1\t6\t231\r\n630\t45\t28\t15\t276\r\n561\t496\t435\t378\t325\u003c/pre\u003e\u003cp\u003eAnd sum its diag = 861 + 91 + 1 + 15 + 325 = 1293.\u003c/p\u003e\u003cp\u003eReturn the output as char.\u003c/p\u003e","function_template":"function y = hexagonalSpiral(m)\r\n  \r\nend","test_suite":"%%\r\nm = 1;\r\ny_correct = '1';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 2;\r\ny_correct = '16';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 5;\r\ny_correct = '1293';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 16;\r\ny_correct = '420800';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 100;\r\ny_correct = '4000333360';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 1295;\r\ny_correct = '1456830580539887';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 2500;\r\ny_correct = '39062505208334000';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 5000;\r\ny_correct = '1250000041666668000';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 8000;\r\ny_correct = '13107200170666668800';\r\nassert(isequal(hexagonalSpiral(m),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":164,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-19T08:06:36.000Z","updated_at":"2026-04-18T10:55:17.000Z","published_at":"2017-10-16T01:50:59.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePut hexagonal numbers in a ( m x m ) spiral matrix and return the sum of its diagonal elements.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eFormula of hexagonal numbers h(n) = 2n^2 - n\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf m = 5;\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[spiral(5) =   \\n  21    22    23    24    25\\n  20     7     8     9    10\\n  19     6     1     2    11\\n  18     5     4     3    12\\n  17    16    15    14    13]]\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\u003eFirst 5x5=25 hexagonal numbers are;\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[h = [1 6 15 28 45 66 91 120 153 190 231 276 325 378 435 496 561 630 703 780 861 946 1035 1128 1225]]]\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\u003eWe put them in a spiral format;\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[   spiralHex = [\\n861  946  1035  1128  1225\\n780  91  120  153  190\\n703  66  1  6  231\\n630  45  28  15  276\\n561  496  435  378  325]]\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 sum its diag = 861 + 91 + 1 + 15 + 325 = 1293.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the output as char.\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":44316,"title":"Pandigital Multiples of 11 (based on Project Euler 491)","description":"A \"Pandigital number of order X\" is one that contains all of the numbers from 0 to X, but with no leading zeroes. If X\u003e9, the cycle 0-9 repeats itself. For example, 2310 is a Pandigital number of order 3 (0-3), while 120345678901 is a Pandigital number of order 11, with the \"01\" at the end of the number representing 10 and 11, respectively (10 and 11 mod 10, essentially). 0321 is not a Pandigital number, as it has a leading zero.\r\n\r\nGiven a number X, determine how many pandigital numbers of that order are divisible by 11.  You do not need to return the numbers themselves, just how many of them there are.","description_html":"\u003cp\u003eA \"Pandigital number of order X\" is one that contains all of the numbers from 0 to X, but with no leading zeroes. If X\u0026gt;9, the cycle 0-9 repeats itself. For example, 2310 is a Pandigital number of order 3 (0-3), while 120345678901 is a Pandigital number of order 11, with the \"01\" at the end of the number representing 10 and 11, respectively (10 and 11 mod 10, essentially). 0321 is not a Pandigital number, as it has a leading zero.\u003c/p\u003e\u003cp\u003eGiven a number X, determine how many pandigital numbers of that order are divisible by 11.  You do not need to return the numbers themselves, just how many of them there are.\u003c/p\u003e","function_template":"function y = pandigitalby11(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 2;y_correct = 0;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\nx = 3;y_correct = 6;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\nx = 7;y_correct = 4032;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\np6=pandigitalby11(6);\r\np8=pandigitalby11(8);\r\np9=pandigitalby11(9);\r\n\r\nassert(p8\u003ep6);\r\nassert(p9\u003ep8);\r\n\r\nf6=factor(p6);\r\nf8=factor(p8);\r\nf9=factor(p9);\r\nf9e1=f9(end-1);\r\n\r\nassert(p6\u003e256);\r\nassert(max(f9)\u003cmax(f8));\r\nassert(f9e1\u003emax(f6));\r\nassert(numel(f9)\u003enumel(f8));\r\n%%\r\nx = 11;y_correct = 9072000;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\nx = 14;y_correct = 3216477600;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\nassert(isequal(pandigitalby11(16),222911740800))","published":true,"deleted":false,"likes_count":5,"comments_count":15,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":55,"test_suite_updated_at":"2017-10-23T01:32:05.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-12T15:26:05.000Z","updated_at":"2026-04-18T11:13:17.000Z","published_at":"2017-10-16T01:50:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eA \\\"Pandigital number of order X\\\" is one that contains all of the numbers from 0 to X, but with no leading zeroes. If X\u0026gt;9, the cycle 0-9 repeats itself. For example, 2310 is a Pandigital number of order 3 (0-3), while 120345678901 is a Pandigital number of order 11, with the \\\"01\\\" at the end of the number representing 10 and 11, respectively (10 and 11 mod 10, essentially). 0321 is not a Pandigital number, as it has a leading zero.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a number X, determine how many pandigital numbers of that order are divisible by 11. You do not need to return the numbers themselves, just how many of them there are.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":44311,"title":"Number of Even Elements in Fibonacci Sequence","description":"Find how many even Fibonacci numbers are available in the first d numbers.\r\n\r\nConsider the following first 14 numbers\r\n\r\n  1 1 2 3 5 8 13 21 34 55 89 144 233 377 ...\r\n\r\n4 of them are even. ","description_html":"\u003cp\u003eFind how many even Fibonacci numbers are available in the first d numbers.\u003c/p\u003e\u003cp\u003eConsider the following first 14 numbers\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e1 1 2 3 5 8 13 21 34 55 89 144 233 377 ...\r\n\u003c/pre\u003e\u003cp\u003e4 of them are even.\u003c/p\u003e","function_template":"function y = evenFibo(d)\r\n  y = x;\r\nend","test_suite":"%%\r\nd = 14;\r\ny_correct = 4;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 20;\r\ny_correct = 6;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 50;\r\ny_correct = 16;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 100;\r\ny_correct = 33;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 150;\r\ny_correct = 50;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 200;\r\ny_correct = 66;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 500;\r\ny_correct = 166;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 1000;\r\ny_correct = 333;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 1e4;\r\ny_correct = 3333;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 2e4;\r\ny_correct = 6666;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 3e5;\r\ny_correct = 1e5;\r\nassert(isequal(evenFibo(d),y_correct))\r\n\r\n%%\r\nd = 6e6;\r\ny_correct = 2e6;\r\nassert(isequal(evenFibo(d),y_correct))\r\n% \r\n% %%\r\n% d = 9223372036854775807;\r\n% y_correct = 3074457345618258432;\r\n% assert(isequal(evenFibo(d),y_correct))\r\n","published":true,"deleted":false,"likes_count":21,"comments_count":9,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1667,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-11T12:36:15.000Z","updated_at":"2026-04-28T16:23:13.000Z","published_at":"2017-10-16T01:50:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind how many even Fibonacci numbers are available in the first d numbers.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eConsider the following first 14 numbers\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 1 2 3 5 8 13 21 34 55 89 144 233 377 ...]]\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\u003e4 of them are even.\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":44364,"title":"Is this a valid Tic Tac Toe State?","description":"For the game of \u003chttps://en.wikipedia.org/wiki/Tic-tac-toe Tic Tac Toe\u003e we will be storing the state of the game in a matrix M.\r\n\r\nFor this game: \r\n\r\n\u003c\u003chttps://upload.wikimedia.org/wikipedia/commons/3/32/Tic_tac_toe.svg\u003e\u003e\r\n\r\nWe would store the state as this:\r\n\r\n  -1  1  1 \r\n   1 -1 -1\r\n   1 -1 -1\r\n\r\nIf there were any blanks squares, they would be 0;\r\n\r\nFor this challenge, X goes first. Neither side is compelled to take a win if possible. The game stops when either player wins.\r\n\r\nFor this challenge, is the the given board state\r\n 0: legal \r\n 1: this state can not occur in a game\r\n\r\nThe example in the image would return 0 because if X goes first there can never be more O than X. The state matrix will only hold [-1 0 1], so we are only checking for logic of the game.","description_html":"\u003cp\u003eFor the game of \u003ca href = \"https://en.wikipedia.org/wiki/Tic-tac-toe\"\u003eTic Tac Toe\u003c/a\u003e we will be storing the state of the game in a matrix M.\u003c/p\u003e\u003cp\u003eFor this game:\u003c/p\u003e\u003cimg src = \"https://upload.wikimedia.org/wikipedia/commons/3/32/Tic_tac_toe.svg\"\u003e\u003cp\u003eWe would store the state as this:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e-1  1  1 \r\n 1 -1 -1\r\n 1 -1 -1\r\n\u003c/pre\u003e\u003cp\u003eIf there were any blanks squares, they would be 0;\u003c/p\u003e\u003cp\u003eFor this challenge, X goes first. Neither side is compelled to take a win if possible. The game stops when either player wins.\u003c/p\u003e\u003cp\u003eFor this challenge, is the the given board state\r\n 0: legal \r\n 1: this state can not occur in a game\u003c/p\u003e\u003cp\u003eThe example in the image would return 0 because if X goes first there can never be more O than X. The state matrix will only hold [-1 0 1], so we are only checking for logic of the game.\u003c/p\u003e","function_template":"function y = isLegalTicTacToeState(M)\r\n  y = round(rand);\r\nend","test_suite":"%%\r\nx = [1 1 0\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [0 0 0\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 1;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [  -1  1  1 \r\n        1 -1 -1\r\n        1 -1 -1];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [ 0 -1 1\r\n     -1  1 0\r\n      1  0 0];\r\ny_correct = 1;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [ 1  1  1\r\n     -1 -1 -1\r\n      0  0  0];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [-1 1 1\r\n     0 -1 1\r\n     1 0 -1];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [-1 1 0\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 1;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [-1 0 0\r\n     0 0 0\r\n     0 0 0];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [-1 1 0\r\n     0 1 0\r\n     0 1 0];\r\ny_correct = 0;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n%%\r\nx = [1  1  1\r\n     -1 1 -1\r\n     -1 1 -1];\r\ny_correct = 1;\r\nassert(isequal(isLegalTicTacToeState(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":6,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":133,"test_suite_updated_at":"2017-10-20T22:46:06.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-09T23:21:35.000Z","updated_at":"2026-04-18T14:02:29.000Z","published_at":"2017-10-20T22:46:06.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor the game of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Tic-tac-toe\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eTic Tac Toe\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e we will be storing the state of the game in a matrix M.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor this game:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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\u003eWe would store the state as this:\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  1  1 \\n 1 -1 -1\\n 1 -1 -1]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf there were any blanks squares, they would be 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\u003eFor this challenge, X goes first. Neither side is compelled to take a win if possible. The game stops when either player wins.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor this challenge, is the the given board state 0: legal 1: this state can not occur in a game\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe example in the image would return 0 because if X goes first there can never be more O than X. The state matrix will only hold [-1 0 1], so we are only checking for logic of the game.\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":44365,"title":"An asteroid and a spacecraft","description":"\r\n\u0026#128640 Imagine a non-relativistic simple situation. \r\n\r\nAssume positions p0, p1, p2, and p3 are three dimensional Cartesian coordinates.\r\n\r\nYour spacecraft started from the position p0 at time t0. \r\n\r\nYour spacecraft is moving with a constant velocity.\r\n\r\nYour spacecraft is expected to reach a star at the location p1 at time t1.\r\n\r\nYou just heard over the radio that an asteroid has been identified at the location p2 at time t0.\r\n\r\nThe asteroid is moving with a constant velocity.\r\n\r\nThe asteroid is expected to reach another star at the location p3 at time t1. \r\n\r\nYou need to write a code 'safetrip' in MATLAB to return true if the minimum distance between your spacecraft and the asteroid will be more than the distance d during the time interval between t0 and t1, otherwise return false.","description_html":"\u003cp\u003e\u0026#128640 Imagine a non-relativistic simple situation.\u003c/p\u003e\u003cp\u003eAssume positions p0, p1, p2, and p3 are three dimensional Cartesian coordinates.\u003c/p\u003e\u003cp\u003eYour spacecraft started from the position p0 at time t0.\u003c/p\u003e\u003cp\u003eYour spacecraft is moving with a constant velocity.\u003c/p\u003e\u003cp\u003eYour spacecraft is expected to reach a star at the location p1 at time t1.\u003c/p\u003e\u003cp\u003eYou just heard over the radio that an asteroid has been identified at the location p2 at time t0.\u003c/p\u003e\u003cp\u003eThe asteroid is moving with a constant velocity.\u003c/p\u003e\u003cp\u003eThe asteroid is expected to reach another star at the location p3 at time t1.\u003c/p\u003e\u003cp\u003eYou need to write a code 'safetrip' in MATLAB to return true if the minimum distance between your spacecraft and the asteroid will be more than the distance d during the time interval between t0 and t1, otherwise return false.\u003c/p\u003e","function_template":"function ok = safetrip(d, t0, t1, p0, p1, p2, p3)\r\n    if d\u003e1000000000\r\n        ok = true;\r\n    end\r\nend","test_suite":"%%\r\np0 = [0 0 0];\r\np1 = [1 1 1];\r\np2 = [2 2 2];\r\np3 = [3 3 3];\r\nt0 = 0; \r\nt1 = 1;\r\nd = 1;\r\nok = true;\r\nassert(isequal(safetrip(d, t0, t1, p0, p1, p2, p3), ok))\r\n\r\n%%\r\np0 = [3 3 3];\r\np1 = [2 2 2];\r\np2 = [2 2 2];\r\np3 = [3 3 3];\r\nt0 = 0; \r\nt1 = 1;\r\nd = 1;\r\nok = false;\r\nassert(isequal(safetrip(d, t0, t1, p0, p1, p2, p3), ok))\r\n\r\n%%\r\np0 = [1 2 3];\r\np1 = [4 5 6];\r\np2 = [3 2 1];\r\np3 = [6 5 4];\r\nt0 = 10; \r\nt1 = 20;\r\nd = 2;\r\nok = true;\r\nassert(isequal(safetrip(d, t0, t1, p0, p1, p2, p3), ok))\r\n\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":8,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":180,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-10T02:30:44.000Z","updated_at":"2026-04-18T10:51:25.000Z","published_at":"2017-10-16T01:51: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\",\"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\u003e\u0026amp;#128640 Imagine a non-relativistic simple situation.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 positions p0, p1, p2, and p3 are three dimensional Cartesian coordinates.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 spacecraft started from the position p0 at time t0.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 spacecraft is moving with a constant velocity.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 spacecraft is expected to reach a star at the location p1 at time t1.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 just heard over the radio that an asteroid has been identified at the location p2 at time t0.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 asteroid is moving with a constant velocity.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 asteroid is expected to reach another star at the location p3 at time t1.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 need to write a code 'safetrip' in MATLAB to return true if the minimum distance between your spacecraft and the asteroid will be more than the distance d during the time interval between t0 and t1, otherwise return false.\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":44381,"title":"Cache me Outside","description":"The test suite includes a simple recursive Fibonacci sequence generator, but it's terribly inefficient. One simple method for improving its performance is using a technique called memoization. Write a function that takes a function_handle that we wish to memoize and returns a function_handle to a memoized version of the initial handle.","description_html":"\u003cp\u003eThe test suite includes a simple recursive Fibonacci sequence generator, but it's terribly inefficient. One simple method for improving its performance is using a technique called memoization. Write a function that takes a function_handle that we wish to memoize and returns a function_handle to a memoized version of the initial handle.\u003c/p\u003e","function_template":"function memfcn = memoize_this(fcn)\r\n    memfcn = fcn;\r\nend","test_suite":"%%\r\nmemfib = memoize_this(@fib);\r\n\r\n[seq, n1] = fib(1, memfib);\r\nassert(n1 == 1);\r\n\r\n[seq, n2] = fib(20, memfib);\r\nassert(n2 - n1 == 19);\r\n\r\n[seq, n3] = fib(100, memfib);\r\nassert(n3 - n2 == 81);\r\n\r\n\r\nfunction [seq, n] = fib(n, memfib)\r\n    persistent num\r\n    if isempty(num)\r\n        num = 1;\r\n    else\r\n        num = num + 1;\r\n    end\r\n    \r\n    if n \u003c 3\r\n        seq = ones(1, n);\r\n    else\r\n        seq = memfib(n-1, memfib);\r\n        seq = [seq, seq(end-1) + seq(end)];\r\n    end\r\n    \r\n    n = num;\r\nend","published":true,"deleted":false,"likes_count":5,"comments_count":6,"created_by":134,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":114,"test_suite_updated_at":"2017-10-17T21:30:35.000Z","rescore_all_solutions":true,"group_id":35,"created_at":"2017-10-12T20:12:52.000Z","updated_at":"2026-04-18T11:45:33.000Z","published_at":"2017-10-16T01:51:02.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe test suite includes a simple recursive Fibonacci sequence generator, but it's terribly inefficient. One simple method for improving its performance is using a technique called memoization. Write a function that takes a function_handle that we wish to memoize and returns a function_handle to a memoized version of the initial handle.\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":281,"title":"Acid and water","description":"\u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878;\r\n\r\nAssume that there is a 100 liter tank. \r\n\r\nIt is initially filled with just distilled water. \r\n\r\nIt is continuously drained at R liters per minute. \r\n\r\nThis tank is always maintained full and homogeneous by continuously adding and stirring R liters per minute of an unknown acid (or some fancy oil if it helps you solving this problem). \r\n\r\nHow many liters W of water will be in the tank after M minutes?\r\n\r\nNeglect any expansion or contraction when the acid is mixed with water. ","description_html":"\u003cp\u003e\u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878;\u003c/p\u003e\u003cp\u003eAssume that there is a 100 liter tank.\u003c/p\u003e\u003cp\u003eIt is initially filled with just distilled water.\u003c/p\u003e\u003cp\u003eIt is continuously drained at R liters per minute.\u003c/p\u003e\u003cp\u003eThis tank is always maintained full and homogeneous by continuously adding and stirring R liters per minute of an unknown acid (or some fancy oil if it helps you solving this problem).\u003c/p\u003e\u003cp\u003eHow many liters W of water will be in the tank after M minutes?\u003c/p\u003e\u003cp\u003eNeglect any expansion or contraction when the acid is mixed with water.\u003c/p\u003e","function_template":"function W = tank(R,M)\r\n  W = 100 * R * M;\r\nend","test_suite":"%%\r\nR=1; \r\nM=1;\r\nW=99;\r\nassert(tank(R,M)\u003eW)\r\n%%\r\nR=2; \r\nM=2;\r\nW=96;\r\nassert(tank(R,M)\u003eW)\r\n%%\r\nR=10; \r\nM=10;\r\nW=36;\r\nassert(tank(R,M)\u003eW)\r\n%%\r\nR=15; \r\nM=20;\r\nW=5;\r\nassert(tank(R,M)\u003cW)\r\n%%\r\nR=7; \r\nM=8;\r\nW=58;\r\nassert(tank(R,M)\u003cW)\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":13,"created_by":166,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":284,"test_suite_updated_at":"2012-02-07T16:08:37.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2012-02-07T16:08:37.000Z","updated_at":"2026-04-18T10:50:56.000Z","published_at":"2017-10-16T01:50:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003e\u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878; \u0026#9878;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssume that there is a 100 liter tank.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIt is initially filled with just distilled water.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIt is continuously drained at R liters per minute.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 tank is always maintained full and homogeneous by continuously adding and stirring R liters per minute of an unknown acid (or some fancy oil if it helps you solving this problem).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHow many liters W of water will be in the tank after M minutes?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNeglect any expansion or contraction when the acid is mixed with water.\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":44344,"title":"The 5th Root","description":"Write a function to find the 5th root of a number.\r\n\r\nIt sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method to solve the problem.","description_html":"\u003cp\u003eWrite a function to find the 5th root of a number.\u003c/p\u003e\u003cp\u003eIt sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method to solve the problem.\u003c/p\u003e","function_template":"function f = fifth_root(n)\r\n f = n^(1/5)\r\nend","test_suite":"%%\r\nfiletext = fileread('fifth_root.m');\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'power')),'power() forbidden')\r\nassert(isempty(strfind(filetext, 'mpower')),'mpower() forbidden')\r\nassert(isempty(strfind(filetext, 'realpow')),'realpow() forbidden')\r\nassert(isempty(strfind(filetext, 'nthroot')),'nthroot() forbidden')\r\nassert(isempty(strfind(filetext, 'roots')),'roots() forbidden')\r\n\r\n%%\r\nn = 1/9765625;\r\nassert(abs(fifth_root(n)-1/25)\u003c1e-5)\r\n\r\n%%\r\nn = 1/5555;\r\nassert(abs(fifth_root(n)-0.178263811215444)\u003c1e-5)\r\n\r\n%%\r\nn = 1/3125;\r\nassert(abs(fifth_root(n)-1/5)\u003c1e-5)\r\n\r\n%%\r\nn = 1/125;\r\nassert(abs(fifth_root(n)-0.380730787743176)\u003c1e-5)\r\n\r\n%%\r\nn = 1/5;\r\nassert(abs(fifth_root(n)-0.724779663677696)\u003c1e-5)\r\n\r\n%%\r\nn = 1;\r\nassert(abs(fifth_root(n)-1)\u003c1e-5)\r\n\r\n%%\r\nn = 5;\r\nassert(abs(fifth_root(n)-1.37972966146121)\u003c1e-5)\r\n\r\n%%\r\nn = 25;\r\nassert(abs(fifth_root(n)-1.90365393871588)\u003c1e-5)\r\n\r\n%%\r\nn = 50;\r\nassert(abs(fifth_root(n)-2.18672414788656)\u003c1e-5)\r\n\r\n%%\r\nn = 500;\r\nassert(abs(fifth_root(n)-3.46572421577573)\u003c1e-5)\r\n\r\n%%\r\nn = 3125;\r\nassert(abs(fifth_root(n)-5)\u003c1e-5)\r\n\r\n%%\r\nn = 759375;\r\nassert(abs(fifth_root(n)-15)\u003c1e-5)\r\n\r\n%%\r\nn = 9765625;\r\nassert(abs(fifth_root(n)-25)\u003c1e-5)\r\n\r\n%%\r\nn = 312500000;\r\nassert(abs(fifth_root(n)-50)\u003c1e-5)\r\n\r\n%%\r\nn = 75937500000;\r\nassert(abs(fifth_root(n)-150)\u003c1e-5)\r\n\r\n%%\r\nn = 31250000000000;\r\nassert(abs(fifth_root(n)-500)\u003c1e-5)\r\n\r\n%%\r\nn = 52658067346875;\r\nassert(abs(fifth_root(n)-555)\u003c1e-5)","published":true,"deleted":false,"likes_count":13,"comments_count":3,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":566,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-22T16:03:40.000Z","updated_at":"2026-04-18T14:10:29.000Z","published_at":"2017-10-16T01:50:59.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eWrite a function to find the 5th root of a number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\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 sounds easy, but the typical functions are not allowed (see the test suite), so you'll need to find a non-standard method 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":44367,"title":"Inscribed Pentagon? 2","description":"Your function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon may or may not be centered on the circle. The function should return one of the following values:\r\n\r\n -1: the pentagon is not centered on the circle (within 5% of r)^\r\n  0: the pentagon is completely enclosed within the circle but is not inscribed\r\n  1: the pentagon is inscribed in the circle (within ±0.02)\r\n  2: the vertices of the pentagon extend beyond the circle\r\n\r\nPoints will be rounded to the nearest hundredth. See the test cases for examples. (There will not be a case where some vertices are within the circle and others without.)\r\n\r\n^ Due to the asymmetric nature of the pentagon, its centroid does not coincide with center of its inscribing circle, hence the ±5% tolerance window. ","description_html":"\u003cp\u003eYour function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon may or may not be centered on the circle. The function should return one of the following values:\u003c/p\u003e\u003cpre\u003e -1: the pentagon is not centered on the circle (within 5% of r)^\r\n  0: the pentagon is completely enclosed within the circle but is not inscribed\r\n  1: the pentagon is inscribed in the circle (within ±0.02)\r\n  2: the vertices of the pentagon extend beyond the circle\u003c/pre\u003e\u003cp\u003ePoints will be rounded to the nearest hundredth. See the test cases for examples. (There will not be a case where some vertices are within the circle and others without.)\u003c/p\u003e\u003cp\u003e^ Due to the asymmetric nature of the pentagon, its centroid does not coincide with center of its inscribing circle, hence the ±5% tolerance window.\u003c/p\u003e","function_template":"function y = inscribed_pentagon2(p,cp,r)\r\n y = -1;\r\nend","test_suite":"%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,6.58; 6.42,1.92; 3.97,-5.63; -3.97,-5.63; -6.42,1.92];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,4.55; 4.28,1.44; 2.65,-3.59; -2.65,-3.59; -4.28,1.44];\r\ncp = [0,0];\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [0,0.5];\r\nr = 8.75;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55];\r\ncp = [1.98,-0.47];\r\nr = 8.75;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,6.58; 6.42,1.92; 3.97,-5.63; -3.97,-5.63; -6.42,1.92] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp = [20,8];\r\np = [0,4.55; 4.28,1.44; 2.65,-3.59; -2.65,-3.59; -4.28,1.44] + repmat(cp,[5,1]);\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp_temp = [20,8];\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55] + repmat(cp_temp,[5,1]);\r\ncp = [19.5,9.08];\r\nr = 2.5;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\ncp_temp = [20,8];\r\np = [0,5; 4.76,1.55; 2.94,-4.05; -2.94,-4.05; -4.76,1.55] + repmat(cp_temp,[5,1]);\r\ncp = [19.86,7.19];\r\nr = 7.5;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.66,11.42; 24.37,5.58; 19.05,3.10; 15.04,7.40; 17.89,12.54];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [25.01,12.47; 25.98,4.58; 18.78,1.23; 13.37,7.03; 17.22,13.97];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [23.27,11.12; 23.92,5.87; 19.12,3.63; 15.52,7.50; 18.08,12.13];\r\ncp = [20,8];\r\nr = 5;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [32.54,38.78; 38.84,26.41; 29.02,16.59; 16.65,22.89; 18.83,36.61];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 2;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.49,35.54; 34.69,27.29; 28.14,20.74; 19.89,24.95; 21.34,34.09];\r\ncp = [26.97,28.45];\r\nr = 8.75;\r\ny_correct = 0;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [26.41,29.04];\r\nr = 6.13;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))\r\n\r\n%%\r\np = [30.94,36.26; 35.61,27.09; 28.34,19.82; 19.17,24.49; 20.78,34.65];\r\ncp = [27.07,27.66];\r\nr = 9.63;\r\ny_correct = -1;\r\nassert(isequal(inscribed_pentagon2(p,cp,r),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":97,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-10T15:28:54.000Z","updated_at":"2026-04-18T10:53:19.000Z","published_at":"2017-10-16T01:51: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\":[],\"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\u003eYour function will be provided with the five vertices of a pentagon (p) as well as the center point (cp) and radius (r) of a circle. The pentagon may or may not be centered on the circle. The function should return one of the following values:\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: the pentagon is not centered on the circle (within 5% of r)^\\n  0: the pentagon is completely enclosed within the circle but is not inscribed\\n  1: the pentagon is inscribed in the circle (within ±0.02)\\n  2: the vertices of the pentagon extend beyond the circle]]\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\u003ePoints will be rounded to the nearest hundredth. See the test cases for examples. (There will not be a case where some vertices are within the circle and others without.)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e^ Due to the asymmetric nature of the pentagon, its centroid does not coincide with center of its inscribing circle, hence the ±5% tolerance window.\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":44359,"title":"5th Time's a Charm","description":"Write a function that will return the input value. However, your function must fail the first four times, only functioning properly every fifth time. Furthermore, the first four times the function is called, successively closer, but not correct, values must be supplied by the function.\r\n\r\nFor example, if x = 10, you may return any number not equal to 10 the first function call. Here, we will return 27. Then, the second function call must return a value between 27 and 10, but not equal to either, and so on, until 10 is returned the fifth time.","description_html":"\u003cp\u003eWrite a function that will return the input value. However, your function must fail the first four times, only functioning properly every fifth time. Furthermore, the first four times the function is called, successively closer, but not correct, values must be supplied by the function.\u003c/p\u003e\u003cp\u003eFor example, if x = 10, you may return any number not equal to 10 the first function call. Here, we will return 27. Then, the second function call must return a value between 27 and 10, but not equal to either, and so on, until 10 is returned the fifth time.\u003c/p\u003e","function_template":"function y = fifth_times_a_charm(x)\r\n y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny1 = fifth_times_a_charm(x);\r\nassert(~isequal(y1,x))\r\n\r\ny2 = fifth_times_a_charm(x);\r\nassert(~isequal(y2,x))\r\nassert(abs(x-y2)\u003cabs(x-y1))\r\n\r\ny3 = fifth_times_a_charm(x);\r\nassert(~isequal(y3,x))\r\nassert(abs(x-y3)\u003cabs(x-y2))\r\n\r\ny4 = fifth_times_a_charm(x);\r\nassert(~isequal(y4,x))\r\nassert(abs(x-y4)\u003cabs(x-y3))\r\n\r\ny5 = fifth_times_a_charm(x);\r\nassert(isequal(y5,x))\r\n\r\n%%\r\nx = -1;\r\ny1 = fifth_times_a_charm(x);\r\nassert(~isequal(y1,x))\r\n\r\ny2 = fifth_times_a_charm(x);\r\nassert(~isequal(y2,x))\r\nassert(abs(x-y2)\u003cabs(x-y1))\r\n\r\ny3 = fifth_times_a_charm(x);\r\nassert(~isequal(y3,x))\r\nassert(abs(x-y3)\u003cabs(x-y2))\r\n\r\ny4 = fifth_times_a_charm(x);\r\nassert(~isequal(y4,x))\r\nassert(abs(x-y4)\u003cabs(x-y3))\r\n\r\ny5 = fifth_times_a_charm(x);\r\nassert(isequal(y5,x))\r\n\r\n%%\r\nx = 42;\r\ny1 = fifth_times_a_charm(x);\r\nassert(~isequal(y1,x))\r\n\r\ny2 = fifth_times_a_charm(x);\r\nassert(~isequal(y2,x))\r\nassert(abs(x-y2)\u003cabs(x-y1))\r\n\r\ny3 = fifth_times_a_charm(x);\r\nassert(~isequal(y3,x))\r\nassert(abs(x-y3)\u003cabs(x-y2))\r\n\r\ny4 = fifth_times_a_charm(x);\r\nassert(~isequal(y4,x))\r\nassert(abs(x-y4)\u003cabs(x-y3))\r\n\r\ny5 = fifth_times_a_charm(x);\r\nassert(isequal(y5,x))\r\n\r\n%%\r\nx = i;\r\ny1 = fifth_times_a_charm(x);\r\nassert(~isequal(y1,x))\r\n\r\ny2 = fifth_times_a_charm(x);\r\nassert(~isequal(y2,x))\r\nassert(abs(x-y2)\u003cabs(x-y1))\r\n\r\ny3 = fifth_times_a_charm(x);\r\nassert(~isequal(y3,x))\r\nassert(abs(x-y3)\u003cabs(x-y2))\r\n\r\ny4 = fifth_times_a_charm(x);\r\nassert(~isequal(y4,x))\r\nassert(abs(x-y4)\u003cabs(x-y3))\r\n\r\ny5 = fifth_times_a_charm(x);\r\nassert(isequal(y5,x))","published":true,"deleted":false,"likes_count":7,"comments_count":5,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":206,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-03T17:35:55.000Z","updated_at":"2026-04-18T10:56:18.000Z","published_at":"2017-10-16T01:51: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\",\"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\u003eWrite a function that will return the input value. However, your function must fail the first four times, only functioning properly every fifth time. Furthermore, the first four times the function is called, successively closer, but not correct, values must be supplied by the function.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, if x = 10, you may return any number not equal to 10 the first function call. Here, we will return 27. Then, the second function call must return a value between 27 and 10, but not equal to either, and so on, until 10 is returned the fifth time.\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":44337,"title":"Sums of Distinct Powers","description":"You will be given three numbers: base, nstart, and nend.  Write a MATLAB script that will compute the sum of a sequence of both the distinct powers of base as well as sums of distinct powers of base.  Your sequence should start with the 'nstart'th term and end with the 'nend'th term.  For example:\r\n\r\n* base=4\r\n* nstart=2\r\n* nend=6\r\n\r\nThe first several sums of the distinct powers of 4 are:\r\n\r\n* 1 (4^0)\r\n* 4 (4^1)\r\n* 5 (4^1 + 4^0)\r\n* 16 (4^2)\r\n* 17 (4^2 + 4^0)\r\n* 20 (4^2 + 4^1)\r\n* 21 (4^2 + 4^1 + 4^0)\r\n* 64 (4^3)\r\n* 65 (4^3 + 4^0)\r\n\r\nSince nstart=2 and nend=6 in this example, you take the second through the sixth terms of this sequence.  The correct output would be 4+5+16+17+20, or 62.  Notice that the number 8 does not occur in this pattern.  While 8 is a multiple of 4, 8=4^1+4^1.  Because there are two 4^1 terms in the sum, 8 does not qualify as a sum of *distinct* powers of 4.  You can assume that all three will be integers, base\u003e1, and that nstart\u003cnend.  Good luck!","description_html":"\u003cp\u003eYou will be given three numbers: base, nstart, and nend.  Write a MATLAB script that will compute the sum of a sequence of both the distinct powers of base as well as sums of distinct powers of base.  Your sequence should start with the 'nstart'th term and end with the 'nend'th term.  For example:\u003c/p\u003e\u003cul\u003e\u003cli\u003ebase=4\u003c/li\u003e\u003cli\u003enstart=2\u003c/li\u003e\u003cli\u003enend=6\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe first several sums of the distinct powers of 4 are:\u003c/p\u003e\u003cul\u003e\u003cli\u003e1 (4^0)\u003c/li\u003e\u003cli\u003e4 (4^1)\u003c/li\u003e\u003cli\u003e5 (4^1 + 4^0)\u003c/li\u003e\u003cli\u003e16 (4^2)\u003c/li\u003e\u003cli\u003e17 (4^2 + 4^0)\u003c/li\u003e\u003cli\u003e20 (4^2 + 4^1)\u003c/li\u003e\u003cli\u003e21 (4^2 + 4^1 + 4^0)\u003c/li\u003e\u003cli\u003e64 (4^3)\u003c/li\u003e\u003cli\u003e65 (4^3 + 4^0)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eSince nstart=2 and nend=6 in this example, you take the second through the sixth terms of this sequence.  The correct output would be 4+5+16+17+20, or 62.  Notice that the number 8 does not occur in this pattern.  While 8 is a multiple of 4, 8=4^1+4^1.  Because there are two 4^1 terms in the sum, 8 does not qualify as a sum of \u003cb\u003edistinct\u003c/b\u003e powers of 4.  You can assume that all three will be integers, base\u0026gt;1, and that nstart\u0026lt;nend.  Good luck!\u003c/p\u003e","function_template":"function y = sum_distinct_powers(base,nstart,nend)\r\n  y = base*nstart*nend;\r\nend","test_suite":"%%\r\nbase=4;nstart=2;nend=6;y_correct=62;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=5;nstart=1;nend=1000;y_correct=1193853250;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=3;nstart=1;nend=1000;y_correct=14438162;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=3;nstart=100;nend=1000;y_correct=14397354;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=2;nstart=1;nend=2017;y_correct=2035153;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=7;nstart=1234;nend=2345;y_correct=843569026324;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nbase=7;nstart=1;nend=10;y_correct=1265;\r\nassert(isequal(sum_distinct_powers(base,nstart,nend),y_correct))\r\n%%\r\nnstart=1;nend=50;\r\njunk=arrayfun(@(base) sum_distinct_powers(base,nstart,nend),2:10);\r\ny_correct=[1275 7120 26365 75000 178591 374560 714465 1266280 2116675];\r\nassert(isequal(junk,y_correct))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":9,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":170,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-18T16:30:15.000Z","updated_at":"2026-04-18T10:51:36.000Z","published_at":"2017-10-16T01:50:59.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou will be given three numbers: base, nstart, and nend. Write a MATLAB script that will compute the sum of a sequence of both the distinct powers of base as well as sums of distinct powers of base. Your sequence should start with the 'nstart'th term and end with the 'nend'th term. For example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ebase=4\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003enstart=2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003enend=6\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe first several sums of the distinct powers of 4 are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1 (4^0)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4 (4^1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e5 (4^1 + 4^0)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e16 (4^2)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e17 (4^2 + 4^0)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e20 (4^2 + 4^1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e21 (4^2 + 4^1 + 4^0)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e64 (4^3)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e65 (4^3 + 4^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\u003eSince nstart=2 and nend=6 in this example, you take the second through the sixth terms of this sequence. The correct output would be 4+5+16+17+20, or 62. Notice that the number 8 does not occur in this pattern. While 8 is a multiple of 4, 8=4^1+4^1. Because there are two 4^1 terms in the sum, 8 does not qualify as a sum of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003edistinct\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e powers of 4. You can assume that all three will be integers, base\u0026gt;1, and that nstart\u0026lt;nend. Good luck!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44340,"title":"Recaman Sequence - III","description":"I want to create a Recaman sequence where there is a \"1\" in the n-th position. So from which integer should I start the Recaman sequence? If there are more than one starting integer that generates a sequence with a 1 in the n-th position, return the lowest one.\r\nFor example if I want to place the digit 1 in the 7th place in the sequence then I should start the sequence from six as follow;\r\nseq = [6 5 3 6 2 7 1 8 16]\r\nYou can also start the sequence with 12 and obtain a series where there is a 1 in 7th position;\r\nseq = [12 11 9 6 2 7 1]\r\nRelated Challenges :\r\nRecaman Sequence - I\r\nRecaman Sequence - II\r\nRecaman Sequence - III","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: 308.167px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 154.083px; transform-origin: 407px 154.083px; 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: 371.5px 8px; transform-origin: 371.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eI want to create a Recaman sequence where there is a \"1\" in the n-th position. So from which integer should I start the Recaman sequence? If there are more than one starting integer that generates a sequence with a 1 in the n-th position, return the lowest one.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 368.5px 8px; transform-origin: 368.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example if I want to place the digit 1 in the 7th place in the sequence then I should start the sequence from six as follow;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 104px 8.5px; tab-size: 4; transform-origin: 104px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eseq = [6 5 3 6 2 7 1 8 16]\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: 294.5px 8px; transform-origin: 294.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou can also start the sequence with 12 and obtain a series where there is a 1 in 7th position;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 92px 8.5px; tab-size: 4; transform-origin: 92px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eseq = [12 11 9 6 2 7 1]\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: 72.5px 8px; transform-origin: 72.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eRelated Challenges :\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 61.3px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: decimal; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 30.65px; transform-origin: 391px 30.65px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/44338\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eRecaman Sequence - I\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/44339\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eRecaman Sequence - II\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 75px 8px; transform-origin: 75px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eRecaman Sequence - III\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function startPoint = RecamanIII(onesplace)\r\n\r\nend","test_suite":"%%\r\nfiletext = fileread('RecamanIII.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'str2num'); \r\nassert(~illegal)\r\n\r\n%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 2;\r\ny_correct = 0;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 3;\r\ny_correct = 4;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 9;\r\ny_correct = 13;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 13;\r\ny_correct = 15;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 15;\r\ny_correct = 26;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 26;\r\ny_correct = 54;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 54;\r\ny_correct = 208;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n%%\r\nx = 208;\r\ny_correct = 2485;\r\nassert(isequal(RecamanIII(x),y_correct))\r\nassert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\\d\\.\\+\\-\\*\\/]+','match'))))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":12,"created_by":8703,"edited_by":223089,"edited_at":"2022-10-11T07:22:46.000Z","deleted_by":null,"deleted_at":null,"solvers_count":103,"test_suite_updated_at":"2022-10-11T07:22:46.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-19T07:36:19.000Z","updated_at":"2026-04-23T02:19:14.000Z","published_at":"2017-10-16T01:50:59.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\u003eI want to create a Recaman sequence where there is a \\\"1\\\" in the n-th position. So from which integer should I start the Recaman sequence? If there are more than one starting integer that generates a sequence with a 1 in the n-th position, return the lowest 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\u003eFor example if I want to place the digit 1 in the 7th place in the sequence then I should start the sequence from six as follow;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[seq = [6 5 3 6 2 7 1 8 16]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou can also start the sequence with 12 and obtain a series where there is a 1 in 7th position;\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[seq = [12 11 9 6 2 7 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\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\u003eRelated Challenges :\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44338\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - I\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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44339\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - II\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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRecaman Sequence - III\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":44353,"title":"Group-wise Euclidean distance","description":"*Input*:\r\n \r\n* *x* —— An array of size *n-by-d*, where each row vector denotes a point in a d-dimensional space;\r\n* *g* —— A grouping (index) vector g of size *n-by-1*, which divides the points in x into groups. Specifically, the rows in x corresponding to the same group index in g belong to the same group. \r\n\r\n*Output*: \r\n\r\n* *y* —— The group-wise Euclidean distance matrix associated with the points in x. Suppose that m = max(g), then y will be an *m-by-m* matrix, where each element y(i,j) is the Euclidean distance between group i and group j, which is defined as the minimum of the Euclidean distances between any points in group i and any other points in group j. \r\n\r\n*Example*:\r\n\r\nExample 1: n = 6, d = 1\r\n\r\n  g = [2   1   3  2  1].';\r\n  x = [3  10  15  8  5].';\r\n  y = [0   2   5            % y(1,2) = y(2,1) = min(10-3,5-3,10-8,8-5) = 2\r\n       2   0   7            % y(1,3) = y(3,1) = min(15-10,15-5) = 5\r\n       5   7   0];          % y(2,3) = y(3,2) = min(15-3,15-8) = 7\r\n\r\nExample 2: n = 3, d = 2\r\n\r\n  g = [1 2 2].';\r\n  x = [0   0\r\n       5  12\r\n       3   4];\r\n  y = [0  5;\r\n       5  0];    % y(1,2) = y(2,1) = min(sqrt(5^2+12^2),sqrt(3^2+4^2)) = 5\r\n  \r\n*Testing*:\r\n\r\nThe test suite will focus mainly on the large-scale problem dimensions (e.g., large n and/or d). The purpose is to direct attention towards efficient runtime speed of execution. Note that your solution may run into a time-out error if it is not sufficiently efficient (which is why this problem falls into the \u003chttps://www.mathworks.com/matlabcentral/cody/groups/35 Cody5:Hard\u003e category).\r\n\r\n*Scoring*:\r\n\r\nWe have modified Cody's default size-based scoring function into a performance-based scoring system (implemented by our fellow Cody player \u003chttps://www.mathworks.com/matlabcentral/cody/players/3021298-ly-cao LY Cao\u003e), in which the score of your submission equals 5 times the execution time of your solution (which reprents a score resolution of 0.2 seconds and allows for more room for performance improvement). Please ignore the code size and focus only on improving the code performance, as our test suite will reject any submissions running longer than 20 seconds (in contrast to Cody's default 40 seconds timeout limit).  \r\n\r\nPlease be advised that an amazingly fast solution would earn a score \u003c 5, meaning that it completes execution of all test cases within a second!\r\n\r\n*Update* (11/21/2017):\r\nAdditional test cases are added to ban cheater solutions (e.g., hard-coded submissions 1351541, 1351007, 1350563, 1349442, all came from \u003chttps://www.mathworks.com/matlabcentral/cody/players/3931805-marco-tullio Marco Tullio\u003e).\r\n","description_html":"\u003cp\u003e\u003cb\u003eInput\u003c/b\u003e:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003cb\u003ex\u003c/b\u003e —— An array of size \u003cb\u003en-by-d\u003c/b\u003e, where each row vector denotes a point in a d-dimensional space;\u003c/li\u003e\u003cli\u003e\u003cb\u003eg\u003c/b\u003e —— A grouping (index) vector g of size \u003cb\u003en-by-1\u003c/b\u003e, which divides the points in x into groups. Specifically, the rows in x corresponding to the same group index in g belong to the same group.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003e\u003cb\u003eOutput\u003c/b\u003e:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003cb\u003ey\u003c/b\u003e —— The group-wise Euclidean distance matrix associated with the points in x. Suppose that m = max(g), then y will be an \u003cb\u003em-by-m\u003c/b\u003e matrix, where each element y(i,j) is the Euclidean distance between group i and group j, which is defined as the minimum of the Euclidean distances between any points in group i and any other points in group j.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003e\u003cb\u003eExample\u003c/b\u003e:\u003c/p\u003e\u003cp\u003eExample 1: n = 6, d = 1\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eg = [2   1   3  2  1].';\r\nx = [3  10  15  8  5].';\r\ny = [0   2   5            % y(1,2) = y(2,1) = min(10-3,5-3,10-8,8-5) = 2\r\n     2   0   7            % y(1,3) = y(3,1) = min(15-10,15-5) = 5\r\n     5   7   0];          % y(2,3) = y(3,2) = min(15-3,15-8) = 7\r\n\u003c/pre\u003e\u003cp\u003eExample 2: n = 3, d = 2\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eg = [1 2 2].';\r\nx = [0   0\r\n     5  12\r\n     3   4];\r\ny = [0  5;\r\n     5  0];    % y(1,2) = y(2,1) = min(sqrt(5^2+12^2),sqrt(3^2+4^2)) = 5\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eTesting\u003c/b\u003e:\u003c/p\u003e\u003cp\u003eThe test suite will focus mainly on the large-scale problem dimensions (e.g., large n and/or d). The purpose is to direct attention towards efficient runtime speed of execution. Note that your solution may run into a time-out error if it is not sufficiently efficient (which is why this problem falls into the \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/groups/35\"\u003eCody5:Hard\u003c/a\u003e category).\u003c/p\u003e\u003cp\u003e\u003cb\u003eScoring\u003c/b\u003e:\u003c/p\u003e\u003cp\u003eWe have modified Cody's default size-based scoring function into a performance-based scoring system (implemented by our fellow Cody player \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/players/3021298-ly-cao\"\u003eLY Cao\u003c/a\u003e), in which the score of your submission equals 5 times the execution time of your solution (which reprents a score resolution of 0.2 seconds and allows for more room for performance improvement). Please ignore the code size and focus only on improving the code performance, as our test suite will reject any submissions running longer than 20 seconds (in contrast to Cody's default 40 seconds timeout limit).\u003c/p\u003e\u003cp\u003ePlease be advised that an amazingly fast solution would earn a score \u0026lt; 5, meaning that it completes execution of all test cases within a second!\u003c/p\u003e\u003cp\u003e\u003cb\u003eUpdate\u003c/b\u003e (11/21/2017):\r\nAdditional test cases are added to ban cheater solutions (e.g., hard-coded submissions 1351541, 1351007, 1350563, 1349442, all came from \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/players/3931805-marco-tullio\"\u003eMarco Tullio\u003c/a\u003e).\u003c/p\u003e","function_template":"function y = groupDist(x,g)\r\n  y = x;\r\nend","test_suite":"%%\r\nassessFunctionAbsence({'regexp','regexpi','regexprep','str2num','tic','toc','persistent','global','rng','assert','!','system','unix','noCheater'},'FileName','groupDist.m')\r\n\r\n%%\r\nfid = fopen('noCheater.p','Wb');\r\nfwrite(fid, hex2dec(reshape([\r\n    '7630312E30307630302E30300007701CAB777FB100000015000000740000007E3D5C20F'...'\r\n    '5319EEB8B0D3D9C9C87C18B91C13D7310D9D8E837C95E62D49A3FE08B071790DBC222B5'...\r\n    '839E9A19EA6AA7CF3785A7E7CEC1CFE46E0E9A5DB7C82D69A4FAB7BF308D0871C342A5F'...\r\n    'EF9AF61623F1D97F80207388D54ABA3CB3D551617DA33AA3F5040CD425FC9B29E2A4233'...\r\n    'AE7C5ADEF399'],2,[]).')); rehash path; \r\nfclose(fid); \r\nassert(noCheater(),'Cheater detected!')\r\n\r\n%%\r\ng = [2   1   3  2  1].';\r\nx = [3  10  15  8  5].';\r\ny_correct = [0   2   5            \r\n             2   0   7      \r\n             5   7   0]; \r\nassert(isequaln(y_correct,groupDist(x,g)))\r\n\r\n%%\r\ng = [1 2 2].';\r\nx = [0   0\r\n     5  12\r\n     3   4];\r\ny_correct = [0  5;\r\n             5  0];    \r\nassert(isequal(y_correct,groupDist(x,g)))\r\n\r\n%%\r\ng = [2 2 3 3 3 1].';\r\nx = [-5   12\r\n      3    4\r\n     -7  -24\r\n     25    4\r\n      9   40\r\n      0    0];\r\ny_correct = [0    5   25;\r\n             5    0   22\r\n             25  22    0];  \r\nassert(isequal(y_correct,groupDist(x,g)))\r\n\r\n%% Randomized case to disallow hard-coded solution\r\ng = randperm(10).';\r\nx = rand(10,1);\r\na = sortrows([g,x]);\r\ny_correct = abs(a(:,2)-a(:,2).');\r\nassert(isequal(round(y_correct,10),round(groupDist(x,g),10))) \r\n\r\n%% Additional test case to disallow hard-coded solution\r\ng = [1,2,3].';\r\nx = [2,5,10].';\r\ny_correct = [0   3   8            \r\n             3   0   5      \r\n             8   5   0]; \r\nassert(isequaln(y_correct,groupDist(x,g)))\r\n\r\n%%\r\nglobal t\r\nt = zeros(1,3); \r\nrng(923,'twister');\r\nn = 5e3; d = 3; m = 5;\r\nx = rand(n,d);\r\ng = randi(m,n,1); \r\ny_correct = [0,0.00653919638188362,0.00319052186150122,0.00858841434457234,0.00359654235965771\r\n             0.00653919638188362,0,0.00855286615862212,0.00589790293838067,0.00484910151004134\r\n             0.00319052186150122,0.00855286615862212,0,0.00591041083080696,0.00483607360689871\r\n             0.00858841434457234,0.00589790293838067,0.00591041083080696,0,0.00695738487959094\r\n             0.00359654235965771,0.00484910151004134,0.00483607360689871,0.00695738487959094,0];\r\ntic, y = groupDist(x,g); t(1) = toc;\r\nassert(isequal(round(y_correct,10),round(y,10))) \r\n\r\n%%\r\nglobal t\r\nrng(123) \r\nrng(max('cody5'),'combRecursive');\r\nn = 5e3; d = 3; m = 100;\r\nx = 10*rand(n,d);\r\ng = randi(m,n,1); \r\ntic, y = groupDist(x,g); t(2) = toc;\r\nassert(norm(y-y.') \u003c 1e-11 \u0026\u0026 all(~diag(y)) \u0026\u0026 all(size(y)==m) \u0026\u0026 abs(det(y)-0.030846735888559)\u003c1e-8 \u0026\u0026...\r\n    abs(cond(y)-1.606720826682107e+04) \u003c 1e-6 \u0026\u0026 abs(max(nonzeros(y))-1.058563379304832)\u003c1e-10 \u0026\u0026...\r\n    abs(mean(nonzeros(y))-0.419901913602729)\u003c1e-8)\r\n\r\n%%\r\nglobal t \r\nrng(sum('Cody5, Oct. 16, 2017'),'multFibonacci') \r\nn = 5e3; d = 1e2;  m = 100;\r\nx = 5*randn(n,d) + 20;\r\ng = randi(m,n,1); \r\ntic, y = groupDist(x,g); t(3) = toc;\r\nassert(norm(y-y.') \u003c 1e-11 \u0026\u0026 all(~diag(y)) \u0026\u0026 all(size(y)==m) \u0026\u0026 ...\r\n    abs(cond(y)-2.024633860688276e+02) \u003c 1e-8 \u0026\u0026 abs(max(nonzeros(y))-57.768463869822135)\u003c1e-10 \u0026\u0026...\r\n    abs(mean(nonzeros(y))-53.852605466762945)\u003c1e-8) \r\n \r\n%%\r\nglobal t\r\nfid = fopen('score.p','Wb');\r\nfwrite(fid,uint8(sscanf([...\r\n     '7630312E30307630302E3030000B901C454EFFB100000031000001330000018D483A60'...\r\n     '366BC9545F84AE26323B67424D4E8A7A2E5B7D8ACAA45A1C3C5C8B33E245C95243E3CB'...\r\n     'AF5D0D993BDA70B7AB5DA365A83E8CA87FFC45265E23EF80943784C5F48E6E53D5DA34'...\r\n     'F1F2ECD34683EABE3B7461DC9E8004CC50B2A79D73495F6F625B5365602B2E6C6093D2'...\r\n     '997D371DA457CE82327E686AF512A507B2CB62A375BFD1B283DDD2C01EDEF2771EDAA3'...\r\n     '6ABB4852BA4061E20149688E812EB41A9AF8627EF35755492D2830EB8718BCFE88027E'...\r\n     '6EA960B63A3B3E26E0451B1DCF14F3C20E70D9D93B08E7FF4AE8D82E7CC38042FD38F7'...\r\n     'A14D312EF5652823FEB7E8B52AF5C69F5E7D16B116B5F979EDA77459D6BB61B7971A51'...\r\n     '041227DD601319D667DF62E8DA5E381FDD07A2806FE835BD2569E5315CDFC19C6B6A2B'...\r\n     '4F0FF6BA803F1759ACAB133CCFAB6D5A5D002FC2C5F381F0'],'%2X')));\r\nfclose(fid);\r\nscore(round(5*sum(t)))\r\nfprintf('The execution time of test case %d is %.5f seconds \\n',[5:7;t])\r\nfprintf('The total execution time is %.5f seconds \\n',sum(t))\r\nassert(sum(t)\u003c20, 'Sorry, your solution is too slow. The execution time must not exceed 20 seconds.')\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":4,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":85,"test_suite_updated_at":"2017-11-21T22:49:00.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-10-01T04:33:43.000Z","updated_at":"2026-04-18T14:03:45.000Z","published_at":"2017-10-16T01:51: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\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e —— An array of size\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en-by-d\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, where each row vector denotes a point in a d-dimensional space;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eg\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e —— A grouping (index) vector g of size\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en-by-1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, which divides the points in x into groups. Specifically, the rows in x corresponding to the same group index in g belong to the same group.\u003c/w:t\u003e\u003c/w:r\u003e\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:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e —— The group-wise Euclidean distance matrix associated with the points in x. Suppose that m = max(g), then y will be an\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003em-by-m\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e matrix, where each element y(i,j) is the Euclidean distance between group i and group j, which is defined as the minimum of the Euclidean distances between any points in group i and any other points in group j.\u003c/w:t\u003e\u003c/w:r\u003e\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\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\u003eExample 1: n = 6, d = 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[g = [2   1   3  2  1].';\\nx = [3  10  15  8  5].';\\ny = [0   2   5            % y(1,2) = y(2,1) = min(10-3,5-3,10-8,8-5) = 2\\n     2   0   7            % y(1,3) = y(3,1) = min(15-10,15-5) = 5\\n     5   7   0];          % y(2,3) = y(3,2) = min(15-3,15-8) = 7]]\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\u003eExample 2: n = 3, d = 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[g = [1 2 2].';\\nx = [0   0\\n     5  12\\n     3   4];\\ny = [0  5;\\n     5  0];    % y(1,2) = y(2,1) = min(sqrt(5^2+12^2),sqrt(3^2+4^2)) = 5]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTesting\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe test suite will focus mainly on the large-scale problem dimensions (e.g., large n and/or d). The purpose is to direct attention towards efficient runtime speed of execution. Note that your solution may run into a time-out error if it is not sufficiently efficient (which is why this problem falls into 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=\\\"https://www.mathworks.com/matlabcentral/cody/groups/35\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody5:Hard\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e category).\u003c/w:t\u003e\u003c/w:r\u003e\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:\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eWe have modified Cody's default size-based scoring function into a performance-based scoring system (implemented by our fellow Cody player\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/players/3021298-ly-cao\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eLY Cao\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e), in which the score of your submission equals 5 times the execution time of your solution (which reprents a score resolution of 0.2 seconds and allows for more room for performance improvement). Please ignore the code size and focus only on improving the code performance, as our test suite will reject any submissions running longer than 20 seconds (in contrast to Cody's default 40 seconds timeout limit).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePlease be advised that an amazingly fast solution would earn a score \u0026lt; 5, meaning that it completes execution of all test cases within a second!\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eUpdate\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (11/21/2017): Additional test cases are added to ban cheater solutions (e.g., hard-coded submissions 1351541, 1351007, 1350563, 1349442, all came from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/players/3931805-marco-tullio\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eMarco Tullio\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44310,"title":"Digit concentration in Champernowne's constant","description":"Consider the first 50 digits of Champernowne's constant\r\n \r\n    0.12345678910111213141516171819202122232425262728293...\r\n  \r\nThere are two zeros (do not count the left side of \".\" (integer part) ) in this series. So the digit concentration for 0 for the first 50 digits is = 2 / 50 = 0.04.\r\n\r\nAlso the number of '2' (x) digit is counted as 13. So the digit concentration of number '2' for the first 50 (d) digit is = 13/50 = 0.26\r\n\r\nCalculate the digit concentration of number x for the first d digit of constant.\r\n","description_html":"\u003cp\u003eConsider the first 50 digits of Champernowne's constant\u003c/p\u003e\u003cpre\u003e    0.12345678910111213141516171819202122232425262728293...\u003c/pre\u003e\u003cp\u003eThere are two zeros (do not count the left side of \".\" (integer part) ) in this series. So the digit concentration for 0 for the first 50 digits is = 2 / 50 = 0.04.\u003c/p\u003e\u003cp\u003eAlso the number of '2' (x) digit is counted as 13. So the digit concentration of number '2' for the first 50 (d) digit is = 13/50 = 0.26\u003c/p\u003e\u003cp\u003eCalculate the digit concentration of number x for the first d digit of constant.\u003c/p\u003e","function_template":"function concentration = digitCon(d,x)\r\n  y = x;\r\nend","test_suite":"%%\r\nd = 1;\r\nx = 1;\r\ny_correct = 1;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 10;\r\nx = 5;\r\ny_correct = 0.1000;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 10;\r\nx = 1;\r\ny_correct = 0.2000;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 20;\r\nx = 9;\r\ny_correct = 0.0500;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n\r\n%%\r\nd = 50;\r\nx = 0;\r\ny_correct = 0.0400;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 50;\r\nx = 2;\r\ny_correct = 0.2600;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1000;\r\nx = 9;\r\ny_correct = 0.0670;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1e4;\r\nx = 8;\r\ny_correct = 0.0747;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1e5;\r\nx = 7;\r\ny_correct = 0.0864;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1e6;\r\nx = 6;\r\ny_correct = 0.0935;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 1e6;\r\nx = 5;\r\ny_correct = 0.0937;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 2e6;\r\nx = 4;\r\ny_correct = 0.0903;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)\r\n\r\n%%\r\nd = 2000124;\r\nx = 3;\r\ny_correct = 0.1162;\r\nassert(abs(digitCon(d,x)-y_correct) \u003c 1e-4)","published":true,"deleted":false,"likes_count":5,"comments_count":1,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":143,"test_suite_updated_at":"2017-10-25T07:12:47.000Z","rescore_all_solutions":true,"group_id":35,"created_at":"2017-09-11T10:35:46.000Z","updated_at":"2026-04-18T10:53:53.000Z","published_at":"2017-10-16T01:50:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eConsider the first 50 digits of Champernowne's constant\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.12345678910111213141516171819202122232425262728293...]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are two zeros (do not count the left side of \\\".\\\" (integer part) ) in this series. So the digit concentration for 0 for the first 50 digits is = 2 / 50 = 0.04.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eAlso the number of '2' (x) digit is counted as 13. So the digit concentration of number '2' for the first 50 (d) digit is = 13/50 = 0.26\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCalculate the digit concentration of number x for the first d digit of constant.\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":44341,"title":"Hexagonal numbers on a spiral matrix","description":"Put hexagonal numbers in a ( m x m ) spiral matrix and return the sum of its diagonal elements.\r\n\r\nFormula of hexagonal numbers h(n) = 2n^2 - n\r\n\r\nIf m = 5;\r\n\r\n  spiral(5) =   \r\n    21    22    23    24    25\r\n    20     7     8     9    10\r\n    19     6     1     2    11\r\n    18     5     4     3    12\r\n    17    16    15    14    13\r\n\r\nFirst 5x5=25 hexagonal numbers are;\r\n\r\n  h = [1 6 15 28 45 66 91 120 153 190 231 276 325 378 435 496 561 630 703 780 861 946 1035 1128 1225]\r\n\r\nWe put them in a spiral format;\r\n\r\n   spiralHex = [\r\n861\t946\t1035\t1128\t1225\r\n780\t91\t120\t153\t190\r\n703\t66\t1\t6\t231\r\n630\t45\t28\t15\t276\r\n561\t496\t435\t378\t325\r\n\r\nAnd sum its diag = 861 + 91 + 1 + 15 + 325 = 1293.\r\n\r\nReturn the output as char.","description_html":"\u003cp\u003ePut hexagonal numbers in a ( m x m ) spiral matrix and return the sum of its diagonal elements.\u003c/p\u003e\u003cp\u003eFormula of hexagonal numbers h(n) = 2n^2 - n\u003c/p\u003e\u003cp\u003eIf m = 5;\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003espiral(5) =   \r\n  21    22    23    24    25\r\n  20     7     8     9    10\r\n  19     6     1     2    11\r\n  18     5     4     3    12\r\n  17    16    15    14    13\r\n\u003c/pre\u003e\u003cp\u003eFirst 5x5=25 hexagonal numbers are;\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eh = [1 6 15 28 45 66 91 120 153 190 231 276 325 378 435 496 561 630 703 780 861 946 1035 1128 1225]\r\n\u003c/pre\u003e\u003cp\u003eWe put them in a spiral format;\u003c/p\u003e\u003cpre\u003e   spiralHex = [\r\n861\t946\t1035\t1128\t1225\r\n780\t91\t120\t153\t190\r\n703\t66\t1\t6\t231\r\n630\t45\t28\t15\t276\r\n561\t496\t435\t378\t325\u003c/pre\u003e\u003cp\u003eAnd sum its diag = 861 + 91 + 1 + 15 + 325 = 1293.\u003c/p\u003e\u003cp\u003eReturn the output as char.\u003c/p\u003e","function_template":"function y = hexagonalSpiral(m)\r\n  \r\nend","test_suite":"%%\r\nm = 1;\r\ny_correct = '1';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 2;\r\ny_correct = '16';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 5;\r\ny_correct = '1293';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 16;\r\ny_correct = '420800';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 100;\r\ny_correct = '4000333360';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 1295;\r\ny_correct = '1456830580539887';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 2500;\r\ny_correct = '39062505208334000';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 5000;\r\ny_correct = '1250000041666668000';\r\nassert(isequal(hexagonalSpiral(m),y_correct))\r\n\r\n%%\r\nm = 8000;\r\ny_correct = '13107200170666668800';\r\nassert(isequal(hexagonalSpiral(m),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":164,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-19T08:06:36.000Z","updated_at":"2026-04-18T10:55:17.000Z","published_at":"2017-10-16T01:50:59.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePut hexagonal numbers in a ( m x m ) spiral matrix and return the sum of its diagonal elements.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eFormula of hexagonal numbers h(n) = 2n^2 - n\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf m = 5;\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[spiral(5) =   \\n  21    22    23    24    25\\n  20     7     8     9    10\\n  19     6     1     2    11\\n  18     5     4     3    12\\n  17    16    15    14    13]]\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\u003eFirst 5x5=25 hexagonal numbers are;\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[h = [1 6 15 28 45 66 91 120 153 190 231 276 325 378 435 496 561 630 703 780 861 946 1035 1128 1225]]]\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\u003eWe put them in a spiral format;\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[   spiralHex = [\\n861  946  1035  1128  1225\\n780  91  120  153  190\\n703  66  1  6  231\\n630  45  28  15  276\\n561  496  435  378  325]]\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 sum its diag = 861 + 91 + 1 + 15 + 325 = 1293.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the output as char.\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":44316,"title":"Pandigital Multiples of 11 (based on Project Euler 491)","description":"A \"Pandigital number of order X\" is one that contains all of the numbers from 0 to X, but with no leading zeroes. If X\u003e9, the cycle 0-9 repeats itself. For example, 2310 is a Pandigital number of order 3 (0-3), while 120345678901 is a Pandigital number of order 11, with the \"01\" at the end of the number representing 10 and 11, respectively (10 and 11 mod 10, essentially). 0321 is not a Pandigital number, as it has a leading zero.\r\n\r\nGiven a number X, determine how many pandigital numbers of that order are divisible by 11.  You do not need to return the numbers themselves, just how many of them there are.","description_html":"\u003cp\u003eA \"Pandigital number of order X\" is one that contains all of the numbers from 0 to X, but with no leading zeroes. If X\u0026gt;9, the cycle 0-9 repeats itself. For example, 2310 is a Pandigital number of order 3 (0-3), while 120345678901 is a Pandigital number of order 11, with the \"01\" at the end of the number representing 10 and 11, respectively (10 and 11 mod 10, essentially). 0321 is not a Pandigital number, as it has a leading zero.\u003c/p\u003e\u003cp\u003eGiven a number X, determine how many pandigital numbers of that order are divisible by 11.  You do not need to return the numbers themselves, just how many of them there are.\u003c/p\u003e","function_template":"function y = pandigitalby11(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 2;y_correct = 0;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\nx = 3;y_correct = 6;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\nx = 7;y_correct = 4032;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\np6=pandigitalby11(6);\r\np8=pandigitalby11(8);\r\np9=pandigitalby11(9);\r\n\r\nassert(p8\u003ep6);\r\nassert(p9\u003ep8);\r\n\r\nf6=factor(p6);\r\nf8=factor(p8);\r\nf9=factor(p9);\r\nf9e1=f9(end-1);\r\n\r\nassert(p6\u003e256);\r\nassert(max(f9)\u003cmax(f8));\r\nassert(f9e1\u003emax(f6));\r\nassert(numel(f9)\u003enumel(f8));\r\n%%\r\nx = 11;y_correct = 9072000;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\nx = 14;y_correct = 3216477600;\r\nassert(isequal(pandigitalby11(x),y_correct))\r\n%%\r\nassert(isequal(pandigitalby11(16),222911740800))","published":true,"deleted":false,"likes_count":5,"comments_count":15,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":55,"test_suite_updated_at":"2017-10-23T01:32:05.000Z","rescore_all_solutions":false,"group_id":35,"created_at":"2017-09-12T15:26:05.000Z","updated_at":"2026-04-18T11:13:17.000Z","published_at":"2017-10-16T01:50:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eA \\\"Pandigital number of order X\\\" is one that contains all of the numbers from 0 to X, but with no leading zeroes. If X\u0026gt;9, the cycle 0-9 repeats itself. For example, 2310 is a Pandigital number of order 3 (0-3), while 120345678901 is a Pandigital number of order 11, with the \\\"01\\\" at the end of the number representing 10 and 11, respectively (10 and 11 mod 10, essentially). 0321 is not a Pandigital number, as it has a leading zero.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a number X, determine how many pandigital numbers of that order are divisible by 11. You do not need to return the numbers themselves, just how many of them there are.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"group:Cody5:Hard difficulty_rating_bin:medium","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"group:Cody5:Hard difficulty_rating_bin:medium","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"group":[["group:Cody5:Hard","","","Cody5:Hard",""]],"difficulty_rating_bin":[["difficulty_rating_bin:medium","","","medium",""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f382541f140\u003e":["Cody5:Hard"],"#\u003cMathWorks::Search::Field:0x00007f382541e7e0\u003e":["medium"]},"filters":{"#\u003cMathWorks::Search::Field:0x00007f382541ce40\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f382541f960\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f382541f8c0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f382541f5a0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f382541f320\u003e":"group:Cody5:Hard difficulty_rating_bin:medium"},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f382541f320\u003e":"group:Cody5:Hard difficulty_rating_bin:medium"},"queried_facets":{"#\u003cMathWorks::Search::Field:0x00007f382541f140\u003e":["Cody5:Hard"],"#\u003cMathWorks::Search::Field:0x00007f382541e7e0\u003e":["medium"]}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"cody-search","password":"78X075ddcV44","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"group:Cody5:Hard difficulty_rating_bin:medium","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"group":[["group:Cody5:Hard","","","Cody5:Hard",""]],"difficulty_rating_bin":[["difficulty_rating_bin:medium","","","medium",""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f382541f140\u003e":["Cody5:Hard"],"#\u003cMathWorks::Search::Field:0x00007f382541e7e0\u003e":["medium"]},"filters":{"#\u003cMathWorks::Search::Field:0x00007f382541ce40\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f382541f960\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f382541f8c0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f382541f5a0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f382541f320\u003e":"group:Cody5:Hard difficulty_rating_bin:medium"},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f382541f320\u003e":"group:Cody5:Hard difficulty_rating_bin:medium"},"queried_facets":{"#\u003cMathWorks::Search::Field:0x00007f382541f140\u003e":["Cody5:Hard"],"#\u003cMathWorks::Search::Field:0x00007f382541e7e0\u003e":["medium"]}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":44311,"difficulty_rating":"easy-medium"},{"id":44364,"difficulty_rating":"easy-medium"},{"id":44365,"difficulty_rating":"medium"},{"id":44381,"difficulty_rating":"medium"},{"id":281,"difficulty_rating":"medium"},{"id":44344,"difficulty_rating":"medium"},{"id":44367,"difficulty_rating":"medium"},{"id":44359,"difficulty_rating":"medium"},{"id":44337,"difficulty_rating":"medium"},{"id":44340,"difficulty_rating":"medium"},{"id":44353,"difficulty_rating":"medium"},{"id":44310,"difficulty_rating":"medium"},{"id":44341,"difficulty_rating":"medium"},{"id":44316,"difficulty_rating":"medium"}]}}