{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-04-06T14:01:22.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2026-04-06T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":647,"title":"Getting the absolute index from a matrix","description":"This is a basic MATLAB operation. It is for instructional purposes.\r\n\r\n---\r\n\r\nYou may already know how to get the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/646-getting-the-row-and-column-location-from-a-matrix row and column index from a matrix\u003e, and the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector logical indexing\u003e technique but there is another way to reference specific elements in a matrix.\r\n\r\nAbsolute indexing refers to specific elements with a single scalar rather than two (row and column).  The upper left entry is value 1, the lower right is the highest value.  MATLAB is column major, so you count down the rows in a specific column first, moving right as needed until you reach the end.\r\n\r\n\u003chttp://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector Indexing into a vector\u003e is really using this kind of indexing, but it is more natural feeling.\r\n\r\nUse \u003chttp://www.mathworks.com/help/techdoc/ref/find.html Find\u003e.\r\n\r\nGiven a matrix M, return the absolute indices where M is greater than scalar, LB (Lower Bound) and less than UB (Upper Bound).  (See \u003chttp://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector Binary comparison\u003e to satisfy two conditions)","description_html":"\u003cp\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/p\u003e\u003cp\u003e---\u003c/p\u003e\u003cp\u003eYou may already know how to get the \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/646-getting-the-row-and-column-location-from-a-matrix\"\u003erow and column index from a matrix\u003c/a\u003e, and the \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\"\u003elogical indexing\u003c/a\u003e technique but there is another way to reference specific elements in a matrix.\u003c/p\u003e\u003cp\u003eAbsolute indexing refers to specific elements with a single scalar rather than two (row and column).  The upper left entry is value 1, the lower right is the highest value.  MATLAB is column major, so you count down the rows in a specific column first, moving right as needed until you reach the end.\u003c/p\u003e\u003cp\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\"\u003eIndexing into a vector\u003c/a\u003e is really using this kind of indexing, but it is more natural feeling.\u003c/p\u003e\u003cp\u003eUse \u003ca href=\"http://www.mathworks.com/help/techdoc/ref/find.html\"\u003eFind\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven a matrix M, return the absolute indices where M is greater than scalar, LB (Lower Bound) and less than UB (Upper Bound).  (See \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\"\u003eBinary comparison\u003c/a\u003e to satisfy two conditions)\u003c/p\u003e","function_template":"function AI = absoluteInBetween(M, LB, UB)\r\n  AI = 1;\r\nend","test_suite":"%%\r\nM = magic(5)\r\nLB = 3;\r\nUB = 10;\r\n\r\nAI = find((M \u003e LB) \u0026 (M \u003c UB));\r\n\r\nassert(isequal(absoluteInBetween(M, LB, UB),AI))\r\n\r\n%%\r\nM = magic(10)\r\nLB = 3;\r\nUB = 10;\r\n\r\nAI = find((M \u003e LB) \u0026 (M \u003c UB));\r\n\r\nassert(isequal(absoluteInBetween(M, LB, UB),AI))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":257,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-01T15:39:39.000Z","updated_at":"2026-03-29T19:40:43.000Z","published_at":"2012-05-01T15:39:39.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e---\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may already know how to get the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/646-getting-the-row-and-column-location-from-a-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003erow and column index from a matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, and the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003elogical indexing\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e technique but there is another way to reference specific elements in a matrix.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eAbsolute indexing refers to specific elements with a single scalar rather than two (row and column). The upper left entry is value 1, the lower right is the highest value. MATLAB is column major, so you count down the rows in a specific column first, moving right as needed until you reach the end.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eIndexing into a vector\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is really using this kind of indexing, but it is more natural feeling.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eUse\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/techdoc/ref/find.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFind\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix M, return the absolute indices where M is greater than scalar, LB (Lower Bound) and less than UB (Upper Bound). (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://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eBinary comparison\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e to satisfy two conditions)\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":646,"title":"Getting the row and column location from a matrix","description":"This is a basic MATLAB operation. It is for instructional purposes.\r\n\r\n---\r\n\r\nYou may already know how to get \u003chttp://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector logical indexes\u003e from a vector, and to \u003chttp://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector find the location\u003e of elements in a vector.\r\n\r\nWhat if you are dealing with a matrix.  Often you will want the row and column location of an element, or set of elements.  For instance:\r\n\r\n   [0 1 0\r\n    0 0 0]\r\n\r\nYou might want \r\n\r\n  row = 1\r\n  col = 2\r\n\r\nor \r\n\r\n   [0 1 1\r\n    1 0 0]\r\n\r\n   row = [2\r\n          1\r\n          1]\r\n\r\n   col = [1\r\n          2\r\n          3]\r\n\r\nCheck out \u003chttp://www.mathworks.com/help/techdoc/ref/find.html Find\u003e to learn to do this.\r\n\r\nGiven a matrix, M, return the column vectors that represent the row and column indices, r and c, where the given matrix, M is greater than the threshold value, thresh.  R and C will be combined into matrix out.","description_html":"\u003cp\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/p\u003e\u003cp\u003e---\u003c/p\u003e\u003cp\u003eYou may already know how to get \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\"\u003elogical indexes\u003c/a\u003e from a vector, and to \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\"\u003efind the location\u003c/a\u003e of elements in a vector.\u003c/p\u003e\u003cp\u003eWhat if you are dealing with a matrix.  Often you will want the row and column location of an element, or set of elements.  For instance:\u003c/p\u003e\u003cpre\u003e   [0 1 0\r\n    0 0 0]\u003c/pre\u003e\u003cp\u003eYou might want\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003erow = 1\r\ncol = 2\r\n\u003c/pre\u003e\u003cp\u003eor\u003c/p\u003e\u003cpre\u003e   [0 1 1\r\n    1 0 0]\u003c/pre\u003e\u003cpre\u003e   row = [2\r\n          1\r\n          1]\u003c/pre\u003e\u003cpre\u003e   col = [1\r\n          2\r\n          3]\u003c/pre\u003e\u003cp\u003eCheck out \u003ca href=\"http://www.mathworks.com/help/techdoc/ref/find.html\"\u003eFind\u003c/a\u003e to learn to do this.\u003c/p\u003e\u003cp\u003eGiven a matrix, M, return the column vectors that represent the row and column indices, r and c, where the given matrix, M is greater than the threshold value, thresh.  R and C will be combined into matrix out.\u003c/p\u003e","function_template":"function out = RCgreaterThan(M, thresh)\r\n  r = 1;\r\n  c = 1;\r\n  out = [r c]; %only one output can be checked in Cody!\r\nend","test_suite":"%%\r\nM = magic(5);\r\nthresh = 4;\r\n\r\n[r,c]= find(magic(5) \u003e 4)\r\nout = [r c]\r\n\r\nassert(isequal(RCgreaterThan(M, thresh),out))\r\n\r\n%%\r\nM = magic(6);\r\nthresh = 2;\r\n\r\n[r,c]= find(magic(6) \u003e 2)\r\nout = [r c]\r\n\r\nassert(isequal(RCgreaterThan(M, thresh),out))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":299,"test_suite_updated_at":"2012-05-01T15:24:26.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-01T15:19:06.000Z","updated_at":"2026-03-09T20:35:23.000Z","published_at":"2012-05-01T15:24:26.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e---\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may already know how to get\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003elogical indexes\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e from a vector, and to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efind the location\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e of elements in a 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:t\u003eWhat if you are dealing with a matrix. Often you will want the row and column location of an element, or set of elements. For instance:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   [0 1 0\\n    0 0 0]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou might want\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[row = 1\\ncol = 2]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eor\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   [0 1 1\\n    1 0 0]\\n\\n   row = [2\\n          1\\n          1]\\n\\n   col = [1\\n          2\\n          3]]]\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\u003eCheck out\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/techdoc/ref/find.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFind\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e to learn to do this.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix, M, return the column vectors that represent the row and column indices, r and c, where the given matrix, M is greater than the threshold value, thresh. R and C will be combined into matrix out.\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":640,"title":"Getting logical indexes","description":"This is a basic MATLAB operation.  It is for instructional purposes.\r\n\r\n---\r\n\r\nLogical indexing works like this.\r\n\r\n  thresh = 4;\r\n  vec    = [1 2 3 4 5 6 7 8];\r\n  \r\n  vi     = (vec \u003e thresh)\r\n  \r\n  vi =\r\n  \r\n       0     0     0     0     1     1     1     1\r\n\r\nOnce you have this TRUE FALSE vector (I call it vi: Valid Indices)\r\n\r\nIt can be used to get the values out:\r\n\r\n  big = vec(vi)\r\n  \r\n  big =\r\n  \r\n       5     6     7     8\r\n\r\nGiven a vector, vec, and a value, v, return a binary vector that represents the indices where vector, vec, is equal to scalar, v.\r\n\r\nNote, this works just as well with scalars and matrices.\r\n\r\n----\r\n\r\nTo get the indices where this comparison is true, see this \u003chttp://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector Cody problem\u003e.","description_html":"\u003cp\u003eThis is a basic MATLAB operation.  It is for instructional purposes.\u003c/p\u003e\u003cp\u003e---\u003c/p\u003e\u003cp\u003eLogical indexing works like this.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ethresh = 4;\r\nvec    = [1 2 3 4 5 6 7 8];\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003evi     = (vec \u003e thresh)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003evi =\r\n\u003c/pre\u003e\u003cpre\u003e       0     0     0     0     1     1     1     1\u003c/pre\u003e\u003cp\u003eOnce you have this TRUE FALSE vector (I call it vi: Valid Indices)\u003c/p\u003e\u003cp\u003eIt can be used to get the values out:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ebig = vec(vi)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ebig =\r\n\u003c/pre\u003e\u003cpre\u003e       5     6     7     8\u003c/pre\u003e\u003cp\u003eGiven a vector, vec, and a value, v, return a binary vector that represents the indices where vector, vec, is equal to scalar, v.\u003c/p\u003e\u003cp\u003eNote, this works just as well with scalars and matrices.\u003c/p\u003e\u003cp\u003e----\u003c/p\u003e\u003cp\u003eTo get the indices where this comparison is true, see this \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\"\u003eCody problem\u003c/a\u003e.\u003c/p\u003e","function_template":"function vi = binaryEqualsVector(vec, v)\r\n  vi = true;\r\nend","test_suite":"%%\r\nvec = [1 2 3 3 2 1];\r\nv = 2;\r\ny_correct = [false true false false true false];\r\nassert(isequal(binaryEqualsVector(vec,v),y_correct))\r\n\r\n%%\r\nvec = [1 2 3 4 5 6];\r\nv = 0;\r\ny_correct = [false false false false false false];\r\nassert(isequal(binaryEqualsVector(vec,v),y_correct))\r\n\r\n%%\r\nvec = [1 1 1 1 1];\r\nv = 1;\r\ny_correct = [true true true true true];\r\nassert(isequal(binaryEqualsVector(vec,v),y_correct))\r\n\r\n%%\r\nvec = 'abcdef';\r\nv = 'a';\r\ny_correct = [true false false false false false];\r\nassert(isequal(binaryEqualsVector(vec,v),y_correct))\r\n","published":true,"deleted":false,"likes_count":9,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1184,"test_suite_updated_at":"2012-04-30T18:48:13.000Z","rescore_all_solutions":false,"group_id":12,"created_at":"2012-04-30T18:46:03.000Z","updated_at":"2026-04-10T23:47:02.000Z","published_at":"2012-04-30T18:48:13.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e---\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLogical indexing works like this.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[thresh = 4;\\nvec    = [1 2 3 4 5 6 7 8];\\n\\nvi     = (vec \u003e thresh)\\n\\nvi =\\n\\n       0     0     0     0     1     1     1     1]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOnce you have this TRUE FALSE vector (I call it vi: Valid Indices)\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eIt can be used to get the values out:\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[big = vec(vi)\\n\\nbig =\\n\\n       5     6     7     8]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector, vec, and a value, v, return a binary vector that represents the indices where vector, vec, is equal to scalar, v.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eNote, this works just as well with scalars and matrices.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e----\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo get the indices where this comparison is true, see this\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\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":648,"title":"Cumulative probability of finding an unlikely combination","description":"This is a supplemental problem to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition CryptoMath\u003e problem.  If you solve the problem methodically or randomly matters for expected solution time.  This calculates the difference in techniques.  My reference solution has some commented out graphics code to visualize the timing differences.\r\n\r\n---\r\n\r\nIf you have N possible combinations to a lock you can calculate the likelihood of opening the lock as a percentage given X attempts.\r\n\r\nThere are two ways to figure out the combination to try:\r\n\r\n* Try a random one, possibly trying an old one again\r\n* Methodically doing them in order\r\n\r\nChoosing a random combination is very fast and easy.  No record keeping needed.  Choosing a methodical way of trying them all is a little slower on each attempt, and incurs a fix cost before the first attempt is made.\r\n\r\nIf you have:\r\n\r\n* Goal of *G%* cumulative probability of opening the lock\r\n* Fixed cost of *F* seconds to start the methodical style\r\n* *TR* seconds per random attempt\r\n* *TM* seconds per methodical attempt\r\n* *N* equally likely combinations\r\n\r\nWhich technique should you use to get to your goal chance fastest?\r\n\r\n* *0* for random\r\n* *1* for methodical\r\n\r\n---\r\nNote for the curious:  The really short solution is gaming the system and just choosing randomly.  Eventually one of the solutions will guess right on all the test suite.","description_html":"\u003cp\u003eThis is a supplemental problem to the \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\"\u003eCryptoMath\u003c/a\u003e problem.  If you solve the problem methodically or randomly matters for expected solution time.  This calculates the difference in techniques.  My reference solution has some commented out graphics code to visualize the timing differences.\u003c/p\u003e\u003cp\u003e---\u003c/p\u003e\u003cp\u003eIf you have N possible combinations to a lock you can calculate the likelihood of opening the lock as a percentage given X attempts.\u003c/p\u003e\u003cp\u003eThere are two ways to figure out the combination to try:\u003c/p\u003e\u003cul\u003e\u003cli\u003eTry a random one, possibly trying an old one again\u003c/li\u003e\u003cli\u003eMethodically doing them in order\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eChoosing a random combination is very fast and easy.  No record keeping needed.  Choosing a methodical way of trying them all is a little slower on each attempt, and incurs a fix cost before the first attempt is made.\u003c/p\u003e\u003cp\u003eIf you have:\u003c/p\u003e\u003cul\u003e\u003cli\u003eGoal of \u003cb\u003eG%\u003c/b\u003e cumulative probability of opening the lock\u003c/li\u003e\u003cli\u003eFixed cost of \u003cb\u003eF\u003c/b\u003e seconds to start the methodical style\u003c/li\u003e\u003cli\u003e\u003cb\u003eTR\u003c/b\u003e seconds per random attempt\u003c/li\u003e\u003cli\u003e\u003cb\u003eTM\u003c/b\u003e seconds per methodical attempt\u003c/li\u003e\u003cli\u003e\u003cb\u003eN\u003c/b\u003e equally likely combinations\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eWhich technique should you use to get to your goal chance fastest?\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003cb\u003e0\u003c/b\u003e for random\u003c/li\u003e\u003cli\u003e\u003cb\u003e1\u003c/b\u003e for methodical\u003c/li\u003e\u003c/ul\u003e\u003cp\u003e---\r\nNote for the curious:  The really short solution is gaming the system and just choosing randomly.  Eventually one of the solutions will guess right on all the test suite.\u003c/p\u003e","function_template":"function choice = chaosOrOrder(g,f,tr,tm, n)\r\n  y = 0;\r\nend","test_suite":"%%\r\ng  =  0.9;\r\nf  = 10;\r\ntr =  1;\r\ntm =  2;\r\nn  = 10;\r\nout = 0;\r\n\r\nassert(isequal(chaosOrOrder(g,f,tr,tm,n),out))\r\n\r\n%%\r\ng  =  0.9;\r\nf  = 10;\r\ntr =  1;\r\ntm =  2;\r\nn  = 100;\r\nout = 1;\r\n\r\nassert(isequal(chaosOrOrder(g,f,tr,tm,n),out))\r\n\r\n%%\r\ng  =  0.9;\r\nf  = 10;\r\ntr =  .1;\r\ntm =  2;\r\nn  = 10000;\r\nout = 0;\r\n\r\nassert(isequal(chaosOrOrder(g,f,tr,tm,n),out))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":35,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-01T17:58:41.000Z","updated_at":"2025-11-27T17:33:42.000Z","published_at":"2012-05-01T19:29:40.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a supplemental problem to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCryptoMath\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e problem. If you solve the problem methodically or randomly matters for expected solution time. This calculates the difference in techniques. My reference solution has some commented out graphics code to visualize the timing differences.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e---\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf you have N possible combinations to a lock you can calculate the likelihood of opening the lock as a percentage given X attempts.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are two ways to figure out the combination to try:\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\u003eTry a random one, possibly trying an old one again\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\u003eMethodically doing them in order\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eChoosing a random combination is very fast and easy. No record keeping needed. Choosing a methodical way of trying them all is a little slower on each attempt, and incurs a fix cost before the first attempt is made.\u003c/w:t\u003e\u003c/w:r\u003e\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 you have:\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\u003eGoal of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eG%\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e cumulative probability of opening the lock\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\u003eFixed cost of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eF\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e seconds to start the methodical style\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTR\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e seconds per random attempt\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTM\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e seconds per methodical attempt\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e equally likely combinations\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhich technique should you use to get to your goal chance fastest?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for random\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for methodical\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e--- Note for the curious: The really short solution is gaming the system and just choosing randomly. Eventually one of the solutions will guess right on all the test suite.\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":641,"title":"Make a random, non-repeating vector.","description":"This is a basic MATLAB operation. It is for instructional purposes.\r\n\r\n---\r\n\r\nIf you want to get a random permutation of integers \u003chttp://www.mathworks.com/help/techdoc/ref/randperm.html randperm\u003e will help.\r\n\r\nGiven n, put the integers [1 2 3... N] in a random order.\r\n\r\nYes, the test suite is not conclusive, but it is pretty close!","description_html":"\u003cp\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/p\u003e\u003cp\u003e---\u003c/p\u003e\u003cp\u003eIf you want to get a random permutation of integers \u003ca href=\"http://www.mathworks.com/help/techdoc/ref/randperm.html\"\u003erandperm\u003c/a\u003e will help.\u003c/p\u003e\u003cp\u003eGiven n, put the integers [1 2 3... N] in a random order.\u003c/p\u003e\u003cp\u003eYes, the test suite is not conclusive, but it is pretty close!\u003c/p\u003e","function_template":"function vec = makeRandomOrdering(n)\r\n  vec = n;\r\nend","test_suite":"%%\r\nn = 10;\r\n\r\nflagSame    = isequal(makeRandomOrdering(n), makeRandomOrdering(n));\r\nflagAllUsed = isequal([1:n],sort(makeRandomOrdering(n)));\r\nassert(~flagSame \u0026 flagAllUsed)","published":true,"deleted":false,"likes_count":48,"comments_count":2,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":11282,"test_suite_updated_at":"2012-04-30T20:15:56.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-30T20:13:04.000Z","updated_at":"2026-04-15T14:47:00.000Z","published_at":"2012-04-30T20:15:56.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e---\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf you want to get a random permutation of integers\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/techdoc/ref/randperm.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003erandperm\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e will help.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven n, put the integers [1 2 3... N] in a random order.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eYes, the test suite is not conclusive, but it is pretty close!\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":642,"title":"Convert a vector into a number","description":"This is a sub problem related to this problem:\r\n\r\n\u003chttp://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\u003e\r\n\r\nIf vector, v, has only whole numbers [0 1 2 ... 9], then it can be turned into a base ten number as follows:\r\n\r\n  [3 4 2 9] ---\u003e 3429\r\n  [1 3 5]   ---\u003e  135\r\n\r\nMake this conversion.","description_html":"\u003cp\u003eThis is a sub problem related to this problem:\u003c/p\u003e\u003cp\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\"\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\u003c/a\u003e\u003c/p\u003e\u003cp\u003eIf vector, v, has only whole numbers [0 1 2 ... 9], then it can be turned into a base ten number as follows:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[3 4 2 9] ---\u003e 3429\r\n[1 3 5]   ---\u003e  135\r\n\u003c/pre\u003e\u003cp\u003eMake this conversion.\u003c/p\u003e","function_template":"function out = digits2Number(vec)\r\n  out = 1;\r\nend","test_suite":"%%\r\nvec = [2 4 9 2];\r\ny_correct = 2492;\r\nassert(isequal(digits2Number(vec),y_correct))\r\n%%\r\nvec = [3 2]';\r\ny_correct = 32;\r\nassert(isequal(digits2Number(vec),y_correct))\r\n%%\r\nvec = [0 1 3 8 9 0];\r\ny_correct = 13890;\r\nassert(isequal(digits2Number(vec),y_correct))\r\n%%\r\nvec = [0 0 9 8 2];\r\ny_correct = 982;\r\nassert(isequal(digits2Number(vec),y_correct))","published":true,"deleted":false,"likes_count":11,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":615,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-30T20:37:07.000Z","updated_at":"2026-03-11T13:59:59.000Z","published_at":"2012-04-30T20:37:23.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a sub problem related to this problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf vector, v, has only whole numbers [0 1 2 ... 9], then it can be turned into a base ten number as follows:\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[[3 4 2 9] ---\u003e 3429\\n[1 3 5]   ---\u003e  135]]\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\u003eMake this conversion.\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":601,"title":"Retirement savings","description":"At the start of what year will you have reached or exceeded a savings goal?\r\n\r\nParameters (all are constant scalars given in a structure):\r\n\r\n*  *f.startingSalary*: Starting yearly salary\r\n*  *f.investRate*: Percentage of salary invested each year\r\n*  *f.raiseRate*: Percentage raise given at beginning of year EXCEPT the first\r\n*  *f.returnRate*: Percentage gain in invested money\r\n*  *f.goal*: Savings goal\r\n\r\nSimplifying assumptions:\r\n\r\n* All money is invested at the end of the year.\r\n* Interest is awarded once at the end of the year on money that has been invest for an entire year\r\n* All interest is reinvested immediately and will gain interest the next year\r\n\r\nReturn:\r\n\r\n* At the beginning of which year will the goal been met or exceeded?","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: 346.9px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 173.45px; transform-origin: 407px 173.45px; 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: 237.5px 8px; transform-origin: 237.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAt the start of what year will you have reached or exceeded a savings goal?\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: 181px 8px; transform-origin: 181px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eParameters (all are constant scalars given in a structure):\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 102.167px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 51.0833px; transform-origin: 391px 51.0833px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 52.5px 8px; transform-origin: 52.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ef.startingSalary\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 70.5px 8px; transform-origin: 70.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e: Starting yearly salary\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 42.5px 8px; transform-origin: 42.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ef.investRate\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 131.5px 8px; transform-origin: 131.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e: Percentage of salary invested each year\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 38px 8px; transform-origin: 38px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ef.raiseRate\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 196.5px 8px; transform-origin: 196.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e: Percentage raise given at beginning of year EXCEPT the first\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 42.5px 8px; transform-origin: 42.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ef.returnRate\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 115px 8px; transform-origin: 115px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e: Percentage gain in invested money\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 19.5px 8px; transform-origin: 19.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ef.goal\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 44.5px 8px; transform-origin: 44.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e: Savings goal\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\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: 77px 8px; transform-origin: 77px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSimplifying assumptions:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 61.3px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 30.65px; transform-origin: 391px 30.65px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 137.5px 8px; transform-origin: 137.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAll money is invested at the end of the year.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 302.5px 8px; transform-origin: 302.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eInterest is awarded once at the end of the year on money that has been invest for an entire year\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 223px 8px; transform-origin: 223px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAll interest is reinvested immediately and will gain interest the next year\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\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: 23.5px 8px; transform-origin: 23.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 20.4333px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 10.2167px; transform-origin: 391px 10.2167px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 210px 8px; transform-origin: 210px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAt the beginning of which year will the goal been met or exceeded?\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function year = calculateRetirementYear(f)\r\n  %f.startingSalary\r\n  %f.investRate\r\n  %f.returnRate\r\n  %f.raiseRate\r\n  %f.goal\r\n  year = 1;\r\nend","test_suite":"%%\r\nfinancial.startingSalary =   50000;\r\nfinancial.investRate     =       0.1;\r\nfinancial.returnRate     =       0.1;\r\nfinancial.raiseRate      =       0.05;\r\nfinancial.goal           = 1000000;\r\n\r\ny_correct = 29;\r\nassert(isequal(calculateRetirementYear(financial),y_correct))\r\n\r\n%%\r\nfinancial.startingSalary =   60000;\r\nfinancial.investRate     =       0.12;\r\nfinancial.returnRate     =       0.1;\r\nfinancial.raiseRate      =       0.05;\r\nfinancial.goal           = 1000000;\r\n\r\ny_correct = 26;\r\nassert(isequal(calculateRetirementYear(financial),y_correct))\r\n\r\n%%\r\nfinancial.startingSalary =   60000;\r\nfinancial.investRate     =       0.12;\r\nfinancial.returnRate     =       0.1;\r\nfinancial.raiseRate      =       0.05;\r\nfinancial.goal           = 2000000;\r\n\r\ny_correct = 32;\r\nassert(isequal(calculateRetirementYear(financial),y_correct))\r\n\r\n%%\r\nfinancial.startingSalary =   60000;\r\nfinancial.investRate     =       0.12;\r\nfinancial.returnRate     =       0.1;\r\nfinancial.raiseRate      =       0.08;\r\nfinancial.goal           = 2000000;\r\n\r\ny_correct = 29;\r\nassert(isequal(calculateRetirementYear(financial),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":29,"test_suite_updated_at":"2020-10-26T17:52:05.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-19T15:41:36.000Z","updated_at":"2025-10-01T03:42:14.000Z","published_at":"2012-04-19T15:41:36.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\u003eAt the start of what year will you have reached or exceeded a savings goal?\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\u003eParameters (all are constant scalars given in a structure):\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ef.startingSalary\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: Starting yearly salary\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ef.investRate\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: Percentage of salary invested each year\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ef.raiseRate\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: Percentage raise given at beginning of year EXCEPT the first\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ef.returnRate\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: Percentage gain in invested money\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ef.goal\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: Savings goal\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\u003eSimplifying assumptions:\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAll money is invested at the end of the year.\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInterest is awarded once at the end of the year on money that has been invest for an entire year\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAll interest is reinvested immediately and will gain interest the next year\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\u003eReturn:\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAt the beginning of which year will the goal been met or exceeded?\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":639,"title":"String substitution, sub problem to cryptoMath","description":"This is a sub problem related to this problem:\r\n\r\n\u003chttp://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\u003e\r\n\r\nIf you have a string\r\n\r\n  'cab' \r\n\r\nand you have a mapping where you want:\r\n\r\n  'abc' to map to the digits [906]\r\n\r\nthen you will get this:\r\n\r\n  % 'cab' , 'abc', [906] --\u003e [6 9 0];\r\n\r\nAnother example is:\r\n\r\n  % 'feed', 'def', [541] --\u003e [1 4 4 5];\r\n\r\nYour inputs will be of this form:\r\n\r\n  out = stringSubstitute(string, letters, digits)\r\n  \r\n  \u003e\u003e stringSubstitute('feed','def',[5 4 1])\r\n  \r\n  ans =\r\n  \r\n       1     4     4     5\r\n\r\n","description_html":"\u003cp\u003eThis is a sub problem related to this problem:\u003c/p\u003e\u003cp\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\"\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\u003c/a\u003e\u003c/p\u003e\u003cp\u003eIf you have a string\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e'cab' \r\n\u003c/pre\u003e\u003cp\u003eand you have a mapping where you want:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e'abc' to map to the digits [906]\r\n\u003c/pre\u003e\u003cp\u003ethen you will get this:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e% 'cab' , 'abc', [906] --\u003e [6 9 0];\r\n\u003c/pre\u003e\u003cp\u003eAnother example is:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e% 'feed', 'def', [541] --\u003e [1 4 4 5];\r\n\u003c/pre\u003e\u003cp\u003eYour inputs will be of this form:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eout = stringSubstitute(string, letters, digits)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003e\u003e\u003e stringSubstitute('feed','def',[5 4 1])\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eans =\r\n\u003c/pre\u003e\u003cpre\u003e       1     4     4     5\u003c/pre\u003e","function_template":"function out = stringSubstitute(string, letters, digits)\r\n  y = 1;\r\nend","test_suite":"%%\r\nstring  = 'cab';\r\nletters = 'abc';\r\ndigits  = [9 0 6]; \r\ny_correct = [6 9 0];\r\nassert(isequal(stringSubstitute(string, letters, digits),y_correct))\r\n\r\n%%\r\n\r\nstring  = 'feed';\r\nletters = 'def';\r\ndigits  = [5 4 1]; \r\ny_correct = [1 4 4 5];\r\nassert(isequal(stringSubstitute(string, letters, digits),y_correct))\r\n\r\n%%\r\n\r\nstring  = 'matlab';\r\nletters = 'ablmt';\r\ndigits  = [0 3 4 6 1]; \r\ny_correct = [6 0 1 4 0 3];\r\nassert(isequal(stringSubstitute(string, letters, digits),y_correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":245,"test_suite_updated_at":"2012-04-30T17:27:03.000Z","rescore_all_solutions":false,"group_id":14,"created_at":"2012-04-30T15:20:02.000Z","updated_at":"2026-04-10T15:08:36.000Z","published_at":"2012-04-30T17:27:03.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a sub problem related to this problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf you have a string\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['cab']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eand you have a mapping where you want:\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['abc' to map to the digits [906]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethen you will get this:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[% 'cab' , 'abc', [906] --\u003e [6 9 0];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAnother example is:\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[% 'feed', 'def', [541] --\u003e [1 4 4 5];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour inputs will be of this form:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[out = stringSubstitute(string, letters, digits)\\n\\n\u003e\u003e stringSubstitute('feed','def',[5 4 1])\\n\\nans =\\n\\n       1     4     4     5]]\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":602,"title":"Make a simplified barcode","description":"Given an integer to encode, make a barcode using the following encoding scheme:\r\n\r\n* The bar code is made from the binary version of the integer\r\n* The bar code is a matrix 30x?\r\n* A '1' becomes a thick bar\r\n* A '0' becomes a thin bar\r\n* Bars are represented by 0's in the output\r\n* A '1' becomes '0 0 0'\r\n* A '0' becomes '0'\r\n* White space between bars is a single 1\r\n* There will be no left hand zeros in the binary representation\r\n* There are three columns of white space at beginning and end of bar code\r\nFor example:\r\n\r\nInput 5 yields\r\n\r\n[1 1 1 0 0 0 1 0 1 0 0 0 1 1 1] (only repeated for 30 rows);\r\n\r\n","description_html":"\u003cp\u003eGiven an integer to encode, make a barcode using the following encoding scheme:\u003c/p\u003e\u003cul\u003e\u003cli\u003eThe bar code is made from the binary version of the integer\u003c/li\u003e\u003cli\u003eThe bar code is a matrix 30x?\u003c/li\u003e\u003cli\u003eA '1' becomes a thick bar\u003c/li\u003e\u003cli\u003eA '0' becomes a thin bar\u003c/li\u003e\u003cli\u003eBars are represented by 0's in the output\u003c/li\u003e\u003cli\u003eA '1' becomes '0 0 0'\u003c/li\u003e\u003cli\u003eA '0' becomes '0'\u003c/li\u003e\u003cli\u003eWhite space between bars is a single 1\u003c/li\u003e\u003cli\u003eThere will be no left hand zeros in the binary representation\u003c/li\u003e\u003cli\u003eThere are three columns of white space at beginning and end of bar code\r\nFor example:\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eInput 5 yields\u003c/p\u003e\u003cp\u003e[1 1 1 0 0 0 1 0 1 0 0 0 1 1 1] (only repeated for 30 rows);\u003c/p\u003e","function_template":"function out = barEncoder(in)\r\n  out = in;\r\nend","test_suite":"%%\r\nx = 5;\r\ny_correct = repmat( [1 1 1 0 0 0 1 0 1 0 0 0 1 1 1],[30,1]);;\r\nassert(isequal(barEncoder(x),y_correct))\r\n%%\r\nx = 12;\r\ny_correct = repmat( [1 1 1 0 0 0 1 0 0 0 1 0 1 0 1 1 1],[30,1]);;\r\nassert(isequal(barEncoder(x),y_correct))\r\n%%\r\nx = 135;\r\ny_correct = repmat( [1 1 1 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 1 1 1],[30,1]);;\r\nassert(isequal(barEncoder(x),y_correct))\r\n%%\r\nx = 2;\r\ny_correct = repmat( [1 1 1 0 0 0 1 0 1 1 1],[30,1]);\r\nassert(isequal(barEncoder(x),y_correct))\r\n%%\r\nx = 22;\r\ny_correct = repmat( [1 1 1 0 0 0 1 0 1 0 0 0 1 0 0 0 1 0 1 1 1],[30,1]);\r\nassert(isequal(barEncoder(x),y_correct))","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":180,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":38,"created_at":"2012-04-19T19:25:38.000Z","updated_at":"2026-03-31T17:44:19.000Z","published_at":"2012-04-19T19:25:46.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an integer to encode, make a barcode using the following encoding scheme:\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\u003eThe bar code is made from the binary version of the integer\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\u003eThe bar code is a matrix 30x?\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\u003eA '1' becomes a thick bar\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\u003eA '0' becomes a thin bar\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\u003eBars are represented by 0's in the output\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\u003eA '1' becomes '0 0 0'\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA '0' becomes '0'\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhite space between bars is a single 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere will be no left hand zeros in 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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are three columns of white space at beginning and end of bar codeFor example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput 5 yields\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[1 1 1 0 0 0 1 0 1 0 0 0 1 1 1] (only repeated for 30 rows);\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":603,"title":"Decode a simplified barcode","description":"Given a bar code from this \u003chttp://www.mathworks.com/matlabcentral/cody/problems/602-make-a-simplified-bar-code exercise\u003e:\r\n\r\nReturn the integer that would generate it.","description_html":"\u003cp\u003eGiven a bar code from this \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/602-make-a-simplified-bar-code\"\u003eexercise\u003c/a\u003e:\u003c/p\u003e\u003cp\u003eReturn the integer that would generate it.\u003c/p\u003e","function_template":"function out = barDecoder(im)\r\n\r\nout = 3;\r\nend","test_suite":"%%\r\nnumOut = 5;\r\nbarIn = repmat( [1 1 1 0 0 0 1 0 1 0 0 0 1 1 1],[30,1]);;\r\nassert(isequal(barDecoder(barIn),numOut))\r\n%%\r\nnumOut = 12;\r\nbarIn = repmat( [1 1 1 0 0 0 1 0 0 0 1 0 1 0 1 1 1],[30,1]);;\r\nassert(isequal(barDecoder(barIn),numOut))\r\n%%\r\nnumOut = 135;\r\nbarIn = repmat( [1 1 1 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 1 1 1],[30,1]);;\r\nassert(isequal(barDecoder(barIn),numOut))\r\n%%\r\nnumOut = 2;\r\nbarIn = repmat( [1 1 1 0 0 0 1 0 1 1 1],[30,1]);\r\nassert(isequal(barDecoder(barIn),numOut))\r\n%%\r\nnumOut = 22;\r\nbarIn = repmat( [1 1 1 0 0 0 1 0 1 0 0 0 1 0 0 0 1 0 1 1 1],[30,1]);\r\nassert(isequal(barDecoder(barIn),numOut))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":133,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":38,"created_at":"2012-04-19T20:53:42.000Z","updated_at":"2026-03-31T17:45:33.000Z","published_at":"2012-04-19T20:54:04.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a bar code from this\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/602-make-a-simplified-bar-code\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eexercise\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the integer that would generate it.\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":645,"title":"Getting the indices from a vector","description":"This is a basic MATLAB operation. It is for instructional purposes.\r\n---\r\nYou may already know how to find the logical indices of the elements of a vector that meet your criteria.\r\nThis exercise is for finding the index of indices that meet your criteria. The difference is this:\r\n     vec = [11 22 33 44];\r\n  thresh = 25;\r\n      vi = (vec \u003e thresh)\r\n\r\nvi =\r\n\r\n     0     0     1     1\r\nWhat we are looking for now is how to get the values\r\n   x =\r\n\r\n     3     4\r\nBecause those are the indices where the binary comparison is true.\r\n\r\nGiven a vector, vec, return the indices where vec is greater than scalar, thresh.","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: 457.333px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 406.5px 228.667px; transform-origin: 406.5px 228.667px; 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: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 211.05px 7.81667px; transform-origin: 211.05px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 6.7px 7.81667px; transform-origin: 6.7px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e---\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 96.5917px 7.81667px; transform-origin: 96.5917px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou may already know how to\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2.23333px 7.81667px; transform-origin: 2.23333px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003efind the logical indices\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 162.475px 7.81667px; transform-origin: 162.475px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e of the elements of a vector that meet your criteria.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 294.8px 7.81667px; transform-origin: 294.8px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis exercise is for finding the index of indices that meet your criteria. The difference is this:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 143.033px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 403.5px 71.5167px; transform-origin: 403.5px 71.5167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 97.7083px 8.375px; tab-size: 4; transform-origin: 97.7083px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     vec = [11 22 33 44];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 54.7167px 8.375px; tab-size: 4; transform-origin: 54.7167px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e  thresh = 25;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 97.7083px 8.375px; tab-size: 4; transform-origin: 97.7083px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e      vi = (vec \u0026gt; thresh)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.375px; tab-size: 4; transform-origin: 0px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 15.6333px 8.375px; tab-size: 4; transform-origin: 15.6333px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003evi =\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.375px; tab-size: 4; transform-origin: 0px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 93.8px 8.375px; tab-size: 4; transform-origin: 93.8px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     0     0     1     1\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 169.175px 7.81667px; transform-origin: 169.175px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWhat we are looking for now is how to get the values\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 403.5px 30.65px; transform-origin: 403.5px 30.65px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 23.45px 8.375px; tab-size: 4; transform-origin: 23.45px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e   x =\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.375px; tab-size: 4; transform-origin: 0px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 46.9px 8.375px; tab-size: 4; transform-origin: 46.9px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     3     4\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 217.75px 7.81667px; transform-origin: 217.75px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eBecause those are the indices where the binary comparison is true.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 7.81667px; transform-origin: 0px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 250.692px 7.81667px; transform-origin: 250.692px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a vector, vec, return the indices where vec is greater than scalar, thresh.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function out = findIndices(vec, thresh)\r\n  out = 1;\r\nend","test_suite":"%%\r\nfiletext = fileread('findIndices.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp');\r\nassert(~illegal)\r\n\r\n\r\n%%\r\nout = [3 4];\r\nvec = [11 22 33 44];\r\nthresh = 25;\r\nassert(isequal(findIndices(vec, thresh),out))\r\n\r\n%%\r\nout = [1 2];\r\nvec = [33 44 11 22];\r\nthresh = 25;\r\nassert(isequal(findIndices(vec, thresh),out))\r\n\r\n%%\r\nout = 5:10;\r\nvec = 10:10:100;\r\nthresh = 45;\r\nassert(isequal(findIndices(vec, thresh),out))\r\n\r\n%%\r\nout = [1 3 4 6 8];\r\nvec = [12 10 13 14 9 17 5 18];\r\nthresh = 11;\r\nassert(isequal(findIndices(vec, thresh),out))\r\n\r\n%%\r\nout = [1:3 7:9];\r\nvec = [50 55 60 15 10 5 43 44 97 41];\r\nthresh = 42;\r\nassert(isequal(findIndices(vec, thresh),out))\r\n\r\n%%\r\nout = 5:8;\r\nvec = [10 12 14 16 18 20 22 23 7 8 9];\r\nthresh = 17;\r\nassert(isequal(findIndices(vec, thresh),out))\r\n\r\n%%\r\nout = [2 4:5 8 12:14 16];\r\nvec = [10 81 24 65 97 13 45 68 24 35 16 79 123 76 45 60];\r\nthresh = 51;\r\nassert(isequal(findIndices(vec, thresh),out))\r\n\r\n%%\r\nout = 1:2:9;\r\nvec = [11 9 12 8 13 7 14 6 15 5];\r\nthresh = 10;\r\nassert(isequal(findIndices(vec, thresh),out))","published":true,"deleted":false,"likes_count":68,"comments_count":6,"created_by":240,"edited_by":223089,"edited_at":"2024-06-28T16:25:40.000Z","deleted_by":null,"deleted_at":null,"solvers_count":11901,"test_suite_updated_at":"2024-06-28T16:25:40.000Z","rescore_all_solutions":false,"group_id":13,"created_at":"2012-05-01T15:07:35.000Z","updated_at":"2026-04-15T12:30:28.000Z","published_at":"2012-05-01T15:07:43.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\u003eThis is a basic MATLAB operation. It is for instructional purposes.\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\u003e---\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may already know how to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efind the logical indices\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e of the elements of a vector that meet your criteria.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis exercise is for finding the index of indices that meet your criteria. The difference is this:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[     vec = [11 22 33 44];\\n  thresh = 25;\\n      vi = (vec \u003e thresh)\\n\\nvi =\\n\\n     0     0     1     1]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhat we are looking for now is how to get the values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   x =\\n\\n     3     4]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBecause those are the indices where the binary comparison is true.\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\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector, vec, return the indices where vec is greater than scalar, thresh.\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":650,"title":"Steal, Share, or Catch","description":"You, I, and a few other characters are going to play a game of *Steal, Share or Catch*.  We are going to play it 10,000 times vs. each of the characters.  \r\n\r\nThe rules of the game are this:\r\n\r\n* There are two points available each round\r\n* We will both choose to either Steal, Share, or Catch\r\n\r\n* If we both choose Share, we both get one point.\r\n* If one chooses Steal and the other Share, the Stealer gets two points.\r\n* If one chooses Steal and the other Catch, the Catcher gets two points.\r\n* Any other combination, no one is awarded points.\r\n\r\nYou are to write an algorithm that will return either\r\n\r\n* -1: Steal\r\n*  0: Share\r\n*  1: Catch\r\n\r\nTo help you make your choice, you will have a history vector that shows what your choices have been so far, and what the opponent's choices have been.  These histories are in the form of:\r\n\r\n  [-1\r\n    1\r\n    1\r\n    0]\r\n\r\nMeaning that the first round there was a Steal, then two Catches, then a share.\r\n\r\nThe characters you will play against are:\r\n\r\n* Evil  (always steals)\r\n* Good  (always shares)\r\n* Chaos (randomly chooses)\r\n* Doug  (Something more complicated)\r\n\r\nAs this problem runs, I will take the better entries and add them into the cast of characters that you play against.  Maybe in a different Cody problem though.\r\n\r\nThe scores to beat are:\r\n\r\n  terribleScore   =     0; % works\r\n  badScore        = 23000; % good  strategy scores this\r\n  okScore         = 26000; % evil  strategy scores this\r\n  decentScore     = 29000; % chaos strategy scores this\r\n  greatScore      = 42000; % doug  strategy scores this\r\n\r\nIf you can make a winning solution here, it might be added to the  \u003chttp://www.mathworks.com/matlabcentral/cody/problems/653-steal-share-or-catch-tournament-of-champions Tournament of Champions\u003e version of this problem.  E-mail me if you want yours added.","description_html":"\u003cp\u003eYou, I, and a few other characters are going to play a game of \u003cb\u003eSteal, Share or Catch\u003c/b\u003e.  We are going to play it 10,000 times vs. each of the characters.\u003c/p\u003e\u003cp\u003eThe rules of the game are this:\u003c/p\u003e\u003cul\u003e\u003cli\u003eThere are two points available each round\u003c/li\u003e\u003cli\u003eWe will both choose to either Steal, Share, or Catch\u003c/li\u003e\u003c/ul\u003e\u003cul\u003e\u003cli\u003eIf we both choose Share, we both get one point.\u003c/li\u003e\u003cli\u003eIf one chooses Steal and the other Share, the Stealer gets two points.\u003c/li\u003e\u003cli\u003eIf one chooses Steal and the other Catch, the Catcher gets two points.\u003c/li\u003e\u003cli\u003eAny other combination, no one is awarded points.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eYou are to write an algorithm that will return either\u003c/p\u003e\u003cul\u003e\u003cli\u003e-1: Steal\u003c/li\u003e\u003cli\u003e0: Share\u003c/li\u003e\u003cli\u003e1: Catch\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eTo help you make your choice, you will have a history vector that shows what your choices have been so far, and what the opponent's choices have been.  These histories are in the form of:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[-1\r\n  1\r\n  1\r\n  0]\r\n\u003c/pre\u003e\u003cp\u003eMeaning that the first round there was a Steal, then two Catches, then a share.\u003c/p\u003e\u003cp\u003eThe characters you will play against are:\u003c/p\u003e\u003cul\u003e\u003cli\u003eEvil  (always steals)\u003c/li\u003e\u003cli\u003eGood  (always shares)\u003c/li\u003e\u003cli\u003eChaos (randomly chooses)\u003c/li\u003e\u003cli\u003eDoug  (Something more complicated)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eAs this problem runs, I will take the better entries and add them into the cast of characters that you play against.  Maybe in a different Cody problem though.\u003c/p\u003e\u003cp\u003eThe scores to beat are:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eterribleScore   =     0; % works\r\nbadScore        = 23000; % good  strategy scores this\r\nokScore         = 26000; % evil  strategy scores this\r\ndecentScore     = 29000; % chaos strategy scores this\r\ngreatScore      = 42000; % doug  strategy scores this\r\n\u003c/pre\u003e\u003cp\u003eIf you can make a winning solution here, it might be added to the  \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/653-steal-share-or-catch-tournament-of-champions\"\u003eTournament of Champions\u003c/a\u003e version of this problem.  E-mail me if you want yours added.\u003c/p\u003e","function_template":"function choice = StealShareCatch(yourHist, theirHist)\r\n% This function will be called 10,000 times.\r\n% the hist vectors will start as [], and get longer each time through.\r\n%-1 steal\r\n% 0 share\r\n% 1 catch\r\n\r\n%stealVal = 2; What you get if you steal and they share\r\n%catchVal = 2; What you get if you catch and they steal\r\n%shareVal = 1; What you both get if both share\r\n%Otherwise no one gets anything!\r\n  choice = 0;\r\nend","test_suite":"% THIS IS A HACK TO GET CODE ON THE PATH\r\n% IGNORE THIS FIRST 'TEST'\r\n%\r\n%\r\nfh=fopen('doug.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = doug(histA, histB)');\r\nfprintf(fh, '%s \\n', '% A is self');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'memoryThresh = 10;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histB = [zeros(memoryThresh,1); histB];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'recentB = histB(end-(memoryThresh-1) : end);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'numStealB = nnz(recentB == -1);');\r\nfprintf(fh, '%s \\n', 'numShareB = nnz(recentB ==  0);');\r\nfprintf(fh, '%s \\n', 'numCatchB = nnz(recentB ==  1);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'percentStealB = (numStealB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentShareB = (numShareB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentCatchB = (numCatchB/memoryThresh);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0; %default to share');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            rollDice = rand;');\r\nfprintf(fh, '%s \\n', 'percentCatchStealers = 0.9;');\r\nfprintf(fh, '%s \\n', 'if (rollDice \u003c percentStealB)');\r\nfprintf(fh, '%s \\n', '    rollDice = rand;');\r\nfprintf(fh, '%s \\n', '    if (rollDice \u003c percentCatchStealers)');\r\nfprintf(fh, '%s \\n', '        out =  1; % catch');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        out = -1; % steal');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\nfh=fopen('runPair.m','wt');\r\nfprintf(fh, '%s \\n', 'function [scoreA, scoreB] = runPair(fhA, fhB);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'n = 10000;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histA = [];');\r\nfprintf(fh, '%s \\n', 'histB = [];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'scoreA = 0;');\r\nfprintf(fh, '%s \\n', 'scoreB = 0;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'stealVal = 2;');\r\nfprintf(fh, '%s \\n', 'catchVal = 2;');\r\nfprintf(fh, '%s \\n', 'shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'for i = 1: n;');\r\nfprintf(fh, '%s \\n', '    histA(end+1,1) = fhA(histA,  histB         );');\r\nfprintf(fh, '%s \\n', '    histB(end+1,1) = fhB(histB,  histA(1:end-1)); %modified one not sent!');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '    switch histA(end)');\r\nfprintf(fh, '%s \\n', '        case -1 %a steal');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + stealVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + catchVal;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'') ');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        case 0 %a share');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + stealVal;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + shareVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + shareVal;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        case 1 %a catch');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + catchVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        otherwise');\r\nfprintf(fh, '%s \\n', '            error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '');\r\nfclose(fh);\r\nfh=fopen('evil.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = evil(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = -1;');\r\nfclose(fh);\r\nfh=fopen('good.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = good(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0;');\r\nfclose(fh);\r\nfh=fopen('chaos.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = chaos(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = ceil(rand*3)-2;');\r\nfclose(fh);\r\nrehash path\r\n\r\n%%\r\n\r\na        = runPair(@StealShareCatch, @chaos);\r\na(end+1) = runPair(@StealShareCatch, @good);\r\na(end+1) = runPair(@StealShareCatch, @evil);\r\na(end+1) = runPair(@StealShareCatch, @doug)\r\nyourScore = sum(a)\r\n\r\nterribleScore   =     0; % works\r\nbadScore        = 23000; % good  strategy scores this\r\nokScore         = 26000; % evil  strategy scores this\r\ndecentScore     = 29000; % chaos strategy scores this\r\ngreatScore      = 42000; % doug  strategy scores this\r\n\r\n\r\nassert(yourScore \u003e terribleScore, 'Score: %d', yourScore)\r\n\r\nassert(yourScore \u003e badScore, 'Score: %d', yourScore)\r\n\r\nassert(yourScore \u003e okScore, 'Score: %d', yourScore)\r\n\r\nassert(yourScore \u003e decentScore, 'Score: %d', yourScore)\r\n\r\nassert(yourScore \u003e greatScore, 'Score: %d', yourScore)","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":79,"test_suite_updated_at":"2012-05-02T20:36:03.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-02T15:42:59.000Z","updated_at":"2025-06-28T09:34:20.000Z","published_at":"2012-05-02T19:40:23.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou, I, and a few other characters are going to play a game of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSteal, Share or Catch\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. We are going to play it 10,000 times vs. each of the characters.\u003c/w:t\u003e\u003c/w:r\u003e\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 rules of the game are this:\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\u003eThere are two points available each round\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\u003eWe will both choose to either Steal, Share, or Catch\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 we both choose Share, we both get one 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\u003eIf one chooses Steal and the other Share, the Stealer gets two points.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf one chooses Steal and the other Catch, the Catcher gets two points.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAny other combination, no one is awarded points.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou are to write an algorithm that will return either\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e-1: Steal\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\u003e0: Share\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1: Catch\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo help you make your choice, you will have a history vector that shows what your choices have been so far, and what the opponent's choices have been. These histories are in the form of:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[[-1\\n  1\\n  1\\n  0]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMeaning that the first round there was a Steal, then two Catches, then a share.\u003c/w:t\u003e\u003c/w:r\u003e\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 characters you will play against are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEvil (always steals)\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\u003eGood (always shares)\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\u003eChaos (randomly chooses)\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\u003eDoug (Something more complicated)\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eAs this problem runs, I will take the better entries and add them into the cast of characters that you play against. Maybe in a different Cody problem though.\u003c/w:t\u003e\u003c/w:r\u003e\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 scores to beat are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[terribleScore   =     0; % works\\nbadScore        = 23000; % good  strategy scores this\\nokScore         = 26000; % evil  strategy scores this\\ndecentScore     = 29000; % chaos strategy scores this\\ngreatScore      = 42000; % doug  strategy scores this]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf you can make a winning solution here, it might be added to the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/653-steal-share-or-catch-tournament-of-champions\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eTournament of Champions\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e version of this problem. E-mail me if you want yours added.\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":626,"title":"Make blocks of color","description":"Given a (Nx3) sequence of RGB colors, I want to create a (numRowBlocks x numColBlocks x 3) image comprising (blockSize x blockSize) blocks of those colors in a (numRowBlocks x numColBlocks) pattern.\r\n\r\ni.e. for this signature:\r\n  makeColorBlocks(blockSize, numColBlocks, numRowBlocks, RGBvec)\r\n\r\n(Using a weird RGB to make the point)\r\n\r\n    \u003e\u003e makeColorBlocks(2, 3, 2, [1 11 10;2 22 20; 3 33 30; 4 44 40; 5 55 50; 6 66 60])\r\n  \r\n  ans(:,:,1) =\r\n  \r\n      1    1    2    2    3    3\r\n      1    1    2    2    3    3\r\n      4    4    5    5    6    6\r\n      4    4    5    5    6    6\r\n  \r\n  \r\n  ans(:,:,2) =\r\n  \r\n     11   11   22   22   33   33\r\n     11   11   22   22   33   33\r\n     44   44   55   55   66   66\r\n     44   44   55   55   66   66\r\n  \r\n  \r\n  ans(:,:,3) =\r\n  \r\n     10   10   20   20   30   30\r\n     10   10   20   20   30   30\r\n     40   40   50   50   60   60\r\n     40   40   50   50   60   60\r\n\r\nThough it can not be mechanically graded as such, I am looking for easy to read an understand code.  Something easy to understand is preferred.  Thanks to \u003chttp://blogs.mathworks.com/pick/ Brett\u003e for the question.","description_html":"\u003cp\u003eGiven a (Nx3) sequence of RGB colors, I want to create a (numRowBlocks x numColBlocks x 3) image comprising (blockSize x blockSize) blocks of those colors in a (numRowBlocks x numColBlocks) pattern.\u003c/p\u003e\u003cp\u003ei.e. for this signature:\r\n  makeColorBlocks(blockSize, numColBlocks, numRowBlocks, RGBvec)\u003c/p\u003e\u003cp\u003e(Using a weird RGB to make the point)\u003c/p\u003e\u003cpre\u003e    \u003e\u003e makeColorBlocks(2, 3, 2, [1 11 10;2 22 20; 3 33 30; 4 44 40; 5 55 50; 6 66 60])\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eans(:,:,1) =\r\n\u003c/pre\u003e\u003cpre\u003e      1    1    2    2    3    3\r\n      1    1    2    2    3    3\r\n      4    4    5    5    6    6\r\n      4    4    5    5    6    6\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eans(:,:,2) =\r\n\u003c/pre\u003e\u003cpre\u003e     11   11   22   22   33   33\r\n     11   11   22   22   33   33\r\n     44   44   55   55   66   66\r\n     44   44   55   55   66   66\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eans(:,:,3) =\r\n\u003c/pre\u003e\u003cpre\u003e     10   10   20   20   30   30\r\n     10   10   20   20   30   30\r\n     40   40   50   50   60   60\r\n     40   40   50   50   60   60\u003c/pre\u003e\u003cp\u003eThough it can not be mechanically graded as such, I am looking for easy to read an understand code.  Something easy to understand is preferred.  Thanks to \u003ca href=\"http://blogs.mathworks.com/pick/\"\u003eBrett\u003c/a\u003e for the question.\u003c/p\u003e","function_template":"function img = makeColorBlocks(blockSize, numColBlocks, numRowBlocks, RGBvec)\r\n  img = 1;\r\nend","test_suite":"%%\r\nblockSize    = 2; \r\nnumColBlocks = 6; \r\nnumRowBlocks = 4;\r\nRGBvec = spring(numColBlocks*numRowBlocks)*255;\r\n\r\ny_correct(:,:,1) =[\r\n  255  255  255  255  255  255  255  255  255  255  255  255\r\n  255  255  255  255  255  255  255  255  255  255  255  255\r\n  255  255  255  255  255  255  255  255  255  255  255  255\r\n  255  255  255  255  255  255  255  255  255  255  255  255\r\n  255  255  255  255  255  255  255  255  255  255  255  255\r\n  255  255  255  255  255  255  255  255  255  255  255  255\r\n  255  255  255  255  255  255  255  255  255  255  255  255\r\n  255  255  255  255  255  255  255  255  255  255  255  255];\r\n\r\ny_correct(:,:,2) = [\r\n    0    0   11   11   22   22   33   33   44   44   55   55\r\n    0    0   11   11   22   22   33   33   44   44   55   55\r\n   67   67   78   78   89   89  100  100  111  111  122  122\r\n   67   67   78   78   89   89  100  100  111  111  122  122\r\n  133  133  144  144  155  155  166  166  177  177  188  188\r\n  133  133  144  144  155  155  166  166  177  177  188  188\r\n  200  200  211  211  222  222  233  233  244  244  255  255\r\n  200  200  211  211  222  222  233  233  244  244  255  255];\r\n\r\ny_correct(:,:,3) = [\r\n  255  255  244  244  233  233  222  222  211  211  200  200\r\n  255  255  244  244  233  233  222  222  211  211  200  200\r\n  188  188  177  177  166  166  155  155  144  144  133  133\r\n  188  188  177  177  166  166  155  155  144  144  133  133\r\n  122  122  111  111  100  100   89   89   78   78   67   67\r\n  122  122  111  111  100  100   89   89   78   78   67   67\r\n   55   55   44   44   33   33   22   22   11   11    0    0\r\n   55   55   44   44   33   33   22   22   11   11    0    0];\r\n\r\n\r\nassert(isequal(makeColorBlocks(blockSize, numColBlocks, numRowBlocks, RGBvec),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-26T14:21:49.000Z","updated_at":"2026-04-11T11:29:37.000Z","published_at":"2012-04-26T14:21:53.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a (Nx3) sequence of RGB colors, I want to create a (numRowBlocks x numColBlocks x 3) image comprising (blockSize x blockSize) blocks of those colors in a (numRowBlocks x numColBlocks) pattern.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ei.e. for this signature: makeColorBlocks(blockSize, numColBlocks, numRowBlocks, RGBvec)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(Using a weird RGB to make the point)\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[    \u003e\u003e makeColorBlocks(2, 3, 2, [1 11 10;2 22 20; 3 33 30; 4 44 40; 5 55 50; 6 66 60])\\n\\nans(:,:,1) =\\n\\n      1    1    2    2    3    3\\n      1    1    2    2    3    3\\n      4    4    5    5    6    6\\n      4    4    5    5    6    6\\n\\nans(:,:,2) =\\n\\n     11   11   22   22   33   33\\n     11   11   22   22   33   33\\n     44   44   55   55   66   66\\n     44   44   55   55   66   66\\n\\nans(:,:,3) =\\n\\n     10   10   20   20   30   30\\n     10   10   20   20   30   30\\n     40   40   50   50   60   60\\n     40   40   50   50   60   60]]\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\u003eThough it can not be mechanically graded as such, I am looking for easy to read an understand code. Something easy to understand is preferred. Thanks to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://blogs.mathworks.com/pick/\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eBrett\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e for the question.\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":621,"title":"Cryptomath: Addition","description":"    W A I T\r\n  +   A L L\r\n  ---------\r\n  G I F T S\r\n\r\nequals:\r\n\r\n    9 6 0 8\r\n  +   6 7 7\r\n  ---------\r\n  1 0 2 8 5\r\n\r\nGiven strings a,b,c find where a + b = c;  No left hand zeros.  All solutions are believed to be unique.\r\n\r\nBeware, the test machine might time out your entry!\r\n\r\nIf you want some easier problems that build up to this one, \r\n\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/641-make-a-random-non-repeating-vector random permutations of integers\u003e\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector binary comparisons\u003e\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/639-string-substitution-sub-problem-to-cryptomath string substitution\u003e \r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/642-convert-a-vector-into-a-number convert list of numbers to a scalar\u003e\r\n\r\nWhy are the above building blocks to solving this problem?  Well, let's think about the \u003chttp://c2.com/xp/DoTheSimplestThingThatCouldPossiblyWork.html simplest thing that could possibly work.\u003e\r\n\r\nIf we \r\n\r\n* Made random mapping of the ten or less characters to the ten digits\r\n* Converted the characters to a vector of numbers\r\n* Converted the vector of numbers to a scalar\r\n* Checked the scalars in the summation\r\n* Tried again if it did not work\r\n\r\nEventually, we would find the correct answer.  Worst case scenario, we have a one in 10! (1/3,600,000) chance of stumbling upon the answer.  For the eight character case, it is 8! (1/40,320).  I like those odds enough that it is worth trying.\r\n\r\nA \u003chttp://www.mathworks.com/matlabcentral/cody/problems/648-cumulative-probability-of-finding-an-unlikely-combination supplemental problem\u003e finds out which technique, methodical or random is better.","description_html":"\u003cpre\u003e    W A I T\r\n  +   A L L\r\n  ---------\r\n  G I F T S\u003c/pre\u003e\u003cp\u003eequals:\u003c/p\u003e\u003cpre\u003e    9 6 0 8\r\n  +   6 7 7\r\n  ---------\r\n  1 0 2 8 5\u003c/pre\u003e\u003cp\u003eGiven strings a,b,c find where a + b = c;  No left hand zeros.  All solutions are believed to be unique.\u003c/p\u003e\u003cp\u003eBeware, the test machine might time out your entry!\u003c/p\u003e\u003cp\u003eIf you want some easier problems that build up to this one,\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/641-make-a-random-non-repeating-vector\"\u003erandom permutations of integers\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\"\u003ebinary comparisons\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/639-string-substitution-sub-problem-to-cryptomath\"\u003estring substitution\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/642-convert-a-vector-into-a-number\"\u003econvert list of numbers to a scalar\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eWhy are the above building blocks to solving this problem?  Well, let's think about the \u003ca href=\"http://c2.com/xp/DoTheSimplestThingThatCouldPossiblyWork.html\"\u003esimplest thing that could possibly work.\u003c/a\u003e\u003c/p\u003e\u003cp\u003eIf we\u003c/p\u003e\u003cul\u003e\u003cli\u003eMade random mapping of the ten or less characters to the ten digits\u003c/li\u003e\u003cli\u003eConverted the characters to a vector of numbers\u003c/li\u003e\u003cli\u003eConverted the vector of numbers to a scalar\u003c/li\u003e\u003cli\u003eChecked the scalars in the summation\u003c/li\u003e\u003cli\u003eTried again if it did not work\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eEventually, we would find the correct answer.  Worst case scenario, we have a one in 10! (1/3,600,000) chance of stumbling upon the answer.  For the eight character case, it is 8! (1/40,320).  I like those odds enough that it is worth trying.\u003c/p\u003e\u003cp\u003eA \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/648-cumulative-probability-of-finding-an-unlikely-combination\"\u003esupplemental problem\u003c/a\u003e finds out which technique, methodical or random is better.\u003c/p\u003e","function_template":"function out = cryptoAdd(aStr,bStr,cStr)\r\n  aNum = 1;\r\n  bNum = 1;\r\n  cNum = 2;\r\n\r\nout = [aNum, bNum, cNum];\r\nend","test_suite":"%%\r\naStr = 'dan';\r\nbStr = 'nan';\r\ncStr = 'nora';\r\n\r\nout = [921 121 1042];\r\n\r\nassert(isequal(cryptoAdd(aStr,bStr,cStr),out))\r\n\r\n%%\r\naStr = 'wait';\r\nbStr = 'all';\r\ncStr = 'gifts';\r\n\r\nout = [9608 677 10285];\r\n\r\nassert(isequal(cryptoAdd(aStr,bStr,cStr),out))\r\n%%\r\naStr = 'memo';\r\nbStr = 'from';\r\ncStr = 'homer';\r\n\r\nout = [8485 7358 15843];\r\n\r\nassert(isequal(cryptoAdd(aStr,bStr,cStr),out))\r\n%%\r\n%aStr = 'coca';\r\n%bStr = 'cola';\r\n%cStr = 'oasis';\r\n\r\n%out = [8186 8106 16292];\r\n\r\n%assert(isequal(cryptoAdd(aStr,bStr,cStr),out))","published":true,"deleted":false,"likes_count":2,"comments_count":9,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":44,"test_suite_updated_at":"2012-04-25T19:43:33.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-25T16:00:11.000Z","updated_at":"2026-04-03T20:11:56.000Z","published_at":"2012-04-25T18:37:25.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    W A I T\\n  +   A L L\\n  ---------\\n  G I F T S]]\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\u003eequals:\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[    9 6 0 8\\n  +   6 7 7\\n  ---------\\n  1 0 2 8 5]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven strings a,b,c find where a + b = c; No left hand zeros. All solutions are believed to be unique.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eBeware, the test machine might time out your entry!\u003c/w:t\u003e\u003c/w:r\u003e\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 you want some easier problems that build up to this one,\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:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/641-make-a-random-non-repeating-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003erandom permutations of integers\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ebinary comparisons\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/639-string-substitution-sub-problem-to-cryptomath\\\"\u003e\u003cw:r\u003e\u003cw:t\u003estring substitution\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/642-convert-a-vector-into-a-number\\\"\u003e\u003cw:r\u003e\u003cw:t\u003econvert list of numbers to a scalar\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhy are the above building blocks to solving this problem? Well, let's think about the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://c2.com/xp/DoTheSimplestThingThatCouldPossiblyWork.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esimplest thing that could possibly work.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf we\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\u003eMade random mapping of the ten or less characters to the ten digits\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\u003eConverted the characters to a vector of numbers\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\u003eConverted the vector of numbers to a scalar\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\u003eChecked the scalars in the summation\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\u003eTried again if it did not work\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eEventually, we would find the correct answer. Worst case scenario, we have a one in 10! (1/3,600,000) chance of stumbling upon the answer. For the eight character case, it is 8! (1/40,320). I like those odds enough that it is worth trying.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/648-cumulative-probability-of-finding-an-unlikely-combination\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esupplemental problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e finds out which technique, methodical or random is better.\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":653,"title":"Steal, Share, or Catch: Tournament of Champions","description":"I am no longer supporting this problem.  No changes will be made to put more entries in the test suite, but have fun playing anyways!\r\n\r\n\r\n\u003chttp://www.mathworks.com/matlabcentral/cody/problems/650-steal-share-or-catch Steal, Share, or Catch\u003e is explained in the link.\r\n\r\nThis problem is the \"Tournament of Champions\".  If you make a passing entry in the original, from time to time I will move entries over to this Cody problem.  You will no longer be playing against only easy characters:\r\n\r\n* Good\r\n* Evil\r\n* Chaos\r\n* Doug\r\n\r\nYou will face\r\n\r\n* Vincent\r\n* Sean\r\n* James\r\n* Exploiter\r\n* Philipp\r\n* Bert\r\n* Amro\r\n\r\nExploiter recognizes the strategies of many of the above characters, and plays well against them.  \r\n\r\nIs this cheating?  Maybe, but \u003chttp://en.wikipedia.org/wiki/Security_through_obscurity#Arguments_against security through obscurity\u003e is questionable!  Take a look at Exploiter, it is the reference solution to this problem.\r\n\r\nI will update the test suite and cast of characters and winning score as we go.  I will try to keep making the test suite tougher so that only one/two entries can pass it at any given time.  It will be a matter of beating the test score more than getting lowest complexity!\r\n\r\n\r\nIf you made something and want to see it here, just call my attention to it.\r\n\r\nWinner is determined by score, not by length.  As of 6/28/2012 on my machine Amro is the current winner at 136K!","description_html":"\u003cp\u003eI am no longer supporting this problem.  No changes will be made to put more entries in the test suite, but have fun playing anyways!\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/650-steal-share-or-catch\"\u003eSteal, Share, or Catch\u003c/a\u003e is explained in the link.\u003c/p\u003e\u003cp\u003eThis problem is the \"Tournament of Champions\".  If you make a passing entry in the original, from time to time I will move entries over to this Cody problem.  You will no longer be playing against only easy characters:\u003c/p\u003e\u003cul\u003e\u003cli\u003eGood\u003c/li\u003e\u003cli\u003eEvil\u003c/li\u003e\u003cli\u003eChaos\u003c/li\u003e\u003cli\u003eDoug\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eYou will face\u003c/p\u003e\u003cul\u003e\u003cli\u003eVincent\u003c/li\u003e\u003cli\u003eSean\u003c/li\u003e\u003cli\u003eJames\u003c/li\u003e\u003cli\u003eExploiter\u003c/li\u003e\u003cli\u003ePhilipp\u003c/li\u003e\u003cli\u003eBert\u003c/li\u003e\u003cli\u003eAmro\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eExploiter recognizes the strategies of many of the above characters, and plays well against them.\u003c/p\u003e\u003cp\u003eIs this cheating?  Maybe, but \u003ca href = \"http://en.wikipedia.org/wiki/Security_through_obscurity#Arguments_against\"\u003esecurity through obscurity\u003c/a\u003e is questionable!  Take a look at Exploiter, it is the reference solution to this problem.\u003c/p\u003e\u003cp\u003eI will update the test suite and cast of characters and winning score as we go.  I will try to keep making the test suite tougher so that only one/two entries can pass it at any given time.  It will be a matter of beating the test score more than getting lowest complexity!\u003c/p\u003e\u003cp\u003eIf you made something and want to see it here, just call my attention to it.\u003c/p\u003e\u003cp\u003eWinner is determined by score, not by length.  As of 6/28/2012 on my machine Amro is the current winner at 136K!\u003c/p\u003e","function_template":"function choice = StealShareCatch(yourHist, theirHist)\r\n% This function will be called 10,000 times.\r\n% the hist vectors will start as [], and get longer each time through.\r\n%-1 steal\r\n% 0 share\r\n% 1 catch\r\n\r\n%stealVal = 2; What you get if you steal and they share\r\n%catchVal = 2; What you get if you catch and they steal\r\n%shareVal = 1; What you both get if both share\r\n%Otherwise no one gets anything!\r\n  choice = 0;\r\nend","test_suite":"% THIS IS A HACK TO GET CODE ON THE PATH\r\n% IGNORE THIS FIRST 'TEST'\r\n%\r\n%\r\nfh=fopen('doug.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = doug(histA, histB)');\r\nfprintf(fh, '%s \\n', '% A is self');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'memoryThresh = 10;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histB = [zeros(memoryThresh,1); histB];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'recentB = histB(end-(memoryThresh-1) : end);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'numStealB = nnz(recentB == -1);');\r\nfprintf(fh, '%s \\n', 'numShareB = nnz(recentB ==  0);');\r\nfprintf(fh, '%s \\n', 'numCatchB = nnz(recentB ==  1);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'percentStealB = (numStealB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentShareB = (numShareB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentCatchB = (numCatchB/memoryThresh);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0; %default to share');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            rollDice = rand;');\r\nfprintf(fh, '%s \\n', 'percentCatchStealers = 0.9;');\r\nfprintf(fh, '%s \\n', 'if (rollDice \u003c percentStealB)');\r\nfprintf(fh, '%s \\n', '    rollDice = rand;');\r\nfprintf(fh, '%s \\n', '    if (rollDice \u003c percentCatchStealers)');\r\nfprintf(fh, '%s \\n', '        out =  1; % catch');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        out = -1; % steal');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n\r\n%%\r\nfh=fopen('runPair.m','wt');\r\nfprintf(fh, '%s \\n', 'function [scoreA, scoreB] = runPair(fhA, fhB);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'n = 10000;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histA = [];');\r\nfprintf(fh, '%s \\n', 'histB = [];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'scoreA = 0;');\r\nfprintf(fh, '%s \\n', 'scoreB = 0;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'stealVal = 2;');\r\nfprintf(fh, '%s \\n', 'catchVal = 2;');\r\nfprintf(fh, '%s \\n', 'shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'for i = 1: n;');\r\nfprintf(fh, '%s \\n', '    histA(end+1,1) = fhA(histA,  histB         );');\r\nfprintf(fh, '%s \\n', '    histB(end+1,1) = fhB(histB,  histA(1:end-1)); %modified one not sent!');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '    switch histA(end)');\r\nfprintf(fh, '%s \\n', '        case -1 %a steal');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + stealVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + catchVal;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'') ');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        case 0 %a share');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + stealVal;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + shareVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + shareVal;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        case 1 %a catch');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + catchVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        otherwise');\r\nfprintf(fh, '%s \\n', '            error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '');\r\nfclose(fh);\r\n%%\r\nfh=fopen('evil.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = evil(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = -1;');\r\nfclose(fh);\r\n%%\r\nfh=fopen('good.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = good(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0;');\r\nfclose(fh);\r\n%%\r\nfh=fopen('chaos.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = chaos(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = ceil(rand*3)-2;');\r\nfclose(fh);\r\n%%\r\nfh=fopen('sean.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = sean(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '    if isempty(theirHist)');\r\nfprintf(fh, '%s \\n', '        [~,choice] = histc(rand,0:0.33:1);');\r\nfprintf(fh, '%s \\n', '        choice = choice-2;');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        [~, idx] = max(histc(theirHist,[-1 0 1]));');\r\nfprintf(fh, '%s \\n', '        choice = [1 0 -1];');\r\nfprintf(fh, '%s \\n', '        choice = choice(idx);');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('vincent.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = vincent(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', 'if all(theirHist == -1)');\r\nfprintf(fh, '%s \\n', 'choice = 1;');\r\nfprintf(fh, '%s \\n', 'elseif all(theirHist == 0);');\r\nfprintf(fh, '%s \\n', 'choice = -1;');\r\nfprintf(fh, '%s \\n', 'elseif all(theirHist == 1);');\r\nfprintf(fh, '%s \\n', 'choice = 1;');\r\nfprintf(fh, '%s \\n', 'else');\r\nfprintf(fh, '%s \\n', 'choice = 0;');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('james.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = james(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', 'if(length(theirHist)\u003c2)');\r\nfprintf(fh, '%s \\n', '  choice = 0;');\r\nfprintf(fh, '%s \\n', 'elseif( theirHist(end-1:end) == -1 )');\r\nfprintf(fh, '%s \\n', '  choice = 1;');\r\nfprintf(fh, '%s \\n', 'else');\r\nfprintf(fh, '%s \\n', '  choice = theirHist(end);');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('dougExploiter.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = dougExploiter(myHist, theirHist)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'threshID = 3;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if numel(myHist) \u003c threshID');\r\nfprintf(fh, '%s \\n', '    out = 0;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if     isGood(theirHist)');\r\nfprintf(fh, '%s \\n', '    out = -1;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'elseif isEvil(theirHist)');\r\nfprintf(fh, '%s \\n', '    out = 1;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', 'elseif isTitForTat(myHist, theirHist)');\r\nfprintf(fh, '%s \\n', '    switch myHist(end)');\r\nfprintf(fh, '%s \\n', '        case -1 %I stole so he wil steal');\r\nfprintf(fh, '%s \\n', '            out =  1; %catch');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        case  0 %I shared so he will share');\r\nfprintf(fh, '%s \\n', '            out = -1;');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        case  1 %I caught so he will catch');\r\nfprintf(fh, '%s \\n', '            out =  0; %Induce a share');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', 'elseif isChaos(theirHist)');\r\nfprintf(fh, '%s \\n', '    out = 1;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', '  ');\r\nfprintf(fh, '%s \\n', 'else %general unexploitable strategy');\r\nfprintf(fh, '%s \\n', '    out = dougGeneral(myHist, theirHist);');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'function flag = isGood(in)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'flag = all(in == 0);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'function flag = isEvil(in)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'flag = all(in == -1);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'function flag = isTitForTat(myHist, theirHist)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'window = 4;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if numel(myHist) \u003c window');\r\nfprintf(fh, '%s \\n', '    flag = false;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', 'else');\r\nfprintf(fh, '%s \\n', '    theirRecent = theirHist(end-(window-1):end);');\r\nfprintf(fh, '%s \\n', '       myRecent =    myHist(end-(window-1):end);');\r\nfprintf(fh, '%s \\n', '       ');\r\nfprintf(fh, '%s \\n', '    flag = isequal(myRecent(1:end-1), theirRecent(2:end));');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'function flag = isChaos(theirHist)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'num = numel(theirHist);');\r\nfprintf(fh, '%s \\n', 'perShare = nnz(theirHist ==  0)/num;');\r\nfprintf(fh, '%s \\n', 'perSteal = nnz(theirHist == -1)/num;');\r\nfprintf(fh, '%s \\n', 'perCatch = nnz(theirHist ==  1)/num;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'thresh = 0.05;');\r\nfprintf(fh, '%s \\n', 'target = 0.33;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'difference = [perShare perSteal perCatch] - target;');\r\nfprintf(fh, '%s \\n', 'flag = all(abs(difference) \u003c thresh);');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', 'function out = dougGeneral(histA, histB)');\r\nfprintf(fh, '%s \\n', 'memoryThresh = 10;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histB = [zeros(memoryThresh,1); histB];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'recentB = histB(end-(memoryThresh-1) : end);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'numStealB = nnz(recentB == -1);');\r\nfprintf(fh, '%s \\n', 'numShareB = nnz(recentB ==  0);');\r\nfprintf(fh, '%s \\n', 'numCatchB = nnz(recentB ==  1);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'percentStealB = (numStealB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentShareB = (numShareB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentCatchB = (numCatchB/memoryThresh);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0; %default to share');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            rollDice = rand;');\r\nfprintf(fh, '%s \\n', 'percentCatchStealers = 0.9;');\r\nfprintf(fh, '%s \\n', 'if (rollDice \u003c percentStealB)');\r\nfprintf(fh, '%s \\n', '    rollDice = rand;');\r\nfprintf(fh, '%s \\n', '    if (rollDice \u003c percentCatchStealers)');\r\nfprintf(fh, '%s \\n', '        out =  1; % catch');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        out = -1; % steal');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '    ');\r\nfclose(fh);\r\n%%\r\nfh=fopen('JamesE.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = jamesE(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if length(theirHist)\u003e10');\r\nfprintf(fh, '%s \\n', '    [yourguess yourcounts]=hist(theirHist(end-9:end),-1:1);');\r\nfprintf(fh, '%s \\n', '    [countmax countval]=max(yourguess);');\r\nfprintf(fh, '%s \\n', '    yourpopguess=yourcounts(countval);');\r\nfprintf(fh, '%s \\n', '    if yourpopguess==-1');\r\nfprintf(fh, '%s \\n', '        choice=1;');\r\nfprintf(fh, '%s \\n', '    elseif yourpopguess==0');\r\nfprintf(fh, '%s \\n', '        choice=-1;');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        choice=floor(3*rand)-1;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'else');\r\nfprintf(fh, '%s \\n', '\tchoice=floor(3*rand)-1;');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('philipp.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = philipp(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histLength = numel(theirHist);');\r\nfprintf(fh, '%s \\n', 'window = histLength-1;');\r\nfprintf(fh, '%s \\n', 'if histLength \u003e 10');\r\nfprintf(fh, '%s \\n', '    window = randi([5 10]);');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', ' if isempty(yourHist)');\r\nfprintf(fh, '%s \\n', '     % No choices made yet');\r\nfprintf(fh, '%s \\n', '     choice = randi([-1 1]);');\r\nfprintf(fh, '%s \\n', ' else');\r\nfprintf(fh, '%s \\n', '     switch mode(theirHist(end-window:end))');\r\nfprintf(fh, '%s \\n', '         case -1');\r\nfprintf(fh, '%s \\n', '             choice = 1;');\r\nfprintf(fh, '%s \\n', '         case 0');\r\nfprintf(fh, '%s \\n', '             choice = -1;');\r\nfprintf(fh, '%s \\n', '         case 1');\r\nfprintf(fh, '%s \\n', '             choice = randi([0 1]);');\r\nfprintf(fh, '%s \\n', '         otherwise');\r\nfprintf(fh, '%s \\n', '             choice = 0;');\r\nfprintf(fh, '%s \\n', '     end');\r\nfprintf(fh, '%s \\n', ' end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('bert.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = bert(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', 'choice = -1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if numel(theirHist)\u003e2');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', '    %check for tit4Tat stratagy');\r\nfprintf(fh, '%s \\n', '    isTit4Tat = isequal(yourHist(end-2:end-1), theirHist(end-1:end));');\r\nfprintf(fh, '%s \\n', '    count=histc(theirHist,-1:1);');\r\nfprintf(fh, '%s \\n', '    stealPercent = count(1)/numel(theirHist);');\r\nfprintf(fh, '%s \\n', '    sharePercent = count(2)/numel(theirHist);');\r\nfprintf(fh, '%s \\n', '    catPercent = count(3)/numel(theirHist);');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', '    choice = -theirHist(end); %general behavior ');\r\nfprintf(fh, '%s \\n', '    if isTit4Tat %check for tit4tat');\r\nfprintf(fh, '%s \\n', '        switch yourHist(end)');\r\nfprintf(fh, '%s \\n', '        case -1 %he wil steal');\r\nfprintf(fh, '%s \\n', '            choice =  1; %catch');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        case  0 %he will share');\r\nfprintf(fh, '%s \\n', '            choice = -1;');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        case  1 %he will catch');\r\nfprintf(fh, '%s \\n', '            choice =  0;');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        end');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    if choice == -1 %dont steal if the last was catch');\r\nfprintf(fh, '%s \\n', '        choice = 0;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', '    if rand(1)\u003e0.9 %random behavior to pass exploiters test');\r\nfprintf(fh, '%s \\n', '     choice = 0;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', '    if stealPercent \u003e 0.7   %if they steal often, I catch     ');\r\nfprintf(fh, '%s \\n', '        choice = 1;');\r\nfprintf(fh, '%s \\n', '    elseif sharePercent \u003e0.7 %if they share often, I steal');\r\nfprintf(fh, '%s \\n', '        choice = -1;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    if numel(theirHist)\u003e9000 %for the last 1000 round, steal');\r\nfprintf(fh, '%s \\n', '        choice = 1;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('amro.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = amro(histA, histB)');\r\nfprintf(fh, '%s \\n', '\t% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '\t% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '\t%-1 steal');\r\nfprintf(fh, '%s \\n', '\t% 0 share');\r\nfprintf(fh, '%s \\n', '\t% 1 catch');\r\nfprintf(fh, '%s \\n', '\t');\r\nfprintf(fh, '%s \\n', '\tif rand\u003c0.01 || isempty(histB)\t% if starting (or flipCoin)');\r\nfprintf(fh, '%s \\n', '\t\t% flipCoin: random move or \"share\"');\r\nfprintf(fh, '%s \\n', '\t\tif rand\u003c0.925');\r\nfprintf(fh, '%s \\n', '\t\t\tout = randi([-1 1]);');\r\nfprintf(fh, '%s \\n', '\t\telse');\r\nfprintf(fh, '%s \\n', '\t\t\tout = -1;');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\telseif rand\u003c0.01\t\t\t\t% flipCoin');\r\nfprintf(fh, '%s \\n', '\t\t% repeat his last move');\r\nfprintf(fh, '%s \\n', '\t\tout = histB(end);');\r\nfprintf(fh, '%s \\n', '\telse');\r\nfprintf(fh, '%s \\n', '\t\t% in the first/last X moves (+flipCoin)');\r\nfprintf(fh, '%s \\n', '\t\tif rand \u003c 0.4 \u0026\u0026 numel(histB)\u003e9900');\r\nfprintf(fh, '%s \\n', '\t\t\tout = 1;\t% catch');\r\nfprintf(fh, '%s \\n', '\t\t\treturn');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\tif rand \u003c 0.1 \u0026\u0026 numel(histB)\u003c15');\r\nfprintf(fh, '%s \\n', '\t\t\tout = 1;\t% catch');\r\nfprintf(fh, '%s \\n', '\t\t\treturn');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% check if player B has been repeating my moves (tit4tat)');\r\nfprintf(fh, '%s \\n', '\t\tn = 2;');\r\nfprintf(fh, '%s \\n', '\t\tif rand \u003c 0.9 \u0026\u0026 numel(histA)\u003en');\r\nfprintf(fh, '%s \\n', '\t\t\tif isequal(histA(end-n:end-1), histB(end-n+1:end))');\r\nfprintf(fh, '%s \\n', '\t\t\t\t% predict his next move based on my previous move');\r\nfprintf(fh, '%s \\n', '\t\t\t\tout = [1 -1 0];');\r\nfprintf(fh, '%s \\n', '\t\t\t\tout = out( histB(end)+2 );');\r\nfprintf(fh, '%s \\n', '\t\t\t\treturn');\r\nfprintf(fh, '%s \\n', '\t\t\tend');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% frequency of moves over entire history of player B');\r\nfprintf(fh, '%s \\n', '\t\tfreq = histc(histB,-1:1) ./ numel(histB);');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% flipCoin: all history or last N only');\r\nfprintf(fh, '%s \\n', '\t\tmaxNum = randi([7 10]);');\r\nfprintf(fh, '%s \\n', '\t\tif rand\u003c0.98 \u0026\u0026 numel(histB)\u003emaxNum');\r\nfprintf(fh, '%s \\n', '\t\t\thistB = histB(end-maxNum+1:end);');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% most frequent move in possibly filtered history');\r\nfprintf(fh, '%s \\n', '\t\t%idx = mode(histB)+2;');\r\nfprintf(fh, '%s \\n', '\t\t[~,idx] = max( histc(histB,-1:1) );');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% counter move');\r\nfprintf(fh, '%s \\n', '\t\tout = [1 0 0];\t\t% steal-\u003ecatch, share-\u003eshare, catch-\u003eshare');\r\nfprintf(fh, '%s \\n', '\t\tif freq(2)\u003e0.7 \u0026\u0026 rand\u003c0.995, out(2) = -1; end\t% adjust if he shares alot');\r\nfprintf(fh, '%s \\n', '\t\tif freq(1)\u003e0.7 \u0026\u0026 rand\u003c0.995, out(3) = 1; end\t% adjust if he catches alot');\r\nfprintf(fh, '%s \\n', '\t\t%{');\r\nfprintf(fh, '%s \\n', '\t\tif rand \u003c freq(1)');\r\nfprintf(fh, '%s \\n', '\t\t\tout = [1 0 1];\t% steal-\u003ecatch, share-\u003eshare, catch-\u003ecatch');\r\nfprintf(fh, '%s \\n', '\t\telseif rand \u003c freq(2)');\r\nfprintf(fh, '%s \\n', '\t\t\tout = [1 -1 0];\t% steal-\u003ecatch, share-\u003esteal, catch-\u003eshare');\r\nfprintf(fh, '%s \\n', '\t\telse');\r\nfprintf(fh, '%s \\n', '\t\t\tout = [1 0 randi([0 1])];\t% steal-\u003ecatch, share-\u003esteal, catch-\u003erandom');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\t%}');\r\nfprintf(fh, '%s \\n', '\t\tout = out(idx);');\r\nfprintf(fh, '%s \\n', '\tend');\r\nfprintf(fh, '%s \\n', '\t');\r\nfprintf(fh, '%s \\n', '\t% check if I am repeating myself in the last N moves');\r\nfprintf(fh, '%s \\n', '\t%{');\r\nfprintf(fh, '%s \\n', '\tn = 50;');\r\nfprintf(fh, '%s \\n', '\tif numel(histA)\u003e=n \u0026\u0026 all(histA(end-n+1:end)==out)');\r\nfprintf(fh, '%s \\n', '\t\tout = randi([0 1]);');\r\nfprintf(fh, '%s \\n', '\tend');\r\nfprintf(fh, '%s \\n', '\t%}');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nrehash path\r\n%%\r\n\r\nfh = @StealShareCatch;\r\n\r\na        = runPair(fh, @chaos)\r\na(end+1) = runPair(fh, @evil)\r\na(end+1) = runPair(fh, @StealShareCatch)\r\na(end+1) = runPair(fh, @good)\r\na(end+1) = runPair(fh, @doug)\r\na(end+1) = runPair(fh, @sean)\r\na(end+1) = runPair(fh, @james)\r\na(end+1) = runPair(fh, @vincent)\r\na(end+1) = runPair(fh, @JamesE)\r\na(end+1) = runPair(fh, @philipp)\r\na(end+1) = runPair(fh, @bert)\r\na(end+1) = runPair(fh, @amro)\r\n\r\nyourScore = sum(a)\r\n\r\nScore =      0; % works\r\nScore =  80219; % Vincent\r\nScore =  84000; % Sean\r\nScore =  93000; % james\r\nScore = 104000; % doug\r\nScore = 118000; % JamesE\r\nScore = 120000; % stealShareCatch\r\nScore = 122000; % philipp\r\nScore = 125000; % bert\r\nScore = 135000; % amro\r\n\r\n\r\n\r\nassert(yourScore \u003e Score(end), 'Score: %d', yourScore)","published":true,"deleted":false,"likes_count":5,"comments_count":2,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":9,"test_suite_updated_at":"2012-07-10T13:37:29.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-03T17:58:45.000Z","updated_at":"2013-04-17T13:38:44.000Z","published_at":"2012-05-03T18:29:26.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eI am no longer supporting this problem. No changes will be made to put more entries in the test suite, but have fun playing anyways!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/650-steal-share-or-catch\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSteal, Share, or Catch\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is explained in the link.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis problem is the \\\"Tournament of Champions\\\". If you make a passing entry in the original, from time to time I will move entries over to this Cody problem. You will no longer be playing against only easy characters:\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\u003eGood\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\u003eEvil\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\u003eChaos\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\u003eDoug\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou will face\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\u003eVincent\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\u003eSean\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\u003eJames\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\u003eExploiter\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\u003ePhilipp\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\u003eBert\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\u003eAmro\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eExploiter recognizes the strategies of many of the above characters, and plays well against them.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIs this cheating? Maybe, but\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/Security_through_obscurity#Arguments_against\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esecurity through obscurity\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is questionable! Take a look at Exploiter, it is the reference solution to this problem.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eI will update the test suite and cast of characters and winning score as we go. I will try to keep making the test suite tougher so that only one/two entries can pass it at any given time. It will be a matter of beating the test score more than getting lowest complexity!\u003c/w:t\u003e\u003c/w:r\u003e\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 you made something and want to see it here, just call my attention to it.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eWinner is determined by score, not by length. As of 6/28/2012 on my machine Amro is the current winner at 136K!\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":647,"title":"Getting the absolute index from a matrix","description":"This is a basic MATLAB operation. It is for instructional purposes.\r\n\r\n---\r\n\r\nYou may already know how to get the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/646-getting-the-row-and-column-location-from-a-matrix row and column index from a matrix\u003e, and the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector logical indexing\u003e technique but there is another way to reference specific elements in a matrix.\r\n\r\nAbsolute indexing refers to specific elements with a single scalar rather than two (row and column).  The upper left entry is value 1, the lower right is the highest value.  MATLAB is column major, so you count down the rows in a specific column first, moving right as needed until you reach the end.\r\n\r\n\u003chttp://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector Indexing into a vector\u003e is really using this kind of indexing, but it is more natural feeling.\r\n\r\nUse \u003chttp://www.mathworks.com/help/techdoc/ref/find.html Find\u003e.\r\n\r\nGiven a matrix M, return the absolute indices where M is greater than scalar, LB (Lower Bound) and less than UB (Upper Bound).  (See \u003chttp://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector Binary comparison\u003e to satisfy two conditions)","description_html":"\u003cp\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/p\u003e\u003cp\u003e---\u003c/p\u003e\u003cp\u003eYou may already know how to get the \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/646-getting-the-row-and-column-location-from-a-matrix\"\u003erow and column index from a matrix\u003c/a\u003e, and the \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\"\u003elogical indexing\u003c/a\u003e technique but there is another way to reference specific elements in a matrix.\u003c/p\u003e\u003cp\u003eAbsolute indexing refers to specific elements with a single scalar rather than two (row and column).  The upper left entry is value 1, the lower right is the highest value.  MATLAB is column major, so you count down the rows in a specific column first, moving right as needed until you reach the end.\u003c/p\u003e\u003cp\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\"\u003eIndexing into a vector\u003c/a\u003e is really using this kind of indexing, but it is more natural feeling.\u003c/p\u003e\u003cp\u003eUse \u003ca href=\"http://www.mathworks.com/help/techdoc/ref/find.html\"\u003eFind\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven a matrix M, return the absolute indices where M is greater than scalar, LB (Lower Bound) and less than UB (Upper Bound).  (See \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\"\u003eBinary comparison\u003c/a\u003e to satisfy two conditions)\u003c/p\u003e","function_template":"function AI = absoluteInBetween(M, LB, UB)\r\n  AI = 1;\r\nend","test_suite":"%%\r\nM = magic(5)\r\nLB = 3;\r\nUB = 10;\r\n\r\nAI = find((M \u003e LB) \u0026 (M \u003c UB));\r\n\r\nassert(isequal(absoluteInBetween(M, LB, UB),AI))\r\n\r\n%%\r\nM = magic(10)\r\nLB = 3;\r\nUB = 10;\r\n\r\nAI = find((M \u003e LB) \u0026 (M \u003c UB));\r\n\r\nassert(isequal(absoluteInBetween(M, LB, UB),AI))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":257,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-01T15:39:39.000Z","updated_at":"2026-03-29T19:40:43.000Z","published_at":"2012-05-01T15:39:39.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e---\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may already know how to get the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/646-getting-the-row-and-column-location-from-a-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003erow and column index from a matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, and the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003elogical indexing\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e technique but there is another way to reference specific elements in a matrix.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eAbsolute indexing refers to specific elements with a single scalar rather than two (row and column). The upper left entry is value 1, the lower right is the highest value. MATLAB is column major, so you count down the rows in a specific column first, moving right as needed until you reach the end.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eIndexing into a vector\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is really using this kind of indexing, but it is more natural feeling.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eUse\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/techdoc/ref/find.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFind\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix M, return the absolute indices where M is greater than scalar, LB (Lower Bound) and less than UB (Upper Bound). (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://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eBinary comparison\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e to satisfy two conditions)\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":646,"title":"Getting the row and column location from a matrix","description":"This is a basic MATLAB operation. It is for instructional purposes.\r\n\r\n---\r\n\r\nYou may already know how to get \u003chttp://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector logical indexes\u003e from a vector, and to \u003chttp://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector find the location\u003e of elements in a vector.\r\n\r\nWhat if you are dealing with a matrix.  Often you will want the row and column location of an element, or set of elements.  For instance:\r\n\r\n   [0 1 0\r\n    0 0 0]\r\n\r\nYou might want \r\n\r\n  row = 1\r\n  col = 2\r\n\r\nor \r\n\r\n   [0 1 1\r\n    1 0 0]\r\n\r\n   row = [2\r\n          1\r\n          1]\r\n\r\n   col = [1\r\n          2\r\n          3]\r\n\r\nCheck out \u003chttp://www.mathworks.com/help/techdoc/ref/find.html Find\u003e to learn to do this.\r\n\r\nGiven a matrix, M, return the column vectors that represent the row and column indices, r and c, where the given matrix, M is greater than the threshold value, thresh.  R and C will be combined into matrix out.","description_html":"\u003cp\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/p\u003e\u003cp\u003e---\u003c/p\u003e\u003cp\u003eYou may already know how to get \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\"\u003elogical indexes\u003c/a\u003e from a vector, and to \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\"\u003efind the location\u003c/a\u003e of elements in a vector.\u003c/p\u003e\u003cp\u003eWhat if you are dealing with a matrix.  Often you will want the row and column location of an element, or set of elements.  For instance:\u003c/p\u003e\u003cpre\u003e   [0 1 0\r\n    0 0 0]\u003c/pre\u003e\u003cp\u003eYou might want\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003erow = 1\r\ncol = 2\r\n\u003c/pre\u003e\u003cp\u003eor\u003c/p\u003e\u003cpre\u003e   [0 1 1\r\n    1 0 0]\u003c/pre\u003e\u003cpre\u003e   row = [2\r\n          1\r\n          1]\u003c/pre\u003e\u003cpre\u003e   col = [1\r\n          2\r\n          3]\u003c/pre\u003e\u003cp\u003eCheck out \u003ca href=\"http://www.mathworks.com/help/techdoc/ref/find.html\"\u003eFind\u003c/a\u003e to learn to do this.\u003c/p\u003e\u003cp\u003eGiven a matrix, M, return the column vectors that represent the row and column indices, r and c, where the given matrix, M is greater than the threshold value, thresh.  R and C will be combined into matrix out.\u003c/p\u003e","function_template":"function out = RCgreaterThan(M, thresh)\r\n  r = 1;\r\n  c = 1;\r\n  out = [r c]; %only one output can be checked in Cody!\r\nend","test_suite":"%%\r\nM = magic(5);\r\nthresh = 4;\r\n\r\n[r,c]= find(magic(5) \u003e 4)\r\nout = [r c]\r\n\r\nassert(isequal(RCgreaterThan(M, thresh),out))\r\n\r\n%%\r\nM = magic(6);\r\nthresh = 2;\r\n\r\n[r,c]= find(magic(6) \u003e 2)\r\nout = [r c]\r\n\r\nassert(isequal(RCgreaterThan(M, thresh),out))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":299,"test_suite_updated_at":"2012-05-01T15:24:26.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-01T15:19:06.000Z","updated_at":"2026-03-09T20:35:23.000Z","published_at":"2012-05-01T15:24:26.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e---\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may already know how to get\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003elogical indexes\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e from a vector, and to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efind the location\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e of elements in a 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:t\u003eWhat if you are dealing with a matrix. Often you will want the row and column location of an element, or set of elements. For instance:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   [0 1 0\\n    0 0 0]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou might want\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[row = 1\\ncol = 2]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eor\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   [0 1 1\\n    1 0 0]\\n\\n   row = [2\\n          1\\n          1]\\n\\n   col = [1\\n          2\\n          3]]]\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\u003eCheck out\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/techdoc/ref/find.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFind\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e to learn to do this.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix, M, return the column vectors that represent the row and column indices, r and c, where the given matrix, M is greater than the threshold value, thresh. R and C will be combined into matrix out.\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":640,"title":"Getting logical indexes","description":"This is a basic MATLAB operation.  It is for instructional purposes.\r\n\r\n---\r\n\r\nLogical indexing works like this.\r\n\r\n  thresh = 4;\r\n  vec    = [1 2 3 4 5 6 7 8];\r\n  \r\n  vi     = (vec \u003e thresh)\r\n  \r\n  vi =\r\n  \r\n       0     0     0     0     1     1     1     1\r\n\r\nOnce you have this TRUE FALSE vector (I call it vi: Valid Indices)\r\n\r\nIt can be used to get the values out:\r\n\r\n  big = vec(vi)\r\n  \r\n  big =\r\n  \r\n       5     6     7     8\r\n\r\nGiven a vector, vec, and a value, v, return a binary vector that represents the indices where vector, vec, is equal to scalar, v.\r\n\r\nNote, this works just as well with scalars and matrices.\r\n\r\n----\r\n\r\nTo get the indices where this comparison is true, see this \u003chttp://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector Cody problem\u003e.","description_html":"\u003cp\u003eThis is a basic MATLAB operation.  It is for instructional purposes.\u003c/p\u003e\u003cp\u003e---\u003c/p\u003e\u003cp\u003eLogical indexing works like this.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ethresh = 4;\r\nvec    = [1 2 3 4 5 6 7 8];\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003evi     = (vec \u003e thresh)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003evi =\r\n\u003c/pre\u003e\u003cpre\u003e       0     0     0     0     1     1     1     1\u003c/pre\u003e\u003cp\u003eOnce you have this TRUE FALSE vector (I call it vi: Valid Indices)\u003c/p\u003e\u003cp\u003eIt can be used to get the values out:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ebig = vec(vi)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ebig =\r\n\u003c/pre\u003e\u003cpre\u003e       5     6     7     8\u003c/pre\u003e\u003cp\u003eGiven a vector, vec, and a value, v, return a binary vector that represents the indices where vector, vec, is equal to scalar, v.\u003c/p\u003e\u003cp\u003eNote, this works just as well with scalars and matrices.\u003c/p\u003e\u003cp\u003e----\u003c/p\u003e\u003cp\u003eTo get the indices where this comparison is true, see this \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\"\u003eCody problem\u003c/a\u003e.\u003c/p\u003e","function_template":"function vi = binaryEqualsVector(vec, v)\r\n  vi = true;\r\nend","test_suite":"%%\r\nvec = [1 2 3 3 2 1];\r\nv = 2;\r\ny_correct = [false true false false true false];\r\nassert(isequal(binaryEqualsVector(vec,v),y_correct))\r\n\r\n%%\r\nvec = [1 2 3 4 5 6];\r\nv = 0;\r\ny_correct = [false false false false false false];\r\nassert(isequal(binaryEqualsVector(vec,v),y_correct))\r\n\r\n%%\r\nvec = [1 1 1 1 1];\r\nv = 1;\r\ny_correct = [true true true true true];\r\nassert(isequal(binaryEqualsVector(vec,v),y_correct))\r\n\r\n%%\r\nvec = 'abcdef';\r\nv = 'a';\r\ny_correct = [true false false false false false];\r\nassert(isequal(binaryEqualsVector(vec,v),y_correct))\r\n","published":true,"deleted":false,"likes_count":9,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1184,"test_suite_updated_at":"2012-04-30T18:48:13.000Z","rescore_all_solutions":false,"group_id":12,"created_at":"2012-04-30T18:46:03.000Z","updated_at":"2026-04-10T23:47:02.000Z","published_at":"2012-04-30T18:48:13.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e---\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLogical indexing works like this.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[thresh = 4;\\nvec    = [1 2 3 4 5 6 7 8];\\n\\nvi     = (vec \u003e thresh)\\n\\nvi =\\n\\n       0     0     0     0     1     1     1     1]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOnce you have this TRUE FALSE vector (I call it vi: Valid Indices)\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eIt can be used to get the values out:\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[big = vec(vi)\\n\\nbig =\\n\\n       5     6     7     8]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector, vec, and a value, v, return a binary vector that represents the indices where vector, vec, is equal to scalar, v.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eNote, this works just as well with scalars and matrices.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e----\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo get the indices where this comparison is true, see this\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\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":648,"title":"Cumulative probability of finding an unlikely combination","description":"This is a supplemental problem to the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition CryptoMath\u003e problem.  If you solve the problem methodically or randomly matters for expected solution time.  This calculates the difference in techniques.  My reference solution has some commented out graphics code to visualize the timing differences.\r\n\r\n---\r\n\r\nIf you have N possible combinations to a lock you can calculate the likelihood of opening the lock as a percentage given X attempts.\r\n\r\nThere are two ways to figure out the combination to try:\r\n\r\n* Try a random one, possibly trying an old one again\r\n* Methodically doing them in order\r\n\r\nChoosing a random combination is very fast and easy.  No record keeping needed.  Choosing a methodical way of trying them all is a little slower on each attempt, and incurs a fix cost before the first attempt is made.\r\n\r\nIf you have:\r\n\r\n* Goal of *G%* cumulative probability of opening the lock\r\n* Fixed cost of *F* seconds to start the methodical style\r\n* *TR* seconds per random attempt\r\n* *TM* seconds per methodical attempt\r\n* *N* equally likely combinations\r\n\r\nWhich technique should you use to get to your goal chance fastest?\r\n\r\n* *0* for random\r\n* *1* for methodical\r\n\r\n---\r\nNote for the curious:  The really short solution is gaming the system and just choosing randomly.  Eventually one of the solutions will guess right on all the test suite.","description_html":"\u003cp\u003eThis is a supplemental problem to the \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\"\u003eCryptoMath\u003c/a\u003e problem.  If you solve the problem methodically or randomly matters for expected solution time.  This calculates the difference in techniques.  My reference solution has some commented out graphics code to visualize the timing differences.\u003c/p\u003e\u003cp\u003e---\u003c/p\u003e\u003cp\u003eIf you have N possible combinations to a lock you can calculate the likelihood of opening the lock as a percentage given X attempts.\u003c/p\u003e\u003cp\u003eThere are two ways to figure out the combination to try:\u003c/p\u003e\u003cul\u003e\u003cli\u003eTry a random one, possibly trying an old one again\u003c/li\u003e\u003cli\u003eMethodically doing them in order\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eChoosing a random combination is very fast and easy.  No record keeping needed.  Choosing a methodical way of trying them all is a little slower on each attempt, and incurs a fix cost before the first attempt is made.\u003c/p\u003e\u003cp\u003eIf you have:\u003c/p\u003e\u003cul\u003e\u003cli\u003eGoal of \u003cb\u003eG%\u003c/b\u003e cumulative probability of opening the lock\u003c/li\u003e\u003cli\u003eFixed cost of \u003cb\u003eF\u003c/b\u003e seconds to start the methodical style\u003c/li\u003e\u003cli\u003e\u003cb\u003eTR\u003c/b\u003e seconds per random attempt\u003c/li\u003e\u003cli\u003e\u003cb\u003eTM\u003c/b\u003e seconds per methodical attempt\u003c/li\u003e\u003cli\u003e\u003cb\u003eN\u003c/b\u003e equally likely combinations\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eWhich technique should you use to get to your goal chance fastest?\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003cb\u003e0\u003c/b\u003e for random\u003c/li\u003e\u003cli\u003e\u003cb\u003e1\u003c/b\u003e for methodical\u003c/li\u003e\u003c/ul\u003e\u003cp\u003e---\r\nNote for the curious:  The really short solution is gaming the system and just choosing randomly.  Eventually one of the solutions will guess right on all the test suite.\u003c/p\u003e","function_template":"function choice = chaosOrOrder(g,f,tr,tm, n)\r\n  y = 0;\r\nend","test_suite":"%%\r\ng  =  0.9;\r\nf  = 10;\r\ntr =  1;\r\ntm =  2;\r\nn  = 10;\r\nout = 0;\r\n\r\nassert(isequal(chaosOrOrder(g,f,tr,tm,n),out))\r\n\r\n%%\r\ng  =  0.9;\r\nf  = 10;\r\ntr =  1;\r\ntm =  2;\r\nn  = 100;\r\nout = 1;\r\n\r\nassert(isequal(chaosOrOrder(g,f,tr,tm,n),out))\r\n\r\n%%\r\ng  =  0.9;\r\nf  = 10;\r\ntr =  .1;\r\ntm =  2;\r\nn  = 10000;\r\nout = 0;\r\n\r\nassert(isequal(chaosOrOrder(g,f,tr,tm,n),out))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":35,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-01T17:58:41.000Z","updated_at":"2025-11-27T17:33:42.000Z","published_at":"2012-05-01T19:29:40.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a supplemental problem to the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCryptoMath\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e problem. If you solve the problem methodically or randomly matters for expected solution time. This calculates the difference in techniques. My reference solution has some commented out graphics code to visualize the timing differences.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e---\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf you have N possible combinations to a lock you can calculate the likelihood of opening the lock as a percentage given X attempts.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are two ways to figure out the combination to try:\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\u003eTry a random one, possibly trying an old one again\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\u003eMethodically doing them in order\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eChoosing a random combination is very fast and easy. No record keeping needed. Choosing a methodical way of trying them all is a little slower on each attempt, and incurs a fix cost before the first attempt is made.\u003c/w:t\u003e\u003c/w:r\u003e\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 you have:\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\u003eGoal of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eG%\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e cumulative probability of opening the lock\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\u003eFixed cost of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eF\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e seconds to start the methodical style\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTR\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e seconds per random attempt\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTM\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e seconds per methodical attempt\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e equally likely combinations\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhich technique should you use to get to your goal chance fastest?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for random\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for methodical\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e--- Note for the curious: The really short solution is gaming the system and just choosing randomly. Eventually one of the solutions will guess right on all the test suite.\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":641,"title":"Make a random, non-repeating vector.","description":"This is a basic MATLAB operation. It is for instructional purposes.\r\n\r\n---\r\n\r\nIf you want to get a random permutation of integers \u003chttp://www.mathworks.com/help/techdoc/ref/randperm.html randperm\u003e will help.\r\n\r\nGiven n, put the integers [1 2 3... N] in a random order.\r\n\r\nYes, the test suite is not conclusive, but it is pretty close!","description_html":"\u003cp\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/p\u003e\u003cp\u003e---\u003c/p\u003e\u003cp\u003eIf you want to get a random permutation of integers \u003ca href=\"http://www.mathworks.com/help/techdoc/ref/randperm.html\"\u003erandperm\u003c/a\u003e will help.\u003c/p\u003e\u003cp\u003eGiven n, put the integers [1 2 3... N] in a random order.\u003c/p\u003e\u003cp\u003eYes, the test suite is not conclusive, but it is pretty close!\u003c/p\u003e","function_template":"function vec = makeRandomOrdering(n)\r\n  vec = n;\r\nend","test_suite":"%%\r\nn = 10;\r\n\r\nflagSame    = isequal(makeRandomOrdering(n), makeRandomOrdering(n));\r\nflagAllUsed = isequal([1:n],sort(makeRandomOrdering(n)));\r\nassert(~flagSame \u0026 flagAllUsed)","published":true,"deleted":false,"likes_count":48,"comments_count":2,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":11282,"test_suite_updated_at":"2012-04-30T20:15:56.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-30T20:13:04.000Z","updated_at":"2026-04-15T14:47:00.000Z","published_at":"2012-04-30T20:15:56.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e---\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf you want to get a random permutation of integers\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/techdoc/ref/randperm.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003erandperm\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e will help.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven n, put the integers [1 2 3... N] in a random order.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eYes, the test suite is not conclusive, but it is pretty close!\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":642,"title":"Convert a vector into a number","description":"This is a sub problem related to this problem:\r\n\r\n\u003chttp://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\u003e\r\n\r\nIf vector, v, has only whole numbers [0 1 2 ... 9], then it can be turned into a base ten number as follows:\r\n\r\n  [3 4 2 9] ---\u003e 3429\r\n  [1 3 5]   ---\u003e  135\r\n\r\nMake this conversion.","description_html":"\u003cp\u003eThis is a sub problem related to this problem:\u003c/p\u003e\u003cp\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\"\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\u003c/a\u003e\u003c/p\u003e\u003cp\u003eIf vector, v, has only whole numbers [0 1 2 ... 9], then it can be turned into a base ten number as follows:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[3 4 2 9] ---\u003e 3429\r\n[1 3 5]   ---\u003e  135\r\n\u003c/pre\u003e\u003cp\u003eMake this conversion.\u003c/p\u003e","function_template":"function out = digits2Number(vec)\r\n  out = 1;\r\nend","test_suite":"%%\r\nvec = [2 4 9 2];\r\ny_correct = 2492;\r\nassert(isequal(digits2Number(vec),y_correct))\r\n%%\r\nvec = [3 2]';\r\ny_correct = 32;\r\nassert(isequal(digits2Number(vec),y_correct))\r\n%%\r\nvec = [0 1 3 8 9 0];\r\ny_correct = 13890;\r\nassert(isequal(digits2Number(vec),y_correct))\r\n%%\r\nvec = [0 0 9 8 2];\r\ny_correct = 982;\r\nassert(isequal(digits2Number(vec),y_correct))","published":true,"deleted":false,"likes_count":11,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":615,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-30T20:37:07.000Z","updated_at":"2026-03-11T13:59:59.000Z","published_at":"2012-04-30T20:37:23.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a sub problem related to this problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf vector, v, has only whole numbers [0 1 2 ... 9], then it can be turned into a base ten number as follows:\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[[3 4 2 9] ---\u003e 3429\\n[1 3 5]   ---\u003e  135]]\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\u003eMake this conversion.\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":601,"title":"Retirement savings","description":"At the start of what year will you have reached or exceeded a savings goal?\r\n\r\nParameters (all are constant scalars given in a structure):\r\n\r\n*  *f.startingSalary*: Starting yearly salary\r\n*  *f.investRate*: Percentage of salary invested each year\r\n*  *f.raiseRate*: Percentage raise given at beginning of year EXCEPT the first\r\n*  *f.returnRate*: Percentage gain in invested money\r\n*  *f.goal*: Savings goal\r\n\r\nSimplifying assumptions:\r\n\r\n* All money is invested at the end of the year.\r\n* Interest is awarded once at the end of the year on money that has been invest for an entire year\r\n* All interest is reinvested immediately and will gain interest the next year\r\n\r\nReturn:\r\n\r\n* At the beginning of which year will the goal been met or exceeded?","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: 346.9px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 173.45px; transform-origin: 407px 173.45px; 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: 237.5px 8px; transform-origin: 237.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAt the start of what year will you have reached or exceeded a savings goal?\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: 181px 8px; transform-origin: 181px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eParameters (all are constant scalars given in a structure):\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 102.167px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 51.0833px; transform-origin: 391px 51.0833px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 52.5px 8px; transform-origin: 52.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ef.startingSalary\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 70.5px 8px; transform-origin: 70.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e: Starting yearly salary\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 42.5px 8px; transform-origin: 42.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ef.investRate\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 131.5px 8px; transform-origin: 131.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e: Percentage of salary invested each year\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 38px 8px; transform-origin: 38px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ef.raiseRate\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 196.5px 8px; transform-origin: 196.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e: Percentage raise given at beginning of year EXCEPT the first\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 42.5px 8px; transform-origin: 42.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ef.returnRate\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 115px 8px; transform-origin: 115px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e: Percentage gain in invested money\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 19.5px 8px; transform-origin: 19.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ef.goal\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 44.5px 8px; transform-origin: 44.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e: Savings goal\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\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: 77px 8px; transform-origin: 77px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSimplifying assumptions:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 61.3px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 30.65px; transform-origin: 391px 30.65px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 137.5px 8px; transform-origin: 137.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAll money is invested at the end of the year.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 302.5px 8px; transform-origin: 302.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eInterest is awarded once at the end of the year on money that has been invest for an entire year\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 223px 8px; transform-origin: 223px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAll interest is reinvested immediately and will gain interest the next year\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\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: 23.5px 8px; transform-origin: 23.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cul style=\"block-size: 20.4333px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 10.2167px; transform-origin: 391px 10.2167px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 210px 8px; transform-origin: 210px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAt the beginning of which year will the goal been met or exceeded?\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function year = calculateRetirementYear(f)\r\n  %f.startingSalary\r\n  %f.investRate\r\n  %f.returnRate\r\n  %f.raiseRate\r\n  %f.goal\r\n  year = 1;\r\nend","test_suite":"%%\r\nfinancial.startingSalary =   50000;\r\nfinancial.investRate     =       0.1;\r\nfinancial.returnRate     =       0.1;\r\nfinancial.raiseRate      =       0.05;\r\nfinancial.goal           = 1000000;\r\n\r\ny_correct = 29;\r\nassert(isequal(calculateRetirementYear(financial),y_correct))\r\n\r\n%%\r\nfinancial.startingSalary =   60000;\r\nfinancial.investRate     =       0.12;\r\nfinancial.returnRate     =       0.1;\r\nfinancial.raiseRate      =       0.05;\r\nfinancial.goal           = 1000000;\r\n\r\ny_correct = 26;\r\nassert(isequal(calculateRetirementYear(financial),y_correct))\r\n\r\n%%\r\nfinancial.startingSalary =   60000;\r\nfinancial.investRate     =       0.12;\r\nfinancial.returnRate     =       0.1;\r\nfinancial.raiseRate      =       0.05;\r\nfinancial.goal           = 2000000;\r\n\r\ny_correct = 32;\r\nassert(isequal(calculateRetirementYear(financial),y_correct))\r\n\r\n%%\r\nfinancial.startingSalary =   60000;\r\nfinancial.investRate     =       0.12;\r\nfinancial.returnRate     =       0.1;\r\nfinancial.raiseRate      =       0.08;\r\nfinancial.goal           = 2000000;\r\n\r\ny_correct = 29;\r\nassert(isequal(calculateRetirementYear(financial),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":29,"test_suite_updated_at":"2020-10-26T17:52:05.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-19T15:41:36.000Z","updated_at":"2025-10-01T03:42:14.000Z","published_at":"2012-04-19T15:41:36.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\u003eAt the start of what year will you have reached or exceeded a savings goal?\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\u003eParameters (all are constant scalars given in a structure):\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ef.startingSalary\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: Starting yearly salary\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ef.investRate\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: Percentage of salary invested each year\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ef.raiseRate\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: Percentage raise given at beginning of year EXCEPT the first\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ef.returnRate\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: Percentage gain in invested money\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ef.goal\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e: Savings goal\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\u003eSimplifying assumptions:\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAll money is invested at the end of the year.\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInterest is awarded once at the end of the year on money that has been invest for an entire year\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAll interest is reinvested immediately and will gain interest the next year\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\u003eReturn:\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAt the beginning of which year will the goal been met or exceeded?\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":639,"title":"String substitution, sub problem to cryptoMath","description":"This is a sub problem related to this problem:\r\n\r\n\u003chttp://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\u003e\r\n\r\nIf you have a string\r\n\r\n  'cab' \r\n\r\nand you have a mapping where you want:\r\n\r\n  'abc' to map to the digits [906]\r\n\r\nthen you will get this:\r\n\r\n  % 'cab' , 'abc', [906] --\u003e [6 9 0];\r\n\r\nAnother example is:\r\n\r\n  % 'feed', 'def', [541] --\u003e [1 4 4 5];\r\n\r\nYour inputs will be of this form:\r\n\r\n  out = stringSubstitute(string, letters, digits)\r\n  \r\n  \u003e\u003e stringSubstitute('feed','def',[5 4 1])\r\n  \r\n  ans =\r\n  \r\n       1     4     4     5\r\n\r\n","description_html":"\u003cp\u003eThis is a sub problem related to this problem:\u003c/p\u003e\u003cp\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\"\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\u003c/a\u003e\u003c/p\u003e\u003cp\u003eIf you have a string\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e'cab' \r\n\u003c/pre\u003e\u003cp\u003eand you have a mapping where you want:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e'abc' to map to the digits [906]\r\n\u003c/pre\u003e\u003cp\u003ethen you will get this:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e% 'cab' , 'abc', [906] --\u003e [6 9 0];\r\n\u003c/pre\u003e\u003cp\u003eAnother example is:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e% 'feed', 'def', [541] --\u003e [1 4 4 5];\r\n\u003c/pre\u003e\u003cp\u003eYour inputs will be of this form:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eout = stringSubstitute(string, letters, digits)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003e\u003e\u003e stringSubstitute('feed','def',[5 4 1])\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eans =\r\n\u003c/pre\u003e\u003cpre\u003e       1     4     4     5\u003c/pre\u003e","function_template":"function out = stringSubstitute(string, letters, digits)\r\n  y = 1;\r\nend","test_suite":"%%\r\nstring  = 'cab';\r\nletters = 'abc';\r\ndigits  = [9 0 6]; \r\ny_correct = [6 9 0];\r\nassert(isequal(stringSubstitute(string, letters, digits),y_correct))\r\n\r\n%%\r\n\r\nstring  = 'feed';\r\nletters = 'def';\r\ndigits  = [5 4 1]; \r\ny_correct = [1 4 4 5];\r\nassert(isequal(stringSubstitute(string, letters, digits),y_correct))\r\n\r\n%%\r\n\r\nstring  = 'matlab';\r\nletters = 'ablmt';\r\ndigits  = [0 3 4 6 1]; \r\ny_correct = [6 0 1 4 0 3];\r\nassert(isequal(stringSubstitute(string, letters, digits),y_correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":245,"test_suite_updated_at":"2012-04-30T17:27:03.000Z","rescore_all_solutions":false,"group_id":14,"created_at":"2012-04-30T15:20:02.000Z","updated_at":"2026-04-10T15:08:36.000Z","published_at":"2012-04-30T17:27:03.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is a sub problem related to this problem:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://www.mathworks.com/matlabcentral/cody/problems/621-cryptomath-addition\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf you have a string\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['cab']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eand you have a mapping where you want:\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['abc' to map to the digits [906]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethen you will get this:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[% 'cab' , 'abc', [906] --\u003e [6 9 0];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAnother example is:\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[% 'feed', 'def', [541] --\u003e [1 4 4 5];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour inputs will be of this form:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[out = stringSubstitute(string, letters, digits)\\n\\n\u003e\u003e stringSubstitute('feed','def',[5 4 1])\\n\\nans =\\n\\n       1     4     4     5]]\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":602,"title":"Make a simplified barcode","description":"Given an integer to encode, make a barcode using the following encoding scheme:\r\n\r\n* The bar code is made from the binary version of the integer\r\n* The bar code is a matrix 30x?\r\n* A '1' becomes a thick bar\r\n* A '0' becomes a thin bar\r\n* Bars are represented by 0's in the output\r\n* A '1' becomes '0 0 0'\r\n* A '0' becomes '0'\r\n* White space between bars is a single 1\r\n* There will be no left hand zeros in the binary representation\r\n* There are three columns of white space at beginning and end of bar code\r\nFor example:\r\n\r\nInput 5 yields\r\n\r\n[1 1 1 0 0 0 1 0 1 0 0 0 1 1 1] (only repeated for 30 rows);\r\n\r\n","description_html":"\u003cp\u003eGiven an integer to encode, make a barcode using the following encoding scheme:\u003c/p\u003e\u003cul\u003e\u003cli\u003eThe bar code is made from the binary version of the integer\u003c/li\u003e\u003cli\u003eThe bar code is a matrix 30x?\u003c/li\u003e\u003cli\u003eA '1' becomes a thick bar\u003c/li\u003e\u003cli\u003eA '0' becomes a thin bar\u003c/li\u003e\u003cli\u003eBars are represented by 0's in the output\u003c/li\u003e\u003cli\u003eA '1' becomes '0 0 0'\u003c/li\u003e\u003cli\u003eA '0' becomes '0'\u003c/li\u003e\u003cli\u003eWhite space between bars is a single 1\u003c/li\u003e\u003cli\u003eThere will be no left hand zeros in the binary representation\u003c/li\u003e\u003cli\u003eThere are three columns of white space at beginning and end of bar code\r\nFor example:\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eInput 5 yields\u003c/p\u003e\u003cp\u003e[1 1 1 0 0 0 1 0 1 0 0 0 1 1 1] (only repeated for 30 rows);\u003c/p\u003e","function_template":"function out = barEncoder(in)\r\n  out = in;\r\nend","test_suite":"%%\r\nx = 5;\r\ny_correct = repmat( [1 1 1 0 0 0 1 0 1 0 0 0 1 1 1],[30,1]);;\r\nassert(isequal(barEncoder(x),y_correct))\r\n%%\r\nx = 12;\r\ny_correct = repmat( [1 1 1 0 0 0 1 0 0 0 1 0 1 0 1 1 1],[30,1]);;\r\nassert(isequal(barEncoder(x),y_correct))\r\n%%\r\nx = 135;\r\ny_correct = repmat( [1 1 1 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 1 1 1],[30,1]);;\r\nassert(isequal(barEncoder(x),y_correct))\r\n%%\r\nx = 2;\r\ny_correct = repmat( [1 1 1 0 0 0 1 0 1 1 1],[30,1]);\r\nassert(isequal(barEncoder(x),y_correct))\r\n%%\r\nx = 22;\r\ny_correct = repmat( [1 1 1 0 0 0 1 0 1 0 0 0 1 0 0 0 1 0 1 1 1],[30,1]);\r\nassert(isequal(barEncoder(x),y_correct))","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":180,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":38,"created_at":"2012-04-19T19:25:38.000Z","updated_at":"2026-03-31T17:44:19.000Z","published_at":"2012-04-19T19:25:46.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an integer to encode, make a barcode using the following encoding scheme:\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\u003eThe bar code is made from the binary version of the integer\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\u003eThe bar code is a matrix 30x?\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\u003eA '1' becomes a thick bar\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\u003eA '0' becomes a thin bar\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\u003eBars are represented by 0's in the output\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\u003eA '1' becomes '0 0 0'\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA '0' becomes '0'\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhite space between bars is a single 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere will be no left hand zeros in 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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are three columns of white space at beginning and end of bar codeFor example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput 5 yields\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[1 1 1 0 0 0 1 0 1 0 0 0 1 1 1] (only repeated for 30 rows);\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":603,"title":"Decode a simplified barcode","description":"Given a bar code from this \u003chttp://www.mathworks.com/matlabcentral/cody/problems/602-make-a-simplified-bar-code exercise\u003e:\r\n\r\nReturn the integer that would generate it.","description_html":"\u003cp\u003eGiven a bar code from this \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/602-make-a-simplified-bar-code\"\u003eexercise\u003c/a\u003e:\u003c/p\u003e\u003cp\u003eReturn the integer that would generate it.\u003c/p\u003e","function_template":"function out = barDecoder(im)\r\n\r\nout = 3;\r\nend","test_suite":"%%\r\nnumOut = 5;\r\nbarIn = repmat( [1 1 1 0 0 0 1 0 1 0 0 0 1 1 1],[30,1]);;\r\nassert(isequal(barDecoder(barIn),numOut))\r\n%%\r\nnumOut = 12;\r\nbarIn = repmat( [1 1 1 0 0 0 1 0 0 0 1 0 1 0 1 1 1],[30,1]);;\r\nassert(isequal(barDecoder(barIn),numOut))\r\n%%\r\nnumOut = 135;\r\nbarIn = repmat( [1 1 1 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 1 1 1],[30,1]);;\r\nassert(isequal(barDecoder(barIn),numOut))\r\n%%\r\nnumOut = 2;\r\nbarIn = repmat( [1 1 1 0 0 0 1 0 1 1 1],[30,1]);\r\nassert(isequal(barDecoder(barIn),numOut))\r\n%%\r\nnumOut = 22;\r\nbarIn = repmat( [1 1 1 0 0 0 1 0 1 0 0 0 1 0 0 0 1 0 1 1 1],[30,1]);\r\nassert(isequal(barDecoder(barIn),numOut))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":133,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":38,"created_at":"2012-04-19T20:53:42.000Z","updated_at":"2026-03-31T17:45:33.000Z","published_at":"2012-04-19T20:54:04.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a bar code from this\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/602-make-a-simplified-bar-code\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eexercise\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the integer that would generate it.\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":645,"title":"Getting the indices from a vector","description":"This is a basic MATLAB operation. It is for instructional purposes.\r\n---\r\nYou may already know how to find the logical indices of the elements of a vector that meet your criteria.\r\nThis exercise is for finding the index of indices that meet your criteria. The difference is this:\r\n     vec = [11 22 33 44];\r\n  thresh = 25;\r\n      vi = (vec \u003e thresh)\r\n\r\nvi =\r\n\r\n     0     0     1     1\r\nWhat we are looking for now is how to get the values\r\n   x =\r\n\r\n     3     4\r\nBecause those are the indices where the binary comparison is true.\r\n\r\nGiven a vector, vec, return the indices where vec is greater than scalar, thresh.","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: 457.333px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 406.5px 228.667px; transform-origin: 406.5px 228.667px; 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: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 211.05px 7.81667px; transform-origin: 211.05px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 6.7px 7.81667px; transform-origin: 6.7px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e---\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 96.5917px 7.81667px; transform-origin: 96.5917px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou may already know how to\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2.23333px 7.81667px; transform-origin: 2.23333px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003efind the logical indices\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 162.475px 7.81667px; transform-origin: 162.475px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e of the elements of a vector that meet your criteria.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 294.8px 7.81667px; transform-origin: 294.8px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis exercise is for finding the index of indices that meet your criteria. The difference is this:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 143.033px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 403.5px 71.5167px; transform-origin: 403.5px 71.5167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 97.7083px 8.375px; tab-size: 4; transform-origin: 97.7083px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     vec = [11 22 33 44];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 54.7167px 8.375px; tab-size: 4; transform-origin: 54.7167px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e  thresh = 25;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 97.7083px 8.375px; tab-size: 4; transform-origin: 97.7083px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e      vi = (vec \u0026gt; thresh)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.375px; tab-size: 4; transform-origin: 0px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 15.6333px 8.375px; tab-size: 4; transform-origin: 15.6333px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003evi =\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.375px; tab-size: 4; transform-origin: 0px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 93.8px 8.375px; tab-size: 4; transform-origin: 93.8px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     0     0     1     1\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 169.175px 7.81667px; transform-origin: 169.175px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWhat we are looking for now is how to get the values\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 403.5px 30.65px; transform-origin: 403.5px 30.65px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 23.45px 8.375px; tab-size: 4; transform-origin: 23.45px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e   x =\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.375px; tab-size: 4; transform-origin: 0px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1.11667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1.11667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1.11667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1.11667px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 403.5px 10.2167px; text-wrap-mode: nowrap; transform-origin: 403.5px 10.2167px; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 46.9px 8.375px; tab-size: 4; transform-origin: 46.9px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     3     4\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 217.75px 7.81667px; transform-origin: 217.75px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eBecause those are the indices where the binary comparison is true.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 7.81667px; transform-origin: 0px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 10.5px; text-align: left; transform-origin: 383.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 250.692px 7.81667px; transform-origin: 250.692px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a vector, vec, return the indices where vec is greater than scalar, thresh.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function out = findIndices(vec, thresh)\r\n  out = 1;\r\nend","test_suite":"%%\r\nfiletext = fileread('findIndices.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp');\r\nassert(~illegal)\r\n\r\n\r\n%%\r\nout = [3 4];\r\nvec = [11 22 33 44];\r\nthresh = 25;\r\nassert(isequal(findIndices(vec, thresh),out))\r\n\r\n%%\r\nout = [1 2];\r\nvec = [33 44 11 22];\r\nthresh = 25;\r\nassert(isequal(findIndices(vec, thresh),out))\r\n\r\n%%\r\nout = 5:10;\r\nvec = 10:10:100;\r\nthresh = 45;\r\nassert(isequal(findIndices(vec, thresh),out))\r\n\r\n%%\r\nout = [1 3 4 6 8];\r\nvec = [12 10 13 14 9 17 5 18];\r\nthresh = 11;\r\nassert(isequal(findIndices(vec, thresh),out))\r\n\r\n%%\r\nout = [1:3 7:9];\r\nvec = [50 55 60 15 10 5 43 44 97 41];\r\nthresh = 42;\r\nassert(isequal(findIndices(vec, thresh),out))\r\n\r\n%%\r\nout = 5:8;\r\nvec = [10 12 14 16 18 20 22 23 7 8 9];\r\nthresh = 17;\r\nassert(isequal(findIndices(vec, thresh),out))\r\n\r\n%%\r\nout = [2 4:5 8 12:14 16];\r\nvec = [10 81 24 65 97 13 45 68 24 35 16 79 123 76 45 60];\r\nthresh = 51;\r\nassert(isequal(findIndices(vec, thresh),out))\r\n\r\n%%\r\nout = 1:2:9;\r\nvec = [11 9 12 8 13 7 14 6 15 5];\r\nthresh = 10;\r\nassert(isequal(findIndices(vec, thresh),out))","published":true,"deleted":false,"likes_count":68,"comments_count":6,"created_by":240,"edited_by":223089,"edited_at":"2024-06-28T16:25:40.000Z","deleted_by":null,"deleted_at":null,"solvers_count":11901,"test_suite_updated_at":"2024-06-28T16:25:40.000Z","rescore_all_solutions":false,"group_id":13,"created_at":"2012-05-01T15:07:35.000Z","updated_at":"2026-04-15T12:30:28.000Z","published_at":"2012-05-01T15:07:43.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\u003eThis is a basic MATLAB operation. It is for instructional purposes.\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\u003e---\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may already know how to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efind the logical indices\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e of the elements of a vector that meet your criteria.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis exercise is for finding the index of indices that meet your criteria. The difference is this:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[     vec = [11 22 33 44];\\n  thresh = 25;\\n      vi = (vec \u003e thresh)\\n\\nvi =\\n\\n     0     0     1     1]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhat we are looking for now is how to get the values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   x =\\n\\n     3     4]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBecause those are the indices where the binary comparison is true.\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\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector, vec, return the indices where vec is greater than scalar, thresh.\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":650,"title":"Steal, Share, or Catch","description":"You, I, and a few other characters are going to play a game of *Steal, Share or Catch*.  We are going to play it 10,000 times vs. each of the characters.  \r\n\r\nThe rules of the game are this:\r\n\r\n* There are two points available each round\r\n* We will both choose to either Steal, Share, or Catch\r\n\r\n* If we both choose Share, we both get one point.\r\n* If one chooses Steal and the other Share, the Stealer gets two points.\r\n* If one chooses Steal and the other Catch, the Catcher gets two points.\r\n* Any other combination, no one is awarded points.\r\n\r\nYou are to write an algorithm that will return either\r\n\r\n* -1: Steal\r\n*  0: Share\r\n*  1: Catch\r\n\r\nTo help you make your choice, you will have a history vector that shows what your choices have been so far, and what the opponent's choices have been.  These histories are in the form of:\r\n\r\n  [-1\r\n    1\r\n    1\r\n    0]\r\n\r\nMeaning that the first round there was a Steal, then two Catches, then a share.\r\n\r\nThe characters you will play against are:\r\n\r\n* Evil  (always steals)\r\n* Good  (always shares)\r\n* Chaos (randomly chooses)\r\n* Doug  (Something more complicated)\r\n\r\nAs this problem runs, I will take the better entries and add them into the cast of characters that you play against.  Maybe in a different Cody problem though.\r\n\r\nThe scores to beat are:\r\n\r\n  terribleScore   =     0; % works\r\n  badScore        = 23000; % good  strategy scores this\r\n  okScore         = 26000; % evil  strategy scores this\r\n  decentScore     = 29000; % chaos strategy scores this\r\n  greatScore      = 42000; % doug  strategy scores this\r\n\r\nIf you can make a winning solution here, it might be added to the  \u003chttp://www.mathworks.com/matlabcentral/cody/problems/653-steal-share-or-catch-tournament-of-champions Tournament of Champions\u003e version of this problem.  E-mail me if you want yours added.","description_html":"\u003cp\u003eYou, I, and a few other characters are going to play a game of \u003cb\u003eSteal, Share or Catch\u003c/b\u003e.  We are going to play it 10,000 times vs. each of the characters.\u003c/p\u003e\u003cp\u003eThe rules of the game are this:\u003c/p\u003e\u003cul\u003e\u003cli\u003eThere are two points available each round\u003c/li\u003e\u003cli\u003eWe will both choose to either Steal, Share, or Catch\u003c/li\u003e\u003c/ul\u003e\u003cul\u003e\u003cli\u003eIf we both choose Share, we both get one point.\u003c/li\u003e\u003cli\u003eIf one chooses Steal and the other Share, the Stealer gets two points.\u003c/li\u003e\u003cli\u003eIf one chooses Steal and the other Catch, the Catcher gets two points.\u003c/li\u003e\u003cli\u003eAny other combination, no one is awarded points.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eYou are to write an algorithm that will return either\u003c/p\u003e\u003cul\u003e\u003cli\u003e-1: Steal\u003c/li\u003e\u003cli\u003e0: Share\u003c/li\u003e\u003cli\u003e1: Catch\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eTo help you make your choice, you will have a history vector that shows what your choices have been so far, and what the opponent's choices have been.  These histories are in the form of:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[-1\r\n  1\r\n  1\r\n  0]\r\n\u003c/pre\u003e\u003cp\u003eMeaning that the first round there was a Steal, then two Catches, then a share.\u003c/p\u003e\u003cp\u003eThe characters you will play against are:\u003c/p\u003e\u003cul\u003e\u003cli\u003eEvil  (always steals)\u003c/li\u003e\u003cli\u003eGood  (always shares)\u003c/li\u003e\u003cli\u003eChaos (randomly chooses)\u003c/li\u003e\u003cli\u003eDoug  (Something more complicated)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eAs this problem runs, I will take the better entries and add them into the cast of characters that you play against.  Maybe in a different Cody problem though.\u003c/p\u003e\u003cp\u003eThe scores to beat are:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eterribleScore   =     0; % works\r\nbadScore        = 23000; % good  strategy scores this\r\nokScore         = 26000; % evil  strategy scores this\r\ndecentScore     = 29000; % chaos strategy scores this\r\ngreatScore      = 42000; % doug  strategy scores this\r\n\u003c/pre\u003e\u003cp\u003eIf you can make a winning solution here, it might be added to the  \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/653-steal-share-or-catch-tournament-of-champions\"\u003eTournament of Champions\u003c/a\u003e version of this problem.  E-mail me if you want yours added.\u003c/p\u003e","function_template":"function choice = StealShareCatch(yourHist, theirHist)\r\n% This function will be called 10,000 times.\r\n% the hist vectors will start as [], and get longer each time through.\r\n%-1 steal\r\n% 0 share\r\n% 1 catch\r\n\r\n%stealVal = 2; What you get if you steal and they share\r\n%catchVal = 2; What you get if you catch and they steal\r\n%shareVal = 1; What you both get if both share\r\n%Otherwise no one gets anything!\r\n  choice = 0;\r\nend","test_suite":"% THIS IS A HACK TO GET CODE ON THE PATH\r\n% IGNORE THIS FIRST 'TEST'\r\n%\r\n%\r\nfh=fopen('doug.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = doug(histA, histB)');\r\nfprintf(fh, '%s \\n', '% A is self');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'memoryThresh = 10;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histB = [zeros(memoryThresh,1); histB];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'recentB = histB(end-(memoryThresh-1) : end);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'numStealB = nnz(recentB == -1);');\r\nfprintf(fh, '%s \\n', 'numShareB = nnz(recentB ==  0);');\r\nfprintf(fh, '%s \\n', 'numCatchB = nnz(recentB ==  1);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'percentStealB = (numStealB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentShareB = (numShareB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentCatchB = (numCatchB/memoryThresh);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0; %default to share');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            rollDice = rand;');\r\nfprintf(fh, '%s \\n', 'percentCatchStealers = 0.9;');\r\nfprintf(fh, '%s \\n', 'if (rollDice \u003c percentStealB)');\r\nfprintf(fh, '%s \\n', '    rollDice = rand;');\r\nfprintf(fh, '%s \\n', '    if (rollDice \u003c percentCatchStealers)');\r\nfprintf(fh, '%s \\n', '        out =  1; % catch');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        out = -1; % steal');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\nfh=fopen('runPair.m','wt');\r\nfprintf(fh, '%s \\n', 'function [scoreA, scoreB] = runPair(fhA, fhB);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'n = 10000;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histA = [];');\r\nfprintf(fh, '%s \\n', 'histB = [];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'scoreA = 0;');\r\nfprintf(fh, '%s \\n', 'scoreB = 0;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'stealVal = 2;');\r\nfprintf(fh, '%s \\n', 'catchVal = 2;');\r\nfprintf(fh, '%s \\n', 'shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'for i = 1: n;');\r\nfprintf(fh, '%s \\n', '    histA(end+1,1) = fhA(histA,  histB         );');\r\nfprintf(fh, '%s \\n', '    histB(end+1,1) = fhB(histB,  histA(1:end-1)); %modified one not sent!');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '    switch histA(end)');\r\nfprintf(fh, '%s \\n', '        case -1 %a steal');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + stealVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + catchVal;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'') ');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        case 0 %a share');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + stealVal;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + shareVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + shareVal;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        case 1 %a catch');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + catchVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        otherwise');\r\nfprintf(fh, '%s \\n', '            error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '');\r\nfclose(fh);\r\nfh=fopen('evil.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = evil(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = -1;');\r\nfclose(fh);\r\nfh=fopen('good.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = good(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0;');\r\nfclose(fh);\r\nfh=fopen('chaos.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = chaos(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = ceil(rand*3)-2;');\r\nfclose(fh);\r\nrehash path\r\n\r\n%%\r\n\r\na        = runPair(@StealShareCatch, @chaos);\r\na(end+1) = runPair(@StealShareCatch, @good);\r\na(end+1) = runPair(@StealShareCatch, @evil);\r\na(end+1) = runPair(@StealShareCatch, @doug)\r\nyourScore = sum(a)\r\n\r\nterribleScore   =     0; % works\r\nbadScore        = 23000; % good  strategy scores this\r\nokScore         = 26000; % evil  strategy scores this\r\ndecentScore     = 29000; % chaos strategy scores this\r\ngreatScore      = 42000; % doug  strategy scores this\r\n\r\n\r\nassert(yourScore \u003e terribleScore, 'Score: %d', yourScore)\r\n\r\nassert(yourScore \u003e badScore, 'Score: %d', yourScore)\r\n\r\nassert(yourScore \u003e okScore, 'Score: %d', yourScore)\r\n\r\nassert(yourScore \u003e decentScore, 'Score: %d', yourScore)\r\n\r\nassert(yourScore \u003e greatScore, 'Score: %d', yourScore)","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":79,"test_suite_updated_at":"2012-05-02T20:36:03.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-02T15:42:59.000Z","updated_at":"2025-06-28T09:34:20.000Z","published_at":"2012-05-02T19:40:23.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou, I, and a few other characters are going to play a game of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSteal, Share or Catch\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. We are going to play it 10,000 times vs. each of the characters.\u003c/w:t\u003e\u003c/w:r\u003e\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 rules of the game are this:\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\u003eThere are two points available each round\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\u003eWe will both choose to either Steal, Share, or Catch\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 we both choose Share, we both get one 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\u003eIf one chooses Steal and the other Share, the Stealer gets two points.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf one chooses Steal and the other Catch, the Catcher gets two points.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAny other combination, no one is awarded points.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou are to write an algorithm that will return either\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e-1: Steal\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\u003e0: Share\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1: Catch\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo help you make your choice, you will have a history vector that shows what your choices have been so far, and what the opponent's choices have been. These histories are in the form of:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[[-1\\n  1\\n  1\\n  0]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMeaning that the first round there was a Steal, then two Catches, then a share.\u003c/w:t\u003e\u003c/w:r\u003e\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 characters you will play against are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEvil (always steals)\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\u003eGood (always shares)\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\u003eChaos (randomly chooses)\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\u003eDoug (Something more complicated)\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eAs this problem runs, I will take the better entries and add them into the cast of characters that you play against. Maybe in a different Cody problem though.\u003c/w:t\u003e\u003c/w:r\u003e\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 scores to beat are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[terribleScore   =     0; % works\\nbadScore        = 23000; % good  strategy scores this\\nokScore         = 26000; % evil  strategy scores this\\ndecentScore     = 29000; % chaos strategy scores this\\ngreatScore      = 42000; % doug  strategy scores this]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf you can make a winning solution here, it might be added to the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/653-steal-share-or-catch-tournament-of-champions\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eTournament of Champions\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e version of this problem. E-mail me if you want yours added.\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":626,"title":"Make blocks of color","description":"Given a (Nx3) sequence of RGB colors, I want to create a (numRowBlocks x numColBlocks x 3) image comprising (blockSize x blockSize) blocks of those colors in a (numRowBlocks x numColBlocks) pattern.\r\n\r\ni.e. for this signature:\r\n  makeColorBlocks(blockSize, numColBlocks, numRowBlocks, RGBvec)\r\n\r\n(Using a weird RGB to make the point)\r\n\r\n    \u003e\u003e makeColorBlocks(2, 3, 2, [1 11 10;2 22 20; 3 33 30; 4 44 40; 5 55 50; 6 66 60])\r\n  \r\n  ans(:,:,1) =\r\n  \r\n      1    1    2    2    3    3\r\n      1    1    2    2    3    3\r\n      4    4    5    5    6    6\r\n      4    4    5    5    6    6\r\n  \r\n  \r\n  ans(:,:,2) =\r\n  \r\n     11   11   22   22   33   33\r\n     11   11   22   22   33   33\r\n     44   44   55   55   66   66\r\n     44   44   55   55   66   66\r\n  \r\n  \r\n  ans(:,:,3) =\r\n  \r\n     10   10   20   20   30   30\r\n     10   10   20   20   30   30\r\n     40   40   50   50   60   60\r\n     40   40   50   50   60   60\r\n\r\nThough it can not be mechanically graded as such, I am looking for easy to read an understand code.  Something easy to understand is preferred.  Thanks to \u003chttp://blogs.mathworks.com/pick/ Brett\u003e for the question.","description_html":"\u003cp\u003eGiven a (Nx3) sequence of RGB colors, I want to create a (numRowBlocks x numColBlocks x 3) image comprising (blockSize x blockSize) blocks of those colors in a (numRowBlocks x numColBlocks) pattern.\u003c/p\u003e\u003cp\u003ei.e. for this signature:\r\n  makeColorBlocks(blockSize, numColBlocks, numRowBlocks, RGBvec)\u003c/p\u003e\u003cp\u003e(Using a weird RGB to make the point)\u003c/p\u003e\u003cpre\u003e    \u003e\u003e makeColorBlocks(2, 3, 2, [1 11 10;2 22 20; 3 33 30; 4 44 40; 5 55 50; 6 66 60])\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eans(:,:,1) =\r\n\u003c/pre\u003e\u003cpre\u003e      1    1    2    2    3    3\r\n      1    1    2    2    3    3\r\n      4    4    5    5    6    6\r\n      4    4    5    5    6    6\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eans(:,:,2) =\r\n\u003c/pre\u003e\u003cpre\u003e     11   11   22   22   33   33\r\n     11   11   22   22   33   33\r\n     44   44   55   55   66   66\r\n     44   44   55   55   66   66\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eans(:,:,3) =\r\n\u003c/pre\u003e\u003cpre\u003e     10   10   20   20   30   30\r\n     10   10   20   20   30   30\r\n     40   40   50   50   60   60\r\n     40   40   50   50   60   60\u003c/pre\u003e\u003cp\u003eThough it can not be mechanically graded as such, I am looking for easy to read an understand code.  Something easy to understand is preferred.  Thanks to \u003ca href=\"http://blogs.mathworks.com/pick/\"\u003eBrett\u003c/a\u003e for the question.\u003c/p\u003e","function_template":"function img = makeColorBlocks(blockSize, numColBlocks, numRowBlocks, RGBvec)\r\n  img = 1;\r\nend","test_suite":"%%\r\nblockSize    = 2; \r\nnumColBlocks = 6; \r\nnumRowBlocks = 4;\r\nRGBvec = spring(numColBlocks*numRowBlocks)*255;\r\n\r\ny_correct(:,:,1) =[\r\n  255  255  255  255  255  255  255  255  255  255  255  255\r\n  255  255  255  255  255  255  255  255  255  255  255  255\r\n  255  255  255  255  255  255  255  255  255  255  255  255\r\n  255  255  255  255  255  255  255  255  255  255  255  255\r\n  255  255  255  255  255  255  255  255  255  255  255  255\r\n  255  255  255  255  255  255  255  255  255  255  255  255\r\n  255  255  255  255  255  255  255  255  255  255  255  255\r\n  255  255  255  255  255  255  255  255  255  255  255  255];\r\n\r\ny_correct(:,:,2) = [\r\n    0    0   11   11   22   22   33   33   44   44   55   55\r\n    0    0   11   11   22   22   33   33   44   44   55   55\r\n   67   67   78   78   89   89  100  100  111  111  122  122\r\n   67   67   78   78   89   89  100  100  111  111  122  122\r\n  133  133  144  144  155  155  166  166  177  177  188  188\r\n  133  133  144  144  155  155  166  166  177  177  188  188\r\n  200  200  211  211  222  222  233  233  244  244  255  255\r\n  200  200  211  211  222  222  233  233  244  244  255  255];\r\n\r\ny_correct(:,:,3) = [\r\n  255  255  244  244  233  233  222  222  211  211  200  200\r\n  255  255  244  244  233  233  222  222  211  211  200  200\r\n  188  188  177  177  166  166  155  155  144  144  133  133\r\n  188  188  177  177  166  166  155  155  144  144  133  133\r\n  122  122  111  111  100  100   89   89   78   78   67   67\r\n  122  122  111  111  100  100   89   89   78   78   67   67\r\n   55   55   44   44   33   33   22   22   11   11    0    0\r\n   55   55   44   44   33   33   22   22   11   11    0    0];\r\n\r\n\r\nassert(isequal(makeColorBlocks(blockSize, numColBlocks, numRowBlocks, RGBvec),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-26T14:21:49.000Z","updated_at":"2026-04-11T11:29:37.000Z","published_at":"2012-04-26T14:21:53.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a (Nx3) sequence of RGB colors, I want to create a (numRowBlocks x numColBlocks x 3) image comprising (blockSize x blockSize) blocks of those colors in a (numRowBlocks x numColBlocks) pattern.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ei.e. for this signature: makeColorBlocks(blockSize, numColBlocks, numRowBlocks, RGBvec)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(Using a weird RGB to make the point)\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[    \u003e\u003e makeColorBlocks(2, 3, 2, [1 11 10;2 22 20; 3 33 30; 4 44 40; 5 55 50; 6 66 60])\\n\\nans(:,:,1) =\\n\\n      1    1    2    2    3    3\\n      1    1    2    2    3    3\\n      4    4    5    5    6    6\\n      4    4    5    5    6    6\\n\\nans(:,:,2) =\\n\\n     11   11   22   22   33   33\\n     11   11   22   22   33   33\\n     44   44   55   55   66   66\\n     44   44   55   55   66   66\\n\\nans(:,:,3) =\\n\\n     10   10   20   20   30   30\\n     10   10   20   20   30   30\\n     40   40   50   50   60   60\\n     40   40   50   50   60   60]]\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\u003eThough it can not be mechanically graded as such, I am looking for easy to read an understand code. Something easy to understand is preferred. Thanks to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://blogs.mathworks.com/pick/\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eBrett\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e for the question.\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":621,"title":"Cryptomath: Addition","description":"    W A I T\r\n  +   A L L\r\n  ---------\r\n  G I F T S\r\n\r\nequals:\r\n\r\n    9 6 0 8\r\n  +   6 7 7\r\n  ---------\r\n  1 0 2 8 5\r\n\r\nGiven strings a,b,c find where a + b = c;  No left hand zeros.  All solutions are believed to be unique.\r\n\r\nBeware, the test machine might time out your entry!\r\n\r\nIf you want some easier problems that build up to this one, \r\n\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/641-make-a-random-non-repeating-vector random permutations of integers\u003e\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector binary comparisons\u003e\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/639-string-substitution-sub-problem-to-cryptomath string substitution\u003e \r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/642-convert-a-vector-into-a-number convert list of numbers to a scalar\u003e\r\n\r\nWhy are the above building blocks to solving this problem?  Well, let's think about the \u003chttp://c2.com/xp/DoTheSimplestThingThatCouldPossiblyWork.html simplest thing that could possibly work.\u003e\r\n\r\nIf we \r\n\r\n* Made random mapping of the ten or less characters to the ten digits\r\n* Converted the characters to a vector of numbers\r\n* Converted the vector of numbers to a scalar\r\n* Checked the scalars in the summation\r\n* Tried again if it did not work\r\n\r\nEventually, we would find the correct answer.  Worst case scenario, we have a one in 10! (1/3,600,000) chance of stumbling upon the answer.  For the eight character case, it is 8! (1/40,320).  I like those odds enough that it is worth trying.\r\n\r\nA \u003chttp://www.mathworks.com/matlabcentral/cody/problems/648-cumulative-probability-of-finding-an-unlikely-combination supplemental problem\u003e finds out which technique, methodical or random is better.","description_html":"\u003cpre\u003e    W A I T\r\n  +   A L L\r\n  ---------\r\n  G I F T S\u003c/pre\u003e\u003cp\u003eequals:\u003c/p\u003e\u003cpre\u003e    9 6 0 8\r\n  +   6 7 7\r\n  ---------\r\n  1 0 2 8 5\u003c/pre\u003e\u003cp\u003eGiven strings a,b,c find where a + b = c;  No left hand zeros.  All solutions are believed to be unique.\u003c/p\u003e\u003cp\u003eBeware, the test machine might time out your entry!\u003c/p\u003e\u003cp\u003eIf you want some easier problems that build up to this one,\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/641-make-a-random-non-repeating-vector\"\u003erandom permutations of integers\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\"\u003ebinary comparisons\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/639-string-substitution-sub-problem-to-cryptomath\"\u003estring substitution\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/642-convert-a-vector-into-a-number\"\u003econvert list of numbers to a scalar\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eWhy are the above building blocks to solving this problem?  Well, let's think about the \u003ca href=\"http://c2.com/xp/DoTheSimplestThingThatCouldPossiblyWork.html\"\u003esimplest thing that could possibly work.\u003c/a\u003e\u003c/p\u003e\u003cp\u003eIf we\u003c/p\u003e\u003cul\u003e\u003cli\u003eMade random mapping of the ten or less characters to the ten digits\u003c/li\u003e\u003cli\u003eConverted the characters to a vector of numbers\u003c/li\u003e\u003cli\u003eConverted the vector of numbers to a scalar\u003c/li\u003e\u003cli\u003eChecked the scalars in the summation\u003c/li\u003e\u003cli\u003eTried again if it did not work\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eEventually, we would find the correct answer.  Worst case scenario, we have a one in 10! (1/3,600,000) chance of stumbling upon the answer.  For the eight character case, it is 8! (1/40,320).  I like those odds enough that it is worth trying.\u003c/p\u003e\u003cp\u003eA \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/648-cumulative-probability-of-finding-an-unlikely-combination\"\u003esupplemental problem\u003c/a\u003e finds out which technique, methodical or random is better.\u003c/p\u003e","function_template":"function out = cryptoAdd(aStr,bStr,cStr)\r\n  aNum = 1;\r\n  bNum = 1;\r\n  cNum = 2;\r\n\r\nout = [aNum, bNum, cNum];\r\nend","test_suite":"%%\r\naStr = 'dan';\r\nbStr = 'nan';\r\ncStr = 'nora';\r\n\r\nout = [921 121 1042];\r\n\r\nassert(isequal(cryptoAdd(aStr,bStr,cStr),out))\r\n\r\n%%\r\naStr = 'wait';\r\nbStr = 'all';\r\ncStr = 'gifts';\r\n\r\nout = [9608 677 10285];\r\n\r\nassert(isequal(cryptoAdd(aStr,bStr,cStr),out))\r\n%%\r\naStr = 'memo';\r\nbStr = 'from';\r\ncStr = 'homer';\r\n\r\nout = [8485 7358 15843];\r\n\r\nassert(isequal(cryptoAdd(aStr,bStr,cStr),out))\r\n%%\r\n%aStr = 'coca';\r\n%bStr = 'cola';\r\n%cStr = 'oasis';\r\n\r\n%out = [8186 8106 16292];\r\n\r\n%assert(isequal(cryptoAdd(aStr,bStr,cStr),out))","published":true,"deleted":false,"likes_count":2,"comments_count":9,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":44,"test_suite_updated_at":"2012-04-25T19:43:33.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-25T16:00:11.000Z","updated_at":"2026-04-03T20:11:56.000Z","published_at":"2012-04-25T18:37:25.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    W A I T\\n  +   A L L\\n  ---------\\n  G I F T S]]\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\u003eequals:\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[    9 6 0 8\\n  +   6 7 7\\n  ---------\\n  1 0 2 8 5]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven strings a,b,c find where a + b = c; No left hand zeros. All solutions are believed to be unique.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eBeware, the test machine might time out your entry!\u003c/w:t\u003e\u003c/w:r\u003e\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 you want some easier problems that build up to this one,\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:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/641-make-a-random-non-repeating-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003erandom permutations of integers\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ebinary comparisons\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/639-string-substitution-sub-problem-to-cryptomath\\\"\u003e\u003cw:r\u003e\u003cw:t\u003estring substitution\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/642-convert-a-vector-into-a-number\\\"\u003e\u003cw:r\u003e\u003cw:t\u003econvert list of numbers to a scalar\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhy are the above building blocks to solving this problem? Well, let's think about the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://c2.com/xp/DoTheSimplestThingThatCouldPossiblyWork.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esimplest thing that could possibly work.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf we\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\u003eMade random mapping of the ten or less characters to the ten digits\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\u003eConverted the characters to a vector of numbers\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\u003eConverted the vector of numbers to a scalar\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\u003eChecked the scalars in the summation\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\u003eTried again if it did not work\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eEventually, we would find the correct answer. Worst case scenario, we have a one in 10! (1/3,600,000) chance of stumbling upon the answer. For the eight character case, it is 8! (1/40,320). I like those odds enough that it is worth trying.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/648-cumulative-probability-of-finding-an-unlikely-combination\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esupplemental problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e finds out which technique, methodical or random is better.\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":653,"title":"Steal, Share, or Catch: Tournament of Champions","description":"I am no longer supporting this problem.  No changes will be made to put more entries in the test suite, but have fun playing anyways!\r\n\r\n\r\n\u003chttp://www.mathworks.com/matlabcentral/cody/problems/650-steal-share-or-catch Steal, Share, or Catch\u003e is explained in the link.\r\n\r\nThis problem is the \"Tournament of Champions\".  If you make a passing entry in the original, from time to time I will move entries over to this Cody problem.  You will no longer be playing against only easy characters:\r\n\r\n* Good\r\n* Evil\r\n* Chaos\r\n* Doug\r\n\r\nYou will face\r\n\r\n* Vincent\r\n* Sean\r\n* James\r\n* Exploiter\r\n* Philipp\r\n* Bert\r\n* Amro\r\n\r\nExploiter recognizes the strategies of many of the above characters, and plays well against them.  \r\n\r\nIs this cheating?  Maybe, but \u003chttp://en.wikipedia.org/wiki/Security_through_obscurity#Arguments_against security through obscurity\u003e is questionable!  Take a look at Exploiter, it is the reference solution to this problem.\r\n\r\nI will update the test suite and cast of characters and winning score as we go.  I will try to keep making the test suite tougher so that only one/two entries can pass it at any given time.  It will be a matter of beating the test score more than getting lowest complexity!\r\n\r\n\r\nIf you made something and want to see it here, just call my attention to it.\r\n\r\nWinner is determined by score, not by length.  As of 6/28/2012 on my machine Amro is the current winner at 136K!","description_html":"\u003cp\u003eI am no longer supporting this problem.  No changes will be made to put more entries in the test suite, but have fun playing anyways!\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/650-steal-share-or-catch\"\u003eSteal, Share, or Catch\u003c/a\u003e is explained in the link.\u003c/p\u003e\u003cp\u003eThis problem is the \"Tournament of Champions\".  If you make a passing entry in the original, from time to time I will move entries over to this Cody problem.  You will no longer be playing against only easy characters:\u003c/p\u003e\u003cul\u003e\u003cli\u003eGood\u003c/li\u003e\u003cli\u003eEvil\u003c/li\u003e\u003cli\u003eChaos\u003c/li\u003e\u003cli\u003eDoug\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eYou will face\u003c/p\u003e\u003cul\u003e\u003cli\u003eVincent\u003c/li\u003e\u003cli\u003eSean\u003c/li\u003e\u003cli\u003eJames\u003c/li\u003e\u003cli\u003eExploiter\u003c/li\u003e\u003cli\u003ePhilipp\u003c/li\u003e\u003cli\u003eBert\u003c/li\u003e\u003cli\u003eAmro\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eExploiter recognizes the strategies of many of the above characters, and plays well against them.\u003c/p\u003e\u003cp\u003eIs this cheating?  Maybe, but \u003ca href = \"http://en.wikipedia.org/wiki/Security_through_obscurity#Arguments_against\"\u003esecurity through obscurity\u003c/a\u003e is questionable!  Take a look at Exploiter, it is the reference solution to this problem.\u003c/p\u003e\u003cp\u003eI will update the test suite and cast of characters and winning score as we go.  I will try to keep making the test suite tougher so that only one/two entries can pass it at any given time.  It will be a matter of beating the test score more than getting lowest complexity!\u003c/p\u003e\u003cp\u003eIf you made something and want to see it here, just call my attention to it.\u003c/p\u003e\u003cp\u003eWinner is determined by score, not by length.  As of 6/28/2012 on my machine Amro is the current winner at 136K!\u003c/p\u003e","function_template":"function choice = StealShareCatch(yourHist, theirHist)\r\n% This function will be called 10,000 times.\r\n% the hist vectors will start as [], and get longer each time through.\r\n%-1 steal\r\n% 0 share\r\n% 1 catch\r\n\r\n%stealVal = 2; What you get if you steal and they share\r\n%catchVal = 2; What you get if you catch and they steal\r\n%shareVal = 1; What you both get if both share\r\n%Otherwise no one gets anything!\r\n  choice = 0;\r\nend","test_suite":"% THIS IS A HACK TO GET CODE ON THE PATH\r\n% IGNORE THIS FIRST 'TEST'\r\n%\r\n%\r\nfh=fopen('doug.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = doug(histA, histB)');\r\nfprintf(fh, '%s \\n', '% A is self');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'memoryThresh = 10;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histB = [zeros(memoryThresh,1); histB];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'recentB = histB(end-(memoryThresh-1) : end);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'numStealB = nnz(recentB == -1);');\r\nfprintf(fh, '%s \\n', 'numShareB = nnz(recentB ==  0);');\r\nfprintf(fh, '%s \\n', 'numCatchB = nnz(recentB ==  1);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'percentStealB = (numStealB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentShareB = (numShareB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentCatchB = (numCatchB/memoryThresh);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0; %default to share');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            rollDice = rand;');\r\nfprintf(fh, '%s \\n', 'percentCatchStealers = 0.9;');\r\nfprintf(fh, '%s \\n', 'if (rollDice \u003c percentStealB)');\r\nfprintf(fh, '%s \\n', '    rollDice = rand;');\r\nfprintf(fh, '%s \\n', '    if (rollDice \u003c percentCatchStealers)');\r\nfprintf(fh, '%s \\n', '        out =  1; % catch');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        out = -1; % steal');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n\r\n%%\r\nfh=fopen('runPair.m','wt');\r\nfprintf(fh, '%s \\n', 'function [scoreA, scoreB] = runPair(fhA, fhB);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'n = 10000;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histA = [];');\r\nfprintf(fh, '%s \\n', 'histB = [];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'scoreA = 0;');\r\nfprintf(fh, '%s \\n', 'scoreB = 0;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'stealVal = 2;');\r\nfprintf(fh, '%s \\n', 'catchVal = 2;');\r\nfprintf(fh, '%s \\n', 'shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'for i = 1: n;');\r\nfprintf(fh, '%s \\n', '    histA(end+1,1) = fhA(histA,  histB         );');\r\nfprintf(fh, '%s \\n', '    histB(end+1,1) = fhB(histB,  histA(1:end-1)); %modified one not sent!');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '    switch histA(end)');\r\nfprintf(fh, '%s \\n', '        case -1 %a steal');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + stealVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + catchVal;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'') ');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        case 0 %a share');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + stealVal;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + shareVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + shareVal;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        case 1 %a catch');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + catchVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        otherwise');\r\nfprintf(fh, '%s \\n', '            error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '');\r\nfclose(fh);\r\n%%\r\nfh=fopen('evil.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = evil(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = -1;');\r\nfclose(fh);\r\n%%\r\nfh=fopen('good.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = good(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0;');\r\nfclose(fh);\r\n%%\r\nfh=fopen('chaos.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = chaos(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = ceil(rand*3)-2;');\r\nfclose(fh);\r\n%%\r\nfh=fopen('sean.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = sean(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '    if isempty(theirHist)');\r\nfprintf(fh, '%s \\n', '        [~,choice] = histc(rand,0:0.33:1);');\r\nfprintf(fh, '%s \\n', '        choice = choice-2;');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        [~, idx] = max(histc(theirHist,[-1 0 1]));');\r\nfprintf(fh, '%s \\n', '        choice = [1 0 -1];');\r\nfprintf(fh, '%s \\n', '        choice = choice(idx);');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('vincent.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = vincent(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', 'if all(theirHist == -1)');\r\nfprintf(fh, '%s \\n', 'choice = 1;');\r\nfprintf(fh, '%s \\n', 'elseif all(theirHist == 0);');\r\nfprintf(fh, '%s \\n', 'choice = -1;');\r\nfprintf(fh, '%s \\n', 'elseif all(theirHist == 1);');\r\nfprintf(fh, '%s \\n', 'choice = 1;');\r\nfprintf(fh, '%s \\n', 'else');\r\nfprintf(fh, '%s \\n', 'choice = 0;');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('james.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = james(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', 'if(length(theirHist)\u003c2)');\r\nfprintf(fh, '%s \\n', '  choice = 0;');\r\nfprintf(fh, '%s \\n', 'elseif( theirHist(end-1:end) == -1 )');\r\nfprintf(fh, '%s \\n', '  choice = 1;');\r\nfprintf(fh, '%s \\n', 'else');\r\nfprintf(fh, '%s \\n', '  choice = theirHist(end);');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('dougExploiter.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = dougExploiter(myHist, theirHist)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'threshID = 3;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if numel(myHist) \u003c threshID');\r\nfprintf(fh, '%s \\n', '    out = 0;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if     isGood(theirHist)');\r\nfprintf(fh, '%s \\n', '    out = -1;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'elseif isEvil(theirHist)');\r\nfprintf(fh, '%s \\n', '    out = 1;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', 'elseif isTitForTat(myHist, theirHist)');\r\nfprintf(fh, '%s \\n', '    switch myHist(end)');\r\nfprintf(fh, '%s \\n', '        case -1 %I stole so he wil steal');\r\nfprintf(fh, '%s \\n', '            out =  1; %catch');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        case  0 %I shared so he will share');\r\nfprintf(fh, '%s \\n', '            out = -1;');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        case  1 %I caught so he will catch');\r\nfprintf(fh, '%s \\n', '            out =  0; %Induce a share');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', 'elseif isChaos(theirHist)');\r\nfprintf(fh, '%s \\n', '    out = 1;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', '  ');\r\nfprintf(fh, '%s \\n', 'else %general unexploitable strategy');\r\nfprintf(fh, '%s \\n', '    out = dougGeneral(myHist, theirHist);');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'function flag = isGood(in)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'flag = all(in == 0);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'function flag = isEvil(in)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'flag = all(in == -1);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'function flag = isTitForTat(myHist, theirHist)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'window = 4;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if numel(myHist) \u003c window');\r\nfprintf(fh, '%s \\n', '    flag = false;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', 'else');\r\nfprintf(fh, '%s \\n', '    theirRecent = theirHist(end-(window-1):end);');\r\nfprintf(fh, '%s \\n', '       myRecent =    myHist(end-(window-1):end);');\r\nfprintf(fh, '%s \\n', '       ');\r\nfprintf(fh, '%s \\n', '    flag = isequal(myRecent(1:end-1), theirRecent(2:end));');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'function flag = isChaos(theirHist)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'num = numel(theirHist);');\r\nfprintf(fh, '%s \\n', 'perShare = nnz(theirHist ==  0)/num;');\r\nfprintf(fh, '%s \\n', 'perSteal = nnz(theirHist == -1)/num;');\r\nfprintf(fh, '%s \\n', 'perCatch = nnz(theirHist ==  1)/num;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'thresh = 0.05;');\r\nfprintf(fh, '%s \\n', 'target = 0.33;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'difference = [perShare perSteal perCatch] - target;');\r\nfprintf(fh, '%s \\n', 'flag = all(abs(difference) \u003c thresh);');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', 'function out = dougGeneral(histA, histB)');\r\nfprintf(fh, '%s \\n', 'memoryThresh = 10;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histB = [zeros(memoryThresh,1); histB];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'recentB = histB(end-(memoryThresh-1) : end);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'numStealB = nnz(recentB == -1);');\r\nfprintf(fh, '%s \\n', 'numShareB = nnz(recentB ==  0);');\r\nfprintf(fh, '%s \\n', 'numCatchB = nnz(recentB ==  1);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'percentStealB = (numStealB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentShareB = (numShareB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentCatchB = (numCatchB/memoryThresh);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0; %default to share');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            rollDice = rand;');\r\nfprintf(fh, '%s \\n', 'percentCatchStealers = 0.9;');\r\nfprintf(fh, '%s \\n', 'if (rollDice \u003c percentStealB)');\r\nfprintf(fh, '%s \\n', '    rollDice = rand;');\r\nfprintf(fh, '%s \\n', '    if (rollDice \u003c percentCatchStealers)');\r\nfprintf(fh, '%s \\n', '        out =  1; % catch');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        out = -1; % steal');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '    ');\r\nfclose(fh);\r\n%%\r\nfh=fopen('JamesE.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = jamesE(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if length(theirHist)\u003e10');\r\nfprintf(fh, '%s \\n', '    [yourguess yourcounts]=hist(theirHist(end-9:end),-1:1);');\r\nfprintf(fh, '%s \\n', '    [countmax countval]=max(yourguess);');\r\nfprintf(fh, '%s \\n', '    yourpopguess=yourcounts(countval);');\r\nfprintf(fh, '%s \\n', '    if yourpopguess==-1');\r\nfprintf(fh, '%s \\n', '        choice=1;');\r\nfprintf(fh, '%s \\n', '    elseif yourpopguess==0');\r\nfprintf(fh, '%s \\n', '        choice=-1;');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        choice=floor(3*rand)-1;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'else');\r\nfprintf(fh, '%s \\n', '\tchoice=floor(3*rand)-1;');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('philipp.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = philipp(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histLength = numel(theirHist);');\r\nfprintf(fh, '%s \\n', 'window = histLength-1;');\r\nfprintf(fh, '%s \\n', 'if histLength \u003e 10');\r\nfprintf(fh, '%s \\n', '    window = randi([5 10]);');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', ' if isempty(yourHist)');\r\nfprintf(fh, '%s \\n', '     % No choices made yet');\r\nfprintf(fh, '%s \\n', '     choice = randi([-1 1]);');\r\nfprintf(fh, '%s \\n', ' else');\r\nfprintf(fh, '%s \\n', '     switch mode(theirHist(end-window:end))');\r\nfprintf(fh, '%s \\n', '         case -1');\r\nfprintf(fh, '%s \\n', '             choice = 1;');\r\nfprintf(fh, '%s \\n', '         case 0');\r\nfprintf(fh, '%s \\n', '             choice = -1;');\r\nfprintf(fh, '%s \\n', '         case 1');\r\nfprintf(fh, '%s \\n', '             choice = randi([0 1]);');\r\nfprintf(fh, '%s \\n', '         otherwise');\r\nfprintf(fh, '%s \\n', '             choice = 0;');\r\nfprintf(fh, '%s \\n', '     end');\r\nfprintf(fh, '%s \\n', ' end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('bert.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = bert(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', 'choice = -1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if numel(theirHist)\u003e2');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', '    %check for tit4Tat stratagy');\r\nfprintf(fh, '%s \\n', '    isTit4Tat = isequal(yourHist(end-2:end-1), theirHist(end-1:end));');\r\nfprintf(fh, '%s \\n', '    count=histc(theirHist,-1:1);');\r\nfprintf(fh, '%s \\n', '    stealPercent = count(1)/numel(theirHist);');\r\nfprintf(fh, '%s \\n', '    sharePercent = count(2)/numel(theirHist);');\r\nfprintf(fh, '%s \\n', '    catPercent = count(3)/numel(theirHist);');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', '    choice = -theirHist(end); %general behavior ');\r\nfprintf(fh, '%s \\n', '    if isTit4Tat %check for tit4tat');\r\nfprintf(fh, '%s \\n', '        switch yourHist(end)');\r\nfprintf(fh, '%s \\n', '        case -1 %he wil steal');\r\nfprintf(fh, '%s \\n', '            choice =  1; %catch');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        case  0 %he will share');\r\nfprintf(fh, '%s \\n', '            choice = -1;');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        case  1 %he will catch');\r\nfprintf(fh, '%s \\n', '            choice =  0;');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        end');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    if choice == -1 %dont steal if the last was catch');\r\nfprintf(fh, '%s \\n', '        choice = 0;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', '    if rand(1)\u003e0.9 %random behavior to pass exploiters test');\r\nfprintf(fh, '%s \\n', '     choice = 0;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', '    if stealPercent \u003e 0.7   %if they steal often, I catch     ');\r\nfprintf(fh, '%s \\n', '        choice = 1;');\r\nfprintf(fh, '%s \\n', '    elseif sharePercent \u003e0.7 %if they share often, I steal');\r\nfprintf(fh, '%s \\n', '        choice = -1;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    if numel(theirHist)\u003e9000 %for the last 1000 round, steal');\r\nfprintf(fh, '%s \\n', '        choice = 1;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('amro.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = amro(histA, histB)');\r\nfprintf(fh, '%s \\n', '\t% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '\t% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '\t%-1 steal');\r\nfprintf(fh, '%s \\n', '\t% 0 share');\r\nfprintf(fh, '%s \\n', '\t% 1 catch');\r\nfprintf(fh, '%s \\n', '\t');\r\nfprintf(fh, '%s \\n', '\tif rand\u003c0.01 || isempty(histB)\t% if starting (or flipCoin)');\r\nfprintf(fh, '%s \\n', '\t\t% flipCoin: random move or \"share\"');\r\nfprintf(fh, '%s \\n', '\t\tif rand\u003c0.925');\r\nfprintf(fh, '%s \\n', '\t\t\tout = randi([-1 1]);');\r\nfprintf(fh, '%s \\n', '\t\telse');\r\nfprintf(fh, '%s \\n', '\t\t\tout = -1;');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\telseif rand\u003c0.01\t\t\t\t% flipCoin');\r\nfprintf(fh, '%s \\n', '\t\t% repeat his last move');\r\nfprintf(fh, '%s \\n', '\t\tout = histB(end);');\r\nfprintf(fh, '%s \\n', '\telse');\r\nfprintf(fh, '%s \\n', '\t\t% in the first/last X moves (+flipCoin)');\r\nfprintf(fh, '%s \\n', '\t\tif rand \u003c 0.4 \u0026\u0026 numel(histB)\u003e9900');\r\nfprintf(fh, '%s \\n', '\t\t\tout = 1;\t% catch');\r\nfprintf(fh, '%s \\n', '\t\t\treturn');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\tif rand \u003c 0.1 \u0026\u0026 numel(histB)\u003c15');\r\nfprintf(fh, '%s \\n', '\t\t\tout = 1;\t% catch');\r\nfprintf(fh, '%s \\n', '\t\t\treturn');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% check if player B has been repeating my moves (tit4tat)');\r\nfprintf(fh, '%s \\n', '\t\tn = 2;');\r\nfprintf(fh, '%s \\n', '\t\tif rand \u003c 0.9 \u0026\u0026 numel(histA)\u003en');\r\nfprintf(fh, '%s \\n', '\t\t\tif isequal(histA(end-n:end-1), histB(end-n+1:end))');\r\nfprintf(fh, '%s \\n', '\t\t\t\t% predict his next move based on my previous move');\r\nfprintf(fh, '%s \\n', '\t\t\t\tout = [1 -1 0];');\r\nfprintf(fh, '%s \\n', '\t\t\t\tout = out( histB(end)+2 );');\r\nfprintf(fh, '%s \\n', '\t\t\t\treturn');\r\nfprintf(fh, '%s \\n', '\t\t\tend');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% frequency of moves over entire history of player B');\r\nfprintf(fh, '%s \\n', '\t\tfreq = histc(histB,-1:1) ./ numel(histB);');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% flipCoin: all history or last N only');\r\nfprintf(fh, '%s \\n', '\t\tmaxNum = randi([7 10]);');\r\nfprintf(fh, '%s \\n', '\t\tif rand\u003c0.98 \u0026\u0026 numel(histB)\u003emaxNum');\r\nfprintf(fh, '%s \\n', '\t\t\thistB = histB(end-maxNum+1:end);');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% most frequent move in possibly filtered history');\r\nfprintf(fh, '%s \\n', '\t\t%idx = mode(histB)+2;');\r\nfprintf(fh, '%s \\n', '\t\t[~,idx] = max( histc(histB,-1:1) );');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% counter move');\r\nfprintf(fh, '%s \\n', '\t\tout = [1 0 0];\t\t% steal-\u003ecatch, share-\u003eshare, catch-\u003eshare');\r\nfprintf(fh, '%s \\n', '\t\tif freq(2)\u003e0.7 \u0026\u0026 rand\u003c0.995, out(2) = -1; end\t% adjust if he shares alot');\r\nfprintf(fh, '%s \\n', '\t\tif freq(1)\u003e0.7 \u0026\u0026 rand\u003c0.995, out(3) = 1; end\t% adjust if he catches alot');\r\nfprintf(fh, '%s \\n', '\t\t%{');\r\nfprintf(fh, '%s \\n', '\t\tif rand \u003c freq(1)');\r\nfprintf(fh, '%s \\n', '\t\t\tout = [1 0 1];\t% steal-\u003ecatch, share-\u003eshare, catch-\u003ecatch');\r\nfprintf(fh, '%s \\n', '\t\telseif rand \u003c freq(2)');\r\nfprintf(fh, '%s \\n', '\t\t\tout = [1 -1 0];\t% steal-\u003ecatch, share-\u003esteal, catch-\u003eshare');\r\nfprintf(fh, '%s \\n', '\t\telse');\r\nfprintf(fh, '%s \\n', '\t\t\tout = [1 0 randi([0 1])];\t% steal-\u003ecatch, share-\u003esteal, catch-\u003erandom');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\t%}');\r\nfprintf(fh, '%s \\n', '\t\tout = out(idx);');\r\nfprintf(fh, '%s \\n', '\tend');\r\nfprintf(fh, '%s \\n', '\t');\r\nfprintf(fh, '%s \\n', '\t% check if I am repeating myself in the last N moves');\r\nfprintf(fh, '%s \\n', '\t%{');\r\nfprintf(fh, '%s \\n', '\tn = 50;');\r\nfprintf(fh, '%s \\n', '\tif numel(histA)\u003e=n \u0026\u0026 all(histA(end-n+1:end)==out)');\r\nfprintf(fh, '%s \\n', '\t\tout = randi([0 1]);');\r\nfprintf(fh, '%s \\n', '\tend');\r\nfprintf(fh, '%s \\n', '\t%}');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nrehash path\r\n%%\r\n\r\nfh = @StealShareCatch;\r\n\r\na        = runPair(fh, @chaos)\r\na(end+1) = runPair(fh, @evil)\r\na(end+1) = runPair(fh, @StealShareCatch)\r\na(end+1) = runPair(fh, @good)\r\na(end+1) = runPair(fh, @doug)\r\na(end+1) = runPair(fh, @sean)\r\na(end+1) = runPair(fh, @james)\r\na(end+1) = runPair(fh, @vincent)\r\na(end+1) = runPair(fh, @JamesE)\r\na(end+1) = runPair(fh, @philipp)\r\na(end+1) = runPair(fh, @bert)\r\na(end+1) = runPair(fh, @amro)\r\n\r\nyourScore = sum(a)\r\n\r\nScore =      0; % works\r\nScore =  80219; % Vincent\r\nScore =  84000; % Sean\r\nScore =  93000; % james\r\nScore = 104000; % doug\r\nScore = 118000; % JamesE\r\nScore = 120000; % stealShareCatch\r\nScore = 122000; % philipp\r\nScore = 125000; % bert\r\nScore = 135000; % amro\r\n\r\n\r\n\r\nassert(yourScore \u003e Score(end), 'Score: %d', yourScore)","published":true,"deleted":false,"likes_count":5,"comments_count":2,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":9,"test_suite_updated_at":"2012-07-10T13:37:29.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-03T17:58:45.000Z","updated_at":"2013-04-17T13:38:44.000Z","published_at":"2012-05-03T18:29:26.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eI am no longer supporting this problem. No changes will be made to put more entries in the test suite, but have fun playing anyways!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/650-steal-share-or-catch\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSteal, Share, or Catch\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is explained in the link.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis problem is the \\\"Tournament of Champions\\\". If you make a passing entry in the original, from time to time I will move entries over to this Cody problem. You will no longer be playing against only easy characters:\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\u003eGood\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\u003eEvil\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\u003eChaos\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\u003eDoug\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou will face\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\u003eVincent\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\u003eSean\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\u003eJames\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\u003eExploiter\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\u003ePhilipp\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\u003eBert\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\u003eAmro\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eExploiter recognizes the strategies of many of the above characters, and plays well against them.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIs this cheating? Maybe, but\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/Security_through_obscurity#Arguments_against\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esecurity through obscurity\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is questionable! Take a look at Exploiter, it is the reference solution to this problem.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eI will update the test suite and cast of characters and winning score as we go. I will try to keep making the test suite tougher so that only one/two entries can pass it at any given time. It will be a matter of beating the test score more than getting lowest complexity!\u003c/w:t\u003e\u003c/w:r\u003e\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 you made something and want to see it here, just call my attention to it.\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eWinner is determined by score, not by length. As of 6/28/2012 on my machine Amro is the current winner at 136K!\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:\"ml101\"","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:\"ml101\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"ml101\"","","\"","ml101","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007faf2bed4748\u003e":null,"#\u003cMathWorks::Search::Field:0x00007faf2bed46a8\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007faf2bed3b68\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007faf2bed49c8\u003e":1,"#\u003cMathWorks::Search::Field:0x00007faf2bed4928\u003e":50,"#\u003cMathWorks::Search::Field:0x00007faf2bed4888\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007faf2bed47e8\u003e":"tag:\"ml101\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007faf2bed47e8\u003e":"tag:\"ml101\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"cody-search","password":"78X075ddcV44","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"ml101\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"ml101\"","","\"","ml101","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007faf2bed4748\u003e":null,"#\u003cMathWorks::Search::Field:0x00007faf2bed46a8\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007faf2bed3b68\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007faf2bed49c8\u003e":1,"#\u003cMathWorks::Search::Field:0x00007faf2bed4928\u003e":50,"#\u003cMathWorks::Search::Field:0x00007faf2bed4888\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007faf2bed47e8\u003e":"tag:\"ml101\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007faf2bed47e8\u003e":"tag:\"ml101\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":647,"difficulty_rating":"easy"},{"id":646,"difficulty_rating":"easy"},{"id":640,"difficulty_rating":"easy-medium"},{"id":648,"difficulty_rating":"easy-medium"},{"id":641,"difficulty_rating":"easy-medium"},{"id":642,"difficulty_rating":"easy-medium"},{"id":601,"difficulty_rating":"easy-medium"},{"id":639,"difficulty_rating":"easy-medium"},{"id":602,"difficulty_rating":"easy-medium"},{"id":603,"difficulty_rating":"easy-medium"},{"id":645,"difficulty_rating":"easy-medium"},{"id":650,"difficulty_rating":"easy-medium"},{"id":626,"difficulty_rating":"medium"},{"id":621,"difficulty_rating":"medium-hard"},{"id":653,"difficulty_rating":"hard"}]}}