{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-06-25T00:23:38.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-06-25T00: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":42503,"title":"Generating random matrix with given probability mass function","description":"Inspired by \u003chttp://www.mathworks.com/matlabcentral/cody/problems/2356-simulating-the-selection-of-a-state-with-given-probabilities Problem 2356. Simulating the selection of a state with given probabilities\u003e, let's consider a similar yet more useful problem. Write a function\r\n\r\n                             x = rndsampling(m,n,prob)\r\n\r\nto generate an m-by-n matrix x, whose entries are drawn independently from integer symbols 1:numel(prob) according to the given probability mass function prob. Specifically, symbol k occurs with probability prob(k), k = 1, 2, ..., numel(prob), where all(prob\u003e0) == 1 and sum(prob) == 1.","description_html":"\u003cp\u003eInspired by \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/2356-simulating-the-selection-of-a-state-with-given-probabilities\"\u003eProblem 2356. Simulating the selection of a state with given probabilities\u003c/a\u003e, let's consider a similar yet more useful problem. Write a function\u003c/p\u003e\u003cpre\u003e                             x = rndsampling(m,n,prob)\u003c/pre\u003e\u003cp\u003eto generate an m-by-n matrix x, whose entries are drawn independently from integer symbols 1:numel(prob) according to the given probability mass function prob. Specifically, symbol k occurs with probability prob(k), k = 1, 2, ..., numel(prob), where all(prob\u0026gt;0) == 1 and sum(prob) == 1.\u003c/p\u003e","function_template":"function x = rndsampling(m,n,prob);\r\n  x = rand(m,n)\r\nend","test_suite":"%%\r\nrnd = sort(rand(randi([10,20]),1));\r\nprob = vertcat(rnd(1,:),diff(rnd,1,1),1-rnd(end,:));\r\nsz = [1 1e5;1e5 1;1e3 1e2;randi([100 200], 100, 2)];\r\nsz = sz(randi(size(sz,1)),:);\r\nx = rndsampling(sz(1),sz(2),prob);\r\nprob_est = histcounts(x,1:numel(prob)+1,'Normalization','probability').';\r\nerr = mean(abs(prob_est - prob))\r\nassert(err \u003c 0.005 \u0026\u0026 isequal(size(x),sz) \u0026\u0026 all(~isnan(x(:))));\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":132,"test_suite_updated_at":"2015-08-13T18:44:59.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-08-11T19:26:49.000Z","updated_at":"2026-05-14T19:22:17.000Z","published_at":"2015-08-11T19:26:49.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\u003eInspired by\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/2356-simulating-the-selection-of-a-state-with-given-probabilities\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 2356. Simulating the selection of a state with given probabilities\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, let's consider a similar yet more useful problem. Write a function\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 = rndsampling(m,n,prob)]]\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 generate an m-by-n matrix x, whose entries are drawn independently from integer symbols 1:numel(prob) according to the given probability mass function prob. Specifically, symbol k occurs with probability prob(k), k = 1, 2, ..., numel(prob), where all(prob\u0026gt;0) == 1 and sum(prob) == 1.\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":1288,"title":"Balanced Ternary Numbers: Easy as |, |-, |o","description":"This problem concerns the so-called \u003chttp://en.wikipedia.org/wiki/Balanced_ternary balanced ternary\u003e system for representing numbers. It is a Base 3 system in which the digits can be 1, 0, or -1. \r\n\r\nIn balanced ternary, the number 8 would be represented as 9 (or 3^2) minus 1 (or 3^0). Typographically we will use \"|\" for one, \"o\" for zero (that's a lower-case O), and \"-\" for negative one. So if the decimal input d is the number 8, the balanced ternary output is the string \"|o-\". Thus\r\n \r\n dec 8  =\u003e bt \"|o-\"\r\n\r\nHere are some more examples.\r\n\r\n dec 3  =\u003e bt \"|o\"\r\n dec 15 =\u003e bt \"|--o\"\r\n dec 52 =\u003e bt \"|-o-|\"\r\n \r\nGiven an integer d, return the string bt. Leading zeros should always be suppressed.","description_html":"\u003cp\u003eThis problem concerns the so-called \u003ca href = \"http://en.wikipedia.org/wiki/Balanced_ternary\"\u003ebalanced ternary\u003c/a\u003e system for representing numbers. It is a Base 3 system in which the digits can be 1, 0, or -1.\u003c/p\u003e\u003cp\u003eIn balanced ternary, the number 8 would be represented as 9 (or 3^2) minus 1 (or 3^0). Typographically we will use \"|\" for one, \"o\" for zero (that's a lower-case O), and \"-\" for negative one. So if the decimal input d is the number 8, the balanced ternary output is the string \"|o-\". Thus\u003c/p\u003e\u003cpre\u003e dec 8  =\u003e bt \"|o-\"\u003c/pre\u003e\u003cp\u003eHere are some more examples.\u003c/p\u003e\u003cpre\u003e dec 3  =\u003e bt \"|o\"\r\n dec 15 =\u003e bt \"|--o\"\r\n dec 52 =\u003e bt \"|-o-|\"\u003c/pre\u003e\u003cp\u003eGiven an integer d, return the string bt. Leading zeros should always be suppressed.\u003c/p\u003e","function_template":"function bt = balanced_ternary(d)\r\n  bt = 'o';\r\nend","test_suite":"%%\r\nd = 3;\r\nbt_correct = '|o';\r\nbt = balanced_ternary(d);\r\nassert(isequal(bt,bt_correct))\r\n\r\n%%\r\nd = 52;\r\nbt_correct = '|-o-|';\r\nbt = balanced_ternary(d);\r\nassert(isequal(bt,bt_correct))\r\n\r\n%%\r\nd = 182;\r\nbt_correct = '|-|-|-';\r\nbt = balanced_ternary(d);\r\nassert(isequal(bt,bt_correct))\r\n\r\n%%\r\nd = 26;\r\nbt_correct = '|oo-';\r\nbt = balanced_ternary(d);\r\nassert(isequal(bt,bt_correct))\r\n\r\n%%\r\nd = -5;\r\nbt_correct = '-||';\r\nbt = balanced_ternary(d);\r\nassert(isequal(bt,bt_correct))\r\n\r\n%%\r\nd = -164;\r\nbt_correct = '-|oo-|';\r\nbt = balanced_ternary(d);\r\nassert(isequal(bt,bt_correct))\r\n\r\n%%\r\nd = 512;\r\nbt_correct = '|-o|oo-';\r\nbt = balanced_ternary(d);\r\nassert(isequal(bt,bt_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":1,"created_by":7,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":84,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-02-21T23:26:14.000Z","updated_at":"2026-05-12T23:00:49.000Z","published_at":"2013-02-21T23:36: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\u003eThis problem concerns the so-called\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/Balanced_ternary\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ebalanced ternary\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e system for representing numbers. It is a Base 3 system in which the digits can be 1, 0, or -1.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn balanced ternary, the number 8 would be represented as 9 (or 3^2) minus 1 (or 3^0). Typographically we will use \\\"|\\\" for one, \\\"o\\\" for zero (that's a lower-case O), and \\\"-\\\" for negative one. So if the decimal input d is the number 8, the balanced ternary output is the string \\\"|o-\\\". Thus\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[ dec 8  =\u003e bt \\\"|o-\\\"]]\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\u003eHere are some more examples.\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[ dec 3  =\u003e bt \\\"|o\\\"\\n dec 15 =\u003e bt \\\"|--o\\\"\\n dec 52 =\u003e bt \\\"|-o-|\\\"]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an integer d, return the string bt. Leading zeros should always be suppressed.\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":1873,"title":"Break it up!  Break it up!","description":"You have N pennies.  Write a Matlab script that will reveal how many different ways you can break up those pennies.  For example, with 5 pennies, there are seven different ways you can divide them:\r\n\r\n* (1,1,1,1,1)\r\n* (2,1,1,1)\r\n* (2,2,1)\r\n* (3,2)\r\n* (3,1,1)\r\n* (4,1)\r\n* (5)\r\n\r\nThe order of the coins does not matter, so (2,2,1) is considered the same combination as (2,1,2).  You can assume that N will always be a positive integer.","description_html":"\u003cp\u003eYou have N pennies.  Write a Matlab script that will reveal how many different ways you can break up those pennies.  For example, with 5 pennies, there are seven different ways you can divide them:\u003c/p\u003e\u003cul\u003e\u003cli\u003e(1,1,1,1,1)\u003c/li\u003e\u003cli\u003e(2,1,1,1)\u003c/li\u003e\u003cli\u003e(2,2,1)\u003c/li\u003e\u003cli\u003e(3,2)\u003c/li\u003e\u003cli\u003e(3,1,1)\u003c/li\u003e\u003cli\u003e(4,1)\u003c/li\u003e\u003cli\u003e(5)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe order of the coins does not matter, so (2,2,1) is considered the same combination as (2,1,2).  You can assume that N will always be a positive integer.\u003c/p\u003e","function_template":"function y = partitions(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;y_correct = 1;assert(isequal(partitions(x),y_correct))\r\n%%\r\nx = 5;y_correct = 7;assert(isequal(partitions(x),y_correct))\r\n%%\r\nx = 50;y_correct = 204226;assert(isequal(partitions(x),y_correct))\r\n%%\r\nassert(isequal(partitions(partitions(partitions(partitions(5)))),476715857290));\r\n%%\r\nassert(isequal(partitions(partitions(partitions(6))),526823));\r\n%%\r\nassert(isequal(partitions(partitions(12)),10619863));\r\n%%\r\nassert(isequal(partitions(199),3646072432125))\r\n%%\r\nP=arrayfun(@(x) partitions(x),10:10:100);\r\ny_correct=[42 627 5604 37338 204226 966467 4087968 15796476 56634173 190569292];\r\nassert(all(isequal(P,y_correct)))","published":true,"deleted":false,"likes_count":4,"comments_count":4,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":93,"test_suite_updated_at":"2016-08-19T11:36:33.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-09-13T18:34:19.000Z","updated_at":"2026-05-12T22:59:52.000Z","published_at":"2013-09-13T18:34:19.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 have N pennies. Write a Matlab script that will reveal how many different ways you can break up those pennies. For example, with 5 pennies, there are seven different ways you can divide them:\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,1,1,1,1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(2,1,1,1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(2,2,1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(3,2)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(3,1,1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(4,1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(5)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe order of the coins does not matter, so (2,2,1) is considered the same combination as (2,1,2). You can assume that N will always be a positive integer.\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":50,"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-05-12T22:59:09.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\"}]}"}],"problem_search":{"problems":[{"id":42503,"title":"Generating random matrix with given probability mass function","description":"Inspired by \u003chttp://www.mathworks.com/matlabcentral/cody/problems/2356-simulating-the-selection-of-a-state-with-given-probabilities Problem 2356. Simulating the selection of a state with given probabilities\u003e, let's consider a similar yet more useful problem. Write a function\r\n\r\n                             x = rndsampling(m,n,prob)\r\n\r\nto generate an m-by-n matrix x, whose entries are drawn independently from integer symbols 1:numel(prob) according to the given probability mass function prob. Specifically, symbol k occurs with probability prob(k), k = 1, 2, ..., numel(prob), where all(prob\u003e0) == 1 and sum(prob) == 1.","description_html":"\u003cp\u003eInspired by \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/2356-simulating-the-selection-of-a-state-with-given-probabilities\"\u003eProblem 2356. Simulating the selection of a state with given probabilities\u003c/a\u003e, let's consider a similar yet more useful problem. Write a function\u003c/p\u003e\u003cpre\u003e                             x = rndsampling(m,n,prob)\u003c/pre\u003e\u003cp\u003eto generate an m-by-n matrix x, whose entries are drawn independently from integer symbols 1:numel(prob) according to the given probability mass function prob. Specifically, symbol k occurs with probability prob(k), k = 1, 2, ..., numel(prob), where all(prob\u0026gt;0) == 1 and sum(prob) == 1.\u003c/p\u003e","function_template":"function x = rndsampling(m,n,prob);\r\n  x = rand(m,n)\r\nend","test_suite":"%%\r\nrnd = sort(rand(randi([10,20]),1));\r\nprob = vertcat(rnd(1,:),diff(rnd,1,1),1-rnd(end,:));\r\nsz = [1 1e5;1e5 1;1e3 1e2;randi([100 200], 100, 2)];\r\nsz = sz(randi(size(sz,1)),:);\r\nx = rndsampling(sz(1),sz(2),prob);\r\nprob_est = histcounts(x,1:numel(prob)+1,'Normalization','probability').';\r\nerr = mean(abs(prob_est - prob))\r\nassert(err \u003c 0.005 \u0026\u0026 isequal(size(x),sz) \u0026\u0026 all(~isnan(x(:))));\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":132,"test_suite_updated_at":"2015-08-13T18:44:59.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-08-11T19:26:49.000Z","updated_at":"2026-05-14T19:22:17.000Z","published_at":"2015-08-11T19:26:49.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\u003eInspired by\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/2356-simulating-the-selection-of-a-state-with-given-probabilities\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 2356. Simulating the selection of a state with given probabilities\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, let's consider a similar yet more useful problem. Write a function\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 = rndsampling(m,n,prob)]]\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 generate an m-by-n matrix x, whose entries are drawn independently from integer symbols 1:numel(prob) according to the given probability mass function prob. Specifically, symbol k occurs with probability prob(k), k = 1, 2, ..., numel(prob), where all(prob\u0026gt;0) == 1 and sum(prob) == 1.\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":1288,"title":"Balanced Ternary Numbers: Easy as |, |-, |o","description":"This problem concerns the so-called \u003chttp://en.wikipedia.org/wiki/Balanced_ternary balanced ternary\u003e system for representing numbers. It is a Base 3 system in which the digits can be 1, 0, or -1. \r\n\r\nIn balanced ternary, the number 8 would be represented as 9 (or 3^2) minus 1 (or 3^0). Typographically we will use \"|\" for one, \"o\" for zero (that's a lower-case O), and \"-\" for negative one. So if the decimal input d is the number 8, the balanced ternary output is the string \"|o-\". Thus\r\n \r\n dec 8  =\u003e bt \"|o-\"\r\n\r\nHere are some more examples.\r\n\r\n dec 3  =\u003e bt \"|o\"\r\n dec 15 =\u003e bt \"|--o\"\r\n dec 52 =\u003e bt \"|-o-|\"\r\n \r\nGiven an integer d, return the string bt. Leading zeros should always be suppressed.","description_html":"\u003cp\u003eThis problem concerns the so-called \u003ca href = \"http://en.wikipedia.org/wiki/Balanced_ternary\"\u003ebalanced ternary\u003c/a\u003e system for representing numbers. It is a Base 3 system in which the digits can be 1, 0, or -1.\u003c/p\u003e\u003cp\u003eIn balanced ternary, the number 8 would be represented as 9 (or 3^2) minus 1 (or 3^0). Typographically we will use \"|\" for one, \"o\" for zero (that's a lower-case O), and \"-\" for negative one. So if the decimal input d is the number 8, the balanced ternary output is the string \"|o-\". Thus\u003c/p\u003e\u003cpre\u003e dec 8  =\u003e bt \"|o-\"\u003c/pre\u003e\u003cp\u003eHere are some more examples.\u003c/p\u003e\u003cpre\u003e dec 3  =\u003e bt \"|o\"\r\n dec 15 =\u003e bt \"|--o\"\r\n dec 52 =\u003e bt \"|-o-|\"\u003c/pre\u003e\u003cp\u003eGiven an integer d, return the string bt. Leading zeros should always be suppressed.\u003c/p\u003e","function_template":"function bt = balanced_ternary(d)\r\n  bt = 'o';\r\nend","test_suite":"%%\r\nd = 3;\r\nbt_correct = '|o';\r\nbt = balanced_ternary(d);\r\nassert(isequal(bt,bt_correct))\r\n\r\n%%\r\nd = 52;\r\nbt_correct = '|-o-|';\r\nbt = balanced_ternary(d);\r\nassert(isequal(bt,bt_correct))\r\n\r\n%%\r\nd = 182;\r\nbt_correct = '|-|-|-';\r\nbt = balanced_ternary(d);\r\nassert(isequal(bt,bt_correct))\r\n\r\n%%\r\nd = 26;\r\nbt_correct = '|oo-';\r\nbt = balanced_ternary(d);\r\nassert(isequal(bt,bt_correct))\r\n\r\n%%\r\nd = -5;\r\nbt_correct = '-||';\r\nbt = balanced_ternary(d);\r\nassert(isequal(bt,bt_correct))\r\n\r\n%%\r\nd = -164;\r\nbt_correct = '-|oo-|';\r\nbt = balanced_ternary(d);\r\nassert(isequal(bt,bt_correct))\r\n\r\n%%\r\nd = 512;\r\nbt_correct = '|-o|oo-';\r\nbt = balanced_ternary(d);\r\nassert(isequal(bt,bt_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":1,"created_by":7,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":84,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-02-21T23:26:14.000Z","updated_at":"2026-05-12T23:00:49.000Z","published_at":"2013-02-21T23:36: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\u003eThis problem concerns the so-called\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/Balanced_ternary\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ebalanced ternary\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e system for representing numbers. It is a Base 3 system in which the digits can be 1, 0, or -1.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn balanced ternary, the number 8 would be represented as 9 (or 3^2) minus 1 (or 3^0). Typographically we will use \\\"|\\\" for one, \\\"o\\\" for zero (that's a lower-case O), and \\\"-\\\" for negative one. So if the decimal input d is the number 8, the balanced ternary output is the string \\\"|o-\\\". Thus\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[ dec 8  =\u003e bt \\\"|o-\\\"]]\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\u003eHere are some more examples.\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[ dec 3  =\u003e bt \\\"|o\\\"\\n dec 15 =\u003e bt \\\"|--o\\\"\\n dec 52 =\u003e bt \\\"|-o-|\\\"]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an integer d, return the string bt. Leading zeros should always be suppressed.\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":1873,"title":"Break it up!  Break it up!","description":"You have N pennies.  Write a Matlab script that will reveal how many different ways you can break up those pennies.  For example, with 5 pennies, there are seven different ways you can divide them:\r\n\r\n* (1,1,1,1,1)\r\n* (2,1,1,1)\r\n* (2,2,1)\r\n* (3,2)\r\n* (3,1,1)\r\n* (4,1)\r\n* (5)\r\n\r\nThe order of the coins does not matter, so (2,2,1) is considered the same combination as (2,1,2).  You can assume that N will always be a positive integer.","description_html":"\u003cp\u003eYou have N pennies.  Write a Matlab script that will reveal how many different ways you can break up those pennies.  For example, with 5 pennies, there are seven different ways you can divide them:\u003c/p\u003e\u003cul\u003e\u003cli\u003e(1,1,1,1,1)\u003c/li\u003e\u003cli\u003e(2,1,1,1)\u003c/li\u003e\u003cli\u003e(2,2,1)\u003c/li\u003e\u003cli\u003e(3,2)\u003c/li\u003e\u003cli\u003e(3,1,1)\u003c/li\u003e\u003cli\u003e(4,1)\u003c/li\u003e\u003cli\u003e(5)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe order of the coins does not matter, so (2,2,1) is considered the same combination as (2,1,2).  You can assume that N will always be a positive integer.\u003c/p\u003e","function_template":"function y = partitions(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;y_correct = 1;assert(isequal(partitions(x),y_correct))\r\n%%\r\nx = 5;y_correct = 7;assert(isequal(partitions(x),y_correct))\r\n%%\r\nx = 50;y_correct = 204226;assert(isequal(partitions(x),y_correct))\r\n%%\r\nassert(isequal(partitions(partitions(partitions(partitions(5)))),476715857290));\r\n%%\r\nassert(isequal(partitions(partitions(partitions(6))),526823));\r\n%%\r\nassert(isequal(partitions(partitions(12)),10619863));\r\n%%\r\nassert(isequal(partitions(199),3646072432125))\r\n%%\r\nP=arrayfun(@(x) partitions(x),10:10:100);\r\ny_correct=[42 627 5604 37338 204226 966467 4087968 15796476 56634173 190569292];\r\nassert(all(isequal(P,y_correct)))","published":true,"deleted":false,"likes_count":4,"comments_count":4,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":93,"test_suite_updated_at":"2016-08-19T11:36:33.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-09-13T18:34:19.000Z","updated_at":"2026-05-12T22:59:52.000Z","published_at":"2013-09-13T18:34:19.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 have N pennies. Write a Matlab script that will reveal how many different ways you can break up those pennies. For example, with 5 pennies, there are seven different ways you can divide them:\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,1,1,1,1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(2,1,1,1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(2,2,1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(3,2)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(3,1,1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(4,1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(5)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe order of the coins does not matter, so (2,2,1) is considered the same combination as (2,1,2). You can assume that N will always be a positive integer.\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":50,"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-05-12T22:59:09.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\"}]}"}],"errors":[],"facets":[[{"value":"Randomness","count":4,"selected":true},{"value":"Combinatorics II","count":1,"selected":false},{"value":"Probability \u0026 Stats","count":1,"selected":false}],[{"value":"hard","count":4,"selected":true}]],"term":"difficulty_rating_bin:hard group:Randomness","page":1,"per_page":50,"sort":"map(difficulty_value,0,0,999) asc"}}