{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-04-06T14:01:22.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2026-04-06T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":43183,"title":"Removing vibration!","description":"There are [y] that vary with [x] but y including small useless vibration.\r\n\r\n x=1:10\r\n y=[1.71 2.03 3.28 4.05 5.10 6.82 7.69 8.32 9.95 10.03]\r\n\r\nRemove the vibration using moving average. processed vector yp is calculated follow these method.\r\n\r\nyp(1)=(y(1)+y(2)+y(3))/3\r\n\r\nyp(2)=(y(2)+y(3)+y(4))/3\r\n\r\nyp(3)=(y(3)+y(4)+y(5))/3 ...\r\n\r\n(hint: conv function)\r\n\r\n","description_html":"\u003cp\u003eThere are [y] that vary with [x] but y including small useless vibration.\u003c/p\u003e\u003cpre\u003e x=1:10\r\n y=[1.71 2.03 3.28 4.05 5.10 6.82 7.69 8.32 9.95 10.03]\u003c/pre\u003e\u003cp\u003eRemove the vibration using moving average. processed vector yp is calculated follow these method.\u003c/p\u003e\u003cp\u003eyp(1)=(y(1)+y(2)+y(3))/3\u003c/p\u003e\u003cp\u003eyp(2)=(y(2)+y(3)+y(4))/3\u003c/p\u003e\u003cp\u003eyp(3)=(y(3)+y(4)+y(5))/3 ...\u003c/p\u003e\u003cp\u003e(hint: conv function)\u003c/p\u003e","function_template":"function z = mysmooth(x)\r\n x=1:10\r\n y=[1.71 2.03 3.28 4.05 5.10 6.82 7.69 8.32 9.95 10.03]\r\n z=x\r\nend","test_suite":"%%\r\nx = [1.71 2.03 3.28 4.05 5.10 6.82 7.69 8.32 9.95 10.03];\r\ny_correct = [2.340 3.120 4.143 5.323 6.536 7.610 8.653 9.433];\r\nassert((mean(mysmooth(x)-y_correct)\u003c0.001))\r\n\r\n%%\r\nx=[1 1 1]\r\ny_correct=1\r\nassert((mean(mysmooth(x)-y_correct)\u003c0.001))\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":33533,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":59,"test_suite_updated_at":"2016-10-25T04:24:35.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-08T02:31:36.000Z","updated_at":"2026-03-03T10:50:49.000Z","published_at":"2016-10-08T02:31: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\u003eThere are [y] that vary with [x] but y including small useless vibration.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x=1:10\\n y=[1.71 2.03 3.28 4.05 5.10 6.82 7.69 8.32 9.95 10.03]]]\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\u003eRemove the vibration using moving average. processed vector yp is calculated follow these method.\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\u003eyp(1)=(y(1)+y(2)+y(3))/3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eyp(2)=(y(2)+y(3)+y(4))/3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eyp(3)=(y(3)+y(4)+y(5))/3 ...\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(hint: conv 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":42793,"title":"Fast 1-D Convolution (full shape)","description":"This is the first problem in the \u003chttp://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution fast 1-D convolution series\u003e. This problem asks you to find a fast algorithm to compute the 1-D convolution in its full output shape.  \r\n\r\nThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in *conv* function invoked in the form *conv(u,v,'full')*, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out. \r\n\r\n* Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape Fast 1-D Convolution (same shape)\u003e.","description_html":"\u003cp\u003eThis is the first problem in the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\"\u003efast 1-D convolution series\u003c/a\u003e. This problem asks you to find a fast algorithm to compute the 1-D convolution in its full output shape.\u003c/p\u003e\u003cp\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in \u003cb\u003econv\u003c/b\u003e function invoked in the form \u003cb\u003econv(u,v,'full')\u003c/b\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/p\u003e\u003cul\u003e\u003cli\u003eNext problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape\"\u003eFast 1-D Convolution (same shape)\u003c/a\u003e.\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = fconv1f(u,v)\r\n  y = conv(u,v,'full');   % Extremely inefficient solution!\r\nend","test_suite":"%%\r\n%{\r\n╔═════════════════════════════════════════════════════════════╗\r\n║ Please note that problems in this series are designed for   ║\r\n║ optimizing the code performance, rather than the usual Cody ║\r\n║ \"size\". We are achieving this goal by courtesy of LY Cao's  ║ \r\n║ new scoring function, which automatically grants a better   ║\r\n║ score to a faster solution. Kindly note that simply using   ║\r\n║ the conv function may result in a poor score or even failure║\r\n║ in one of the tests. Suggestions and comments are welcome.  ║\r\n║                                                             ║\r\n║ Thanks \u0026 have fun!                                          ║\r\n║ Peng                                                        ║\r\n╚═════════════════════════════════════════════════════════════╝\r\n%}\r\n\r\n%%\r\nfid = fopen('EvaluateSolution.p','wb'); \r\nfwrite(fid,uint8(sscanf('7630312E30307630302E30300005B01CF7473FB1000000B50000010D000001A93014D309F9979F2A2C808C4F104ACA1480D0378FBCF4FF1C4C94A38C84A4969D0A597F5F12C8D564E7CD9584DF8BDD849A3B8C5FDEB66A3837A064275728B38736860BB79ABC4B3091D37C9A2010BE0378E708E59716738F85AA4AEBC8982C45E6CD45BAD19BD043D16D5834122D405752633CE6BD78ABA0676336E7BCDD4F2E181FF1CE8E9165F6BF30D850ED74385A40BDEB73AD82518B4CF2BB034951B1D23D360EDF335C22C209AAB3857BCEF61D192170FDE9D5449721A6B6DD082257E430059753696F1C5CD66E6B09AD24270B0335E830203EACA5BDF3E2A57620D5DB44A96AFCDE0387EF112F2A83FBF90E4AF09F9D4FCAA22134055610D0F7B55568D50A52CD5C46A3F0CA655C1B68','%2x')));\r\nfclose(fid);\r\n\r\n%%\r\nu = 1; v = 1;\r\ny_correct = 1;\r\nassert(isequal(fconv1f(u,v),y_correct))\r\n\r\n%%\r\nu = 1:10; v = 1:5;\r\ny_correct = [1,4,10,20,35,50,65,80,95,110,114,106,85,50];\r\nassert(all(abs(fconv1f(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = [2 -4 0 1].'; v = [1:5].';\r\ny_correct = [2,0,-2,-3,-4,-17,4,5].';\r\nassert(all(abs(fconv1f(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = rand(20,1); v = rand(10,1);\r\ny_correct = conv(u,v,'full');\r\nassert(all(abs(fconv1f(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\n% Large data size\r\nglobal sol_score\r\nu = rand(8e5,1); v = rand(1e5,1);\r\nt = builtin('tic');\r\ny = fconv1f(u,v);\r\nsol_score = 50*builtin('toc',t);\r\nAbsTol = 1e-6;   % Maximum absolute error tolerance\r\npass = EvaluateSolution(u,v,y,AbsTol);  \r\nassert(pass);\r\n\r\n%%\r\n% New scoring function by LY Cao\r\nglobal sol_score\r\nfid = fopen('score.p','wb');\r\nfwrite(fid,sscanf('7630312E30307630302E30300008501CD77E9FB100000035000001110000018422762999A8C1DE50537BEE443F4D73651F830FC6C78ADFB7DF68DF98823F565884DC58E21C7E397E3D26E4FFEA9A0D83589ABB5C0B0B553B44CFD79C9B272D11DF1965AD538598E8319529727DF4C4CF36A6016DD7816544AE5A8F64C9B2D9D0C4B94DD5EDF14595CBFE3D402647499EA3D9D125AC927454ED85973BCD1AAEA536D5A6CDDCD78A0211E8179603FFE12E4AB0E4704EA195704428700BAE5C4DFD42FF1A8760EDF2721F9724498ECC9F957735E7A3CDB9630DB17DF92ACE8F486706020E0A8D022D14BC313879724760AE20D67F572DD85211E4BEA45CDF3E22976253F113AEA96C1FF907329E4BD429BCFC6331077DA21F05D791DA6ECCF680D2E23AC77DFCE5C1D9869D3098F5B89FF92A','%2x'));\r\nfclose(fid);\r\nscore(sol_score);\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":6,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":34,"test_suite_updated_at":"2016-04-04T03:53:09.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-04-02T21:05:59.000Z","updated_at":"2025-12-09T13:00:47.000Z","published_at":"2016-04-03T19:56:23.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is the first problem in the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efast 1-D convolution series\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. This problem asks you to find a fast algorithm to compute the 1-D convolution in its full output shape.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in\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\u003econv\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e function invoked in the form\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\u003econv(u,v,'full')\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\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\u003eNext problem:\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/42794-fast-1-d-convolution-same-shape\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFast 1-D Convolution (same shape)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":834,"title":"Solve Quadratic : No * - or key functions permitted","description":"Solve the quadratic equation *ax^2+bx+c=0*.  However, some of the normal functions and symbols are not allowed.\r\n\r\nx=[ -b +/- sqrt ( b^2 - 4ac ) ] / ( 2a ) \r\n\r\n\r\n*Unallowed functions and symbols:* \r\n\r\nroots mtimes cross prod cumprod times mldivide mrdivide dot numstr int2str dec2bin * / \\ - ^ '\r\n\r\nDerivative of Aurelien's \u003chttp://www.mathworks.com/matlabcentral/cody/problems/813-multiply-2-numbers Cody 813 Multiply 2 numbers\u003e\r\n\r\nAlso related to \u003chttp://www.mathworks.com/matlabcentral/cody/problems/833-find-third-side-of-a-right-triangle-given-hypotenuse-and-a-side-no-or-other-functions-allowed/solutions/map Cody 833 Side of a Triangle\u003e \r\n\r\nTest suite \"disallowed function usage check\" courtesy of Aurelien Queffurust.\r\n\r\nExample : \r\n\r\n*Input*\r\n\r\na= 1; b= 1; c=1\r\n\r\n*Output* \r\n\r\n x(1)= -0.5+0.866i; x(2)= -0.5-0.866i","description_html":"\u003cp\u003eSolve the quadratic equation \u003cb\u003eax^2+bx+c=0\u003c/b\u003e.  However, some of the normal functions and symbols are not allowed.\u003c/p\u003e\u003cp\u003ex=[ -b +/- sqrt ( b^2 - 4ac ) ] / ( 2a )\u003c/p\u003e\u003cp\u003e\u003cb\u003eUnallowed functions and symbols:\u003c/b\u003e\u003c/p\u003e\u003cp\u003eroots mtimes cross prod cumprod times mldivide mrdivide dot numstr int2str dec2bin * / \\ - ^ '\u003c/p\u003e\u003cp\u003eDerivative of Aurelien's \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/813-multiply-2-numbers\"\u003eCody 813 Multiply 2 numbers\u003c/a\u003e\u003c/p\u003e\u003cp\u003eAlso related to \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/833-find-third-side-of-a-right-triangle-given-hypotenuse-and-a-side-no-or-other-functions-allowed/solutions/map\"\u003eCody 833 Side of a Triangle\u003c/a\u003e\u003c/p\u003e\u003cp\u003eTest suite \"disallowed function usage check\" courtesy of Aurelien Queffurust.\u003c/p\u003e\u003cp\u003eExample :\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput\u003c/b\u003e\u003c/p\u003e\u003cp\u003ea= 1; b= 1; c=1\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput\u003c/b\u003e\u003c/p\u003e\u003cpre\u003e x(1)= -0.5+0.866i; x(2)= -0.5-0.866i\u003c/pre\u003e","function_template":"function x = quadratic(a,b,c)\r\n  x(1)=(-b+sqrt(b^2-4*a*c))/(2*a); % Must delete symbol check will fail\r\n  x(2)=(-b-sqrt(b^2-4*a*c))/(2*a);\r\nend","test_suite":"%%\r\n% Courtesy of Aurelien Queffurust\r\nfiletext = fileread('quadratic.m');\r\nassert(isempty(strfind(filetext, '*')),'sign * forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')))\r\nassert(isempty(strfind(filetext, 'times')))\r\nassert(isempty(strfind(filetext, 'mldivide')))\r\nassert(isempty(strfind(filetext, 'mrdivide')))\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')))\r\nassert(isempty(strfind(filetext, '-')))\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')))\r\nassert(isempty(strfind(filetext, '''')),'string forbidden')\r\nassert(isempty(strfind(filetext, 'num2str')))\r\nassert(isempty(strfind(filetext, 'int2str')))\r\nassert(isempty(strfind(filetext, 'dec2bin')))\r\nassert(isempty(strfind(filetext, 'roots')))\r\n%%\r\na=1;b=1;c=1;\r\nrad=sqrt(b*b-4*a*c);\r\nxe(1)=(-b+rad)/(2*a);\r\nxe(2)=(-b-rad)/(2*a)\r\n\r\nxq = quadratic(a,b,c)\r\n\r\nassert(isequal(round(1e6*xq)/1e6,round(1e6*xe)/1e6) || isequal(round(1e6*xq(2:-1:1))/1e6,round(1e6*xe)/1e6))\r\n%%\r\na=1;b=4;c=1;\r\nrad=sqrt(b*b-4*a*c);\r\nxe(1)=(-b+rad)/(2*a);\r\nxe(2)=(-b-rad)/(2*a)\r\n\r\nxq = quadratic(a,b,c)\r\n\r\nassert(isequal(round(1e6*xq)/1e6,round(1e6*xe)/1e6) || isequal(round(1e6*xq(2:-1:1))/1e6,round(1e6*xe)/1e6))\r\n%%\r\na=1;b=4;c=1;\r\na=a+rand\r\nrad=sqrt(b*b-4*a*c);\r\nxe(1)=(-b+rad)/(2*a);\r\nxe(2)=(-b-rad)/(2*a)\r\n\r\nxq = quadratic(a,b,c)\r\n\r\nassert(isequal(round(1e6*xq)/1e6,round(1e6*xe)/1e6) || isequal(round(1e6*xq(2:-1:1))/1e6,round(1e6*xe)/1e6))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":34,"test_suite_updated_at":"2012-07-16T12:17:04.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-07-15T21:45:22.000Z","updated_at":"2025-09-27T21:24:29.000Z","published_at":"2012-07-15T22:25: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\u003eSolve the quadratic equation\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\u003eax^2+bx+c=0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. However, some of the normal functions and symbols are not allowed.\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\u003ex=[ -b +/- sqrt ( b^2 - 4ac ) ] / ( 2a )\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\u003eUnallowed functions and symbols:\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\u003eroots mtimes cross prod cumprod times mldivide mrdivide dot numstr int2str dec2bin * / \\\\ - ^ '\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\u003eDerivative of Aurelien'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/813-multiply-2-numbers\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody 813 Multiply 2 numbers\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\u003eAlso 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=\\\"http://www.mathworks.com/matlabcentral/cody/problems/833-find-third-side-of-a-right-triangle-given-hypotenuse-and-a-side-no-or-other-functions-allowed/solutions/map\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody 833 Side of a Triangle\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\u003eTest suite \\\"disallowed function usage check\\\" courtesy of Aurelien Queffurust.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample :\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ea= 1; b= 1; c=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\u003eOutput\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x(1)= -0.5+0.866i; x(2)= -0.5-0.866i]]\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":42795,"title":" Fast 1-D Convolution (valid shape) ","description":"Pursuant to the first problem in the \u003chttp://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution fast 1-D convolution series\u003e, this problem asks for the fast algorithm to compute the 1-D convolution in its \"valid\" output shape.  \r\n\r\nThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in *conv* function invoked in the form *conv(u,v,'valid')*, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out. \r\n\r\n* Previous problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape Fast 1-D Convolution (same shape)\u003e.","description_html":"\u003cp\u003ePursuant to the first problem in the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\"\u003efast 1-D convolution series\u003c/a\u003e, this problem asks for the fast algorithm to compute the 1-D convolution in its \"valid\" output shape.\u003c/p\u003e\u003cp\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in \u003cb\u003econv\u003c/b\u003e function invoked in the form \u003cb\u003econv(u,v,'valid')\u003c/b\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/p\u003e\u003cul\u003e\u003cli\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape\"\u003eFast 1-D Convolution (same shape)\u003c/a\u003e.\u003c/li\u003e\u003c/ul\u003e","function_template":"function w = fconv1v(u,v)\r\n  % Extremely inefficient solution not guaranteed to pass all tests :-(\r\n  w = conv(u,v,'valid'); \r\nend","test_suite":"%%\r\n%{\r\n╔═════════════════════════════════════════════════════════════╗\r\n║ Please note that problems in this series are designed for   ║\r\n║ optimizing the code performance, rather than the usual Cody ║\r\n║ \"size\". We are achieving this goal by courtesy of LY Cao's  ║ \r\n║ new scoring function, which automatically grants a better   ║\r\n║ score to a faster solution. Kindly note that simply using   ║\r\n║ the conv function may result in a poor score or even failure║\r\n║ in one of the tests. Suggestions and comments are welcome.  ║\r\n║                                                             ║\r\n║ Thanks \u0026 have fun!                                          ║\r\n║ Peng                                                        ║\r\n╚═════════════════════════════════════════════════════════════╝\r\n%}\r\n\r\n%%\r\nfid = fopen('EvaluateSolution.p','wb'); \r\nfwrite(fid,uint8(sscanf('7630312E30307630302E3030000CF01CCC561FB1000000C30000012D000001D160E44E2EC6DB5CE66B30F9B560AF40D6A7226365293F6413AE84ABD44D4C7EE5C617DCDAC2521B24B2951C23F50BA9DAA4179B35DCED27A697FC9CA9A308698729973CACEC16670C077236F96E9D16612152B0C32FC57E4755E80E40AC876804B7835D9703BC5A1D6FC519FDEDE22237DC59455FF0014FEBCEF1CB2A840158E11CDD5D6C78D594F50B575A4DF9FB54705F2C6D40341F12CE207B892CBEDEC018A1F94CFA1D5FBB9E1912BA424CD5C6C422D6F3451A8BDD2543834B3FFAD3107D8F16C78D75DD9F3AD197D5591B1686E190D8DF4B5EF3AC28C641296E92FB02BC395D442C03480E156E48F8B61AA3C6F1526AA95C1C466C77A3803AF8523098B0A3ED10A07E2F93274DC8207B05A572988754AAC211A330C2FEC7928CFD51D3A6FBDD9FFA6036C948E0C4239A16','%2x')));\r\nfclose(fid);\r\n\r\n%%\r\nu = 1; v = 1;\r\ny_correct = 1;\r\nassert(isequal(fconv1v(u,v),y_correct))\r\n\r\n%%\r\nu = 1:10; v = 1:5;\r\ny_correct = conv(u,v,'valid');\r\nassert(all(abs(fconv1v(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = 1:5; v = 1:10;\r\ny_correct = zeros(1,0);\r\nassert(isequal(fconv1v(u,v),y_correct))\r\n\r\n%%\r\nu = rand(20,1); v = rand(10,1);\r\ny_correct = conv(u,v,'valid');\r\nassert(all(abs(fconv1v(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = rand(10,1); v = rand(20,1);\r\ny_correct = zeros(0,1);\r\nassert(isequal(fconv1v(u,v),y_correct))\r\n\r\n%%\r\n% Large data size\r\nglobal sol_score\r\nAbsTol = 1e-6;   % Maximum absolute error tolerance\r\nuu = rand(5e6,15); vv = rand(2e5,15);\r\nfor iter = 15:-1:1\r\n    u = uu(:,iter); v = vv(:,iter);\r\n    t = builtin('tic');\r\n    y = fconv1v(u,v);\r\n    timeSpan(iter) = builtin('toc',t);\r\n    pass(iter) = EvaluateSolution(u,v,y,AbsTol);  \r\nend\r\nsol_score = sum(timeSpan);\r\nassert(all(pass));\r\n\r\n%%\r\n% New scoring function by LY Cao\r\nglobal sol_score\r\nfid = fopen('score.p','wb');\r\nfwrite(fid,sscanf('7630312E30307630302E30300008501CD77E9FB100000035000001110000018422762999A8C1DE50537BEE443F4D73651F830FC6C78ADFB7DF68DF98823F565884DC58E21C7E397E3D26E4FFEA9A0D83589ABB5C0B0B553B44CFD79C9B272D11DF1965AD538598E8319529727DF4C4CF36A6016DD7816544AE5A8F64C9B2D9D0C4B94DD5EDF14595CBFE3D402647499EA3D9D125AC927454ED85973BCD1AAEA536D5A6CDDCD78A0211E8179603FFE12E4AB0E4704EA195704428700BAE5C4DFD42FF1A8760EDF2721F9724498ECC9F957735E7A3CDB9630DB17DF92ACE8F486706020E0A8D022D14BC313879724760AE20D67F572DD85211E4BEA45CDF3E22976253F113AEA96C1FF907329E4BD429BCFC6331077DA21F05D791DA6ECCF680D2E23AC77DFCE5C1D9869D3098F5B89FF92A','%2x'));\r\nfclose(fid);\r\nscore(sol_score);","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":"2016-04-05T21:09:16.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2016-04-02T21:30:34.000Z","updated_at":"2025-12-21T14:08:51.000Z","published_at":"2016-04-04T01:47: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\u003ePursuant to the first problem in the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efast 1-D convolution series\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, this problem asks for the fast algorithm to compute the 1-D convolution in its \\\"valid\\\" output shape.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in\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\u003econv\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e function invoked in the form\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\u003econv(u,v,'valid')\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\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\u003ePrevious problem:\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/42794-fast-1-d-convolution-same-shape\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFast 1-D Convolution (same shape)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42794,"title":" Fast 1-D Convolution (same shape) ","description":"Pursuant to the first problem in the \u003chttp://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution fast 1-D convolution series\u003e, this problem asks for the fast algorithm to compute the 1-D convolution with the same input-output shape.  \r\n\r\nThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in *conv* function invoked in the form *conv(u,v,'same')*, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out. \r\n\r\n* Previous problem:  \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42793-fast-1-d-convolution-full-shape Fast 1-D Convolution (full shape)\u003e\r\n* Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42795-fast-1-d-convolution-valid-shape Fast 1-D Convolution (valid shape)\u003e\r\n","description_html":"\u003cp\u003ePursuant to the first problem in the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\"\u003efast 1-D convolution series\u003c/a\u003e, this problem asks for the fast algorithm to compute the 1-D convolution with the same input-output shape.\u003c/p\u003e\u003cp\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in \u003cb\u003econv\u003c/b\u003e function invoked in the form \u003cb\u003econv(u,v,'same')\u003c/b\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/p\u003e\u003cul\u003e\u003cli\u003ePrevious problem:  \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42793-fast-1-d-convolution-full-shape\"\u003eFast 1-D Convolution (full shape)\u003c/a\u003e\u003c/li\u003e\u003cli\u003eNext problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42795-fast-1-d-convolution-valid-shape\"\u003eFast 1-D Convolution (valid shape)\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = fconv1s(u,v)\r\n  % Extremely inefficient solution not guaranteed to pass all tests :-(\r\n  y = conv(u,v,'same'); \r\nend","test_suite":"%%\r\n%{\r\n╔═════════════════════════════════════════════════════════════╗\r\n║ Please note that problems in this series are designed for   ║\r\n║ optimizing the code performance, rather than the usual Cody ║\r\n║ \"size\". We are achieving this goal by courtesy of LY Cao's  ║ \r\n║ new scoring function, which automatically grants a better   ║\r\n║ score to a faster solution. Kindly note that simply using   ║\r\n║ the conv function may result in a poor score or even failure║\r\n║ in one of the tests. Suggestions and comments are welcome.  ║\r\n║                                                             ║\r\n║ Thanks \u0026 have fun!                                          ║\r\n║ Peng                                                        ║\r\n╚═════════════════════════════════════════════════════════════╝\r\n%}\r\n\r\n%%\r\nfid = fopen('EvaluateSolution.p','wb'); \r\nfwrite(fid,uint8(sscanf('7630312E30307630302E3030000E201CC0225FB10000010B000001480000023C141D1F2F8C075F9CDC9AA9EE4F066DD1BE8B37851CBC980DC3CFCB6C55FAA40EAEED061766137EB39A214C865F6410AAF263010C3B9D012F499C4718371499BB689324D8892718476958CEAC4EE884BB215750071FA3AEE658AB639696B588AA35864A8AF99C9981E6AB14F1BE31F76F320D6F1EA110DE5A9E1C9F4597921FF711410412A4E9C4AA1026E997F054CBEF2A6FC2607C95B65D62747B293B8A86A0D33830E20CCB930D6986416727FFE5CB77FE03A0722EE2B47A07493392D53C4C7A0995EDFA31DB344F2C390E67574523D59403673E343AB6E1A5D83D0EE6B4E784AAA80184B8295937D1648E6A92E82360BE54C82D837FFBE28102BB1EF99FEB94473DB16240A68474D4E8DA84CD1B6DB5AA3FB2921D378C5D78A3A006E36169618AF0F4A18645472518E158E85BB81BC6CBEDCD7A861A67E1ECC712442F423199F4EB715F9493CA','%2x')));\r\nfclose(fid);\r\n\r\n%%\r\nu = 1; v = 1;\r\ny_correct = 1;\r\nassert(isequal(fconv1s(u,v),y_correct))\r\n\r\n%%\r\nu = 1:10; v = 1:5;\r\ny_correct = conv(u,v,'same');\r\nassert(all(abs(fconv1s(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = 1:5; v = 1:10;\r\ny_correct = conv(u,v,'same');\r\nassert(all(abs(fconv1s(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = rand(20,1); v = rand(10,1);\r\ny_correct = conv(u,v,'same');\r\nassert(all(abs(fconv1s(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = rand(10,1); v = rand(20,1);\r\ny_correct = conv(u,v,'same');\r\nassert(all(abs(fconv1s(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\n% Large data size\r\nglobal sol_score\r\nAbsTol = 1e-6;   % Maximum absolute error tolerance\r\nfor iter = 15:-1:1\r\n    u = rand(5e6,1); v = rand(2e5,1);\r\n    t = builtin('tic');\r\n    y = fconv1s(u,v);\r\n    timeSpan(iter) = builtin('toc',t);\r\n    pass(iter) = EvaluateSolution(u,v,y,AbsTol);  \r\nend\r\nsol_score = sum(timeSpan);\r\nassert(all(pass));\r\n\r\n%%\r\n% New scoring function by LY Cao\r\nglobal sol_score\r\nfid = fopen('score.p','wb');\r\nfwrite(fid,sscanf('7630312E30307630302E30300008501CD77E9FB100000035000001110000018422762999A8C1DE50537BEE443F4D73651F830FC6C78ADFB7DF68DF98823F565884DC58E21C7E397E3D26E4FFEA9A0D83589ABB5C0B0B553B44CFD79C9B272D11DF1965AD538598E8319529727DF4C4CF36A6016DD7816544AE5A8F64C9B2D9D0C4B94DD5EDF14595CBFE3D402647499EA3D9D125AC927454ED85973BCD1AAEA536D5A6CDDCD78A0211E8179603FFE12E4AB0E4704EA195704428700BAE5C4DFD42FF1A8760EDF2721F9724498ECC9F957735E7A3CDB9630DB17DF92ACE8F486706020E0A8D022D14BC313879724760AE20D67F572DD85211E4BEA45CDF3E22976253F113AEA96C1FF907329E4BD429BCFC6331077DA21F05D791DA6ECCF680D2E23AC77DFCE5C1D9869D3098F5B89FF92A','%2x'));\r\nfclose(fid);\r\nscore(sol_score);","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":"2016-04-05T20:53:23.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2016-04-02T21:30:23.000Z","updated_at":"2025-12-21T14:01:33.000Z","published_at":"2016-04-04T01:47:11.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\u003ePursuant to the first problem in the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efast 1-D convolution series\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, this problem asks for the fast algorithm to compute the 1-D convolution with the same input-output shape.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in\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\u003econv\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e function invoked in the form\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\u003econv(u,v,'same')\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\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\u003ePrevious problem: \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/42793-fast-1-d-convolution-full-shape\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFast 1-D Convolution (full shape)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNext problem:\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/42795-fast-1-d-convolution-valid-shape\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFast 1-D Convolution (valid shape)\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\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":43183,"title":"Removing vibration!","description":"There are [y] that vary with [x] but y including small useless vibration.\r\n\r\n x=1:10\r\n y=[1.71 2.03 3.28 4.05 5.10 6.82 7.69 8.32 9.95 10.03]\r\n\r\nRemove the vibration using moving average. processed vector yp is calculated follow these method.\r\n\r\nyp(1)=(y(1)+y(2)+y(3))/3\r\n\r\nyp(2)=(y(2)+y(3)+y(4))/3\r\n\r\nyp(3)=(y(3)+y(4)+y(5))/3 ...\r\n\r\n(hint: conv function)\r\n\r\n","description_html":"\u003cp\u003eThere are [y] that vary with [x] but y including small useless vibration.\u003c/p\u003e\u003cpre\u003e x=1:10\r\n y=[1.71 2.03 3.28 4.05 5.10 6.82 7.69 8.32 9.95 10.03]\u003c/pre\u003e\u003cp\u003eRemove the vibration using moving average. processed vector yp is calculated follow these method.\u003c/p\u003e\u003cp\u003eyp(1)=(y(1)+y(2)+y(3))/3\u003c/p\u003e\u003cp\u003eyp(2)=(y(2)+y(3)+y(4))/3\u003c/p\u003e\u003cp\u003eyp(3)=(y(3)+y(4)+y(5))/3 ...\u003c/p\u003e\u003cp\u003e(hint: conv function)\u003c/p\u003e","function_template":"function z = mysmooth(x)\r\n x=1:10\r\n y=[1.71 2.03 3.28 4.05 5.10 6.82 7.69 8.32 9.95 10.03]\r\n z=x\r\nend","test_suite":"%%\r\nx = [1.71 2.03 3.28 4.05 5.10 6.82 7.69 8.32 9.95 10.03];\r\ny_correct = [2.340 3.120 4.143 5.323 6.536 7.610 8.653 9.433];\r\nassert((mean(mysmooth(x)-y_correct)\u003c0.001))\r\n\r\n%%\r\nx=[1 1 1]\r\ny_correct=1\r\nassert((mean(mysmooth(x)-y_correct)\u003c0.001))\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":33533,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":59,"test_suite_updated_at":"2016-10-25T04:24:35.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-08T02:31:36.000Z","updated_at":"2026-03-03T10:50:49.000Z","published_at":"2016-10-08T02:31: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\u003eThere are [y] that vary with [x] but y including small useless vibration.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x=1:10\\n y=[1.71 2.03 3.28 4.05 5.10 6.82 7.69 8.32 9.95 10.03]]]\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\u003eRemove the vibration using moving average. processed vector yp is calculated follow these method.\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\u003eyp(1)=(y(1)+y(2)+y(3))/3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eyp(2)=(y(2)+y(3)+y(4))/3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eyp(3)=(y(3)+y(4)+y(5))/3 ...\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(hint: conv 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":42793,"title":"Fast 1-D Convolution (full shape)","description":"This is the first problem in the \u003chttp://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution fast 1-D convolution series\u003e. This problem asks you to find a fast algorithm to compute the 1-D convolution in its full output shape.  \r\n\r\nThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in *conv* function invoked in the form *conv(u,v,'full')*, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out. \r\n\r\n* Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape Fast 1-D Convolution (same shape)\u003e.","description_html":"\u003cp\u003eThis is the first problem in the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\"\u003efast 1-D convolution series\u003c/a\u003e. This problem asks you to find a fast algorithm to compute the 1-D convolution in its full output shape.\u003c/p\u003e\u003cp\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in \u003cb\u003econv\u003c/b\u003e function invoked in the form \u003cb\u003econv(u,v,'full')\u003c/b\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/p\u003e\u003cul\u003e\u003cli\u003eNext problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape\"\u003eFast 1-D Convolution (same shape)\u003c/a\u003e.\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = fconv1f(u,v)\r\n  y = conv(u,v,'full');   % Extremely inefficient solution!\r\nend","test_suite":"%%\r\n%{\r\n╔═════════════════════════════════════════════════════════════╗\r\n║ Please note that problems in this series are designed for   ║\r\n║ optimizing the code performance, rather than the usual Cody ║\r\n║ \"size\". We are achieving this goal by courtesy of LY Cao's  ║ \r\n║ new scoring function, which automatically grants a better   ║\r\n║ score to a faster solution. Kindly note that simply using   ║\r\n║ the conv function may result in a poor score or even failure║\r\n║ in one of the tests. Suggestions and comments are welcome.  ║\r\n║                                                             ║\r\n║ Thanks \u0026 have fun!                                          ║\r\n║ Peng                                                        ║\r\n╚═════════════════════════════════════════════════════════════╝\r\n%}\r\n\r\n%%\r\nfid = fopen('EvaluateSolution.p','wb'); \r\nfwrite(fid,uint8(sscanf('7630312E30307630302E30300005B01CF7473FB1000000B50000010D000001A93014D309F9979F2A2C808C4F104ACA1480D0378FBCF4FF1C4C94A38C84A4969D0A597F5F12C8D564E7CD9584DF8BDD849A3B8C5FDEB66A3837A064275728B38736860BB79ABC4B3091D37C9A2010BE0378E708E59716738F85AA4AEBC8982C45E6CD45BAD19BD043D16D5834122D405752633CE6BD78ABA0676336E7BCDD4F2E181FF1CE8E9165F6BF30D850ED74385A40BDEB73AD82518B4CF2BB034951B1D23D360EDF335C22C209AAB3857BCEF61D192170FDE9D5449721A6B6DD082257E430059753696F1C5CD66E6B09AD24270B0335E830203EACA5BDF3E2A57620D5DB44A96AFCDE0387EF112F2A83FBF90E4AF09F9D4FCAA22134055610D0F7B55568D50A52CD5C46A3F0CA655C1B68','%2x')));\r\nfclose(fid);\r\n\r\n%%\r\nu = 1; v = 1;\r\ny_correct = 1;\r\nassert(isequal(fconv1f(u,v),y_correct))\r\n\r\n%%\r\nu = 1:10; v = 1:5;\r\ny_correct = [1,4,10,20,35,50,65,80,95,110,114,106,85,50];\r\nassert(all(abs(fconv1f(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = [2 -4 0 1].'; v = [1:5].';\r\ny_correct = [2,0,-2,-3,-4,-17,4,5].';\r\nassert(all(abs(fconv1f(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = rand(20,1); v = rand(10,1);\r\ny_correct = conv(u,v,'full');\r\nassert(all(abs(fconv1f(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\n% Large data size\r\nglobal sol_score\r\nu = rand(8e5,1); v = rand(1e5,1);\r\nt = builtin('tic');\r\ny = fconv1f(u,v);\r\nsol_score = 50*builtin('toc',t);\r\nAbsTol = 1e-6;   % Maximum absolute error tolerance\r\npass = EvaluateSolution(u,v,y,AbsTol);  \r\nassert(pass);\r\n\r\n%%\r\n% New scoring function by LY Cao\r\nglobal sol_score\r\nfid = fopen('score.p','wb');\r\nfwrite(fid,sscanf('7630312E30307630302E30300008501CD77E9FB100000035000001110000018422762999A8C1DE50537BEE443F4D73651F830FC6C78ADFB7DF68DF98823F565884DC58E21C7E397E3D26E4FFEA9A0D83589ABB5C0B0B553B44CFD79C9B272D11DF1965AD538598E8319529727DF4C4CF36A6016DD7816544AE5A8F64C9B2D9D0C4B94DD5EDF14595CBFE3D402647499EA3D9D125AC927454ED85973BCD1AAEA536D5A6CDDCD78A0211E8179603FFE12E4AB0E4704EA195704428700BAE5C4DFD42FF1A8760EDF2721F9724498ECC9F957735E7A3CDB9630DB17DF92ACE8F486706020E0A8D022D14BC313879724760AE20D67F572DD85211E4BEA45CDF3E22976253F113AEA96C1FF907329E4BD429BCFC6331077DA21F05D791DA6ECCF680D2E23AC77DFCE5C1D9869D3098F5B89FF92A','%2x'));\r\nfclose(fid);\r\nscore(sol_score);\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":6,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":34,"test_suite_updated_at":"2016-04-04T03:53:09.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-04-02T21:05:59.000Z","updated_at":"2025-12-09T13:00:47.000Z","published_at":"2016-04-03T19:56:23.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is the first problem in the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efast 1-D convolution series\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. This problem asks you to find a fast algorithm to compute the 1-D convolution in its full output shape.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in\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\u003econv\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e function invoked in the form\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\u003econv(u,v,'full')\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\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\u003eNext problem:\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/42794-fast-1-d-convolution-same-shape\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFast 1-D Convolution (same shape)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":834,"title":"Solve Quadratic : No * - or key functions permitted","description":"Solve the quadratic equation *ax^2+bx+c=0*.  However, some of the normal functions and symbols are not allowed.\r\n\r\nx=[ -b +/- sqrt ( b^2 - 4ac ) ] / ( 2a ) \r\n\r\n\r\n*Unallowed functions and symbols:* \r\n\r\nroots mtimes cross prod cumprod times mldivide mrdivide dot numstr int2str dec2bin * / \\ - ^ '\r\n\r\nDerivative of Aurelien's \u003chttp://www.mathworks.com/matlabcentral/cody/problems/813-multiply-2-numbers Cody 813 Multiply 2 numbers\u003e\r\n\r\nAlso related to \u003chttp://www.mathworks.com/matlabcentral/cody/problems/833-find-third-side-of-a-right-triangle-given-hypotenuse-and-a-side-no-or-other-functions-allowed/solutions/map Cody 833 Side of a Triangle\u003e \r\n\r\nTest suite \"disallowed function usage check\" courtesy of Aurelien Queffurust.\r\n\r\nExample : \r\n\r\n*Input*\r\n\r\na= 1; b= 1; c=1\r\n\r\n*Output* \r\n\r\n x(1)= -0.5+0.866i; x(2)= -0.5-0.866i","description_html":"\u003cp\u003eSolve the quadratic equation \u003cb\u003eax^2+bx+c=0\u003c/b\u003e.  However, some of the normal functions and symbols are not allowed.\u003c/p\u003e\u003cp\u003ex=[ -b +/- sqrt ( b^2 - 4ac ) ] / ( 2a )\u003c/p\u003e\u003cp\u003e\u003cb\u003eUnallowed functions and symbols:\u003c/b\u003e\u003c/p\u003e\u003cp\u003eroots mtimes cross prod cumprod times mldivide mrdivide dot numstr int2str dec2bin * / \\ - ^ '\u003c/p\u003e\u003cp\u003eDerivative of Aurelien's \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/813-multiply-2-numbers\"\u003eCody 813 Multiply 2 numbers\u003c/a\u003e\u003c/p\u003e\u003cp\u003eAlso related to \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/833-find-third-side-of-a-right-triangle-given-hypotenuse-and-a-side-no-or-other-functions-allowed/solutions/map\"\u003eCody 833 Side of a Triangle\u003c/a\u003e\u003c/p\u003e\u003cp\u003eTest suite \"disallowed function usage check\" courtesy of Aurelien Queffurust.\u003c/p\u003e\u003cp\u003eExample :\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput\u003c/b\u003e\u003c/p\u003e\u003cp\u003ea= 1; b= 1; c=1\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput\u003c/b\u003e\u003c/p\u003e\u003cpre\u003e x(1)= -0.5+0.866i; x(2)= -0.5-0.866i\u003c/pre\u003e","function_template":"function x = quadratic(a,b,c)\r\n  x(1)=(-b+sqrt(b^2-4*a*c))/(2*a); % Must delete symbol check will fail\r\n  x(2)=(-b-sqrt(b^2-4*a*c))/(2*a);\r\nend","test_suite":"%%\r\n% Courtesy of Aurelien Queffurust\r\nfiletext = fileread('quadratic.m');\r\nassert(isempty(strfind(filetext, '*')),'sign * forbidden')\r\nassert(isempty(strfind(filetext, 'mtimes')),'mtimes forbidden')\r\nassert(isempty(strfind(filetext, 'cross')),'cross forbidden')\r\nassert(isempty(strfind(filetext, 'prod')),'prod forbidden')\r\nassert(isempty(strfind(filetext, 'cumprod')))\r\nassert(isempty(strfind(filetext, 'times')))\r\nassert(isempty(strfind(filetext, 'mldivide')))\r\nassert(isempty(strfind(filetext, 'mrdivide')))\r\nassert(isempty(strfind(filetext, '/')),'/ forbidden')\r\nassert(isempty(strfind(filetext, '\\')))\r\nassert(isempty(strfind(filetext, '-')))\r\nassert(isempty(strfind(filetext, '^')),'^ forbidden')\r\nassert(isempty(strfind(filetext, 'dot')))\r\nassert(isempty(strfind(filetext, '''')),'string forbidden')\r\nassert(isempty(strfind(filetext, 'num2str')))\r\nassert(isempty(strfind(filetext, 'int2str')))\r\nassert(isempty(strfind(filetext, 'dec2bin')))\r\nassert(isempty(strfind(filetext, 'roots')))\r\n%%\r\na=1;b=1;c=1;\r\nrad=sqrt(b*b-4*a*c);\r\nxe(1)=(-b+rad)/(2*a);\r\nxe(2)=(-b-rad)/(2*a)\r\n\r\nxq = quadratic(a,b,c)\r\n\r\nassert(isequal(round(1e6*xq)/1e6,round(1e6*xe)/1e6) || isequal(round(1e6*xq(2:-1:1))/1e6,round(1e6*xe)/1e6))\r\n%%\r\na=1;b=4;c=1;\r\nrad=sqrt(b*b-4*a*c);\r\nxe(1)=(-b+rad)/(2*a);\r\nxe(2)=(-b-rad)/(2*a)\r\n\r\nxq = quadratic(a,b,c)\r\n\r\nassert(isequal(round(1e6*xq)/1e6,round(1e6*xe)/1e6) || isequal(round(1e6*xq(2:-1:1))/1e6,round(1e6*xe)/1e6))\r\n%%\r\na=1;b=4;c=1;\r\na=a+rand\r\nrad=sqrt(b*b-4*a*c);\r\nxe(1)=(-b+rad)/(2*a);\r\nxe(2)=(-b-rad)/(2*a)\r\n\r\nxq = quadratic(a,b,c)\r\n\r\nassert(isequal(round(1e6*xq)/1e6,round(1e6*xe)/1e6) || isequal(round(1e6*xq(2:-1:1))/1e6,round(1e6*xe)/1e6))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":34,"test_suite_updated_at":"2012-07-16T12:17:04.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-07-15T21:45:22.000Z","updated_at":"2025-09-27T21:24:29.000Z","published_at":"2012-07-15T22:25: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\u003eSolve the quadratic equation\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\u003eax^2+bx+c=0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. However, some of the normal functions and symbols are not allowed.\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\u003ex=[ -b +/- sqrt ( b^2 - 4ac ) ] / ( 2a )\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\u003eUnallowed functions and symbols:\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\u003eroots mtimes cross prod cumprod times mldivide mrdivide dot numstr int2str dec2bin * / \\\\ - ^ '\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\u003eDerivative of Aurelien'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/813-multiply-2-numbers\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody 813 Multiply 2 numbers\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\u003eAlso 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=\\\"http://www.mathworks.com/matlabcentral/cody/problems/833-find-third-side-of-a-right-triangle-given-hypotenuse-and-a-side-no-or-other-functions-allowed/solutions/map\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody 833 Side of a Triangle\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\u003eTest suite \\\"disallowed function usage check\\\" courtesy of Aurelien Queffurust.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample :\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ea= 1; b= 1; c=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\u003eOutput\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x(1)= -0.5+0.866i; x(2)= -0.5-0.866i]]\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":42795,"title":" Fast 1-D Convolution (valid shape) ","description":"Pursuant to the first problem in the \u003chttp://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution fast 1-D convolution series\u003e, this problem asks for the fast algorithm to compute the 1-D convolution in its \"valid\" output shape.  \r\n\r\nThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in *conv* function invoked in the form *conv(u,v,'valid')*, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out. \r\n\r\n* Previous problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape Fast 1-D Convolution (same shape)\u003e.","description_html":"\u003cp\u003ePursuant to the first problem in the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\"\u003efast 1-D convolution series\u003c/a\u003e, this problem asks for the fast algorithm to compute the 1-D convolution in its \"valid\" output shape.\u003c/p\u003e\u003cp\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in \u003cb\u003econv\u003c/b\u003e function invoked in the form \u003cb\u003econv(u,v,'valid')\u003c/b\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/p\u003e\u003cul\u003e\u003cli\u003ePrevious problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42794-fast-1-d-convolution-same-shape\"\u003eFast 1-D Convolution (same shape)\u003c/a\u003e.\u003c/li\u003e\u003c/ul\u003e","function_template":"function w = fconv1v(u,v)\r\n  % Extremely inefficient solution not guaranteed to pass all tests :-(\r\n  w = conv(u,v,'valid'); \r\nend","test_suite":"%%\r\n%{\r\n╔═════════════════════════════════════════════════════════════╗\r\n║ Please note that problems in this series are designed for   ║\r\n║ optimizing the code performance, rather than the usual Cody ║\r\n║ \"size\". We are achieving this goal by courtesy of LY Cao's  ║ \r\n║ new scoring function, which automatically grants a better   ║\r\n║ score to a faster solution. Kindly note that simply using   ║\r\n║ the conv function may result in a poor score or even failure║\r\n║ in one of the tests. Suggestions and comments are welcome.  ║\r\n║                                                             ║\r\n║ Thanks \u0026 have fun!                                          ║\r\n║ Peng                                                        ║\r\n╚═════════════════════════════════════════════════════════════╝\r\n%}\r\n\r\n%%\r\nfid = fopen('EvaluateSolution.p','wb'); \r\nfwrite(fid,uint8(sscanf('7630312E30307630302E3030000CF01CCC561FB1000000C30000012D000001D160E44E2EC6DB5CE66B30F9B560AF40D6A7226365293F6413AE84ABD44D4C7EE5C617DCDAC2521B24B2951C23F50BA9DAA4179B35DCED27A697FC9CA9A308698729973CACEC16670C077236F96E9D16612152B0C32FC57E4755E80E40AC876804B7835D9703BC5A1D6FC519FDEDE22237DC59455FF0014FEBCEF1CB2A840158E11CDD5D6C78D594F50B575A4DF9FB54705F2C6D40341F12CE207B892CBEDEC018A1F94CFA1D5FBB9E1912BA424CD5C6C422D6F3451A8BDD2543834B3FFAD3107D8F16C78D75DD9F3AD197D5591B1686E190D8DF4B5EF3AC28C641296E92FB02BC395D442C03480E156E48F8B61AA3C6F1526AA95C1C466C77A3803AF8523098B0A3ED10A07E2F93274DC8207B05A572988754AAC211A330C2FEC7928CFD51D3A6FBDD9FFA6036C948E0C4239A16','%2x')));\r\nfclose(fid);\r\n\r\n%%\r\nu = 1; v = 1;\r\ny_correct = 1;\r\nassert(isequal(fconv1v(u,v),y_correct))\r\n\r\n%%\r\nu = 1:10; v = 1:5;\r\ny_correct = conv(u,v,'valid');\r\nassert(all(abs(fconv1v(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = 1:5; v = 1:10;\r\ny_correct = zeros(1,0);\r\nassert(isequal(fconv1v(u,v),y_correct))\r\n\r\n%%\r\nu = rand(20,1); v = rand(10,1);\r\ny_correct = conv(u,v,'valid');\r\nassert(all(abs(fconv1v(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = rand(10,1); v = rand(20,1);\r\ny_correct = zeros(0,1);\r\nassert(isequal(fconv1v(u,v),y_correct))\r\n\r\n%%\r\n% Large data size\r\nglobal sol_score\r\nAbsTol = 1e-6;   % Maximum absolute error tolerance\r\nuu = rand(5e6,15); vv = rand(2e5,15);\r\nfor iter = 15:-1:1\r\n    u = uu(:,iter); v = vv(:,iter);\r\n    t = builtin('tic');\r\n    y = fconv1v(u,v);\r\n    timeSpan(iter) = builtin('toc',t);\r\n    pass(iter) = EvaluateSolution(u,v,y,AbsTol);  \r\nend\r\nsol_score = sum(timeSpan);\r\nassert(all(pass));\r\n\r\n%%\r\n% New scoring function by LY Cao\r\nglobal sol_score\r\nfid = fopen('score.p','wb');\r\nfwrite(fid,sscanf('7630312E30307630302E30300008501CD77E9FB100000035000001110000018422762999A8C1DE50537BEE443F4D73651F830FC6C78ADFB7DF68DF98823F565884DC58E21C7E397E3D26E4FFEA9A0D83589ABB5C0B0B553B44CFD79C9B272D11DF1965AD538598E8319529727DF4C4CF36A6016DD7816544AE5A8F64C9B2D9D0C4B94DD5EDF14595CBFE3D402647499EA3D9D125AC927454ED85973BCD1AAEA536D5A6CDDCD78A0211E8179603FFE12E4AB0E4704EA195704428700BAE5C4DFD42FF1A8760EDF2721F9724498ECC9F957735E7A3CDB9630DB17DF92ACE8F486706020E0A8D022D14BC313879724760AE20D67F572DD85211E4BEA45CDF3E22976253F113AEA96C1FF907329E4BD429BCFC6331077DA21F05D791DA6ECCF680D2E23AC77DFCE5C1D9869D3098F5B89FF92A','%2x'));\r\nfclose(fid);\r\nscore(sol_score);","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":"2016-04-05T21:09:16.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2016-04-02T21:30:34.000Z","updated_at":"2025-12-21T14:08:51.000Z","published_at":"2016-04-04T01:47: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\u003ePursuant to the first problem in the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efast 1-D convolution series\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, this problem asks for the fast algorithm to compute the 1-D convolution in its \\\"valid\\\" output shape.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in\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\u003econv\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e function invoked in the form\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\u003econv(u,v,'valid')\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\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\u003ePrevious problem:\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/42794-fast-1-d-convolution-same-shape\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFast 1-D Convolution (same shape)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42794,"title":" Fast 1-D Convolution (same shape) ","description":"Pursuant to the first problem in the \u003chttp://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution fast 1-D convolution series\u003e, this problem asks for the fast algorithm to compute the 1-D convolution with the same input-output shape.  \r\n\r\nThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in *conv* function invoked in the form *conv(u,v,'same')*, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out. \r\n\r\n* Previous problem:  \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42793-fast-1-d-convolution-full-shape Fast 1-D Convolution (full shape)\u003e\r\n* Next problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42795-fast-1-d-convolution-valid-shape Fast 1-D Convolution (valid shape)\u003e\r\n","description_html":"\u003cp\u003ePursuant to the first problem in the \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\"\u003efast 1-D convolution series\u003c/a\u003e, this problem asks for the fast algorithm to compute the 1-D convolution with the same input-output shape.\u003c/p\u003e\u003cp\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in \u003cb\u003econv\u003c/b\u003e function invoked in the form \u003cb\u003econv(u,v,'same')\u003c/b\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\u003c/p\u003e\u003cul\u003e\u003cli\u003ePrevious problem:  \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42793-fast-1-d-convolution-full-shape\"\u003eFast 1-D Convolution (full shape)\u003c/a\u003e\u003c/li\u003e\u003cli\u003eNext problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42795-fast-1-d-convolution-valid-shape\"\u003eFast 1-D Convolution (valid shape)\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = fconv1s(u,v)\r\n  % Extremely inefficient solution not guaranteed to pass all tests :-(\r\n  y = conv(u,v,'same'); \r\nend","test_suite":"%%\r\n%{\r\n╔═════════════════════════════════════════════════════════════╗\r\n║ Please note that problems in this series are designed for   ║\r\n║ optimizing the code performance, rather than the usual Cody ║\r\n║ \"size\". We are achieving this goal by courtesy of LY Cao's  ║ \r\n║ new scoring function, which automatically grants a better   ║\r\n║ score to a faster solution. Kindly note that simply using   ║\r\n║ the conv function may result in a poor score or even failure║\r\n║ in one of the tests. Suggestions and comments are welcome.  ║\r\n║                                                             ║\r\n║ Thanks \u0026 have fun!                                          ║\r\n║ Peng                                                        ║\r\n╚═════════════════════════════════════════════════════════════╝\r\n%}\r\n\r\n%%\r\nfid = fopen('EvaluateSolution.p','wb'); \r\nfwrite(fid,uint8(sscanf('7630312E30307630302E3030000E201CC0225FB10000010B000001480000023C141D1F2F8C075F9CDC9AA9EE4F066DD1BE8B37851CBC980DC3CFCB6C55FAA40EAEED061766137EB39A214C865F6410AAF263010C3B9D012F499C4718371499BB689324D8892718476958CEAC4EE884BB215750071FA3AEE658AB639696B588AA35864A8AF99C9981E6AB14F1BE31F76F320D6F1EA110DE5A9E1C9F4597921FF711410412A4E9C4AA1026E997F054CBEF2A6FC2607C95B65D62747B293B8A86A0D33830E20CCB930D6986416727FFE5CB77FE03A0722EE2B47A07493392D53C4C7A0995EDFA31DB344F2C390E67574523D59403673E343AB6E1A5D83D0EE6B4E784AAA80184B8295937D1648E6A92E82360BE54C82D837FFBE28102BB1EF99FEB94473DB16240A68474D4E8DA84CD1B6DB5AA3FB2921D378C5D78A3A006E36169618AF0F4A18645472518E158E85BB81BC6CBEDCD7A861A67E1ECC712442F423199F4EB715F9493CA','%2x')));\r\nfclose(fid);\r\n\r\n%%\r\nu = 1; v = 1;\r\ny_correct = 1;\r\nassert(isequal(fconv1s(u,v),y_correct))\r\n\r\n%%\r\nu = 1:10; v = 1:5;\r\ny_correct = conv(u,v,'same');\r\nassert(all(abs(fconv1s(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = 1:5; v = 1:10;\r\ny_correct = conv(u,v,'same');\r\nassert(all(abs(fconv1s(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = rand(20,1); v = rand(10,1);\r\ny_correct = conv(u,v,'same');\r\nassert(all(abs(fconv1s(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\nu = rand(10,1); v = rand(20,1);\r\ny_correct = conv(u,v,'same');\r\nassert(all(abs(fconv1s(u,v)-y_correct)\u003c1e-10))\r\n\r\n%%\r\n% Large data size\r\nglobal sol_score\r\nAbsTol = 1e-6;   % Maximum absolute error tolerance\r\nfor iter = 15:-1:1\r\n    u = rand(5e6,1); v = rand(2e5,1);\r\n    t = builtin('tic');\r\n    y = fconv1s(u,v);\r\n    timeSpan(iter) = builtin('toc',t);\r\n    pass(iter) = EvaluateSolution(u,v,y,AbsTol);  \r\nend\r\nsol_score = sum(timeSpan);\r\nassert(all(pass));\r\n\r\n%%\r\n% New scoring function by LY Cao\r\nglobal sol_score\r\nfid = fopen('score.p','wb');\r\nfwrite(fid,sscanf('7630312E30307630302E30300008501CD77E9FB100000035000001110000018422762999A8C1DE50537BEE443F4D73651F830FC6C78ADFB7DF68DF98823F565884DC58E21C7E397E3D26E4FFEA9A0D83589ABB5C0B0B553B44CFD79C9B272D11DF1965AD538598E8319529727DF4C4CF36A6016DD7816544AE5A8F64C9B2D9D0C4B94DD5EDF14595CBFE3D402647499EA3D9D125AC927454ED85973BCD1AAEA536D5A6CDDCD78A0211E8179603FFE12E4AB0E4704EA195704428700BAE5C4DFD42FF1A8760EDF2721F9724498ECC9F957735E7A3CDB9630DB17DF92ACE8F486706020E0A8D022D14BC313879724760AE20D67F572DD85211E4BEA45CDF3E22976253F113AEA96C1FF907329E4BD429BCFC6331077DA21F05D791DA6ECCF680D2E23AC77DFCE5C1D9869D3098F5B89FF92A','%2x'));\r\nfclose(fid);\r\nscore(sol_score);","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":"2016-04-05T20:53:23.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2016-04-02T21:30:23.000Z","updated_at":"2025-12-21T14:01:33.000Z","published_at":"2016-04-04T01:47:11.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\u003ePursuant to the first problem in the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/?term=Fast+1-D+Convolution\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efast 1-D convolution series\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, this problem asks for the fast algorithm to compute the 1-D convolution with the same input-output shape.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere exists a fast 1-D convolution algorithm way more efficient than MATLAB's built-in\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\u003econv\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e function invoked in the form\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\u003econv(u,v,'same')\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and the performance improvement is more pronounced when length(u) and/or length(v) are large. Do you know how? Try it out.\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\u003ePrevious problem: \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/42793-fast-1-d-convolution-full-shape\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFast 1-D Convolution (full shape)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNext problem:\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/42795-fast-1-d-convolution-valid-shape\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFast 1-D Convolution (valid shape)\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\"}]}"}],"term":"tag:\"conv\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"conv\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"conv\"","","\"","conv","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f03e8c44300\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f03e8c44260\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f03e8c439a0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f03e8c44580\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f03e8c444e0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f03e8c44440\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f03e8c443a0\u003e":"tag:\"conv\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f03e8c443a0\u003e":"tag:\"conv\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"cody-search","password":"78X075ddcV44","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"conv\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"conv\"","","\"","conv","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f03e8c44300\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f03e8c44260\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f03e8c439a0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f03e8c44580\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f03e8c444e0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f03e8c44440\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f03e8c443a0\u003e":"tag:\"conv\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f03e8c443a0\u003e":"tag:\"conv\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":43183,"difficulty_rating":"easy"},{"id":42793,"difficulty_rating":"easy-medium"},{"id":834,"difficulty_rating":"easy-medium"},{"id":42795,"difficulty_rating":"medium"},{"id":42794,"difficulty_rating":"medium"}]}}