{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.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":"2025-12-14T00: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":1141,"title":"Volume difference between Ellipsoid and Sphere ","description":"Given an ellipsoid of semi  principal axis (a,b,c) find the volume of the difference between this ellipsoid and  the sphere within, round the result toward zero using the \"floor\" function. ","description_html":"\u003cp\u003eGiven an ellipsoid of semi  principal axis (a,b,c) find the volume of the difference between this ellipsoid and  the sphere within, round the result toward zero using the \"floor\" function.\u003c/p\u003e","function_template":"function y = ellipsoid_sphere_diff(a,b,c)\r\n  y = x;\r\nend","test_suite":"%%\r\na=2;b=2;c=8;\r\ny_correct = 100;\r\nassert(isequal(ellipsoid_sphere_diff(a,b,c),y_correct))\r\n%%\r\na=4;b=4;c=4;\r\ny_correct =0;\r\nassert(isequal(ellipsoid_sphere_diff(a,b,c),y_correct))\r\n%%\r\na=3;b=5;c=8;\r\ny_correct= 389;\r\nassert(isequal(ellipsoid_sphere_diff(a,b,c),y_correct))\r\n%%\r\na=4;b=6;c=8;\r\ny_correct=536;\r\nassert(isequal(ellipsoid_sphere_diff(a,b,c),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":5260,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":136,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":20,"created_at":"2012-12-25T23:34:50.000Z","updated_at":"2026-04-02T12:56:31.000Z","published_at":"2012-12-25T23:35: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\u003eGiven an ellipsoid of semi principal axis (a,b,c) find the volume of the difference between this ellipsoid and the sphere within, round the result toward zero using the \\\"floor\\\" function.\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":1442,"title":"Volume of a Simplex","description":"Return the volume of a \u003chttp://en.wikipedia.org/wiki/Simplex  regular _n_-simplex\u003e with a unit side length.\r\n\r\nResults are up to |4*eps| precision.\r\n\r\nNeither *string operations* nor *interpolations* are allowed!","description_html":"\u003cp\u003eReturn the volume of a \u003ca href = \"http://en.wikipedia.org/wiki/Simplex\"\u003eregular \u003ci\u003en\u003c/i\u003e-simplex\u003c/a\u003e with a unit side length.\u003c/p\u003e\u003cp\u003eResults are up to \u003ctt\u003e4*eps\u003c/tt\u003e precision.\u003c/p\u003e\u003cp\u003eNeither \u003cb\u003estring operations\u003c/b\u003e nor \u003cb\u003einterpolations\u003c/b\u003e are allowed!\u003c/p\u003e","function_template":"function V = simplexvolume(n)\r\n  V = n;\r\nend","test_suite":"user_solution = fileread('simplexvolume.m');\r\nassert(isempty(strfind(user_solution,'regexp')));\r\nassert(isempty(strfind(user_solution,'2str')));\r\nassert(isempty(strfind(user_solution,'str2')));\r\nassert(isempty(strfind(user_solution,'interp')));\r\nassert(isempty(strfind(user_solution,'printf')));\r\nassert(isempty(strfind(user_solution,'assert')));\r\n\r\n%%\r\nn = 0;\r\nV_correct = 1.0;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 1;\r\nV_correct = 1.0;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 2;\r\nV_correct = 0.433012701892219;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 3;\r\nV_correct = 0.117851130197758;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 4;\r\nV_correct = 0.023292374765623;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 5;\r\nV_correct = 0.003608439182435;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 6;\r\nV_correct = 0.000459331824838;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 7;\r\nV_correct = 0.000049603174603;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 8;\r\nV_correct = 0.000004650297619;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 9;\r\nV_correct = 0.000000385125244;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 10;\r\nV_correct = 0.000000028561653;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 11;\r\nV_correct = 0.000000001917653;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 12;\r\nV_correct = 0.000000000117613;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 13;\r\nV_correct = 0.000000000006639;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 14;\r\nV_correct = 0.000000000000347;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 15;\r\nV_correct = 0.000000000000017;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":10352,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":98,"test_suite_updated_at":"2013-04-28T07:06:18.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-22T11:35:14.000Z","updated_at":"2026-03-16T12:09:25.000Z","published_at":"2013-04-22T11:35:14.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\u003eReturn the volume of a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Simplex\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eregular\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e-simplex\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e with a unit side length.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eResults are up to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e4*eps\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e precision.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eNeither\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\u003estring operations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e nor\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\u003einterpolations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are allowed!\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":1385,"title":"Perimeter","description":"Given a sequence of points forming a closed path (first and last points are coincident) return the perimeter value.\r\nFor example:\r\n\r\n xy = [ 0,0 ;\r\n        1,0 ;\r\n        1,1 ;\r\n        0,1 ;\r\n        0,0 ];\r\n\r\n L = 4","description_html":"\u003cp\u003eGiven a sequence of points forming a closed path (first and last points are coincident) return the perimeter value.\r\nFor example:\u003c/p\u003e\u003cpre\u003e xy = [ 0,0 ;\r\n        1,0 ;\r\n        1,1 ;\r\n        0,1 ;\r\n        0,0 ];\u003c/pre\u003e\u003cpre\u003e L = 4\u003c/pre\u003e","function_template":"function L = perimeter1(xy)\r\n\r\n  L=xy;\r\n\r\nend","test_suite":"%% Test case 1: Square\r\n\r\nxy=[0,0;\r\n    1,0;\r\n    1,1;\r\n    0,1;\r\n    0,0];\r\n\r\n\r\nerr=(abs(perimeter1(xy)-4)/(4))*100;\r\nassert(err\u003c.1)\r\n\r\n%% Test case 2 : Circle\r\n\r\nt=[0:pi/100:2*pi,0]';\r\nxy=[cos(t),sin(t)];\r\n\r\n\r\nerr=(abs(perimeter1(xy)-2*pi)/(2*pi))*100;\r\nassert(err\u003c.1)\r\n\r\n%% Test case 4 : Half-circle\r\n\r\nt=[0:pi/100:pi,0]';\r\nxy=[cos(t),sin(t)];\r\n\r\nerr=(abs(perimeter1(xy)-(pi+2))/(2+pi))*100;\r\nassert(err\u003c.1)\r\n\r\n%% Test case 4 : Hexagon\r\n\r\nside=rand;\r\nx=side*[-1 -0.5 0.5 1 0.5 -0.5 -1];\r\ny=side*sqrt(3)*[0 -0.5 -0.5 0 0.5 0.5 0];\r\nxy=[x',y'];\r\nerr=(abs(perimeter1(xy)-(6*side))/(6*side))*100;\r\nassert(err\u003c.1)","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":10742,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":156,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":20,"created_at":"2013-03-25T10:56:31.000Z","updated_at":"2026-02-18T16:34:50.000Z","published_at":"2013-03-25T10:57:47.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a sequence of points forming a closed path (first and last points are coincident) return the perimeter value. For example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ xy = [ 0,0 ;\\n        1,0 ;\\n        1,1 ;\\n        0,1 ;\\n        0,0 ];\\n\\n L = 4]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1443,"title":"Edges of a n-dimensional Hypercube","description":"Return the number of edges on an \u003chttp://en.wikipedia.org/wiki/Hypercube _n_-dimensional hypercube\u003e (with an integer n \u0026ge; 0).\r\n\r\nNeither *string operations* nor *interpolations* are allowed!\r\n","description_html":"\u003cp\u003eReturn the number of edges on an \u003ca href = \"http://en.wikipedia.org/wiki/Hypercube\"\u003e\u003ci\u003en\u003c/i\u003e-dimensional hypercube\u003c/a\u003e (with an integer n \u0026ge; 0).\u003c/p\u003e\u003cp\u003eNeither \u003cb\u003estring operations\u003c/b\u003e nor \u003cb\u003einterpolations\u003c/b\u003e are allowed!\u003c/p\u003e","function_template":"function E = hypercube_edges(n)\r\n  E = n;\r\nend","test_suite":"%%\r\nuser_solution = fileread('hypercube_edges.m');\r\nassert(isempty(strfind(user_solution,'regexp')));\r\nassert(isempty(strfind(user_solution,'2str')));\r\nassert(isempty(strfind(user_solution,'str2')));\r\nassert(isempty(strfind(user_solution,'interp')));\r\nassert(isempty(strfind(user_solution,'printf')));\r\nassert(isempty(strfind(user_solution,'assert')));\r\n\r\n%%\r\nn = 0;\r\nE_correct = 0;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 1;\r\nE_correct = 1;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 2;\r\nE_correct = 4;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 3;\r\nE_correct = 12;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 4;\r\nE_correct = 32;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 5;\r\nE_correct = 80;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 6;\r\nE_correct = 192;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 7;\r\nE_correct = 448;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 8;\r\nE_correct = 1024;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 9;\r\nE_correct = 2304;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 10;\r\nE_correct = 5120;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 11;\r\nE_correct = 11264;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 12;\r\nE_correct = 24576;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 13;\r\nE_correct = 53248;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 14;\r\nE_correct = 114688;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 15;\r\nE_correct = 245760;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":10352,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":88,"test_suite_updated_at":"2013-04-28T07:06:47.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-22T11:46:41.000Z","updated_at":"2026-02-16T11:00:34.000Z","published_at":"2013-04-22T11:47:26.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\u003eReturn the number of edges on an\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Hypercube\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e-dimensional hypercube\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (with an integer n ≥ 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\u003eNeither\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\u003estring operations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e nor\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\u003einterpolations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are allowed!\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":1456,"title":"Beads on a Necklace (Convex Hulls)","description":"We may describe a \u003chttp://en.wikipedia.org/wiki/Convex_hull convex hull\u003e as a rubber band stretched around a list of points. Some of the points will be inside the rubber band, and some will define vertices of (or lie along the edge of) a \u003chttp://en.wikipedia.org/wiki/Convex_and_concave_polygons convex polygon\u003e.\r\n\r\nGiven an n-by-2 list of points xy where each row describes a point, your job is to determine if all the points belong to the convex hull for those points. In the matrix xy, the x coordinate is the first column and the y coordinate is the second column.\r\n\r\nSo, for example, the points below form a single convex hull.\r\n\r\n   *     *\r\n            \r\n   *     *  \r\n\r\nIn contrast, the points below do not, since the convex hull is a triangle that includes an interior point. Any polygon that includes all the points must necessarily be concave.\r\n\r\n      *\r\n      *  \r\n   *     *\r\n\r\nThus if\r\n\r\n xy = [1 1;1 2;2 2;2 1]\r\n\r\nthen\r\n\r\n allConvex(xy) =\u003e true\r\n\r\nWhereas\r\n\r\n xy = [1 1;3 1;2 2;2 3]\r\n allConvex(xy) =\u003e false\r\n \r\n\r\n","description_html":"\u003cp\u003eWe may describe a \u003ca href = \"http://en.wikipedia.org/wiki/Convex_hull\"\u003econvex hull\u003c/a\u003e as a rubber band stretched around a list of points. Some of the points will be inside the rubber band, and some will define vertices of (or lie along the edge of) a \u003ca href = \"http://en.wikipedia.org/wiki/Convex_and_concave_polygons\"\u003econvex polygon\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven an n-by-2 list of points xy where each row describes a point, your job is to determine if all the points belong to the convex hull for those points. In the matrix xy, the x coordinate is the first column and the y coordinate is the second column.\u003c/p\u003e\u003cp\u003eSo, for example, the points below form a single convex hull.\u003c/p\u003e\u003cpre\u003e   *     *\u003c/pre\u003e\u003cpre\u003e   *     *  \u003c/pre\u003e\u003cp\u003eIn contrast, the points below do not, since the convex hull is a triangle that includes an interior point. Any polygon that includes all the points must necessarily be concave.\u003c/p\u003e\u003cpre\u003e      *\r\n      *  \r\n   *     *\u003c/pre\u003e\u003cp\u003eThus if\u003c/p\u003e\u003cpre\u003e xy = [1 1;1 2;2 2;2 1]\u003c/pre\u003e\u003cp\u003ethen\u003c/p\u003e\u003cpre\u003e allConvex(xy) =\u003e true\u003c/pre\u003e\u003cp\u003eWhereas\u003c/p\u003e\u003cpre\u003e xy = [1 1;3 1;2 2;2 3]\r\n allConvex(xy) =\u003e false\u003c/pre\u003e","function_template":"function tf = allConvex(xy)\r\n  tf = true;\r\nend","test_suite":"%%\r\nxy = [1 1;1 2;2 2;2 1];\r\ntf_correct = true;\r\nassert(isequal(allConvex(xy),tf_correct))\r\n\r\n%%\r\nxy = [1 1;3 1;2 2;2 3];\r\ntf_correct = false;\r\nassert(isequal(allConvex(xy),tf_correct))\r\n\r\n%%\r\nxy = [6 4;10 6;10 3;3 1;5 5];\r\ntf_correct = false;\r\nassert(isequal(allConvex(xy),tf_correct))\r\n\r\n%%\r\nxy = [8 4;3 7;4 10;9 10;9 6;5 4];\r\ntf_correct = true;\r\nassert(isequal(allConvex(xy),tf_correct))\r\n\r\n%%\r\nxy = [14 26;14 29;2 15;2 7;3 7;18 17;8 23;26 11];\r\ntf_correct = false;\r\nassert(isequal(allConvex(xy),tf_correct))\r\n\r\n%%\r\nxy = [18 11;9 8;4 10;12 30;25 17;30 23;26 26;3 6];\r\ntf_correct = true;\r\nassert(isequal(allConvex(xy),tf_correct))\r\n\r\n%%\r\nxy = [1 1;1 2;1 3;3 3;3 1];\r\ntf_correct = true;\r\nassert(isequal(allConvex(xy),tf_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":7,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":"2013-04-24T19:14:21.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-24T18:11:58.000Z","updated_at":"2026-02-16T10:55:29.000Z","published_at":"2013-04-24T19:11:37.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWe may describe a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Convex_hull\\\"\u003e\u003cw:r\u003e\u003cw:t\u003econvex hull\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e as a rubber band stretched around a list of points. Some of the points will be inside the rubber band, and some will define vertices of (or lie along the edge of) a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Convex_and_concave_polygons\\\"\u003e\u003cw:r\u003e\u003cw:t\u003econvex polygon\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an n-by-2 list of points xy where each row describes a point, your job is to determine if all the points belong to the convex hull for those points. In the matrix xy, the x coordinate is the first column and the y coordinate is the second column.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSo, for example, the points below form a single convex hull.\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[   *     *\\n\\n   *     *]]\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\u003eIn contrast, the points below do not, since the convex hull is a triangle that includes an interior point. Any polygon that includes all the points must necessarily be concave.\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[      *\\n      *  \\n   *     *]]\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\u003eThus if\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[ xy = [1 1;1 2;2 2;2 1]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethen\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[ allConvex(xy) =\u003e true]]\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\u003eWhereas\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[ xy = [1 1;3 1;2 2;2 3]\\n allConvex(xy) =\u003e false]]\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":1462,"title":"Dots in a Sphere","description":"Return how many integer grid points there are inside a 3D sphere of radius _r_ centred at (0,0,0) (including points on the edge).\r\n\r\nNeither *string operations* nor *interpolations* are allowed!","description_html":"\u003cp\u003eReturn how many integer grid points there are inside a 3D sphere of radius \u003ci\u003er\u003c/i\u003e centred at (0,0,0) (including points on the edge).\u003c/p\u003e\u003cp\u003eNeither \u003cb\u003estring operations\u003c/b\u003e nor \u003cb\u003einterpolations\u003c/b\u003e are allowed!\u003c/p\u003e","function_template":"function n = dots_in_sphere(r)\r\n   n = r;\r\nend","test_suite":"%%\r\nuser_solution = fileread('dots_in_sphere.m');\r\nassert(isempty(strfind(user_solution,'regexp')));\r\nassert(isempty(strfind(user_solution,'2str')));\r\nassert(isempty(strfind(user_solution,'str2')));\r\nassert(isempty(strfind(user_solution,'interp')));\r\nassert(isempty(strfind(user_solution,'printf')));\r\nassert(isempty(strfind(user_solution,'assert')));\r\n\r\n%%\r\nr = 0;\r\nn_correct = 1;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 0.5;\r\nn_correct = 1;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 1;\r\nn_correct = 7;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 1.5;\r\nn_correct = 19;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 2;\r\nn_correct = 33;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 2.5;\r\nn_correct = 81;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 3;\r\nn_correct = 123;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 5;\r\nn_correct = 515;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 7.5;\r\nn_correct = 1791;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 10;\r\nn_correct = 4169;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 15;\r\nn_correct = 14147;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 20;\r\nn_correct = 33401;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 25;\r\nn_correct = 65267;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 50;\r\nn_correct = 523305;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 100;\r\nn_correct = 4187857;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":10352,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":65,"test_suite_updated_at":"2013-04-28T07:09:00.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-26T06:32:56.000Z","updated_at":"2026-02-16T10:50:59.000Z","published_at":"2013-04-26T06:41:52.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\u003eReturn how many integer grid points there are inside a 3D sphere of radius\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003er\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e centred at (0,0,0) (including points on the edge).\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eNeither\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\u003estring operations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e nor\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\u003einterpolations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are allowed!\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":1444,"title":"Dots in a Circle","description":"Return how many integer grid points there are inside a circle of radius _r_ centred at (0,0) (including points on the edge).\r\n\r\nNeither *string operations* nor *interpolations* are allowed!\r\n","description_html":"\u003cp\u003eReturn how many integer grid points there are inside a circle of radius \u003ci\u003er\u003c/i\u003e centred at (0,0) (including points on the edge).\u003c/p\u003e\u003cp\u003eNeither \u003cb\u003estring operations\u003c/b\u003e nor \u003cb\u003einterpolations\u003c/b\u003e are allowed!\u003c/p\u003e","function_template":"function n = dots_in_circle(r)\r\n  n = r;\r\nend","test_suite":"%%\r\nuser_solution = fileread('dots_in_circle.m');\r\nassert(isempty(strfind(user_solution,'regexp')));\r\nassert(isempty(strfind(user_solution,'2str')));\r\nassert(isempty(strfind(user_solution,'str2')));\r\nassert(isempty(strfind(user_solution,'interp')));\r\nassert(isempty(strfind(user_solution,'printf')));\r\nassert(isempty(strfind(user_solution,'assert')));\r\n\r\n%%\r\nr = 0;\r\nn_correct = 1;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 1;\r\nn_correct = 5;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 2;\r\nn_correct = 13;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 3;\r\nn_correct = 29;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 4;\r\nn_correct = 49;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 5;\r\nn_correct = 81;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 7.5;\r\nn_correct = 177;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 10;\r\nn_correct = 317;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 20;\r\nn_correct = 1257;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 30;\r\nn_correct = 2821;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 40;\r\nn_correct = 5025;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 50;\r\nn_correct = 7845;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 75;\r\nn_correct = 17665;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 100;\r\nn_correct = 31417;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":5,"created_by":10352,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":100,"test_suite_updated_at":"2013-04-28T07:07:28.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-22T12:50:26.000Z","updated_at":"2026-02-16T10:59:41.000Z","published_at":"2013-04-22T12:50:26.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\u003eReturn how many integer grid points there are inside a circle of radius\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003er\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e centred at (0,0) (including points on the edge).\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eNeither\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\u003estring operations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e nor\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\u003einterpolations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are allowed!\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":1074,"title":"Property dispute!","description":"Two neighbors have rectangular plots of land A and B. The surveyors give you the coordinates of each. If they overlap, there is a property dispute, and you must return the coordinates of the disputed region. If there is no conflict, return the empty set [].\r\nSuppose A and B look like this.\r\n *--------*\r\n | A      |\r\n |    *--------*\r\n |    |   |    |\r\n |    |   | B  |\r\n |    |   |    |\r\n |    *--------*\r\n |        |\r\n *--------*\r\nWe will give rectangle coordinates in [xLow yLow width height] format. So\r\n A = [0  0  5 10]\r\n B = [3  2  6  6]\r\nThen you should return rectangle that corresponds to the overlapping region.\r\n C = [3  2  2  6]","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: 430.2px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 406.5px 215.1px; transform-origin: 406.5px 215.1px; 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: 383.5px 31.5px; text-align: left; transform-origin: 383.5px 31.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 378.55px 7.81667px; transform-origin: 378.55px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eTwo neighbors have rectangular plots of land A and B. The surveyors give you the coordinates of each. If they overlap, there is a property dispute, and you must return the coordinates of the disputed region. If there is no conflict, return the empty set [].\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 102.175px 7.81667px; transform-origin: 102.175px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSuppose A and B look like this.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 183.9px; 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: 403.5px 91.95px; transform-origin: 403.5px 91.95px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 42.9917px 8.375px; tab-size: 4; transform-origin: 42.9917px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e *--------*\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 42.9917px 8.375px; tab-size: 4; transform-origin: 42.9917px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e | A      |\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 62.5333px 8.375px; tab-size: 4; transform-origin: 62.5333px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e |    *--------*\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 62.5333px 8.375px; tab-size: 4; transform-origin: 62.5333px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e |    |   |    |\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 62.5333px 8.375px; tab-size: 4; transform-origin: 62.5333px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e |    |   | B  |\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 62.5333px 8.375px; tab-size: 4; transform-origin: 62.5333px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e |    |   |    |\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 62.5333px 8.375px; tab-size: 4; transform-origin: 62.5333px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e |    *--------*\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 42.9917px 8.375px; tab-size: 4; transform-origin: 42.9917px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e |        |\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 42.9917px 8.375px; tab-size: 4; transform-origin: 42.9917px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e *--------*\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: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; 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: 236.175px 7.81667px; transform-origin: 236.175px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWe will give rectangle coordinates in [xLow yLow width height] format. So\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 40.8667px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 403.5px 20.4333px; transform-origin: 403.5px 20.4333px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 66.4417px 8.375px; tab-size: 4; transform-origin: 66.4417px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e A = [0  0  5 10]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 66.4417px 8.375px; tab-size: 4; transform-origin: 66.4417px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e B = [3  2  6  6]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; 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: 244.55px 7.81667px; transform-origin: 244.55px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThen you should return rectangle that corresponds to the overlapping region.\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: 403.5px 10.2167px; transform-origin: 403.5px 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: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; 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; text-wrap-mode: 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: 66.4417px 8.375px; tab-size: 4; transform-origin: 66.4417px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e C = [3  2  2  6]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function C = disputed_region(A,B)\r\n  C = [];\r\nend","test_suite":"%%\r\na = [0 0 5 10];\r\nb = [3 2 6 6];\r\nc = [3 2 2 6];\r\nassert(isequal(disputed_region(a,b),c))\r\n\r\n%%\r\na = [0 1 2 3];\r\nb = [-1 2 4 5];\r\nc = [0 2 2 2];\r\nassert(isequal(disputed_region(a,b),c))\r\n\r\n%%\r\na = [3 4 6 1];\r\nb = [2 1 2 2];\r\nassert(isempty(disputed_region(a,b)))\r\n\r\n%%\r\na = [5 18 14 6];\r\nb = [11 23 17 18];\r\nc = [11 23 8 1];\r\nassert(isequal(disputed_region(a,b),c))\r\n\r\n%%\r\na = [100 97 3 2];\r\nb = [99 93 12 12];\r\nc = [100 97 3 2];\r\nassert(isequal(disputed_region(a,b),c))\r\n\r\n%%\r\ndelta = 0.5;\r\na = [0 0 5 10]+delta;\r\nb = [3 2 6 6]+delta;\r\nc = [3 2 2 6]+delta;\r\nassert(isequal(disputed_region(a,b),c))\r\n\r\n%%\r\na = [0 0 1 1];\r\nb = [2 2 1 1];\r\nc = [];\r\nassert(isempty(disputed_region(a,b)))","published":true,"deleted":false,"likes_count":3,"comments_count":4,"created_by":7,"edited_by":223089,"edited_at":"2024-06-11T15:31:25.000Z","deleted_by":null,"deleted_at":null,"solvers_count":41,"test_suite_updated_at":"2024-06-11T15:31:25.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2012-11-28T22:11:52.000Z","updated_at":"2026-02-16T10:40:33.000Z","published_at":"2012-12-19T20:58:35.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTwo neighbors have rectangular plots of land A and B. The surveyors give you the coordinates of each. If they overlap, there is a property dispute, and you must return the coordinates of the disputed region. If there is no conflict, return the empty set [].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSuppose A and B look like 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[ *--------*\\n | A      |\\n |    *--------*\\n |    |   |    |\\n |    |   | B  |\\n |    |   |    |\\n |    *--------*\\n |        |\\n *--------*]]\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\u003eWe will give rectangle coordinates in [xLow yLow width height] format. So\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ A = [0  0  5 10]\\n B = [3  2  6  6]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThen you should return rectangle that corresponds to the overlapping region.\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[ C = [3  2  2  6]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":1411,"title":"Number of lattice points within a circle","description":"Find the number of points (x,y) in square lattice with x^2 + y^2 =\u003c n. This is related to Jame's \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1387 Problem 1387\u003e. Here you have to find the number of points within a circle.","description_html":"\u003cp\u003eFind the number of points (x,y) in square lattice with x^2 + y^2 =\u0026lt; n. This is related to Jame's \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1387\"\u003eProblem 1387\u003c/a\u003e. Here you have to find the number of points within a circle.\u003c/p\u003e","function_template":"function y = within_circle(n)\r\n  y = n;\r\nend","test_suite":"%%\r\nassert(isequal(within_circle(1),5))\r\n\r\n%%\r\nassert(isequal(within_circle(3),9))\r\n\r\n%%\r\nassert(isequal(within_circle(20),69))\r\n\r\n%%\r\nassert(isequal(within_circle(45),145))\r\n\r\n%%\r\nassert(isequal(within_circle(55),177))\r\n\r\n%%\r\nassert(isequal(within_circle(500),1581))\r\n\r\n%%\r\nassert(isequal(within_circle(10000),31417))\r\n\r\n%%\r\nassert(isequal(within_circle(50000),157093))\r\n\r\n%%\r\nassert(isequal(within_circle(999999),3141521))\r\n\r\n%%\r\nassert(isequal(within_circle(9999999),31415993))\r\n\r\n%%\r\nassert(isequal(within_circle(99999999),314159017)) % Approaching to Pi...\r\n\r\n%%\r\nfiletext = fileread('within_circle.m');\r\nassert(isempty(strfind(filetext, 'switch')))\r\nassert(isempty(strfind(filetext, 'case')))\r\nassert(isempty(strfind(filetext, 'if')))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":810,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":36,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-03T00:59:36.000Z","updated_at":"2026-02-16T11:05:45.000Z","published_at":"2013-04-03T01:11:03.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the number of points (x,y) in square lattice with x^2 + y^2 =\u0026lt; n. This is related to Jame's\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1387\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 1387\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Here you have to find the number of points within a circle.\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":1336,"title":"Geometry: Find Circle given 3 Non-Colinear Points","description":"*This Challenge is to determine the center and radius of a circle given three non-colinear points.*\r\n\r\n*Input:* Points\r\n\r\n*Output:* [xc, yc, r] where [xc,yc] are the center and r is the radius\r\n\r\n*Example:*\r\n\r\nInput: Points = [1 0 ; 0 -1 ; 0 1]\r\n\r\nOutput: [ 0 0 1]\r\n\r\n*Theory/Hint:* The Kasa method provides a best fit circle to a set of points.\r\n\r\n*Future:* 1) Circumscribe 4 points  2) Circumscribe N points  3) The Great Lego Cup Challenge","description_html":"\u003cp\u003e\u003cb\u003eThis Challenge is to determine the center and radius of a circle given three non-colinear points.\u003c/b\u003e\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e Points\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e [xc, yc, r] where [xc,yc] are the center and r is the radius\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample:\u003c/b\u003e\u003c/p\u003e\u003cp\u003eInput: Points = [1 0 ; 0 -1 ; 0 1]\u003c/p\u003e\u003cp\u003eOutput: [ 0 0 1]\u003c/p\u003e\u003cp\u003e\u003cb\u003eTheory/Hint:\u003c/b\u003e The Kasa method provides a best fit circle to a set of points.\u003c/p\u003e\u003cp\u003e\u003cb\u003eFuture:\u003c/b\u003e 1) Circumscribe 4 points  2) Circumscribe N points  3) The Great Lego Cup Challenge\u003c/p\u003e","function_template":"function [xc,yc,r]=find_circle(pts)\r\n xc=0;\r\n yc=0;\r\n r=1;\r\n\r\n","test_suite":"%%\r\nfor tests=1:5\r\n xc_truth=randn;\r\n yc_truth=randn;\r\n r_truth=rand;\r\n rand_ang=randi(360,3,1)+rand(3,1); % Avoid duplicate location via rand(3,1)\r\n pts=[xc_truth+r_truth*cosd(rand_ang) yc_truth+r_truth*sind(rand_ang)]; \r\n\r\n [xc,yc,r]=find_circle(pts);\r\n\r\n %dif=[xc yc r]-[xc_truth yc_truth r_truth]\r\n\r\n assert(max(abs([xc,yc,r]-[xc_truth,yc_truth,r_truth]))\u003c1e-6,...\r\nsprintf('Expect xc %.2f yc %.2f r %.2f  Ans:%.2f %.2f %.2f',...\r\n  xc_truth,yc_truth,r_truth,xc,yc,r))\r\nend","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":64,"test_suite_updated_at":"2017-02-24T17:19:01.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-03-10T17:26:14.000Z","updated_at":"2026-02-16T11:13:15.000Z","published_at":"2013-03-10T18:03:52.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\u003eThis Challenge is to determine the center and radius of a circle given three non-colinear points.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Points\u003c/w:t\u003e\u003c/w:r\u003e\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 [xc, yc, r] where [xc,yc] are the center and r is the radius\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput: Points = [1 0 ; 0 -1 ; 0 1]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput: [ 0 0 1]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTheory/Hint:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e The Kasa method provides a best fit circle to a set of points.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eFuture:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 1) Circumscribe 4 points 2) Circumscribe N points 3) The Great Lego Cup Challenge\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":567,"title":"Crossing to Kissing - Untangle the Lines","description":"Turn lines that cross into lines that kiss.\r\n\r\nYou will be given two lines that cross at some point. Your job is to untangle them in the following way. Imagine two line segments, L1 and L2. L1 goes from (0,0) to (2,2). L2 goes from (0,1) to (2,1). We can specify them like so.\r\n\r\n L1 = [0 0; \r\n       2 2]\r\n\r\n L2 = [0 1; \r\n       2 1]\r\n\r\nWe want to transform these into two non-crossing segmented lines that look the same when plotted. To do this, we need to introduce a new point in each line. Both lines share this point, so now they \"kiss\" instead of crossing.\r\n\r\n L3 = [0 0; \r\n       1 1;\r\n       2 1]\r\n\r\n L4 = [0 1;\r\n       1 1;\r\n       2 2]\r\n\r\n            * L1               * L4\r\n           /                  /\r\n          /                  /\r\n   L2 *--/--* L2      L4 *--*--* L3\r\n        /                  /\r\n       /                  /\r\n   L1 *               L3 *\r\n\r\nYour function should take the form\r\n\r\n [L3,L4] = cross2kiss(L1,L2)\r\n\r\nThe lines L3 and L4 should be ordered by the y coordinate of their first point. So in the case above, the first point in L3 is [0 0], so it comes first.","description_html":"\u003cp\u003eTurn lines that cross into lines that kiss.\u003c/p\u003e\u003cp\u003eYou will be given two lines that cross at some point. Your job is to untangle them in the following way. Imagine two line segments, L1 and L2. L1 goes from (0,0) to (2,2). L2 goes from (0,1) to (2,1). We can specify them like so.\u003c/p\u003e\u003cpre\u003e L1 = [0 0; \r\n       2 2]\u003c/pre\u003e\u003cpre\u003e L2 = [0 1; \r\n       2 1]\u003c/pre\u003e\u003cp\u003eWe want to transform these into two non-crossing segmented lines that look the same when plotted. To do this, we need to introduce a new point in each line. Both lines share this point, so now they \"kiss\" instead of crossing.\u003c/p\u003e\u003cpre\u003e L3 = [0 0; \r\n       1 1;\r\n       2 1]\u003c/pre\u003e\u003cpre\u003e L4 = [0 1;\r\n       1 1;\r\n       2 2]\u003c/pre\u003e\u003cpre\u003e            * L1               * L4\r\n           /                  /\r\n          /                  /\r\n   L2 *--/--* L2      L4 *--*--* L3\r\n        /                  /\r\n       /                  /\r\n   L1 *               L3 *\u003c/pre\u003e\u003cp\u003eYour function should take the form\u003c/p\u003e\u003cpre\u003e [L3,L4] = cross2kiss(L1,L2)\u003c/pre\u003e\u003cp\u003eThe lines L3 and L4 should be ordered by the y coordinate of their first point. So in the case above, the first point in L3 is [0 0], so it comes first.\u003c/p\u003e","function_template":"function [L3,L4] = cross2kiss(L1,L2);\r\n  L3 = 0;\r\n  L4 = 0;\r\nend","test_suite":"%%\r\nL1 =  [0 0; \r\n       2 2];\r\nL2 =  [0 1;\r\n       2 1];\r\n[L3,L4] = cross2kiss(L1,L2);\r\nL3c = [0 0; \r\n       1 1;\r\n       2 1]\r\nL4c = [0 1;\r\n       1 1;\r\n       2 2]\r\nassert(isequal(L3,L3c))\r\nassert(isequal(L4,L4c))\r\n\r\n%%\r\nL1 =  [-2 -1; \r\n        2  1];\r\nL2 =  [-1  1;\r\n        1 -1];\r\n[L3,L4] = cross2kiss(L1,L2);\r\nL3c =  [-2 -1; \r\n         0  0;\r\n         1 -1];\r\nL4c =  [-1  1;\r\n         0  0;\r\n         2  1];\r\nassert(isequal(L3,L3c))\r\nassert(isequal(L4,L4c))\r\n\r\n%%\r\nL1 =  [ 5  5; \r\n        8 -4];\r\nL2 =  [ 5 -2;\r\n        9  0];\r\n[L3,L4] = cross2kiss(L1,L2);\r\nL3c =  [ 5 -2;\r\n         7 -1;\r\n         8 -4];\r\nL4c =  [ 5  5; \r\n         7 -1;\r\n         9  0];\r\nassert(isequal(L3,L3c))\r\nassert(isequal(L4,L4c))\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":7,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":34,"test_suite_updated_at":"2012-12-18T16:37:17.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2012-04-09T22:07:02.000Z","updated_at":"2026-02-16T11:19:24.000Z","published_at":"2012-12-18T16:31:46.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\u003eTurn lines that cross into lines that kiss.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou will be given two lines that cross at some point. Your job is to untangle them in the following way. Imagine two line segments, L1 and L2. L1 goes from (0,0) to (2,2). L2 goes from (0,1) to (2,1). We can specify them like so.\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[ L1 = [0 0; \\n       2 2]\\n\\n L2 = [0 1; \\n       2 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\u003eWe want to transform these into two non-crossing segmented lines that look the same when plotted. To do this, we need to introduce a new point in each line. Both lines share this point, so now they \\\"kiss\\\" instead of crossing.\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[ L3 = [0 0; \\n       1 1;\\n       2 1]\\n\\n L4 = [0 1;\\n       1 1;\\n       2 2]\\n\\n            * L1               * L4\\n           /                  /\\n          /                  /\\n   L2 *--/--* L2      L4 *--*--* L3\\n        /                  /\\n       /                  /\\n   L1 *               L3 *]]\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\u003eYour function should take the form\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[ [L3,L4] = cross2kiss(L1,L2)]]\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 lines L3 and L4 should be ordered by the y coordinate of their first point. So in the case above, the first point in L3 is [0 0], so it comes first.\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":1446,"title":"Minimum Distance Point to Segment","description":"This Challenge is to determine the minimum distance from a 2-D line segment defined by two points to a point.\r\n\r\nThe point is (px,py) and the segment is [(vx,vy) to (wx,wy)].\r\n\r\nInput are the three defining points and the output is distance.\r\n\r\n*Input (px py vx vy wx wy):*   1 1 0 3 3 0\r\n\r\n*Output distance:* .7071\r\n\r\nPoint is beyond perpendicular to segment.\r\n\r\n*Input (px py vx vy wx wy):*   4 3 -100 0 0 0\r\n\r\n*Output distance:* 5\r\n\r\n\r\nFollow Up Challenges:\r\n\r\n1) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1452-minimum-distance-between-two-n-sided-polygons Minimum distance between non-contiguous N-sided polygons\u003e\r\n\r\n2) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1457-usc-spring-2013-acm-walking-on-thin-ice USC Spring 2013 ACM: Walking on Thin Ice\u003e\r\n\r\n","description_html":"\u003cp\u003eThis Challenge is to determine the minimum distance from a 2-D line segment defined by two points to a point.\u003c/p\u003e\u003cp\u003eThe point is (px,py) and the segment is [(vx,vy) to (wx,wy)].\u003c/p\u003e\u003cp\u003eInput are the three defining points and the output is distance.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput (px py vx vy wx wy):\u003c/b\u003e   1 1 0 3 3 0\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput distance:\u003c/b\u003e .7071\u003c/p\u003e\u003cp\u003ePoint is beyond perpendicular to segment.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput (px py vx vy wx wy):\u003c/b\u003e   4 3 -100 0 0 0\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput distance:\u003c/b\u003e 5\u003c/p\u003e\u003cp\u003eFollow Up Challenges:\u003c/p\u003e\u003cp\u003e1) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1452-minimum-distance-between-two-n-sided-polygons\"\u003eMinimum distance between non-contiguous N-sided polygons\u003c/a\u003e\u003c/p\u003e\u003cp\u003e2) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1457-usc-spring-2013-acm-walking-on-thin-ice\"\u003eUSC Spring 2013 ACM: Walking on Thin Ice\u003c/a\u003e\u003c/p\u003e","function_template":"function d=distP2S(px,py,vx,vy,wx,wy)\r\n% segment defined by (vx,vy) to (wx,wy)\r\n% [px py vx vy wx wy]\r\n d=0;\r\nend","test_suite":"%%\r\np=[0 0];\r\nv=[1 -1];\r\nw=[1 1];\r\nd=distP2S(p(1),p(2),v(1),v(2),w(1),w(2));\r\nassert(abs(d-1)\u003c.005)\r\n\r\n%%\r\np=[0 0];\r\nv=[-1 2];\r\nw=[1 2];\r\nd=distP2S(p(1),p(2),v(1),v(2),w(1),w(2));\r\nassert(abs(d-2)\u003c.005)\r\n\r\n%%\r\np=[0 0];\r\nv=[-1 -1];\r\nw=[1 1];\r\nd=distP2S(p(1),p(2),v(1),v(2),w(1),w(2));\r\nassert(abs(d)\u003c.005)\r\n\r\n%%\r\np=[1 1];\r\nv=[0 3];\r\nw=[3 0];\r\nd=distP2S(p(1),p(2),v(1),v(2),w(1),w(2));\r\nassert(abs(d-1/2^.5)\u003c.005)\r\n\r\n%%\r\np=[5 0];\r\nv=[0 3];\r\nw=[3 0];\r\nd=distP2S(p(1),p(2),v(1),v(2),w(1),w(2));\r\nassert(abs(d-2)\u003c.005)\r\n\r\n%%\r\np=[0 6];\r\nv=[0 3];\r\nw=[3 0];\r\nd=distP2S(p(1),p(2),v(1),v(2),w(1),w(2));\r\nassert(abs(d-3)\u003c.005)\r\n\r\n%%\r\np=[-4 0];\r\nv=[0 3];\r\nw=[-3 0];\r\nd=distP2S(p(1),p(2),v(1),v(2),w(1),w(2))\r\nassert(abs(d-1)\u003c.005)\r\n\r\n%%\r\np=[1 0];\r\nv=[1.01 0];\r\nw=[5 5];\r\nd=distP2S(p(1),p(2),v(1),v(2),w(1),w(2))\r\nassert(abs(d-.01)\u003c.005)","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":62,"test_suite_updated_at":"2018-07-20T15:16:15.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-23T02:10:21.000Z","updated_at":"2026-02-16T10:58:16.000Z","published_at":"2013-04-23T02:45:32.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis Challenge is to determine the minimum distance from a 2-D line segment defined by two points to a point.\u003c/w:t\u003e\u003c/w:r\u003e\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 point is (px,py) and the segment is [(vx,vy) to (wx,wy)].\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eInput are the three defining points and the output is distance.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput (px py vx vy wx wy):\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 1 1 0 3 3 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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput distance:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e .7071\u003c/w:t\u003e\u003c/w:r\u003e\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\u003ePoint is beyond perpendicular to segment.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput (px py vx vy wx wy):\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 4 3 -100 0 0 0\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput distance:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFollow Up Challenges:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1452-minimum-distance-between-two-n-sided-polygons\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eMinimum distance between non-contiguous N-sided polygons\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1457-usc-spring-2013-acm-walking-on-thin-ice\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eUSC Spring 2013 ACM: Walking on Thin Ice\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1428,"title":"Find the optimal shape to bring the maximum product by a given perimeter","description":"Find the optimal shape (with Nopt sides, where Nopt is at least 3) to bring the maximum product of the sides length, given a specified perimeter.\r\n\r\nExample:\r\nAssuming perimeter equals to 7 (p=7) then the known optimal value is Nopt=3 (a triangle, so 3 sides).\r\n  let mark L1,L2,L3 the triangle sides length (L1+L2+L3=7), thus the product is L1*L2*L3 and we want the product to be as large as possible for your chosen number of sides Nopt.\r\n\r\nDon't assume the perimeter is an integer. The side lengths need not be integers, although it is possible they might be so. And of course, you need to decide if the optimum happens for an equilateral polygon, so with equal side lengths, or if some other set of side lengths that collectively sum to p might be a better choice.\r\n\r\n\u003chttps://docs.google.com/file/d/0B-d0Lx2W7Gsma0F6LS1TbjB6dm8/edit?usp=sharing Illustrate Link\u003e\r\n\r\nDifficulty level on a scale 1 to 10:  *8* \r\n","description_html":"\u003cp\u003eFind the optimal shape (with Nopt sides, where Nopt is at least 3) to bring the maximum product of the sides length, given a specified perimeter.\u003c/p\u003e\u003cp\u003eExample:\r\nAssuming perimeter equals to 7 (p=7) then the known optimal value is Nopt=3 (a triangle, so 3 sides).\r\n  let mark L1,L2,L3 the triangle sides length (L1+L2+L3=7), thus the product is L1*L2*L3 and we want the product to be as large as possible for your chosen number of sides Nopt.\u003c/p\u003e\u003cp\u003eDon't assume the perimeter is an integer. The side lengths need not be integers, although it is possible they might be so. And of course, you need to decide if the optimum happens for an equilateral polygon, so with equal side lengths, or if some other set of side lengths that collectively sum to p might be a better choice.\u003c/p\u003e\u003cp\u003e\u003ca href = \"https://docs.google.com/file/d/0B-d0Lx2W7Gsma0F6LS1TbjB6dm8/edit?usp=sharing\"\u003eIllustrate Link\u003c/a\u003e\u003c/p\u003e\u003cp\u003eDifficulty level on a scale 1 to 10:  \u003cb\u003e8\u003c/b\u003e\u003c/p\u003e","function_template":"function [Nopt,prd] = max_product(p)\r\n  % p is the given perimeter\r\n  \r\n  % Nopt - number of sides(optimal)to bring the product to max\r\n  % prd - is that maximum product\r\n\r\nend","test_suite":"%%\r\np = 5;\r\n[Nopt,prd] = max_product(p);\r\nassert(isequal(Nopt,3))\r\nassert(abs(prd - 4.62962962962963)/4.62962962962963 \u003c 1e-13)\r\n\r\n%%\r\np = 10;\r\n[Nopt,prd] = max_product(p);\r\nassert(isequal(Nopt,4))\r\nassert(abs(prd - 39.0625)/39.0625 \u003c 1e-13)\r\n\r\n%%\r\np = 17.5;\r\n[Nopt,prd] = max_product(p);\r\nassert(isequal(Nopt,6))\r\nassert(abs(prd - 615.631438413601)/615.631438413601 \u003c 1e-13)\r\n\r\n%%\r\np = 29;\r\n[Nopt,prd] = max_product(p);\r\nassert(isequal(Nopt,11))\r\nassert(abs(prd - 4.276204243443044e+04)/4.276204243443044e+04 \u003c 1e-13)\r\n\r\n%%\r\np = 49;\r\n[Nopt,prd] = max_product(p);\r\nassert(isequal(Nopt,18))\r\nassert(abs(prd - 6.739448339947788e+07)/6.739448339947788e+07 \u003c 1e-13)\r\n\r\n%%\r\np = 256;\r\n[Nopt,prd] = max_product(p);\r\nassert(isequal(Nopt,94))\r\nassert(abs(prd - 7.953137683223010e+40)/7.953137683223010e+40 \u003c 1e-13)\r\n\r\n%%\r\np = 1000000;\r\n[Nopt,prd] = max_product(p);\r\nassert(isequal(Nopt,367879))\r\nassert(isinf(prd))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":10,"created_by":12871,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":45,"test_suite_updated_at":"2018-03-26T21:41:39.000Z","rescore_all_solutions":true,"group_id":20,"created_at":"2013-04-15T10:19:39.000Z","updated_at":"2026-02-16T11:04:21.000Z","published_at":"2013-04-16T17:10:41.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 the optimal shape (with Nopt sides, where Nopt is at least 3) to bring the maximum product of the sides length, given a specified perimeter.\u003c/w:t\u003e\u003c/w:r\u003e\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: Assuming perimeter equals to 7 (p=7) then the known optimal value is Nopt=3 (a triangle, so 3 sides). let mark L1,L2,L3 the triangle sides length (L1+L2+L3=7), thus the product is L1*L2*L3 and we want the product to be as large as possible for your chosen number of sides Nopt.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eDon't assume the perimeter is an integer. The side lengths need not be integers, although it is possible they might be so. And of course, you need to decide if the optimum happens for an equilateral polygon, so with equal side lengths, or if some other set of side lengths that collectively sum to p might be a better choice.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://docs.google.com/file/d/0B-d0Lx2W7Gsma0F6LS1TbjB6dm8/edit?usp=sharing\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eIllustrate Link\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDifficulty level on a scale 1 to 10: \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\u003e8\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":1459,"title":"Triangular Tiling Dots in a Circle","description":"Return how many \u003chttp://en.wikipedia.org/wiki/Triangular_tiling Triangular Tiling\u003e grid points there are inside a circle of radius _r_ centred at (0,0) (including points on the edge).  \r\n\r\nAssume that a Triangular Tiling grid is a \u003chttp://en.wikipedia.org/wiki/Bravais_lattice 2D Hexagonal Bravais lattice\u003e with | _a1_ | = | _a2_ | = 1 and _\u0026phi;_ = 120\u0026deg;.\r\n\r\nNeither *string operations* nor *interpolations* are allowed!","description_html":"\u003cp\u003eReturn how many \u003ca href = \"http://en.wikipedia.org/wiki/Triangular_tiling\"\u003eTriangular Tiling\u003c/a\u003e grid points there are inside a circle of radius \u003ci\u003er\u003c/i\u003e centred at (0,0) (including points on the edge).\u003c/p\u003e\u003cp\u003eAssume that a Triangular Tiling grid is a \u003ca href = \"http://en.wikipedia.org/wiki/Bravais_lattice\"\u003e2D Hexagonal Bravais lattice\u003c/a\u003e with | \u003ci\u003ea1\u003c/i\u003e | = | \u003ci\u003ea2\u003c/i\u003e | = 1 and \u003ci\u003e\u0026phi;\u003c/i\u003e = 120\u0026deg;.\u003c/p\u003e\u003cp\u003eNeither \u003cb\u003estring operations\u003c/b\u003e nor \u003cb\u003einterpolations\u003c/b\u003e are allowed!\u003c/p\u003e","function_template":"function n = hexagonal_dots_in_circle(r)\r\n  n = r;\r\nend","test_suite":"%%\r\nuser_solution = fileread('hexagonal_dots_in_circle.m');\r\nassert(isempty(strfind(user_solution,'regexp')));\r\nassert(isempty(strfind(user_solution,'2str')));\r\nassert(isempty(strfind(user_solution,'str2')));\r\nassert(isempty(strfind(user_solution,'interp')));\r\nassert(isempty(strfind(user_solution,'printf')));\r\nassert(isempty(strfind(user_solution,'assert')));\r\n\r\n%%\r\nr = 0;\r\nn_correct = 1;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 0.5;\r\nn_correct = 1;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 1;\r\nn_correct = 7;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 1.5;\r\nn_correct = 7;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 2;\r\nn_correct = 19;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 2.5;\r\nn_correct = 19;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 3;\r\nn_correct = 37;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 5;\r\nn_correct = 91;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 7.5;\r\nn_correct = 199;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 10;\r\nn_correct = 367;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 15;\r\nn_correct = 823;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 20;\r\nn_correct = 1459;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 25;\r\nn_correct = 2263;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 50;\r\nn_correct = 9061;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 100;\r\nn_correct = 36295;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n ","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":10352,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":32,"test_suite_updated_at":"2013-05-05T10:49:55.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-25T18:57:26.000Z","updated_at":"2026-02-16T10:52:57.000Z","published_at":"2013-04-25T18:57:26.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\u003eReturn how many\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Triangular_tiling\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eTriangular Tiling\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e grid points there are inside a circle of radius\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003er\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e centred at (0,0) (including points on the edge).\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eAssume that a Triangular Tiling grid is a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Bravais_lattice\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2D Hexagonal Bravais lattice\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e with |\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ea1\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:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ea2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e | = 1 and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eφ\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e = 120°.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNeither\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\u003estring operations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e nor\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\u003einterpolations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are allowed!\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":1490,"title":"Shifted Hexagonal Tiling Dots in a Circle","description":"Return how many \u003chttp://en.wikipedia.org/wiki/Hexagonal_grid Hexagonal Tiling\u003e grid points there are inside a circle of radius _r_ centred at (0,0) (including points on the edge).  Assume that a Hexagonal Tiling grid is a \u003chttp://en.wikipedia.org/wiki/Regular_tiling 2D Regular Hexagonal Tessellation\u003e with equal edges of size _e_=1.  \r\n\r\nFor _shifted_ symmetry purposes, assume that (0,0) is a _grid point_.\r\n\r\nNeither *string operations* nor *interpolations* are allowed!","description_html":"\u003cp\u003eReturn how many \u003ca href = \"http://en.wikipedia.org/wiki/Hexagonal_grid\"\u003eHexagonal Tiling\u003c/a\u003e grid points there are inside a circle of radius \u003ci\u003er\u003c/i\u003e centred at (0,0) (including points on the edge).  Assume that a Hexagonal Tiling grid is a \u003ca href = \"http://en.wikipedia.org/wiki/Regular_tiling\"\u003e2D Regular Hexagonal Tessellation\u003c/a\u003e with equal edges of size \u003ci\u003ee\u003c/i\u003e=1.\u003c/p\u003e\u003cp\u003eFor \u003ci\u003eshifted\u003c/i\u003e symmetry purposes, assume that (0,0) is a \u003ci\u003egrid point\u003c/i\u003e.\u003c/p\u003e\u003cp\u003eNeither \u003cb\u003estring operations\u003c/b\u003e nor \u003cb\u003einterpolations\u003c/b\u003e are allowed!\u003c/p\u003e","function_template":"function n = shifted_hexagonal_tiling_dots_in_circle(r)\r\n  n = r;\r\nend","test_suite":"%%\r\nuser_solution = fileread('shifted_hexagonal_tiling_dots_in_circle.m');\r\nassert(isempty(strfind(user_solution,'regexp')));\r\nassert(isempty(strfind(user_solution,'2str')));\r\nassert(isempty(strfind(user_solution,'str2')));\r\nassert(isempty(strfind(user_solution,'interp')));\r\nassert(isempty(strfind(user_solution,'printf')));\r\nassert(isempty(strfind(user_solution,'assert')));\r\n\r\n%%\r\nr = 0;\r\nN_correct = 1;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 0.5;\r\nN_correct = 1;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 1;\r\nN_correct = 4;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 1.5;\r\nN_correct = 4;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 2;\r\nN_correct = 13;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 2.5;\r\nN_correct = 13;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 3;\r\nN_correct = 25;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 5;\r\nN_correct = 61;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 7.5;\r\nN_correct = 130;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 10;\r\nN_correct = 244;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 15;\r\nN_correct = 547;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 20;\r\nN_correct = 979;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 25;\r\nN_correct = 1510;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 50;\r\nN_correct = 6049;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 100;\r\nN_correct = 24202;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":10352,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":20,"created_at":"2013-05-05T11:12:35.000Z","updated_at":"2026-02-16T10:46:10.000Z","published_at":"2013-05-05T11:13:56.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eReturn how many\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Hexagonal_grid\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eHexagonal Tiling\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e grid points there are inside a circle of radius\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003er\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e centred at (0,0) (including points on the edge). Assume that a Hexagonal Tiling grid is a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Regular_tiling\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2D Regular Hexagonal Tessellation\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e with equal edges 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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ee\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e=1.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eshifted\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e symmetry purposes, assume that (0,0) is a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003egrid point\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\u003eNeither\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\u003estring operations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e nor\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\u003einterpolations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are allowed!\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":1489,"title":"Hexagonal Tiling Dots in a Circle","description":"Return how many \u003chttp://en.wikipedia.org/wiki/Hexagonal_grid Hexagonal Tiling\u003e grid points there are inside a circle of radius _r_ centred at (0,0) (including points on the edge).  Assume that a Hexagonal Tiling grid is a \u003chttp://en.wikipedia.org/wiki/Regular_tiling 2D Regular Hexagonal Tessellation\u003e with equal edges of size _e_=1.  \r\n\r\nFor symmetry purposes, assume that (0,0) point is a _vacancy_; i.e., there _are_ points at (\u0026plusmn;1,0), (\u0026plusmn;1/2,\u0026plusmn;\u0026radic;3/2), etcetera.\r\n\r\nNeither *string operations* nor *interpolations* are allowed!","description_html":"\u003cp\u003eReturn how many \u003ca href = \"http://en.wikipedia.org/wiki/Hexagonal_grid\"\u003eHexagonal Tiling\u003c/a\u003e grid points there are inside a circle of radius \u003ci\u003er\u003c/i\u003e centred at (0,0) (including points on the edge).  Assume that a Hexagonal Tiling grid is a \u003ca href = \"http://en.wikipedia.org/wiki/Regular_tiling\"\u003e2D Regular Hexagonal Tessellation\u003c/a\u003e with equal edges of size \u003ci\u003ee\u003c/i\u003e=1.\u003c/p\u003e\u003cp\u003eFor symmetry purposes, assume that (0,0) point is a \u003ci\u003evacancy\u003c/i\u003e; i.e., there \u003ci\u003eare\u003c/i\u003e points at (\u0026plusmn;1,0), (\u0026plusmn;1/2,\u0026plusmn;\u0026radic;3/2), etcetera.\u003c/p\u003e\u003cp\u003eNeither \u003cb\u003estring operations\u003c/b\u003e nor \u003cb\u003einterpolations\u003c/b\u003e are allowed!\u003c/p\u003e","function_template":"function n = hexagonal_tiling_dots_in_circle(r)\r\n  n = r;\r\nend","test_suite":"%%\r\nuser_solution = fileread('hexagonal_tiling_dots_in_circle.m');\r\nassert(isempty(strfind(user_solution,'regexp')));\r\nassert(isempty(strfind(user_solution,'2str')));\r\nassert(isempty(strfind(user_solution,'str2')));\r\nassert(isempty(strfind(user_solution,'interp')));\r\nassert(isempty(strfind(user_solution,'printf')));\r\nassert(isempty(strfind(user_solution,'assert')));\r\n\r\n%%\r\nr = 0;\r\nN_correct = 0;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 0.5;\r\nN_correct = 0;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 1;\r\nN_correct = 6;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 1.5;\r\nN_correct = 6;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 2;\r\nN_correct = 12;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 2.5;\r\nN_correct = 12;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 3;\r\nN_correct = 24;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 5;\r\nN_correct = 60;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 7.5;\r\nN_correct = 138;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 10;\r\nN_correct = 246;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 15;\r\nN_correct = 552;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 20;\r\nN_correct = 960;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 25;\r\nN_correct = 1506;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 50;\r\nN_correct = 6024;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 100;\r\nN_correct = 24186;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":10352,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":29,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":20,"created_at":"2013-05-05T10:39:46.000Z","updated_at":"2026-03-25T00:01:03.000Z","published_at":"2013-05-05T10:54:39.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn how many\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Hexagonal_grid\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eHexagonal Tiling\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e grid points there are inside a circle of radius\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003er\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e centred at (0,0) (including points on the edge). Assume that a Hexagonal Tiling grid is a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Regular_tiling\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2D Regular Hexagonal Tessellation\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e with equal edges 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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ee\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e=1.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor symmetry purposes, assume that (0,0) point is a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003evacancy\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e; i.e., there\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eare\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e points at (±1,0), (±1/2,±√3/2), etcetera.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eNeither\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\u003estring operations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e nor\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\u003einterpolations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are allowed!\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":1283,"title":"Points on a Sphere","description":"Given a sphere of radius R, determine how many points on the surface of that sphere have three integer coordinates.  Do not output the actual coordinates, but just the number of points.\r\n\r\nFor example, a sphere of radius 1 has 6 points with three integer coordinates:\r\n\r\n* (1,0,0)\r\n* (-1,0,0)\r\n* (0,-1,0)\r\n* (0,1,0)\r\n* (0,0,1)\r\n* (0,0,-1)\r\n\r\nYour output of surface_points(1) would be 6.  Good luck!","description_html":"\u003cp\u003eGiven a sphere of radius R, determine how many points on the surface of that sphere have three integer coordinates.  Do not output the actual coordinates, but just the number of points.\u003c/p\u003e\u003cp\u003eFor example, a sphere of radius 1 has 6 points with three integer coordinates:\u003c/p\u003e\u003cul\u003e\u003cli\u003e(1,0,0)\u003c/li\u003e\u003cli\u003e(-1,0,0)\u003c/li\u003e\u003cli\u003e(0,-1,0)\u003c/li\u003e\u003cli\u003e(0,1,0)\u003c/li\u003e\u003cli\u003e(0,0,1)\u003c/li\u003e\u003cli\u003e(0,0,-1)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eYour output of surface_points(1) would be 6.  Good luck!\u003c/p\u003e","function_template":"function y = surface_points(r)\r\ny=6;\r\nend","test_suite":"%%\r\nx = 1; y_correct = 6;\r\nassert(isequal(surface_points(x),y_correct))\r\n%%\r\nx = 1024; y_correct = 6;\r\nassert(isequal(surface_points(x),y_correct))\r\n%%\r\nx = 7581; y_correct = 108270;\r\nassert(isequal(surface_points(x),y_correct))\r\n%%\r\nx = 450; y_correct = 2550;\r\nassert(isequal(surface_points(x),y_correct))\r\n%%\r\nx = 123456; y_correct = 19350;\r\nassert(isequal(surface_points(x),y_correct))\r\n%%\r\nx=ceil(rand*8); y_correct=[6 30 30 150 510 4590 4590 43470];\r\nassert(isequal(surface_points(factorial(x+1)),y_correct(x)))","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":26,"test_suite_updated_at":"2013-02-22T17:25:38.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-02-20T16:48:12.000Z","updated_at":"2026-02-16T11:16:05.000Z","published_at":"2013-02-20T16:49:36.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a sphere of radius R, determine how many points on the surface of that sphere have three integer coordinates. Do not output the actual coordinates, but just the number of points.\u003c/w:t\u003e\u003c/w:r\u003e\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 example, a sphere of radius 1 has 6 points with three integer coordinates:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(1,0,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\u003e(-1,0,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\u003e(0,-1,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\u003e(0,1,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\u003e(0,0,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\u003e(0,0,-1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour output of surface_points(1) would be 6. 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":1452,"title":"Minimum Distance between two N-sided Polygons","description":"This Challenge is to determine the minimum distance between two non-overlapping polygons. The input is a cell array of two vectors that represent the sequential points of 3 to 100 sided polygons. [x0 y0 x1 y1 ... xn yn]\r\n\r\n*Input:* polycell={[0 0 0 5 4 5 4 0] [2.5 5.5 3 9 -2 5.6]};\r\n\r\n*Output:* 0.5  \r\n\r\n\r\nRelated Challenges:\r\n\r\n1) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1446-minimum-distance-point-to-segment Minimum Distance Point to Segment\u003e\r\n\r\n2) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1457-usc-spring-2013-acm-walking-on-thin-ice USC Spring 2013 ACM Walking on Thin Ice\u003e","description_html":"\u003cp\u003eThis Challenge is to determine the minimum distance between two non-overlapping polygons. The input is a cell array of two vectors that represent the sequential points of 3 to 100 sided polygons. [x0 y0 x1 y1 ... xn yn]\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e polycell={[0 0 0 5 4 5 4 0] [2.5 5.5 3 9 -2 5.6]};\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e 0.5\u003c/p\u003e\u003cp\u003eRelated Challenges:\u003c/p\u003e\u003cp\u003e1) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1446-minimum-distance-point-to-segment\"\u003eMinimum Distance Point to Segment\u003c/a\u003e\u003c/p\u003e\u003cp\u003e2) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1457-usc-spring-2013-acm-walking-on-thin-ice\"\u003eUSC Spring 2013 ACM Walking on Thin Ice\u003c/a\u003e\u003c/p\u003e","function_template":"function pdistmin=PolytoPol(polycell)\r\n% Convert [x0 y0 x1 y1 ... xn yn] to nx2 array\r\n% Length of polycell{1} may vary from polycell{2}\r\n p1=reshape(polycell{1},2,[])';\r\n p2=reshape(polycell{2},2,[])';\r\n \r\n pdistmin=0;\r\nend","test_suite":"polycell={[0 0 5 10 10 0] [5 -1 6 -5 5 -5]};\r\np2p_min=PolytoPol(polycell);\r\nassert(abs(p2p_min-1)\u003c.01);\r\n%%\r\npolycell={[0 0 0 5 4 5 4 0] [2.5 5.5 3 9 -2 5.6]};\r\np2p_min=PolytoPol(polycell);\r\nassert(abs(p2p_min-0.5)\u003c.01);\r\n%%\r\npolycell={[0 10 0 90 50 50 100 90 100 10] [0 110 100 110 50 70]};\r\np2p_min=PolytoPol(polycell);\r\nassert(abs(p2p_min-15.617376)\u003c.01);\r\n%%\r\npolycell={[0 110 100 110 50 70] [20 5 50 7 30 5]};\r\np2p_min=PolytoPol(polycell);\r\nassert(abs(p2p_min-63)\u003c.01);\r\n%%\r\npolycell={[-5 -5 -4 -4 -3 -3 -2 -2 5 5 5 0] [6 10 6 -10 20 0]};\r\np2p_min=PolytoPol(polycell);\r\nassert(abs(p2p_min-1)\u003c.01);\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":27,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-24T01:39:41.000Z","updated_at":"2026-02-16T10:57:04.000Z","published_at":"2013-04-24T02:03:10.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis Challenge is to determine the minimum distance between two non-overlapping polygons. The input is a cell array of two vectors that represent the sequential points of 3 to 100 sided polygons. [x0 y0 x1 y1 ... xn yn]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e polycell={[0 0 0 5 4 5 4 0] [2.5 5.5 3 9 -2 5.6]};\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\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 0.5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRelated Challenges:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1446-minimum-distance-point-to-segment\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eMinimum Distance Point to Segment\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1457-usc-spring-2013-acm-walking-on-thin-ice\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eUSC Spring 2013 ACM Walking on Thin Ice\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1493,"title":"Dots in a Diamond","description":"Return how many \u003chttp://en.wikipedia.org/wiki/Diamond_cubic Diamond Cubic\u003e lattice grid points there are inside a 3D sphere of radius _r_ centred at (0,0,0) (including points on the edge).  \r\n\r\nSet the distance between two adjacent lattice grid points to be _e_ =1. In addition, assume that (0,0,0) is a grid point.\r\n\r\nNeither *string operations* nor *interpolations* are allowed!","description_html":"\u003cp\u003eReturn how many \u003ca href = \"http://en.wikipedia.org/wiki/Diamond_cubic\"\u003eDiamond Cubic\u003c/a\u003e lattice grid points there are inside a 3D sphere of radius \u003ci\u003er\u003c/i\u003e centred at (0,0,0) (including points on the edge).\u003c/p\u003e\u003cp\u003eSet the distance between two adjacent lattice grid points to be \u003ci\u003ee\u003c/i\u003e =1. In addition, assume that (0,0,0) is a grid point.\u003c/p\u003e\u003cp\u003eNeither \u003cb\u003estring operations\u003c/b\u003e nor \u003cb\u003einterpolations\u003c/b\u003e are allowed!\u003c/p\u003e","function_template":"function n = dots_in_diamond(r)\r\n  n = r;\r\nend","test_suite":"%%\r\nuser_solution = fileread('dots_in_diamond.m');\r\nassert(isempty(strfind(user_solution,'regexp')));\r\nassert(isempty(strfind(user_solution,'2str')));\r\nassert(isempty(strfind(user_solution,'str2')));\r\nassert(isempty(strfind(user_solution,'interp')));\r\nassert(isempty(strfind(user_solution,'printf')));\r\nassert(isempty(strfind(user_solution,'assert')));\r\n\r\n%%\r\nr = 0;\r\nN_correct = 1;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 0.5;\r\nN_correct = 1;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 1;\r\nN_correct = 5;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 1.5;\r\nN_correct = 5;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 1.74;\r\nN_correct = 17;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 2;\r\nN_correct = 29;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 2.5;\r\nN_correct = 35;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 3;\r\nN_correct = 87;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 4;\r\nN_correct = 167;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 5;\r\nN_correct = 357;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 6;\r\nN_correct = 633;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 7;\r\nN_correct = 943;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 8;\r\nN_correct = 1371;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 9;\r\nN_correct = 1963;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 10;\r\nN_correct = 2809;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 12.5;\r\nN_correct = 5359;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 15;\r\nN_correct = 9249;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 17.5;\r\nN_correct = 14451;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 20;\r\nN_correct = 21777;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 22.5;\r\nN_correct = 31075;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 25;\r\nN_correct = 42509;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":10352,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":"2013-05-10T08:33:38.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-05-08T09:16:44.000Z","updated_at":"2026-02-16T10:39:28.000Z","published_at":"2013-05-08T09:58:42.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn how many\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Diamond_cubic\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDiamond Cubic\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e lattice grid points there are inside a 3D sphere of radius\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003er\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e centred at (0,0,0) (including points on the edge).\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eSet the distance between two adjacent lattice grid points to be\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ee\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e =1. In addition, assume that (0,0,0) is a grid point.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eNeither\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\u003estring operations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e nor\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\u003einterpolations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are allowed!\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":1387,"title":"Points on a circle.","description":"This problem is related to \u003curl=http://www.mathworks.com/matlabcentral/cody/problems/1283-points-on-a-sphere\u003eProblem 1283, Points on a Sphere.\u003e  In this case, instead of a sphere, you have a circle.  Given a radius R, calculate the number of points on the circumference of the circle that have two integer coordinates.  For a circle of radius 5, you would have 12 points:\r\n\r\n* (0, 5) and (0, -5)\r\n* (5, 0) and (-5, 0)\r\n* (4, 3) and (4, -3)\r\n* (-4, 3) and (-4, -3)\r\n* (3, 4) and (3, -4)\r\n* (-3, 4) and (-3, -4)\r\n\r\nSome radii are quite large, so watch out.  Good luck!","description_html":"\u003cp\u003eThis problem is related to \u003ca href = \"url=http://www.mathworks.com/matlabcentral/cody/problems/1283-points-on-a-sphere\u0026gt;Problem\"\u003e1283, Points on a Sphere.\u003c/a\u003e  In this case, instead of a sphere, you have a circle.  Given a radius R, calculate the number of points on the circumference of the circle that have two integer coordinates.  For a circle of radius 5, you would have 12 points:\u003c/p\u003e\u003cul\u003e\u003cli\u003e(0, 5) and (0, -5)\u003c/li\u003e\u003cli\u003e(5, 0) and (-5, 0)\u003c/li\u003e\u003cli\u003e(4, 3) and (4, -3)\u003c/li\u003e\u003cli\u003e(-4, 3) and (-4, -3)\u003c/li\u003e\u003cli\u003e(3, 4) and (3, -4)\u003c/li\u003e\u003cli\u003e(-3, 4) and (-3, -4)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eSome radii are quite large, so watch out.  Good luck!\u003c/p\u003e","function_template":"function y = circle_points(r)\r\n  y = r;\r\nend","test_suite":"%%\r\nassert(isequal(circle_points(1),4))\r\n%%\r\nassert(isequal(circle_points(3),4))\r\n%%\r\nassert(isequal(circle_points(5),12))\r\n%%\r\nassert(isequal(circle_points(65),36))\r\n%%\r\nassert(isequal(circle_points(64090),324))\r\n%%\r\nassert(isequal(circle_points(326441),12))\r\n%%\r\nassert(isequal(circle_points(359125),420))\r\n%%\r\nassert(isequal(circle_points(1000001),36))\r\n%%\r\nassert(isequal(circle_points(2417899275),20))\r\n%%\r\nassert(isequal(circle_points(31432690549),8748))\r\n%%\r\nassert(isequal(circle_points(11472932050385),78732))\r\n%%\r\nassert(isequal(circle_points(1021090952484265),236196))\r\n%%\r\nassert(isequal(circle_points(6095127531752228),78732))\r\n%%\r\nassert(isequal(circle_points(5*circle_points(630209)),12))\r\n%%\r\ny=arrayfun(@(x) circle_points(x),1000:2000);\r\n[m1,m2]=max(y);\r\nassert(isequal(m1-m2,2));\r\n[h1,h2]=hist(y,unique(y));\r\nassert(isequal(prod(h1-h2),1399066124544000))","published":true,"deleted":false,"likes_count":2,"comments_count":5,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":"2018-02-22T17:55:59.000Z","rescore_all_solutions":true,"group_id":20,"created_at":"2013-03-25T18:05:05.000Z","updated_at":"2026-02-16T11:09:55.000Z","published_at":"2013-03-25T18:44:35.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis problem is related to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"url=http://www.mathworks.com/matlabcentral/cody/problems/1283-points-on-a-sphere\u003eProblem\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1283, Points on a Sphere.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e In this case, instead of a sphere, you have a circle. Given a radius R, calculate the number of points on the circumference of the circle that have two integer coordinates. For a circle of radius 5, you would have 12 points:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(0, 5) and (0, -5)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(5, 0) and (-5, 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\u003e(4, 3) and (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\u003e(-4, 3) and (-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\u003e(3, 4) and (3, -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\u003e(-3, 4) and (-3, -4)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSome radii are quite large, so watch out. 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\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":1141,"title":"Volume difference between Ellipsoid and Sphere ","description":"Given an ellipsoid of semi  principal axis (a,b,c) find the volume of the difference between this ellipsoid and  the sphere within, round the result toward zero using the \"floor\" function. ","description_html":"\u003cp\u003eGiven an ellipsoid of semi  principal axis (a,b,c) find the volume of the difference between this ellipsoid and  the sphere within, round the result toward zero using the \"floor\" function.\u003c/p\u003e","function_template":"function y = ellipsoid_sphere_diff(a,b,c)\r\n  y = x;\r\nend","test_suite":"%%\r\na=2;b=2;c=8;\r\ny_correct = 100;\r\nassert(isequal(ellipsoid_sphere_diff(a,b,c),y_correct))\r\n%%\r\na=4;b=4;c=4;\r\ny_correct =0;\r\nassert(isequal(ellipsoid_sphere_diff(a,b,c),y_correct))\r\n%%\r\na=3;b=5;c=8;\r\ny_correct= 389;\r\nassert(isequal(ellipsoid_sphere_diff(a,b,c),y_correct))\r\n%%\r\na=4;b=6;c=8;\r\ny_correct=536;\r\nassert(isequal(ellipsoid_sphere_diff(a,b,c),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":5260,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":136,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":20,"created_at":"2012-12-25T23:34:50.000Z","updated_at":"2026-04-02T12:56:31.000Z","published_at":"2012-12-25T23:35: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\u003eGiven an ellipsoid of semi principal axis (a,b,c) find the volume of the difference between this ellipsoid and the sphere within, round the result toward zero using the \\\"floor\\\" function.\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":1442,"title":"Volume of a Simplex","description":"Return the volume of a \u003chttp://en.wikipedia.org/wiki/Simplex  regular _n_-simplex\u003e with a unit side length.\r\n\r\nResults are up to |4*eps| precision.\r\n\r\nNeither *string operations* nor *interpolations* are allowed!","description_html":"\u003cp\u003eReturn the volume of a \u003ca href = \"http://en.wikipedia.org/wiki/Simplex\"\u003eregular \u003ci\u003en\u003c/i\u003e-simplex\u003c/a\u003e with a unit side length.\u003c/p\u003e\u003cp\u003eResults are up to \u003ctt\u003e4*eps\u003c/tt\u003e precision.\u003c/p\u003e\u003cp\u003eNeither \u003cb\u003estring operations\u003c/b\u003e nor \u003cb\u003einterpolations\u003c/b\u003e are allowed!\u003c/p\u003e","function_template":"function V = simplexvolume(n)\r\n  V = n;\r\nend","test_suite":"user_solution = fileread('simplexvolume.m');\r\nassert(isempty(strfind(user_solution,'regexp')));\r\nassert(isempty(strfind(user_solution,'2str')));\r\nassert(isempty(strfind(user_solution,'str2')));\r\nassert(isempty(strfind(user_solution,'interp')));\r\nassert(isempty(strfind(user_solution,'printf')));\r\nassert(isempty(strfind(user_solution,'assert')));\r\n\r\n%%\r\nn = 0;\r\nV_correct = 1.0;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 1;\r\nV_correct = 1.0;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 2;\r\nV_correct = 0.433012701892219;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 3;\r\nV_correct = 0.117851130197758;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 4;\r\nV_correct = 0.023292374765623;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 5;\r\nV_correct = 0.003608439182435;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 6;\r\nV_correct = 0.000459331824838;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 7;\r\nV_correct = 0.000049603174603;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 8;\r\nV_correct = 0.000004650297619;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 9;\r\nV_correct = 0.000000385125244;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 10;\r\nV_correct = 0.000000028561653;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 11;\r\nV_correct = 0.000000001917653;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 12;\r\nV_correct = 0.000000000117613;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 13;\r\nV_correct = 0.000000000006639;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 14;\r\nV_correct = 0.000000000000347;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n\r\n%%\r\nn = 15;\r\nV_correct = 0.000000000000017;\r\nassert(abs(simplexvolume(n)-V_correct)\u003c4*eps)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":10352,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":98,"test_suite_updated_at":"2013-04-28T07:06:18.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-22T11:35:14.000Z","updated_at":"2026-03-16T12:09:25.000Z","published_at":"2013-04-22T11:35:14.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\u003eReturn the volume of a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Simplex\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eregular\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e-simplex\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e with a unit side length.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eResults are up to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e4*eps\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e precision.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eNeither\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\u003estring operations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e nor\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\u003einterpolations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are allowed!\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":1385,"title":"Perimeter","description":"Given a sequence of points forming a closed path (first and last points are coincident) return the perimeter value.\r\nFor example:\r\n\r\n xy = [ 0,0 ;\r\n        1,0 ;\r\n        1,1 ;\r\n        0,1 ;\r\n        0,0 ];\r\n\r\n L = 4","description_html":"\u003cp\u003eGiven a sequence of points forming a closed path (first and last points are coincident) return the perimeter value.\r\nFor example:\u003c/p\u003e\u003cpre\u003e xy = [ 0,0 ;\r\n        1,0 ;\r\n        1,1 ;\r\n        0,1 ;\r\n        0,0 ];\u003c/pre\u003e\u003cpre\u003e L = 4\u003c/pre\u003e","function_template":"function L = perimeter1(xy)\r\n\r\n  L=xy;\r\n\r\nend","test_suite":"%% Test case 1: Square\r\n\r\nxy=[0,0;\r\n    1,0;\r\n    1,1;\r\n    0,1;\r\n    0,0];\r\n\r\n\r\nerr=(abs(perimeter1(xy)-4)/(4))*100;\r\nassert(err\u003c.1)\r\n\r\n%% Test case 2 : Circle\r\n\r\nt=[0:pi/100:2*pi,0]';\r\nxy=[cos(t),sin(t)];\r\n\r\n\r\nerr=(abs(perimeter1(xy)-2*pi)/(2*pi))*100;\r\nassert(err\u003c.1)\r\n\r\n%% Test case 4 : Half-circle\r\n\r\nt=[0:pi/100:pi,0]';\r\nxy=[cos(t),sin(t)];\r\n\r\nerr=(abs(perimeter1(xy)-(pi+2))/(2+pi))*100;\r\nassert(err\u003c.1)\r\n\r\n%% Test case 4 : Hexagon\r\n\r\nside=rand;\r\nx=side*[-1 -0.5 0.5 1 0.5 -0.5 -1];\r\ny=side*sqrt(3)*[0 -0.5 -0.5 0 0.5 0.5 0];\r\nxy=[x',y'];\r\nerr=(abs(perimeter1(xy)-(6*side))/(6*side))*100;\r\nassert(err\u003c.1)","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":10742,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":156,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":20,"created_at":"2013-03-25T10:56:31.000Z","updated_at":"2026-02-18T16:34:50.000Z","published_at":"2013-03-25T10:57:47.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a sequence of points forming a closed path (first and last points are coincident) return the perimeter value. For example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ xy = [ 0,0 ;\\n        1,0 ;\\n        1,1 ;\\n        0,1 ;\\n        0,0 ];\\n\\n L = 4]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1443,"title":"Edges of a n-dimensional Hypercube","description":"Return the number of edges on an \u003chttp://en.wikipedia.org/wiki/Hypercube _n_-dimensional hypercube\u003e (with an integer n \u0026ge; 0).\r\n\r\nNeither *string operations* nor *interpolations* are allowed!\r\n","description_html":"\u003cp\u003eReturn the number of edges on an \u003ca href = \"http://en.wikipedia.org/wiki/Hypercube\"\u003e\u003ci\u003en\u003c/i\u003e-dimensional hypercube\u003c/a\u003e (with an integer n \u0026ge; 0).\u003c/p\u003e\u003cp\u003eNeither \u003cb\u003estring operations\u003c/b\u003e nor \u003cb\u003einterpolations\u003c/b\u003e are allowed!\u003c/p\u003e","function_template":"function E = hypercube_edges(n)\r\n  E = n;\r\nend","test_suite":"%%\r\nuser_solution = fileread('hypercube_edges.m');\r\nassert(isempty(strfind(user_solution,'regexp')));\r\nassert(isempty(strfind(user_solution,'2str')));\r\nassert(isempty(strfind(user_solution,'str2')));\r\nassert(isempty(strfind(user_solution,'interp')));\r\nassert(isempty(strfind(user_solution,'printf')));\r\nassert(isempty(strfind(user_solution,'assert')));\r\n\r\n%%\r\nn = 0;\r\nE_correct = 0;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 1;\r\nE_correct = 1;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 2;\r\nE_correct = 4;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 3;\r\nE_correct = 12;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 4;\r\nE_correct = 32;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 5;\r\nE_correct = 80;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 6;\r\nE_correct = 192;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 7;\r\nE_correct = 448;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 8;\r\nE_correct = 1024;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 9;\r\nE_correct = 2304;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 10;\r\nE_correct = 5120;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 11;\r\nE_correct = 11264;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 12;\r\nE_correct = 24576;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 13;\r\nE_correct = 53248;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 14;\r\nE_correct = 114688;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n\r\n%%\r\nn = 15;\r\nE_correct = 245760;\r\nassert(isequal(hypercube_edges(n),E_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":10352,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":88,"test_suite_updated_at":"2013-04-28T07:06:47.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-22T11:46:41.000Z","updated_at":"2026-02-16T11:00:34.000Z","published_at":"2013-04-22T11:47:26.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\u003eReturn the number of edges on an\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Hypercube\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e-dimensional hypercube\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e (with an integer n ≥ 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\u003eNeither\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\u003estring operations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e nor\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\u003einterpolations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are allowed!\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":1456,"title":"Beads on a Necklace (Convex Hulls)","description":"We may describe a \u003chttp://en.wikipedia.org/wiki/Convex_hull convex hull\u003e as a rubber band stretched around a list of points. Some of the points will be inside the rubber band, and some will define vertices of (or lie along the edge of) a \u003chttp://en.wikipedia.org/wiki/Convex_and_concave_polygons convex polygon\u003e.\r\n\r\nGiven an n-by-2 list of points xy where each row describes a point, your job is to determine if all the points belong to the convex hull for those points. In the matrix xy, the x coordinate is the first column and the y coordinate is the second column.\r\n\r\nSo, for example, the points below form a single convex hull.\r\n\r\n   *     *\r\n            \r\n   *     *  \r\n\r\nIn contrast, the points below do not, since the convex hull is a triangle that includes an interior point. Any polygon that includes all the points must necessarily be concave.\r\n\r\n      *\r\n      *  \r\n   *     *\r\n\r\nThus if\r\n\r\n xy = [1 1;1 2;2 2;2 1]\r\n\r\nthen\r\n\r\n allConvex(xy) =\u003e true\r\n\r\nWhereas\r\n\r\n xy = [1 1;3 1;2 2;2 3]\r\n allConvex(xy) =\u003e false\r\n \r\n\r\n","description_html":"\u003cp\u003eWe may describe a \u003ca href = \"http://en.wikipedia.org/wiki/Convex_hull\"\u003econvex hull\u003c/a\u003e as a rubber band stretched around a list of points. Some of the points will be inside the rubber band, and some will define vertices of (or lie along the edge of) a \u003ca href = \"http://en.wikipedia.org/wiki/Convex_and_concave_polygons\"\u003econvex polygon\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven an n-by-2 list of points xy where each row describes a point, your job is to determine if all the points belong to the convex hull for those points. In the matrix xy, the x coordinate is the first column and the y coordinate is the second column.\u003c/p\u003e\u003cp\u003eSo, for example, the points below form a single convex hull.\u003c/p\u003e\u003cpre\u003e   *     *\u003c/pre\u003e\u003cpre\u003e   *     *  \u003c/pre\u003e\u003cp\u003eIn contrast, the points below do not, since the convex hull is a triangle that includes an interior point. Any polygon that includes all the points must necessarily be concave.\u003c/p\u003e\u003cpre\u003e      *\r\n      *  \r\n   *     *\u003c/pre\u003e\u003cp\u003eThus if\u003c/p\u003e\u003cpre\u003e xy = [1 1;1 2;2 2;2 1]\u003c/pre\u003e\u003cp\u003ethen\u003c/p\u003e\u003cpre\u003e allConvex(xy) =\u003e true\u003c/pre\u003e\u003cp\u003eWhereas\u003c/p\u003e\u003cpre\u003e xy = [1 1;3 1;2 2;2 3]\r\n allConvex(xy) =\u003e false\u003c/pre\u003e","function_template":"function tf = allConvex(xy)\r\n  tf = true;\r\nend","test_suite":"%%\r\nxy = [1 1;1 2;2 2;2 1];\r\ntf_correct = true;\r\nassert(isequal(allConvex(xy),tf_correct))\r\n\r\n%%\r\nxy = [1 1;3 1;2 2;2 3];\r\ntf_correct = false;\r\nassert(isequal(allConvex(xy),tf_correct))\r\n\r\n%%\r\nxy = [6 4;10 6;10 3;3 1;5 5];\r\ntf_correct = false;\r\nassert(isequal(allConvex(xy),tf_correct))\r\n\r\n%%\r\nxy = [8 4;3 7;4 10;9 10;9 6;5 4];\r\ntf_correct = true;\r\nassert(isequal(allConvex(xy),tf_correct))\r\n\r\n%%\r\nxy = [14 26;14 29;2 15;2 7;3 7;18 17;8 23;26 11];\r\ntf_correct = false;\r\nassert(isequal(allConvex(xy),tf_correct))\r\n\r\n%%\r\nxy = [18 11;9 8;4 10;12 30;25 17;30 23;26 26;3 6];\r\ntf_correct = true;\r\nassert(isequal(allConvex(xy),tf_correct))\r\n\r\n%%\r\nxy = [1 1;1 2;1 3;3 3;3 1];\r\ntf_correct = true;\r\nassert(isequal(allConvex(xy),tf_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":7,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":"2013-04-24T19:14:21.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-24T18:11:58.000Z","updated_at":"2026-02-16T10:55:29.000Z","published_at":"2013-04-24T19:11:37.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWe may describe a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Convex_hull\\\"\u003e\u003cw:r\u003e\u003cw:t\u003econvex hull\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e as a rubber band stretched around a list of points. Some of the points will be inside the rubber band, and some will define vertices of (or lie along the edge of) a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Convex_and_concave_polygons\\\"\u003e\u003cw:r\u003e\u003cw:t\u003econvex polygon\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an n-by-2 list of points xy where each row describes a point, your job is to determine if all the points belong to the convex hull for those points. In the matrix xy, the x coordinate is the first column and the y coordinate is the second column.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSo, for example, the points below form a single convex hull.\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[   *     *\\n\\n   *     *]]\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\u003eIn contrast, the points below do not, since the convex hull is a triangle that includes an interior point. Any polygon that includes all the points must necessarily be concave.\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[      *\\n      *  \\n   *     *]]\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\u003eThus if\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[ xy = [1 1;1 2;2 2;2 1]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethen\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[ allConvex(xy) =\u003e true]]\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\u003eWhereas\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[ xy = [1 1;3 1;2 2;2 3]\\n allConvex(xy) =\u003e false]]\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":1462,"title":"Dots in a Sphere","description":"Return how many integer grid points there are inside a 3D sphere of radius _r_ centred at (0,0,0) (including points on the edge).\r\n\r\nNeither *string operations* nor *interpolations* are allowed!","description_html":"\u003cp\u003eReturn how many integer grid points there are inside a 3D sphere of radius \u003ci\u003er\u003c/i\u003e centred at (0,0,0) (including points on the edge).\u003c/p\u003e\u003cp\u003eNeither \u003cb\u003estring operations\u003c/b\u003e nor \u003cb\u003einterpolations\u003c/b\u003e are allowed!\u003c/p\u003e","function_template":"function n = dots_in_sphere(r)\r\n   n = r;\r\nend","test_suite":"%%\r\nuser_solution = fileread('dots_in_sphere.m');\r\nassert(isempty(strfind(user_solution,'regexp')));\r\nassert(isempty(strfind(user_solution,'2str')));\r\nassert(isempty(strfind(user_solution,'str2')));\r\nassert(isempty(strfind(user_solution,'interp')));\r\nassert(isempty(strfind(user_solution,'printf')));\r\nassert(isempty(strfind(user_solution,'assert')));\r\n\r\n%%\r\nr = 0;\r\nn_correct = 1;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 0.5;\r\nn_correct = 1;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 1;\r\nn_correct = 7;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 1.5;\r\nn_correct = 19;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 2;\r\nn_correct = 33;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 2.5;\r\nn_correct = 81;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 3;\r\nn_correct = 123;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 5;\r\nn_correct = 515;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 7.5;\r\nn_correct = 1791;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 10;\r\nn_correct = 4169;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 15;\r\nn_correct = 14147;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 20;\r\nn_correct = 33401;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 25;\r\nn_correct = 65267;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 50;\r\nn_correct = 523305;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n\r\n%%\r\nr = 100;\r\nn_correct = 4187857;\r\nassert(isequal(dots_in_sphere(r),n_correct));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":10352,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":65,"test_suite_updated_at":"2013-04-28T07:09:00.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-26T06:32:56.000Z","updated_at":"2026-02-16T10:50:59.000Z","published_at":"2013-04-26T06:41:52.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\u003eReturn how many integer grid points there are inside a 3D sphere of radius\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003er\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e centred at (0,0,0) (including points on the edge).\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eNeither\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\u003estring operations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e nor\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\u003einterpolations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are allowed!\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":1444,"title":"Dots in a Circle","description":"Return how many integer grid points there are inside a circle of radius _r_ centred at (0,0) (including points on the edge).\r\n\r\nNeither *string operations* nor *interpolations* are allowed!\r\n","description_html":"\u003cp\u003eReturn how many integer grid points there are inside a circle of radius \u003ci\u003er\u003c/i\u003e centred at (0,0) (including points on the edge).\u003c/p\u003e\u003cp\u003eNeither \u003cb\u003estring operations\u003c/b\u003e nor \u003cb\u003einterpolations\u003c/b\u003e are allowed!\u003c/p\u003e","function_template":"function n = dots_in_circle(r)\r\n  n = r;\r\nend","test_suite":"%%\r\nuser_solution = fileread('dots_in_circle.m');\r\nassert(isempty(strfind(user_solution,'regexp')));\r\nassert(isempty(strfind(user_solution,'2str')));\r\nassert(isempty(strfind(user_solution,'str2')));\r\nassert(isempty(strfind(user_solution,'interp')));\r\nassert(isempty(strfind(user_solution,'printf')));\r\nassert(isempty(strfind(user_solution,'assert')));\r\n\r\n%%\r\nr = 0;\r\nn_correct = 1;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 1;\r\nn_correct = 5;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 2;\r\nn_correct = 13;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 3;\r\nn_correct = 29;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 4;\r\nn_correct = 49;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 5;\r\nn_correct = 81;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 7.5;\r\nn_correct = 177;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 10;\r\nn_correct = 317;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 20;\r\nn_correct = 1257;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 30;\r\nn_correct = 2821;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 40;\r\nn_correct = 5025;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 50;\r\nn_correct = 7845;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 75;\r\nn_correct = 17665;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n\r\n%%\r\nr = 100;\r\nn_correct = 31417;\r\nassert(isequal(dots_in_circle(r),n_correct))\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":5,"created_by":10352,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":100,"test_suite_updated_at":"2013-04-28T07:07:28.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-22T12:50:26.000Z","updated_at":"2026-02-16T10:59:41.000Z","published_at":"2013-04-22T12:50:26.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\u003eReturn how many integer grid points there are inside a circle of radius\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003er\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e centred at (0,0) (including points on the edge).\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eNeither\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\u003estring operations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e nor\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\u003einterpolations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are allowed!\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":1074,"title":"Property dispute!","description":"Two neighbors have rectangular plots of land A and B. The surveyors give you the coordinates of each. If they overlap, there is a property dispute, and you must return the coordinates of the disputed region. If there is no conflict, return the empty set [].\r\nSuppose A and B look like this.\r\n *--------*\r\n | A      |\r\n |    *--------*\r\n |    |   |    |\r\n |    |   | B  |\r\n |    |   |    |\r\n |    *--------*\r\n |        |\r\n *--------*\r\nWe will give rectangle coordinates in [xLow yLow width height] format. So\r\n A = [0  0  5 10]\r\n B = [3  2  6  6]\r\nThen you should return rectangle that corresponds to the overlapping region.\r\n C = [3  2  2  6]","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: 430.2px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 406.5px 215.1px; transform-origin: 406.5px 215.1px; 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: 383.5px 31.5px; text-align: left; transform-origin: 383.5px 31.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 378.55px 7.81667px; transform-origin: 378.55px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eTwo neighbors have rectangular plots of land A and B. The surveyors give you the coordinates of each. If they overlap, there is a property dispute, and you must return the coordinates of the disputed region. If there is no conflict, return the empty set [].\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 102.175px 7.81667px; transform-origin: 102.175px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSuppose A and B look like this.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 183.9px; 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: 403.5px 91.95px; transform-origin: 403.5px 91.95px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 42.9917px 8.375px; tab-size: 4; transform-origin: 42.9917px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e *--------*\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 42.9917px 8.375px; tab-size: 4; transform-origin: 42.9917px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e | A      |\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 62.5333px 8.375px; tab-size: 4; transform-origin: 62.5333px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e |    *--------*\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 62.5333px 8.375px; tab-size: 4; transform-origin: 62.5333px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e |    |   |    |\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 62.5333px 8.375px; tab-size: 4; transform-origin: 62.5333px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e |    |   | B  |\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 62.5333px 8.375px; tab-size: 4; transform-origin: 62.5333px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e |    |   |    |\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 62.5333px 8.375px; tab-size: 4; transform-origin: 62.5333px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e |    *--------*\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 42.9917px 8.375px; tab-size: 4; transform-origin: 42.9917px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e |        |\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 42.9917px 8.375px; tab-size: 4; transform-origin: 42.9917px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e *--------*\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: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; 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: 236.175px 7.81667px; transform-origin: 236.175px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWe will give rectangle coordinates in [xLow yLow width height] format. So\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 40.8667px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 403.5px 20.4333px; transform-origin: 403.5px 20.4333px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 66.4417px 8.375px; tab-size: 4; transform-origin: 66.4417px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e A = [0  0  5 10]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\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: 66.4417px 8.375px; tab-size: 4; transform-origin: 66.4417px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e B = [3  2  6  6]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; 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: 244.55px 7.81667px; transform-origin: 244.55px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThen you should return rectangle that corresponds to the overlapping region.\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: 403.5px 10.2167px; transform-origin: 403.5px 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: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; 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; text-wrap-mode: 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: 66.4417px 8.375px; tab-size: 4; transform-origin: 66.4417px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e C = [3  2  2  6]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function C = disputed_region(A,B)\r\n  C = [];\r\nend","test_suite":"%%\r\na = [0 0 5 10];\r\nb = [3 2 6 6];\r\nc = [3 2 2 6];\r\nassert(isequal(disputed_region(a,b),c))\r\n\r\n%%\r\na = [0 1 2 3];\r\nb = [-1 2 4 5];\r\nc = [0 2 2 2];\r\nassert(isequal(disputed_region(a,b),c))\r\n\r\n%%\r\na = [3 4 6 1];\r\nb = [2 1 2 2];\r\nassert(isempty(disputed_region(a,b)))\r\n\r\n%%\r\na = [5 18 14 6];\r\nb = [11 23 17 18];\r\nc = [11 23 8 1];\r\nassert(isequal(disputed_region(a,b),c))\r\n\r\n%%\r\na = [100 97 3 2];\r\nb = [99 93 12 12];\r\nc = [100 97 3 2];\r\nassert(isequal(disputed_region(a,b),c))\r\n\r\n%%\r\ndelta = 0.5;\r\na = [0 0 5 10]+delta;\r\nb = [3 2 6 6]+delta;\r\nc = [3 2 2 6]+delta;\r\nassert(isequal(disputed_region(a,b),c))\r\n\r\n%%\r\na = [0 0 1 1];\r\nb = [2 2 1 1];\r\nc = [];\r\nassert(isempty(disputed_region(a,b)))","published":true,"deleted":false,"likes_count":3,"comments_count":4,"created_by":7,"edited_by":223089,"edited_at":"2024-06-11T15:31:25.000Z","deleted_by":null,"deleted_at":null,"solvers_count":41,"test_suite_updated_at":"2024-06-11T15:31:25.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2012-11-28T22:11:52.000Z","updated_at":"2026-02-16T10:40:33.000Z","published_at":"2012-12-19T20:58:35.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTwo neighbors have rectangular plots of land A and B. The surveyors give you the coordinates of each. If they overlap, there is a property dispute, and you must return the coordinates of the disputed region. If there is no conflict, return the empty set [].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSuppose A and B look like 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[ *--------*\\n | A      |\\n |    *--------*\\n |    |   |    |\\n |    |   | B  |\\n |    |   |    |\\n |    *--------*\\n |        |\\n *--------*]]\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\u003eWe will give rectangle coordinates in [xLow yLow width height] format. So\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ A = [0  0  5 10]\\n B = [3  2  6  6]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThen you should return rectangle that corresponds to the overlapping region.\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[ C = [3  2  2  6]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":1411,"title":"Number of lattice points within a circle","description":"Find the number of points (x,y) in square lattice with x^2 + y^2 =\u003c n. This is related to Jame's \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1387 Problem 1387\u003e. Here you have to find the number of points within a circle.","description_html":"\u003cp\u003eFind the number of points (x,y) in square lattice with x^2 + y^2 =\u0026lt; n. This is related to Jame's \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1387\"\u003eProblem 1387\u003c/a\u003e. Here you have to find the number of points within a circle.\u003c/p\u003e","function_template":"function y = within_circle(n)\r\n  y = n;\r\nend","test_suite":"%%\r\nassert(isequal(within_circle(1),5))\r\n\r\n%%\r\nassert(isequal(within_circle(3),9))\r\n\r\n%%\r\nassert(isequal(within_circle(20),69))\r\n\r\n%%\r\nassert(isequal(within_circle(45),145))\r\n\r\n%%\r\nassert(isequal(within_circle(55),177))\r\n\r\n%%\r\nassert(isequal(within_circle(500),1581))\r\n\r\n%%\r\nassert(isequal(within_circle(10000),31417))\r\n\r\n%%\r\nassert(isequal(within_circle(50000),157093))\r\n\r\n%%\r\nassert(isequal(within_circle(999999),3141521))\r\n\r\n%%\r\nassert(isequal(within_circle(9999999),31415993))\r\n\r\n%%\r\nassert(isequal(within_circle(99999999),314159017)) % Approaching to Pi...\r\n\r\n%%\r\nfiletext = fileread('within_circle.m');\r\nassert(isempty(strfind(filetext, 'switch')))\r\nassert(isempty(strfind(filetext, 'case')))\r\nassert(isempty(strfind(filetext, 'if')))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":810,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":36,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-03T00:59:36.000Z","updated_at":"2026-02-16T11:05:45.000Z","published_at":"2013-04-03T01:11:03.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the number of points (x,y) in square lattice with x^2 + y^2 =\u0026lt; n. This is related to Jame's\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1387\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 1387\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Here you have to find the number of points within a circle.\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":1336,"title":"Geometry: Find Circle given 3 Non-Colinear Points","description":"*This Challenge is to determine the center and radius of a circle given three non-colinear points.*\r\n\r\n*Input:* Points\r\n\r\n*Output:* [xc, yc, r] where [xc,yc] are the center and r is the radius\r\n\r\n*Example:*\r\n\r\nInput: Points = [1 0 ; 0 -1 ; 0 1]\r\n\r\nOutput: [ 0 0 1]\r\n\r\n*Theory/Hint:* The Kasa method provides a best fit circle to a set of points.\r\n\r\n*Future:* 1) Circumscribe 4 points  2) Circumscribe N points  3) The Great Lego Cup Challenge","description_html":"\u003cp\u003e\u003cb\u003eThis Challenge is to determine the center and radius of a circle given three non-colinear points.\u003c/b\u003e\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e Points\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e [xc, yc, r] where [xc,yc] are the center and r is the radius\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample:\u003c/b\u003e\u003c/p\u003e\u003cp\u003eInput: Points = [1 0 ; 0 -1 ; 0 1]\u003c/p\u003e\u003cp\u003eOutput: [ 0 0 1]\u003c/p\u003e\u003cp\u003e\u003cb\u003eTheory/Hint:\u003c/b\u003e The Kasa method provides a best fit circle to a set of points.\u003c/p\u003e\u003cp\u003e\u003cb\u003eFuture:\u003c/b\u003e 1) Circumscribe 4 points  2) Circumscribe N points  3) The Great Lego Cup Challenge\u003c/p\u003e","function_template":"function [xc,yc,r]=find_circle(pts)\r\n xc=0;\r\n yc=0;\r\n r=1;\r\n\r\n","test_suite":"%%\r\nfor tests=1:5\r\n xc_truth=randn;\r\n yc_truth=randn;\r\n r_truth=rand;\r\n rand_ang=randi(360,3,1)+rand(3,1); % Avoid duplicate location via rand(3,1)\r\n pts=[xc_truth+r_truth*cosd(rand_ang) yc_truth+r_truth*sind(rand_ang)]; \r\n\r\n [xc,yc,r]=find_circle(pts);\r\n\r\n %dif=[xc yc r]-[xc_truth yc_truth r_truth]\r\n\r\n assert(max(abs([xc,yc,r]-[xc_truth,yc_truth,r_truth]))\u003c1e-6,...\r\nsprintf('Expect xc %.2f yc %.2f r %.2f  Ans:%.2f %.2f %.2f',...\r\n  xc_truth,yc_truth,r_truth,xc,yc,r))\r\nend","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":64,"test_suite_updated_at":"2017-02-24T17:19:01.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-03-10T17:26:14.000Z","updated_at":"2026-02-16T11:13:15.000Z","published_at":"2013-03-10T18:03:52.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\u003eThis Challenge is to determine the center and radius of a circle given three non-colinear points.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Points\u003c/w:t\u003e\u003c/w:r\u003e\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 [xc, yc, r] where [xc,yc] are the center and r is the radius\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput: Points = [1 0 ; 0 -1 ; 0 1]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput: [ 0 0 1]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTheory/Hint:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e The Kasa method provides a best fit circle to a set of points.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eFuture:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 1) Circumscribe 4 points 2) Circumscribe N points 3) The Great Lego Cup Challenge\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":567,"title":"Crossing to Kissing - Untangle the Lines","description":"Turn lines that cross into lines that kiss.\r\n\r\nYou will be given two lines that cross at some point. Your job is to untangle them in the following way. Imagine two line segments, L1 and L2. L1 goes from (0,0) to (2,2). L2 goes from (0,1) to (2,1). We can specify them like so.\r\n\r\n L1 = [0 0; \r\n       2 2]\r\n\r\n L2 = [0 1; \r\n       2 1]\r\n\r\nWe want to transform these into two non-crossing segmented lines that look the same when plotted. To do this, we need to introduce a new point in each line. Both lines share this point, so now they \"kiss\" instead of crossing.\r\n\r\n L3 = [0 0; \r\n       1 1;\r\n       2 1]\r\n\r\n L4 = [0 1;\r\n       1 1;\r\n       2 2]\r\n\r\n            * L1               * L4\r\n           /                  /\r\n          /                  /\r\n   L2 *--/--* L2      L4 *--*--* L3\r\n        /                  /\r\n       /                  /\r\n   L1 *               L3 *\r\n\r\nYour function should take the form\r\n\r\n [L3,L4] = cross2kiss(L1,L2)\r\n\r\nThe lines L3 and L4 should be ordered by the y coordinate of their first point. So in the case above, the first point in L3 is [0 0], so it comes first.","description_html":"\u003cp\u003eTurn lines that cross into lines that kiss.\u003c/p\u003e\u003cp\u003eYou will be given two lines that cross at some point. Your job is to untangle them in the following way. Imagine two line segments, L1 and L2. L1 goes from (0,0) to (2,2). L2 goes from (0,1) to (2,1). We can specify them like so.\u003c/p\u003e\u003cpre\u003e L1 = [0 0; \r\n       2 2]\u003c/pre\u003e\u003cpre\u003e L2 = [0 1; \r\n       2 1]\u003c/pre\u003e\u003cp\u003eWe want to transform these into two non-crossing segmented lines that look the same when plotted. To do this, we need to introduce a new point in each line. Both lines share this point, so now they \"kiss\" instead of crossing.\u003c/p\u003e\u003cpre\u003e L3 = [0 0; \r\n       1 1;\r\n       2 1]\u003c/pre\u003e\u003cpre\u003e L4 = [0 1;\r\n       1 1;\r\n       2 2]\u003c/pre\u003e\u003cpre\u003e            * L1               * L4\r\n           /                  /\r\n          /                  /\r\n   L2 *--/--* L2      L4 *--*--* L3\r\n        /                  /\r\n       /                  /\r\n   L1 *               L3 *\u003c/pre\u003e\u003cp\u003eYour function should take the form\u003c/p\u003e\u003cpre\u003e [L3,L4] = cross2kiss(L1,L2)\u003c/pre\u003e\u003cp\u003eThe lines L3 and L4 should be ordered by the y coordinate of their first point. So in the case above, the first point in L3 is [0 0], so it comes first.\u003c/p\u003e","function_template":"function [L3,L4] = cross2kiss(L1,L2);\r\n  L3 = 0;\r\n  L4 = 0;\r\nend","test_suite":"%%\r\nL1 =  [0 0; \r\n       2 2];\r\nL2 =  [0 1;\r\n       2 1];\r\n[L3,L4] = cross2kiss(L1,L2);\r\nL3c = [0 0; \r\n       1 1;\r\n       2 1]\r\nL4c = [0 1;\r\n       1 1;\r\n       2 2]\r\nassert(isequal(L3,L3c))\r\nassert(isequal(L4,L4c))\r\n\r\n%%\r\nL1 =  [-2 -1; \r\n        2  1];\r\nL2 =  [-1  1;\r\n        1 -1];\r\n[L3,L4] = cross2kiss(L1,L2);\r\nL3c =  [-2 -1; \r\n         0  0;\r\n         1 -1];\r\nL4c =  [-1  1;\r\n         0  0;\r\n         2  1];\r\nassert(isequal(L3,L3c))\r\nassert(isequal(L4,L4c))\r\n\r\n%%\r\nL1 =  [ 5  5; \r\n        8 -4];\r\nL2 =  [ 5 -2;\r\n        9  0];\r\n[L3,L4] = cross2kiss(L1,L2);\r\nL3c =  [ 5 -2;\r\n         7 -1;\r\n         8 -4];\r\nL4c =  [ 5  5; \r\n         7 -1;\r\n         9  0];\r\nassert(isequal(L3,L3c))\r\nassert(isequal(L4,L4c))\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":7,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":34,"test_suite_updated_at":"2012-12-18T16:37:17.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2012-04-09T22:07:02.000Z","updated_at":"2026-02-16T11:19:24.000Z","published_at":"2012-12-18T16:31:46.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\u003eTurn lines that cross into lines that kiss.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou will be given two lines that cross at some point. Your job is to untangle them in the following way. Imagine two line segments, L1 and L2. L1 goes from (0,0) to (2,2). L2 goes from (0,1) to (2,1). We can specify them like so.\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[ L1 = [0 0; \\n       2 2]\\n\\n L2 = [0 1; \\n       2 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\u003eWe want to transform these into two non-crossing segmented lines that look the same when plotted. To do this, we need to introduce a new point in each line. Both lines share this point, so now they \\\"kiss\\\" instead of crossing.\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[ L3 = [0 0; \\n       1 1;\\n       2 1]\\n\\n L4 = [0 1;\\n       1 1;\\n       2 2]\\n\\n            * L1               * L4\\n           /                  /\\n          /                  /\\n   L2 *--/--* L2      L4 *--*--* L3\\n        /                  /\\n       /                  /\\n   L1 *               L3 *]]\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\u003eYour function should take the form\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[ [L3,L4] = cross2kiss(L1,L2)]]\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 lines L3 and L4 should be ordered by the y coordinate of their first point. So in the case above, the first point in L3 is [0 0], so it comes first.\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":1446,"title":"Minimum Distance Point to Segment","description":"This Challenge is to determine the minimum distance from a 2-D line segment defined by two points to a point.\r\n\r\nThe point is (px,py) and the segment is [(vx,vy) to (wx,wy)].\r\n\r\nInput are the three defining points and the output is distance.\r\n\r\n*Input (px py vx vy wx wy):*   1 1 0 3 3 0\r\n\r\n*Output distance:* .7071\r\n\r\nPoint is beyond perpendicular to segment.\r\n\r\n*Input (px py vx vy wx wy):*   4 3 -100 0 0 0\r\n\r\n*Output distance:* 5\r\n\r\n\r\nFollow Up Challenges:\r\n\r\n1) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1452-minimum-distance-between-two-n-sided-polygons Minimum distance between non-contiguous N-sided polygons\u003e\r\n\r\n2) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1457-usc-spring-2013-acm-walking-on-thin-ice USC Spring 2013 ACM: Walking on Thin Ice\u003e\r\n\r\n","description_html":"\u003cp\u003eThis Challenge is to determine the minimum distance from a 2-D line segment defined by two points to a point.\u003c/p\u003e\u003cp\u003eThe point is (px,py) and the segment is [(vx,vy) to (wx,wy)].\u003c/p\u003e\u003cp\u003eInput are the three defining points and the output is distance.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput (px py vx vy wx wy):\u003c/b\u003e   1 1 0 3 3 0\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput distance:\u003c/b\u003e .7071\u003c/p\u003e\u003cp\u003ePoint is beyond perpendicular to segment.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput (px py vx vy wx wy):\u003c/b\u003e   4 3 -100 0 0 0\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput distance:\u003c/b\u003e 5\u003c/p\u003e\u003cp\u003eFollow Up Challenges:\u003c/p\u003e\u003cp\u003e1) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1452-minimum-distance-between-two-n-sided-polygons\"\u003eMinimum distance between non-contiguous N-sided polygons\u003c/a\u003e\u003c/p\u003e\u003cp\u003e2) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1457-usc-spring-2013-acm-walking-on-thin-ice\"\u003eUSC Spring 2013 ACM: Walking on Thin Ice\u003c/a\u003e\u003c/p\u003e","function_template":"function d=distP2S(px,py,vx,vy,wx,wy)\r\n% segment defined by (vx,vy) to (wx,wy)\r\n% [px py vx vy wx wy]\r\n d=0;\r\nend","test_suite":"%%\r\np=[0 0];\r\nv=[1 -1];\r\nw=[1 1];\r\nd=distP2S(p(1),p(2),v(1),v(2),w(1),w(2));\r\nassert(abs(d-1)\u003c.005)\r\n\r\n%%\r\np=[0 0];\r\nv=[-1 2];\r\nw=[1 2];\r\nd=distP2S(p(1),p(2),v(1),v(2),w(1),w(2));\r\nassert(abs(d-2)\u003c.005)\r\n\r\n%%\r\np=[0 0];\r\nv=[-1 -1];\r\nw=[1 1];\r\nd=distP2S(p(1),p(2),v(1),v(2),w(1),w(2));\r\nassert(abs(d)\u003c.005)\r\n\r\n%%\r\np=[1 1];\r\nv=[0 3];\r\nw=[3 0];\r\nd=distP2S(p(1),p(2),v(1),v(2),w(1),w(2));\r\nassert(abs(d-1/2^.5)\u003c.005)\r\n\r\n%%\r\np=[5 0];\r\nv=[0 3];\r\nw=[3 0];\r\nd=distP2S(p(1),p(2),v(1),v(2),w(1),w(2));\r\nassert(abs(d-2)\u003c.005)\r\n\r\n%%\r\np=[0 6];\r\nv=[0 3];\r\nw=[3 0];\r\nd=distP2S(p(1),p(2),v(1),v(2),w(1),w(2));\r\nassert(abs(d-3)\u003c.005)\r\n\r\n%%\r\np=[-4 0];\r\nv=[0 3];\r\nw=[-3 0];\r\nd=distP2S(p(1),p(2),v(1),v(2),w(1),w(2))\r\nassert(abs(d-1)\u003c.005)\r\n\r\n%%\r\np=[1 0];\r\nv=[1.01 0];\r\nw=[5 5];\r\nd=distP2S(p(1),p(2),v(1),v(2),w(1),w(2))\r\nassert(abs(d-.01)\u003c.005)","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":62,"test_suite_updated_at":"2018-07-20T15:16:15.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-23T02:10:21.000Z","updated_at":"2026-02-16T10:58:16.000Z","published_at":"2013-04-23T02:45:32.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis Challenge is to determine the minimum distance from a 2-D line segment defined by two points to a point.\u003c/w:t\u003e\u003c/w:r\u003e\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 point is (px,py) and the segment is [(vx,vy) to (wx,wy)].\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eInput are the three defining points and the output is distance.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput (px py vx vy wx wy):\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 1 1 0 3 3 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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput distance:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e .7071\u003c/w:t\u003e\u003c/w:r\u003e\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\u003ePoint is beyond perpendicular to segment.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput (px py vx vy wx wy):\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 4 3 -100 0 0 0\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput distance:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFollow Up Challenges:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1452-minimum-distance-between-two-n-sided-polygons\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eMinimum distance between non-contiguous N-sided polygons\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1457-usc-spring-2013-acm-walking-on-thin-ice\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eUSC Spring 2013 ACM: Walking on Thin Ice\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1428,"title":"Find the optimal shape to bring the maximum product by a given perimeter","description":"Find the optimal shape (with Nopt sides, where Nopt is at least 3) to bring the maximum product of the sides length, given a specified perimeter.\r\n\r\nExample:\r\nAssuming perimeter equals to 7 (p=7) then the known optimal value is Nopt=3 (a triangle, so 3 sides).\r\n  let mark L1,L2,L3 the triangle sides length (L1+L2+L3=7), thus the product is L1*L2*L3 and we want the product to be as large as possible for your chosen number of sides Nopt.\r\n\r\nDon't assume the perimeter is an integer. The side lengths need not be integers, although it is possible they might be so. And of course, you need to decide if the optimum happens for an equilateral polygon, so with equal side lengths, or if some other set of side lengths that collectively sum to p might be a better choice.\r\n\r\n\u003chttps://docs.google.com/file/d/0B-d0Lx2W7Gsma0F6LS1TbjB6dm8/edit?usp=sharing Illustrate Link\u003e\r\n\r\nDifficulty level on a scale 1 to 10:  *8* \r\n","description_html":"\u003cp\u003eFind the optimal shape (with Nopt sides, where Nopt is at least 3) to bring the maximum product of the sides length, given a specified perimeter.\u003c/p\u003e\u003cp\u003eExample:\r\nAssuming perimeter equals to 7 (p=7) then the known optimal value is Nopt=3 (a triangle, so 3 sides).\r\n  let mark L1,L2,L3 the triangle sides length (L1+L2+L3=7), thus the product is L1*L2*L3 and we want the product to be as large as possible for your chosen number of sides Nopt.\u003c/p\u003e\u003cp\u003eDon't assume the perimeter is an integer. The side lengths need not be integers, although it is possible they might be so. And of course, you need to decide if the optimum happens for an equilateral polygon, so with equal side lengths, or if some other set of side lengths that collectively sum to p might be a better choice.\u003c/p\u003e\u003cp\u003e\u003ca href = \"https://docs.google.com/file/d/0B-d0Lx2W7Gsma0F6LS1TbjB6dm8/edit?usp=sharing\"\u003eIllustrate Link\u003c/a\u003e\u003c/p\u003e\u003cp\u003eDifficulty level on a scale 1 to 10:  \u003cb\u003e8\u003c/b\u003e\u003c/p\u003e","function_template":"function [Nopt,prd] = max_product(p)\r\n  % p is the given perimeter\r\n  \r\n  % Nopt - number of sides(optimal)to bring the product to max\r\n  % prd - is that maximum product\r\n\r\nend","test_suite":"%%\r\np = 5;\r\n[Nopt,prd] = max_product(p);\r\nassert(isequal(Nopt,3))\r\nassert(abs(prd - 4.62962962962963)/4.62962962962963 \u003c 1e-13)\r\n\r\n%%\r\np = 10;\r\n[Nopt,prd] = max_product(p);\r\nassert(isequal(Nopt,4))\r\nassert(abs(prd - 39.0625)/39.0625 \u003c 1e-13)\r\n\r\n%%\r\np = 17.5;\r\n[Nopt,prd] = max_product(p);\r\nassert(isequal(Nopt,6))\r\nassert(abs(prd - 615.631438413601)/615.631438413601 \u003c 1e-13)\r\n\r\n%%\r\np = 29;\r\n[Nopt,prd] = max_product(p);\r\nassert(isequal(Nopt,11))\r\nassert(abs(prd - 4.276204243443044e+04)/4.276204243443044e+04 \u003c 1e-13)\r\n\r\n%%\r\np = 49;\r\n[Nopt,prd] = max_product(p);\r\nassert(isequal(Nopt,18))\r\nassert(abs(prd - 6.739448339947788e+07)/6.739448339947788e+07 \u003c 1e-13)\r\n\r\n%%\r\np = 256;\r\n[Nopt,prd] = max_product(p);\r\nassert(isequal(Nopt,94))\r\nassert(abs(prd - 7.953137683223010e+40)/7.953137683223010e+40 \u003c 1e-13)\r\n\r\n%%\r\np = 1000000;\r\n[Nopt,prd] = max_product(p);\r\nassert(isequal(Nopt,367879))\r\nassert(isinf(prd))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":10,"created_by":12871,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":45,"test_suite_updated_at":"2018-03-26T21:41:39.000Z","rescore_all_solutions":true,"group_id":20,"created_at":"2013-04-15T10:19:39.000Z","updated_at":"2026-02-16T11:04:21.000Z","published_at":"2013-04-16T17:10:41.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 the optimal shape (with Nopt sides, where Nopt is at least 3) to bring the maximum product of the sides length, given a specified perimeter.\u003c/w:t\u003e\u003c/w:r\u003e\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: Assuming perimeter equals to 7 (p=7) then the known optimal value is Nopt=3 (a triangle, so 3 sides). let mark L1,L2,L3 the triangle sides length (L1+L2+L3=7), thus the product is L1*L2*L3 and we want the product to be as large as possible for your chosen number of sides Nopt.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eDon't assume the perimeter is an integer. The side lengths need not be integers, although it is possible they might be so. And of course, you need to decide if the optimum happens for an equilateral polygon, so with equal side lengths, or if some other set of side lengths that collectively sum to p might be a better choice.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://docs.google.com/file/d/0B-d0Lx2W7Gsma0F6LS1TbjB6dm8/edit?usp=sharing\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eIllustrate Link\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDifficulty level on a scale 1 to 10: \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\u003e8\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":1459,"title":"Triangular Tiling Dots in a Circle","description":"Return how many \u003chttp://en.wikipedia.org/wiki/Triangular_tiling Triangular Tiling\u003e grid points there are inside a circle of radius _r_ centred at (0,0) (including points on the edge).  \r\n\r\nAssume that a Triangular Tiling grid is a \u003chttp://en.wikipedia.org/wiki/Bravais_lattice 2D Hexagonal Bravais lattice\u003e with | _a1_ | = | _a2_ | = 1 and _\u0026phi;_ = 120\u0026deg;.\r\n\r\nNeither *string operations* nor *interpolations* are allowed!","description_html":"\u003cp\u003eReturn how many \u003ca href = \"http://en.wikipedia.org/wiki/Triangular_tiling\"\u003eTriangular Tiling\u003c/a\u003e grid points there are inside a circle of radius \u003ci\u003er\u003c/i\u003e centred at (0,0) (including points on the edge).\u003c/p\u003e\u003cp\u003eAssume that a Triangular Tiling grid is a \u003ca href = \"http://en.wikipedia.org/wiki/Bravais_lattice\"\u003e2D Hexagonal Bravais lattice\u003c/a\u003e with | \u003ci\u003ea1\u003c/i\u003e | = | \u003ci\u003ea2\u003c/i\u003e | = 1 and \u003ci\u003e\u0026phi;\u003c/i\u003e = 120\u0026deg;.\u003c/p\u003e\u003cp\u003eNeither \u003cb\u003estring operations\u003c/b\u003e nor \u003cb\u003einterpolations\u003c/b\u003e are allowed!\u003c/p\u003e","function_template":"function n = hexagonal_dots_in_circle(r)\r\n  n = r;\r\nend","test_suite":"%%\r\nuser_solution = fileread('hexagonal_dots_in_circle.m');\r\nassert(isempty(strfind(user_solution,'regexp')));\r\nassert(isempty(strfind(user_solution,'2str')));\r\nassert(isempty(strfind(user_solution,'str2')));\r\nassert(isempty(strfind(user_solution,'interp')));\r\nassert(isempty(strfind(user_solution,'printf')));\r\nassert(isempty(strfind(user_solution,'assert')));\r\n\r\n%%\r\nr = 0;\r\nn_correct = 1;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 0.5;\r\nn_correct = 1;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 1;\r\nn_correct = 7;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 1.5;\r\nn_correct = 7;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 2;\r\nn_correct = 19;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 2.5;\r\nn_correct = 19;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 3;\r\nn_correct = 37;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 5;\r\nn_correct = 91;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 7.5;\r\nn_correct = 199;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 10;\r\nn_correct = 367;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 15;\r\nn_correct = 823;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 20;\r\nn_correct = 1459;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 25;\r\nn_correct = 2263;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 50;\r\nn_correct = 9061;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n\r\n%%\r\nr = 100;\r\nn_correct = 36295;\r\nassert(isequal(hexagonal_dots_in_circle(r),n_correct));\r\n ","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":10352,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":32,"test_suite_updated_at":"2013-05-05T10:49:55.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-25T18:57:26.000Z","updated_at":"2026-02-16T10:52:57.000Z","published_at":"2013-04-25T18:57:26.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\u003eReturn how many\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Triangular_tiling\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eTriangular Tiling\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e grid points there are inside a circle of radius\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003er\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e centred at (0,0) (including points on the edge).\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eAssume that a Triangular Tiling grid is a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Bravais_lattice\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2D Hexagonal Bravais lattice\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e with |\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ea1\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:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ea2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e | = 1 and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eφ\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e = 120°.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNeither\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\u003estring operations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e nor\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\u003einterpolations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are allowed!\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":1490,"title":"Shifted Hexagonal Tiling Dots in a Circle","description":"Return how many \u003chttp://en.wikipedia.org/wiki/Hexagonal_grid Hexagonal Tiling\u003e grid points there are inside a circle of radius _r_ centred at (0,0) (including points on the edge).  Assume that a Hexagonal Tiling grid is a \u003chttp://en.wikipedia.org/wiki/Regular_tiling 2D Regular Hexagonal Tessellation\u003e with equal edges of size _e_=1.  \r\n\r\nFor _shifted_ symmetry purposes, assume that (0,0) is a _grid point_.\r\n\r\nNeither *string operations* nor *interpolations* are allowed!","description_html":"\u003cp\u003eReturn how many \u003ca href = \"http://en.wikipedia.org/wiki/Hexagonal_grid\"\u003eHexagonal Tiling\u003c/a\u003e grid points there are inside a circle of radius \u003ci\u003er\u003c/i\u003e centred at (0,0) (including points on the edge).  Assume that a Hexagonal Tiling grid is a \u003ca href = \"http://en.wikipedia.org/wiki/Regular_tiling\"\u003e2D Regular Hexagonal Tessellation\u003c/a\u003e with equal edges of size \u003ci\u003ee\u003c/i\u003e=1.\u003c/p\u003e\u003cp\u003eFor \u003ci\u003eshifted\u003c/i\u003e symmetry purposes, assume that (0,0) is a \u003ci\u003egrid point\u003c/i\u003e.\u003c/p\u003e\u003cp\u003eNeither \u003cb\u003estring operations\u003c/b\u003e nor \u003cb\u003einterpolations\u003c/b\u003e are allowed!\u003c/p\u003e","function_template":"function n = shifted_hexagonal_tiling_dots_in_circle(r)\r\n  n = r;\r\nend","test_suite":"%%\r\nuser_solution = fileread('shifted_hexagonal_tiling_dots_in_circle.m');\r\nassert(isempty(strfind(user_solution,'regexp')));\r\nassert(isempty(strfind(user_solution,'2str')));\r\nassert(isempty(strfind(user_solution,'str2')));\r\nassert(isempty(strfind(user_solution,'interp')));\r\nassert(isempty(strfind(user_solution,'printf')));\r\nassert(isempty(strfind(user_solution,'assert')));\r\n\r\n%%\r\nr = 0;\r\nN_correct = 1;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 0.5;\r\nN_correct = 1;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 1;\r\nN_correct = 4;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 1.5;\r\nN_correct = 4;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 2;\r\nN_correct = 13;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 2.5;\r\nN_correct = 13;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 3;\r\nN_correct = 25;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 5;\r\nN_correct = 61;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 7.5;\r\nN_correct = 130;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 10;\r\nN_correct = 244;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 15;\r\nN_correct = 547;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 20;\r\nN_correct = 979;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 25;\r\nN_correct = 1510;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 50;\r\nN_correct = 6049;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 100;\r\nN_correct = 24202;\r\nassert(isequal(shifted_hexagonal_tiling_dots_in_circle(r),N_correct));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":10352,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":20,"created_at":"2013-05-05T11:12:35.000Z","updated_at":"2026-02-16T10:46:10.000Z","published_at":"2013-05-05T11:13:56.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eReturn how many\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Hexagonal_grid\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eHexagonal Tiling\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e grid points there are inside a circle of radius\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003er\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e centred at (0,0) (including points on the edge). Assume that a Hexagonal Tiling grid is a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Regular_tiling\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2D Regular Hexagonal Tessellation\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e with equal edges 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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ee\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e=1.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eshifted\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e symmetry purposes, assume that (0,0) is a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003egrid point\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\u003eNeither\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\u003estring operations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e nor\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\u003einterpolations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are allowed!\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":1489,"title":"Hexagonal Tiling Dots in a Circle","description":"Return how many \u003chttp://en.wikipedia.org/wiki/Hexagonal_grid Hexagonal Tiling\u003e grid points there are inside a circle of radius _r_ centred at (0,0) (including points on the edge).  Assume that a Hexagonal Tiling grid is a \u003chttp://en.wikipedia.org/wiki/Regular_tiling 2D Regular Hexagonal Tessellation\u003e with equal edges of size _e_=1.  \r\n\r\nFor symmetry purposes, assume that (0,0) point is a _vacancy_; i.e., there _are_ points at (\u0026plusmn;1,0), (\u0026plusmn;1/2,\u0026plusmn;\u0026radic;3/2), etcetera.\r\n\r\nNeither *string operations* nor *interpolations* are allowed!","description_html":"\u003cp\u003eReturn how many \u003ca href = \"http://en.wikipedia.org/wiki/Hexagonal_grid\"\u003eHexagonal Tiling\u003c/a\u003e grid points there are inside a circle of radius \u003ci\u003er\u003c/i\u003e centred at (0,0) (including points on the edge).  Assume that a Hexagonal Tiling grid is a \u003ca href = \"http://en.wikipedia.org/wiki/Regular_tiling\"\u003e2D Regular Hexagonal Tessellation\u003c/a\u003e with equal edges of size \u003ci\u003ee\u003c/i\u003e=1.\u003c/p\u003e\u003cp\u003eFor symmetry purposes, assume that (0,0) point is a \u003ci\u003evacancy\u003c/i\u003e; i.e., there \u003ci\u003eare\u003c/i\u003e points at (\u0026plusmn;1,0), (\u0026plusmn;1/2,\u0026plusmn;\u0026radic;3/2), etcetera.\u003c/p\u003e\u003cp\u003eNeither \u003cb\u003estring operations\u003c/b\u003e nor \u003cb\u003einterpolations\u003c/b\u003e are allowed!\u003c/p\u003e","function_template":"function n = hexagonal_tiling_dots_in_circle(r)\r\n  n = r;\r\nend","test_suite":"%%\r\nuser_solution = fileread('hexagonal_tiling_dots_in_circle.m');\r\nassert(isempty(strfind(user_solution,'regexp')));\r\nassert(isempty(strfind(user_solution,'2str')));\r\nassert(isempty(strfind(user_solution,'str2')));\r\nassert(isempty(strfind(user_solution,'interp')));\r\nassert(isempty(strfind(user_solution,'printf')));\r\nassert(isempty(strfind(user_solution,'assert')));\r\n\r\n%%\r\nr = 0;\r\nN_correct = 0;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 0.5;\r\nN_correct = 0;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 1;\r\nN_correct = 6;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 1.5;\r\nN_correct = 6;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 2;\r\nN_correct = 12;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 2.5;\r\nN_correct = 12;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 3;\r\nN_correct = 24;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 5;\r\nN_correct = 60;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 7.5;\r\nN_correct = 138;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 10;\r\nN_correct = 246;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 15;\r\nN_correct = 552;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 20;\r\nN_correct = 960;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 25;\r\nN_correct = 1506;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 50;\r\nN_correct = 6024;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n\r\n%%\r\nr = 100;\r\nN_correct = 24186;\r\nassert(isequal(hexagonal_tiling_dots_in_circle(r),N_correct));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":10352,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":29,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":20,"created_at":"2013-05-05T10:39:46.000Z","updated_at":"2026-03-25T00:01:03.000Z","published_at":"2013-05-05T10:54:39.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn how many\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Hexagonal_grid\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eHexagonal Tiling\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e grid points there are inside a circle of radius\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003er\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e centred at (0,0) (including points on the edge). Assume that a Hexagonal Tiling grid is a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Regular_tiling\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2D Regular Hexagonal Tessellation\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e with equal edges 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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ee\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e=1.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor symmetry purposes, assume that (0,0) point is a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003evacancy\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e; i.e., there\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eare\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e points at (±1,0), (±1/2,±√3/2), etcetera.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eNeither\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\u003estring operations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e nor\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\u003einterpolations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are allowed!\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":1283,"title":"Points on a Sphere","description":"Given a sphere of radius R, determine how many points on the surface of that sphere have three integer coordinates.  Do not output the actual coordinates, but just the number of points.\r\n\r\nFor example, a sphere of radius 1 has 6 points with three integer coordinates:\r\n\r\n* (1,0,0)\r\n* (-1,0,0)\r\n* (0,-1,0)\r\n* (0,1,0)\r\n* (0,0,1)\r\n* (0,0,-1)\r\n\r\nYour output of surface_points(1) would be 6.  Good luck!","description_html":"\u003cp\u003eGiven a sphere of radius R, determine how many points on the surface of that sphere have three integer coordinates.  Do not output the actual coordinates, but just the number of points.\u003c/p\u003e\u003cp\u003eFor example, a sphere of radius 1 has 6 points with three integer coordinates:\u003c/p\u003e\u003cul\u003e\u003cli\u003e(1,0,0)\u003c/li\u003e\u003cli\u003e(-1,0,0)\u003c/li\u003e\u003cli\u003e(0,-1,0)\u003c/li\u003e\u003cli\u003e(0,1,0)\u003c/li\u003e\u003cli\u003e(0,0,1)\u003c/li\u003e\u003cli\u003e(0,0,-1)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eYour output of surface_points(1) would be 6.  Good luck!\u003c/p\u003e","function_template":"function y = surface_points(r)\r\ny=6;\r\nend","test_suite":"%%\r\nx = 1; y_correct = 6;\r\nassert(isequal(surface_points(x),y_correct))\r\n%%\r\nx = 1024; y_correct = 6;\r\nassert(isequal(surface_points(x),y_correct))\r\n%%\r\nx = 7581; y_correct = 108270;\r\nassert(isequal(surface_points(x),y_correct))\r\n%%\r\nx = 450; y_correct = 2550;\r\nassert(isequal(surface_points(x),y_correct))\r\n%%\r\nx = 123456; y_correct = 19350;\r\nassert(isequal(surface_points(x),y_correct))\r\n%%\r\nx=ceil(rand*8); y_correct=[6 30 30 150 510 4590 4590 43470];\r\nassert(isequal(surface_points(factorial(x+1)),y_correct(x)))","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":26,"test_suite_updated_at":"2013-02-22T17:25:38.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-02-20T16:48:12.000Z","updated_at":"2026-02-16T11:16:05.000Z","published_at":"2013-02-20T16:49:36.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a sphere of radius R, determine how many points on the surface of that sphere have three integer coordinates. Do not output the actual coordinates, but just the number of points.\u003c/w:t\u003e\u003c/w:r\u003e\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 example, a sphere of radius 1 has 6 points with three integer coordinates:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(1,0,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\u003e(-1,0,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\u003e(0,-1,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\u003e(0,1,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\u003e(0,0,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\u003e(0,0,-1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour output of surface_points(1) would be 6. 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":1452,"title":"Minimum Distance between two N-sided Polygons","description":"This Challenge is to determine the minimum distance between two non-overlapping polygons. The input is a cell array of two vectors that represent the sequential points of 3 to 100 sided polygons. [x0 y0 x1 y1 ... xn yn]\r\n\r\n*Input:* polycell={[0 0 0 5 4 5 4 0] [2.5 5.5 3 9 -2 5.6]};\r\n\r\n*Output:* 0.5  \r\n\r\n\r\nRelated Challenges:\r\n\r\n1) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1446-minimum-distance-point-to-segment Minimum Distance Point to Segment\u003e\r\n\r\n2) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1457-usc-spring-2013-acm-walking-on-thin-ice USC Spring 2013 ACM Walking on Thin Ice\u003e","description_html":"\u003cp\u003eThis Challenge is to determine the minimum distance between two non-overlapping polygons. The input is a cell array of two vectors that represent the sequential points of 3 to 100 sided polygons. [x0 y0 x1 y1 ... xn yn]\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e polycell={[0 0 0 5 4 5 4 0] [2.5 5.5 3 9 -2 5.6]};\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e 0.5\u003c/p\u003e\u003cp\u003eRelated Challenges:\u003c/p\u003e\u003cp\u003e1) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1446-minimum-distance-point-to-segment\"\u003eMinimum Distance Point to Segment\u003c/a\u003e\u003c/p\u003e\u003cp\u003e2) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1457-usc-spring-2013-acm-walking-on-thin-ice\"\u003eUSC Spring 2013 ACM Walking on Thin Ice\u003c/a\u003e\u003c/p\u003e","function_template":"function pdistmin=PolytoPol(polycell)\r\n% Convert [x0 y0 x1 y1 ... xn yn] to nx2 array\r\n% Length of polycell{1} may vary from polycell{2}\r\n p1=reshape(polycell{1},2,[])';\r\n p2=reshape(polycell{2},2,[])';\r\n \r\n pdistmin=0;\r\nend","test_suite":"polycell={[0 0 5 10 10 0] [5 -1 6 -5 5 -5]};\r\np2p_min=PolytoPol(polycell);\r\nassert(abs(p2p_min-1)\u003c.01);\r\n%%\r\npolycell={[0 0 0 5 4 5 4 0] [2.5 5.5 3 9 -2 5.6]};\r\np2p_min=PolytoPol(polycell);\r\nassert(abs(p2p_min-0.5)\u003c.01);\r\n%%\r\npolycell={[0 10 0 90 50 50 100 90 100 10] [0 110 100 110 50 70]};\r\np2p_min=PolytoPol(polycell);\r\nassert(abs(p2p_min-15.617376)\u003c.01);\r\n%%\r\npolycell={[0 110 100 110 50 70] [20 5 50 7 30 5]};\r\np2p_min=PolytoPol(polycell);\r\nassert(abs(p2p_min-63)\u003c.01);\r\n%%\r\npolycell={[-5 -5 -4 -4 -3 -3 -2 -2 5 5 5 0] [6 10 6 -10 20 0]};\r\np2p_min=PolytoPol(polycell);\r\nassert(abs(p2p_min-1)\u003c.01);\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":27,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":20,"created_at":"2013-04-24T01:39:41.000Z","updated_at":"2026-02-16T10:57:04.000Z","published_at":"2013-04-24T02:03:10.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis Challenge is to determine the minimum distance between two non-overlapping polygons. The input is a cell array of two vectors that represent the sequential points of 3 to 100 sided polygons. [x0 y0 x1 y1 ... xn yn]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e polycell={[0 0 0 5 4 5 4 0] [2.5 5.5 3 9 -2 5.6]};\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\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 0.5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRelated Challenges:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1446-minimum-distance-point-to-segment\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eMinimum Distance Point to Segment\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1457-usc-spring-2013-acm-walking-on-thin-ice\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eUSC Spring 2013 ACM Walking on Thin Ice\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1493,"title":"Dots in a Diamond","description":"Return how many \u003chttp://en.wikipedia.org/wiki/Diamond_cubic Diamond Cubic\u003e lattice grid points there are inside a 3D sphere of radius _r_ centred at (0,0,0) (including points on the edge).  \r\n\r\nSet the distance between two adjacent lattice grid points to be _e_ =1. In addition, assume that (0,0,0) is a grid point.\r\n\r\nNeither *string operations* nor *interpolations* are allowed!","description_html":"\u003cp\u003eReturn how many \u003ca href = \"http://en.wikipedia.org/wiki/Diamond_cubic\"\u003eDiamond Cubic\u003c/a\u003e lattice grid points there are inside a 3D sphere of radius \u003ci\u003er\u003c/i\u003e centred at (0,0,0) (including points on the edge).\u003c/p\u003e\u003cp\u003eSet the distance between two adjacent lattice grid points to be \u003ci\u003ee\u003c/i\u003e =1. In addition, assume that (0,0,0) is a grid point.\u003c/p\u003e\u003cp\u003eNeither \u003cb\u003estring operations\u003c/b\u003e nor \u003cb\u003einterpolations\u003c/b\u003e are allowed!\u003c/p\u003e","function_template":"function n = dots_in_diamond(r)\r\n  n = r;\r\nend","test_suite":"%%\r\nuser_solution = fileread('dots_in_diamond.m');\r\nassert(isempty(strfind(user_solution,'regexp')));\r\nassert(isempty(strfind(user_solution,'2str')));\r\nassert(isempty(strfind(user_solution,'str2')));\r\nassert(isempty(strfind(user_solution,'interp')));\r\nassert(isempty(strfind(user_solution,'printf')));\r\nassert(isempty(strfind(user_solution,'assert')));\r\n\r\n%%\r\nr = 0;\r\nN_correct = 1;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 0.5;\r\nN_correct = 1;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 1;\r\nN_correct = 5;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 1.5;\r\nN_correct = 5;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 1.74;\r\nN_correct = 17;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 2;\r\nN_correct = 29;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 2.5;\r\nN_correct = 35;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 3;\r\nN_correct = 87;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 4;\r\nN_correct = 167;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 5;\r\nN_correct = 357;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 6;\r\nN_correct = 633;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 7;\r\nN_correct = 943;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 8;\r\nN_correct = 1371;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 9;\r\nN_correct = 1963;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 10;\r\nN_correct = 2809;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 12.5;\r\nN_correct = 5359;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 15;\r\nN_correct = 9249;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 17.5;\r\nN_correct = 14451;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 20;\r\nN_correct = 21777;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 22.5;\r\nN_correct = 31075;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n\r\n%%\r\nr = 25;\r\nN_correct = 42509;\r\nassert(isequal(dots_in_diamond(r),N_correct));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":10352,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":"2013-05-10T08:33:38.000Z","rescore_all_solutions":false,"group_id":20,"created_at":"2013-05-08T09:16:44.000Z","updated_at":"2026-02-16T10:39:28.000Z","published_at":"2013-05-08T09:58:42.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn how many\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Diamond_cubic\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eDiamond Cubic\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e lattice grid points there are inside a 3D sphere of radius\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003er\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e centred at (0,0,0) (including points on the edge).\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eSet the distance between two adjacent lattice grid points to be\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ee\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e =1. In addition, assume that (0,0,0) is a grid point.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eNeither\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\u003estring operations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e nor\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\u003einterpolations\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are allowed!\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":1387,"title":"Points on a circle.","description":"This problem is related to \u003curl=http://www.mathworks.com/matlabcentral/cody/problems/1283-points-on-a-sphere\u003eProblem 1283, Points on a Sphere.\u003e  In this case, instead of a sphere, you have a circle.  Given a radius R, calculate the number of points on the circumference of the circle that have two integer coordinates.  For a circle of radius 5, you would have 12 points:\r\n\r\n* (0, 5) and (0, -5)\r\n* (5, 0) and (-5, 0)\r\n* (4, 3) and (4, -3)\r\n* (-4, 3) and (-4, -3)\r\n* (3, 4) and (3, -4)\r\n* (-3, 4) and (-3, -4)\r\n\r\nSome radii are quite large, so watch out.  Good luck!","description_html":"\u003cp\u003eThis problem is related to \u003ca href = \"url=http://www.mathworks.com/matlabcentral/cody/problems/1283-points-on-a-sphere\u0026gt;Problem\"\u003e1283, Points on a Sphere.\u003c/a\u003e  In this case, instead of a sphere, you have a circle.  Given a radius R, calculate the number of points on the circumference of the circle that have two integer coordinates.  For a circle of radius 5, you would have 12 points:\u003c/p\u003e\u003cul\u003e\u003cli\u003e(0, 5) and (0, -5)\u003c/li\u003e\u003cli\u003e(5, 0) and (-5, 0)\u003c/li\u003e\u003cli\u003e(4, 3) and (4, -3)\u003c/li\u003e\u003cli\u003e(-4, 3) and (-4, -3)\u003c/li\u003e\u003cli\u003e(3, 4) and (3, -4)\u003c/li\u003e\u003cli\u003e(-3, 4) and (-3, -4)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eSome radii are quite large, so watch out.  Good luck!\u003c/p\u003e","function_template":"function y = circle_points(r)\r\n  y = r;\r\nend","test_suite":"%%\r\nassert(isequal(circle_points(1),4))\r\n%%\r\nassert(isequal(circle_points(3),4))\r\n%%\r\nassert(isequal(circle_points(5),12))\r\n%%\r\nassert(isequal(circle_points(65),36))\r\n%%\r\nassert(isequal(circle_points(64090),324))\r\n%%\r\nassert(isequal(circle_points(326441),12))\r\n%%\r\nassert(isequal(circle_points(359125),420))\r\n%%\r\nassert(isequal(circle_points(1000001),36))\r\n%%\r\nassert(isequal(circle_points(2417899275),20))\r\n%%\r\nassert(isequal(circle_points(31432690549),8748))\r\n%%\r\nassert(isequal(circle_points(11472932050385),78732))\r\n%%\r\nassert(isequal(circle_points(1021090952484265),236196))\r\n%%\r\nassert(isequal(circle_points(6095127531752228),78732))\r\n%%\r\nassert(isequal(circle_points(5*circle_points(630209)),12))\r\n%%\r\ny=arrayfun(@(x) circle_points(x),1000:2000);\r\n[m1,m2]=max(y);\r\nassert(isequal(m1-m2,2));\r\n[h1,h2]=hist(y,unique(y));\r\nassert(isequal(prod(h1-h2),1399066124544000))","published":true,"deleted":false,"likes_count":2,"comments_count":5,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":"2018-02-22T17:55:59.000Z","rescore_all_solutions":true,"group_id":20,"created_at":"2013-03-25T18:05:05.000Z","updated_at":"2026-02-16T11:09:55.000Z","published_at":"2013-03-25T18:44:35.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis problem is related to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"url=http://www.mathworks.com/matlabcentral/cody/problems/1283-points-on-a-sphere\u003eProblem\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1283, Points on a Sphere.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e In this case, instead of a sphere, you have a circle. Given a radius R, calculate the number of points on the circumference of the circle that have two integer coordinates. For a circle of radius 5, you would have 12 points:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(0, 5) and (0, -5)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(5, 0) and (-5, 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\u003e(4, 3) and (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\u003e(-4, 3) and (-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\u003e(3, 4) and (3, -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\u003e(-3, 4) and (-3, -4)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSome radii are quite large, so watch out. 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\"}]}"}],"term":"group:\"Computational Geometry II\"","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:\"Computational Geometry II\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"group":[["group:\"Computational Geometry II\"","","\"","Computational Geometry II","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f4f45e4b7e0\u003e":["Computational Geometry II"],"#\u003cMathWorks::Search::Field:0x00007f4f45e4b740\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f4f45e4ad40\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f4f45e4bc40\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f4f45e4bba0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f4f45e4ba60\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f4f45e4b880\u003e":"group:\"Computational Geometry II\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f4f45e4b880\u003e":"group:\"Computational Geometry II\""},"queried_facets":{"#\u003cMathWorks::Search::Field:0x00007f4f45e4b7e0\u003e":["Computational Geometry II"]}},"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":"search","password":"J3bGPZzQ7asjJcCk","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:\"Computational Geometry II\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"group":[["group:\"Computational Geometry II\"","","\"","Computational Geometry II","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f4f45e4b7e0\u003e":["Computational Geometry II"],"#\u003cMathWorks::Search::Field:0x00007f4f45e4b740\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f4f45e4ad40\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f4f45e4bc40\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f4f45e4bba0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f4f45e4ba60\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f4f45e4b880\u003e":"group:\"Computational Geometry II\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f4f45e4b880\u003e":"group:\"Computational Geometry II\""},"queried_facets":{"#\u003cMathWorks::Search::Field:0x00007f4f45e4b7e0\u003e":["Computational Geometry II"]}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":1141,"difficulty_rating":"easy"},{"id":1442,"difficulty_rating":"easy-medium"},{"id":1385,"difficulty_rating":"easy-medium"},{"id":1443,"difficulty_rating":"easy-medium"},{"id":1456,"difficulty_rating":"easy-medium"},{"id":1462,"difficulty_rating":"easy-medium"},{"id":1444,"difficulty_rating":"easy-medium"},{"id":1074,"difficulty_rating":"easy-medium"},{"id":1411,"difficulty_rating":"easy-medium"},{"id":1336,"difficulty_rating":"medium"},{"id":567,"difficulty_rating":"medium"},{"id":1446,"difficulty_rating":"medium"},{"id":1428,"difficulty_rating":"medium"},{"id":1459,"difficulty_rating":"medium"},{"id":1490,"difficulty_rating":"medium"},{"id":1489,"difficulty_rating":"medium-hard"},{"id":1283,"difficulty_rating":"medium-hard"},{"id":1452,"difficulty_rating":"medium-hard"},{"id":1493,"difficulty_rating":"medium-hard"},{"id":1387,"difficulty_rating":"hard"}]}}