{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":52669,"title":"Count the primes in Collatz sequences","description":"Several Cody problems (21, 69, 42937, 44448, 44784, 52422) involve Collatz sequences. These start with a seed . If  is odd, the next element is , and if  is even, the next element is . For example, if the seed is 3, then the sequence is 3, 10, 5, 16, 8, 4, 2, 1. The Collatz conjecture is that all of these sequences terminate at the value 1; that is, all seeds lead to terminating sequences. \r\nThis problem deals with the number of primes in the sequence. With a seed of 3, the number of primes is 3 (2, 3, 5). \r\nWrite a function to determine the numbers of primes in the sequences with seeds of 1 to the input number. See the test suite for banned terms and commands. ","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: 165px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 82.5px; transform-origin: 407px 82.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 84px; 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 42px; text-align: left; transform-origin: 384px 42px; 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: 78px 8px; transform-origin: 78px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSeveral Cody problems (\u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/21\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003e21\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: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/69\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003e69\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: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/42937\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003e42937\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: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/44448\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003e44448\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: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/44784\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003e44784\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: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/52422\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003e52422\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: 165.5px 8px; transform-origin: 165.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e) involve Collatz sequences. These start with a seed \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003en\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: 9.5px 8px; transform-origin: 9.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. If \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003en\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 is odd, the next element is \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFUAAAAkCAYAAAD4i3Y+AAACDklEQVRoge2ZUZWDMBBFrwccYAADKEABDnCAg1pAQyXgAQvVsBa6H2EOQ5rQbYBtKXPP4adJM8nry2RCwTAMwzAMI0QBlED+7om8mWLtABnQAT/AXT03nMBnogR6nBbJZMAwDnIBWuDKXNwzCFvgxJQ1rxK1x7k0CwQR5/ZrAhyABmemimnNyaKWOFfG6NYG2AFx0uqcF0HcmrzmiuUDqR0DDKkBduDjRX2GOLXZK0AChxY1Gwfuecy3sf7+QnO2L88OK6pUBFfigla49CDlh3Z0zuNJupUIhxM1A2rm9WpP2GniwpvqmzNVDS1TTr7jyrUtOJSoUgloh2mnxbbwwFx87cpSjVFvMUkOJqqP79hQ6ZWp9gYnsBavUe1/ycswXZNjj/6RlvqlsvvpL86TIL4wFfM00XntnWr7K6Gd8uqzRpDdRQWXC2NbrlNtt8B35QdpX4zXLzwSb1jos3Sheca/iKq3nC+qPqQqr61Y+N4aDp1TBRHVD6JFCzlD8unWk/sKUWvCJZE+hHyX6sn5eXYtXyFqj9vm/iKWguuqQKqBa2CMFD5eVDmEYi+j5SAKOVEWF3JirdrlBfhpin99ekvpIzchuaaGJq9LqZDgOjXIOFuxp6j6UL6TWO9mOAF0OXIZP1t6CVKr/rFx5Xa21U1K2EPUEmewUHl2IWycr0J20tn/mDQMwzAMwzCMKL/9cBTuzEvrTwAAAABJRU5ErkJggg==\" alt=\"3n+1\" style=\"width: 42.5px; height: 18px;\" width=\"42.5\" height=\"18\"\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: 23.5px 8px; transform-origin: 23.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, and if \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003en\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: 89.5px 8px; transform-origin: 89.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e is even, the next element is \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADMAAAAlCAYAAADvLtGsAAAB/0lEQVRYhe2YUbGDMBBFjwccYAADVYACHNQBDmoBDUjAAxbQgIW+j7DDUpIQCC08hjOTL1q4m+zeXYCbm0tTAMnRIvYgBd5AdrSQPXgC7dEi9qLFBLTEY1inPcEMk2Kp43oCVMNv9OoJ24Cf8gIax7UUI/ozEL1eP9AYTIdxMhuN5XrG/KTybwoM5YERY7PkHHMqrvooGYOpv6JuJdWwbNT4ayJhWj+H0+NOkQq3KQgNkcEkzI8+xaTM0sM1RYyIAQnGZSAzckx+NozOIsefqhvKDoX2gJp4J+o+9Cwiuy5/lJ6QYcSXTIsxRKDke0zzkxGoY11GAKZLy5GK/4sYcaU3bpvVPAcRMcgGrm6c2jlkjtKin+p6yOQbOr749PSsqBVNzii2YW6nFeGFKOmxOjUUNWZDNr0y6I5rSw8xhjLgXr7xJQRJ0c31pov/sy9k6lrIA3zjyxIFkYFosbaxQeolpGf4xpclogOBaXHburX0GddYoqnYNkflLAeSEVCHvpFBu5ykTu15qG988YnsMafqIsEYwmIwIta28wVTS65wN02ZgtcggbSMzdm2OgJMRVuybUd1Crb4U6gmLBUFCcT3YrbqnabAROyKOhlENvgdasv4IvcNWTU//EwlTnQJJOf/PXuML6eh5EIf+GLGl1Mho9BlPoif4pvWzc2X+APNAsLGctE5qwAAAABJRU5ErkJggg==\" alt=\"n/2\" style=\"width: 25.5px; height: 18.5px;\" width=\"25.5\" height=\"18.5\"\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: 125px 8px; transform-origin: 125px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. For example, if the seed is 3, then the sequence is 3, 10, 5, 16, 8, 4, 2, 1. The Collatz conjecture is that all of these sequences terminate at the value 1; that is, all seeds lead to terminating sequences. \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: 366px 8px; transform-origin: 366px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis problem deals with the number of primes in the sequence. With a seed of 3, the number of primes is 3 (2, 3, 5). \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: 375.5px 8px; transform-origin: 375.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to determine the numbers of primes in the sequences with seeds of 1 to the input number. See the test suite for banned terms and commands. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = CollatzPrimes(n)\r\n  y = f(n);\r\nend","test_suite":"%%\r\nn = 20;\r\ny = CollatzPrimes(n);\r\ny_correct = [0 1 3 1 2 3 6 1 6 2 5 3 3 6 4 1 4 6 7 2];\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 1000;\r\ny = CollatzPrimes(n);\r\nindx = [171 231 257 342 347 411 457 462 463 487 514 521 543 609 617 649 684 685 694 703 731 763 811 815 822 823 859 865 871 913 914 915 919 924 925 926 937 967 974];\r\nyi_correct = [28 29 28 28 29 29 28 29 28 30 28 28 29 28 29 30 28 28 29 28 29 32 30 29 29 28 32 30 30 28 28 28 28 29 29 28 29 30 30];\r\nassert(isequal(y(indx),yi_correct))\r\n\r\n%%\r\nn = 10000;\r\ny = CollatzPrimes(n);\r\nsum_correct = 163462;\r\nindx_correct = [1263 1895 2411 2526 2843 2857 3567 3790 3809 4822 4927 5052 5053 5351 5686 5714 6429 6771 7134 7391 7423 7580 7581 7618 8455 8983 9644 9854 9897]; \r\nassert(isequal(sum(y),sum_correct) \u0026\u0026 isequal(find(y==35),indx_correct))\r\n\r\n%%\r\nn = 30000;\r\ny = CollatzPrimes(n);\r\nsum_correct = 521564;\r\nstd_correct = 8.757947181665990;\r\nassert(isequal(sum(y),sum_correct) \u0026\u0026 abs(std(y)-std_correct)\u003c1e-12)\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":46909,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":20,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2021-09-06T04:13:28.000Z","updated_at":"2025-12-21T18:14:55.000Z","published_at":"2021-09-06T04:18:39.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\u003eSeveral Cody problems (\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/21\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e21\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/69\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e69\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/42937\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e42937\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44448\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e44448\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44784\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e44784\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/52422\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e52422\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e) involve Collatz sequences. These start with a seed \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"n\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e. If \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"n\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e is odd, the next element is \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"3n+1\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003e3n+1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e, and if \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"n\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e is even, the next element is \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"n/2\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003en/2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e. For example, if the seed is 3, then the sequence is 3, 10, 5, 16, 8, 4, 2, 1. The Collatz conjecture is that all of these sequences terminate at the value 1; that is, all seeds lead to terminating sequences. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis problem deals with the number of primes in the sequence. With a seed of 3, the number of primes is 3 (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=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine the numbers of primes in the sequences with seeds of 1 to the input number. See the test suite for banned terms and commands. \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\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":52669,"title":"Count the primes in Collatz sequences","description":"Several Cody problems (21, 69, 42937, 44448, 44784, 52422) involve Collatz sequences. These start with a seed . If  is odd, the next element is , and if  is even, the next element is . For example, if the seed is 3, then the sequence is 3, 10, 5, 16, 8, 4, 2, 1. The Collatz conjecture is that all of these sequences terminate at the value 1; that is, all seeds lead to terminating sequences. \r\nThis problem deals with the number of primes in the sequence. With a seed of 3, the number of primes is 3 (2, 3, 5). \r\nWrite a function to determine the numbers of primes in the sequences with seeds of 1 to the input number. See the test suite for banned terms and commands. ","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: 165px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 82.5px; transform-origin: 407px 82.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 84px; 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 42px; text-align: left; transform-origin: 384px 42px; 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: 78px 8px; transform-origin: 78px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSeveral Cody problems (\u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/21\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003e21\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: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/69\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003e69\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: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/42937\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003e42937\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: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/44448\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003e44448\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: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/44784\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003e44784\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: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/52422\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003e52422\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: 165.5px 8px; transform-origin: 165.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e) involve Collatz sequences. These start with a seed \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003en\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: 9.5px 8px; transform-origin: 9.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. If \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003en\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 is odd, the next element is \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFUAAAAkCAYAAAD4i3Y+AAACDklEQVRoge2ZUZWDMBBFrwccYAADKEABDnCAg1pAQyXgAQvVsBa6H2EOQ5rQbYBtKXPP4adJM8nry2RCwTAMwzAMI0QBlED+7om8mWLtABnQAT/AXT03nMBnogR6nBbJZMAwDnIBWuDKXNwzCFvgxJQ1rxK1x7k0CwQR5/ZrAhyABmemimnNyaKWOFfG6NYG2AFx0uqcF0HcmrzmiuUDqR0DDKkBduDjRX2GOLXZK0AChxY1Gwfuecy3sf7+QnO2L88OK6pUBFfigla49CDlh3Z0zuNJupUIhxM1A2rm9WpP2GniwpvqmzNVDS1TTr7jyrUtOJSoUgloh2mnxbbwwFx87cpSjVFvMUkOJqqP79hQ6ZWp9gYnsBavUe1/ycswXZNjj/6RlvqlsvvpL86TIL4wFfM00XntnWr7K6Gd8uqzRpDdRQWXC2NbrlNtt8B35QdpX4zXLzwSb1jos3Sheca/iKq3nC+qPqQqr61Y+N4aDp1TBRHVD6JFCzlD8unWk/sKUWvCJZE+hHyX6sn5eXYtXyFqj9vm/iKWguuqQKqBa2CMFD5eVDmEYi+j5SAKOVEWF3JirdrlBfhpin99ekvpIzchuaaGJq9LqZDgOjXIOFuxp6j6UL6TWO9mOAF0OXIZP1t6CVKr/rFx5Xa21U1K2EPUEmewUHl2IWycr0J20tn/mDQMwzAMwzCMKL/9cBTuzEvrTwAAAABJRU5ErkJggg==\" alt=\"3n+1\" style=\"width: 42.5px; height: 18px;\" width=\"42.5\" height=\"18\"\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: 23.5px 8px; transform-origin: 23.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, and if \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003en\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: 89.5px 8px; transform-origin: 89.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e is even, the next element is \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADMAAAAlCAYAAADvLtGsAAAB/0lEQVRYhe2YUbGDMBBFjwccYAADVYACHNQBDmoBDUjAAxbQgIW+j7DDUpIQCC08hjOTL1q4m+zeXYCbm0tTAMnRIvYgBd5AdrSQPXgC7dEi9qLFBLTEY1inPcEMk2Kp43oCVMNv9OoJ24Cf8gIax7UUI/ozEL1eP9AYTIdxMhuN5XrG/KTybwoM5YERY7PkHHMqrvooGYOpv6JuJdWwbNT4ayJhWj+H0+NOkQq3KQgNkcEkzI8+xaTM0sM1RYyIAQnGZSAzckx+NozOIsefqhvKDoX2gJp4J+o+9Cwiuy5/lJ6QYcSXTIsxRKDke0zzkxGoY11GAKZLy5GK/4sYcaU3bpvVPAcRMcgGrm6c2jlkjtKin+p6yOQbOr749PSsqBVNzii2YW6nFeGFKOmxOjUUNWZDNr0y6I5rSw8xhjLgXr7xJQRJ0c31pov/sy9k6lrIA3zjyxIFkYFosbaxQeolpGf4xpclogOBaXHburX0GddYoqnYNkflLAeSEVCHvpFBu5ykTu15qG988YnsMafqIsEYwmIwIta28wVTS65wN02ZgtcggbSMzdm2OgJMRVuybUd1Crb4U6gmLBUFCcT3YrbqnabAROyKOhlENvgdasv4IvcNWTU//EwlTnQJJOf/PXuML6eh5EIf+GLGl1Mho9BlPoif4pvWzc2X+APNAsLGctE5qwAAAABJRU5ErkJggg==\" alt=\"n/2\" style=\"width: 25.5px; height: 18.5px;\" width=\"25.5\" height=\"18.5\"\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: 125px 8px; transform-origin: 125px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. For example, if the seed is 3, then the sequence is 3, 10, 5, 16, 8, 4, 2, 1. The Collatz conjecture is that all of these sequences terminate at the value 1; that is, all seeds lead to terminating sequences. \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: 366px 8px; transform-origin: 366px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis problem deals with the number of primes in the sequence. With a seed of 3, the number of primes is 3 (2, 3, 5). \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: 375.5px 8px; transform-origin: 375.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to determine the numbers of primes in the sequences with seeds of 1 to the input number. See the test suite for banned terms and commands. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = CollatzPrimes(n)\r\n  y = f(n);\r\nend","test_suite":"%%\r\nn = 20;\r\ny = CollatzPrimes(n);\r\ny_correct = [0 1 3 1 2 3 6 1 6 2 5 3 3 6 4 1 4 6 7 2];\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 1000;\r\ny = CollatzPrimes(n);\r\nindx = [171 231 257 342 347 411 457 462 463 487 514 521 543 609 617 649 684 685 694 703 731 763 811 815 822 823 859 865 871 913 914 915 919 924 925 926 937 967 974];\r\nyi_correct = [28 29 28 28 29 29 28 29 28 30 28 28 29 28 29 30 28 28 29 28 29 32 30 29 29 28 32 30 30 28 28 28 28 29 29 28 29 30 30];\r\nassert(isequal(y(indx),yi_correct))\r\n\r\n%%\r\nn = 10000;\r\ny = CollatzPrimes(n);\r\nsum_correct = 163462;\r\nindx_correct = [1263 1895 2411 2526 2843 2857 3567 3790 3809 4822 4927 5052 5053 5351 5686 5714 6429 6771 7134 7391 7423 7580 7581 7618 8455 8983 9644 9854 9897]; \r\nassert(isequal(sum(y),sum_correct) \u0026\u0026 isequal(find(y==35),indx_correct))\r\n\r\n%%\r\nn = 30000;\r\ny = CollatzPrimes(n);\r\nsum_correct = 521564;\r\nstd_correct = 8.757947181665990;\r\nassert(isequal(sum(y),sum_correct) \u0026\u0026 abs(std(y)-std_correct)\u003c1e-12)\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":46909,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":20,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2021-09-06T04:13:28.000Z","updated_at":"2025-12-21T18:14:55.000Z","published_at":"2021-09-06T04:18:39.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\u003eSeveral Cody problems (\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/21\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e21\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/69\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e69\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/42937\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e42937\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44448\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e44448\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44784\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e44784\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/52422\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e52422\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e) involve Collatz sequences. These start with a seed \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"n\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e. If \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"n\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e is odd, the next element is \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"3n+1\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003e3n+1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e, and if \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"n\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e is even, the next element is \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"n/2\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003en/2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e. For example, if the seed is 3, then the sequence is 3, 10, 5, 16, 8, 4, 2, 1. The Collatz conjecture is that all of these sequences terminate at the value 1; that is, all seeds lead to terminating sequences. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis problem deals with the number of primes in the sequence. With a seed of 3, the number of primes is 3 (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=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine the numbers of primes in the sequences with seeds of 1 to the input number. See the test suite for banned terms and commands. \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\"}]}"}],"term":"tag:\"another collatz problem\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"another collatz problem\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"another collatz problem\"","","\"","another collatz problem","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f534ae0f480\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f534ae0f340\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f534ae0ea80\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f534ae0f700\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f534ae0f660\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f534ae0f5c0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f534ae0f520\u003e":"tag:\"another collatz problem\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f534ae0f520\u003e":"tag:\"another collatz problem\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"another collatz problem\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"another collatz problem\"","","\"","another collatz problem","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f534ae0f480\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f534ae0f340\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f534ae0ea80\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f534ae0f700\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f534ae0f660\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f534ae0f5c0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f534ae0f520\u003e":"tag:\"another collatz problem\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f534ae0f520\u003e":"tag:\"another collatz problem\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":52669,"difficulty_rating":"medium"}]}}