{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":2492,"title":"Factorions: Numbers that equal the sum of the factorials of their digits","description":"From Wikipedia: _A factorion is a natural number that equals the sum of the factorials of its decimal digits_\r\n\r\nFor example:\r\n\r\n2!=2\r\n\r\n1!+4!+5!=145\r\n\r\nWrite a function that returns true if a number is a factorion and false otherwise.\r\n\r\nAssume all numbers are of base 10.","description_html":"\u003cp\u003eFrom Wikipedia: \u003ci\u003eA factorion is a natural number that equals the sum of the factorials of its decimal digits\u003c/i\u003e\u003c/p\u003e\u003cp\u003eFor example:\u003c/p\u003e\u003cp\u003e2!=2\u003c/p\u003e\u003cp\u003e1!+4!+5!=145\u003c/p\u003e\u003cp\u003eWrite a function that returns true if a number is a factorion and false otherwise.\u003c/p\u003e\u003cp\u003eAssume all numbers are of base 10.\u003c/p\u003e","function_template":"function y = isFactorion(x)\r\n  y = num2str(x);\r\nend","test_suite":"%%\r\nx = 0;\r\ny_correct = 0;\r\nassert(isequal(isFactorion(x),y_correct))\r\n%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(isFactorion(x),y_correct))\r\n%%\r\nx = 2;\r\ny_correct = 1;\r\nassert(isequal(isFactorion(x),y_correct))\r\n%%\r\nx = 145;\r\ny_correct = 1;\r\nassert(isequal(isFactorion(x),y_correct))\r\n%%\r\nx = 666;\r\ny_correct = 0;\r\nassert(isequal(isFactorion(x),y_correct))\r\n%%\r\nx = 1729;\r\ny_correct = 0;\r\nassert(isequal(isFactorion(x),y_correct))\r\n%%\r\nx = 40585;\r\ny_correct = 1;\r\nassert(isequal(isFactorion(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":379,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":83,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-08-08T15:54:48.000Z","updated_at":"2026-03-04T02:46:13.000Z","published_at":"2014-08-08T15:55: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\u003eFrom Wikipedia:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA factorion is a natural number that equals the sum of the factorials of its decimal digits\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2!=2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1!+4!+5!=145\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that returns true if a number is a factorion and false otherwise.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssume all numbers are of base 10.\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":2491,"title":"Dudeney Numbers: Numbers which are the cube of their decimal sum","description":"From Wikipedia: \r\n_A Dudeney number is a positive integer that is a perfect cube such that the sum of its decimal digits is equal to the cube root of the number._\r\n\r\nFor example:\r\n\r\n512=(5+1+2)^3\r\n\r\n4913=(4+9+1+3)^3\r\n\r\n19683=(1+9+6+8+3)^3\r\n\r\nWrite a function that returns true if a number is a Dudeney number and false otherwise.\r\n\r\nAssume all numbers are of base 10.\r\n\r\nIf a number is negative, assume that only the leading digit carries the negative sign e.g. -4913 -\u003e (-4+9+1+3)^3","description_html":"\u003cp\u003eFrom Wikipedia:  \u003ci\u003eA Dudeney number is a positive integer that is a perfect cube such that the sum of its decimal digits is equal to the cube root of the number.\u003c/i\u003e\u003c/p\u003e\u003cp\u003eFor example:\u003c/p\u003e\u003cp\u003e512=(5+1+2)^3\u003c/p\u003e\u003cp\u003e4913=(4+9+1+3)^3\u003c/p\u003e\u003cp\u003e19683=(1+9+6+8+3)^3\u003c/p\u003e\u003cp\u003eWrite a function that returns true if a number is a Dudeney number and false otherwise.\u003c/p\u003e\u003cp\u003eAssume all numbers are of base 10.\u003c/p\u003e\u003cp\u003eIf a number is negative, assume that only the leading digit carries the negative sign e.g. -4913 -\u0026gt; (-4+9+1+3)^3\u003c/p\u003e","function_template":"function y = isDudenay(x)\r\n  s = num2str(x)';\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 10;\r\ny_correct = 0;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 21;\r\ny_correct = 0;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 99;\r\ny_correct = 0;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 512;\r\ny_correct = 1;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 666;\r\ny_correct = 0;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 1729;\r\ny_correct = 0;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 4913;\r\ny_correct = 1;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = -4913;\r\ny_correct = 0;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 5832;\r\ny_correct = 1;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 17576;\r\ny_correct = 1;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 19683;\r\ny_correct = 1;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 87539319;\r\ny_correct = 0;\r\nassert(isequal(isDudenay(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":379,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":78,"test_suite_updated_at":"2014-08-08T09:11:49.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-08-08T08:47:21.000Z","updated_at":"2026-03-04T14:07:40.000Z","published_at":"2014-08-08T09:11: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\u003eFrom Wikipedia: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA Dudeney number is a positive integer that is a perfect cube such that the sum of its decimal digits is equal to the cube root of the number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor 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\u003e512=(5+1+2)^3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4913=(4+9+1+3)^3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e19683=(1+9+6+8+3)^3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that returns true if a number is a Dudeney number and false otherwise.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssume all numbers are of base 10.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 a number is negative, assume that only the leading digit carries the negative sign e.g. -4913 -\u0026gt; (-4+9+1+3)^3\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":1673,"title":"Pandiagonal Prime Magic Square Verification","description":"Verify if an NxN matrix is a Pandiagonal Prime Magic Square.  \r\n\r\nRequired properties:\r\n\r\n  1) N^2 prime values ( No repeats, 1 is a non-prime )\r\n  2) Every row, column, diagonal, anti-diagonal, broken diagonals sum to same value\r\n3) Magic Constant is the sum of a row/column/diagonal\r\n\r\n\r\n*Input:* M  (Matrix NxN)\r\n\r\n*Output:* Magic Constant ( 0 if invalid )\r\n\r\n*Example:*\r\n\r\nm=[7 107 23 103;89 37 73 41;97 17 113 13;47 79 31 83]; Magic is 240\r\n\r\nRows;Columns; Diags 7+37+113+83, 107+73+13+47, 23+41+97+79, 103+89+17+31; \r\n\r\nAnti-Diag 103+73+17+47, 23+37+97+83, 107+89+13+31, 7+41+113+79\r\n\r\n*Related:*\r\n\r\n1) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1634-kurchan-square-evaluation-function Kurchan Evaluation\u003e has similar array processing\r\n\r\n2) Create Minimum Pandiagonal Prime Magic Squares (6:20) Bonus for 14","description_html":"\u003cp\u003eVerify if an NxN matrix is a Pandiagonal Prime Magic Square.\u003c/p\u003e\u003cp\u003eRequired properties:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e1) N^2 prime values ( No repeats, 1 is a non-prime )\r\n2) Every row, column, diagonal, anti-diagonal, broken diagonals sum to same value\r\n3) Magic Constant is the sum of a row/column/diagonal\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e M  (Matrix NxN)\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e Magic Constant ( 0 if invalid )\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample:\u003c/b\u003e\u003c/p\u003e\u003cp\u003em=[7 107 23 103;89 37 73 41;97 17 113 13;47 79 31 83]; Magic is 240\u003c/p\u003e\u003cp\u003eRows;Columns; Diags 7+37+113+83, 107+73+13+47, 23+41+97+79, 103+89+17+31;\u003c/p\u003e\u003cp\u003eAnti-Diag 103+73+17+47, 23+37+97+83, 107+89+13+31, 7+41+113+79\u003c/p\u003e\u003cp\u003e\u003cb\u003eRelated:\u003c/b\u003e\u003c/p\u003e\u003cp\u003e1) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1634-kurchan-square-evaluation-function\"\u003eKurchan Evaluation\u003c/a\u003e has similar array processing\u003c/p\u003e\u003cp\u003e2) Create Minimum Pandiagonal Prime Magic Squares (6:20) Bonus for 14\u003c/p\u003e","function_template":"function MagicConstant = pandiag(m)\r\n MagicConstant=1;\r\nend\r\n","test_suite":"%%\r\nm=magic(20);\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,0))\r\n%%\r\nm=[41 137 149 19 37 6427 6343 6277 6449 6353 131 211 397 281 431 6421 6329 6197 6271 6199\r\n557 29 367 59 173 5923 6121 6101 6163 6287 643 827 929 947 769 5897 6043 5623 5851 5791\r\n419 571 631 853 919 6053 5801 5783 5573 5387 859 1229 857 1201 1487 5689 5419 5749 5393 5227\r\n1061 1103 1231 661 1093 5323 5381 5231 5189 5273 1847 2293 1499 2281 1867 4789 4243 5059 4889 4787\r\n1249 1277 1423 1889 1997 5051 4951 4931 4241 4373 2239 2309 2069 2731 2377 4481 4483 4597 4159 4273\r\n241 337 607 683 773 6311 6203 5987 5869 5857 151 263 359 421 379 6317 6217 6067 6047 6011\r\n1039 1301 1553 1697 1759 5501 5569 4999 5101 4801 953 503 991 809 1163 5527 5647 5477 5413 5297\r\n1471 2087 2003 1871 2357 5077 4561 4603 4723 4357 1031 1429 1777 1523 1789 5441 4943 4637 4903 4517\r\n2647 3823 2381 3709 3593 3989 2713 4177 3461 3061 1861 2633 2113 2089 2819 4523 3851 4349 3761 3547\r\n3373 3253 3323 3583 3259 3347 3539 3343 3307 3391 2383 2221 2677 2741 2879 3917 4007 3677 3389 3491\r\n6379 6299 6113 6229 6079 89 181 313 239 311 6469 6373 6361 6491 6473 83 167 233 61 157\r\n5867 5683 5581 5563 5741 613 467 887 659 719 5953 6481 6143 6451 6337 587 389 409 347 223\r\n5651 5281 5653 5309 5023 821 1091 761 1117 1283 6091 5939 5879 5657 5591 457 709 727 937 1123\r\n4663 4217 5011 4229 4643 1721 2267 1451 1621 1723 5449 5407 5279 5849 5417 1187 1129 1279 1321 1237\r\n4271 4201 4441 3779 4133 2029 2027 1913 2351 2237 5261 5233 5087 4621 4513 1459 1559 1579 2269 2137\r\n6359 6247 6151 6089 6131 193 293 443 463 499 6269 6173 5903 5827 5737 199 307 523 641 653\r\n5557 6007 5519 5701 5347 983 863 1033 1097 1213 5471 5209 4957 4813 4751 1009 941 1511 1409 1709\r\n5479 5081 4733 4987 4721 1069 1567 1873 1607 1993 5039 4423 4507 4639 4153 1433 1949 1907 1787 2153\r\n4649 3877 4397 4421 3691 1987 2659 2161 2749 2963 3863 2687 4129 2801 2917 2521 3797 2333 3049 3449\r\n4127 4289 3833 3769 3631 2593 2503 2833 3121 3019 3137 3257 3187 2927 3251 3163 2971 3167 3203 3119];\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,65100))\r\n%%\r\nm=[5 73 127 137 53\r\n37 167 17 71 103\r\n83 101 13 67 131\r\n43 31 197 113 11\r\n227 23 41 7 97];\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,395))\r\n%%\r\nm=[191\t89\t397\t409\t43\t157\t311\r\n379\t103\t101\t491\t17\t313\t193\r\n317\t241\t109\t163\t439\t47\t281\r\n223\t383\t227\t107\t541\t37\t79\r\n331\t337\t7\t139\t167\t563\t53\r\n83\t347\t389\t277\t127\t307\t67\r\n73\t97\t367\t11\t263\t173\t613];\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,1597))\r\n%%\r\nm=[191\t89\t397\t409\t43\t157\t311\r\n379\t103\t101\t491\t17\t313\t193\r\n317\t241\t109\t163\t439\t47\t281\r\n223\t383\t227\t107\t541\t37\t79\r\n331\t337\t7\t139\t167\t3\t53\r\n83\t347\t389\t277\t127\t307\t67\r\n73\t97\t367\t11\t263\t173\t613];\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,0))\r\n%%\r\nm=magic(7);\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,0))\r\n\r\n\r\n\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":40,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-22T04:21:02.000Z","updated_at":"2026-03-02T16:07:10.000Z","published_at":"2013-06-22T06:02:47.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eVerify if an NxN matrix is a Pandiagonal Prime Magic Square.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRequired properties:\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^2 prime values ( No repeats, 1 is a non-prime )\\n2) Every row, column, diagonal, anti-diagonal, broken diagonals sum to same value\\n3) Magic Constant is the sum of a row/column/diagonal]]\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e M (Matrix NxN)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Magic Constant ( 0 if invalid )\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003em=[7 107 23 103;89 37 73 41;97 17 113 13;47 79 31 83]; Magic is 240\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRows;Columns; Diags 7+37+113+83, 107+73+13+47, 23+41+97+79, 103+89+17+31;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAnti-Diag 103+73+17+47, 23+37+97+83, 107+89+13+31, 7+41+113+79\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRelated:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1634-kurchan-square-evaluation-function\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eKurchan Evaluation\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e has similar array processing\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2) Create Minimum Pandiagonal Prime Magic Squares (6:20) Bonus for 14\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":2051,"title":"is the number happy?","description":"test is a given integer number is Happy of not?\r\nanswer 1 if yes or 0 is no","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: 51px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 25.5px; transform-origin: 407px 25.5px; 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: 146.5px 8px; transform-origin: 146.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003etest is a given integer number is Happy of not?\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: 78.5px 8px; transform-origin: 78.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eanswer 1 if yes or 0 is no\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function tf = ishappy(n)\r\n  tf='?';\r\nend","test_suite":"%%\r\nn = 10;\r\ny_correct = 1;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 1;\r\ny_correct = 1;\r\nassert(isequal(ishappy(n),n))\r\n%%\r\nn = 2;\r\ny_correct = 0;\r\nassert(isequal(ishappy(n),rem(n,2)))\r\n%%\r\nn = 31;\r\nassert(isequal(ishappy(n),rem(n,2)))\r\n%%\r\nn = 13;\r\ny_correct = 1;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 11;\r\ny_correct = 0;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 47;\r\ny_correct = 0;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 101;\r\ny_correct = 0;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 100;\r\ny_correct = 1;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 130;\r\ny_correct = 1;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 230;\r\ny_correct = 1;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 190;\r\ny_correct = 1;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 290;\r\ny_correct = 0;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 998;\r\ny_correct = 1;\r\nassert(isequal(ishappy(n),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":17471,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":77,"test_suite_updated_at":"2022-02-07T06:56:32.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-12-15T04:37:05.000Z","updated_at":"2026-01-09T18:26:15.000Z","published_at":"2013-12-15T05:19: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\u003etest is a given integer number is Happy of not?\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\u003eanswer 1 if yes or 0 is no\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":2721,"title":"Pandigital Factors (Based on Euler 491)","description":"A Pandigital Number is a number containing all of the digits from 0-9 inclusive, with the added stipulation that it does not have a leading zero.  Lower level pandigital numbers just contain the digits 0-X, where X is less than 9.\r\n\r\nWrite a MATLAB script that takes as input the number X, and another integer Y.  Determine how many pandigital numbers containing the digits 0-X are evenly divisible by Y.  For example, there are thirteen pandigital numbers containing 0-4 that are evenly divisible by 7:\r\n\r\n       43120\r\n       42301\r\n       41230\r\n       32410\r\n       31402\r\n       31024\r\n       30142\r\n       23401\r\n       24031\r\n       20314\r\n       14203\r\n       10234\r\n       10423\r\n\r\nThe number 03421 does not count.  Even though it contains all of the digits 0-4, it has a leading zero.  Therefore, the output of pandigit_factors(4,7) would be 13.  You do not need to output all of the numbers themselves, just how many of them there are.  Good luck!","description_html":"\u003cp\u003eA Pandigital Number is a number containing all of the digits from 0-9 inclusive, with the added stipulation that it does not have a leading zero.  Lower level pandigital numbers just contain the digits 0-X, where X is less than 9.\u003c/p\u003e\u003cp\u003eWrite a MATLAB script that takes as input the number X, and another integer Y.  Determine how many pandigital numbers containing the digits 0-X are evenly divisible by Y.  For example, there are thirteen pandigital numbers containing 0-4 that are evenly divisible by 7:\u003c/p\u003e\u003cpre\u003e       43120\r\n       42301\r\n       41230\r\n       32410\r\n       31402\r\n       31024\r\n       30142\r\n       23401\r\n       24031\r\n       20314\r\n       14203\r\n       10234\r\n       10423\u003c/pre\u003e\u003cp\u003eThe number 03421 does not count.  Even though it contains all of the digits 0-4, it has a leading zero.  Therefore, the output of pandigit_factors(4,7) would be 13.  You do not need to output all of the numbers themselves, just how many of them there are.  Good luck!\u003c/p\u003e","function_template":"function pf = pandigit_factors(x,y)\r\n  pf=x*y;\r\nend","test_suite":"%%\r\nx = 4;y=7;\r\ny_correct = 13;\r\nassert(isequal(pandigit_factors(x,y),y_correct));\r\n%%\r\nx = 3;y=3;\r\ny_correct = 18;\r\nassert(isequal(pandigit_factors(x,y),y_correct));\r\n%%\r\nx = 8;y=8;\r\ny_correct = 45360;\r\nassert(isequal(pandigit_factors(x,y),y_correct));\r\n%%\r\nj=[600 312 600 144 216 312 75 74 0 120 0 144 55];\r\nx=5;y=ceil(13*rand)\r\nassert(isequal(pandigit_factors(x,y),j(y)));\r\n%%\r\nx=1;y=10;\r\nassert(isequal(pandigit_factors(x,y),x));","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":41,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-12-05T17:20:24.000Z","updated_at":"2025-11-30T01:34:22.000Z","published_at":"2014-12-05T17:20:24.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA Pandigital Number is a number containing all of the digits from 0-9 inclusive, with the added stipulation that it does not have a leading zero. Lower level pandigital numbers just contain the digits 0-X, where X is less than 9.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a MATLAB script that takes as input the number X, and another integer Y. Determine how many pandigital numbers containing the digits 0-X are evenly divisible by Y. For example, there are thirteen pandigital numbers containing 0-4 that are evenly divisible by 7:\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[       43120\\n       42301\\n       41230\\n       32410\\n       31402\\n       31024\\n       30142\\n       23401\\n       24031\\n       20314\\n       14203\\n       10234\\n       10423]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe number 03421 does not count. Even though it contains all of the digits 0-4, it has a leading zero. Therefore, the output of pandigit_factors(4,7) would be 13. You do not need to output all of the numbers themselves, just how many of them there are. Good luck!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":2319,"title":"Pandigital number n°1 (Inspired by Project Euler 32)","description":"A little warm-up to begin...\r\n\r\nAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE.\r\n\r\nFor example, the 5-digit number 15234, is 1 through 5 pandigital.\r\n\r\nGiven a positive integer find whether it is a pandigital number.\r\n\r\n","description_html":"\u003cp\u003eA little warm-up to begin...\u003c/p\u003e\u003cp\u003eAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE.\u003c/p\u003e\u003cp\u003eFor example, the 5-digit number 15234, is 1 through 5 pandigital.\u003c/p\u003e\u003cp\u003eGiven a positive integer find whether it is a pandigital number.\u003c/p\u003e","function_template":"function flag = is_pandigital(x)\r\nflag=2;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = true;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 0;\r\ny_correct = false;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 100;\r\ny_correct = false;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 123;\r\ny_correct = true;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 1203;\r\ny_correct = false;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 5432;\r\ny_correct = false;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 54321;\r\ny_correct = true;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 2361457879;\r\ny_correct = false;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 1234567809;\r\ny_correct = false;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 987654321;\r\ny_correct = true;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":5390,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":114,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-05-13T22:49:33.000Z","updated_at":"2026-03-09T20:20:18.000Z","published_at":"2014-05-13T22:55:20.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA little warm-up to begin...\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\u003eAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE.\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\u003eFor example, the 5-digit number 15234, is 1 through 5 pandigital.\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 positive integer find whether it is a pandigital number.\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":1804,"title":"Fangs of a vampire number","description":"A vampire number is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\r\nat most one of x and y is divisible by 10;\r\nx and y have the same number of digits; and\r\nThe digits in v consist of the digits of x and y (including any repetitions).\r\nIf these conditions are met, x and y are known as \"fangs\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\r\nWrite a function that determines whether two numbers are fangs of a vampire number.\r\nSee also: 1825. Find all vampire fangs and 1826. Find vampire numbers.","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: 214.3px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 107.15px; transform-origin: 407px 107.15px; 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: 4.5px 8px; transform-origin: 4.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/1804-fangs-of-a-vampire-number/edit#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003evampire number\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: 326.5px 8px; transform-origin: 326.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 61.3px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: decimal; 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: 125px 8px; transform-origin: 125px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eat most one of x and y is divisible by 10;\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: 139.5px 8px; transform-origin: 139.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ex and y have the same number of digits; and\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: 224.5px 8px; transform-origin: 224.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe digits in v consist of the digits of x and y (including any repetitions).\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 375px 8px; transform-origin: 375px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf these conditions are met, x and y are known as \"fangs\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\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: 270px 8px; transform-origin: 270px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that determines whether two numbers are fangs of a vampire number.\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: 29.5px 8px; transform-origin: 29.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSee also:\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/1804-fangs-of-a-vampire-number/edit#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e1825. Find all vampire fangs\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: 14px 8px; transform-origin: 14px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/1804-fangs-of-a-vampire-number/edit#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e1826. Find vampire numbers\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function tf = are_fangs(x)\r\n  tf = false;\r\nend","test_suite":"%%\r\nx = 1; y = 1;\r\nassert(~are_fangs(x,y))\r\n\r\n%%\r\nx = 21; y = 60;\r\nassert(are_fangs(x,y))\r\n\r\n%%\r\nx = randi(9,1); y = randi([10 99],1);\r\nassert(~are_fangs(x,y))\r\n\r\n%%\r\nx = 15; y = 93;\r\nassert(are_fangs(x,y))\r\n\r\n%%\r\nx = randi(9,1)*10; y = randi(9,1)*10;\r\nassert(~are_fangs(x,y))\r\n\r\n%%\r\nx = 1; y = 1;\r\nassert(~are_fangs(x,y))\r\n\r\n%%\r\nx = 35; y = 41;\r\nassert(are_fangs(x,y))\r\n\r\n%%\r\nx = 150; y=930;\r\nassert(~are_fangs(x,y))\r\n\r\n%%\r\nx = 300; y = 501;\r\nassert(are_fangs(x,y))","published":true,"deleted":false,"likes_count":5,"comments_count":4,"created_by":1011,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":105,"test_suite_updated_at":"2021-11-06T10:47:07.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-08-14T04:31:10.000Z","updated_at":"2026-03-02T17:11:58.000Z","published_at":"2013-08-14T04:37:10.000Z","restored_at":"2022-02-16T22:10:22.000Z","restored_by":null,"spam":false,"simulink":false,"admin_reviewed":true,"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\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=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003evampire number\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eat most one of x and y is divisible by 10;\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex and y have the same number of digits; and\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe digits in v consist of the digits of x and y (including any repetitions).\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\u003eIf these conditions are met, x and y are known as \\\"fangs\\\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\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\u003eWrite a function that determines whether two numbers are fangs of a vampire number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSee also:\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\u003e1825. Find all vampire fangs\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\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\u003e1826. Find vampire numbers\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\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":2320,"title":"Pandigital number n°2 (Inspired by Project Euler 32)","description":"After Problem 2319.\r\nAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE.\r\nFor example, the 5-digit number 15234, is 1 through 5 pandigital.\r\nFind the number of pandigital numbers in a given interval [xlower,xupper] (inclusive if it is not explicit enough).\r\nThe test suite is simple here, but how to compute this number with BIG interval (pandigital number length \u003e 7) in Cody time?\r\nFor example, between 58755 and 99899923?","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: 192px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 96px; transform-origin: 407px 96px; 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: 15px 8px; transform-origin: 15px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAfter\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 2319\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: 2px 8px; transform-origin: 2px 8px; 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: 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: 257px 8px; transform-origin: 257px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE.\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: 204.5px 8px; transform-origin: 204.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, the 5-digit number 15234, is 1 through 5 pandigital.\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: 343px 8px; transform-origin: 343px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFind the number of pandigital numbers in a given interval [xlower,xupper] (inclusive if it is not explicit enough).\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 370.5px 8px; transform-origin: 370.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe test suite is simple here, but how to compute this number with BIG interval (pandigital number length \u0026gt; 7) in Cody time?\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: 143.5px 8px; transform-origin: 143.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, between 58755 and 99899923?\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = pandigital_nb(xlower, xupper)\r\n  y=xupper-xlower;\r\nend","test_suite":"%%\r\nxl = 1;\r\nxu = 10\r\ny_correct = 1;\r\nassert(isequal(pandigital_nb(xl,xu),y_correct))\r\n%%\r\nxl = 10;\r\nxu = 99;\r\ny_correct = 2;\r\nassert(isequal(pandigital_nb(xl,xu),y_correct))\r\n%%\r\nxl = 100;\r\nxu = 999;\r\ny_correct = 6;\r\nassert(isequal(pandigital_nb(xl,xu),y_correct))\r\n%%\r\nxl = 1000;\r\nxu = 9999;\r\ny_correct = 24;\r\nassert(isequal(pandigital_nb(xl,xu),y_correct))\r\n%%\r\nxl = 10000;\r\nxu = 99999;\r\ny_correct = 120;\r\nassert(isequal(pandigital_nb(xl,xu),y_correct))\r\n%%\r\nxl = 1;\r\nxu = 999;\r\ny_correct = 9;\r\nassert(isequal(pandigital_nb(xl,xu),y_correct))\r\n%%\r\nxl = 1;\r\nxu = 9999;\r\ny_correct = 33;\r\nassert(isequal(pandigital_nb(xl,xu),y_correct))\r\n%%\r\nxl = 100000;\r\nxu = 999999;\r\ny_correct = 720;\r\nassert(isequal(pandigital_nb(xl,xu),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":5390,"edited_by":223089,"edited_at":"2022-08-09T08:36:16.000Z","deleted_by":null,"deleted_at":null,"solvers_count":68,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-05-14T08:11:36.000Z","updated_at":"2026-03-10T00:41:57.000Z","published_at":"2014-05-14T08:12:54.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAfter\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\u003eProblem 2319\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE.\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\u003eFor example, the 5-digit number 15234, is 1 through 5 pandigital.\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\u003eFind the number of pandigital numbers in a given interval [xlower,xupper] (inclusive if it is not explicit enough).\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\u003eThe test suite is simple here, but how to compute this number with BIG interval (pandigital number length \u0026gt; 7) in Cody time?\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\u003eFor example, between 58755 and 99899923?\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":1697,"title":"Make a Pandiagonal Prime Magic Square: 11 x 11","description":"This Fun with Primes Challenge is to create a Pandiagonal Prime Magic Square of size 11x11 given eleven APk sequences with 10 constant offsets and 121 unique prime values.\r\n\r\n\r\nAn APk sequence is of the form P + offset(i) where P is a prime and i=1:11 with offset(1)=0 and offset(j)\u003eoffset(i), j\u003ei.\r\n\r\nA Pandiagonal Magic Square has all rows, columns, diagonals(including broken), and anti-diagonals(including broken) summing to the same value.\r\n\r\n*Input:* APk matrix (11,11)\r\n\r\n*Output:* Pandiagonal Matrix (11,11) \r\n\r\n*Algorithm:*\r\n\r\nThe 11x11 algorithm can be summarized as circular shift of rows to make all columns sum to the same goal value.  The goal value is the diagonal sum of the APk matrix. Use Knight moves +2 rows +1 column, with bottom to top wrap.\r\n\r\n  Detailed Methodolgy:\r\n  1) PS : Shift APk rows 2 thru 11 by 2*(row value)\r\n  2) First column of PS will be first column of P\r\n  3) P from PS row 1 : P(1,1)=PS(1,1), P(3,2)=PS(1,2) or P(delta Knight)=PS(row,next). The P(3,2) is 2 down and 1 over from P(1,1).\r\n  4) Repeat Knight moves starting at P(row,1) for the remaining rows.\r\n\r\n*Related Challenges:*\r\n\r\n1) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1673-pandiagonal-prime-magic-square-verification Pandiagonal Check\u003e\r\n\r\n2) Find 11x11 Pandiagonal 18191 APk set\r\n\r\n*Restrictions: No str2num or regexp (enforced as necessary)*  ","description_html":"\u003cp\u003eThis Fun with Primes Challenge is to create a Pandiagonal Prime Magic Square of size 11x11 given eleven APk sequences with 10 constant offsets and 121 unique prime values.\u003c/p\u003e\u003cp\u003eAn APk sequence is of the form P + offset(i) where P is a prime and i=1:11 with offset(1)=0 and offset(j)\u003eoffset(i), j\u003ei.\u003c/p\u003e\u003cp\u003eA Pandiagonal Magic Square has all rows, columns, diagonals(including broken), and anti-diagonals(including broken) summing to the same value.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e APk matrix (11,11)\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e Pandiagonal Matrix (11,11)\u003c/p\u003e\u003cp\u003e\u003cb\u003eAlgorithm:\u003c/b\u003e\u003c/p\u003e\u003cp\u003eThe 11x11 algorithm can be summarized as circular shift of rows to make all columns sum to the same goal value.  The goal value is the diagonal sum of the APk matrix. Use Knight moves +2 rows +1 column, with bottom to top wrap.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eDetailed Methodolgy:\r\n1) PS : Shift APk rows 2 thru 11 by 2*(row value)\r\n2) First column of PS will be first column of P\r\n3) P from PS row 1 : P(1,1)=PS(1,1), P(3,2)=PS(1,2) or P(delta Knight)=PS(row,next). The P(3,2) is 2 down and 1 over from P(1,1).\r\n4) Repeat Knight moves starting at P(row,1) for the remaining rows.\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eRelated Challenges:\u003c/b\u003e\u003c/p\u003e\u003cp\u003e1) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1673-pandiagonal-prime-magic-square-verification\"\u003ePandiagonal Check\u003c/a\u003e\u003c/p\u003e\u003cp\u003e2) Find 11x11 Pandiagonal 18191 APk set\u003c/p\u003e\u003cp\u003e\u003cb\u003eRestrictions: No str2num or regexp (enforced as necessary)\u003c/b\u003e\u003c/p\u003e","function_template":"function p = Pandiagonal_11(APk)\r\n  p=APk;\r\nend","test_suite":"%%\r\nAPk= [59 101 271 509 577 1291 1699 1877 2357 2999 3307 \r\n311 353 523 761 829 1543 1951 2129 2609 3251 3559 \r\n389 431 601 839 907 1621 2029 2207 2687 3329 3637 \r\n521 563 733 971 1039 1753 2161 2339 2819 3461 3769 \r\n599 641 811 1049 1117 1831 2239 2417 2897 3539 3847 \r\n911 953 1123 1361 1429 2143 2551 2729 3209 3851 4159 \r\n1109 1151 1321 1559 1627 2341 2749 2927 3407 4049 4357 \r\n1481 1523 1693 1931 1999 2713 3121 3299 3779 4421 4729 \r\n2099 2141 2311 2549 2617 3331 3739 3917 4397 5039 5347 \r\n2591 2633 2803 3041 3109 3823 4231 4409 4889 5531 5839 \r\n3371 3413 3583 3821 3889 4603 5011 5189 5669 6311 6619];\r\np = Pandiagonal_11(APk);\r\nassert(all(unique(p(:))==unique(APk(:))))\r\nrcs=sum([p p']);\r\nassert(all(rcs==trace(APk)))\r\n\r\npd=p;\r\npad=p;\r\nfor i=2:11\r\n pd(i,:)=circshift(p(i,:),[0 -i+1]);\r\n pad(i,:)=circshift(p(i,:),[0 i-1]);\r\nend\r\n\r\nrd=sum([pd pad]);\r\nassert(all(rd==trace(APk)))","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":"2013-07-09T19:42:44.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-07-05T21:43:45.000Z","updated_at":"2025-12-04T05:22:24.000Z","published_at":"2013-07-05T22:55: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 Fun with Primes Challenge is to create a Pandiagonal Prime Magic Square of size 11x11 given eleven APk sequences with 10 constant offsets and 121 unique prime values.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAn APk sequence is of the form P + offset(i) where P is a prime and i=1:11 with offset(1)=0 and offset(j)\u0026gt;offset(i), j\u0026gt;i.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 Pandiagonal Magic Square has all rows, columns, diagonals(including broken), and anti-diagonals(including broken) summing to the same value.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e APk matrix (11,11)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Pandiagonal Matrix (11,11)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eAlgorithm:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 11x11 algorithm can be summarized as circular shift of rows to make all columns sum to the same goal value. The goal value is the diagonal sum of the APk matrix. Use Knight moves +2 rows +1 column, with bottom to top wrap.\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[Detailed Methodolgy:\\n1) PS : Shift APk rows 2 thru 11 by 2*(row value)\\n2) First column of PS will be first column of P\\n3) P from PS row 1 : P(1,1)=PS(1,1), P(3,2)=PS(1,2) or P(delta Knight)=PS(row,next). The P(3,2) is 2 down and 1 over from P(1,1).\\n4) Repeat Knight moves starting at P(row,1) for the remaining rows.]]\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRelated Challenges:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1673-pandiagonal-prime-magic-square-verification\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePandiagonal Check\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2) Find 11x11 Pandiagonal 18191 APk set\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRestrictions: No str2num or regexp (enforced as necessary)\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":1477,"title":"Champernowne Constant","description":"The \u003chttp://en.wikipedia.org/wiki/Champernowne_constant Champernowne constant\u003e is a real number whose digits in decimal representation come from the concatenation of all consecutive positive integers starting from 1.\r\n\r\nThat is\r\n\r\n 0.1234567891011121314151617181920...\r\n\r\nThis constant is of interest because it can be understood to contain an encoding of any past, present or future information, because any given sequence of numbers can be shown to exist somewhere in the champernowne representation. \r\n\r\nReturn the nth digit of the champernowne constant. The function takes an array of position values and returns an array of digits corresponding to those positions. \r\n\r\nExamples:\r\n\r\n [1 2 3 4 5] returns [1 2 3 4 5]\r\n\r\n [10 11 12 13 14 15] returns [1 0 1 1 1 2]\r\n\r\n [188 289] returns [9 9] \r\n\r\nProblem 3)\r\nPrev: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1472 1472\u003e\r\nNext: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1478 1478\u003e","description_html":"\u003cp\u003eThe \u003ca href = \"http://en.wikipedia.org/wiki/Champernowne_constant\"\u003eChampernowne constant\u003c/a\u003e is a real number whose digits in decimal representation come from the concatenation of all consecutive positive integers starting from 1.\u003c/p\u003e\u003cp\u003eThat is\u003c/p\u003e\u003cpre\u003e 0.1234567891011121314151617181920...\u003c/pre\u003e\u003cp\u003eThis constant is of interest because it can be understood to contain an encoding of any past, present or future information, because any given sequence of numbers can be shown to exist somewhere in the champernowne representation.\u003c/p\u003e\u003cp\u003eReturn the nth digit of the champernowne constant. The function takes an array of position values and returns an array of digits corresponding to those positions.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre\u003e [1 2 3 4 5] returns [1 2 3 4 5]\u003c/pre\u003e\u003cpre\u003e [10 11 12 13 14 15] returns [1 0 1 1 1 2]\u003c/pre\u003e\u003cpre\u003e [188 289] returns [9 9] \u003c/pre\u003e\u003cp\u003eProblem 3)\r\nPrev: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1472\"\u003e1472\u003c/a\u003e\r\nNext: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1478\"\u003e1478\u003c/a\u003e\u003c/p\u003e","function_template":"function vy = gendigit_champernowne(vx)\r\n  vy = vx;\r\nend","test_suite":"%%\r\nx = [1 2 3 4 5];\r\ny_correct = [1 2 3 4 5];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx = [10 11 12 13 14 15];\r\ny_correct = [1 0 1 1 1 2];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx = [188 189];\r\ny_correct = [9 9];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx = 2887:3000;\r\ny_correct = '999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102';\r\nassert(isequal(sprintf('%d',gendigit_champernowne(2887:3000)),y_correct))\r\n\r\n%%\r\nx=[1000000 1000001 1000002];\r\ny_correct = [1 8 5];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx=[12000:12005];\r\ny_correct = [7     7     3     2     7     8];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx=[10000000 10000001 10000002];\r\ny_correct = [7 3 0];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx=[120000:120005];\r\ny_correct = [2     6     2     2     2     2];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx=[1200000:1200005];\r\ny_correct = [ 8     5     1     8     2     1];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx=[1200004:1200009];\r\ny_correct = [ 2     1     8     5     1     9];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx=[1200008:1200013];\r\ny_correct = [1     9      2     1     8     5];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx=[13000008:13000013];\r\ny_correct = [2     0     1     5     8     7];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx=[14000008:14000013];\r\ny_correct = [ 1     5     8     7     3     1];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":2,"created_by":11275,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":94,"test_suite_updated_at":"2013-05-02T00:27:45.000Z","rescore_all_solutions":false,"group_id":44,"created_at":"2013-04-30T14:25:37.000Z","updated_at":"2026-02-11T20:30:17.000Z","published_at":"2013-04-30T14:25:36.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe\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/Champernowne_constant\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eChampernowne constant\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is a real number whose digits in decimal representation come from the concatenation of all consecutive positive integers starting from 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\u003eThat 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[ 0.1234567891011121314151617181920...]]\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\u003eThis constant is of interest because it can be understood to contain an encoding of any past, present or future information, because any given sequence of numbers can be shown to exist somewhere in the champernowne representation.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the nth digit of the champernowne constant. The function takes an array of position values and returns an array of digits corresponding to those positions.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ [1 2 3 4 5] returns [1 2 3 4 5]\\n\\n [10 11 12 13 14 15] returns [1 0 1 1 1 2]\\n\\n [188 289] returns [9 9]]]\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\u003eProblem 3) Prev:\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/1472\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1472\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e Next:\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/1478\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1478\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1672,"title":"Leftovers?  Again?!","description":"I am thinking of a positive number X.  To determine what number I am thinking of, I will give you two 1xN vectors.  The first vector (V1) is several numbers, none of which will share a factor.  The second vector (V2) is the remainder of X when divided by each of the numbers in V1. Calculate what the lowest possible value of X can be given these criteria.  For example:\r\n\r\nV1 = [2 3] ; V2 = [1 2]\r\n\r\nwould give an X value of 5.  There are an infinite number of other values of X that would satisfy V1 and V2, but I want the lowest one.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20px; 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: normal; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"display: block; min-width: 0px; padding-top: 0px; transform-origin: 332px 82.5px; vertical-align: baseline; perspective-origin: 332px 82.5px; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; transform-origin: 309px 42px; white-space: pre-wrap; perspective-origin: 309px 42px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eI am thinking of a positive number X. To determine what number I am thinking of, I will give you two 1xN vectors. The first vector (V1) is several numbers, none of which will share a factor. The second vector (V2) is the remainder of X when divided by each of the numbers in V1. Calculate what the lowest possible value of X can be given these criteria. For example:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; transform-origin: 309px 10.5px; white-space: pre-wrap; perspective-origin: 309px 10.5px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eV1 = [2 3] ; V2 = [1 2]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; transform-origin: 309px 21px; white-space: pre-wrap; perspective-origin: 309px 21px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003ewould give an X value of 5. There are an infinite number of other values of X that would satisfy V1 and V2, but I want the lowest one.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function X = leftovers(n,a)\r\n X = pi;\r\nend","test_suite":"%!cp leftovers.m safe\r\n%!rm *.*\r\n%!mv safe leftovers.m\r\n%!rm @*\r\n\r\n% Clean user's function from some known jailbreaking mechanisms\r\nfid = fopen('leftovers.m');\r\nst = regexprep(char(fread(fid)'), '!', 'error(''No shell commands!''); %');\r\nst = regexprep(st, 'feval', 'error(''No fancy functions!''); %');\r\nst = regexprep(st, 'str2func', 'error(''No fancy functions!''); %');\r\nst = regexprep(st, 'regex', 'error(''No fancy functions!''); %');\r\nst = regexprep(st, 'system', 'error(''No shell commands!''); %');\r\nst = regexprep(st, 'dos', 'error(''No shell commands!''); %');\r\nst = regexprep(st, 'unix', 'error(''No shell commands!''); %');\r\nst = regexprep(st, 'perl', 'error(''No external languages commands!''); %');\r\nst = regexprep(st, 'java', 'error(''No external languages commands!''); %');\r\nst = regexprep(st, 'assert', 'error(''No overwriting!''); %');\r\nfclose(fid)\r\n\r\nfid = fopen('leftovers.m' , 'w');\r\nfwrite(fid,st);\r\nfclose(fid)\r\n%%\r\nV1 = [2 3] ; V2 = [1 2];; y_correct = 5; assert(isequal(leftovers(V1,V2),y_correct))\r\n%%\r\nV1=[3 5 7] ; V2=[1 2 3]; y_correct = 52; assert(isequal(leftovers(V1,V2),y_correct))\r\n%%\r\nV1=[3 4 5] ; V2=[2 3 1]; y_correct = 11; assert(isequal(leftovers(V1,V2),y_correct))\r\n%%\r\nV1=[4 9 25] ; V2=[3 2 7]; y_correct = 407; assert(isequal(leftovers(V1,V2),y_correct))\r\n%%\r\nV1=[9 10 77] ; V2=[1 2 69]; y_correct = 6922; assert(isequal(leftovers(V1,V2),y_correct))\r\n%%\r\na=primes(30);\r\nb=ceil(8*rand()+2)\r\nV1=a(1:b);V2=1:b;\r\ny_correct=[23 53 1523 29243 299513 4383593 188677703 5765999453];\r\nassert(isequal(leftovers(V1,V2),y_correct(b-2)))\r\n%%\r\nV1=[leftovers([6 35],[3 9]) leftovers([3 5 7],[1 3 1])];\r\nassert(isequal(leftovers(V1,V1-8),379))\r\n%%\r\n% Discourage the for x=1:inf loops\r\nV1=[74 93 145 161 209 221]; V2=[66 85 137 153 201 213];\r\ny_correct=7420738134802;\r\nassert(isequal(leftovers(V1,V2),y_correct))\r\n%%\r\n% Discourage the for x=1:inf loops\r\nV1=[17 82 111 155 203 247 253] ; V2=[11 50 68 95 124 150 154];\r\ny_correct=59652745309190;\r\nassert(isequal(leftovers(V1,V2),y_correct))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":10,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":32,"test_suite_updated_at":"2020-09-29T13:24:49.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-21T18:45:36.000Z","updated_at":"2025-11-22T17:35:45.000Z","published_at":"2013-06-21T18:45: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\u003eI am thinking of a positive number X. To determine what number I am thinking of, I will give you two 1xN vectors. The first vector (V1) is several numbers, none of which will share a factor. The second vector (V2) is the remainder of X when divided by each of the numbers in V1. Calculate what the lowest possible value of X can be given these criteria. For 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eV1 = [2 3] ; V2 = [1 2]\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\u003ewould give an X value of 5. There are an infinite number of other values of X that would satisfy V1 and V2, but I want the lowest one.\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":1825,"title":"Find all vampire fangs","description":"A vampire number is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\r\nat most one of x and y are divisible by 10;\r\nx and y have the same number of digits; and\r\nThe digits in v consist of the digits of x and y (including anyrepetitions).\r\nIf these conditions are met, x and y are known as \"fangs\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\r\nWrite a function that returns all the pairs of fangs for a given number. The output is a matrix in which each row is a pair; the values in the first row should be in increasing order. If it is not a vampire number, it will return empty arrays.\r\nExample:\r\ndisp(vampire_factor(125460))\r\n\r\n   204   615\r\n   246   510\r\nSee also:  Problem 1804. Fangs of a vampire number and and 1826. Find vampire numbers.","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: 379.033px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 406.5px 189.517px; transform-origin: 406.5px 189.517px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 21px; text-align: left; transform-origin: 383.5px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 5.025px 7.81667px; transform-origin: 5.025px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA\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=\"\"\u003evampire number\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: 307.642px 7.81667px; transform-origin: 307.642px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 61.3px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: decimal; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 390.5px 30.65px; transform-origin: 390.5px 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: 362.5px 10.2167px; text-align: left; transform-origin: 362.5px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 134.558px 7.81667px; transform-origin: 134.558px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eat most one of x and y are divisible by 10;\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: 362.5px 10.2167px; text-align: left; transform-origin: 362.5px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 142.933px 7.81667px; transform-origin: 142.933px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ex and y have the same number of digits; and\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: 362.5px 10.2167px; text-align: left; transform-origin: 362.5px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 228.358px 7.81667px; transform-origin: 228.358px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe digits in v consist of the digits of x and y (including anyrepetitions).\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 21px; text-align: left; transform-origin: 383.5px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 383.5px 7.81667px; transform-origin: 383.5px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf these conditions are met, x and y are known as \"fangs\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 21px; text-align: left; transform-origin: 383.5px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 383.5px 7.81667px; transform-origin: 383.5px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that returns all the pairs of fangs for a given number. The output is a matrix in which each row is a pair; the values in the first row should be in increasing order. If it is not a vampire number, it will return empty arrays.\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: 30.7083px 7.81667px; transform-origin: 30.7083px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.7333px; 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 40.8667px; transform-origin: 403.5px 40.8667px; 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: 109.433px 8.375px; tab-size: 4; transform-origin: 109.433px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003edisp(vampire_factor(125460))\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   204   615\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   246   510\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: 32.9417px 7.81667px; transform-origin: 32.9417px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSee also: \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=\"\"\u003eProblem 1804. Fangs of a vampire number\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: 27.9167px 7.81667px; transform-origin: 27.9167px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and and\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=\"\"\u003e1826. Find vampire numbers\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: 2.23333px 7.81667px; transform-origin: 2.23333px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = vampire_factor(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 125460;\r\nfactors = vampire_factor(x);\r\ncorrect_factors = [204   615; 246   510];\r\nassert(isequal(factors,correct_factors))\r\n\r\n%%\r\nx = 1827;\r\nfactors = vampire_factor(x);\r\ncorrect_factors = [21 87];\r\nassert(isequal(factors,correct_factors))\r\n\r\n%%\r\nx = 100;\r\nfactors = vampire_factor(x);\r\ncorrect_factors = [];\r\nassert(isequal(factors,correct_factors))\r\n\r\n%%\r\nx = 13078260;\r\nfactors = vampire_factor(x);\r\ncorrect_factors = [1620 8073; 1863 7020; 2070 6318];\r\nassert(isequal(factors,correct_factors))\r\n\r\n%%\r\nx = randi([125460+1 125500-1],1);\r\nfactors = vampire_factor(x);\r\ncorrect_factors = [];\r\nassert(isequal(factors,correct_factors))","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":1011,"edited_by":223089,"edited_at":"2024-12-08T11:25:13.000Z","deleted_by":null,"deleted_at":null,"solvers_count":77,"test_suite_updated_at":"2024-12-08T11:25:13.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-08-14T22:05:51.000Z","updated_at":"2026-03-02T17:50:35.000Z","published_at":"2013-08-14T22:07:02.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003evampire number\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eat most one of x and y are divisible by 10;\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex and y have the same number of digits; and\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe digits in v consist of the digits of x and y (including anyrepetitions).\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\u003eIf these conditions are met, x and y are known as \\\"fangs\\\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\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\u003eWrite a function that returns all the pairs of fangs for a given number. The output is a matrix in which each row is a pair; the values in the first row should be in increasing order. If it is not a vampire number, it will return empty arrays.\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\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[disp(vampire_factor(125460))\\n\\n   204   615\\n   246   510]]\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\u003eSee also: \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\u003eProblem 1804. Fangs of a vampire number\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and and\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\u003e1826. Find vampire numbers\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\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":2838,"title":"Optimum Egyptian Fractions","description":"Following problem was inspired by \u003chttp://www.mathworks.com/matlabcentral/cody/problems/2126-split-bread-like-the-pharaohs-egyptian-fractions-and-greedy-algorithm this problem\u003e and \u003chttp://www.mathworks.com/matlabcentral/cody/solutions/868356#comment_6542 that comment\u003e.\r\n\r\nGiven fraction numerator _A_ and denominator _B_, find denominators _C_ for \u003chttps://en.wikipedia.org/wiki/Egyptian_fraction Egyptian fraction\u003e. The goal of this problem is to minimize the sum of the list.\r\n\r\nExample:\r\n  \r\n   A = 16;\r\n   B = 63;\r\n   % 16/63 == 1/7 + 1/9\r\n   C = [7, 9];\r\n\r\n_C_ may be _[4, 252]_ or _[5, 19, 749, 640395]_ or _[5, 27, 63, 945]_ or _[6, 12, 252]_ or _[7, 9]_ or almost any else of infinite more other options. The best one is _[7, 9]_ with sum 16.\r\n\r\n* You may assume _A\u003cB_,\r\n* Your score will be based on sum of answers,\r\n* No cheating, please,\r\n* While greedy algorithm usually solves this problem, score may not be satisfying,\r\n* Class of inputs is double, but keep in mind it may change in the future - most likely to uint64. Preferred output class is uint64.\r\n* I'm open for proposals to improve test, i.e. verification of output which is far from perfect.","description_html":"\u003cp\u003eFollowing problem was inspired by \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/2126-split-bread-like-the-pharaohs-egyptian-fractions-and-greedy-algorithm\"\u003ethis problem\u003c/a\u003e and \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/solutions/868356#comment_6542\"\u003ethat comment\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven fraction numerator \u003ci\u003eA\u003c/i\u003e and denominator \u003ci\u003eB\u003c/i\u003e, find denominators \u003ci\u003eC\u003c/i\u003e for \u003ca href = \"https://en.wikipedia.org/wiki/Egyptian_fraction\"\u003eEgyptian fraction\u003c/a\u003e. The goal of this problem is to minimize the sum of the list.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e   A = 16;\r\n   B = 63;\r\n   % 16/63 == 1/7 + 1/9\r\n   C = [7, 9];\u003c/pre\u003e\u003cp\u003e\u003ci\u003eC\u003c/i\u003e may be \u003ci\u003e[4, 252]\u003c/i\u003e or \u003ci\u003e[5, 19, 749, 640395]\u003c/i\u003e or \u003ci\u003e[5, 27, 63, 945]\u003c/i\u003e or \u003ci\u003e[6, 12, 252]\u003c/i\u003e or \u003ci\u003e[7, 9]\u003c/i\u003e or almost any else of infinite more other options. The best one is \u003ci\u003e[7, 9]\u003c/i\u003e with sum 16.\u003c/p\u003e\u003cul\u003e\u003cli\u003eYou may assume \u003ci\u003eA\u0026lt;B\u003c/i\u003e,\u003c/li\u003e\u003cli\u003eYour score will be based on sum of answers,\u003c/li\u003e\u003cli\u003eNo cheating, please,\u003c/li\u003e\u003cli\u003eWhile greedy algorithm usually solves this problem, score may not be satisfying,\u003c/li\u003e\u003cli\u003eClass of inputs is double, but keep in mind it may change in the future - most likely to uint64. Preferred output class is uint64.\u003c/li\u003e\u003cli\u003eI'm open for proposals to improve test, i.e. verification of output which is far from perfect.\u003c/li\u003e\u003c/ul\u003e","function_template":"function C = egyptian(A,B)\r\n  A = uint64(A);\r\n  B = uint64(B);\r\n  C = idivide(A,B,'ceil'); % not likely\r\nend","test_suite":"%%\r\nA = 1;\r\nB = 4;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),4);\r\n%%\r\nA = 2;\r\nB = 6;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),3);\r\n%%\r\nA = 3;\r\nB = 7;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),59);\r\n%%\r\nA = 11;\r\nB = 30;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),11);\r\n%%\r\n% random\r\nfor k = 3:7;\r\n  C_min = unique(randi([2 30],1,k));\r\n  A = 0; B = 1;\r\n  for l = C_min\r\n    A = round((A*l + B)/gcd(l,B));\r\n    B = lcm(B,l);\r\n  end\r\n  C = egyptian(A,B);\r\n  fra = sum(1./double(C));\r\n  fra_correct = A/B;\r\n  assert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\n  fprintf('Choosen A: %d, B: %d\\nbased on random C: [%s\\b]\\n Sum of C: %d, best is %d or less\\n',A,B,sprintf(' %d,',C_min),sum(C),sum(C_min));\r\nend\r\n%%\r\nA = 2;\r\nB = 101;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),1212);\r\n%%\r\nA = 11;\r\nB = 28;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),11);\r\n%%\r\nA = 17;\r\nB = 24;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),15);\r\n%%\r\nA = 25;\r\nB = 36;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),16);\r\n%%\r\nA = 1805;\r\nB = 1806;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),55);\r\n%%\r\n\r\nA = 287;\r\nB = 396;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),49);\r\n%%\r\n% Scoring.\r\n% by courtesy of LY Cao\r\nfid = fopen('score.p','wb');\r\nfwrite(fid,sscanf('7630312E30307630302E30300008501CD77E9FB100000035000001110000018422762999A8C1DE50537BEE443F4D73651F830FC6C78ADFB7DF68DF98823F565884DC58E21C7E397E3D26E4FFEA9A0D83589ABB5C0B0B553B44CFD79C9B272D11DF1965AD538598E8319529727DF4C4CF36A6016DD7816544AE5A8F64C9B2D9D0C4B94DD5EDF14595CBFE3D402647499EA3D9D125AC927454ED85973BCD1AAEA536D5A6CDDCD78A0211E8179603FFE12E4AB0E4704EA195704428700BAE5C4DFD42FF1A8760EDF2721F9724498ECC9F957735E7A3CDB9630DB17DF92ACE8F486706020E0A8D022D14BC313879724760AE20D67F572DD85211E4BEA45CDF3E22976253F113AEA96C1FF907329E4BD429BCFC6331077DA21F05D791DA6ECCF680D2E23AC77DFCE5C1D9869D3098F5B89FF92A','%2x'));\r\nfclose(fid);\r\n% Those lists may be extended and scoring mechanism may be changed a bit\r\nlistA = [2 2 2  2  3 3 3 3  4  5   5  13 31  1805];\r\nlistB = [5 7 21 25 5 7 8 71 71 121 17 42 311 1806];\r\nS = 0;\r\ntry\r\n  for k = 1:numel(listA),\r\n    A = listA(k);\r\n    B = listB(k);\r\n    C = egyptian(A,B);\r\n    fra = sum(1./double(C));\r\n    fra_correct = A/B;\r\n    assert(~any(mod(C,1)) ...\r\n         \u0026\u0026 all(C\u003e1) ...\r\n         \u0026\u0026 isequal(sort(C),unique(C)) ...\r\n         \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\n    S = S + sum(C);\r\n  end\r\n  score(round(20*log10(double(S))));\r\ncatch\r\n  score(1e4);\r\n  error+1;\r\nend\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":12,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":20,"test_suite_updated_at":"2016-04-12T22:03:10.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-01-18T23:21:47.000Z","updated_at":"2025-11-29T19:57:57.000Z","published_at":"2016-04-11T13:38:12.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFollowing problem was inspired 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/2126-split-bread-like-the-pharaohs-egyptian-fractions-and-greedy-algorithm\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ethis problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\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/solutions/868356#comment_6542\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ethat comment\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 fraction numerator\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and denominator\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eB\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, find denominators\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eC\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for\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=\\\"https://en.wikipedia.org/wiki/Egyptian_fraction\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eEgyptian fraction\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. The goal of this problem is to minimize the sum of the list.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   A = 16;\\n   B = 63;\\n   % 16/63 == 1/7 + 1/9\\n   C = [7, 9];]]\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:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eC\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e may be\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[4, 252]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[5, 19, 749, 640395]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[5, 27, 63, 945]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[6, 12, 252]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[7, 9]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or almost any else of infinite more other options. The best one is\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[7, 9]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e with sum 16.\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\u003eYou may assume\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA\u0026lt;B\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour score will be based on sum of answers,\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\u003eNo cheating, please,\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\u003eWhile greedy algorithm usually solves this problem, score may not be satisfying,\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\u003eClass of inputs is double, but keep in mind it may change in the future - most likely to uint64. Preferred output class is uint64.\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\u003eI'm open for proposals to improve test, i.e. verification of output which is far from perfect.\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":2323,"title":"Pandigital number n°3 (Inspired by Project Euler 32)","description":"After Problem 2319 and 2320.\r\n\r\nAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE. For example, the 5-digit number 15234, is 1 through 5 pandigital.\r\n\r\nThe product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital ([391867254]).\r\n\r\nFind the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through n pandigital (n is given in input).\r\n\r\nHINT1: Some products can be obtained in more than one way so be sure to only include it once in your sum.\r\n\r\nHINT2: All in good time...  \r\n\r\n","description_html":"\u003cp\u003eAfter Problem 2319 and 2320.\u003c/p\u003e\u003cp\u003eAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE. For example, the 5-digit number 15234, is 1 through 5 pandigital.\u003c/p\u003e\u003cp\u003eThe product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital ([391867254]).\u003c/p\u003e\u003cp\u003eFind the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through n pandigital (n is given in input).\u003c/p\u003e\u003cp\u003eHINT1: Some products can be obtained in more than one way so be sure to only include it once in your sum.\u003c/p\u003e\u003cp\u003eHINT2: All in good time...\u003c/p\u003e","function_template":"function y = pandigital_sum(n)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 3;\r\ny_correct = [];\r\nassert(isequal(pandigital_sum(x),y_correct))\r\n%%\r\nx = 4;\r\ny_correct = 12;\r\nassert(isequal(pandigital_sum(x),y_correct))\r\n%%\r\nx = 5;\r\ny_correct = 52;\r\nassert(isequal(pandigital_sum(x),y_correct))\r\n%%\r\nx = 6;\r\ny_correct = 162;\r\nassert(isequal(pandigital_sum(x),y_correct))\r\n%%\r\nx = 7;\r\ny_correct = []; % Strange no ?\r\nassert(isequal(pandigital_sum(x),y_correct))\r\n\r\n%%\r\nx = 8;\r\ny_correct = 13458;\r\nassert(isequal(pandigital_sum(x),y_correct))\r\n\r\n\r\n%% You obtain the Project Euler n°32 solution with n=9\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":3,"created_by":5390,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":"2019-10-23T23:21:29.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-05-15T10:08:43.000Z","updated_at":"2025-12-19T11:41:31.000Z","published_at":"2014-05-15T10:20:54.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAfter Problem 2319 and 2320.\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\u003eAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE. For example, the 5-digit number 15234, is 1 through 5 pandigital.\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\u003eThe product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital ([391867254]).\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\u003eFind the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through n pandigital (n is given in input).\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\u003eHINT1: Some products can be obtained in more than one way so be sure to only include it once in your sum.\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\u003eHINT2: All in good time...\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":1826,"title":"Find vampire numbers","description":"A vampire number is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\r\nat most one of x and y are divisible by 10;\r\nx and y have the same number of digits; and\r\nThe digits in v consist of the digits of x and y (including anyrepetitions).\r\nIf these conditions are met, x and y are known as \"fangs\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\r\nWrite a function that returns all the vampire numbers in a given array. The output is a vector.\r\nExample: disp(find_vampire(1000:2000) 1260 1395 1435 1530 1827\r\nSee also:  Problem 1825. Find all vampire fangs and Problem 1804. Fangs of a vampire number.","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: 265.3px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 406.5px 132.65px; transform-origin: 406.5px 132.65px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 21px; text-align: left; transform-origin: 383.5px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 5.025px 7.81667px; transform-origin: 5.025px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA\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=\"\"\u003evampire number\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: 307.642px 7.81667px; transform-origin: 307.642px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 61.3px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: decimal; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 390.5px 30.65px; transform-origin: 390.5px 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: 362.5px 10.2167px; text-align: left; transform-origin: 362.5px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 134.558px 7.81667px; transform-origin: 134.558px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eat most one of x and y are divisible by 10;\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: 362.5px 10.2167px; text-align: left; transform-origin: 362.5px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 142.933px 7.81667px; transform-origin: 142.933px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ex and y have the same number of digits; and\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: 362.5px 10.2167px; text-align: left; transform-origin: 362.5px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 228.358px 7.81667px; transform-origin: 228.358px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe digits in v consist of the digits of x and y (including anyrepetitions).\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 21px; text-align: left; transform-origin: 383.5px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 383.5px 7.81667px; transform-origin: 383.5px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf these conditions are met, x and y are known as \"fangs\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\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.242px 7.81667px; transform-origin: 294.242px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that returns all the vampire numbers in a given array. The output is a vector.\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: 215.517px 7.81667px; transform-origin: 215.517px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample: disp(find_vampire(1000:2000) 1260 1395 1435 1530 1827\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: 32.9417px 7.81667px; transform-origin: 32.9417px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSee also: \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=\"\"\u003eProblem 1825. Find all vampire fangs\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: 13.9583px 7.81667px; transform-origin: 13.9583px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and\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=\"\"\u003eProblem 1804. Fangs of a vampire number\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: 2.23333px 7.81667px; transform-origin: 2.23333px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y =find_vampire(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nfiletext = fileread('find_vampire.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp') ...\r\n    || contains(filetext, '1260') || contains(filetext, 'intersect') ;\r\n%test case enhanced on 01-08-2024\r\n%intersect and the elements themselves were used to hard-code the problem\r\nassert(~illegal)\r\n\r\n%%\r\nx = 1000:2000;\r\nv = find_vampire(x);\r\nv_correct = [1260 1395 1435 1530 1827];\r\nassert(isequal(v,v_correct))\r\n\r\n%%\r\nx = 1:999;\r\nv = find_vampire(x);\r\nassert(isempty(v))\r\n\r\n%%\r\nx = reshape(2000:2999,100,[]);\r\nv = find_vampire(x);\r\nv_correct = 2187;\r\nassert(isequal(v,v_correct))\r\n\r\n%%\r\nx = [];\r\nv = find_vampire(x);\r\nassert(isempty(v))\r\n\r\n%%\r\nx = -2000:-1000;\r\nv = find_vampire(x);\r\nassert(isempty(v))\r\n\r\n%%\r\nx = 125000:125501;\r\nv = find_vampire(x);\r\nv_correct = [125248 125433 125460 125500];\r\nassert(isequal(v,v_correct))","published":true,"deleted":false,"likes_count":12,"comments_count":7,"created_by":1011,"edited_by":223089,"edited_at":"2024-08-01T16:28:29.000Z","deleted_by":null,"deleted_at":null,"solvers_count":394,"test_suite_updated_at":"2024-08-01T16:28:29.000Z","rescore_all_solutions":false,"group_id":8,"created_at":"2013-08-14T22:41:30.000Z","updated_at":"2026-02-15T13:30:53.000Z","published_at":"2013-08-14T22:42:12.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003evampire number\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eat most one of x and y are divisible by 10;\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex and y have the same number of digits; and\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe digits in v consist of the digits of x and y (including anyrepetitions).\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\u003eIf these conditions are met, x and y are known as \\\"fangs\\\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\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\u003eWrite a function that returns all the vampire numbers in a given array. The output is 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample: disp(find_vampire(1000:2000) 1260 1395 1435 1530 1827\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\u003eSee also: \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\u003eProblem 1825. Find all vampire fangs\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\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\u003eProblem 1804. Fangs of a vampire number\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\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":1394,"title":"Prime Ladders","description":"A \u003chttp://en.wikipedia.org/wiki/Word_ladder word ladder\u003e transforms one word to another by means of single-letter mutations. So COLD can become WARM like so (there are often multiple solutions):\r\n\r\n COLD\r\n CORD\r\n CARD\r\n WARD\r\n WARM\r\n\r\nA number ladder does much the same thing, changing one digit at a time. A *prime ladder* is a number ladder with the additional constraint that each element is a prime number. Here is a prime ladder that connects 757 and 139\r\n\r\n 757 \r\n 157\r\n 137\r\n 139\r\n\r\nGiven two numbers p1 and p2, construct a prime ladder column vector in which p1 is the first element, p2 is the last element, and each successive row differs by exactly one digit from the preceding element. \r\n\r\nTo restate the above example, consider\r\n\r\n p1 = 757\r\n p2 = 139\r\n\r\nfor which an acceptable answer is\r\n\r\n ladder = [757; 157; 137; 139]\r\n\r\nYou can assume that p1 and p2 contain the same number of digits. I am not looking for a unique answer. I will only check that the conditions of a prime ladder are met.\r\n\r\n","description_html":"\u003cp\u003eA \u003ca href = \"http://en.wikipedia.org/wiki/Word_ladder\"\u003eword ladder\u003c/a\u003e transforms one word to another by means of single-letter mutations. So COLD can become WARM like so (there are often multiple solutions):\u003c/p\u003e\u003cpre\u003e COLD\r\n CORD\r\n CARD\r\n WARD\r\n WARM\u003c/pre\u003e\u003cp\u003eA number ladder does much the same thing, changing one digit at a time. A \u003cb\u003eprime ladder\u003c/b\u003e is a number ladder with the additional constraint that each element is a prime number. Here is a prime ladder that connects 757 and 139\u003c/p\u003e\u003cpre\u003e 757 \r\n 157\r\n 137\r\n 139\u003c/pre\u003e\u003cp\u003eGiven two numbers p1 and p2, construct a prime ladder column vector in which p1 is the first element, p2 is the last element, and each successive row differs by exactly one digit from the preceding element.\u003c/p\u003e\u003cp\u003eTo restate the above example, consider\u003c/p\u003e\u003cpre\u003e p1 = 757\r\n p2 = 139\u003c/pre\u003e\u003cp\u003efor which an acceptable answer is\u003c/p\u003e\u003cpre\u003e ladder = [757; 157; 137; 139]\u003c/pre\u003e\u003cp\u003eYou can assume that p1 and p2 contain the same number of digits. I am not looking for a unique answer. I will only check that the conditions of a prime ladder are met.\u003c/p\u003e","function_template":"function ladder = prime_ladder(p1,p2)\r\n  ladder = 0;\r\nend","test_suite":"%%\r\n\r\np1 = 13;\r\np2 = 29;\r\nladder = prime_ladder(p1,p2);\r\n\r\nassert(all(isprime(ladder)))\r\nassert(iscolumn(ladder))\r\nassert(ladder(1)==p1)\r\nassert(ladder(end)==p2)\r\nassert(all(sum(diff(num2str(ladder))~=0,2)==1))\r\n\r\n%%\r\n\r\np1 = 389;\r\np2 = 269;\r\nladder = prime_ladder(p1,p2);\r\n\r\nassert(all(isprime(ladder)))\r\nassert(iscolumn(ladder))\r\nassert(ladder(1)==p1)\r\nassert(ladder(end)==p2)\r\nassert(all(sum(diff(num2str(ladder))~=0,2)==1))\r\n\r\n%%\r\n\r\np1 = 761;\r\np2 = 397;\r\nladder = prime_ladder(p1,p2);\r\n\r\nassert(all(isprime(ladder)))\r\nassert(iscolumn(ladder))\r\nassert(ladder(1)==p1)\r\nassert(ladder(end)==p2)\r\nassert(all(sum(diff(num2str(ladder))~=0,2)==1))\r\n\r\n%%\r\n\r\np1 = 983;\r\np2 = 239;\r\nladder = prime_ladder(p1,p2);\r\n\r\nassert(all(isprime(ladder)))\r\nassert(iscolumn(ladder))\r\nassert(ladder(1)==p1)\r\nassert(ladder(end)==p2)\r\nassert(all(sum(diff(num2str(ladder))~=0,2)==1))\r\n\r\n%%\r\n\r\np1 = 271;\r\np2 = 439;\r\nladder = prime_ladder(p1,p2);\r\n\r\nassert(all(isprime(ladder)))\r\nassert(iscolumn(ladder))\r\nassert(ladder(1)==p1)\r\nassert(ladder(end)==p2)\r\nassert(all(sum(diff(num2str(ladder))~=0,2)==1))\r\n\r\n%%\r\n\r\np1 = 877;\r\np2 = 733;\r\nladder = prime_ladder(p1,p2);\r\n\r\nassert(all(isprime(ladder)))\r\nassert(iscolumn(ladder))\r\nassert(ladder(1)==p1)\r\nassert(ladder(end)==p2)\r\nassert(all(sum(diff(num2str(ladder))~=0,2)==1))\r\n\r\n%%\r\n\r\np1 = 2267;\r\np2 = 1153;\r\nladder = prime_ladder(p1,p2);\r\n\r\nassert(all(isprime(ladder)))\r\nassert(iscolumn(ladder))\r\nassert(ladder(1)==p1)\r\nassert(ladder(end)==p2)\r\nassert(all(sum(diff(num2str(ladder))~=0,2)==1))\r\n","published":true,"deleted":false,"likes_count":10,"comments_count":3,"created_by":7,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":55,"test_suite_updated_at":"2013-03-27T21:24:26.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-03-26T22:51:16.000Z","updated_at":"2026-01-03T14:28:57.000Z","published_at":"2013-03-27T15:28:59.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA\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/Word_ladder\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eword ladder\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e transforms one word to another by means of single-letter mutations. So COLD can become WARM like so (there are often multiple solutions):\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[ COLD\\n CORD\\n CARD\\n WARD\\n WARM]]\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\u003eA number ladder does much the same thing, changing one digit at a time. A\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eprime ladder\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is a number ladder with the additional constraint that each element is a prime number. Here is a prime ladder that connects 757 and 139\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[ 757 \\n 157\\n 137\\n 139]]\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 two numbers p1 and p2, construct a prime ladder column vector in which p1 is the first element, p2 is the last element, and each successive row differs by exactly one digit from the preceding element.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 restate the above example, consider\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[ p1 = 757\\n p2 = 139]]\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\u003efor which an acceptable answer 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[ ladder = [757; 157; 137; 139]]]\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 can assume that p1 and p2 contain the same number of digits. I am not looking for a unique answer. I will only check that the conditions of a prime ladder are met.\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":2492,"title":"Factorions: Numbers that equal the sum of the factorials of their digits","description":"From Wikipedia: _A factorion is a natural number that equals the sum of the factorials of its decimal digits_\r\n\r\nFor example:\r\n\r\n2!=2\r\n\r\n1!+4!+5!=145\r\n\r\nWrite a function that returns true if a number is a factorion and false otherwise.\r\n\r\nAssume all numbers are of base 10.","description_html":"\u003cp\u003eFrom Wikipedia: \u003ci\u003eA factorion is a natural number that equals the sum of the factorials of its decimal digits\u003c/i\u003e\u003c/p\u003e\u003cp\u003eFor example:\u003c/p\u003e\u003cp\u003e2!=2\u003c/p\u003e\u003cp\u003e1!+4!+5!=145\u003c/p\u003e\u003cp\u003eWrite a function that returns true if a number is a factorion and false otherwise.\u003c/p\u003e\u003cp\u003eAssume all numbers are of base 10.\u003c/p\u003e","function_template":"function y = isFactorion(x)\r\n  y = num2str(x);\r\nend","test_suite":"%%\r\nx = 0;\r\ny_correct = 0;\r\nassert(isequal(isFactorion(x),y_correct))\r\n%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(isFactorion(x),y_correct))\r\n%%\r\nx = 2;\r\ny_correct = 1;\r\nassert(isequal(isFactorion(x),y_correct))\r\n%%\r\nx = 145;\r\ny_correct = 1;\r\nassert(isequal(isFactorion(x),y_correct))\r\n%%\r\nx = 666;\r\ny_correct = 0;\r\nassert(isequal(isFactorion(x),y_correct))\r\n%%\r\nx = 1729;\r\ny_correct = 0;\r\nassert(isequal(isFactorion(x),y_correct))\r\n%%\r\nx = 40585;\r\ny_correct = 1;\r\nassert(isequal(isFactorion(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":379,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":83,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-08-08T15:54:48.000Z","updated_at":"2026-03-04T02:46:13.000Z","published_at":"2014-08-08T15:55: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\u003eFrom Wikipedia:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA factorion is a natural number that equals the sum of the factorials of its decimal digits\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2!=2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1!+4!+5!=145\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that returns true if a number is a factorion and false otherwise.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssume all numbers are of base 10.\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":2491,"title":"Dudeney Numbers: Numbers which are the cube of their decimal sum","description":"From Wikipedia: \r\n_A Dudeney number is a positive integer that is a perfect cube such that the sum of its decimal digits is equal to the cube root of the number._\r\n\r\nFor example:\r\n\r\n512=(5+1+2)^3\r\n\r\n4913=(4+9+1+3)^3\r\n\r\n19683=(1+9+6+8+3)^3\r\n\r\nWrite a function that returns true if a number is a Dudeney number and false otherwise.\r\n\r\nAssume all numbers are of base 10.\r\n\r\nIf a number is negative, assume that only the leading digit carries the negative sign e.g. -4913 -\u003e (-4+9+1+3)^3","description_html":"\u003cp\u003eFrom Wikipedia:  \u003ci\u003eA Dudeney number is a positive integer that is a perfect cube such that the sum of its decimal digits is equal to the cube root of the number.\u003c/i\u003e\u003c/p\u003e\u003cp\u003eFor example:\u003c/p\u003e\u003cp\u003e512=(5+1+2)^3\u003c/p\u003e\u003cp\u003e4913=(4+9+1+3)^3\u003c/p\u003e\u003cp\u003e19683=(1+9+6+8+3)^3\u003c/p\u003e\u003cp\u003eWrite a function that returns true if a number is a Dudeney number and false otherwise.\u003c/p\u003e\u003cp\u003eAssume all numbers are of base 10.\u003c/p\u003e\u003cp\u003eIf a number is negative, assume that only the leading digit carries the negative sign e.g. -4913 -\u0026gt; (-4+9+1+3)^3\u003c/p\u003e","function_template":"function y = isDudenay(x)\r\n  s = num2str(x)';\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 10;\r\ny_correct = 0;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 21;\r\ny_correct = 0;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 99;\r\ny_correct = 0;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 512;\r\ny_correct = 1;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 666;\r\ny_correct = 0;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 1729;\r\ny_correct = 0;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 4913;\r\ny_correct = 1;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = -4913;\r\ny_correct = 0;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 5832;\r\ny_correct = 1;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 17576;\r\ny_correct = 1;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 19683;\r\ny_correct = 1;\r\nassert(isequal(isDudenay(x),y_correct))\r\n%%\r\nx = 87539319;\r\ny_correct = 0;\r\nassert(isequal(isDudenay(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":379,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":78,"test_suite_updated_at":"2014-08-08T09:11:49.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-08-08T08:47:21.000Z","updated_at":"2026-03-04T14:07:40.000Z","published_at":"2014-08-08T09:11: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\u003eFrom Wikipedia: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA Dudeney number is a positive integer that is a perfect cube such that the sum of its decimal digits is equal to the cube root of the number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor 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\u003e512=(5+1+2)^3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e4913=(4+9+1+3)^3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e19683=(1+9+6+8+3)^3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that returns true if a number is a Dudeney number and false otherwise.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssume all numbers are of base 10.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 a number is negative, assume that only the leading digit carries the negative sign e.g. -4913 -\u0026gt; (-4+9+1+3)^3\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":1673,"title":"Pandiagonal Prime Magic Square Verification","description":"Verify if an NxN matrix is a Pandiagonal Prime Magic Square.  \r\n\r\nRequired properties:\r\n\r\n  1) N^2 prime values ( No repeats, 1 is a non-prime )\r\n  2) Every row, column, diagonal, anti-diagonal, broken diagonals sum to same value\r\n3) Magic Constant is the sum of a row/column/diagonal\r\n\r\n\r\n*Input:* M  (Matrix NxN)\r\n\r\n*Output:* Magic Constant ( 0 if invalid )\r\n\r\n*Example:*\r\n\r\nm=[7 107 23 103;89 37 73 41;97 17 113 13;47 79 31 83]; Magic is 240\r\n\r\nRows;Columns; Diags 7+37+113+83, 107+73+13+47, 23+41+97+79, 103+89+17+31; \r\n\r\nAnti-Diag 103+73+17+47, 23+37+97+83, 107+89+13+31, 7+41+113+79\r\n\r\n*Related:*\r\n\r\n1) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1634-kurchan-square-evaluation-function Kurchan Evaluation\u003e has similar array processing\r\n\r\n2) Create Minimum Pandiagonal Prime Magic Squares (6:20) Bonus for 14","description_html":"\u003cp\u003eVerify if an NxN matrix is a Pandiagonal Prime Magic Square.\u003c/p\u003e\u003cp\u003eRequired properties:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e1) N^2 prime values ( No repeats, 1 is a non-prime )\r\n2) Every row, column, diagonal, anti-diagonal, broken diagonals sum to same value\r\n3) Magic Constant is the sum of a row/column/diagonal\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e M  (Matrix NxN)\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e Magic Constant ( 0 if invalid )\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample:\u003c/b\u003e\u003c/p\u003e\u003cp\u003em=[7 107 23 103;89 37 73 41;97 17 113 13;47 79 31 83]; Magic is 240\u003c/p\u003e\u003cp\u003eRows;Columns; Diags 7+37+113+83, 107+73+13+47, 23+41+97+79, 103+89+17+31;\u003c/p\u003e\u003cp\u003eAnti-Diag 103+73+17+47, 23+37+97+83, 107+89+13+31, 7+41+113+79\u003c/p\u003e\u003cp\u003e\u003cb\u003eRelated:\u003c/b\u003e\u003c/p\u003e\u003cp\u003e1) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1634-kurchan-square-evaluation-function\"\u003eKurchan Evaluation\u003c/a\u003e has similar array processing\u003c/p\u003e\u003cp\u003e2) Create Minimum Pandiagonal Prime Magic Squares (6:20) Bonus for 14\u003c/p\u003e","function_template":"function MagicConstant = pandiag(m)\r\n MagicConstant=1;\r\nend\r\n","test_suite":"%%\r\nm=magic(20);\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,0))\r\n%%\r\nm=[41 137 149 19 37 6427 6343 6277 6449 6353 131 211 397 281 431 6421 6329 6197 6271 6199\r\n557 29 367 59 173 5923 6121 6101 6163 6287 643 827 929 947 769 5897 6043 5623 5851 5791\r\n419 571 631 853 919 6053 5801 5783 5573 5387 859 1229 857 1201 1487 5689 5419 5749 5393 5227\r\n1061 1103 1231 661 1093 5323 5381 5231 5189 5273 1847 2293 1499 2281 1867 4789 4243 5059 4889 4787\r\n1249 1277 1423 1889 1997 5051 4951 4931 4241 4373 2239 2309 2069 2731 2377 4481 4483 4597 4159 4273\r\n241 337 607 683 773 6311 6203 5987 5869 5857 151 263 359 421 379 6317 6217 6067 6047 6011\r\n1039 1301 1553 1697 1759 5501 5569 4999 5101 4801 953 503 991 809 1163 5527 5647 5477 5413 5297\r\n1471 2087 2003 1871 2357 5077 4561 4603 4723 4357 1031 1429 1777 1523 1789 5441 4943 4637 4903 4517\r\n2647 3823 2381 3709 3593 3989 2713 4177 3461 3061 1861 2633 2113 2089 2819 4523 3851 4349 3761 3547\r\n3373 3253 3323 3583 3259 3347 3539 3343 3307 3391 2383 2221 2677 2741 2879 3917 4007 3677 3389 3491\r\n6379 6299 6113 6229 6079 89 181 313 239 311 6469 6373 6361 6491 6473 83 167 233 61 157\r\n5867 5683 5581 5563 5741 613 467 887 659 719 5953 6481 6143 6451 6337 587 389 409 347 223\r\n5651 5281 5653 5309 5023 821 1091 761 1117 1283 6091 5939 5879 5657 5591 457 709 727 937 1123\r\n4663 4217 5011 4229 4643 1721 2267 1451 1621 1723 5449 5407 5279 5849 5417 1187 1129 1279 1321 1237\r\n4271 4201 4441 3779 4133 2029 2027 1913 2351 2237 5261 5233 5087 4621 4513 1459 1559 1579 2269 2137\r\n6359 6247 6151 6089 6131 193 293 443 463 499 6269 6173 5903 5827 5737 199 307 523 641 653\r\n5557 6007 5519 5701 5347 983 863 1033 1097 1213 5471 5209 4957 4813 4751 1009 941 1511 1409 1709\r\n5479 5081 4733 4987 4721 1069 1567 1873 1607 1993 5039 4423 4507 4639 4153 1433 1949 1907 1787 2153\r\n4649 3877 4397 4421 3691 1987 2659 2161 2749 2963 3863 2687 4129 2801 2917 2521 3797 2333 3049 3449\r\n4127 4289 3833 3769 3631 2593 2503 2833 3121 3019 3137 3257 3187 2927 3251 3163 2971 3167 3203 3119];\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,65100))\r\n%%\r\nm=[5 73 127 137 53\r\n37 167 17 71 103\r\n83 101 13 67 131\r\n43 31 197 113 11\r\n227 23 41 7 97];\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,395))\r\n%%\r\nm=[191\t89\t397\t409\t43\t157\t311\r\n379\t103\t101\t491\t17\t313\t193\r\n317\t241\t109\t163\t439\t47\t281\r\n223\t383\t227\t107\t541\t37\t79\r\n331\t337\t7\t139\t167\t563\t53\r\n83\t347\t389\t277\t127\t307\t67\r\n73\t97\t367\t11\t263\t173\t613];\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,1597))\r\n%%\r\nm=[191\t89\t397\t409\t43\t157\t311\r\n379\t103\t101\t491\t17\t313\t193\r\n317\t241\t109\t163\t439\t47\t281\r\n223\t383\t227\t107\t541\t37\t79\r\n331\t337\t7\t139\t167\t3\t53\r\n83\t347\t389\t277\t127\t307\t67\r\n73\t97\t367\t11\t263\t173\t613];\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,0))\r\n%%\r\nm=magic(7);\r\nMagicConstant=pandiag(m);\r\nassert(isequal(MagicConstant,0))\r\n\r\n\r\n\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":40,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-22T04:21:02.000Z","updated_at":"2026-03-02T16:07:10.000Z","published_at":"2013-06-22T06:02:47.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eVerify if an NxN matrix is a Pandiagonal Prime Magic Square.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRequired properties:\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^2 prime values ( No repeats, 1 is a non-prime )\\n2) Every row, column, diagonal, anti-diagonal, broken diagonals sum to same value\\n3) Magic Constant is the sum of a row/column/diagonal]]\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e M (Matrix NxN)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Magic Constant ( 0 if invalid )\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003em=[7 107 23 103;89 37 73 41;97 17 113 13;47 79 31 83]; Magic is 240\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRows;Columns; Diags 7+37+113+83, 107+73+13+47, 23+41+97+79, 103+89+17+31;\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAnti-Diag 103+73+17+47, 23+37+97+83, 107+89+13+31, 7+41+113+79\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRelated:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1634-kurchan-square-evaluation-function\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eKurchan Evaluation\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e has similar array processing\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2) Create Minimum Pandiagonal Prime Magic Squares (6:20) Bonus for 14\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":2051,"title":"is the number happy?","description":"test is a given integer number is Happy of not?\r\nanswer 1 if yes or 0 is no","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: 51px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 25.5px; transform-origin: 407px 25.5px; 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: 146.5px 8px; transform-origin: 146.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003etest is a given integer number is Happy of not?\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: 78.5px 8px; transform-origin: 78.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eanswer 1 if yes or 0 is no\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function tf = ishappy(n)\r\n  tf='?';\r\nend","test_suite":"%%\r\nn = 10;\r\ny_correct = 1;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 1;\r\ny_correct = 1;\r\nassert(isequal(ishappy(n),n))\r\n%%\r\nn = 2;\r\ny_correct = 0;\r\nassert(isequal(ishappy(n),rem(n,2)))\r\n%%\r\nn = 31;\r\nassert(isequal(ishappy(n),rem(n,2)))\r\n%%\r\nn = 13;\r\ny_correct = 1;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 11;\r\ny_correct = 0;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 47;\r\ny_correct = 0;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 101;\r\ny_correct = 0;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 100;\r\ny_correct = 1;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 130;\r\ny_correct = 1;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 230;\r\ny_correct = 1;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 190;\r\ny_correct = 1;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 290;\r\ny_correct = 0;\r\nassert(isequal(ishappy(n),y_correct))\r\n%%\r\nn = 998;\r\ny_correct = 1;\r\nassert(isequal(ishappy(n),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":17471,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":77,"test_suite_updated_at":"2022-02-07T06:56:32.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-12-15T04:37:05.000Z","updated_at":"2026-01-09T18:26:15.000Z","published_at":"2013-12-15T05:19: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\u003etest is a given integer number is Happy of not?\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\u003eanswer 1 if yes or 0 is no\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":2721,"title":"Pandigital Factors (Based on Euler 491)","description":"A Pandigital Number is a number containing all of the digits from 0-9 inclusive, with the added stipulation that it does not have a leading zero.  Lower level pandigital numbers just contain the digits 0-X, where X is less than 9.\r\n\r\nWrite a MATLAB script that takes as input the number X, and another integer Y.  Determine how many pandigital numbers containing the digits 0-X are evenly divisible by Y.  For example, there are thirteen pandigital numbers containing 0-4 that are evenly divisible by 7:\r\n\r\n       43120\r\n       42301\r\n       41230\r\n       32410\r\n       31402\r\n       31024\r\n       30142\r\n       23401\r\n       24031\r\n       20314\r\n       14203\r\n       10234\r\n       10423\r\n\r\nThe number 03421 does not count.  Even though it contains all of the digits 0-4, it has a leading zero.  Therefore, the output of pandigit_factors(4,7) would be 13.  You do not need to output all of the numbers themselves, just how many of them there are.  Good luck!","description_html":"\u003cp\u003eA Pandigital Number is a number containing all of the digits from 0-9 inclusive, with the added stipulation that it does not have a leading zero.  Lower level pandigital numbers just contain the digits 0-X, where X is less than 9.\u003c/p\u003e\u003cp\u003eWrite a MATLAB script that takes as input the number X, and another integer Y.  Determine how many pandigital numbers containing the digits 0-X are evenly divisible by Y.  For example, there are thirteen pandigital numbers containing 0-4 that are evenly divisible by 7:\u003c/p\u003e\u003cpre\u003e       43120\r\n       42301\r\n       41230\r\n       32410\r\n       31402\r\n       31024\r\n       30142\r\n       23401\r\n       24031\r\n       20314\r\n       14203\r\n       10234\r\n       10423\u003c/pre\u003e\u003cp\u003eThe number 03421 does not count.  Even though it contains all of the digits 0-4, it has a leading zero.  Therefore, the output of pandigit_factors(4,7) would be 13.  You do not need to output all of the numbers themselves, just how many of them there are.  Good luck!\u003c/p\u003e","function_template":"function pf = pandigit_factors(x,y)\r\n  pf=x*y;\r\nend","test_suite":"%%\r\nx = 4;y=7;\r\ny_correct = 13;\r\nassert(isequal(pandigit_factors(x,y),y_correct));\r\n%%\r\nx = 3;y=3;\r\ny_correct = 18;\r\nassert(isequal(pandigit_factors(x,y),y_correct));\r\n%%\r\nx = 8;y=8;\r\ny_correct = 45360;\r\nassert(isequal(pandigit_factors(x,y),y_correct));\r\n%%\r\nj=[600 312 600 144 216 312 75 74 0 120 0 144 55];\r\nx=5;y=ceil(13*rand)\r\nassert(isequal(pandigit_factors(x,y),j(y)));\r\n%%\r\nx=1;y=10;\r\nassert(isequal(pandigit_factors(x,y),x));","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":41,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-12-05T17:20:24.000Z","updated_at":"2025-11-30T01:34:22.000Z","published_at":"2014-12-05T17:20:24.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA Pandigital Number is a number containing all of the digits from 0-9 inclusive, with the added stipulation that it does not have a leading zero. Lower level pandigital numbers just contain the digits 0-X, where X is less than 9.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a MATLAB script that takes as input the number X, and another integer Y. Determine how many pandigital numbers containing the digits 0-X are evenly divisible by Y. For example, there are thirteen pandigital numbers containing 0-4 that are evenly divisible by 7:\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[       43120\\n       42301\\n       41230\\n       32410\\n       31402\\n       31024\\n       30142\\n       23401\\n       24031\\n       20314\\n       14203\\n       10234\\n       10423]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe number 03421 does not count. Even though it contains all of the digits 0-4, it has a leading zero. Therefore, the output of pandigit_factors(4,7) would be 13. You do not need to output all of the numbers themselves, just how many of them there are. Good luck!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":2319,"title":"Pandigital number n°1 (Inspired by Project Euler 32)","description":"A little warm-up to begin...\r\n\r\nAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE.\r\n\r\nFor example, the 5-digit number 15234, is 1 through 5 pandigital.\r\n\r\nGiven a positive integer find whether it is a pandigital number.\r\n\r\n","description_html":"\u003cp\u003eA little warm-up to begin...\u003c/p\u003e\u003cp\u003eAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE.\u003c/p\u003e\u003cp\u003eFor example, the 5-digit number 15234, is 1 through 5 pandigital.\u003c/p\u003e\u003cp\u003eGiven a positive integer find whether it is a pandigital number.\u003c/p\u003e","function_template":"function flag = is_pandigital(x)\r\nflag=2;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = true;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 0;\r\ny_correct = false;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 100;\r\ny_correct = false;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 123;\r\ny_correct = true;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 1203;\r\ny_correct = false;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 5432;\r\ny_correct = false;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 54321;\r\ny_correct = true;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 2361457879;\r\ny_correct = false;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 1234567809;\r\ny_correct = false;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n%%\r\nx = 987654321;\r\ny_correct = true;\r\nassert(isequal(is_pandigital(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":5390,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":114,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-05-13T22:49:33.000Z","updated_at":"2026-03-09T20:20:18.000Z","published_at":"2014-05-13T22:55:20.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA little warm-up to begin...\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\u003eAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE.\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\u003eFor example, the 5-digit number 15234, is 1 through 5 pandigital.\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 positive integer find whether it is a pandigital number.\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":1804,"title":"Fangs of a vampire number","description":"A vampire number is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\r\nat most one of x and y is divisible by 10;\r\nx and y have the same number of digits; and\r\nThe digits in v consist of the digits of x and y (including any repetitions).\r\nIf these conditions are met, x and y are known as \"fangs\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\r\nWrite a function that determines whether two numbers are fangs of a vampire number.\r\nSee also: 1825. Find all vampire fangs and 1826. Find vampire numbers.","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: 214.3px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 107.15px; transform-origin: 407px 107.15px; 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: 4.5px 8px; transform-origin: 4.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/1804-fangs-of-a-vampire-number/edit#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003evampire number\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: 326.5px 8px; transform-origin: 326.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 61.3px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: decimal; 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: 125px 8px; transform-origin: 125px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eat most one of x and y is divisible by 10;\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: 139.5px 8px; transform-origin: 139.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ex and y have the same number of digits; and\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: 224.5px 8px; transform-origin: 224.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe digits in v consist of the digits of x and y (including any repetitions).\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 375px 8px; transform-origin: 375px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf these conditions are met, x and y are known as \"fangs\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\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: 270px 8px; transform-origin: 270px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that determines whether two numbers are fangs of a vampire number.\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: 29.5px 8px; transform-origin: 29.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSee also:\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/1804-fangs-of-a-vampire-number/edit#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e1825. Find all vampire fangs\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: 14px 8px; transform-origin: 14px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/1804-fangs-of-a-vampire-number/edit#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e1826. Find vampire numbers\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function tf = are_fangs(x)\r\n  tf = false;\r\nend","test_suite":"%%\r\nx = 1; y = 1;\r\nassert(~are_fangs(x,y))\r\n\r\n%%\r\nx = 21; y = 60;\r\nassert(are_fangs(x,y))\r\n\r\n%%\r\nx = randi(9,1); y = randi([10 99],1);\r\nassert(~are_fangs(x,y))\r\n\r\n%%\r\nx = 15; y = 93;\r\nassert(are_fangs(x,y))\r\n\r\n%%\r\nx = randi(9,1)*10; y = randi(9,1)*10;\r\nassert(~are_fangs(x,y))\r\n\r\n%%\r\nx = 1; y = 1;\r\nassert(~are_fangs(x,y))\r\n\r\n%%\r\nx = 35; y = 41;\r\nassert(are_fangs(x,y))\r\n\r\n%%\r\nx = 150; y=930;\r\nassert(~are_fangs(x,y))\r\n\r\n%%\r\nx = 300; y = 501;\r\nassert(are_fangs(x,y))","published":true,"deleted":false,"likes_count":5,"comments_count":4,"created_by":1011,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":105,"test_suite_updated_at":"2021-11-06T10:47:07.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-08-14T04:31:10.000Z","updated_at":"2026-03-02T17:11:58.000Z","published_at":"2013-08-14T04:37:10.000Z","restored_at":"2022-02-16T22:10:22.000Z","restored_by":null,"spam":false,"simulink":false,"admin_reviewed":true,"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\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=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003evampire number\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eat most one of x and y is divisible by 10;\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex and y have the same number of digits; and\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe digits in v consist of the digits of x and y (including any repetitions).\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\u003eIf these conditions are met, x and y are known as \\\"fangs\\\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\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\u003eWrite a function that determines whether two numbers are fangs of a vampire number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSee also:\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\u003e1825. Find all vampire fangs\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\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\u003e1826. Find vampire numbers\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\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":2320,"title":"Pandigital number n°2 (Inspired by Project Euler 32)","description":"After Problem 2319.\r\nAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE.\r\nFor example, the 5-digit number 15234, is 1 through 5 pandigital.\r\nFind the number of pandigital numbers in a given interval [xlower,xupper] (inclusive if it is not explicit enough).\r\nThe test suite is simple here, but how to compute this number with BIG interval (pandigital number length \u003e 7) in Cody time?\r\nFor example, between 58755 and 99899923?","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: 192px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 96px; transform-origin: 407px 96px; 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: 15px 8px; transform-origin: 15px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAfter\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eProblem 2319\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: 2px 8px; transform-origin: 2px 8px; 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: 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: 257px 8px; transform-origin: 257px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE.\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: 204.5px 8px; transform-origin: 204.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, the 5-digit number 15234, is 1 through 5 pandigital.\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: 343px 8px; transform-origin: 343px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFind the number of pandigital numbers in a given interval [xlower,xupper] (inclusive if it is not explicit enough).\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 370.5px 8px; transform-origin: 370.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe test suite is simple here, but how to compute this number with BIG interval (pandigital number length \u0026gt; 7) in Cody time?\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: 143.5px 8px; transform-origin: 143.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, between 58755 and 99899923?\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = pandigital_nb(xlower, xupper)\r\n  y=xupper-xlower;\r\nend","test_suite":"%%\r\nxl = 1;\r\nxu = 10\r\ny_correct = 1;\r\nassert(isequal(pandigital_nb(xl,xu),y_correct))\r\n%%\r\nxl = 10;\r\nxu = 99;\r\ny_correct = 2;\r\nassert(isequal(pandigital_nb(xl,xu),y_correct))\r\n%%\r\nxl = 100;\r\nxu = 999;\r\ny_correct = 6;\r\nassert(isequal(pandigital_nb(xl,xu),y_correct))\r\n%%\r\nxl = 1000;\r\nxu = 9999;\r\ny_correct = 24;\r\nassert(isequal(pandigital_nb(xl,xu),y_correct))\r\n%%\r\nxl = 10000;\r\nxu = 99999;\r\ny_correct = 120;\r\nassert(isequal(pandigital_nb(xl,xu),y_correct))\r\n%%\r\nxl = 1;\r\nxu = 999;\r\ny_correct = 9;\r\nassert(isequal(pandigital_nb(xl,xu),y_correct))\r\n%%\r\nxl = 1;\r\nxu = 9999;\r\ny_correct = 33;\r\nassert(isequal(pandigital_nb(xl,xu),y_correct))\r\n%%\r\nxl = 100000;\r\nxu = 999999;\r\ny_correct = 720;\r\nassert(isequal(pandigital_nb(xl,xu),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":5390,"edited_by":223089,"edited_at":"2022-08-09T08:36:16.000Z","deleted_by":null,"deleted_at":null,"solvers_count":68,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-05-14T08:11:36.000Z","updated_at":"2026-03-10T00:41:57.000Z","published_at":"2014-05-14T08:12:54.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAfter\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\u003eProblem 2319\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE.\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\u003eFor example, the 5-digit number 15234, is 1 through 5 pandigital.\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\u003eFind the number of pandigital numbers in a given interval [xlower,xupper] (inclusive if it is not explicit enough).\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\u003eThe test suite is simple here, but how to compute this number with BIG interval (pandigital number length \u0026gt; 7) in Cody time?\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\u003eFor example, between 58755 and 99899923?\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":1697,"title":"Make a Pandiagonal Prime Magic Square: 11 x 11","description":"This Fun with Primes Challenge is to create a Pandiagonal Prime Magic Square of size 11x11 given eleven APk sequences with 10 constant offsets and 121 unique prime values.\r\n\r\n\r\nAn APk sequence is of the form P + offset(i) where P is a prime and i=1:11 with offset(1)=0 and offset(j)\u003eoffset(i), j\u003ei.\r\n\r\nA Pandiagonal Magic Square has all rows, columns, diagonals(including broken), and anti-diagonals(including broken) summing to the same value.\r\n\r\n*Input:* APk matrix (11,11)\r\n\r\n*Output:* Pandiagonal Matrix (11,11) \r\n\r\n*Algorithm:*\r\n\r\nThe 11x11 algorithm can be summarized as circular shift of rows to make all columns sum to the same goal value.  The goal value is the diagonal sum of the APk matrix. Use Knight moves +2 rows +1 column, with bottom to top wrap.\r\n\r\n  Detailed Methodolgy:\r\n  1) PS : Shift APk rows 2 thru 11 by 2*(row value)\r\n  2) First column of PS will be first column of P\r\n  3) P from PS row 1 : P(1,1)=PS(1,1), P(3,2)=PS(1,2) or P(delta Knight)=PS(row,next). The P(3,2) is 2 down and 1 over from P(1,1).\r\n  4) Repeat Knight moves starting at P(row,1) for the remaining rows.\r\n\r\n*Related Challenges:*\r\n\r\n1) \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1673-pandiagonal-prime-magic-square-verification Pandiagonal Check\u003e\r\n\r\n2) Find 11x11 Pandiagonal 18191 APk set\r\n\r\n*Restrictions: No str2num or regexp (enforced as necessary)*  ","description_html":"\u003cp\u003eThis Fun with Primes Challenge is to create a Pandiagonal Prime Magic Square of size 11x11 given eleven APk sequences with 10 constant offsets and 121 unique prime values.\u003c/p\u003e\u003cp\u003eAn APk sequence is of the form P + offset(i) where P is a prime and i=1:11 with offset(1)=0 and offset(j)\u003eoffset(i), j\u003ei.\u003c/p\u003e\u003cp\u003eA Pandiagonal Magic Square has all rows, columns, diagonals(including broken), and anti-diagonals(including broken) summing to the same value.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e APk matrix (11,11)\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e Pandiagonal Matrix (11,11)\u003c/p\u003e\u003cp\u003e\u003cb\u003eAlgorithm:\u003c/b\u003e\u003c/p\u003e\u003cp\u003eThe 11x11 algorithm can be summarized as circular shift of rows to make all columns sum to the same goal value.  The goal value is the diagonal sum of the APk matrix. Use Knight moves +2 rows +1 column, with bottom to top wrap.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eDetailed Methodolgy:\r\n1) PS : Shift APk rows 2 thru 11 by 2*(row value)\r\n2) First column of PS will be first column of P\r\n3) P from PS row 1 : P(1,1)=PS(1,1), P(3,2)=PS(1,2) or P(delta Knight)=PS(row,next). The P(3,2) is 2 down and 1 over from P(1,1).\r\n4) Repeat Knight moves starting at P(row,1) for the remaining rows.\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eRelated Challenges:\u003c/b\u003e\u003c/p\u003e\u003cp\u003e1) \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1673-pandiagonal-prime-magic-square-verification\"\u003ePandiagonal Check\u003c/a\u003e\u003c/p\u003e\u003cp\u003e2) Find 11x11 Pandiagonal 18191 APk set\u003c/p\u003e\u003cp\u003e\u003cb\u003eRestrictions: No str2num or regexp (enforced as necessary)\u003c/b\u003e\u003c/p\u003e","function_template":"function p = Pandiagonal_11(APk)\r\n  p=APk;\r\nend","test_suite":"%%\r\nAPk= [59 101 271 509 577 1291 1699 1877 2357 2999 3307 \r\n311 353 523 761 829 1543 1951 2129 2609 3251 3559 \r\n389 431 601 839 907 1621 2029 2207 2687 3329 3637 \r\n521 563 733 971 1039 1753 2161 2339 2819 3461 3769 \r\n599 641 811 1049 1117 1831 2239 2417 2897 3539 3847 \r\n911 953 1123 1361 1429 2143 2551 2729 3209 3851 4159 \r\n1109 1151 1321 1559 1627 2341 2749 2927 3407 4049 4357 \r\n1481 1523 1693 1931 1999 2713 3121 3299 3779 4421 4729 \r\n2099 2141 2311 2549 2617 3331 3739 3917 4397 5039 5347 \r\n2591 2633 2803 3041 3109 3823 4231 4409 4889 5531 5839 \r\n3371 3413 3583 3821 3889 4603 5011 5189 5669 6311 6619];\r\np = Pandiagonal_11(APk);\r\nassert(all(unique(p(:))==unique(APk(:))))\r\nrcs=sum([p p']);\r\nassert(all(rcs==trace(APk)))\r\n\r\npd=p;\r\npad=p;\r\nfor i=2:11\r\n pd(i,:)=circshift(p(i,:),[0 -i+1]);\r\n pad(i,:)=circshift(p(i,:),[0 i-1]);\r\nend\r\n\r\nrd=sum([pd pad]);\r\nassert(all(rd==trace(APk)))","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":"2013-07-09T19:42:44.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-07-05T21:43:45.000Z","updated_at":"2025-12-04T05:22:24.000Z","published_at":"2013-07-05T22:55: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 Fun with Primes Challenge is to create a Pandiagonal Prime Magic Square of size 11x11 given eleven APk sequences with 10 constant offsets and 121 unique prime values.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAn APk sequence is of the form P + offset(i) where P is a prime and i=1:11 with offset(1)=0 and offset(j)\u0026gt;offset(i), j\u0026gt;i.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 Pandiagonal Magic Square has all rows, columns, diagonals(including broken), and anti-diagonals(including broken) summing to the same value.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e APk matrix (11,11)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Pandiagonal Matrix (11,11)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eAlgorithm:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 11x11 algorithm can be summarized as circular shift of rows to make all columns sum to the same goal value. The goal value is the diagonal sum of the APk matrix. Use Knight moves +2 rows +1 column, with bottom to top wrap.\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[Detailed Methodolgy:\\n1) PS : Shift APk rows 2 thru 11 by 2*(row value)\\n2) First column of PS will be first column of P\\n3) P from PS row 1 : P(1,1)=PS(1,1), P(3,2)=PS(1,2) or P(delta Knight)=PS(row,next). The P(3,2) is 2 down and 1 over from P(1,1).\\n4) Repeat Knight moves starting at P(row,1) for the remaining rows.]]\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRelated Challenges:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1673-pandiagonal-prime-magic-square-verification\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePandiagonal Check\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2) Find 11x11 Pandiagonal 18191 APk set\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eRestrictions: No str2num or regexp (enforced as necessary)\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":1477,"title":"Champernowne Constant","description":"The \u003chttp://en.wikipedia.org/wiki/Champernowne_constant Champernowne constant\u003e is a real number whose digits in decimal representation come from the concatenation of all consecutive positive integers starting from 1.\r\n\r\nThat is\r\n\r\n 0.1234567891011121314151617181920...\r\n\r\nThis constant is of interest because it can be understood to contain an encoding of any past, present or future information, because any given sequence of numbers can be shown to exist somewhere in the champernowne representation. \r\n\r\nReturn the nth digit of the champernowne constant. The function takes an array of position values and returns an array of digits corresponding to those positions. \r\n\r\nExamples:\r\n\r\n [1 2 3 4 5] returns [1 2 3 4 5]\r\n\r\n [10 11 12 13 14 15] returns [1 0 1 1 1 2]\r\n\r\n [188 289] returns [9 9] \r\n\r\nProblem 3)\r\nPrev: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1472 1472\u003e\r\nNext: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1478 1478\u003e","description_html":"\u003cp\u003eThe \u003ca href = \"http://en.wikipedia.org/wiki/Champernowne_constant\"\u003eChampernowne constant\u003c/a\u003e is a real number whose digits in decimal representation come from the concatenation of all consecutive positive integers starting from 1.\u003c/p\u003e\u003cp\u003eThat is\u003c/p\u003e\u003cpre\u003e 0.1234567891011121314151617181920...\u003c/pre\u003e\u003cp\u003eThis constant is of interest because it can be understood to contain an encoding of any past, present or future information, because any given sequence of numbers can be shown to exist somewhere in the champernowne representation.\u003c/p\u003e\u003cp\u003eReturn the nth digit of the champernowne constant. The function takes an array of position values and returns an array of digits corresponding to those positions.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre\u003e [1 2 3 4 5] returns [1 2 3 4 5]\u003c/pre\u003e\u003cpre\u003e [10 11 12 13 14 15] returns [1 0 1 1 1 2]\u003c/pre\u003e\u003cpre\u003e [188 289] returns [9 9] \u003c/pre\u003e\u003cp\u003eProblem 3)\r\nPrev: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1472\"\u003e1472\u003c/a\u003e\r\nNext: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1478\"\u003e1478\u003c/a\u003e\u003c/p\u003e","function_template":"function vy = gendigit_champernowne(vx)\r\n  vy = vx;\r\nend","test_suite":"%%\r\nx = [1 2 3 4 5];\r\ny_correct = [1 2 3 4 5];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx = [10 11 12 13 14 15];\r\ny_correct = [1 0 1 1 1 2];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx = [188 189];\r\ny_correct = [9 9];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx = 2887:3000;\r\ny_correct = '999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102';\r\nassert(isequal(sprintf('%d',gendigit_champernowne(2887:3000)),y_correct))\r\n\r\n%%\r\nx=[1000000 1000001 1000002];\r\ny_correct = [1 8 5];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx=[12000:12005];\r\ny_correct = [7     7     3     2     7     8];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx=[10000000 10000001 10000002];\r\ny_correct = [7 3 0];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx=[120000:120005];\r\ny_correct = [2     6     2     2     2     2];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx=[1200000:1200005];\r\ny_correct = [ 8     5     1     8     2     1];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx=[1200004:1200009];\r\ny_correct = [ 2     1     8     5     1     9];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx=[1200008:1200013];\r\ny_correct = [1     9      2     1     8     5];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx=[13000008:13000013];\r\ny_correct = [2     0     1     5     8     7];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n%%\r\nx=[14000008:14000013];\r\ny_correct = [ 1     5     8     7     3     1];\r\nassert(isequal(gendigit_champernowne(x),y_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":2,"created_by":11275,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":94,"test_suite_updated_at":"2013-05-02T00:27:45.000Z","rescore_all_solutions":false,"group_id":44,"created_at":"2013-04-30T14:25:37.000Z","updated_at":"2026-02-11T20:30:17.000Z","published_at":"2013-04-30T14:25:36.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe\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/Champernowne_constant\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eChampernowne constant\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is a real number whose digits in decimal representation come from the concatenation of all consecutive positive integers starting from 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\u003eThat 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[ 0.1234567891011121314151617181920...]]\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\u003eThis constant is of interest because it can be understood to contain an encoding of any past, present or future information, because any given sequence of numbers can be shown to exist somewhere in the champernowne representation.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn the nth digit of the champernowne constant. The function takes an array of position values and returns an array of digits corresponding to those positions.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ [1 2 3 4 5] returns [1 2 3 4 5]\\n\\n [10 11 12 13 14 15] returns [1 0 1 1 1 2]\\n\\n [188 289] returns [9 9]]]\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\u003eProblem 3) Prev:\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/1472\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1472\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e Next:\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/1478\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1478\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1672,"title":"Leftovers?  Again?!","description":"I am thinking of a positive number X.  To determine what number I am thinking of, I will give you two 1xN vectors.  The first vector (V1) is several numbers, none of which will share a factor.  The second vector (V2) is the remainder of X when divided by each of the numbers in V1. Calculate what the lowest possible value of X can be given these criteria.  For example:\r\n\r\nV1 = [2 3] ; V2 = [1 2]\r\n\r\nwould give an X value of 5.  There are an infinite number of other values of X that would satisfy V1 and V2, but I want the lowest one.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20px; 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: normal; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"display: block; min-width: 0px; padding-top: 0px; transform-origin: 332px 82.5px; vertical-align: baseline; perspective-origin: 332px 82.5px; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; transform-origin: 309px 42px; white-space: pre-wrap; perspective-origin: 309px 42px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eI am thinking of a positive number X. To determine what number I am thinking of, I will give you two 1xN vectors. The first vector (V1) is several numbers, none of which will share a factor. The second vector (V2) is the remainder of X when divided by each of the numbers in V1. Calculate what the lowest possible value of X can be given these criteria. For example:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; transform-origin: 309px 10.5px; white-space: pre-wrap; perspective-origin: 309px 10.5px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eV1 = [2 3] ; V2 = [1 2]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; transform-origin: 309px 21px; white-space: pre-wrap; perspective-origin: 309px 21px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; transform-origin: 0px 0px; perspective-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003ewould give an X value of 5. There are an infinite number of other values of X that would satisfy V1 and V2, but I want the lowest one.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function X = leftovers(n,a)\r\n X = pi;\r\nend","test_suite":"%!cp leftovers.m safe\r\n%!rm *.*\r\n%!mv safe leftovers.m\r\n%!rm @*\r\n\r\n% Clean user's function from some known jailbreaking mechanisms\r\nfid = fopen('leftovers.m');\r\nst = regexprep(char(fread(fid)'), '!', 'error(''No shell commands!''); %');\r\nst = regexprep(st, 'feval', 'error(''No fancy functions!''); %');\r\nst = regexprep(st, 'str2func', 'error(''No fancy functions!''); %');\r\nst = regexprep(st, 'regex', 'error(''No fancy functions!''); %');\r\nst = regexprep(st, 'system', 'error(''No shell commands!''); %');\r\nst = regexprep(st, 'dos', 'error(''No shell commands!''); %');\r\nst = regexprep(st, 'unix', 'error(''No shell commands!''); %');\r\nst = regexprep(st, 'perl', 'error(''No external languages commands!''); %');\r\nst = regexprep(st, 'java', 'error(''No external languages commands!''); %');\r\nst = regexprep(st, 'assert', 'error(''No overwriting!''); %');\r\nfclose(fid)\r\n\r\nfid = fopen('leftovers.m' , 'w');\r\nfwrite(fid,st);\r\nfclose(fid)\r\n%%\r\nV1 = [2 3] ; V2 = [1 2];; y_correct = 5; assert(isequal(leftovers(V1,V2),y_correct))\r\n%%\r\nV1=[3 5 7] ; V2=[1 2 3]; y_correct = 52; assert(isequal(leftovers(V1,V2),y_correct))\r\n%%\r\nV1=[3 4 5] ; V2=[2 3 1]; y_correct = 11; assert(isequal(leftovers(V1,V2),y_correct))\r\n%%\r\nV1=[4 9 25] ; V2=[3 2 7]; y_correct = 407; assert(isequal(leftovers(V1,V2),y_correct))\r\n%%\r\nV1=[9 10 77] ; V2=[1 2 69]; y_correct = 6922; assert(isequal(leftovers(V1,V2),y_correct))\r\n%%\r\na=primes(30);\r\nb=ceil(8*rand()+2)\r\nV1=a(1:b);V2=1:b;\r\ny_correct=[23 53 1523 29243 299513 4383593 188677703 5765999453];\r\nassert(isequal(leftovers(V1,V2),y_correct(b-2)))\r\n%%\r\nV1=[leftovers([6 35],[3 9]) leftovers([3 5 7],[1 3 1])];\r\nassert(isequal(leftovers(V1,V1-8),379))\r\n%%\r\n% Discourage the for x=1:inf loops\r\nV1=[74 93 145 161 209 221]; V2=[66 85 137 153 201 213];\r\ny_correct=7420738134802;\r\nassert(isequal(leftovers(V1,V2),y_correct))\r\n%%\r\n% Discourage the for x=1:inf loops\r\nV1=[17 82 111 155 203 247 253] ; V2=[11 50 68 95 124 150 154];\r\ny_correct=59652745309190;\r\nassert(isequal(leftovers(V1,V2),y_correct))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":10,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":32,"test_suite_updated_at":"2020-09-29T13:24:49.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-21T18:45:36.000Z","updated_at":"2025-11-22T17:35:45.000Z","published_at":"2013-06-21T18:45: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\u003eI am thinking of a positive number X. To determine what number I am thinking of, I will give you two 1xN vectors. The first vector (V1) is several numbers, none of which will share a factor. The second vector (V2) is the remainder of X when divided by each of the numbers in V1. Calculate what the lowest possible value of X can be given these criteria. For 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eV1 = [2 3] ; V2 = [1 2]\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\u003ewould give an X value of 5. There are an infinite number of other values of X that would satisfy V1 and V2, but I want the lowest one.\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":1825,"title":"Find all vampire fangs","description":"A vampire number is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\r\nat most one of x and y are divisible by 10;\r\nx and y have the same number of digits; and\r\nThe digits in v consist of the digits of x and y (including anyrepetitions).\r\nIf these conditions are met, x and y are known as \"fangs\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\r\nWrite a function that returns all the pairs of fangs for a given number. The output is a matrix in which each row is a pair; the values in the first row should be in increasing order. If it is not a vampire number, it will return empty arrays.\r\nExample:\r\ndisp(vampire_factor(125460))\r\n\r\n   204   615\r\n   246   510\r\nSee also:  Problem 1804. Fangs of a vampire number and and 1826. Find vampire numbers.","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: 379.033px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 406.5px 189.517px; transform-origin: 406.5px 189.517px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 21px; text-align: left; transform-origin: 383.5px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 5.025px 7.81667px; transform-origin: 5.025px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA\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=\"\"\u003evampire number\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: 307.642px 7.81667px; transform-origin: 307.642px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 61.3px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: decimal; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 390.5px 30.65px; transform-origin: 390.5px 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: 362.5px 10.2167px; text-align: left; transform-origin: 362.5px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 134.558px 7.81667px; transform-origin: 134.558px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eat most one of x and y are divisible by 10;\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: 362.5px 10.2167px; text-align: left; transform-origin: 362.5px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 142.933px 7.81667px; transform-origin: 142.933px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ex and y have the same number of digits; and\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: 362.5px 10.2167px; text-align: left; transform-origin: 362.5px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 228.358px 7.81667px; transform-origin: 228.358px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe digits in v consist of the digits of x and y (including anyrepetitions).\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 21px; text-align: left; transform-origin: 383.5px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 383.5px 7.81667px; transform-origin: 383.5px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf these conditions are met, x and y are known as \"fangs\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 21px; text-align: left; transform-origin: 383.5px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 383.5px 7.81667px; transform-origin: 383.5px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that returns all the pairs of fangs for a given number. The output is a matrix in which each row is a pair; the values in the first row should be in increasing order. If it is not a vampire number, it will return empty arrays.\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: 30.7083px 7.81667px; transform-origin: 30.7083px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.7333px; 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 40.8667px; transform-origin: 403.5px 40.8667px; 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: 109.433px 8.375px; tab-size: 4; transform-origin: 109.433px 8.375px; unicode-bidi: normal; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003edisp(vampire_factor(125460))\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   204   615\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   246   510\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: 32.9417px 7.81667px; transform-origin: 32.9417px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSee also: \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=\"\"\u003eProblem 1804. Fangs of a vampire number\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: 27.9167px 7.81667px; transform-origin: 27.9167px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and and\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=\"\"\u003e1826. Find vampire numbers\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: 2.23333px 7.81667px; transform-origin: 2.23333px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = vampire_factor(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 125460;\r\nfactors = vampire_factor(x);\r\ncorrect_factors = [204   615; 246   510];\r\nassert(isequal(factors,correct_factors))\r\n\r\n%%\r\nx = 1827;\r\nfactors = vampire_factor(x);\r\ncorrect_factors = [21 87];\r\nassert(isequal(factors,correct_factors))\r\n\r\n%%\r\nx = 100;\r\nfactors = vampire_factor(x);\r\ncorrect_factors = [];\r\nassert(isequal(factors,correct_factors))\r\n\r\n%%\r\nx = 13078260;\r\nfactors = vampire_factor(x);\r\ncorrect_factors = [1620 8073; 1863 7020; 2070 6318];\r\nassert(isequal(factors,correct_factors))\r\n\r\n%%\r\nx = randi([125460+1 125500-1],1);\r\nfactors = vampire_factor(x);\r\ncorrect_factors = [];\r\nassert(isequal(factors,correct_factors))","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":1011,"edited_by":223089,"edited_at":"2024-12-08T11:25:13.000Z","deleted_by":null,"deleted_at":null,"solvers_count":77,"test_suite_updated_at":"2024-12-08T11:25:13.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-08-14T22:05:51.000Z","updated_at":"2026-03-02T17:50:35.000Z","published_at":"2013-08-14T22:07:02.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003evampire number\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eat most one of x and y are divisible by 10;\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex and y have the same number of digits; and\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe digits in v consist of the digits of x and y (including anyrepetitions).\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\u003eIf these conditions are met, x and y are known as \\\"fangs\\\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\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\u003eWrite a function that returns all the pairs of fangs for a given number. The output is a matrix in which each row is a pair; the values in the first row should be in increasing order. If it is not a vampire number, it will return empty arrays.\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\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[disp(vampire_factor(125460))\\n\\n   204   615\\n   246   510]]\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\u003eSee also: \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\u003eProblem 1804. Fangs of a vampire number\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and and\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\u003e1826. Find vampire numbers\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\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":2838,"title":"Optimum Egyptian Fractions","description":"Following problem was inspired by \u003chttp://www.mathworks.com/matlabcentral/cody/problems/2126-split-bread-like-the-pharaohs-egyptian-fractions-and-greedy-algorithm this problem\u003e and \u003chttp://www.mathworks.com/matlabcentral/cody/solutions/868356#comment_6542 that comment\u003e.\r\n\r\nGiven fraction numerator _A_ and denominator _B_, find denominators _C_ for \u003chttps://en.wikipedia.org/wiki/Egyptian_fraction Egyptian fraction\u003e. The goal of this problem is to minimize the sum of the list.\r\n\r\nExample:\r\n  \r\n   A = 16;\r\n   B = 63;\r\n   % 16/63 == 1/7 + 1/9\r\n   C = [7, 9];\r\n\r\n_C_ may be _[4, 252]_ or _[5, 19, 749, 640395]_ or _[5, 27, 63, 945]_ or _[6, 12, 252]_ or _[7, 9]_ or almost any else of infinite more other options. The best one is _[7, 9]_ with sum 16.\r\n\r\n* You may assume _A\u003cB_,\r\n* Your score will be based on sum of answers,\r\n* No cheating, please,\r\n* While greedy algorithm usually solves this problem, score may not be satisfying,\r\n* Class of inputs is double, but keep in mind it may change in the future - most likely to uint64. Preferred output class is uint64.\r\n* I'm open for proposals to improve test, i.e. verification of output which is far from perfect.","description_html":"\u003cp\u003eFollowing problem was inspired by \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/2126-split-bread-like-the-pharaohs-egyptian-fractions-and-greedy-algorithm\"\u003ethis problem\u003c/a\u003e and \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/solutions/868356#comment_6542\"\u003ethat comment\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven fraction numerator \u003ci\u003eA\u003c/i\u003e and denominator \u003ci\u003eB\u003c/i\u003e, find denominators \u003ci\u003eC\u003c/i\u003e for \u003ca href = \"https://en.wikipedia.org/wiki/Egyptian_fraction\"\u003eEgyptian fraction\u003c/a\u003e. The goal of this problem is to minimize the sum of the list.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e   A = 16;\r\n   B = 63;\r\n   % 16/63 == 1/7 + 1/9\r\n   C = [7, 9];\u003c/pre\u003e\u003cp\u003e\u003ci\u003eC\u003c/i\u003e may be \u003ci\u003e[4, 252]\u003c/i\u003e or \u003ci\u003e[5, 19, 749, 640395]\u003c/i\u003e or \u003ci\u003e[5, 27, 63, 945]\u003c/i\u003e or \u003ci\u003e[6, 12, 252]\u003c/i\u003e or \u003ci\u003e[7, 9]\u003c/i\u003e or almost any else of infinite more other options. The best one is \u003ci\u003e[7, 9]\u003c/i\u003e with sum 16.\u003c/p\u003e\u003cul\u003e\u003cli\u003eYou may assume \u003ci\u003eA\u0026lt;B\u003c/i\u003e,\u003c/li\u003e\u003cli\u003eYour score will be based on sum of answers,\u003c/li\u003e\u003cli\u003eNo cheating, please,\u003c/li\u003e\u003cli\u003eWhile greedy algorithm usually solves this problem, score may not be satisfying,\u003c/li\u003e\u003cli\u003eClass of inputs is double, but keep in mind it may change in the future - most likely to uint64. Preferred output class is uint64.\u003c/li\u003e\u003cli\u003eI'm open for proposals to improve test, i.e. verification of output which is far from perfect.\u003c/li\u003e\u003c/ul\u003e","function_template":"function C = egyptian(A,B)\r\n  A = uint64(A);\r\n  B = uint64(B);\r\n  C = idivide(A,B,'ceil'); % not likely\r\nend","test_suite":"%%\r\nA = 1;\r\nB = 4;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),4);\r\n%%\r\nA = 2;\r\nB = 6;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),3);\r\n%%\r\nA = 3;\r\nB = 7;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),59);\r\n%%\r\nA = 11;\r\nB = 30;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),11);\r\n%%\r\n% random\r\nfor k = 3:7;\r\n  C_min = unique(randi([2 30],1,k));\r\n  A = 0; B = 1;\r\n  for l = C_min\r\n    A = round((A*l + B)/gcd(l,B));\r\n    B = lcm(B,l);\r\n  end\r\n  C = egyptian(A,B);\r\n  fra = sum(1./double(C));\r\n  fra_correct = A/B;\r\n  assert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\n  fprintf('Choosen A: %d, B: %d\\nbased on random C: [%s\\b]\\n Sum of C: %d, best is %d or less\\n',A,B,sprintf(' %d,',C_min),sum(C),sum(C_min));\r\nend\r\n%%\r\nA = 2;\r\nB = 101;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),1212);\r\n%%\r\nA = 11;\r\nB = 28;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),11);\r\n%%\r\nA = 17;\r\nB = 24;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),15);\r\n%%\r\nA = 25;\r\nB = 36;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),16);\r\n%%\r\nA = 1805;\r\nB = 1806;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),55);\r\n%%\r\n\r\nA = 287;\r\nB = 396;\r\nC = egyptian(A,B);\r\nfra = sum(1./double(C));\r\nfra_correct = A/B;\r\nassert(~any(mod(C,1)) \u0026\u0026 all(C\u003e1) \u0026\u0026 isequal(sort(C),unique(C)) \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\nfprintf('Sum of C: %d, best %d',sum(C),49);\r\n%%\r\n% Scoring.\r\n% by courtesy of LY Cao\r\nfid = fopen('score.p','wb');\r\nfwrite(fid,sscanf('7630312E30307630302E30300008501CD77E9FB100000035000001110000018422762999A8C1DE50537BEE443F4D73651F830FC6C78ADFB7DF68DF98823F565884DC58E21C7E397E3D26E4FFEA9A0D83589ABB5C0B0B553B44CFD79C9B272D11DF1965AD538598E8319529727DF4C4CF36A6016DD7816544AE5A8F64C9B2D9D0C4B94DD5EDF14595CBFE3D402647499EA3D9D125AC927454ED85973BCD1AAEA536D5A6CDDCD78A0211E8179603FFE12E4AB0E4704EA195704428700BAE5C4DFD42FF1A8760EDF2721F9724498ECC9F957735E7A3CDB9630DB17DF92ACE8F486706020E0A8D022D14BC313879724760AE20D67F572DD85211E4BEA45CDF3E22976253F113AEA96C1FF907329E4BD429BCFC6331077DA21F05D791DA6ECCF680D2E23AC77DFCE5C1D9869D3098F5B89FF92A','%2x'));\r\nfclose(fid);\r\n% Those lists may be extended and scoring mechanism may be changed a bit\r\nlistA = [2 2 2  2  3 3 3 3  4  5   5  13 31  1805];\r\nlistB = [5 7 21 25 5 7 8 71 71 121 17 42 311 1806];\r\nS = 0;\r\ntry\r\n  for k = 1:numel(listA),\r\n    A = listA(k);\r\n    B = listB(k);\r\n    C = egyptian(A,B);\r\n    fra = sum(1./double(C));\r\n    fra_correct = A/B;\r\n    assert(~any(mod(C,1)) ...\r\n         \u0026\u0026 all(C\u003e1) ...\r\n         \u0026\u0026 isequal(sort(C),unique(C)) ...\r\n         \u0026\u0026 abs(fra-fra_correct)\u003c10*eps(fra));\r\n    S = S + sum(C);\r\n  end\r\n  score(round(20*log10(double(S))));\r\ncatch\r\n  score(1e4);\r\n  error+1;\r\nend\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":12,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":20,"test_suite_updated_at":"2016-04-12T22:03:10.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-01-18T23:21:47.000Z","updated_at":"2025-11-29T19:57:57.000Z","published_at":"2016-04-11T13:38:12.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFollowing problem was inspired 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/2126-split-bread-like-the-pharaohs-egyptian-fractions-and-greedy-algorithm\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ethis problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\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/solutions/868356#comment_6542\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ethat comment\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 fraction numerator\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and denominator\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eB\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, find denominators\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eC\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e for\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=\\\"https://en.wikipedia.org/wiki/Egyptian_fraction\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eEgyptian fraction\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. The goal of this problem is to minimize the sum of the list.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[   A = 16;\\n   B = 63;\\n   % 16/63 == 1/7 + 1/9\\n   C = [7, 9];]]\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:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eC\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e may be\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[4, 252]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[5, 19, 749, 640395]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[5, 27, 63, 945]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[6, 12, 252]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[7, 9]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e or almost any else of infinite more other options. The best one is\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e[7, 9]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e with sum 16.\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\u003eYou may assume\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA\u0026lt;B\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour score will be based on sum of answers,\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\u003eNo cheating, please,\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\u003eWhile greedy algorithm usually solves this problem, score may not be satisfying,\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\u003eClass of inputs is double, but keep in mind it may change in the future - most likely to uint64. Preferred output class is uint64.\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\u003eI'm open for proposals to improve test, i.e. verification of output which is far from perfect.\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":2323,"title":"Pandigital number n°3 (Inspired by Project Euler 32)","description":"After Problem 2319 and 2320.\r\n\r\nAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE. For example, the 5-digit number 15234, is 1 through 5 pandigital.\r\n\r\nThe product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital ([391867254]).\r\n\r\nFind the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through n pandigital (n is given in input).\r\n\r\nHINT1: Some products can be obtained in more than one way so be sure to only include it once in your sum.\r\n\r\nHINT2: All in good time...  \r\n\r\n","description_html":"\u003cp\u003eAfter Problem 2319 and 2320.\u003c/p\u003e\u003cp\u003eAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE. For example, the 5-digit number 15234, is 1 through 5 pandigital.\u003c/p\u003e\u003cp\u003eThe product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital ([391867254]).\u003c/p\u003e\u003cp\u003eFind the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through n pandigital (n is given in input).\u003c/p\u003e\u003cp\u003eHINT1: Some products can be obtained in more than one way so be sure to only include it once in your sum.\u003c/p\u003e\u003cp\u003eHINT2: All in good time...\u003c/p\u003e","function_template":"function y = pandigital_sum(n)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 3;\r\ny_correct = [];\r\nassert(isequal(pandigital_sum(x),y_correct))\r\n%%\r\nx = 4;\r\ny_correct = 12;\r\nassert(isequal(pandigital_sum(x),y_correct))\r\n%%\r\nx = 5;\r\ny_correct = 52;\r\nassert(isequal(pandigital_sum(x),y_correct))\r\n%%\r\nx = 6;\r\ny_correct = 162;\r\nassert(isequal(pandigital_sum(x),y_correct))\r\n%%\r\nx = 7;\r\ny_correct = []; % Strange no ?\r\nassert(isequal(pandigital_sum(x),y_correct))\r\n\r\n%%\r\nx = 8;\r\ny_correct = 13458;\r\nassert(isequal(pandigital_sum(x),y_correct))\r\n\r\n\r\n%% You obtain the Project Euler n°32 solution with n=9\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":3,"created_by":5390,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":"2019-10-23T23:21:29.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-05-15T10:08:43.000Z","updated_at":"2025-12-19T11:41:31.000Z","published_at":"2014-05-15T10:20:54.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAfter Problem 2319 and 2320.\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\u003eAn n-digit number is pandigital if it makes use of all the digits 1 to n exactly ONCE. For example, the 5-digit number 15234, is 1 through 5 pandigital.\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\u003eThe product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital ([391867254]).\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\u003eFind the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through n pandigital (n is given in input).\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\u003eHINT1: Some products can be obtained in more than one way so be sure to only include it once in your sum.\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\u003eHINT2: All in good time...\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":1826,"title":"Find vampire numbers","description":"A vampire number is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\r\nat most one of x and y are divisible by 10;\r\nx and y have the same number of digits; and\r\nThe digits in v consist of the digits of x and y (including anyrepetitions).\r\nIf these conditions are met, x and y are known as \"fangs\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\r\nWrite a function that returns all the vampire numbers in a given array. The output is a vector.\r\nExample: disp(find_vampire(1000:2000) 1260 1395 1435 1530 1827\r\nSee also:  Problem 1825. Find all vampire fangs and Problem 1804. Fangs of a vampire number.","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: 265.3px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 406.5px 132.65px; transform-origin: 406.5px 132.65px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 21px; text-align: left; transform-origin: 383.5px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 5.025px 7.81667px; transform-origin: 5.025px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA\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=\"\"\u003evampire number\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: 307.642px 7.81667px; transform-origin: 307.642px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 61.3px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: decimal; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 390.5px 30.65px; transform-origin: 390.5px 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: 362.5px 10.2167px; text-align: left; transform-origin: 362.5px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 134.558px 7.81667px; transform-origin: 134.558px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eat most one of x and y are divisible by 10;\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: 362.5px 10.2167px; text-align: left; transform-origin: 362.5px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 142.933px 7.81667px; transform-origin: 142.933px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ex and y have the same number of digits; and\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: 362.5px 10.2167px; text-align: left; transform-origin: 362.5px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 228.358px 7.81667px; transform-origin: 228.358px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe digits in v consist of the digits of x and y (including anyrepetitions).\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 383.5px 21px; text-align: left; transform-origin: 383.5px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 383.5px 7.81667px; transform-origin: 383.5px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf these conditions are met, x and y are known as \"fangs\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\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.242px 7.81667px; transform-origin: 294.242px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that returns all the vampire numbers in a given array. The output is a vector.\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: 215.517px 7.81667px; transform-origin: 215.517px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample: disp(find_vampire(1000:2000) 1260 1395 1435 1530 1827\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: 32.9417px 7.81667px; transform-origin: 32.9417px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSee also: \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=\"\"\u003eProblem 1825. Find all vampire fangs\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: 13.9583px 7.81667px; transform-origin: 13.9583px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and\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=\"\"\u003eProblem 1804. Fangs of a vampire number\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: 2.23333px 7.81667px; transform-origin: 2.23333px 7.81667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y =find_vampire(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nfiletext = fileread('find_vampire.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp') ...\r\n    || contains(filetext, '1260') || contains(filetext, 'intersect') ;\r\n%test case enhanced on 01-08-2024\r\n%intersect and the elements themselves were used to hard-code the problem\r\nassert(~illegal)\r\n\r\n%%\r\nx = 1000:2000;\r\nv = find_vampire(x);\r\nv_correct = [1260 1395 1435 1530 1827];\r\nassert(isequal(v,v_correct))\r\n\r\n%%\r\nx = 1:999;\r\nv = find_vampire(x);\r\nassert(isempty(v))\r\n\r\n%%\r\nx = reshape(2000:2999,100,[]);\r\nv = find_vampire(x);\r\nv_correct = 2187;\r\nassert(isequal(v,v_correct))\r\n\r\n%%\r\nx = [];\r\nv = find_vampire(x);\r\nassert(isempty(v))\r\n\r\n%%\r\nx = -2000:-1000;\r\nv = find_vampire(x);\r\nassert(isempty(v))\r\n\r\n%%\r\nx = 125000:125501;\r\nv = find_vampire(x);\r\nv_correct = [125248 125433 125460 125500];\r\nassert(isequal(v,v_correct))","published":true,"deleted":false,"likes_count":12,"comments_count":7,"created_by":1011,"edited_by":223089,"edited_at":"2024-08-01T16:28:29.000Z","deleted_by":null,"deleted_at":null,"solvers_count":394,"test_suite_updated_at":"2024-08-01T16:28:29.000Z","rescore_all_solutions":false,"group_id":8,"created_at":"2013-08-14T22:41:30.000Z","updated_at":"2026-02-15T13:30:53.000Z","published_at":"2013-08-14T22:42:12.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003evampire number\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is a number v that is the product of two numbers x and y such that the following conditions are satisfied:\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eat most one of x and y are divisible by 10;\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex and y have the same number of digits; and\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=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe digits in v consist of the digits of x and y (including anyrepetitions).\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\u003eIf these conditions are met, x and y are known as \\\"fangs\\\" of v. For example, 1260 is a vampire number because 1260 = 21*60, so 21 and 60 are the fangs.\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\u003eWrite a function that returns all the vampire numbers in a given array. The output is 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample: disp(find_vampire(1000:2000) 1260 1395 1435 1530 1827\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\u003eSee also: \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\u003eProblem 1825. Find all vampire fangs\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\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\u003eProblem 1804. Fangs of a vampire number\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\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":1394,"title":"Prime Ladders","description":"A \u003chttp://en.wikipedia.org/wiki/Word_ladder word ladder\u003e transforms one word to another by means of single-letter mutations. So COLD can become WARM like so (there are often multiple solutions):\r\n\r\n COLD\r\n CORD\r\n CARD\r\n WARD\r\n WARM\r\n\r\nA number ladder does much the same thing, changing one digit at a time. A *prime ladder* is a number ladder with the additional constraint that each element is a prime number. Here is a prime ladder that connects 757 and 139\r\n\r\n 757 \r\n 157\r\n 137\r\n 139\r\n\r\nGiven two numbers p1 and p2, construct a prime ladder column vector in which p1 is the first element, p2 is the last element, and each successive row differs by exactly one digit from the preceding element. \r\n\r\nTo restate the above example, consider\r\n\r\n p1 = 757\r\n p2 = 139\r\n\r\nfor which an acceptable answer is\r\n\r\n ladder = [757; 157; 137; 139]\r\n\r\nYou can assume that p1 and p2 contain the same number of digits. I am not looking for a unique answer. I will only check that the conditions of a prime ladder are met.\r\n\r\n","description_html":"\u003cp\u003eA \u003ca href = \"http://en.wikipedia.org/wiki/Word_ladder\"\u003eword ladder\u003c/a\u003e transforms one word to another by means of single-letter mutations. So COLD can become WARM like so (there are often multiple solutions):\u003c/p\u003e\u003cpre\u003e COLD\r\n CORD\r\n CARD\r\n WARD\r\n WARM\u003c/pre\u003e\u003cp\u003eA number ladder does much the same thing, changing one digit at a time. A \u003cb\u003eprime ladder\u003c/b\u003e is a number ladder with the additional constraint that each element is a prime number. Here is a prime ladder that connects 757 and 139\u003c/p\u003e\u003cpre\u003e 757 \r\n 157\r\n 137\r\n 139\u003c/pre\u003e\u003cp\u003eGiven two numbers p1 and p2, construct a prime ladder column vector in which p1 is the first element, p2 is the last element, and each successive row differs by exactly one digit from the preceding element.\u003c/p\u003e\u003cp\u003eTo restate the above example, consider\u003c/p\u003e\u003cpre\u003e p1 = 757\r\n p2 = 139\u003c/pre\u003e\u003cp\u003efor which an acceptable answer is\u003c/p\u003e\u003cpre\u003e ladder = [757; 157; 137; 139]\u003c/pre\u003e\u003cp\u003eYou can assume that p1 and p2 contain the same number of digits. I am not looking for a unique answer. I will only check that the conditions of a prime ladder are met.\u003c/p\u003e","function_template":"function ladder = prime_ladder(p1,p2)\r\n  ladder = 0;\r\nend","test_suite":"%%\r\n\r\np1 = 13;\r\np2 = 29;\r\nladder = prime_ladder(p1,p2);\r\n\r\nassert(all(isprime(ladder)))\r\nassert(iscolumn(ladder))\r\nassert(ladder(1)==p1)\r\nassert(ladder(end)==p2)\r\nassert(all(sum(diff(num2str(ladder))~=0,2)==1))\r\n\r\n%%\r\n\r\np1 = 389;\r\np2 = 269;\r\nladder = prime_ladder(p1,p2);\r\n\r\nassert(all(isprime(ladder)))\r\nassert(iscolumn(ladder))\r\nassert(ladder(1)==p1)\r\nassert(ladder(end)==p2)\r\nassert(all(sum(diff(num2str(ladder))~=0,2)==1))\r\n\r\n%%\r\n\r\np1 = 761;\r\np2 = 397;\r\nladder = prime_ladder(p1,p2);\r\n\r\nassert(all(isprime(ladder)))\r\nassert(iscolumn(ladder))\r\nassert(ladder(1)==p1)\r\nassert(ladder(end)==p2)\r\nassert(all(sum(diff(num2str(ladder))~=0,2)==1))\r\n\r\n%%\r\n\r\np1 = 983;\r\np2 = 239;\r\nladder = prime_ladder(p1,p2);\r\n\r\nassert(all(isprime(ladder)))\r\nassert(iscolumn(ladder))\r\nassert(ladder(1)==p1)\r\nassert(ladder(end)==p2)\r\nassert(all(sum(diff(num2str(ladder))~=0,2)==1))\r\n\r\n%%\r\n\r\np1 = 271;\r\np2 = 439;\r\nladder = prime_ladder(p1,p2);\r\n\r\nassert(all(isprime(ladder)))\r\nassert(iscolumn(ladder))\r\nassert(ladder(1)==p1)\r\nassert(ladder(end)==p2)\r\nassert(all(sum(diff(num2str(ladder))~=0,2)==1))\r\n\r\n%%\r\n\r\np1 = 877;\r\np2 = 733;\r\nladder = prime_ladder(p1,p2);\r\n\r\nassert(all(isprime(ladder)))\r\nassert(iscolumn(ladder))\r\nassert(ladder(1)==p1)\r\nassert(ladder(end)==p2)\r\nassert(all(sum(diff(num2str(ladder))~=0,2)==1))\r\n\r\n%%\r\n\r\np1 = 2267;\r\np2 = 1153;\r\nladder = prime_ladder(p1,p2);\r\n\r\nassert(all(isprime(ladder)))\r\nassert(iscolumn(ladder))\r\nassert(ladder(1)==p1)\r\nassert(ladder(end)==p2)\r\nassert(all(sum(diff(num2str(ladder))~=0,2)==1))\r\n","published":true,"deleted":false,"likes_count":10,"comments_count":3,"created_by":7,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":55,"test_suite_updated_at":"2013-03-27T21:24:26.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-03-26T22:51:16.000Z","updated_at":"2026-01-03T14:28:57.000Z","published_at":"2013-03-27T15:28:59.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA\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/Word_ladder\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eword ladder\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e transforms one word to another by means of single-letter mutations. So COLD can become WARM like so (there are often multiple solutions):\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[ COLD\\n CORD\\n CARD\\n WARD\\n WARM]]\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\u003eA number ladder does much the same thing, changing one digit at a time. A\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eprime ladder\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is a number ladder with the additional constraint that each element is a prime number. Here is a prime ladder that connects 757 and 139\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[ 757 \\n 157\\n 137\\n 139]]\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 two numbers p1 and p2, construct a prime ladder column vector in which p1 is the first element, p2 is the last element, and each successive row differs by exactly one digit from the preceding element.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 restate the above example, consider\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[ p1 = 757\\n p2 = 139]]\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\u003efor which an acceptable answer 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[ ladder = [757; 157; 137; 139]]]\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 can assume that p1 and p2 contain the same number of digits. I am not looking for a unique answer. I will only check that the conditions of a prime ladder are met.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"group:\"Magic Numbers III\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"group:\"Magic Numbers III\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"group":[["group:\"Magic Numbers III\"","","\"","Magic Numbers III","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f45e5801e20\u003e":["Magic Numbers III"],"#\u003cMathWorks::Search::Field:0x00007f45e5801d80\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f45e5801380\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f45e5802140\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f45e58020a0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f45e5801f60\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f45e5801ec0\u003e":"group:\"Magic Numbers III\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f45e5801ec0\u003e":"group:\"Magic Numbers III\""},"queried_facets":{"#\u003cMathWorks::Search::Field:0x00007f45e5801e20\u003e":["Magic Numbers III"]}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"group:\"Magic Numbers III\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"group":[["group:\"Magic Numbers III\"","","\"","Magic Numbers III","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f45e5801e20\u003e":["Magic Numbers III"],"#\u003cMathWorks::Search::Field:0x00007f45e5801d80\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f45e5801380\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f45e5802140\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f45e58020a0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f45e5801f60\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f45e5801ec0\u003e":"group:\"Magic Numbers III\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f45e5801ec0\u003e":"group:\"Magic Numbers III\""},"queried_facets":{"#\u003cMathWorks::Search::Field:0x00007f45e5801e20\u003e":["Magic Numbers III"]}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":2492,"difficulty_rating":"easy"},{"id":2491,"difficulty_rating":"easy"},{"id":1673,"difficulty_rating":"easy"},{"id":2051,"difficulty_rating":"easy-medium"},{"id":2721,"difficulty_rating":"easy-medium"},{"id":2319,"difficulty_rating":"easy-medium"},{"id":1804,"difficulty_rating":"easy-medium"},{"id":2320,"difficulty_rating":"easy-medium"},{"id":1697,"difficulty_rating":"easy-medium"},{"id":1477,"difficulty_rating":"medium"},{"id":1672,"difficulty_rating":"medium"},{"id":1825,"difficulty_rating":"medium"},{"id":2838,"difficulty_rating":"medium"},{"id":2323,"difficulty_rating":"medium"},{"id":1826,"difficulty_rating":"medium-hard"},{"id":1394,"difficulty_rating":"medium-hard"}]}}