{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":1644,"title":"What percentage?","description":"Calculate the output c as the percentage of a on b for given a and b.","description_html":"\u003cp\u003eCalculate the output c as the percentage of a on b for given a and b.\u003c/p\u003e","function_template":"function c = percentage_is(a,b)\r\n  c = 0;\r\nend","test_suite":"%%\r\na = 10;\r\nb = 100;\r\nc_correct = 10;\r\nassert(isequal(percentage_is(a,b),c_correct))\r\n\r\n%%\r\na = 10;\r\nb = 50;\r\nc_correct = 20;\r\nassert(isequal(percentage_is(a,b),c_correct))\r\n\r\n%%\r\na = 10;\r\nb = 20;\r\nc_correct = 50;\r\nassert(isequal(percentage_is(a,b),c_correct))\r\n\r\n%%\r\na = 8;\r\nb = 32;\r\nc_correct = 25;\r\nassert(isequal(percentage_is(a,b),c_correct))\r\n\r\n%%\r\na = 28;\r\nb = 7;\r\nc_correct = 400;\r\nassert(isequal(percentage_is(a,b),c_correct))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":14304,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":523,"test_suite_updated_at":"2013-06-11T20:58:58.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-11T08:41:49.000Z","updated_at":"2026-02-08T05:46:14.000Z","published_at":"2013-06-11T08:42:21.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCalculate the output c as the percentage of a on b for given a and b.\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":43057,"title":"Binary Inversion","description":"Given the unsigned 8-bit integer x, return the number y which is the binary inversion of x.\r\n\r\nFor example if x is 5, y should be 250 because:\r\n\r\n   5 (8-bit): 00000101\r\n\r\n 250 (8-bit): 11111010","description_html":"\u003cp\u003eGiven the unsigned 8-bit integer x, return the number y which is the binary inversion of x.\u003c/p\u003e\u003cp\u003eFor example if x is 5, y should be 250 because:\u003c/p\u003e\u003cpre\u003e   5 (8-bit): 00000101\u003c/pre\u003e\u003cpre\u003e 250 (8-bit): 11111010\u003c/pre\u003e","function_template":"function y = binInvert(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 10;\r\ny_correct = 245;\r\nassert(isequal(binInvert(x),y_correct))\r\n%%\r\nx = 245;\r\ny_correct = 10;\r\nassert(isequal(binInvert(x),y_correct))\r\n%%\r\nx = 20;\r\ny_correct = 235;\r\nassert(isequal(binInvert(x),y_correct))\r\n%%\r\nx = 235;\r\ny_correct = 20;\r\nassert(isequal(binInvert(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":94929,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":67,"test_suite_updated_at":"2016-10-19T11:46:21.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-05T13:46:36.000Z","updated_at":"2026-02-04T15:53:48.000Z","published_at":"2016-10-05T13:46:36.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven the unsigned 8-bit integer x, return the number y which is the binary inversion of x.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example if x is 5, y should be 250 because:\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[   5 (8-bit): 00000101\\n\\n 250 (8-bit): 11111010]]\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":1468,"title":"Numbers at bit-boundary","description":"Find if a number is on or below the bit-boundary, as defined below.\r\nExamples\r\n7,9 straddle the bit-boundary at 2^3 as do 31,32 at 2^5; in these cases 7,8 are on bit boundary as are 31, and 32, but 5 and 33 do not qualify by definition.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 102px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 51px; transform-origin: 407px 51px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 209px 8px; transform-origin: 209px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFind if a number is on or below the bit-boundary, as defined below.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 30px 8px; transform-origin: 30px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExamples\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 377.5px 8px; transform-origin: 377.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e7,9 straddle the bit-boundary at 2^3 as do 31,32 at 2^5; in these cases 7,8 are on bit boundary as are 31, and 32, but 5 and 33 do not qualify by definition.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = on_bit_boundary(x)\r\n\r\nend","test_suite":"%%\r\nx = 2^5;\r\ny_correct = true;\r\nassert( isequal(on_bit_boundary(x),y_correct) )\r\n\r\n%%\r\nx = 2^5 - 5;\r\ny_correct = false;\r\nassert( isequal(on_bit_boundary(x),y_correct) )\r\n\r\n%%\r\nx = 127\r\ny_correct = true;\r\nassert( isequal(on_bit_boundary(x),y_correct) )\r\n\r\n%%\r\nx = 1023\r\nassert( isequal(on_bit_boundary(x),1) )\r\n\r\n%%\r\ny_correct = false;\r\nx = 501\r\nassert( isequal(on_bit_boundary(x),y_correct) )\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":3378,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":35,"test_suite_updated_at":"2021-06-17T09:56:18.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-04-28T17:30:15.000Z","updated_at":"2025-10-30T18:59:13.000Z","published_at":"2013-04-28T17:32:24.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind if a number is on or below the bit-boundary, as defined below.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e7,9 straddle the bit-boundary at 2^3 as do 31,32 at 2^5; in these cases 7,8 are on bit boundary as are 31, and 32, but 5 and 33 do not qualify by definition.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":808,"title":"Hamming Weight - Fast","description":"The Hamming Weight, \u003chttp://en.wikipedia.org/wiki/Hamming_weight wiki Hamming Weight\u003e, in its most simple form is the number of ones in the binary representation of a value.\r\n\r\nThe task here is to create a fast Hamming Weight function/method such that processing many 4K x 4K images of 32 bit integer can be evaluated rapidly. Saw this question posed on Stack Overflow.\r\n\r\n*Input:* Vector of length N of 32 bit integer values.\r\n\r\n*Output:* Vector of number of ones of the binary representation\r\n\r\n*Scoring:* Time in milliseconds to process a [4096*4096,1] vector\r\n\r\n*Examples:* Input [7 ; 3], output=[3;2];  [16 32], output [1;1]; [0 4294967295] output [0;32]\r\n\r\n*Timing Test vector:* uint32(randi(2^32,[4096*4096,1])-1)\r\n\r\n*Minimum vector length/increment:* 65536\r\n\r\nHelpful, possibly, global variables.\r\n\r\nb1=uint32(1431655765); b2=uint32(858993459); b3=uint32(252645135) b4=uint32(16711935); b5=uint32(65535);\r\n\r\nHex: b1=55555555 b2=33333333 b3=0F0F0F0F b4=00FF00FF b5=0000FFFF \r\n\r\nThe array num_ones is created for values 0-65535 (0:2^16-1).\r\nnum_ones(1)=0, num_ones(2)=1, num_ones(3)=1,num_ones(4)=2,...num_ones(65536)=15\r\n\r\nDue to lack of zero indexing num_ones(value+1) is number of ones for value.\r\n\r\n\r\nHint: Globals are not good for time performance.\r\n\r\nHint: Segmentation appears to provide significant time optimization potential.\r\n\r\n\r\n\r\n","description_html":"\u003cp\u003eThe Hamming Weight, \u003ca href=\"http://en.wikipedia.org/wiki/Hamming_weight\"\u003ewiki Hamming Weight\u003c/a\u003e, in its most simple form is the number of ones in the binary representation of a value.\u003c/p\u003e\u003cp\u003eThe task here is to create a fast Hamming Weight function/method such that processing many 4K x 4K images of 32 bit integer can be evaluated rapidly. Saw this question posed on Stack Overflow.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e Vector of length N of 32 bit integer values.\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e Vector of number of ones of the binary representation\u003c/p\u003e\u003cp\u003e\u003cb\u003eScoring:\u003c/b\u003e Time in milliseconds to process a [4096*4096,1] vector\u003c/p\u003e\u003cp\u003e\u003cb\u003eExamples:\u003c/b\u003e Input [7 ; 3], output=[3;2];  [16 32], output [1;1]; [0 4294967295] output [0;32]\u003c/p\u003e\u003cp\u003e\u003cb\u003eTiming Test vector:\u003c/b\u003e uint32(randi(2^32,[4096*4096,1])-1)\u003c/p\u003e\u003cp\u003e\u003cb\u003eMinimum vector length/increment:\u003c/b\u003e 65536\u003c/p\u003e\u003cp\u003eHelpful, possibly, global variables.\u003c/p\u003e\u003cp\u003eb1=uint32(1431655765); b2=uint32(858993459); b3=uint32(252645135) b4=uint32(16711935); b5=uint32(65535);\u003c/p\u003e\u003cp\u003eHex: b1=55555555 b2=33333333 b3=0F0F0F0F b4=00FF00FF b5=0000FFFF\u003c/p\u003e\u003cp\u003eThe array num_ones is created for values 0-65535 (0:2^16-1).\r\nnum_ones(1)=0, num_ones(2)=1, num_ones(3)=1,num_ones(4)=2,...num_ones(65536)=15\u003c/p\u003e\u003cp\u003eDue to lack of zero indexing num_ones(value+1) is number of ones for value.\u003c/p\u003e\u003cp\u003eHint: Globals are not good for time performance.\u003c/p\u003e\u003cp\u003eHint: Segmentation appears to provide significant time optimization potential.\u003c/p\u003e","function_template":"function y = Ham(x)\r\n% Input uint32\r\nglobal num_ones b1 b2 b3 b4 b5\r\n  y = x;\r\nend","test_suite":"%%\r\nfeval(@assignin,'caller','score',2000);\r\n%%\r\nglobal num_ones b1 b2 b3 b4 b5 net_time\r\nnet_time=2000; % default in case of time out (not needed)\r\n\r\nb1=uint32(1431655765); \r\nb2=uint32(858993459);\r\nb3=uint32(252645135);\r\nb4=uint32(16711935);\r\nb5=uint32(65535);\r\n \r\nnum_ones=uint32(zeros(65536,1)); \r\nfor i=0:65535  num_ones(i+1)=length( find( bitget( i, 1:32 ) ) ) ; \r\nend % Cody 0.996 sec\r\n%%\r\nglobal num_ones b1 b2 b3 b4 b5 net_time\r\n\r\nw=uint32(randi(2^32,[65536*1,1])-1); \r\nfor i=1:4 % Clear timing\r\n  vw=Ham(w);\r\nend\r\n\r\nwexpect=num_ones(mod(w,65536)+1)+num_ones(floor(double(w)/65536)+1); %1.56\r\nt0=clock;\r\n vw=Ham(w);\r\n vw=Ham(w);\r\n vw=Ham(w);\r\n vw=Ham(w);\r\ndt=etime(clock,t0)*250*1000; % avg of 4 runs in us\r\nfprintf('Time to execute 65536 values %.0f usec\\n',dt);\r\nassert(isequal(wexpect,vw),sprintf('Time to execute 65536 values %.0f usec\\n',dt))\r\n%%\r\nglobal num_ones b1 b2 b3 b4 b5 net_time\r\n\r\nw=uint32(randi(2^32,[65536*1,1])-1); \r\n\r\n vw=Ham(w); % Three cycles of smaller vector\r\n vw=Ham(w);\r\n vw=Ham(w);\r\n\r\nw=uint32(randi(2^32,[4096*4096,1])-1);\r\nwexpect=num_ones(mod(w,65536)+1)+num_ones(floor(double(w)/65536)+1); %1.56\r\n\r\n \r\n  vw=Ham(w); % Big Prep file\r\n  vw=Ham(w); % Big Prep file\r\n \r\nt0=clock;\r\n vw=Ham(w);\r\n vw=Ham(w);\r\n vw=Ham(w);\r\n vw=Ham(w);\r\nnet_time=etime(clock,t0)*250; % avg of 4 runs\r\nfprintf('Time to execute 4096*4096 values %.0f msec\\n',net_time);\r\n\r\nassert(isequal(wexpect,vw),sprintf('Time to execute 4096*4096 values %.0f msec\\n',net_time))\r\n%%\r\nglobal net_time\r\n% net_time in ms\r\n% Create graph data\r\nnet_time=min(2000,net_time); % Limit graph y-axis\r\n\r\nfeval(@assignin,'caller','score',floor(net_time));\r\n\r\n%fh=fopen('Ham.m','wt');\r\n%fprintf(fh,'%s\\n',repmat('1;',[1,round(net_time/2)]));\r\n%fclose(fh);","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":"2012-11-22T11:18:57.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-06-30T05:08:08.000Z","updated_at":"2026-02-09T12:51:11.000Z","published_at":"2012-07-01T05:19:12.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe Hamming Weight,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Hamming_weight\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ewiki Hamming Weight\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, in its most simple form is the number of ones in the binary representation of a value.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe task here is to create a fast Hamming Weight function/method such that processing many 4K x 4K images of 32 bit integer can be evaluated rapidly. Saw this question posed on Stack Overflow.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Vector of length N of 32 bit integer values.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Vector of number of ones of the binary representation\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eScoring:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Time in milliseconds to process a [4096*4096,1] vector\u003c/w:t\u003e\u003c/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\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Input [7 ; 3], output=[3;2]; [16 32], output [1;1]; [0 4294967295] output [0;32]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTiming Test vector:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e uint32(randi(2^32,[4096*4096,1])-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\u003eMinimum vector length/increment:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 65536\u003c/w:t\u003e\u003c/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\u003eHelpful, possibly, global variables.\u003c/w:t\u003e\u003c/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\u003eb1=uint32(1431655765); b2=uint32(858993459); b3=uint32(252645135) b4=uint32(16711935); b5=uint32(65535);\u003c/w:t\u003e\u003c/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\u003eHex: b1=55555555 b2=33333333 b3=0F0F0F0F b4=00FF00FF b5=0000FFFF\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe array num_ones is created for values 0-65535 (0:2^16-1). num_ones(1)=0, num_ones(2)=1, num_ones(3)=1,num_ones(4)=2,...num_ones(65536)=15\u003c/w:t\u003e\u003c/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\u003eDue to lack of zero indexing num_ones(value+1) is number of ones for value.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHint: Globals are not good for time performance.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHint: Segmentation appears to provide significant time optimization potential.\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":45267,"title":"Zero","description":"given an integer a, find the smallest possible integer b(b\u003e0) such that their bitwise logical AND is zero.\r\n\r\n*  if a=11(1011) then b=4(0100)","description_html":"\u003cp\u003egiven an integer a, find the smallest possible integer b(b\u0026gt;0) such that their bitwise logical AND is zero.\u003c/p\u003e\u003cul\u003e\u003cli\u003eif a=11(1011) then b=4(0100)\u003c/li\u003e\u003c/ul\u003e","function_template":"function b=zero_and(a)\r\nend","test_suite":"%%\r\na = 1;\r\ny_correct = 2;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 2;\r\ny_correct = 1;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 12;\r\ny_correct = 1;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 11;\r\ny_correct = 4;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 15;\r\ny_correct = 16;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 23;\r\ny_correct = 8;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 93;\r\ny_correct = 2;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 1455;\r\ny_correct = 16;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 255;\r\ny_correct = 256;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 435175;\r\ny_correct = 8;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\nfiletext = fileread('zero_and.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp() forbidden')\r\nassert(isempty(strfind(filetext, 'varargin')),'varargin() forbidden')\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":"2020-02-13T21:41:25.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-01-16T14:29:26.000Z","updated_at":"2026-01-03T11:47:45.000Z","published_at":"2020-01-16T14:30:08.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003egiven an integer a, find the smallest possible integer b(b\u0026gt;0) such that their bitwise logical AND is zero.\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\u003eif a=11(1011) then b=4(0100)\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":2202,"title":"Flip the bit","description":"Given an input character string (e.g. '1001'), return a character string with the bits flipped ('0110').","description_html":"\u003cp\u003eGiven an input character string (e.g. '1001'), return a character string with the bits flipped ('0110').\u003c/p\u003e","function_template":"function y = flipbit(s)\r\n  y = '010101';\r\nend","test_suite":"%%\r\ns = '1001';\r\ny_correct = '0110';\r\nassert(all(isequal(flipbit(s),y_correct)\u0026ischar(flipbit(s))))\r\n%%\r\ns = '11';\r\ny_correct = '00';\r\nassert(all(isequal(flipbit(s),y_correct)\u0026ischar(flipbit(s))))\r\n%%\r\ns = '1';\r\ny_correct = '0';\r\nassert(all(isequal(flipbit(s),y_correct)\u0026ischar(flipbit(s))))\r\n%%\r\ns = '100000001';\r\ny_correct = '011111110';\r\nassert(all(isequal(flipbit(s),y_correct)\u0026ischar(flipbit(s))))\r\n%%\r\ns = '00001';\r\ny_correct = '11110';\r\nassert(all(isequal(flipbit(s),y_correct)\u0026ischar(flipbit(s))))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":2,"created_by":39,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":535,"test_suite_updated_at":"2014-02-20T18:44:05.000Z","rescore_all_solutions":false,"group_id":32,"created_at":"2014-02-20T15:53:55.000Z","updated_at":"2026-03-19T20:08:33.000Z","published_at":"2014-02-20T15:56:43.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an input character string (e.g. '1001'), return a character string with the bits flipped ('0110').\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":58399,"title":"Sign of IEEE Single","description":"Output the sign bit of the IEEE representation of the single-typed 32-bit float input as the uint8 \"1\" or the uint8 \"0\".","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 21px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407.5px 10.5px; transform-origin: 407.5px 10.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eOutput the sign bit of the IEEE representation of the single-typed 32-bit float input as the uint8 \"1\" or the uint8 \"0\".\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = signBit(x)\r\n    y = uint8(x);\r\nend","test_suite":"%%\r\nx = single(1);\r\ny_correct = 0;\r\nassert(isequal(signBit(x),y_correct))\r\n\r\nx = single(0.125);\r\ny_correct = 0;\r\nassert(isequal(signBit(x),y_correct))\r\n\r\nx = single(-1);\r\ny_correct = 1;\r\nassert(isequal(signBit(x),y_correct))\r\n\r\nx = single(-0.125);\r\ny_correct = 1;\r\nassert(isequal(signBit(x),y_correct))\r\n\r\nx = single(10000.15);\r\ny_correct = 0;\r\nassert(isequal(signBit(x),y_correct))\r\n\r\nx = single(-1000.15);\r\ny_correct = 1;\r\nassert(isequal(signBit(x),y_correct))\r\n\r\nx = single(0.0);\r\ny_correct = 0;\r\nassert(isequal(signBit(x),y_correct))\r\n\r\nx = single(-0.0);\r\ny_correct = 1;\r\nassert(isequal(signBit(x),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":2436475,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":7,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2023-06-07T20:12:38.000Z","updated_at":"2023-06-07T20:12:38.000Z","published_at":"2023-06-07T20:12:38.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput the sign bit of the IEEE representation of the single-typed 32-bit float input as the uint8 \\\"1\\\" or the uint8 \\\"0\\\".\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":58404,"title":"Mantissa of IEEE Single","description":"Output the mantissa bits as a uint32 of the IEEE representation of the single-typed 32-bit float input. Store these bits in the least significant bits of the uint32.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 42px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407.5px 21px; transform-origin: 407.5px 21px; vertical-align: baseline; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384.5px 21px; text-align: left; transform-origin: 384.5px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eOutput the mantissa bits as a uint32 of the IEEE representation of the single-typed 32-bit float input. Store these bits in the least significant bits of the uint32.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = mantissa(x)\r\n    y = uint32(x);\r\nend","test_suite":"%%\r\nx = single(4);\r\ny_correct = uint32(0);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(1+2^-23);\r\ny_correct = uint32(1);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(1+2^-22);\r\ny_correct = uint32(2);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(-1-2^-22);\r\ny_correct = uint32(2);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(1+2^-23+2^-22);\r\ny_correct = uint32(3);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(-1-2^-23-2^-22);\r\ny_correct = uint32(3);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(100454.4324);\r\ny_correct = uint32(4469559);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(1694995438329000);\r\ny_correct = uint32(4240092);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(0);\r\ny_correct = uint32(0);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(-0.0);\r\ny_correct = uint32(0);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(inf);\r\ny_correct = uint32(0);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(-inf);\r\ny_correct = uint32(0);\r\nassert(isequal(uint32(mantissa(x)),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":2436475,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":4,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2023-06-07T20:26:20.000Z","updated_at":"2023-06-07T20:26:20.000Z","published_at":"2023-06-07T20:26:20.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput the mantissa bits as a uint32 of the IEEE representation of the single-typed 32-bit float input. Store these bits in the least significant bits of the uint32.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":45326,"title":"Decimal Fraction to binary conversion","description":"Given an fraction decimal number n, convert it to its equivalent binary number.\r\n\r\nIf it is an infinite binary fraction, keep it upto k precision point.\r\n\r\n* n=55.125\r\n* out='110111.001'","description_html":"\u003cp\u003eGiven an fraction decimal number n, convert it to its equivalent binary number.\u003c/p\u003e\u003cp\u003eIf it is an infinite binary fraction, keep it upto k precision point.\u003c/p\u003e\u003cul\u003e\u003cli\u003en=55.125\u003c/li\u003e\u003cli\u003eout='110111.001'\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = dec2bin_frac(n,k)\r\n  y = x;\r\nend","test_suite":"%%\r\nassert(isequal(dec2bin_frac(123.25),'1111011.01'))\r\n%%\r\nassert(isequal(dec2bin_frac(123.2,6),'1111011.001100'))\r\n%%\r\nassert(isequal(dec2bin_frac(6.97,10), '110.1111100001'))\r\n%%\r\nassert(isequal(dec2bin_frac(61.81250),'111101.1101'))\r\n%%\r\nassert(isequal(dec2bin_frac(666),'1010011010'))\r\n%%\r\nassert(isequal(dec2bin_frac(666624.5),'10100010110000000000.1'))\r\n%%\r\nassert(isequal(dec2bin_frac(55.125,7),'110111.001'))\r\n%%\r\nassert(isequal(dec2bin_frac(123),'1111011'))","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":8,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-02-14T19:50:58.000Z","updated_at":"2020-02-14T19:52:21.000Z","published_at":"2020-02-14T19:52:21.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an fraction decimal number n, convert it to its equivalent binary number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf it is an infinite binary fraction, keep it upto k precision point.\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\u003en=55.125\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\u003eout='110111.001'\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":185,"title":"Data decompression","description":"A chunk of data is to be 'decompressed'.\r\n\r\nInput:\r\n\r\n* compressed: a row vector of uint8 values. This is the compressed data.\r\n* table: a cell-array of strings. Each string contains only '1's and '0's and represents a binary code.\r\n* alphabet: a string containing all possible symbols that may occur in the decompressed data. The symbol at alphabet(x) is encoded with the code at table{x}.\r\n\r\nOutput:\r\n\r\n* decompressed: a string with the decoded message.\r\n\r\nExample:\r\n\r\n  compressed=[93,85,127]\r\n  table={'1','010'}\r\n  alphabet='al'\r\n==\u003e  decompressed = 'laaalalalaaaaaaa'\r\n\r\nbecause:  \r\n\r\n  [93,85,127] = '01011101 01010101 01111111' in binary\r\n  decoded from left to right:\r\n  '010 1 1 1 010 1 010 1 010 1 1 1 1 1 1 1'\r\n  = l  a a a  l  a  l  a  l  a a a a a a a\r\n\r\nRemarks: The message is such that always exactly all bits of |compressed| are used. The solution is unique (see \u003chttp://en.wikipedia.org/wiki/Prefix_code prefix-free code\u003e).","description_html":"\u003cp\u003eA chunk of data is to be 'decompressed'.\u003c/p\u003e\u003cp\u003eInput:\u003c/p\u003e\u003cul\u003e\u003cli\u003ecompressed: a row vector of uint8 values. This is the compressed data.\u003c/li\u003e\u003cli\u003etable: a cell-array of strings. Each string contains only '1's and '0's and represents a binary code.\u003c/li\u003e\u003cli\u003ealphabet: a string containing all possible symbols that may occur in the decompressed data. The symbol at alphabet(x) is encoded with the code at table{x}.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eOutput:\u003c/p\u003e\u003cul\u003e\u003cli\u003edecompressed: a string with the decoded message.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ecompressed=[93,85,127]\r\ntable={'1','010'}\r\nalphabet='al'\r\n==\u003e  decompressed = 'laaalalalaaaaaaa'\r\n\u003c/pre\u003e\u003cp\u003ebecause:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[93,85,127] = '01011101 01010101 01111111' in binary\r\ndecoded from left to right:\r\n'010 1 1 1 010 1 010 1 010 1 1 1 1 1 1 1'\r\n= l  a a a  l  a  l  a  l  a a a a a a a\r\n\u003c/pre\u003e\u003cp\u003eRemarks: The message is such that always exactly all bits of \u003ctt\u003ecompressed\u003c/tt\u003e are used. The solution is unique (see \u003ca href=\"http://en.wikipedia.org/wiki/Prefix_code\"\u003eprefix-free code\u003c/a\u003e).\u003c/p\u003e","function_template":"function decompressed = decode(compressed,table,alphabet)\r\n  decompressed = char(compressed);\r\nend","test_suite":"%% the example from the problem description\r\nalphabet = 'al';\r\ntable = {'1','010'};\r\ncompressed = [93,85,127];\r\nassert(isequal(decode(compressed,table,alphabet),'laaalalalaaaaaaa'))\r\n\r\n%% another short test\r\nalphabet = 'ehlo';\r\ntable = {'00','01','10','11'};\r\ncompressed = uint8([74 210 191]);\r\nassert(isequal(decode(compressed,table,alphabet),'hellohellooo'))\r\n\r\n%% longer test\r\nalphabet = ',.kcgIblowaisnufhe try';\r\ntable = {'000000','000001','00001','000100','000101','000110','000111','001','010','01100','01101','0111','1000','10010','10011','10100','10101','1011','110','1110','11110','11111'};\r\ncompressed = uint8([27 179 198 146 236 197 238 174 234 222 29 117 111 217 83 5 201 121 11 190 167 232 179 64 52 60 132 189 245 60 210 198 254 48 92 157 245 63 69 154 110 75 22 245 131 182]);\r\nassert(isequal(decode(compressed,table,alphabet),'It is not worth the bother of killing yourself, since you always kill yourself too late.   '))\r\n\r\n%% randomized test (random alphabet)\r\nalphabet = char(randi(13)+96); alphabet=[alphabet alphabet+randi(13)];\r\ntable = {'1','010'};\r\nn=randi(5)+2;\r\ncompressed = repmat([93,85,127],1,n);\r\nassert(isequal(decode(compressed,table,alphabet),regexprep(regexprep(repmat('laaalalalaaaaaaa',1,n),'l',alphabet(2)),'a',alphabet(1)) ))\r\n\r\n%% another randomized test (random code)\r\ncompressed = char(randi(26,1,42)+96);\r\nalphabet = unique(compressed);\r\ncompressed = uint8(compressed);\r\ntable = cellstr(dec2bin(alphabet,8));\r\nassert(isequal(decode(compressed,table,alphabet), char(compressed)));","published":true,"deleted":false,"likes_count":6,"comments_count":2,"created_by":203,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":94,"test_suite_updated_at":"2012-02-01T19:00:28.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-01-30T21:19:56.000Z","updated_at":"2026-03-08T18:55:42.000Z","published_at":"2012-02-01T19:14:05.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eA chunk of data is to be 'decompressed'.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput:\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\u003ecompressed: a row vector of uint8 values. This is the compressed data.\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\u003etable: a cell-array of strings. Each string contains only '1's and '0's and represents a binary code.\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\u003ealphabet: a string containing all possible symbols that may occur in the decompressed data. The symbol at alphabet(x) is encoded with the code at table{x}.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput:\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\u003edecompressed: a string with the decoded message.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[compressed=[93,85,127]\\ntable={'1','010'}\\nalphabet='al'\\n==\u003e  decompressed = 'laaalalalaaaaaaa']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ebecause:\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[[93,85,127] = '01011101 01010101 01111111' in binary\\ndecoded from left to right:\\n'010 1 1 1 010 1 010 1 010 1 1 1 1 1 1 1'\\n= l  a a a  l  a  l  a  l  a a a a a a a]]\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\u003eRemarks: The message is such that always exactly all bits of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecompressed\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are used. The solution is unique (see\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Prefix_code\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eprefix-free code\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\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":1644,"title":"What percentage?","description":"Calculate the output c as the percentage of a on b for given a and b.","description_html":"\u003cp\u003eCalculate the output c as the percentage of a on b for given a and b.\u003c/p\u003e","function_template":"function c = percentage_is(a,b)\r\n  c = 0;\r\nend","test_suite":"%%\r\na = 10;\r\nb = 100;\r\nc_correct = 10;\r\nassert(isequal(percentage_is(a,b),c_correct))\r\n\r\n%%\r\na = 10;\r\nb = 50;\r\nc_correct = 20;\r\nassert(isequal(percentage_is(a,b),c_correct))\r\n\r\n%%\r\na = 10;\r\nb = 20;\r\nc_correct = 50;\r\nassert(isequal(percentage_is(a,b),c_correct))\r\n\r\n%%\r\na = 8;\r\nb = 32;\r\nc_correct = 25;\r\nassert(isequal(percentage_is(a,b),c_correct))\r\n\r\n%%\r\na = 28;\r\nb = 7;\r\nc_correct = 400;\r\nassert(isequal(percentage_is(a,b),c_correct))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":14304,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":523,"test_suite_updated_at":"2013-06-11T20:58:58.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-11T08:41:49.000Z","updated_at":"2026-02-08T05:46:14.000Z","published_at":"2013-06-11T08:42:21.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCalculate the output c as the percentage of a on b for given a and b.\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":43057,"title":"Binary Inversion","description":"Given the unsigned 8-bit integer x, return the number y which is the binary inversion of x.\r\n\r\nFor example if x is 5, y should be 250 because:\r\n\r\n   5 (8-bit): 00000101\r\n\r\n 250 (8-bit): 11111010","description_html":"\u003cp\u003eGiven the unsigned 8-bit integer x, return the number y which is the binary inversion of x.\u003c/p\u003e\u003cp\u003eFor example if x is 5, y should be 250 because:\u003c/p\u003e\u003cpre\u003e   5 (8-bit): 00000101\u003c/pre\u003e\u003cpre\u003e 250 (8-bit): 11111010\u003c/pre\u003e","function_template":"function y = binInvert(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 10;\r\ny_correct = 245;\r\nassert(isequal(binInvert(x),y_correct))\r\n%%\r\nx = 245;\r\ny_correct = 10;\r\nassert(isequal(binInvert(x),y_correct))\r\n%%\r\nx = 20;\r\ny_correct = 235;\r\nassert(isequal(binInvert(x),y_correct))\r\n%%\r\nx = 235;\r\ny_correct = 20;\r\nassert(isequal(binInvert(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":94929,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":67,"test_suite_updated_at":"2016-10-19T11:46:21.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-05T13:46:36.000Z","updated_at":"2026-02-04T15:53:48.000Z","published_at":"2016-10-05T13:46:36.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven the unsigned 8-bit integer x, return the number y which is the binary inversion of x.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example if x is 5, y should be 250 because:\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[   5 (8-bit): 00000101\\n\\n 250 (8-bit): 11111010]]\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":1468,"title":"Numbers at bit-boundary","description":"Find if a number is on or below the bit-boundary, as defined below.\r\nExamples\r\n7,9 straddle the bit-boundary at 2^3 as do 31,32 at 2^5; in these cases 7,8 are on bit boundary as are 31, and 32, but 5 and 33 do not qualify by definition.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 102px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 51px; transform-origin: 407px 51px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 209px 8px; transform-origin: 209px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFind if a number is on or below the bit-boundary, as defined below.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 30px 8px; transform-origin: 30px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExamples\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 377.5px 8px; transform-origin: 377.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e7,9 straddle the bit-boundary at 2^3 as do 31,32 at 2^5; in these cases 7,8 are on bit boundary as are 31, and 32, but 5 and 33 do not qualify by definition.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = on_bit_boundary(x)\r\n\r\nend","test_suite":"%%\r\nx = 2^5;\r\ny_correct = true;\r\nassert( isequal(on_bit_boundary(x),y_correct) )\r\n\r\n%%\r\nx = 2^5 - 5;\r\ny_correct = false;\r\nassert( isequal(on_bit_boundary(x),y_correct) )\r\n\r\n%%\r\nx = 127\r\ny_correct = true;\r\nassert( isequal(on_bit_boundary(x),y_correct) )\r\n\r\n%%\r\nx = 1023\r\nassert( isequal(on_bit_boundary(x),1) )\r\n\r\n%%\r\ny_correct = false;\r\nx = 501\r\nassert( isequal(on_bit_boundary(x),y_correct) )\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":3378,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":35,"test_suite_updated_at":"2021-06-17T09:56:18.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-04-28T17:30:15.000Z","updated_at":"2025-10-30T18:59:13.000Z","published_at":"2013-04-28T17:32:24.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind if a number is on or below the bit-boundary, as defined below.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e7,9 straddle the bit-boundary at 2^3 as do 31,32 at 2^5; in these cases 7,8 are on bit boundary as are 31, and 32, but 5 and 33 do not qualify by definition.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":808,"title":"Hamming Weight - Fast","description":"The Hamming Weight, \u003chttp://en.wikipedia.org/wiki/Hamming_weight wiki Hamming Weight\u003e, in its most simple form is the number of ones in the binary representation of a value.\r\n\r\nThe task here is to create a fast Hamming Weight function/method such that processing many 4K x 4K images of 32 bit integer can be evaluated rapidly. Saw this question posed on Stack Overflow.\r\n\r\n*Input:* Vector of length N of 32 bit integer values.\r\n\r\n*Output:* Vector of number of ones of the binary representation\r\n\r\n*Scoring:* Time in milliseconds to process a [4096*4096,1] vector\r\n\r\n*Examples:* Input [7 ; 3], output=[3;2];  [16 32], output [1;1]; [0 4294967295] output [0;32]\r\n\r\n*Timing Test vector:* uint32(randi(2^32,[4096*4096,1])-1)\r\n\r\n*Minimum vector length/increment:* 65536\r\n\r\nHelpful, possibly, global variables.\r\n\r\nb1=uint32(1431655765); b2=uint32(858993459); b3=uint32(252645135) b4=uint32(16711935); b5=uint32(65535);\r\n\r\nHex: b1=55555555 b2=33333333 b3=0F0F0F0F b4=00FF00FF b5=0000FFFF \r\n\r\nThe array num_ones is created for values 0-65535 (0:2^16-1).\r\nnum_ones(1)=0, num_ones(2)=1, num_ones(3)=1,num_ones(4)=2,...num_ones(65536)=15\r\n\r\nDue to lack of zero indexing num_ones(value+1) is number of ones for value.\r\n\r\n\r\nHint: Globals are not good for time performance.\r\n\r\nHint: Segmentation appears to provide significant time optimization potential.\r\n\r\n\r\n\r\n","description_html":"\u003cp\u003eThe Hamming Weight, \u003ca href=\"http://en.wikipedia.org/wiki/Hamming_weight\"\u003ewiki Hamming Weight\u003c/a\u003e, in its most simple form is the number of ones in the binary representation of a value.\u003c/p\u003e\u003cp\u003eThe task here is to create a fast Hamming Weight function/method such that processing many 4K x 4K images of 32 bit integer can be evaluated rapidly. Saw this question posed on Stack Overflow.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e Vector of length N of 32 bit integer values.\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e Vector of number of ones of the binary representation\u003c/p\u003e\u003cp\u003e\u003cb\u003eScoring:\u003c/b\u003e Time in milliseconds to process a [4096*4096,1] vector\u003c/p\u003e\u003cp\u003e\u003cb\u003eExamples:\u003c/b\u003e Input [7 ; 3], output=[3;2];  [16 32], output [1;1]; [0 4294967295] output [0;32]\u003c/p\u003e\u003cp\u003e\u003cb\u003eTiming Test vector:\u003c/b\u003e uint32(randi(2^32,[4096*4096,1])-1)\u003c/p\u003e\u003cp\u003e\u003cb\u003eMinimum vector length/increment:\u003c/b\u003e 65536\u003c/p\u003e\u003cp\u003eHelpful, possibly, global variables.\u003c/p\u003e\u003cp\u003eb1=uint32(1431655765); b2=uint32(858993459); b3=uint32(252645135) b4=uint32(16711935); b5=uint32(65535);\u003c/p\u003e\u003cp\u003eHex: b1=55555555 b2=33333333 b3=0F0F0F0F b4=00FF00FF b5=0000FFFF\u003c/p\u003e\u003cp\u003eThe array num_ones is created for values 0-65535 (0:2^16-1).\r\nnum_ones(1)=0, num_ones(2)=1, num_ones(3)=1,num_ones(4)=2,...num_ones(65536)=15\u003c/p\u003e\u003cp\u003eDue to lack of zero indexing num_ones(value+1) is number of ones for value.\u003c/p\u003e\u003cp\u003eHint: Globals are not good for time performance.\u003c/p\u003e\u003cp\u003eHint: Segmentation appears to provide significant time optimization potential.\u003c/p\u003e","function_template":"function y = Ham(x)\r\n% Input uint32\r\nglobal num_ones b1 b2 b3 b4 b5\r\n  y = x;\r\nend","test_suite":"%%\r\nfeval(@assignin,'caller','score',2000);\r\n%%\r\nglobal num_ones b1 b2 b3 b4 b5 net_time\r\nnet_time=2000; % default in case of time out (not needed)\r\n\r\nb1=uint32(1431655765); \r\nb2=uint32(858993459);\r\nb3=uint32(252645135);\r\nb4=uint32(16711935);\r\nb5=uint32(65535);\r\n \r\nnum_ones=uint32(zeros(65536,1)); \r\nfor i=0:65535  num_ones(i+1)=length( find( bitget( i, 1:32 ) ) ) ; \r\nend % Cody 0.996 sec\r\n%%\r\nglobal num_ones b1 b2 b3 b4 b5 net_time\r\n\r\nw=uint32(randi(2^32,[65536*1,1])-1); \r\nfor i=1:4 % Clear timing\r\n  vw=Ham(w);\r\nend\r\n\r\nwexpect=num_ones(mod(w,65536)+1)+num_ones(floor(double(w)/65536)+1); %1.56\r\nt0=clock;\r\n vw=Ham(w);\r\n vw=Ham(w);\r\n vw=Ham(w);\r\n vw=Ham(w);\r\ndt=etime(clock,t0)*250*1000; % avg of 4 runs in us\r\nfprintf('Time to execute 65536 values %.0f usec\\n',dt);\r\nassert(isequal(wexpect,vw),sprintf('Time to execute 65536 values %.0f usec\\n',dt))\r\n%%\r\nglobal num_ones b1 b2 b3 b4 b5 net_time\r\n\r\nw=uint32(randi(2^32,[65536*1,1])-1); \r\n\r\n vw=Ham(w); % Three cycles of smaller vector\r\n vw=Ham(w);\r\n vw=Ham(w);\r\n\r\nw=uint32(randi(2^32,[4096*4096,1])-1);\r\nwexpect=num_ones(mod(w,65536)+1)+num_ones(floor(double(w)/65536)+1); %1.56\r\n\r\n \r\n  vw=Ham(w); % Big Prep file\r\n  vw=Ham(w); % Big Prep file\r\n \r\nt0=clock;\r\n vw=Ham(w);\r\n vw=Ham(w);\r\n vw=Ham(w);\r\n vw=Ham(w);\r\nnet_time=etime(clock,t0)*250; % avg of 4 runs\r\nfprintf('Time to execute 4096*4096 values %.0f msec\\n',net_time);\r\n\r\nassert(isequal(wexpect,vw),sprintf('Time to execute 4096*4096 values %.0f msec\\n',net_time))\r\n%%\r\nglobal net_time\r\n% net_time in ms\r\n% Create graph data\r\nnet_time=min(2000,net_time); % Limit graph y-axis\r\n\r\nfeval(@assignin,'caller','score',floor(net_time));\r\n\r\n%fh=fopen('Ham.m','wt');\r\n%fprintf(fh,'%s\\n',repmat('1;',[1,round(net_time/2)]));\r\n%fclose(fh);","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":"2012-11-22T11:18:57.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-06-30T05:08:08.000Z","updated_at":"2026-02-09T12:51:11.000Z","published_at":"2012-07-01T05:19:12.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe Hamming Weight,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Hamming_weight\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ewiki Hamming Weight\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, in its most simple form is the number of ones in the binary representation of a value.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe task here is to create a fast Hamming Weight function/method such that processing many 4K x 4K images of 32 bit integer can be evaluated rapidly. Saw this question posed on Stack Overflow.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Vector of length N of 32 bit integer values.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Vector of number of ones of the binary representation\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eScoring:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Time in milliseconds to process a [4096*4096,1] vector\u003c/w:t\u003e\u003c/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\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Input [7 ; 3], output=[3;2]; [16 32], output [1;1]; [0 4294967295] output [0;32]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTiming Test vector:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e uint32(randi(2^32,[4096*4096,1])-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\u003eMinimum vector length/increment:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 65536\u003c/w:t\u003e\u003c/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\u003eHelpful, possibly, global variables.\u003c/w:t\u003e\u003c/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\u003eb1=uint32(1431655765); b2=uint32(858993459); b3=uint32(252645135) b4=uint32(16711935); b5=uint32(65535);\u003c/w:t\u003e\u003c/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\u003eHex: b1=55555555 b2=33333333 b3=0F0F0F0F b4=00FF00FF b5=0000FFFF\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe array num_ones is created for values 0-65535 (0:2^16-1). num_ones(1)=0, num_ones(2)=1, num_ones(3)=1,num_ones(4)=2,...num_ones(65536)=15\u003c/w:t\u003e\u003c/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\u003eDue to lack of zero indexing num_ones(value+1) is number of ones for value.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHint: Globals are not good for time performance.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHint: Segmentation appears to provide significant time optimization potential.\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":45267,"title":"Zero","description":"given an integer a, find the smallest possible integer b(b\u003e0) such that their bitwise logical AND is zero.\r\n\r\n*  if a=11(1011) then b=4(0100)","description_html":"\u003cp\u003egiven an integer a, find the smallest possible integer b(b\u0026gt;0) such that their bitwise logical AND is zero.\u003c/p\u003e\u003cul\u003e\u003cli\u003eif a=11(1011) then b=4(0100)\u003c/li\u003e\u003c/ul\u003e","function_template":"function b=zero_and(a)\r\nend","test_suite":"%%\r\na = 1;\r\ny_correct = 2;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 2;\r\ny_correct = 1;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 12;\r\ny_correct = 1;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 11;\r\ny_correct = 4;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 15;\r\ny_correct = 16;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 23;\r\ny_correct = 8;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 93;\r\ny_correct = 2;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 1455;\r\ny_correct = 16;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 255;\r\ny_correct = 256;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\na = 435175;\r\ny_correct = 8;\r\nassert(isequal(zero_and(a),y_correct))\r\n%%\r\nfiletext = fileread('zero_and.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp() forbidden')\r\nassert(isempty(strfind(filetext, 'varargin')),'varargin() forbidden')\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":"2020-02-13T21:41:25.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-01-16T14:29:26.000Z","updated_at":"2026-01-03T11:47:45.000Z","published_at":"2020-01-16T14:30:08.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003egiven an integer a, find the smallest possible integer b(b\u0026gt;0) such that their bitwise logical AND is zero.\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\u003eif a=11(1011) then b=4(0100)\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":2202,"title":"Flip the bit","description":"Given an input character string (e.g. '1001'), return a character string with the bits flipped ('0110').","description_html":"\u003cp\u003eGiven an input character string (e.g. '1001'), return a character string with the bits flipped ('0110').\u003c/p\u003e","function_template":"function y = flipbit(s)\r\n  y = '010101';\r\nend","test_suite":"%%\r\ns = '1001';\r\ny_correct = '0110';\r\nassert(all(isequal(flipbit(s),y_correct)\u0026ischar(flipbit(s))))\r\n%%\r\ns = '11';\r\ny_correct = '00';\r\nassert(all(isequal(flipbit(s),y_correct)\u0026ischar(flipbit(s))))\r\n%%\r\ns = '1';\r\ny_correct = '0';\r\nassert(all(isequal(flipbit(s),y_correct)\u0026ischar(flipbit(s))))\r\n%%\r\ns = '100000001';\r\ny_correct = '011111110';\r\nassert(all(isequal(flipbit(s),y_correct)\u0026ischar(flipbit(s))))\r\n%%\r\ns = '00001';\r\ny_correct = '11110';\r\nassert(all(isequal(flipbit(s),y_correct)\u0026ischar(flipbit(s))))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":2,"created_by":39,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":535,"test_suite_updated_at":"2014-02-20T18:44:05.000Z","rescore_all_solutions":false,"group_id":32,"created_at":"2014-02-20T15:53:55.000Z","updated_at":"2026-03-19T20:08:33.000Z","published_at":"2014-02-20T15:56:43.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an input character string (e.g. '1001'), return a character string with the bits flipped ('0110').\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":58399,"title":"Sign of IEEE Single","description":"Output the sign bit of the IEEE representation of the single-typed 32-bit float input as the uint8 \"1\" or the uint8 \"0\".","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 21px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407.5px 10.5px; transform-origin: 407.5px 10.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eOutput the sign bit of the IEEE representation of the single-typed 32-bit float input as the uint8 \"1\" or the uint8 \"0\".\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = signBit(x)\r\n    y = uint8(x);\r\nend","test_suite":"%%\r\nx = single(1);\r\ny_correct = 0;\r\nassert(isequal(signBit(x),y_correct))\r\n\r\nx = single(0.125);\r\ny_correct = 0;\r\nassert(isequal(signBit(x),y_correct))\r\n\r\nx = single(-1);\r\ny_correct = 1;\r\nassert(isequal(signBit(x),y_correct))\r\n\r\nx = single(-0.125);\r\ny_correct = 1;\r\nassert(isequal(signBit(x),y_correct))\r\n\r\nx = single(10000.15);\r\ny_correct = 0;\r\nassert(isequal(signBit(x),y_correct))\r\n\r\nx = single(-1000.15);\r\ny_correct = 1;\r\nassert(isequal(signBit(x),y_correct))\r\n\r\nx = single(0.0);\r\ny_correct = 0;\r\nassert(isequal(signBit(x),y_correct))\r\n\r\nx = single(-0.0);\r\ny_correct = 1;\r\nassert(isequal(signBit(x),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":2436475,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":7,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2023-06-07T20:12:38.000Z","updated_at":"2023-06-07T20:12:38.000Z","published_at":"2023-06-07T20:12:38.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput the sign bit of the IEEE representation of the single-typed 32-bit float input as the uint8 \\\"1\\\" or the uint8 \\\"0\\\".\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":58404,"title":"Mantissa of IEEE Single","description":"Output the mantissa bits as a uint32 of the IEEE representation of the single-typed 32-bit float input. Store these bits in the least significant bits of the uint32.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 42px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407.5px 21px; transform-origin: 407.5px 21px; vertical-align: baseline; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384.5px 21px; text-align: left; transform-origin: 384.5px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eOutput the mantissa bits as a uint32 of the IEEE representation of the single-typed 32-bit float input. Store these bits in the least significant bits of the uint32.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = mantissa(x)\r\n    y = uint32(x);\r\nend","test_suite":"%%\r\nx = single(4);\r\ny_correct = uint32(0);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(1+2^-23);\r\ny_correct = uint32(1);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(1+2^-22);\r\ny_correct = uint32(2);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(-1-2^-22);\r\ny_correct = uint32(2);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(1+2^-23+2^-22);\r\ny_correct = uint32(3);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(-1-2^-23-2^-22);\r\ny_correct = uint32(3);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(100454.4324);\r\ny_correct = uint32(4469559);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(1694995438329000);\r\ny_correct = uint32(4240092);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(0);\r\ny_correct = uint32(0);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(-0.0);\r\ny_correct = uint32(0);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(inf);\r\ny_correct = uint32(0);\r\nassert(isequal(uint32(mantissa(x)),y_correct))\r\n\r\n%%\r\nx = single(-inf);\r\ny_correct = uint32(0);\r\nassert(isequal(uint32(mantissa(x)),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":2436475,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":4,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2023-06-07T20:26:20.000Z","updated_at":"2023-06-07T20:26:20.000Z","published_at":"2023-06-07T20:26:20.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput the mantissa bits as a uint32 of the IEEE representation of the single-typed 32-bit float input. Store these bits in the least significant bits of the uint32.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":45326,"title":"Decimal Fraction to binary conversion","description":"Given an fraction decimal number n, convert it to its equivalent binary number.\r\n\r\nIf it is an infinite binary fraction, keep it upto k precision point.\r\n\r\n* n=55.125\r\n* out='110111.001'","description_html":"\u003cp\u003eGiven an fraction decimal number n, convert it to its equivalent binary number.\u003c/p\u003e\u003cp\u003eIf it is an infinite binary fraction, keep it upto k precision point.\u003c/p\u003e\u003cul\u003e\u003cli\u003en=55.125\u003c/li\u003e\u003cli\u003eout='110111.001'\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = dec2bin_frac(n,k)\r\n  y = x;\r\nend","test_suite":"%%\r\nassert(isequal(dec2bin_frac(123.25),'1111011.01'))\r\n%%\r\nassert(isequal(dec2bin_frac(123.2,6),'1111011.001100'))\r\n%%\r\nassert(isequal(dec2bin_frac(6.97,10), '110.1111100001'))\r\n%%\r\nassert(isequal(dec2bin_frac(61.81250),'111101.1101'))\r\n%%\r\nassert(isequal(dec2bin_frac(666),'1010011010'))\r\n%%\r\nassert(isequal(dec2bin_frac(666624.5),'10100010110000000000.1'))\r\n%%\r\nassert(isequal(dec2bin_frac(55.125,7),'110111.001'))\r\n%%\r\nassert(isequal(dec2bin_frac(123),'1111011'))","published":true,"deleted":false,"likes_count":0,"comments_count":2,"created_by":363598,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":8,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-02-14T19:50:58.000Z","updated_at":"2020-02-14T19:52:21.000Z","published_at":"2020-02-14T19:52:21.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an fraction decimal number n, convert it to its equivalent binary number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf it is an infinite binary fraction, keep it upto k precision point.\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\u003en=55.125\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\u003eout='110111.001'\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":185,"title":"Data decompression","description":"A chunk of data is to be 'decompressed'.\r\n\r\nInput:\r\n\r\n* compressed: a row vector of uint8 values. This is the compressed data.\r\n* table: a cell-array of strings. Each string contains only '1's and '0's and represents a binary code.\r\n* alphabet: a string containing all possible symbols that may occur in the decompressed data. The symbol at alphabet(x) is encoded with the code at table{x}.\r\n\r\nOutput:\r\n\r\n* decompressed: a string with the decoded message.\r\n\r\nExample:\r\n\r\n  compressed=[93,85,127]\r\n  table={'1','010'}\r\n  alphabet='al'\r\n==\u003e  decompressed = 'laaalalalaaaaaaa'\r\n\r\nbecause:  \r\n\r\n  [93,85,127] = '01011101 01010101 01111111' in binary\r\n  decoded from left to right:\r\n  '010 1 1 1 010 1 010 1 010 1 1 1 1 1 1 1'\r\n  = l  a a a  l  a  l  a  l  a a a a a a a\r\n\r\nRemarks: The message is such that always exactly all bits of |compressed| are used. The solution is unique (see \u003chttp://en.wikipedia.org/wiki/Prefix_code prefix-free code\u003e).","description_html":"\u003cp\u003eA chunk of data is to be 'decompressed'.\u003c/p\u003e\u003cp\u003eInput:\u003c/p\u003e\u003cul\u003e\u003cli\u003ecompressed: a row vector of uint8 values. This is the compressed data.\u003c/li\u003e\u003cli\u003etable: a cell-array of strings. Each string contains only '1's and '0's and represents a binary code.\u003c/li\u003e\u003cli\u003ealphabet: a string containing all possible symbols that may occur in the decompressed data. The symbol at alphabet(x) is encoded with the code at table{x}.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eOutput:\u003c/p\u003e\u003cul\u003e\u003cli\u003edecompressed: a string with the decoded message.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ecompressed=[93,85,127]\r\ntable={'1','010'}\r\nalphabet='al'\r\n==\u003e  decompressed = 'laaalalalaaaaaaa'\r\n\u003c/pre\u003e\u003cp\u003ebecause:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[93,85,127] = '01011101 01010101 01111111' in binary\r\ndecoded from left to right:\r\n'010 1 1 1 010 1 010 1 010 1 1 1 1 1 1 1'\r\n= l  a a a  l  a  l  a  l  a a a a a a a\r\n\u003c/pre\u003e\u003cp\u003eRemarks: The message is such that always exactly all bits of \u003ctt\u003ecompressed\u003c/tt\u003e are used. The solution is unique (see \u003ca href=\"http://en.wikipedia.org/wiki/Prefix_code\"\u003eprefix-free code\u003c/a\u003e).\u003c/p\u003e","function_template":"function decompressed = decode(compressed,table,alphabet)\r\n  decompressed = char(compressed);\r\nend","test_suite":"%% the example from the problem description\r\nalphabet = 'al';\r\ntable = {'1','010'};\r\ncompressed = [93,85,127];\r\nassert(isequal(decode(compressed,table,alphabet),'laaalalalaaaaaaa'))\r\n\r\n%% another short test\r\nalphabet = 'ehlo';\r\ntable = {'00','01','10','11'};\r\ncompressed = uint8([74 210 191]);\r\nassert(isequal(decode(compressed,table,alphabet),'hellohellooo'))\r\n\r\n%% longer test\r\nalphabet = ',.kcgIblowaisnufhe try';\r\ntable = {'000000','000001','00001','000100','000101','000110','000111','001','010','01100','01101','0111','1000','10010','10011','10100','10101','1011','110','1110','11110','11111'};\r\ncompressed = uint8([27 179 198 146 236 197 238 174 234 222 29 117 111 217 83 5 201 121 11 190 167 232 179 64 52 60 132 189 245 60 210 198 254 48 92 157 245 63 69 154 110 75 22 245 131 182]);\r\nassert(isequal(decode(compressed,table,alphabet),'It is not worth the bother of killing yourself, since you always kill yourself too late.   '))\r\n\r\n%% randomized test (random alphabet)\r\nalphabet = char(randi(13)+96); alphabet=[alphabet alphabet+randi(13)];\r\ntable = {'1','010'};\r\nn=randi(5)+2;\r\ncompressed = repmat([93,85,127],1,n);\r\nassert(isequal(decode(compressed,table,alphabet),regexprep(regexprep(repmat('laaalalalaaaaaaa',1,n),'l',alphabet(2)),'a',alphabet(1)) ))\r\n\r\n%% another randomized test (random code)\r\ncompressed = char(randi(26,1,42)+96);\r\nalphabet = unique(compressed);\r\ncompressed = uint8(compressed);\r\ntable = cellstr(dec2bin(alphabet,8));\r\nassert(isequal(decode(compressed,table,alphabet), char(compressed)));","published":true,"deleted":false,"likes_count":6,"comments_count":2,"created_by":203,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":94,"test_suite_updated_at":"2012-02-01T19:00:28.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-01-30T21:19:56.000Z","updated_at":"2026-03-08T18:55:42.000Z","published_at":"2012-02-01T19:14:05.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eA chunk of data is to be 'decompressed'.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput:\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\u003ecompressed: a row vector of uint8 values. This is the compressed data.\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\u003etable: a cell-array of strings. Each string contains only '1's and '0's and represents a binary code.\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\u003ealphabet: a string containing all possible symbols that may occur in the decompressed data. The symbol at alphabet(x) is encoded with the code at table{x}.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput:\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\u003edecompressed: a string with the decoded message.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[compressed=[93,85,127]\\ntable={'1','010'}\\nalphabet='al'\\n==\u003e  decompressed = 'laaalalalaaaaaaa']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ebecause:\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[[93,85,127] = '01011101 01010101 01111111' in binary\\ndecoded from left to right:\\n'010 1 1 1 010 1 010 1 010 1 1 1 1 1 1 1'\\n= l  a a a  l  a  l  a  l  a a a a a a a]]\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\u003eRemarks: The message is such that always exactly all bits of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecompressed\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are used. The solution is unique (see\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Prefix_code\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eprefix-free code\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\"}]}"}],"term":"tag:\"bit manipulation\"","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:\"bit manipulation\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"bit manipulation\"","","\"","bit manipulation","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f5348c5dcb0\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f5348c5dc10\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f5348c5d350\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f5348c5df30\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f5348c5de90\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f5348c5ddf0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f5348c5dd50\u003e":"tag:\"bit manipulation\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f5348c5dd50\u003e":"tag:\"bit manipulation\""},"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":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"bit manipulation\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"bit manipulation\"","","\"","bit manipulation","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f5348c5dcb0\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f5348c5dc10\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f5348c5d350\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f5348c5df30\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f5348c5de90\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f5348c5ddf0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f5348c5dd50\u003e":"tag:\"bit manipulation\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f5348c5dd50\u003e":"tag:\"bit manipulation\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":1644,"difficulty_rating":"easy"},{"id":43057,"difficulty_rating":"easy"},{"id":1468,"difficulty_rating":"easy"},{"id":808,"difficulty_rating":"easy"},{"id":45267,"difficulty_rating":"easy-medium"},{"id":2202,"difficulty_rating":"easy-medium"},{"id":58399,"difficulty_rating":"easy-medium"},{"id":58404,"difficulty_rating":"easy-medium"},{"id":45326,"difficulty_rating":"easy-medium"},{"id":185,"difficulty_rating":"medium"}]}}