{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-04-06T14:01:22.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2026-04-06T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":2521,"title":"Find out sum of prime number till given number","description":"Find out sum of prime number till given number \r\n\r\nExample, if number is 10, then answer must be 17. ","description_html":"\u003cp\u003eFind out sum of prime number till given number\u003c/p\u003e\u003cp\u003eExample, if number is 10, then answer must be 17.\u003c/p\u003e","function_template":"function y = sum_prime(n)\r\n  y = n;\r\nend","test_suite":"%%\r\nn=10;\r\ny_correct = 17;\r\nassert(isequal(sum_prime(n),y_correct))\r\n%%\r\nn=1;\r\ny_correct = 0;\r\nassert(isequal(sum_prime(n),y_correct))\r\n%%\r\nn=1000;\r\ny_correct =  76127;\r\nassert(isequal(sum_prime(n),y_correct))\r\n%%\r\nn=185;\r\ny_correct =  3447;\r\nassert(isequal(sum_prime(n),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":27760,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":271,"test_suite_updated_at":"2014-08-20T07:38:14.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-08-20T07:36:26.000Z","updated_at":"2026-03-12T06:36:06.000Z","published_at":"2014-08-20T07:38:14.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\u003eFind out sum of prime number till given 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\u003eExample, if number is 10, then answer must be 17.\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":1761,"title":"Primes Faster for Large N","description":"This Challenge is to improve the \"primes\" function for speed. This may be accomplished by fixing memory usage.\r\n\r\nThe Matlab function \"primes\" has a very efficient sieving method but it suffers from a memory usage issue that may bump into a user's RAM size causing \"out of memory\", significant slow down, or Matlab freeze.\r\n\r\nCody appears to have 2GB of RAM based upon \"out of memory\" messages observed.\r\n\r\nThe test case of 2^28 starts to bump into memory limit affects but will complete with the standard primes function.\r\n\r\nThe reference solution can process N=2^33 on a 16GB machine in 284sec.\r\n\r\n*Input:* N  (max of primes to find)\r\n\r\n*Output:* vector of primes  (all primes less than or equal to N)\r\n\r\n*Scoring:* Time to find all primes \u003c 2^28\r\n\r\n*Hints:*\r\n\r\n  1) Doubles use 8 bytes; logicals use 1 byte\r\n  2) The method p = p(p\u003e0); is good but can be improved\r\n  3) The method p = 1:2:n; creates a double and is a little slow\r\n  4) Usage of profiler and Task Manager combined give performance insights\r\n\r\n*Related:* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1763-primes-for-large-n-2-30-system-memory-limit Primes 2^30\u003e\r\n\r\n*Matlab 2014a incorporated the speed enhancement of logicals*","description_html":"\u003cp\u003eThis Challenge is to improve the \"primes\" function for speed. This may be accomplished by fixing memory usage.\u003c/p\u003e\u003cp\u003eThe Matlab function \"primes\" has a very efficient sieving method but it suffers from a memory usage issue that may bump into a user's RAM size causing \"out of memory\", significant slow down, or Matlab freeze.\u003c/p\u003e\u003cp\u003eCody appears to have 2GB of RAM based upon \"out of memory\" messages observed.\u003c/p\u003e\u003cp\u003eThe test case of 2^28 starts to bump into memory limit affects but will complete with the standard primes function.\u003c/p\u003e\u003cp\u003eThe reference solution can process N=2^33 on a 16GB machine in 284sec.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e N  (max of primes to find)\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e vector of primes  (all primes less than or equal to N)\u003c/p\u003e\u003cp\u003e\u003cb\u003eScoring:\u003c/b\u003e Time to find all primes \u0026lt; 2^28\u003c/p\u003e\u003cp\u003e\u003cb\u003eHints:\u003c/b\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e1) Doubles use 8 bytes; logicals use 1 byte\r\n2) The method p = p(p\u0026gt;0); is good but can be improved\r\n3) The method p = 1:2:n; creates a double and is a little slow\r\n4) Usage of profiler and Task Manager combined give performance insights\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eRelated:\u003c/b\u003e \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1763-primes-for-large-n-2-30-system-memory-limit\"\u003ePrimes 2^30\u003c/a\u003e\u003c/p\u003e\u003cp\u003e\u003cb\u003eMatlab 2014a incorporated the speed enhancement of logicals\u003c/b\u003e\u003c/p\u003e","function_template":"function p = primes_faster(n) % The mathworks primes function\r\n%PRIMES Generate list of prime numbers.\r\n%   PRIMES(N) is a row vector of the prime numbers less than or \r\n%   equal to N.  A prime number is one that has no factors other\r\n%   than 1 and itself.\r\n%\r\n%   Class support for input N:\r\n%      float: double, single\r\n%\r\n%   See also FACTOR, ISPRIME.\r\n\r\n%   Copyright 1984-2004 The MathWorks, Inc. \r\n%   $Revision: 1.16.4.3 $  $Date: 2010/08/23 23:13:13 $\r\n\r\nif length(n)~=1 \r\n  error(message('MATLAB:primes:InputNotScalar')); \r\nend\r\nif n \u003c 2, p = zeros(1,0,class(n)); return, end\r\np = 1:2:n;\r\nq = length(p);\r\np(1) = 2;\r\nfor k = 3:2:sqrt(n)\r\n  if p((k+1)/2)\r\n     p(((k*k+1)/2):k:q) = 0;\r\n  end\r\nend\r\np = p(p\u003e0);\r\n\r\nend","test_suite":"feval(@assignin,'caller','score',30); %\r\n%%\r\ntic\r\nassert(isequal(primes_faster(1),primes(1)))\r\nassert(isequal(primes_faster(2),primes(2)))\r\nfor i=1:100\r\n n=randi(2000,1);\r\n assert(isequal(primes_faster(n),primes(n)))\r\nend\r\ntoc\r\n%%\r\ntic\r\nta=clock;\r\n p = primes_faster(2^28);\r\nt1=etime(clock,ta); % time in sec\r\n\r\nfprintf('P 2^28 %12i %10.3f\\n',length(p),t1)\r\n\r\nassert(isequal(size(unique(p),2),14630843))\r\n\r\nptr=randi(7603553,1,10); % small to avoid timeout\r\n\r\npchk=double(p(ptr));\r\n\r\nassert(all(isprime(pchk)))\r\n\r\nfeval(  @assignin,'caller','score',floor(min(30,t1))  );\r\ntoc","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":56,"test_suite_updated_at":"2013-08-07T00:21:13.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-07-30T02:37:44.000Z","updated_at":"2025-12-15T18:33:37.000Z","published_at":"2013-07-30T04:30:58.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 Challenge is to improve the \\\"primes\\\" function for speed. This may be accomplished by fixing memory usage.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 Matlab function \\\"primes\\\" has a very efficient sieving method but it suffers from a memory usage issue that may bump into a user's RAM size causing \\\"out of memory\\\", significant slow down, or Matlab freeze.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCody appears to have 2GB of RAM based upon \\\"out of memory\\\" messages observed.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 test case of 2^28 starts to bump into memory limit affects but will complete with the standard primes function.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 reference solution can process N=2^33 on a 16GB machine in 284sec.\u003c/w:t\u003e\u003c/w:r\u003e\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 N (max of primes to find)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e vector of primes (all primes less than or equal to N)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eScoring:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Time to find all primes \u0026lt; 2^28\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eHints:\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) Doubles use 8 bytes; logicals use 1 byte\\n2) The method p = p(p\u003e0); is good but can be improved\\n3) The method p = 1:2:n; creates a double and is a little slow\\n4) Usage of profiler and Task Manager combined give performance insights]]\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:\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/1763-primes-for-large-n-2-30-system-memory-limit\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePrimes 2^30\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eMatlab 2014a incorporated the speed enhancement of logicals\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":43142,"title":"Find max prime number","description":"Given integer number n. Find the max prime number (mpn) that smaller than or equal to n.\r\nExample:\r\n\r\n  n = 10\r\n  --\u003e mpn = 7 ","description_html":"\u003cp\u003eGiven integer number n. Find the max prime number (mpn) that smaller than or equal to n.\r\nExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003en = 10\r\n--\u0026gt; mpn = 7 \r\n\u003c/pre\u003e","function_template":"function mpn = max_prime(n)\r\n  mpn = n;\r\nend","test_suite":"%%\r\nn = 10;\r\ny_correct = 7;\r\nassert(isequal(max_prime(n),y_correct))\r\n\r\n%%\r\nn = 30;\r\ny_correct = 29;\r\nassert(isequal(max_prime(n),y_correct))","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":87297,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":192,"test_suite_updated_at":"2016-10-07T09:06:51.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-07T09:05:59.000Z","updated_at":"2026-02-05T20:27:46.000Z","published_at":"2016-10-07T09:06:51.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven integer number n. Find the max prime number (mpn) that smaller than or equal to n. Example:\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[n = 10\\n--\u003e mpn = 7]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42749,"title":"Find the nearest prime","description":"Given a positive integer 'n', the task is to find a prime number greater than or equal to 'n'. \r\n\r\nExample 1\r\n\r\nIf given 'n' is 10, then the closest prime number greater than 10 is 11 at a distance of 1. So 11 must be returned.  \r\n\r\nExample 2\r\n\r\nIf the given 'n' is 17, then the closest prime number is itself at a distance of 0. So 17 must be returned.  \r\n\r\nThe returned prime number must be greater than or equal to 'n'.  \r\n","description_html":"\u003cp\u003eGiven a positive integer 'n', the task is to find a prime number greater than or equal to 'n'.\u003c/p\u003e\u003cp\u003eExample 1\u003c/p\u003e\u003cp\u003eIf given 'n' is 10, then the closest prime number greater than 10 is 11 at a distance of 1. So 11 must be returned.\u003c/p\u003e\u003cp\u003eExample 2\u003c/p\u003e\u003cp\u003eIf the given 'n' is 17, then the closest prime number is itself at a distance of 0. So 17 must be returned.\u003c/p\u003e\u003cp\u003eThe returned prime number must be greater than or equal to 'n'.\u003c/p\u003e","function_template":"function y = closestPrime(n)\r\n  y = 2;  \r\nend","test_suite":"%%\r\nn = 3;\r\ny_correct = 3;\r\nassert(isequal(closestPrime(n),y_correct))\r\n\r\n%%\r\nn = 20;\r\ny_correct = 23;\r\nassert(isequal(closestPrime(n),y_correct))\r\n\r\n%%\r\nn = 86;\r\ny_correct = 89;\r\nassert(isequal(closestPrime(n),y_correct))\r\n\r\n%%\r\nn = 250;\r\ny_correct = 251;\r\nassert(isequal(closestPrime(n),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":66083,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":104,"test_suite_updated_at":"2016-02-23T21:20:07.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-02-23T21:05:45.000Z","updated_at":"2025-12-11T05:21:59.000Z","published_at":"2016-02-23T21:20:07.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a positive integer 'n', the task is to find a prime number greater than or equal to 'n'.\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 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf given 'n' is 10, then the closest prime number greater than 10 is 11 at a distance of 1. So 11 must be returned.\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 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\u003eIf the given 'n' is 17, then the closest prime number is itself at a distance of 0. So 17 must be returned.\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 returned prime number must be greater than or equal to 'n'.\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":896,"title":"Sophie Germain prime","description":"In number theory, a prime number p is a *Sophie Germain prime* if 2p + 1 is also prime. For example, 23 is a Sophie Germain prime because it is a prime and 2 × 23 + 1 = 47, and 47 is also a prime number. These numbers are named after French mathematician Marie-Sophie Germain.\r\n\r\nSee \u003chttp://en.wikipedia.org/wiki/Sophie_Germain_prime Sophie Germain prime\u003e article on Wikipedia.\r\n\r\n\r\nIn this Problem , the input is a number and you must return true or false if this number is a Sophie Germain prime.","description_html":"\u003cp\u003eIn number theory, a prime number p is a \u003cb\u003eSophie Germain prime\u003c/b\u003e if 2p + 1 is also prime. For example, 23 is a Sophie Germain prime because it is a prime and 2 × 23 + 1 = 47, and 47 is also a prime number. These numbers are named after French mathematician Marie-Sophie Germain.\u003c/p\u003e\u003cp\u003eSee \u003ca href=\"http://en.wikipedia.org/wiki/Sophie_Germain_prime\"\u003eSophie Germain prime\u003c/a\u003e article on Wikipedia.\u003c/p\u003e\u003cp\u003eIn this Problem , the input is a number and you must return true or false if this number is a Sophie Germain prime.\u003c/p\u003e","function_template":"function tf = your_fcn_name(x)\r\n  tf = true;\r\nend","test_suite":"%%\r\np = 233;\r\ny_correct = true;\r\nassert(isequal(your_fcn_name(p),y_correct))\r\n\r\n%%\r\np = 23;\r\ny_correct14 = true;\r\nassert(isequal(your_fcn_name(p),y_correct14))\r\n\r\n%%\r\np = 22;\r\ny_correct14 = false;\r\nassert(isequal(your_fcn_name(p),y_correct14))\r\n\r\n%% \r\np = 1 % p must also be a prime number !!\r\ny_correct1t = false;\r\nassert(isequal(your_fcn_name(p),y_correct1t))\r\n\r\n%% \r\np = 14 % p must also be a prime number !!\r\ncorrect1t = false;\r\nassert(isequal(your_fcn_name(p),correct1t))\r\n\r\n%% \r\np = 29 \r\ncorrect1tp = true;\r\nassert(isequal(your_fcn_name(p),correct1tp))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":2,"created_by":639,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1065,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":44,"created_at":"2012-08-10T13:04:11.000Z","updated_at":"2026-02-15T10:55:16.000Z","published_at":"2012-08-10T13:04:11.000Z","restored_at":"2018-10-10T14:57:27.000Z","restored_by":null,"spam":false,"simulink":false,"admin_reviewed":true,"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\u003eIn number theory, a prime number p is 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\u003eSophie Germain prime\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e if 2p + 1 is also prime. For example, 23 is a Sophie Germain prime because it is a prime and 2 × 23 + 1 = 47, and 47 is also a prime number. These numbers are named after French mathematician Marie-Sophie Germain.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSee\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/Sophie_Germain_prime\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSophie Germain prime\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e article on Wikipedia.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn this Problem , the input is a number and you must return true or false if this number is a Sophie Germain prime.\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":981,"title":"Find nearest prime number less than input number ","description":"Find nearest prime number less than input number. \r\n\r\nFor example: if the input number is 125, then the nearest prime number which is less than this number is 113.\r\n\r\nBe careful, in that 1 is not a prime number. So there is NO prime less than 2.","description_html":"\u003cp\u003eFind nearest prime number less than input number.\u003c/p\u003e\u003cp\u003eFor example: if the input number is 125, then the nearest prime number which is less than this number is 113.\u003c/p\u003e\u003cp\u003eBe careful, in that 1 is not a prime number. So there is NO prime less than 2.\u003c/p\u003e","function_template":"function y = minorprime(n)\r\n  y = n-1;\r\nend","test_suite":"%%\r\nn = 127;\r\ny_correct = 113;\r\nassert(isequal(minorprime(n),y_correct))\r\n%%\r\nn = 125;\r\ny_correct = 113;\r\nassert(isequal(minorprime(n),y_correct))\r\n%% \r\nn = 3;\r\ny_correct = 2;\r\nassert(isequal(minorprime(n),y_correct))\r\n%% \r\nn = 2;\r\ny_correct = [];\r\nassert(isequal(minorprime(n),y_correct))\r\n%%\r\nn = 1328;\r\ny_correct = 1327;\r\nassert(isequal(minorprime(n),y_correct))\r\n\r\n%%\r\nn = 5050109;\r\ny_correct = 5050099;\r\nassert(isequal(minorprime(n),y_correct))\r\n\r\n%%\r\npn = primes(1e6);\r\nind = max(100,floor(numel(pn)*rand));\r\nn = pn(ind) - 1;\r\ny_correct = pn(ind - 1);\r\nassert(isequal(minorprime(n),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":8,"comments_count":8,"created_by":4320,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1017,"test_suite_updated_at":"2018-02-22T01:26:00.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2012-10-09T12:11:53.000Z","updated_at":"2026-02-15T11:02:12.000Z","published_at":"2012-10-09T12:11:53.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eFind nearest prime number less than input 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\u003eFor example: if the input number is 125, then the nearest prime number which is less than this number is 113.\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\u003eBe careful, in that 1 is not a prime number. So there is NO prime less than 2.\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":2337,"title":"Sum of big primes without primes","description":"Inspired by Project Euler n°10 (I am quite obviously a fan).\r\nWith problem n°250 by Doug, you can find some global methods to compute the sum of all the primes below the input n.\r\nFor example, the sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.\r\nBut how to proceed (in time) with big number and WITHOUT the primes function ?\r\nHINTS: sum(primes(n)) is possible here but why miss the wonderfull Sieve of Eratosthenes ?\r\nhttp://en.wikipedia.org/wiki/Sieve_of_Eratosthenes","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: 171px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 85.5px; transform-origin: 407px 85.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: 183px 8px; transform-origin: 183px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eInspired by Project Euler n°10 (I am quite obviously a fan).\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: 376px 8px; transform-origin: 376px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWith problem n°250 by Doug, you can find some global methods to compute the sum of all the primes below the input n.\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: 208px 8px; transform-origin: 208px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, the sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.\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: 255.5px 8px; transform-origin: 255.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eBut how to proceed (in time) with big number and WITHOUT the primes function ?\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: 288.5px 8px; transform-origin: 288.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eHINTS: sum(primes(n)) is possible here but why miss the wonderfull Sieve of Eratosthenes ?\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\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehttp://en.wikipedia.org/wiki/Sieve_of_Eratosthenes\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = big_euler10(n)\r\n  y = x;\r\nend","test_suite":"%%\r\nfiletext = fileread('big_euler10.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp') || ...\r\n          contains(filetext, 'primes'); \r\nassert(~illegal)\r\n\r\n%%\r\nx = 1;\r\ny_correct = 0;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%%\r\nx = 10;\r\ny_correct = 17;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%%\r\nx = 100;\r\ny_correct = 1060;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%%\r\nx = 1000;\r\ny_correct = 76127;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%%\r\nx = 10000;\r\ny_correct = 5736396;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%%\r\nx = 100000;\r\ny_correct = 454396537;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%%\r\nx = 1000000;\r\ny_correct = 37550402023;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%%\r\nx = 1000000-100;\r\ny_correct = 37542402433;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%%\r\nx = 2000000-1000;\r\ny_correct = 142781862782;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%% Solution of Project Euler 10 with n=2000000\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":3,"created_by":5390,"edited_by":223089,"edited_at":"2023-06-05T10:25:19.000Z","deleted_by":null,"deleted_at":null,"solvers_count":239,"test_suite_updated_at":"2023-06-05T10:25:19.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-05-27T21:25:58.000Z","updated_at":"2026-03-29T22:02:38.000Z","published_at":"2014-05-27T21:51:18.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\u003eInspired by Project Euler n°10 (I am quite obviously a fan).\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\u003eWith problem n°250 by Doug, you can find some global methods to compute the sum of all the primes below the input n.\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 sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.\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\u003eBut how to proceed (in time) with big number and WITHOUT the primes function ?\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\u003eHINTS: sum(primes(n)) is possible here but why miss the wonderfull Sieve of Eratosthenes ?\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:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://en.wikipedia.org/wiki/Sieve_of_Eratosthenes\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":42914,"title":"Counting the Grand Primes","description":"A grand prime pair is a pair of primes, p1 and p2=p1+1000, such that both numbers are prime. Like a twin prime pair, where the difference is 2, the members of a grand prime pair always have a difference of 1000. Some facts about grand prime pairs, so that you can test your code:\r\n\r\n1. The smallest grand prime pair is [13,1013], the 100th such pair is [3229,4229].\r\n\r\n2. There are 37 grand prime pairs such that the larger element of the pair is no larger than 2000.\r\n\r\n3. There should be infinitely many grand prime pairs.\r\n\r\n4. All such grand prime pairs must have the property that the smaller element of the pair is of the form 6*k+1, for some integer k.\r\n\r\nWrite a function that counts the number of grand prime pairs that exist, such that the larger element of the pair is no larger than N. I'll be nice and not ask you to compute that result for N too large, 1e8 seems a reasonable upper limit.","description_html":"\u003cp\u003eA grand prime pair is a pair of primes, p1 and p2=p1+1000, such that both numbers are prime. Like a twin prime pair, where the difference is 2, the members of a grand prime pair always have a difference of 1000. Some facts about grand prime pairs, so that you can test your code:\u003c/p\u003e\u003cp\u003e1. The smallest grand prime pair is [13,1013], the 100th such pair is [3229,4229].\u003c/p\u003e\u003cp\u003e2. There are 37 grand prime pairs such that the larger element of the pair is no larger than 2000.\u003c/p\u003e\u003cp\u003e3. There should be infinitely many grand prime pairs.\u003c/p\u003e\u003cp\u003e4. All such grand prime pairs must have the property that the smaller element of the pair is of the form 6*k+1, for some integer k.\u003c/p\u003e\u003cp\u003eWrite a function that counts the number of grand prime pairs that exist, such that the larger element of the pair is no larger than N. I'll be nice and not ask you to compute that result for N too large, 1e8 seems a reasonable upper limit.\u003c/p\u003e","function_template":"function y = grandPrimeCounter(N)\r\n  y = N;\r\nend","test_suite":"%%\r\nN = 1000;\r\ny_correct = 0;\r\nassert(isequal(grandPrimeCounter(N),y_correct))\r\n\r\n%%\r\nN = 1234;\r\ny_correct = 13;\r\nassert(isequal(grandPrimeCounter(N),y_correct))\r\n\r\n%%\r\nN = 12345;\r\ny_correct = 280;\r\nassert(isequal(grandPrimeCounter(N),y_correct))\r\n\r\n%%\r\nN = 123456;\r\ny_correct = 1925;\r\nassert(isequal(grandPrimeCounter(N),y_correct))\r\n\r\n%%\r\nN = 1234567;\r\ny_correct = 13142;\r\nassert(isequal(grandPrimeCounter(N),y_correct))\r\n\r\n%%\r\nN = 99999900;\r\ny_correct = 586509;\r\nassert(isequal(grandPrimeCounter(N),y_correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":544,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":63,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-07-22T17:41:15.000Z","updated_at":"2026-03-16T15:24:57.000Z","published_at":"2016-07-22T18:20:37.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 grand prime pair is a pair of primes, p1 and p2=p1+1000, such that both numbers are prime. Like a twin prime pair, where the difference is 2, the members of a grand prime pair always have a difference of 1000. Some facts about grand prime pairs, so that you can test your code:\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\u003e1. The smallest grand prime pair is [13,1013], the 100th such pair is [3229,4229].\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\u003e2. There are 37 grand prime pairs such that the larger element of the pair is no larger than 2000.\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\u003e3. There should be infinitely many grand prime pairs.\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\u003e4. All such grand prime pairs must have the property that the smaller element of the pair is of the form 6*k+1, for some integer k.\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 counts the number of grand prime pairs that exist, such that the larger element of the pair is no larger than N. I'll be nice and not ask you to compute that result for N too large, 1e8 seems a reasonable upper limit.\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":1567,"title":"Make a vector of prime numbers","description":"Input(n) - length of vector with prime numbers\r\n\r\nOutput(v) - vector of prime numbers\r\n\r\nExample:\r\n\r\n* n=1; v=2\r\n* n=3; v=[2 3 5]\r\n* n=7; v=[2 3 5 7 11 13 17]","description_html":"\u003cp\u003eInput(n) - length of vector with prime numbers\u003c/p\u003e\u003cp\u003eOutput(v) - vector of prime numbers\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cul\u003e\u003cli\u003en=1; v=2\u003c/li\u003e\u003cli\u003en=3; v=[2 3 5]\u003c/li\u003e\u003cli\u003en=7; v=[2 3 5 7 11 13 17]\u003c/li\u003e\u003c/ul\u003e","function_template":"function v = prime_vec(n)\r\n  v = n;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 2;\r\nassert(isequal(prime_vec(x),y_correct))\r\n%%\r\nx = 3;\r\ny_correct = [2 3 5];\r\nassert(isequal(prime_vec(x),y_correct))\r\n%%\r\nx = 7;\r\ny_correct = [2 3 5 7 11 13 17];\r\nassert(isequal(prime_vec(x),y_correct))\r\n%%\r\nx = 60;\r\ny_correct =[2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281];\r\nassert(isequal(prime_vec(x),y_correct))\r\n%%\r\nx = 4896;\r\ny_correct = 4896;\r\nassert(isequal(length(prime_vec(x)),y_correct))","published":true,"deleted":false,"likes_count":6,"comments_count":1,"created_by":14249,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":966,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-06T11:49:21.000Z","updated_at":"2026-02-15T12:16:05.000Z","published_at":"2013-06-06T11:49:21.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput(n) - length of vector with prime numbers\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput(v) - vector of prime numbers\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en=1; v=2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en=3; v=[2 3 5]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en=7; v=[2 3 5 7 11 13 17]\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":42830,"title":"Hilbert numbers","description":"Given a positive integer, n, return h as follows:\r\n\r\n1. If n is not a \u003chttps://en.wikipedia.org/wiki/Hilbert_number Hilbert number\u003e, return h = 0\r\n\r\n2. If n is a Hilbert prime, return h = 1\r\n\r\n3. If n is a Hilbert non-prime, return all of its Hilbert factors in one sorted vector. \r\n\r\nExample 1:\r\n\r\nn = 3\r\n\r\nh = 0\r\n\r\nExample 2:\r\n\r\nn = 5\r\n\r\nh = 1\r\n\r\nExample 3:\r\n\r\nn = 45\r\n\r\nh = [5 9]\r\n\r\nExample 4:\r\n\r\nn = 441\r\n\r\nh = [9 21 49]","description_html":"\u003cp\u003eGiven a positive integer, n, return h as follows:\u003c/p\u003e\u003cp\u003e1. If n is not a \u003ca href = \"https://en.wikipedia.org/wiki/Hilbert_number\"\u003eHilbert number\u003c/a\u003e, return h = 0\u003c/p\u003e\u003cp\u003e2. If n is a Hilbert prime, return h = 1\u003c/p\u003e\u003cp\u003e3. If n is a Hilbert non-prime, return all of its Hilbert factors in one sorted vector.\u003c/p\u003e\u003cp\u003eExample 1:\u003c/p\u003e\u003cp\u003en = 3\u003c/p\u003e\u003cp\u003eh = 0\u003c/p\u003e\u003cp\u003eExample 2:\u003c/p\u003e\u003cp\u003en = 5\u003c/p\u003e\u003cp\u003eh = 1\u003c/p\u003e\u003cp\u003eExample 3:\u003c/p\u003e\u003cp\u003en = 45\u003c/p\u003e\u003cp\u003eh = [5 9]\u003c/p\u003e\u003cp\u003eExample 4:\u003c/p\u003e\u003cp\u003en = 441\u003c/p\u003e\u003cp\u003eh = [9 21 49]\u003c/p\u003e","function_template":"function h = hilbertnum(n)\r\n  h = 0;\r\nend","test_suite":"%%\r\nn = 3;\r\nh_correct = 0;\r\nassert(isequal(hilbertnum(n),h_correct))\r\n\r\n%%\r\nn = 5;\r\nh_correct = 1;\r\nassert(isequal(hilbertnum(n),h_correct))\r\n\r\n%%\r\nn = 45;\r\nh_correct = [5 9];\r\nassert(isequal(hilbertnum(n),h_correct))\r\n\r\n%%\r\nn = 1169;\r\nh_correct = 1;\r\nassert(isequal(hilbertnum(n),h_correct))\r\n\r\n%%\r\nn = 441;\r\nh_correct = [9 21 49];\r\nassert(isequal(hilbertnum(n),h_correct))\r\n\r\n%%\r\nn = 45678;\r\nh_correct = 0;\r\nassert(isequal(hilbertnum(n),h_correct))\r\n\r\n%%\r\nn = 56789;\r\nh_correct = [109 521];\r\nassert(isequal(hilbertnum(n),h_correct))\r\n\r\n%%\r\nn = 353535;\r\nh_correct = 0;\r\nassert(isequal(hilbertnum(n),h_correct))\r\n\r\n%%\r\nn = 35353549;\r\nh_correct = [49 77 613 749 1177 30037 47201 57673 459137 721501];\r\nassert(isequal(hilbertnum(n),h_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":61,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-04-25T18:22:53.000Z","updated_at":"2026-03-02T11:43:26.000Z","published_at":"2016-04-25T18:22:53.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a positive integer, n, return h as follows:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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. If n is not a\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/Hilbert_number\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eHilbert number\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, return h = 0\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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. If n is a Hilbert prime, return h = 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\u003e3. If n is a Hilbert non-prime, return all of its Hilbert factors in one sorted vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 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\u003en = 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\u003eh = 0\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 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\u003en = 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eh = 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\u003eExample 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\u003en = 45\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eh = [5 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\u003eExample 4:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en = 441\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eh = [9 21 49]\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":1096,"title":"Largest Twin Primes","description":"\u003chttp://en.wikipedia.org/wiki/Twin_prime Twin primes\u003e are primes p1, p2 = p1 + 2 such that both p1 and p2 are prime numbers. Given a positive integer N (\u003e=5) what are the largest twin primes (in order) \u003c= N. For example, if N = 20 then p1 = 17 and p2 = 19.","description_html":"\u003cp\u003e\u003ca href=\"http://en.wikipedia.org/wiki/Twin_prime\"\u003eTwin primes\u003c/a\u003e are primes p1, p2 = p1 + 2 such that both p1 and p2 are prime numbers. Given a positive integer N (\u003e=5) what are the largest twin primes (in order) \u0026lt;= N. For example, if N = 20 then p1 = 17 and p2 = 19.\u003c/p\u003e","function_template":"function [y] = your_fcn_name(N)\r\n  y = [N-2 N]; \r\nend","test_suite":"%%\r\nx = 1001;\r\ny_correct = [881 883];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 1964;\r\ny_correct = [1949 1951];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 123456789;\r\ny_correct = [123456209 123456211];\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":8873,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":988,"test_suite_updated_at":"2012-12-05T19:39:01.000Z","rescore_all_solutions":false,"group_id":44,"created_at":"2012-12-05T19:36:12.000Z","updated_at":"2026-02-15T11:07:16.000Z","published_at":"2012-12-05T19:37:15.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:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Twin_prime\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eTwin primes\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e are primes p1, p2 = p1 + 2 such that both p1 and p2 are prime numbers. Given a positive integer N (\u0026gt;=5) what are the largest twin primes (in order) \u0026lt;= N. For example, if N = 20 then p1 = 17 and p2 = 19.\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":525,"title":"Mersenne Primes","description":"A Mersenne prime is a prime number of the form M = 2^p - 1, where p is another prime number.  For example, 31 is a Mersenne prime because 31 = 2^5 - 1 and both 31 and 5 are prime numbers.\r\n\r\nImplement the function isMersenne(x) so that it returns true if x is a Mersenne prime and false otherwise.  Your solution should work for all positive integer values of x less than 1,000,000,000 (one billion).","description_html":"\u003cp\u003eA Mersenne prime is a prime number of the form M = 2^p - 1, where p is another prime number.  For example, 31 is a Mersenne prime because 31 = 2^5 - 1 and both 31 and 5 are prime numbers.\u003c/p\u003e\u003cp\u003eImplement the function isMersenne(x) so that it returns true if x is a Mersenne prime and false otherwise.  Your solution should work for all positive integer values of x less than 1,000,000,000 (one billion).\u003c/p\u003e","function_template":"function y = isMersenne(x)\r\n  y = false;\r\nend","test_suite":"%%\r\nx = 3;\r\ny_correct = true;\r\nassert(isequal(isMersenne(x),y_correct))\r\n\r\n%%\r\nx = 127;\r\ny_correct = true;\r\nassert(isequal(isMersenne(x),y_correct))\r\n\r\n%%\r\nx = 157;\r\ny_correct = false;\r\nassert(isequal(isMersenne(x),y_correct))\r\n\r\n%%\r\nx = 2047;\r\ny_correct = false;\r\nassert(isequal(isMersenne(x),y_correct))\r\n\r\n%%\r\nx = 8191;\r\ny_correct = true;\r\nassert(isequal(isMersenne(x),y_correct))\r\n\r\n%%\r\nx = 524287;\r\ny_correct = true;\r\nassert(isequal(isMersenne(x),y_correct))\r\n\r\n%%\r\nx = 536870911;\r\ny_correct = false;\r\nassert(isequal(isMersenne(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":4,"created_by":1537,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":968,"test_suite_updated_at":"2012-03-24T15:03:26.000Z","rescore_all_solutions":false,"group_id":44,"created_at":"2012-03-24T14:32:54.000Z","updated_at":"2026-02-15T11:05:47.000Z","published_at":"2012-03-24T14:36:27.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 Mersenne prime is a prime number of the form M = 2^p - 1, where p is another prime number. For example, 31 is a Mersenne prime because 31 = 2^5 - 1 and both 31 and 5 are prime numbers.\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\u003eImplement the function isMersenne(x) so that it returns true if x is a Mersenne prime and false otherwise. Your solution should work for all positive integer values of x less than 1,000,000,000 (one billion).\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":241,"title":"Project Euler: Problem 7, Nth prime","description":"By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.\r\nWhat is the Nth prime number?\r\nThank you to Project Euler Problem 7","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: 81px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 40.5px; transform-origin: 407px 40.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: 298px 8px; transform-origin: 298px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eBy listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.\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: 97.5px 8px; transform-origin: 97.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWhat is the Nth prime 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: 41.5px 8px; transform-origin: 41.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThank you to\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 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=\"\"\u003eProject Euler Problem 7\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = euler007(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nfiletext = fileread('euler007.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp') || ...\r\n          contains(filetext, 'if') || contains(filetext, 'switch'); \r\nassert(~illegal)\r\n\r\n%%\r\nx = 6;\r\ny_correct = 13;\r\nassert(isequal(euler007(x),y_correct))\r\n\r\n%%\r\nx = 69;\r\ny_correct = 347;\r\nassert(isequal(euler007(x),y_correct))\r\n\r\n%%\r\nx = 420;\r\ny_correct = 2903;\r\nassert(isequal(euler007(x),y_correct))\r\n\r\n%%\r\nx = 1729;\r\ny_correct = 14759;\r\nassert(isequal(euler007(x),y_correct))\r\n\r\n%%\r\nx = 10001;\r\ny_correct = 104743;\r\nassert(isequal(euler007(x),y_correct))\r\n\r\n%%\r\nx = 123456;\r\ny_correct = 1632899;\r\nassert(isequal(euler007(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":21,"comments_count":11,"created_by":240,"edited_by":223089,"edited_at":"2022-12-27T06:14:17.000Z","deleted_by":null,"deleted_at":null,"solvers_count":1753,"test_suite_updated_at":"2022-12-27T06:14:17.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-02-02T21:11:56.000Z","updated_at":"2026-03-15T19:01:28.000Z","published_at":"2012-02-03T14:47:05.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\u003eBy listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhat is the Nth prime 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\u003eThank you to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProject Euler Problem 7\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":1722,"title":"Find the next prime number","description":"Find the next prime number or numbers for given n. For example:\r\n\r\n  n = 1;\r\n  out = 2;\r\n\r\nor\r\n\r\n  n = [5 7];\r\n  out = [7 11];\r\n\r\nGood luck!\r\n","description_html":"\u003cp\u003eFind the next prime number or numbers for given n. For example:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003en = 1;\r\nout = 2;\r\n\u003c/pre\u003e\u003cp\u003eor\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003en = [5 7];\r\nout = [7 11];\r\n\u003c/pre\u003e\u003cp\u003eGood luck!\u003c/p\u003e","function_template":"function y = nextprimenum(n)\r\n  y = n;\r\nend","test_suite":"%%\r\nn = 1;\r\nout = 2;\r\nassert(isequal(nextprimenum(n),out))\r\n%%\r\nn = 7;\r\nout = 11;\r\nassert(isequal(nextprimenum(n),out))\r\n%%\r\nn = [1 2 3 4 5 6 7 8 9];\r\nout = [2 3 5 5 7 7 11 11 11];\r\nassert(isequal(nextprimenum(n),out))\r\n%%\r\nn = [71 25 63 47 65 36 47 58 69];\r\nout = [73 29 67 53 67 37 53 59 71];\r\nassert(isequal(nextprimenum(n),out))\r\n%%\r\nn = [171 255 636 487 675 369 477 538 969];\r\nout =  [173 257 641 491 677 373 479 541 971];\r\nassert(isequal(nextprimenum(n),out))\r\n%%\r\nn = [172541 255564 632436 4564587 6778675 334469 475647 575638 96879];\r\nout =  [172553 255571 632447 4564589 6778691 334487 475649 575647 96893];\r\nassert(isequal(nextprimenum(n),out))","published":true,"deleted":false,"likes_count":6,"comments_count":0,"created_by":15013,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":836,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-07-17T21:54:33.000Z","updated_at":"2026-02-15T12:18:36.000Z","published_at":"2013-07-17T21:54:32.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\u003eFind the next prime number or numbers for given n. For example:\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[n = 1;\\nout = 2;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eor\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[n = [5 7];\\nout = [7 11];]]\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\u003eGood 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":2910,"title":"Mersenne Primes vs. All Primes","description":"A Mersenne prime (M) is a prime number of the form M = 2^p - 1, where p is another prime number. \u003chttps://www.mathworks.com/matlabcentral/cody/problems/525-mersenne-primes Problem 525\u003e asks the user to determine if a number is a Mersenne prime. In this problem, you are tasked with returning the number of primes numbers below the input number, n, that are Mersenne primes and the fraction of all primes below that input number that the Mersenne primes represent.\r\n\r\nFor example, for n = 100, there are 25 primes numbers: 2, 3, 5, 7, ..., 89, 97. As far as Mersenne primes go, there are only three that are less than 100: 2^2 - 1 = 3, 2^3 - 1 = 7, and 2^5 - 1 = 31. The corresponding fraction would be 3/25.","description_html":"\u003cp\u003eA Mersenne prime (M) is a prime number of the form M = 2^p - 1, where p is another prime number. \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/525-mersenne-primes\"\u003eProblem 525\u003c/a\u003e asks the user to determine if a number is a Mersenne prime. In this problem, you are tasked with returning the number of primes numbers below the input number, n, that are Mersenne primes and the fraction of all primes below that input number that the Mersenne primes represent.\u003c/p\u003e\u003cp\u003eFor example, for n = 100, there are 25 primes numbers: 2, 3, 5, 7, ..., 89, 97. As far as Mersenne primes go, there are only three that are less than 100: 2^2 - 1 = 3, 2^3 - 1 = 7, and 2^5 - 1 = 31. The corresponding fraction would be 3/25.\u003c/p\u003e","function_template":"function [y,f] = Mersenne_prime_comp(n)\r\n y = 1;\r\n f = 0;\r\nend","test_suite":"%%\r\nn = 1e2;\r\ny_correct = 3;\r\nf_correct = 3/25;\r\n[y,f] = Mersenne_prime_comp(n);\r\nassert(isequal(y,y_correct))\r\nassert(isequal(f,f_correct))\r\n\r\n%%\r\nn = 1e3;\r\ny_correct = 4;\r\nf_correct = 0.023809523809524;\r\n[y,f] = Mersenne_prime_comp(n);\r\nassert(isequal(y,y_correct))\r\nassert(abs(f-f_correct)\u003c(10*eps))\r\n\r\n%%\r\nn = 1e4;\r\ny_correct = 5;\r\nf_correct = 0.004068348250610;\r\n[y,f] = Mersenne_prime_comp(n);\r\nassert(isequal(y,y_correct))\r\nassert(abs(f-f_correct)\u003c(10*eps))\r\n\r\n%%\r\nn = 1e5;\r\ny_correct = 5;\r\nf_correct = 5.212677231025855e-04;\r\n[y,f] = Mersenne_prime_comp(n);\r\nassert(isequal(y,y_correct))\r\nassert(abs(f-f_correct)\u003c(10*eps))\r\n\r\n%%\r\nn = 1e6;\r\ny_correct = 7;\r\nf_correct = 8.917424647761727e-05;\r\n[y,f] = Mersenne_prime_comp(n);\r\nassert(isequal(y,y_correct))\r\nassert(abs(f-f_correct)\u003c(10*eps))\r\n","published":true,"deleted":false,"likes_count":8,"comments_count":2,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":846,"test_suite_updated_at":"2015-02-01T04:14:08.000Z","rescore_all_solutions":false,"group_id":29,"created_at":"2015-02-01T03:56:07.000Z","updated_at":"2026-04-01T10:02:01.000Z","published_at":"2015-02-01T04:14:08.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA Mersenne prime (M) is a prime number of the form M = 2^p - 1, where p is another prime number.\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://www.mathworks.com/matlabcentral/cody/problems/525-mersenne-primes\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 525\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e asks the user to determine if a number is a Mersenne prime. In this problem, you are tasked with returning the number of primes numbers below the input number, n, that are Mersenne primes and the fraction of all primes below that input number that the Mersenne primes represent.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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, for n = 100, there are 25 primes numbers: 2, 3, 5, 7, ..., 89, 97. As far as Mersenne primes go, there are only three that are less than 100: 2^2 - 1 = 3, 2^3 - 1 = 7, and 2^5 - 1 = 31. The corresponding fraction would be 3/25.\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":60,"title":"The Goldbach Conjecture","description":"The Goldbach conjecture asserts that every even integer greater than 2 can be expressed as the sum of two primes.\r\nGiven the even integer n, return primes p1 and p2 that satisfy the condition n = p1 + p2. Note that the primes are not always unique. The test is not sensitive to order or uniqueness. You just need to meet the appropriate conditions.\r\nExample:\r\n Input  n = 286\r\n Output (any of the following is acceptable) \r\n        [  3 283]\r\n        [283   3]\r\n        [  5 281]\r\n        [107 179]\r\n        [137 149]","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: 255.033px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 127.517px; transform-origin: 407px 127.517px; 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: 12.5px 8px; transform-origin: 12.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe\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=\"\"\u003eGoldbach conjecture\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: 287px 8px; transform-origin: 287px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e asserts that every even integer greater than 2 can be expressed as the sum of two primes.\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: 368.5px 8px; transform-origin: 368.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven the even integer n, return primes p1 and p2 that satisfy the condition n = p1 + p2. Note that the primes are not always unique. The test is not sensitive to order or uniqueness. You just need to meet the appropriate conditions.\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: 28.5px 8px; transform-origin: 28.5px 8px; 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: 143.033px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 71.5167px; transform-origin: 404px 71.5167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; 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: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\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: 60px 8.5px; tab-size: 4; transform-origin: 60px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 32px 8.5px; transform-origin: 32px 8.5px; \"\u003e Input  \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 28px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 28px 8.5px; \"\u003en = 286\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: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; 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: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\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: 180px 8.5px; tab-size: 4; transform-origin: 180px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e Output (any of the following is acceptable) \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: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; 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: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\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: 68px 8.5px; tab-size: 4; transform-origin: 68px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        [  3 283]\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: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; 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: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\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: 68px 8.5px; tab-size: 4; transform-origin: 68px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        [283   3]\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: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; 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: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\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: 68px 8.5px; tab-size: 4; transform-origin: 68px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        [  5 281]\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: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; 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: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\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: 68px 8.5px; tab-size: 4; transform-origin: 68px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        [107 179]\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: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; 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: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\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: 68px 8.5px; tab-size: 4; transform-origin: 68px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        [137 149]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [p1,p2] = goldbach(n)\r\n  p1 = n;\r\n  p2 = n;\r\nend","test_suite":"%%\r\nfiletext = fileread('goldbach.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp'); \r\nassert(~illegal)\r\n\r\n%%\r\nnList = 28:6:76;\r\nfor i = 1:length(nList)\r\n  n = nList(i);\r\n  [p1,p2] = goldbach(n)\r\n  assert(isprime(p1) \u0026\u0026 isprime(p2) \u0026\u0026 (p1+p2==n));\r\nend\r\n\r\n%%\r\nnList = [18 20 22 100 102 114 1000 2000 36 3600];\r\nfor i = 1:length(nList)\r\n  n = nList(i);\r\n  [p1,p2] = goldbach(n)\r\n  assert(isprime(p1) \u0026\u0026 isprime(p2) \u0026\u0026 (p1+p2==n));\r\nend","published":true,"deleted":false,"likes_count":60,"comments_count":17,"created_by":1,"edited_by":223089,"edited_at":"2023-06-05T15:48:22.000Z","deleted_by":null,"deleted_at":null,"solvers_count":5972,"test_suite_updated_at":"2023-06-05T15:48:22.000Z","rescore_all_solutions":false,"group_id":2,"created_at":"2012-01-18T01:00:25.000Z","updated_at":"2026-03-23T12:29:13.000Z","published_at":"2012-01-18T01:00:25.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\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=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGoldbach conjecture\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e asserts that every even integer greater than 2 can be expressed as the sum of two primes.\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 the even integer n, return primes p1 and p2 that satisfy the condition n = p1 + p2. Note that the primes are not always unique. The test is not sensitive to order or uniqueness. You just need to meet the appropriate conditions.\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[ Input  n = 286\\n Output (any of the following is acceptable) \\n        [  3 283]\\n        [283   3]\\n        [  5 281]\\n        [107 179]\\n        [137 149]]]\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":1095,"title":"Circular Primes (based on Project Euler, problem 35)","description":"The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.\r\n\r\nThere are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.\r\n\r\nGiven a number x, write a MATLAB script that will tell you the number of circular primes less than or equal to x as well as a sorted list of what the circular prime numbers are.","description_html":"\u003cp\u003eThe number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.\u003c/p\u003e\u003cp\u003eThere are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.\u003c/p\u003e\u003cp\u003eGiven a number x, write a MATLAB script that will tell you the number of circular primes less than or equal to x as well as a sorted list of what the circular prime numbers are.\u003c/p\u003e","function_template":"function [how_many what_numbers]=circular_prime(x)\r\n    how_many=3;\r\n    what_numbers=[2 3 5];\r\nend","test_suite":"%%\r\n[y numbers]=circular_prime(197)\r\nassert(isequal(y,16)\u0026\u0026isequal(numbers,[2 3 5 7 11 13 17 31 37 71 73 79 97 113 131 197]))\r\n%%\r\n[y numbers]=circular_prime(100)\r\nassert(isequal(y,13)\u0026\u0026isequal(numbers,[2 3 5 7 11 13 17 31 37 71 73 79 97]))\r\n%%\r\n[y numbers]=circular_prime(250)\r\nassert(isequal(y,17)\u0026\u0026isequal(numbers,[2 3 5 7 11 13 17 31 37 71 73 79 97 113 131 197 199]))\r\n%%\r\n[y numbers]=circular_prime(2000)\r\nassert(isequal(y,27)\u0026\u0026isequal(numbers,[2 3 5 7 11 13 17 31 37 71 73 79 97 113 131 197 199 311 337 373 719 733 919 971 991 1193 1931]))\r\n%%\r\n[y numbers]=circular_prime(10000)\r\nassert(isequal(y,33)\u0026\u0026isequal(numbers,[2 3 5 7 11 13 17 31 37 71 73 79 97 113 131 197 199 311 337 373 719 733 919 971 991 1193 1931 3119 3779 7793 7937 9311 9377]))\r\n%%\r\n[y numbers]=circular_prime(54321)\r\nassert(isequal(y,38)\u0026\u0026isequal(numbers,[2 3 5 7 11 13 17 31 37 71 73 79 97 113 131 197 199 311 337 373 719 733 919 971 991 1193 1931 3119 3779 7793 7937 9311 9377 11939 19391 19937 37199 39119]))\r\n","published":true,"deleted":false,"likes_count":10,"comments_count":6,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":651,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-12-05T18:02:09.000Z","updated_at":"2026-02-15T10:48:53.000Z","published_at":"2012-12-05T18:02:09.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\u003eThe number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.\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\u003eThere are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.\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 number x, write a MATLAB script that will tell you the number of circular primes less than or equal to x as well as a sorted list of what the circular prime numbers are.\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":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":2521,"title":"Find out sum of prime number till given number","description":"Find out sum of prime number till given number \r\n\r\nExample, if number is 10, then answer must be 17. ","description_html":"\u003cp\u003eFind out sum of prime number till given number\u003c/p\u003e\u003cp\u003eExample, if number is 10, then answer must be 17.\u003c/p\u003e","function_template":"function y = sum_prime(n)\r\n  y = n;\r\nend","test_suite":"%%\r\nn=10;\r\ny_correct = 17;\r\nassert(isequal(sum_prime(n),y_correct))\r\n%%\r\nn=1;\r\ny_correct = 0;\r\nassert(isequal(sum_prime(n),y_correct))\r\n%%\r\nn=1000;\r\ny_correct =  76127;\r\nassert(isequal(sum_prime(n),y_correct))\r\n%%\r\nn=185;\r\ny_correct =  3447;\r\nassert(isequal(sum_prime(n),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":27760,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":271,"test_suite_updated_at":"2014-08-20T07:38:14.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-08-20T07:36:26.000Z","updated_at":"2026-03-12T06:36:06.000Z","published_at":"2014-08-20T07:38:14.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\u003eFind out sum of prime number till given 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\u003eExample, if number is 10, then answer must be 17.\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":1761,"title":"Primes Faster for Large N","description":"This Challenge is to improve the \"primes\" function for speed. This may be accomplished by fixing memory usage.\r\n\r\nThe Matlab function \"primes\" has a very efficient sieving method but it suffers from a memory usage issue that may bump into a user's RAM size causing \"out of memory\", significant slow down, or Matlab freeze.\r\n\r\nCody appears to have 2GB of RAM based upon \"out of memory\" messages observed.\r\n\r\nThe test case of 2^28 starts to bump into memory limit affects but will complete with the standard primes function.\r\n\r\nThe reference solution can process N=2^33 on a 16GB machine in 284sec.\r\n\r\n*Input:* N  (max of primes to find)\r\n\r\n*Output:* vector of primes  (all primes less than or equal to N)\r\n\r\n*Scoring:* Time to find all primes \u003c 2^28\r\n\r\n*Hints:*\r\n\r\n  1) Doubles use 8 bytes; logicals use 1 byte\r\n  2) The method p = p(p\u003e0); is good but can be improved\r\n  3) The method p = 1:2:n; creates a double and is a little slow\r\n  4) Usage of profiler and Task Manager combined give performance insights\r\n\r\n*Related:* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1763-primes-for-large-n-2-30-system-memory-limit Primes 2^30\u003e\r\n\r\n*Matlab 2014a incorporated the speed enhancement of logicals*","description_html":"\u003cp\u003eThis Challenge is to improve the \"primes\" function for speed. This may be accomplished by fixing memory usage.\u003c/p\u003e\u003cp\u003eThe Matlab function \"primes\" has a very efficient sieving method but it suffers from a memory usage issue that may bump into a user's RAM size causing \"out of memory\", significant slow down, or Matlab freeze.\u003c/p\u003e\u003cp\u003eCody appears to have 2GB of RAM based upon \"out of memory\" messages observed.\u003c/p\u003e\u003cp\u003eThe test case of 2^28 starts to bump into memory limit affects but will complete with the standard primes function.\u003c/p\u003e\u003cp\u003eThe reference solution can process N=2^33 on a 16GB machine in 284sec.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e N  (max of primes to find)\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e vector of primes  (all primes less than or equal to N)\u003c/p\u003e\u003cp\u003e\u003cb\u003eScoring:\u003c/b\u003e Time to find all primes \u0026lt; 2^28\u003c/p\u003e\u003cp\u003e\u003cb\u003eHints:\u003c/b\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e1) Doubles use 8 bytes; logicals use 1 byte\r\n2) The method p = p(p\u0026gt;0); is good but can be improved\r\n3) The method p = 1:2:n; creates a double and is a little slow\r\n4) Usage of profiler and Task Manager combined give performance insights\r\n\u003c/pre\u003e\u003cp\u003e\u003cb\u003eRelated:\u003c/b\u003e \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1763-primes-for-large-n-2-30-system-memory-limit\"\u003ePrimes 2^30\u003c/a\u003e\u003c/p\u003e\u003cp\u003e\u003cb\u003eMatlab 2014a incorporated the speed enhancement of logicals\u003c/b\u003e\u003c/p\u003e","function_template":"function p = primes_faster(n) % The mathworks primes function\r\n%PRIMES Generate list of prime numbers.\r\n%   PRIMES(N) is a row vector of the prime numbers less than or \r\n%   equal to N.  A prime number is one that has no factors other\r\n%   than 1 and itself.\r\n%\r\n%   Class support for input N:\r\n%      float: double, single\r\n%\r\n%   See also FACTOR, ISPRIME.\r\n\r\n%   Copyright 1984-2004 The MathWorks, Inc. \r\n%   $Revision: 1.16.4.3 $  $Date: 2010/08/23 23:13:13 $\r\n\r\nif length(n)~=1 \r\n  error(message('MATLAB:primes:InputNotScalar')); \r\nend\r\nif n \u003c 2, p = zeros(1,0,class(n)); return, end\r\np = 1:2:n;\r\nq = length(p);\r\np(1) = 2;\r\nfor k = 3:2:sqrt(n)\r\n  if p((k+1)/2)\r\n     p(((k*k+1)/2):k:q) = 0;\r\n  end\r\nend\r\np = p(p\u003e0);\r\n\r\nend","test_suite":"feval(@assignin,'caller','score',30); %\r\n%%\r\ntic\r\nassert(isequal(primes_faster(1),primes(1)))\r\nassert(isequal(primes_faster(2),primes(2)))\r\nfor i=1:100\r\n n=randi(2000,1);\r\n assert(isequal(primes_faster(n),primes(n)))\r\nend\r\ntoc\r\n%%\r\ntic\r\nta=clock;\r\n p = primes_faster(2^28);\r\nt1=etime(clock,ta); % time in sec\r\n\r\nfprintf('P 2^28 %12i %10.3f\\n',length(p),t1)\r\n\r\nassert(isequal(size(unique(p),2),14630843))\r\n\r\nptr=randi(7603553,1,10); % small to avoid timeout\r\n\r\npchk=double(p(ptr));\r\n\r\nassert(all(isprime(pchk)))\r\n\r\nfeval(  @assignin,'caller','score',floor(min(30,t1))  );\r\ntoc","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":56,"test_suite_updated_at":"2013-08-07T00:21:13.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-07-30T02:37:44.000Z","updated_at":"2025-12-15T18:33:37.000Z","published_at":"2013-07-30T04:30:58.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 Challenge is to improve the \\\"primes\\\" function for speed. This may be accomplished by fixing memory usage.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 Matlab function \\\"primes\\\" has a very efficient sieving method but it suffers from a memory usage issue that may bump into a user's RAM size causing \\\"out of memory\\\", significant slow down, or Matlab freeze.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCody appears to have 2GB of RAM based upon \\\"out of memory\\\" messages observed.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 test case of 2^28 starts to bump into memory limit affects but will complete with the standard primes function.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 reference solution can process N=2^33 on a 16GB machine in 284sec.\u003c/w:t\u003e\u003c/w:r\u003e\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 N (max of primes to find)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e vector of primes (all primes less than or equal to N)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eScoring:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Time to find all primes \u0026lt; 2^28\u003c/w:t\u003e\u003c/w:r\u003e\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\u003eHints:\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) Doubles use 8 bytes; logicals use 1 byte\\n2) The method p = p(p\u003e0); is good but can be improved\\n3) The method p = 1:2:n; creates a double and is a little slow\\n4) Usage of profiler and Task Manager combined give performance insights]]\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:\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/1763-primes-for-large-n-2-30-system-memory-limit\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePrimes 2^30\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eMatlab 2014a incorporated the speed enhancement of logicals\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":43142,"title":"Find max prime number","description":"Given integer number n. Find the max prime number (mpn) that smaller than or equal to n.\r\nExample:\r\n\r\n  n = 10\r\n  --\u003e mpn = 7 ","description_html":"\u003cp\u003eGiven integer number n. Find the max prime number (mpn) that smaller than or equal to n.\r\nExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003en = 10\r\n--\u0026gt; mpn = 7 \r\n\u003c/pre\u003e","function_template":"function mpn = max_prime(n)\r\n  mpn = n;\r\nend","test_suite":"%%\r\nn = 10;\r\ny_correct = 7;\r\nassert(isequal(max_prime(n),y_correct))\r\n\r\n%%\r\nn = 30;\r\ny_correct = 29;\r\nassert(isequal(max_prime(n),y_correct))","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":87297,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":192,"test_suite_updated_at":"2016-10-07T09:06:51.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-07T09:05:59.000Z","updated_at":"2026-02-05T20:27:46.000Z","published_at":"2016-10-07T09:06:51.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven integer number n. Find the max prime number (mpn) that smaller than or equal to n. Example:\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[n = 10\\n--\u003e mpn = 7]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":42749,"title":"Find the nearest prime","description":"Given a positive integer 'n', the task is to find a prime number greater than or equal to 'n'. \r\n\r\nExample 1\r\n\r\nIf given 'n' is 10, then the closest prime number greater than 10 is 11 at a distance of 1. So 11 must be returned.  \r\n\r\nExample 2\r\n\r\nIf the given 'n' is 17, then the closest prime number is itself at a distance of 0. So 17 must be returned.  \r\n\r\nThe returned prime number must be greater than or equal to 'n'.  \r\n","description_html":"\u003cp\u003eGiven a positive integer 'n', the task is to find a prime number greater than or equal to 'n'.\u003c/p\u003e\u003cp\u003eExample 1\u003c/p\u003e\u003cp\u003eIf given 'n' is 10, then the closest prime number greater than 10 is 11 at a distance of 1. So 11 must be returned.\u003c/p\u003e\u003cp\u003eExample 2\u003c/p\u003e\u003cp\u003eIf the given 'n' is 17, then the closest prime number is itself at a distance of 0. So 17 must be returned.\u003c/p\u003e\u003cp\u003eThe returned prime number must be greater than or equal to 'n'.\u003c/p\u003e","function_template":"function y = closestPrime(n)\r\n  y = 2;  \r\nend","test_suite":"%%\r\nn = 3;\r\ny_correct = 3;\r\nassert(isequal(closestPrime(n),y_correct))\r\n\r\n%%\r\nn = 20;\r\ny_correct = 23;\r\nassert(isequal(closestPrime(n),y_correct))\r\n\r\n%%\r\nn = 86;\r\ny_correct = 89;\r\nassert(isequal(closestPrime(n),y_correct))\r\n\r\n%%\r\nn = 250;\r\ny_correct = 251;\r\nassert(isequal(closestPrime(n),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":66083,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":104,"test_suite_updated_at":"2016-02-23T21:20:07.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-02-23T21:05:45.000Z","updated_at":"2025-12-11T05:21:59.000Z","published_at":"2016-02-23T21:20:07.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a positive integer 'n', the task is to find a prime number greater than or equal to 'n'.\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 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf given 'n' is 10, then the closest prime number greater than 10 is 11 at a distance of 1. So 11 must be returned.\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 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\u003eIf the given 'n' is 17, then the closest prime number is itself at a distance of 0. So 17 must be returned.\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 returned prime number must be greater than or equal to 'n'.\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":896,"title":"Sophie Germain prime","description":"In number theory, a prime number p is a *Sophie Germain prime* if 2p + 1 is also prime. For example, 23 is a Sophie Germain prime because it is a prime and 2 × 23 + 1 = 47, and 47 is also a prime number. These numbers are named after French mathematician Marie-Sophie Germain.\r\n\r\nSee \u003chttp://en.wikipedia.org/wiki/Sophie_Germain_prime Sophie Germain prime\u003e article on Wikipedia.\r\n\r\n\r\nIn this Problem , the input is a number and you must return true or false if this number is a Sophie Germain prime.","description_html":"\u003cp\u003eIn number theory, a prime number p is a \u003cb\u003eSophie Germain prime\u003c/b\u003e if 2p + 1 is also prime. For example, 23 is a Sophie Germain prime because it is a prime and 2 × 23 + 1 = 47, and 47 is also a prime number. These numbers are named after French mathematician Marie-Sophie Germain.\u003c/p\u003e\u003cp\u003eSee \u003ca href=\"http://en.wikipedia.org/wiki/Sophie_Germain_prime\"\u003eSophie Germain prime\u003c/a\u003e article on Wikipedia.\u003c/p\u003e\u003cp\u003eIn this Problem , the input is a number and you must return true or false if this number is a Sophie Germain prime.\u003c/p\u003e","function_template":"function tf = your_fcn_name(x)\r\n  tf = true;\r\nend","test_suite":"%%\r\np = 233;\r\ny_correct = true;\r\nassert(isequal(your_fcn_name(p),y_correct))\r\n\r\n%%\r\np = 23;\r\ny_correct14 = true;\r\nassert(isequal(your_fcn_name(p),y_correct14))\r\n\r\n%%\r\np = 22;\r\ny_correct14 = false;\r\nassert(isequal(your_fcn_name(p),y_correct14))\r\n\r\n%% \r\np = 1 % p must also be a prime number !!\r\ny_correct1t = false;\r\nassert(isequal(your_fcn_name(p),y_correct1t))\r\n\r\n%% \r\np = 14 % p must also be a prime number !!\r\ncorrect1t = false;\r\nassert(isequal(your_fcn_name(p),correct1t))\r\n\r\n%% \r\np = 29 \r\ncorrect1tp = true;\r\nassert(isequal(your_fcn_name(p),correct1tp))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":2,"created_by":639,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1065,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":44,"created_at":"2012-08-10T13:04:11.000Z","updated_at":"2026-02-15T10:55:16.000Z","published_at":"2012-08-10T13:04:11.000Z","restored_at":"2018-10-10T14:57:27.000Z","restored_by":null,"spam":false,"simulink":false,"admin_reviewed":true,"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\u003eIn number theory, a prime number p is 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\u003eSophie Germain prime\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e if 2p + 1 is also prime. For example, 23 is a Sophie Germain prime because it is a prime and 2 × 23 + 1 = 47, and 47 is also a prime number. These numbers are named after French mathematician Marie-Sophie Germain.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSee\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/Sophie_Germain_prime\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSophie Germain prime\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e article on Wikipedia.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn this Problem , the input is a number and you must return true or false if this number is a Sophie Germain prime.\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":981,"title":"Find nearest prime number less than input number ","description":"Find nearest prime number less than input number. \r\n\r\nFor example: if the input number is 125, then the nearest prime number which is less than this number is 113.\r\n\r\nBe careful, in that 1 is not a prime number. So there is NO prime less than 2.","description_html":"\u003cp\u003eFind nearest prime number less than input number.\u003c/p\u003e\u003cp\u003eFor example: if the input number is 125, then the nearest prime number which is less than this number is 113.\u003c/p\u003e\u003cp\u003eBe careful, in that 1 is not a prime number. So there is NO prime less than 2.\u003c/p\u003e","function_template":"function y = minorprime(n)\r\n  y = n-1;\r\nend","test_suite":"%%\r\nn = 127;\r\ny_correct = 113;\r\nassert(isequal(minorprime(n),y_correct))\r\n%%\r\nn = 125;\r\ny_correct = 113;\r\nassert(isequal(minorprime(n),y_correct))\r\n%% \r\nn = 3;\r\ny_correct = 2;\r\nassert(isequal(minorprime(n),y_correct))\r\n%% \r\nn = 2;\r\ny_correct = [];\r\nassert(isequal(minorprime(n),y_correct))\r\n%%\r\nn = 1328;\r\ny_correct = 1327;\r\nassert(isequal(minorprime(n),y_correct))\r\n\r\n%%\r\nn = 5050109;\r\ny_correct = 5050099;\r\nassert(isequal(minorprime(n),y_correct))\r\n\r\n%%\r\npn = primes(1e6);\r\nind = max(100,floor(numel(pn)*rand));\r\nn = pn(ind) - 1;\r\ny_correct = pn(ind - 1);\r\nassert(isequal(minorprime(n),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":8,"comments_count":8,"created_by":4320,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1017,"test_suite_updated_at":"2018-02-22T01:26:00.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2012-10-09T12:11:53.000Z","updated_at":"2026-02-15T11:02:12.000Z","published_at":"2012-10-09T12:11:53.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eFind nearest prime number less than input 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\u003eFor example: if the input number is 125, then the nearest prime number which is less than this number is 113.\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\u003eBe careful, in that 1 is not a prime number. So there is NO prime less than 2.\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":2337,"title":"Sum of big primes without primes","description":"Inspired by Project Euler n°10 (I am quite obviously a fan).\r\nWith problem n°250 by Doug, you can find some global methods to compute the sum of all the primes below the input n.\r\nFor example, the sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.\r\nBut how to proceed (in time) with big number and WITHOUT the primes function ?\r\nHINTS: sum(primes(n)) is possible here but why miss the wonderfull Sieve of Eratosthenes ?\r\nhttp://en.wikipedia.org/wiki/Sieve_of_Eratosthenes","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: 171px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 85.5px; transform-origin: 407px 85.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: 183px 8px; transform-origin: 183px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eInspired by Project Euler n°10 (I am quite obviously a fan).\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: 376px 8px; transform-origin: 376px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWith problem n°250 by Doug, you can find some global methods to compute the sum of all the primes below the input n.\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: 208px 8px; transform-origin: 208px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example, the sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.\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: 255.5px 8px; transform-origin: 255.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eBut how to proceed (in time) with big number and WITHOUT the primes function ?\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: 288.5px 8px; transform-origin: 288.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eHINTS: sum(primes(n)) is possible here but why miss the wonderfull Sieve of Eratosthenes ?\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\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehttp://en.wikipedia.org/wiki/Sieve_of_Eratosthenes\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = big_euler10(n)\r\n  y = x;\r\nend","test_suite":"%%\r\nfiletext = fileread('big_euler10.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp') || ...\r\n          contains(filetext, 'primes'); \r\nassert(~illegal)\r\n\r\n%%\r\nx = 1;\r\ny_correct = 0;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%%\r\nx = 10;\r\ny_correct = 17;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%%\r\nx = 100;\r\ny_correct = 1060;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%%\r\nx = 1000;\r\ny_correct = 76127;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%%\r\nx = 10000;\r\ny_correct = 5736396;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%%\r\nx = 100000;\r\ny_correct = 454396537;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%%\r\nx = 1000000;\r\ny_correct = 37550402023;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%%\r\nx = 1000000-100;\r\ny_correct = 37542402433;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%%\r\nx = 2000000-1000;\r\ny_correct = 142781862782;\r\nassert(isequal(big_euler10(x),y_correct))\r\n%% Solution of Project Euler 10 with n=2000000\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":3,"created_by":5390,"edited_by":223089,"edited_at":"2023-06-05T10:25:19.000Z","deleted_by":null,"deleted_at":null,"solvers_count":239,"test_suite_updated_at":"2023-06-05T10:25:19.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-05-27T21:25:58.000Z","updated_at":"2026-03-29T22:02:38.000Z","published_at":"2014-05-27T21:51:18.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\u003eInspired by Project Euler n°10 (I am quite obviously a fan).\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\u003eWith problem n°250 by Doug, you can find some global methods to compute the sum of all the primes below the input n.\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 sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.\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\u003eBut how to proceed (in time) with big number and WITHOUT the primes function ?\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\u003eHINTS: sum(primes(n)) is possible here but why miss the wonderfull Sieve of Eratosthenes ?\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:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://en.wikipedia.org/wiki/Sieve_of_Eratosthenes\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":42914,"title":"Counting the Grand Primes","description":"A grand prime pair is a pair of primes, p1 and p2=p1+1000, such that both numbers are prime. Like a twin prime pair, where the difference is 2, the members of a grand prime pair always have a difference of 1000. Some facts about grand prime pairs, so that you can test your code:\r\n\r\n1. The smallest grand prime pair is [13,1013], the 100th such pair is [3229,4229].\r\n\r\n2. There are 37 grand prime pairs such that the larger element of the pair is no larger than 2000.\r\n\r\n3. There should be infinitely many grand prime pairs.\r\n\r\n4. All such grand prime pairs must have the property that the smaller element of the pair is of the form 6*k+1, for some integer k.\r\n\r\nWrite a function that counts the number of grand prime pairs that exist, such that the larger element of the pair is no larger than N. I'll be nice and not ask you to compute that result for N too large, 1e8 seems a reasonable upper limit.","description_html":"\u003cp\u003eA grand prime pair is a pair of primes, p1 and p2=p1+1000, such that both numbers are prime. Like a twin prime pair, where the difference is 2, the members of a grand prime pair always have a difference of 1000. Some facts about grand prime pairs, so that you can test your code:\u003c/p\u003e\u003cp\u003e1. The smallest grand prime pair is [13,1013], the 100th such pair is [3229,4229].\u003c/p\u003e\u003cp\u003e2. There are 37 grand prime pairs such that the larger element of the pair is no larger than 2000.\u003c/p\u003e\u003cp\u003e3. There should be infinitely many grand prime pairs.\u003c/p\u003e\u003cp\u003e4. All such grand prime pairs must have the property that the smaller element of the pair is of the form 6*k+1, for some integer k.\u003c/p\u003e\u003cp\u003eWrite a function that counts the number of grand prime pairs that exist, such that the larger element of the pair is no larger than N. I'll be nice and not ask you to compute that result for N too large, 1e8 seems a reasonable upper limit.\u003c/p\u003e","function_template":"function y = grandPrimeCounter(N)\r\n  y = N;\r\nend","test_suite":"%%\r\nN = 1000;\r\ny_correct = 0;\r\nassert(isequal(grandPrimeCounter(N),y_correct))\r\n\r\n%%\r\nN = 1234;\r\ny_correct = 13;\r\nassert(isequal(grandPrimeCounter(N),y_correct))\r\n\r\n%%\r\nN = 12345;\r\ny_correct = 280;\r\nassert(isequal(grandPrimeCounter(N),y_correct))\r\n\r\n%%\r\nN = 123456;\r\ny_correct = 1925;\r\nassert(isequal(grandPrimeCounter(N),y_correct))\r\n\r\n%%\r\nN = 1234567;\r\ny_correct = 13142;\r\nassert(isequal(grandPrimeCounter(N),y_correct))\r\n\r\n%%\r\nN = 99999900;\r\ny_correct = 586509;\r\nassert(isequal(grandPrimeCounter(N),y_correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":544,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":63,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-07-22T17:41:15.000Z","updated_at":"2026-03-16T15:24:57.000Z","published_at":"2016-07-22T18:20:37.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 grand prime pair is a pair of primes, p1 and p2=p1+1000, such that both numbers are prime. Like a twin prime pair, where the difference is 2, the members of a grand prime pair always have a difference of 1000. Some facts about grand prime pairs, so that you can test your code:\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\u003e1. The smallest grand prime pair is [13,1013], the 100th such pair is [3229,4229].\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\u003e2. There are 37 grand prime pairs such that the larger element of the pair is no larger than 2000.\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\u003e3. There should be infinitely many grand prime pairs.\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\u003e4. All such grand prime pairs must have the property that the smaller element of the pair is of the form 6*k+1, for some integer k.\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 counts the number of grand prime pairs that exist, such that the larger element of the pair is no larger than N. I'll be nice and not ask you to compute that result for N too large, 1e8 seems a reasonable upper limit.\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":1567,"title":"Make a vector of prime numbers","description":"Input(n) - length of vector with prime numbers\r\n\r\nOutput(v) - vector of prime numbers\r\n\r\nExample:\r\n\r\n* n=1; v=2\r\n* n=3; v=[2 3 5]\r\n* n=7; v=[2 3 5 7 11 13 17]","description_html":"\u003cp\u003eInput(n) - length of vector with prime numbers\u003c/p\u003e\u003cp\u003eOutput(v) - vector of prime numbers\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cul\u003e\u003cli\u003en=1; v=2\u003c/li\u003e\u003cli\u003en=3; v=[2 3 5]\u003c/li\u003e\u003cli\u003en=7; v=[2 3 5 7 11 13 17]\u003c/li\u003e\u003c/ul\u003e","function_template":"function v = prime_vec(n)\r\n  v = n;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 2;\r\nassert(isequal(prime_vec(x),y_correct))\r\n%%\r\nx = 3;\r\ny_correct = [2 3 5];\r\nassert(isequal(prime_vec(x),y_correct))\r\n%%\r\nx = 7;\r\ny_correct = [2 3 5 7 11 13 17];\r\nassert(isequal(prime_vec(x),y_correct))\r\n%%\r\nx = 60;\r\ny_correct =[2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281];\r\nassert(isequal(prime_vec(x),y_correct))\r\n%%\r\nx = 4896;\r\ny_correct = 4896;\r\nassert(isequal(length(prime_vec(x)),y_correct))","published":true,"deleted":false,"likes_count":6,"comments_count":1,"created_by":14249,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":966,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-06T11:49:21.000Z","updated_at":"2026-02-15T12:16:05.000Z","published_at":"2013-06-06T11:49:21.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput(n) - length of vector with prime numbers\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput(v) - vector of prime numbers\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en=1; v=2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en=3; v=[2 3 5]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en=7; v=[2 3 5 7 11 13 17]\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":42830,"title":"Hilbert numbers","description":"Given a positive integer, n, return h as follows:\r\n\r\n1. If n is not a \u003chttps://en.wikipedia.org/wiki/Hilbert_number Hilbert number\u003e, return h = 0\r\n\r\n2. If n is a Hilbert prime, return h = 1\r\n\r\n3. If n is a Hilbert non-prime, return all of its Hilbert factors in one sorted vector. \r\n\r\nExample 1:\r\n\r\nn = 3\r\n\r\nh = 0\r\n\r\nExample 2:\r\n\r\nn = 5\r\n\r\nh = 1\r\n\r\nExample 3:\r\n\r\nn = 45\r\n\r\nh = [5 9]\r\n\r\nExample 4:\r\n\r\nn = 441\r\n\r\nh = [9 21 49]","description_html":"\u003cp\u003eGiven a positive integer, n, return h as follows:\u003c/p\u003e\u003cp\u003e1. If n is not a \u003ca href = \"https://en.wikipedia.org/wiki/Hilbert_number\"\u003eHilbert number\u003c/a\u003e, return h = 0\u003c/p\u003e\u003cp\u003e2. If n is a Hilbert prime, return h = 1\u003c/p\u003e\u003cp\u003e3. If n is a Hilbert non-prime, return all of its Hilbert factors in one sorted vector.\u003c/p\u003e\u003cp\u003eExample 1:\u003c/p\u003e\u003cp\u003en = 3\u003c/p\u003e\u003cp\u003eh = 0\u003c/p\u003e\u003cp\u003eExample 2:\u003c/p\u003e\u003cp\u003en = 5\u003c/p\u003e\u003cp\u003eh = 1\u003c/p\u003e\u003cp\u003eExample 3:\u003c/p\u003e\u003cp\u003en = 45\u003c/p\u003e\u003cp\u003eh = [5 9]\u003c/p\u003e\u003cp\u003eExample 4:\u003c/p\u003e\u003cp\u003en = 441\u003c/p\u003e\u003cp\u003eh = [9 21 49]\u003c/p\u003e","function_template":"function h = hilbertnum(n)\r\n  h = 0;\r\nend","test_suite":"%%\r\nn = 3;\r\nh_correct = 0;\r\nassert(isequal(hilbertnum(n),h_correct))\r\n\r\n%%\r\nn = 5;\r\nh_correct = 1;\r\nassert(isequal(hilbertnum(n),h_correct))\r\n\r\n%%\r\nn = 45;\r\nh_correct = [5 9];\r\nassert(isequal(hilbertnum(n),h_correct))\r\n\r\n%%\r\nn = 1169;\r\nh_correct = 1;\r\nassert(isequal(hilbertnum(n),h_correct))\r\n\r\n%%\r\nn = 441;\r\nh_correct = [9 21 49];\r\nassert(isequal(hilbertnum(n),h_correct))\r\n\r\n%%\r\nn = 45678;\r\nh_correct = 0;\r\nassert(isequal(hilbertnum(n),h_correct))\r\n\r\n%%\r\nn = 56789;\r\nh_correct = [109 521];\r\nassert(isequal(hilbertnum(n),h_correct))\r\n\r\n%%\r\nn = 353535;\r\nh_correct = 0;\r\nassert(isequal(hilbertnum(n),h_correct))\r\n\r\n%%\r\nn = 35353549;\r\nh_correct = [49 77 613 749 1177 30037 47201 57673 459137 721501];\r\nassert(isequal(hilbertnum(n),h_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":61,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-04-25T18:22:53.000Z","updated_at":"2026-03-02T11:43:26.000Z","published_at":"2016-04-25T18:22:53.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a positive integer, n, return h as follows:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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. If n is not a\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/Hilbert_number\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eHilbert number\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, return h = 0\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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. If n is a Hilbert prime, return h = 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\u003e3. If n is a Hilbert non-prime, return all of its Hilbert factors in one sorted vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample 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\u003en = 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\u003eh = 0\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 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\u003en = 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eh = 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\u003eExample 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\u003en = 45\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eh = [5 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\u003eExample 4:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003en = 441\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eh = [9 21 49]\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":1096,"title":"Largest Twin Primes","description":"\u003chttp://en.wikipedia.org/wiki/Twin_prime Twin primes\u003e are primes p1, p2 = p1 + 2 such that both p1 and p2 are prime numbers. Given a positive integer N (\u003e=5) what are the largest twin primes (in order) \u003c= N. For example, if N = 20 then p1 = 17 and p2 = 19.","description_html":"\u003cp\u003e\u003ca href=\"http://en.wikipedia.org/wiki/Twin_prime\"\u003eTwin primes\u003c/a\u003e are primes p1, p2 = p1 + 2 such that both p1 and p2 are prime numbers. Given a positive integer N (\u003e=5) what are the largest twin primes (in order) \u0026lt;= N. For example, if N = 20 then p1 = 17 and p2 = 19.\u003c/p\u003e","function_template":"function [y] = your_fcn_name(N)\r\n  y = [N-2 N]; \r\nend","test_suite":"%%\r\nx = 1001;\r\ny_correct = [881 883];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 1964;\r\ny_correct = [1949 1951];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 123456789;\r\ny_correct = [123456209 123456211];\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":8873,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":988,"test_suite_updated_at":"2012-12-05T19:39:01.000Z","rescore_all_solutions":false,"group_id":44,"created_at":"2012-12-05T19:36:12.000Z","updated_at":"2026-02-15T11:07:16.000Z","published_at":"2012-12-05T19:37:15.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:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Twin_prime\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eTwin primes\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e are primes p1, p2 = p1 + 2 such that both p1 and p2 are prime numbers. Given a positive integer N (\u0026gt;=5) what are the largest twin primes (in order) \u0026lt;= N. For example, if N = 20 then p1 = 17 and p2 = 19.\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":525,"title":"Mersenne Primes","description":"A Mersenne prime is a prime number of the form M = 2^p - 1, where p is another prime number.  For example, 31 is a Mersenne prime because 31 = 2^5 - 1 and both 31 and 5 are prime numbers.\r\n\r\nImplement the function isMersenne(x) so that it returns true if x is a Mersenne prime and false otherwise.  Your solution should work for all positive integer values of x less than 1,000,000,000 (one billion).","description_html":"\u003cp\u003eA Mersenne prime is a prime number of the form M = 2^p - 1, where p is another prime number.  For example, 31 is a Mersenne prime because 31 = 2^5 - 1 and both 31 and 5 are prime numbers.\u003c/p\u003e\u003cp\u003eImplement the function isMersenne(x) so that it returns true if x is a Mersenne prime and false otherwise.  Your solution should work for all positive integer values of x less than 1,000,000,000 (one billion).\u003c/p\u003e","function_template":"function y = isMersenne(x)\r\n  y = false;\r\nend","test_suite":"%%\r\nx = 3;\r\ny_correct = true;\r\nassert(isequal(isMersenne(x),y_correct))\r\n\r\n%%\r\nx = 127;\r\ny_correct = true;\r\nassert(isequal(isMersenne(x),y_correct))\r\n\r\n%%\r\nx = 157;\r\ny_correct = false;\r\nassert(isequal(isMersenne(x),y_correct))\r\n\r\n%%\r\nx = 2047;\r\ny_correct = false;\r\nassert(isequal(isMersenne(x),y_correct))\r\n\r\n%%\r\nx = 8191;\r\ny_correct = true;\r\nassert(isequal(isMersenne(x),y_correct))\r\n\r\n%%\r\nx = 524287;\r\ny_correct = true;\r\nassert(isequal(isMersenne(x),y_correct))\r\n\r\n%%\r\nx = 536870911;\r\ny_correct = false;\r\nassert(isequal(isMersenne(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":4,"created_by":1537,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":968,"test_suite_updated_at":"2012-03-24T15:03:26.000Z","rescore_all_solutions":false,"group_id":44,"created_at":"2012-03-24T14:32:54.000Z","updated_at":"2026-02-15T11:05:47.000Z","published_at":"2012-03-24T14:36:27.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 Mersenne prime is a prime number of the form M = 2^p - 1, where p is another prime number. For example, 31 is a Mersenne prime because 31 = 2^5 - 1 and both 31 and 5 are prime numbers.\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\u003eImplement the function isMersenne(x) so that it returns true if x is a Mersenne prime and false otherwise. Your solution should work for all positive integer values of x less than 1,000,000,000 (one billion).\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":241,"title":"Project Euler: Problem 7, Nth prime","description":"By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.\r\nWhat is the Nth prime number?\r\nThank you to Project Euler Problem 7","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: 81px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 40.5px; transform-origin: 407px 40.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: 298px 8px; transform-origin: 298px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eBy listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.\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: 97.5px 8px; transform-origin: 97.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWhat is the Nth prime 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: 41.5px 8px; transform-origin: 41.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThank you to\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 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=\"\"\u003eProject Euler Problem 7\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = euler007(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nfiletext = fileread('euler007.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp') || ...\r\n          contains(filetext, 'if') || contains(filetext, 'switch'); \r\nassert(~illegal)\r\n\r\n%%\r\nx = 6;\r\ny_correct = 13;\r\nassert(isequal(euler007(x),y_correct))\r\n\r\n%%\r\nx = 69;\r\ny_correct = 347;\r\nassert(isequal(euler007(x),y_correct))\r\n\r\n%%\r\nx = 420;\r\ny_correct = 2903;\r\nassert(isequal(euler007(x),y_correct))\r\n\r\n%%\r\nx = 1729;\r\ny_correct = 14759;\r\nassert(isequal(euler007(x),y_correct))\r\n\r\n%%\r\nx = 10001;\r\ny_correct = 104743;\r\nassert(isequal(euler007(x),y_correct))\r\n\r\n%%\r\nx = 123456;\r\ny_correct = 1632899;\r\nassert(isequal(euler007(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":21,"comments_count":11,"created_by":240,"edited_by":223089,"edited_at":"2022-12-27T06:14:17.000Z","deleted_by":null,"deleted_at":null,"solvers_count":1753,"test_suite_updated_at":"2022-12-27T06:14:17.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-02-02T21:11:56.000Z","updated_at":"2026-03-15T19:01:28.000Z","published_at":"2012-02-03T14:47:05.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\u003eBy listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhat is the Nth prime 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\u003eThank you to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProject Euler Problem 7\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":1722,"title":"Find the next prime number","description":"Find the next prime number or numbers for given n. For example:\r\n\r\n  n = 1;\r\n  out = 2;\r\n\r\nor\r\n\r\n  n = [5 7];\r\n  out = [7 11];\r\n\r\nGood luck!\r\n","description_html":"\u003cp\u003eFind the next prime number or numbers for given n. For example:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003en = 1;\r\nout = 2;\r\n\u003c/pre\u003e\u003cp\u003eor\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003en = [5 7];\r\nout = [7 11];\r\n\u003c/pre\u003e\u003cp\u003eGood luck!\u003c/p\u003e","function_template":"function y = nextprimenum(n)\r\n  y = n;\r\nend","test_suite":"%%\r\nn = 1;\r\nout = 2;\r\nassert(isequal(nextprimenum(n),out))\r\n%%\r\nn = 7;\r\nout = 11;\r\nassert(isequal(nextprimenum(n),out))\r\n%%\r\nn = [1 2 3 4 5 6 7 8 9];\r\nout = [2 3 5 5 7 7 11 11 11];\r\nassert(isequal(nextprimenum(n),out))\r\n%%\r\nn = [71 25 63 47 65 36 47 58 69];\r\nout = [73 29 67 53 67 37 53 59 71];\r\nassert(isequal(nextprimenum(n),out))\r\n%%\r\nn = [171 255 636 487 675 369 477 538 969];\r\nout =  [173 257 641 491 677 373 479 541 971];\r\nassert(isequal(nextprimenum(n),out))\r\n%%\r\nn = [172541 255564 632436 4564587 6778675 334469 475647 575638 96879];\r\nout =  [172553 255571 632447 4564589 6778691 334487 475649 575647 96893];\r\nassert(isequal(nextprimenum(n),out))","published":true,"deleted":false,"likes_count":6,"comments_count":0,"created_by":15013,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":836,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-07-17T21:54:33.000Z","updated_at":"2026-02-15T12:18:36.000Z","published_at":"2013-07-17T21:54:32.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\u003eFind the next prime number or numbers for given n. For example:\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[n = 1;\\nout = 2;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eor\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[n = [5 7];\\nout = [7 11];]]\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\u003eGood 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":2910,"title":"Mersenne Primes vs. All Primes","description":"A Mersenne prime (M) is a prime number of the form M = 2^p - 1, where p is another prime number. \u003chttps://www.mathworks.com/matlabcentral/cody/problems/525-mersenne-primes Problem 525\u003e asks the user to determine if a number is a Mersenne prime. In this problem, you are tasked with returning the number of primes numbers below the input number, n, that are Mersenne primes and the fraction of all primes below that input number that the Mersenne primes represent.\r\n\r\nFor example, for n = 100, there are 25 primes numbers: 2, 3, 5, 7, ..., 89, 97. As far as Mersenne primes go, there are only three that are less than 100: 2^2 - 1 = 3, 2^3 - 1 = 7, and 2^5 - 1 = 31. The corresponding fraction would be 3/25.","description_html":"\u003cp\u003eA Mersenne prime (M) is a prime number of the form M = 2^p - 1, where p is another prime number. \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/525-mersenne-primes\"\u003eProblem 525\u003c/a\u003e asks the user to determine if a number is a Mersenne prime. In this problem, you are tasked with returning the number of primes numbers below the input number, n, that are Mersenne primes and the fraction of all primes below that input number that the Mersenne primes represent.\u003c/p\u003e\u003cp\u003eFor example, for n = 100, there are 25 primes numbers: 2, 3, 5, 7, ..., 89, 97. As far as Mersenne primes go, there are only three that are less than 100: 2^2 - 1 = 3, 2^3 - 1 = 7, and 2^5 - 1 = 31. The corresponding fraction would be 3/25.\u003c/p\u003e","function_template":"function [y,f] = Mersenne_prime_comp(n)\r\n y = 1;\r\n f = 0;\r\nend","test_suite":"%%\r\nn = 1e2;\r\ny_correct = 3;\r\nf_correct = 3/25;\r\n[y,f] = Mersenne_prime_comp(n);\r\nassert(isequal(y,y_correct))\r\nassert(isequal(f,f_correct))\r\n\r\n%%\r\nn = 1e3;\r\ny_correct = 4;\r\nf_correct = 0.023809523809524;\r\n[y,f] = Mersenne_prime_comp(n);\r\nassert(isequal(y,y_correct))\r\nassert(abs(f-f_correct)\u003c(10*eps))\r\n\r\n%%\r\nn = 1e4;\r\ny_correct = 5;\r\nf_correct = 0.004068348250610;\r\n[y,f] = Mersenne_prime_comp(n);\r\nassert(isequal(y,y_correct))\r\nassert(abs(f-f_correct)\u003c(10*eps))\r\n\r\n%%\r\nn = 1e5;\r\ny_correct = 5;\r\nf_correct = 5.212677231025855e-04;\r\n[y,f] = Mersenne_prime_comp(n);\r\nassert(isequal(y,y_correct))\r\nassert(abs(f-f_correct)\u003c(10*eps))\r\n\r\n%%\r\nn = 1e6;\r\ny_correct = 7;\r\nf_correct = 8.917424647761727e-05;\r\n[y,f] = Mersenne_prime_comp(n);\r\nassert(isequal(y,y_correct))\r\nassert(abs(f-f_correct)\u003c(10*eps))\r\n","published":true,"deleted":false,"likes_count":8,"comments_count":2,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":846,"test_suite_updated_at":"2015-02-01T04:14:08.000Z","rescore_all_solutions":false,"group_id":29,"created_at":"2015-02-01T03:56:07.000Z","updated_at":"2026-04-01T10:02:01.000Z","published_at":"2015-02-01T04:14:08.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA Mersenne prime (M) is a prime number of the form M = 2^p - 1, where p is another prime number.\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://www.mathworks.com/matlabcentral/cody/problems/525-mersenne-primes\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 525\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e asks the user to determine if a number is a Mersenne prime. In this problem, you are tasked with returning the number of primes numbers below the input number, n, that are Mersenne primes and the fraction of all primes below that input number that the Mersenne primes represent.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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, for n = 100, there are 25 primes numbers: 2, 3, 5, 7, ..., 89, 97. As far as Mersenne primes go, there are only three that are less than 100: 2^2 - 1 = 3, 2^3 - 1 = 7, and 2^5 - 1 = 31. The corresponding fraction would be 3/25.\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":60,"title":"The Goldbach Conjecture","description":"The Goldbach conjecture asserts that every even integer greater than 2 can be expressed as the sum of two primes.\r\nGiven the even integer n, return primes p1 and p2 that satisfy the condition n = p1 + p2. Note that the primes are not always unique. The test is not sensitive to order or uniqueness. You just need to meet the appropriate conditions.\r\nExample:\r\n Input  n = 286\r\n Output (any of the following is acceptable) \r\n        [  3 283]\r\n        [283   3]\r\n        [  5 281]\r\n        [107 179]\r\n        [137 149]","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: 255.033px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 127.517px; transform-origin: 407px 127.517px; 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: 12.5px 8px; transform-origin: 12.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe\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=\"\"\u003eGoldbach conjecture\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: 287px 8px; transform-origin: 287px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e asserts that every even integer greater than 2 can be expressed as the sum of two primes.\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: 368.5px 8px; transform-origin: 368.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven the even integer n, return primes p1 and p2 that satisfy the condition n = p1 + p2. Note that the primes are not always unique. The test is not sensitive to order or uniqueness. You just need to meet the appropriate conditions.\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: 28.5px 8px; transform-origin: 28.5px 8px; 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: 143.033px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 71.5167px; transform-origin: 404px 71.5167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; 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: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\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: 60px 8.5px; tab-size: 4; transform-origin: 60px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 32px 8.5px; transform-origin: 32px 8.5px; \"\u003e Input  \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 28px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 28px 8.5px; \"\u003en = 286\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: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; 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: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\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: 180px 8.5px; tab-size: 4; transform-origin: 180px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e Output (any of the following is acceptable) \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: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; 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: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\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: 68px 8.5px; tab-size: 4; transform-origin: 68px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        [  3 283]\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: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; 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: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\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: 68px 8.5px; tab-size: 4; transform-origin: 68px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        [283   3]\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: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; 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: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\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: 68px 8.5px; tab-size: 4; transform-origin: 68px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        [  5 281]\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: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; 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: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\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: 68px 8.5px; tab-size: 4; transform-origin: 68px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        [107 179]\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: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; 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: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\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: 68px 8.5px; tab-size: 4; transform-origin: 68px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        [137 149]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [p1,p2] = goldbach(n)\r\n  p1 = n;\r\n  p2 = n;\r\nend","test_suite":"%%\r\nfiletext = fileread('goldbach.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'regexp'); \r\nassert(~illegal)\r\n\r\n%%\r\nnList = 28:6:76;\r\nfor i = 1:length(nList)\r\n  n = nList(i);\r\n  [p1,p2] = goldbach(n)\r\n  assert(isprime(p1) \u0026\u0026 isprime(p2) \u0026\u0026 (p1+p2==n));\r\nend\r\n\r\n%%\r\nnList = [18 20 22 100 102 114 1000 2000 36 3600];\r\nfor i = 1:length(nList)\r\n  n = nList(i);\r\n  [p1,p2] = goldbach(n)\r\n  assert(isprime(p1) \u0026\u0026 isprime(p2) \u0026\u0026 (p1+p2==n));\r\nend","published":true,"deleted":false,"likes_count":60,"comments_count":17,"created_by":1,"edited_by":223089,"edited_at":"2023-06-05T15:48:22.000Z","deleted_by":null,"deleted_at":null,"solvers_count":5972,"test_suite_updated_at":"2023-06-05T15:48:22.000Z","rescore_all_solutions":false,"group_id":2,"created_at":"2012-01-18T01:00:25.000Z","updated_at":"2026-03-23T12:29:13.000Z","published_at":"2012-01-18T01:00:25.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\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=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGoldbach conjecture\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e asserts that every even integer greater than 2 can be expressed as the sum of two primes.\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 the even integer n, return primes p1 and p2 that satisfy the condition n = p1 + p2. Note that the primes are not always unique. The test is not sensitive to order or uniqueness. You just need to meet the appropriate conditions.\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[ Input  n = 286\\n Output (any of the following is acceptable) \\n        [  3 283]\\n        [283   3]\\n        [  5 281]\\n        [107 179]\\n        [137 149]]]\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":1095,"title":"Circular Primes (based on Project Euler, problem 35)","description":"The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.\r\n\r\nThere are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.\r\n\r\nGiven a number x, write a MATLAB script that will tell you the number of circular primes less than or equal to x as well as a sorted list of what the circular prime numbers are.","description_html":"\u003cp\u003eThe number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.\u003c/p\u003e\u003cp\u003eThere are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.\u003c/p\u003e\u003cp\u003eGiven a number x, write a MATLAB script that will tell you the number of circular primes less than or equal to x as well as a sorted list of what the circular prime numbers are.\u003c/p\u003e","function_template":"function [how_many what_numbers]=circular_prime(x)\r\n    how_many=3;\r\n    what_numbers=[2 3 5];\r\nend","test_suite":"%%\r\n[y numbers]=circular_prime(197)\r\nassert(isequal(y,16)\u0026\u0026isequal(numbers,[2 3 5 7 11 13 17 31 37 71 73 79 97 113 131 197]))\r\n%%\r\n[y numbers]=circular_prime(100)\r\nassert(isequal(y,13)\u0026\u0026isequal(numbers,[2 3 5 7 11 13 17 31 37 71 73 79 97]))\r\n%%\r\n[y numbers]=circular_prime(250)\r\nassert(isequal(y,17)\u0026\u0026isequal(numbers,[2 3 5 7 11 13 17 31 37 71 73 79 97 113 131 197 199]))\r\n%%\r\n[y numbers]=circular_prime(2000)\r\nassert(isequal(y,27)\u0026\u0026isequal(numbers,[2 3 5 7 11 13 17 31 37 71 73 79 97 113 131 197 199 311 337 373 719 733 919 971 991 1193 1931]))\r\n%%\r\n[y numbers]=circular_prime(10000)\r\nassert(isequal(y,33)\u0026\u0026isequal(numbers,[2 3 5 7 11 13 17 31 37 71 73 79 97 113 131 197 199 311 337 373 719 733 919 971 991 1193 1931 3119 3779 7793 7937 9311 9377]))\r\n%%\r\n[y numbers]=circular_prime(54321)\r\nassert(isequal(y,38)\u0026\u0026isequal(numbers,[2 3 5 7 11 13 17 31 37 71 73 79 97 113 131 197 199 311 337 373 719 733 919 971 991 1193 1931 3119 3779 7793 7937 9311 9377 11939 19391 19937 37199 39119]))\r\n","published":true,"deleted":false,"likes_count":10,"comments_count":6,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":651,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-12-05T18:02:09.000Z","updated_at":"2026-02-15T10:48:53.000Z","published_at":"2012-12-05T18:02:09.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\u003eThe number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.\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\u003eThere are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.\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 number x, write a MATLAB script that will tell you the number of circular primes less than or equal to x as well as a sorted list of what the circular prime numbers are.\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":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:\"Basics - Prime Numbers\"","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:\"Basics - Prime Numbers\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"group":[["group:\"Basics - Prime Numbers\"","","\"","Basics - Prime Numbers","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f69f484c0a0\u003e":["Basics - Prime Numbers"],"#\u003cMathWorks::Search::Field:0x00007f69f484bf60\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f69f484aac0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f69f484c960\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f69f484c460\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f69f484c3c0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f69f484c280\u003e":"group:\"Basics - Prime Numbers\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f69f484c280\u003e":"group:\"Basics - Prime Numbers\""},"queried_facets":{"#\u003cMathWorks::Search::Field:0x00007f69f484c0a0\u003e":["Basics - Prime Numbers"]}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"cody-search","password":"78X075ddcV44","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"group:\"Basics - Prime Numbers\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"group":[["group:\"Basics - Prime Numbers\"","","\"","Basics - Prime Numbers","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f69f484c0a0\u003e":["Basics - Prime Numbers"],"#\u003cMathWorks::Search::Field:0x00007f69f484bf60\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f69f484aac0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f69f484c960\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f69f484c460\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f69f484c3c0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f69f484c280\u003e":"group:\"Basics - Prime Numbers\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f69f484c280\u003e":"group:\"Basics - Prime Numbers\""},"queried_facets":{"#\u003cMathWorks::Search::Field:0x00007f69f484c0a0\u003e":["Basics - Prime Numbers"]}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":2521,"difficulty_rating":"easy-medium"},{"id":1761,"difficulty_rating":"easy-medium"},{"id":43142,"difficulty_rating":"easy-medium"},{"id":42749,"difficulty_rating":"easy-medium"},{"id":896,"difficulty_rating":"easy-medium"},{"id":981,"difficulty_rating":"easy-medium"},{"id":2337,"difficulty_rating":"easy-medium"},{"id":42914,"difficulty_rating":"easy-medium"},{"id":1567,"difficulty_rating":"easy-medium"},{"id":42830,"difficulty_rating":"easy-medium"},{"id":1096,"difficulty_rating":"easy-medium"},{"id":525,"difficulty_rating":"medium"},{"id":241,"difficulty_rating":"medium"},{"id":1722,"difficulty_rating":"medium"},{"id":2910,"difficulty_rating":"medium"},{"id":60,"difficulty_rating":"medium"},{"id":1095,"difficulty_rating":"medium"},{"id":1394,"difficulty_rating":"medium-hard"}]}}