{"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":60486,"title":"Compute Farey sequences","description":"Problem statement\r\nThe Farey sequence of order  consists of fractions between 0 and 1 expressed in reduced form in increasing order and with no denominator greater than . For example, the Farey sequence of order 3 is {0/1, 1/3, 1/2, 2/3, 1/1}. \r\nWrite a function to compute the Farey sequence of order . Put the numerators in the first row of a two-row matrix and denominators in the second row. \r\nFurther comments\r\nFarey sequences are connected to Stern-Brocot trees, but unlike some other problems of mine (e.g., CP 59791 and 60311), this one was not inspired by a problem of minnolina’s. Instead it arose out of reading The Riemann Hypothesis: The Greatest Unsolved Problem in Mathematics by Karl Sabbagh. Geologist John Farey noted, in a half-page 1816 paper in Philosophical Magazine, a relationship between a fraction in the sequence and the fractions to its left and right. In discussing the connection between the Riemann hypothesis and Farey sequences, Sabbagh writes that, mathematician G.H. Hardy “said, somewhat cruelly:\r\nJust once in his life Mr. Farey rose above mediocrity, and made an original observation. He did not understand very well what he was doing, and he was too weak a mathematician to prove the quite simple theorem he had discovered. It is evident also that he did not consider his discovery…at all important…He had obviously no idea that this casual letter was the one event of real importance in his life. We may be tempted to think that Farey was very lucky; but a man who has made an observation that has escaped Fermat and Euler deserves any luck that comes his way.”  \r\nStunned by this mean-spirited statement—which Hardy read in a 1928 lecture in New York City, I decided to write a problem on the sequences named for Farey.","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: 474px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 237px; transform-origin: 407px 237px; 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-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 63.0083px 8px; transform-origin: 63.0083px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eProblem statement\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-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 92.1833px 8px; transform-origin: 92.1833px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe Farey sequence of order \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: 276.958px 8px; transform-origin: 276.958px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e consists of fractions between 0 and 1 expressed in reduced form in increasing order and with no denominator greater than \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: 222.075px 8px; transform-origin: 222.075px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. For example, the Farey sequence of order 3 is {0/1, 1/3, 1/2, 2/3, 1/1}. \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-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 176.842px 8px; transform-origin: 176.842px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to compute the Farey sequence of order \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: 185.508px 8px; transform-origin: 185.508px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. Put the numerators in the first row of a two-row matrix and denominators in the second row. \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-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 61.45px 8px; transform-origin: 61.45px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eFurther comments\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 126px; 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 63px; text-align: left; transform-origin: 384px 63px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 109.692px 8px; transform-origin: 109.692px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFarey sequences are connected to \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/60266\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration-line: underline; \"\u003eStern-Brocot\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: 175.408px 8px; transform-origin: 175.408px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e trees, but unlike some other problems of mine (e.g., CP \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/59791\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration-line: underline; \"\u003e59791\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: 15.5583px 8px; transform-origin: 15.5583px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/60311\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration-line: underline; \"\u003e60311\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: 5.65833px 8px; transform-origin: 5.65833px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e), this one was not inspired by a problem of minnolina’s. Instead it arose out of reading \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: 80.525px 8px; transform-origin: 80.525px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eThe Riemann Hypothesis:\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: 1.94167px 8px; transform-origin: 1.94167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \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: 14px 8px; transform-origin: 14px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eThe Greatest Unsolved Problem in Mathematics \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: 234.567px 8px; transform-origin: 234.567px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eby Karl Sabbagh. Geologist John Farey noted, in a half-page 1816 paper in \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: 73.5417px 8px; transform-origin: 73.5417px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003ePhilosophical Magazine\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: 278.492px 8px; transform-origin: 278.492px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, a relationship between a fraction in the sequence and the fractions to its left and right. In discussing the connection between the Riemann hypothesis and Farey sequences, Sabbagh writes that, mathematician G.H. Hardy “said, somewhat cruelly:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 126px; 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 63px; text-align: left; transform-origin: 384px 63px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eJust once in his life Mr. Farey rose above mediocrity, and made an original observation. He did not understand very well what he was doing, and he was too weak a mathematician to prove the quite simple theorem he had discovered. It is evident also that he did not consider his discovery…at all important…He had obviously no idea that this casual letter was the one event of real importance in his life. We may be tempted to think that Farey was very lucky; but a man who has made an observation that has escaped Fermat and Euler deserves any luck that comes his way.” \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: 3.85px 8px; transform-origin: 3.85px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; font-style: italic; \"\u003e \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-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eStunned by this mean-spirited statement—which Hardy read in a 1928 lecture in New York City, I decided to write a problem on the sequences named for Farey.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = Farey(n)\r\n  y = [0 1:n 1; 1 n:-1:1 1]; % Numerators in the first row, denominators in the second\r\nend","test_suite":"%%\r\nn = 1;\r\ny = Farey(n);\r\ny_correct = [0 1; 1 1];\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 3;\r\ny = Farey(n);\r\ny_correct = [0 1 1 2 1; 1 3 2 3 1];\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 5;\r\ny = Farey(n);\r\ny_correct = [0 1 1 1 2 1 3 2 3 4 1; 1 5 4 3 5 2 5 3 4 5 1];\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 8;\r\ny = Farey(n);\r\ny_correct = [0 1 1 1 1 1 2 1 3 2 3 1 4 3 5 2 5 3 4 5 6 7 1; 1 8 7 6 5 4 7 3 8 5 7 2 7 5 8 3 7 4 5 6 7 8 1];\r\nassert(isequal(y,y_correct))\r\n\r\n%% \r\nn = 18;\r\ny = Farey(n);\r\ny_correct = [0 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1 3 2 3 1 3 2 3 4 1 4 3 5 2 5 3 4 5 1 6 5 4 3 5 7 2 7 5 3 7 4 5 6 7 8 1 9 8 7 6 5 9 4 7 10 3 11 8 5 7 9 11 2 11 9 7 12 5 13 8 11 3 13 10 7 11 4 13 9 14 5 11 6 13 7 15 8 9 10 11 12 13 14 15 16 17 1; ...\r\n             1 18 17 16 15 14 13 12 11 10 9 17 8 15 7 13 6 17 11 16 5 14 9 13 17 4 15 11 18 7 17 10 13 16 3 17 14 11 8 13 18 5 17 12 7 16 9 11 13 15 17 2 17 15 13 11 9 16 7 12 17 5 18 13 8 11 14 17 3 16 13 10 17 7 18 11 15 4 17 13 9 14 5 16 11 17 6 13 7 15 8 17 9 10 11 12 13 14 15 16 17 18 1];\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 81;\r\ny = Farey(n);\r\nf = y(1,:)./y(2,:);\r\nindx73 = find(y==73)';\r\nindx73_correct = [20 102 162 220 276 332 386 446 502 552 608 670 722 776 828 886 940 1006 1052 1104 1158 1214 1274 1340 1380 1440 1494 1552 1614 1662 1720 1772 1828 1886 1942 2012 2032 2102 2158 2216 2272 2324 2382 2430 2492 2550 2604 2664 2704 2770 2830 2886 2940 2992 3038 3104 3158 3216 3268 3322 3374 3436 3492 3542 3598 3641 3658 3693 3712 3735 3768 3787 3824 3835 3882 3889 3942 3945 4024 4025];\r\nwidth_correct = 2021;\r\nsum_correct = [54882; 109764];\r\nnprime_correct = 1648;\r\nassert(all(diff(f)\u003e0))\r\nassert(isequal(indx73,indx73_correct))\r\nassert(isequal(width(y),width_correct))\r\nassert(isequal(sum(y,2),sum_correct))\r\nassert(isequal(length(find(isprime(y))),nprime_correct))\r\n\r\n%%\r\nn = 188;\r\ny = Farey(n);\r\nf = y(1,:)./y(2,:);\r\nindx173 = find(y==173)';\r\nindx173_correct = [34 222 358 490 618 742 870 996 1124 1242 1370 1494 1624 1752 1876 1996 2124 2250 2378 2496 2618 2746 2876 3000 3120 3244 3374 3498 3606 3746 3872 3998 4118 4246 4364 4498 4624 4742 4868 4986 5116 5244 5388 5486 5614 5742 5868 5996 6118 6240 6366 6484 6618 6746 6870 6990 7124 7210 7360 7488 7616 7738 7852 7988 8100 8236 8358 8486 8630 8736 8860 8994 9114 9250 9362 9488 9602 9738 9862 9984 10112 10232 10366 10492 10618 10782 10814 10978 11104 11230 11364 11484 11612 11734 11858 11994 12108 12234 12346 12482 12602 12736 12860 12966 13110 13238 13360 13496 13608 13744 13858 13980 14108 14236 14386 14472 14606 14726 14850 14978 15112 15230 15356 15478 15600 15728 15854 15982 16110 16208 16352 16480 16610 16728 16854 16972 17098 17232 17350 17478 17598 17724 17850 17990 18098 18222 18352 18476 18596 18720 18850 18978 19100 19218 19346 19472 19600 19720 19844 19867 19972 19975 20089 20102 20195 20226 20309 20354 20417 20472 20527 20600 20643 20726 20761 20854 20877 20978 20997 21106 21117 21238 21245 21374 21377 21562 21563];\r\nwidth_correct = 10797;\r\nsum_correct = [678175; 1356350];\r\nnprime_correct = 7550;\r\nassert(all(diff(f)\u003e0))\r\nassert(isequal(indx173,indx173_correct))\r\nassert(isequal(width(y),width_correct))\r\nassert(isequal(sum(y,2),sum_correct))\r\nassert(isequal(length(find(isprime(y))),nprime_correct))\r\n\r\n%%\r\nn = 811;\r\ny = Farey(n);\r\nf = y(1,:)./y(2,:);\r\nindx773 = find(y==773)';\r\nindx773_correct = [80 892 1458 2014 2538 3078 3588 4124 4644 5160 5682 6200 6724 7254 7768 8266 8792 9298 9844 10358 10880 11388 11918 12434 12950 13470 13986 14504 15018 15540 16062 16592 17106 17628 18142 18656 19176 19700 20204 20720 21238 21772 22264 22802 23320 23846 24364 24888 25400 25916 26438 26956 27476 27992 28514 29028 29542 30046 30584 31098 31632 32136 32656 33174 33688 34202 34724 35240 35766 36286 36794 37318 37838 38360 38874 39396 39920 40428 40942 41452 41986 42500 43026 43554 44062 44534 45098 45618 46134 46652 47142 47692 48196 48722 49236 49754 50258 50778 51308 51826 52342 52860 53410 53900 54420 54940 55462 55980 56508 57032 57528 58054 58570 59092 59606 60104 60646 61164 61646 62196 62708 63256 63744 64270 64786 65310 65828 66354 66792 67376 67904 68406 68932 69454 69976 70492 71008 71544 72050 72566 73078 73586 74122 74632 75128 75678 76196 76718 77232 77738 78268 78784 79300 79836 80308 80848 81378 81892 82406 82924 83466 83968 84484 84992 85522 86040 86566 87100 87602 88118 88638 89138 89670 90188 90714 91228 91748 92266 92786 93306 93820 94330 94858 95394 95890 96412 96936 97456 97964 98486 99004 99532 100146 100532 101062 101586 102110 102626 103140 103664 104174 104702 105220 105732 106256 106786 107294 107812 108326 108848 109350 109878 110396 110916 111436 111946 112462 112996 113512 114030 114480 115056 115570 116094 116616 117132 117648 118168 118698 119202 119726 120196 120754 121278 121796 122314 122836 123342 123870 124384 124904 125422 125940 126470 126978 127480 128014 128536 129054 129576 130090 130616 131120 131646 132172 132694 133246 133570 134214 134744 135270 135788 136300 136820 137350 137862 138378 138894 139416 139934 140454 140968 141488 142014 142536 143080 143566 144092 144600 145124 145678 146154 146674 147192 147712 148236 148752 149262 149792 150250 150826 151348 151858 152382 152898 153420 153936 154450 154966 155490 156006 156524 157044 157564 158082 158602 159130 159644 160248 160668 161194 161712 162226 162762 163262 163792 164304 164826 165344 165860 166374 166930 167414 167934 168456 168974 169508 170004 170526 171040 171578 172068 172586 173118 173620 174160 174668 175194 175708 176226 176748 177254 177780 178288 178812 179332 179854 180368 180894 181406 181932 182438 182958 183476 183996 184512 185026 185552 186066 186588 187100 187622 188142 188660 189188 189708 190222 190742 191254 191768 192306 192816 193330 193860 194366 194886 195402 195924 196438 196958 197482 197998 198528 199054 199592 200282 200362 201052 201590 202116 202646 203162 203686 204206 204720 205242 205758 206278 206784 207314 207828 208338 208876 209390 209902 210422 210936 211456 211984 212502 213022 213544 214056 214578 215092 215618 216132 216648 217168 217686 218206 218712 219238 219750 220276 220790 221312 221832 222356 222864 223390 223896 224418 224936 225450 225976 226484 227024 227526 228058 228576 229066 229604 230118 230640 231136 231670 232188 232710 233230 233714 234270 234784 235300 235818 236340 236852 237382 237882 238418 238932 239450 239976 240396 241000 241514 242042 242562 243080 243600 244120 244638 245154 245678 246194 246708 247224 247746 248262 248786 249296 249818 250394 250852 251382 251892 252408 252932 253452 253970 254490 254966 255520 256044 256552 257078 257564 258108 258630 259156 259676 260190 260710 261228 261750 262266 262782 263294 263824 264344 264856 265374 265900 266430 267074 267398 267950 268472 268998 269524 270028 270554 271068 271590 272108 272630 273164 273666 274174 274704 275222 275740 276260 276774 277302 277808 278330 278848 279366 279890 280448 280918 281442 281946 282476 282996 283512 284028 284550 285074 285588 286164 286614 287132 287648 288182 288698 289208 289728 290248 290766 291294 291796 292318 292832 293350 293858 294388 294912 295424 295942 296470 296980 297504 298018 298534 299058 299582 300112 300498 301112 301640 302158 302680 303188 303708 304232 304754 305250 305786 306314 306824 307338 307858 308378 308896 309416 309930 310456 310974 311506 312006 312526 313042 313544 314078 314604 315122 315652 316160 316676 317178 317720 318238 318752 319266 319796 320336 320808 321344 321860 322376 322906 323412 323926 324448 324966 325516 326012 326522 327058 327566 328078 328594 329100 329636 330152 330668 331190 331712 332238 332740 333268 333852 334290 334816 335334 335858 336374 336900 337388 337936 338448 338998 339480 339998 340540 341038 341552 342074 342590 343116 343612 344136 344664 345182 345704 346224 346744 347234 347784 348302 348818 349336 349866 350386 350890 351408 351922 352448 352952 353502 353992 354510 355026 355546 356110 356582 357090 357618 358144 358658 359192 359702 360216 360724 361248 361770 362284 362806 363326 363850 364358 364878 365404 365920 366442 366956 367470 367988 368508 369012 369546 370060 370598 371102 371616 372130 372652 373168 373688 374206 374728 375244 375756 376280 376798 377324 377842 378380 378872 379406 379924 380440 380944 381468 381865 381988 382349 382502 382813 383016 383281 383538 383759 384052 384239 384582 384715 385104 385211 385626 385683 386140 386171 386645 386658 387125 387174 387609 387694 388101 388210 388579 388726 389073 389256 389561 389764 390045 390286 390541 390800 391039 391346 391549 391852 392043 392378 392537 392876 393019 393390 393517 393920 394035 394444 394535 394962 395045 395484 395547 396000 396055 396520 396563 397056 397091 397566 397589 398106 398125 398630 398641 399186 399193 399752 399755 400564 400565];\r\nwidth_correct = 200321;\r\nsum_correct = [54206832; 108413664];\r\nnprime_correct = 112653;\r\nassert(all(diff(f)\u003e0))\r\nassert(isequal(indx773,indx773_correct))\r\nassert(isequal(width(y),width_correct))\r\nassert(isequal(sum(y,2),sum_correct))\r\nassert(isequal(length(find(isprime(y))),nprime_correct))\r\n\r\n%%\r\nn = randi(134);\r\ny = Farey(n);\r\nm = width(y);\r\nb = y(2,:);\r\nassert(abs(sum(b(1:end-1)./b(2:end))-(3*m-4)/2)\u003c1e-5)\r\nassert(abs(sum(1./(b(1:end-1).*b(2:end)))-1)\u003c1e-5)\r\n\r\n%%\r\nfiletext = fileread('Farey.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'assert'); \r\nassert(~illegal)","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":46909,"edited_by":46909,"edited_at":"2024-06-10T05:07:53.000Z","deleted_by":null,"deleted_at":null,"solvers_count":8,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2024-06-10T05:03:32.000Z","updated_at":"2024-06-10T05:07:53.000Z","published_at":"2024-06-10T05:03:55.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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eProblem statement\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 Farey sequence of order \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 consists of fractions between 0 and 1 expressed in reduced form in increasing order and with no denominator greater than \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. For example, the Farey sequence of order 3 is {0/1, 1/3, 1/2, 2/3, 1/1}. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to compute the Farey sequence of order \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. Put the numerators in the first row of a two-row matrix and denominators in the second row. \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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eFurther comments\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\u003eFarey sequences are connected to \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/60266\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eStern-Brocot\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e trees, but unlike some other problems of mine (e.g., CP \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/59791\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e59791\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/60311\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e60311\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e), this one was not inspired by a problem of minnolina’s. Instead it arose out of reading \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eThe Riemann Hypothesis:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eThe Greatest Unsolved Problem in Mathematics \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eby Karl Sabbagh. Geologist John Farey noted, in a half-page 1816 paper in \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ePhilosophical Magazine\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, a relationship between a fraction in the sequence and the fractions to its left and right. In discussing the connection between the Riemann hypothesis and Farey sequences, Sabbagh writes that, mathematician G.H. Hardy “said, somewhat cruelly:\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eJust once in his life Mr. Farey rose above mediocrity, and made an original observation. He did not understand very well what he was doing, and he was too weak a mathematician to prove the quite simple theorem he had discovered. It is evident also that he did not consider his discovery…at all important…He had obviously no idea that this casual letter was the one event of real importance in his life. We may be tempted to think that Farey was very lucky; but a man who has made an observation that has escaped Fermat and Euler deserves any luck that comes his way.” \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eStunned by this mean-spirited statement—which Hardy read in a 1928 lecture in New York City, I decided to write a problem on the sequences named for Farey.\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":60486,"title":"Compute Farey sequences","description":"Problem statement\r\nThe Farey sequence of order  consists of fractions between 0 and 1 expressed in reduced form in increasing order and with no denominator greater than . For example, the Farey sequence of order 3 is {0/1, 1/3, 1/2, 2/3, 1/1}. \r\nWrite a function to compute the Farey sequence of order . Put the numerators in the first row of a two-row matrix and denominators in the second row. \r\nFurther comments\r\nFarey sequences are connected to Stern-Brocot trees, but unlike some other problems of mine (e.g., CP 59791 and 60311), this one was not inspired by a problem of minnolina’s. Instead it arose out of reading The Riemann Hypothesis: The Greatest Unsolved Problem in Mathematics by Karl Sabbagh. Geologist John Farey noted, in a half-page 1816 paper in Philosophical Magazine, a relationship between a fraction in the sequence and the fractions to its left and right. In discussing the connection between the Riemann hypothesis and Farey sequences, Sabbagh writes that, mathematician G.H. Hardy “said, somewhat cruelly:\r\nJust once in his life Mr. Farey rose above mediocrity, and made an original observation. He did not understand very well what he was doing, and he was too weak a mathematician to prove the quite simple theorem he had discovered. It is evident also that he did not consider his discovery…at all important…He had obviously no idea that this casual letter was the one event of real importance in his life. We may be tempted to think that Farey was very lucky; but a man who has made an observation that has escaped Fermat and Euler deserves any luck that comes his way.”  \r\nStunned by this mean-spirited statement—which Hardy read in a 1928 lecture in New York City, I decided to write a problem on the sequences named for Farey.","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: 474px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 237px; transform-origin: 407px 237px; 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-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 63.0083px 8px; transform-origin: 63.0083px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eProblem statement\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-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 92.1833px 8px; transform-origin: 92.1833px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe Farey sequence of order \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: 276.958px 8px; transform-origin: 276.958px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e consists of fractions between 0 and 1 expressed in reduced form in increasing order and with no denominator greater than \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: 222.075px 8px; transform-origin: 222.075px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. For example, the Farey sequence of order 3 is {0/1, 1/3, 1/2, 2/3, 1/1}. \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-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 176.842px 8px; transform-origin: 176.842px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to compute the Farey sequence of order \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: 185.508px 8px; transform-origin: 185.508px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. Put the numerators in the first row of a two-row matrix and denominators in the second row. \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-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 61.45px 8px; transform-origin: 61.45px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eFurther comments\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 126px; 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 63px; text-align: left; transform-origin: 384px 63px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 109.692px 8px; transform-origin: 109.692px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFarey sequences are connected to \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/60266\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration-line: underline; \"\u003eStern-Brocot\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: 175.408px 8px; transform-origin: 175.408px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e trees, but unlike some other problems of mine (e.g., CP \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/59791\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration-line: underline; \"\u003e59791\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: 15.5583px 8px; transform-origin: 15.5583px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/60311\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration-line: underline; \"\u003e60311\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: 5.65833px 8px; transform-origin: 5.65833px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e), this one was not inspired by a problem of minnolina’s. Instead it arose out of reading \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: 80.525px 8px; transform-origin: 80.525px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eThe Riemann Hypothesis:\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: 1.94167px 8px; transform-origin: 1.94167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \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: 14px 8px; transform-origin: 14px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003eThe Greatest Unsolved Problem in Mathematics \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: 234.567px 8px; transform-origin: 234.567px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eby Karl Sabbagh. Geologist John Farey noted, in a half-page 1816 paper in \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: 73.5417px 8px; transform-origin: 73.5417px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003ePhilosophical Magazine\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: 278.492px 8px; transform-origin: 278.492px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, a relationship between a fraction in the sequence and the fractions to its left and right. In discussing the connection between the Riemann hypothesis and Farey sequences, Sabbagh writes that, mathematician G.H. Hardy “said, somewhat cruelly:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 126px; 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 63px; text-align: left; transform-origin: 384px 63px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eJust once in his life Mr. Farey rose above mediocrity, and made an original observation. He did not understand very well what he was doing, and he was too weak a mathematician to prove the quite simple theorem he had discovered. It is evident also that he did not consider his discovery…at all important…He had obviously no idea that this casual letter was the one event of real importance in his life. We may be tempted to think that Farey was very lucky; but a man who has made an observation that has escaped Fermat and Euler deserves any luck that comes his way.” \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: 3.85px 8px; transform-origin: 3.85px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; font-style: italic; \"\u003e \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-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eStunned by this mean-spirited statement—which Hardy read in a 1928 lecture in New York City, I decided to write a problem on the sequences named for Farey.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = Farey(n)\r\n  y = [0 1:n 1; 1 n:-1:1 1]; % Numerators in the first row, denominators in the second\r\nend","test_suite":"%%\r\nn = 1;\r\ny = Farey(n);\r\ny_correct = [0 1; 1 1];\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 3;\r\ny = Farey(n);\r\ny_correct = [0 1 1 2 1; 1 3 2 3 1];\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 5;\r\ny = Farey(n);\r\ny_correct = [0 1 1 1 2 1 3 2 3 4 1; 1 5 4 3 5 2 5 3 4 5 1];\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 8;\r\ny = Farey(n);\r\ny_correct = [0 1 1 1 1 1 2 1 3 2 3 1 4 3 5 2 5 3 4 5 6 7 1; 1 8 7 6 5 4 7 3 8 5 7 2 7 5 8 3 7 4 5 6 7 8 1];\r\nassert(isequal(y,y_correct))\r\n\r\n%% \r\nn = 18;\r\ny = Farey(n);\r\ny_correct = [0 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1 3 2 3 1 3 2 3 4 1 4 3 5 2 5 3 4 5 1 6 5 4 3 5 7 2 7 5 3 7 4 5 6 7 8 1 9 8 7 6 5 9 4 7 10 3 11 8 5 7 9 11 2 11 9 7 12 5 13 8 11 3 13 10 7 11 4 13 9 14 5 11 6 13 7 15 8 9 10 11 12 13 14 15 16 17 1; ...\r\n             1 18 17 16 15 14 13 12 11 10 9 17 8 15 7 13 6 17 11 16 5 14 9 13 17 4 15 11 18 7 17 10 13 16 3 17 14 11 8 13 18 5 17 12 7 16 9 11 13 15 17 2 17 15 13 11 9 16 7 12 17 5 18 13 8 11 14 17 3 16 13 10 17 7 18 11 15 4 17 13 9 14 5 16 11 17 6 13 7 15 8 17 9 10 11 12 13 14 15 16 17 18 1];\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 81;\r\ny = Farey(n);\r\nf = y(1,:)./y(2,:);\r\nindx73 = find(y==73)';\r\nindx73_correct = [20 102 162 220 276 332 386 446 502 552 608 670 722 776 828 886 940 1006 1052 1104 1158 1214 1274 1340 1380 1440 1494 1552 1614 1662 1720 1772 1828 1886 1942 2012 2032 2102 2158 2216 2272 2324 2382 2430 2492 2550 2604 2664 2704 2770 2830 2886 2940 2992 3038 3104 3158 3216 3268 3322 3374 3436 3492 3542 3598 3641 3658 3693 3712 3735 3768 3787 3824 3835 3882 3889 3942 3945 4024 4025];\r\nwidth_correct = 2021;\r\nsum_correct = [54882; 109764];\r\nnprime_correct = 1648;\r\nassert(all(diff(f)\u003e0))\r\nassert(isequal(indx73,indx73_correct))\r\nassert(isequal(width(y),width_correct))\r\nassert(isequal(sum(y,2),sum_correct))\r\nassert(isequal(length(find(isprime(y))),nprime_correct))\r\n\r\n%%\r\nn = 188;\r\ny = Farey(n);\r\nf = y(1,:)./y(2,:);\r\nindx173 = find(y==173)';\r\nindx173_correct = [34 222 358 490 618 742 870 996 1124 1242 1370 1494 1624 1752 1876 1996 2124 2250 2378 2496 2618 2746 2876 3000 3120 3244 3374 3498 3606 3746 3872 3998 4118 4246 4364 4498 4624 4742 4868 4986 5116 5244 5388 5486 5614 5742 5868 5996 6118 6240 6366 6484 6618 6746 6870 6990 7124 7210 7360 7488 7616 7738 7852 7988 8100 8236 8358 8486 8630 8736 8860 8994 9114 9250 9362 9488 9602 9738 9862 9984 10112 10232 10366 10492 10618 10782 10814 10978 11104 11230 11364 11484 11612 11734 11858 11994 12108 12234 12346 12482 12602 12736 12860 12966 13110 13238 13360 13496 13608 13744 13858 13980 14108 14236 14386 14472 14606 14726 14850 14978 15112 15230 15356 15478 15600 15728 15854 15982 16110 16208 16352 16480 16610 16728 16854 16972 17098 17232 17350 17478 17598 17724 17850 17990 18098 18222 18352 18476 18596 18720 18850 18978 19100 19218 19346 19472 19600 19720 19844 19867 19972 19975 20089 20102 20195 20226 20309 20354 20417 20472 20527 20600 20643 20726 20761 20854 20877 20978 20997 21106 21117 21238 21245 21374 21377 21562 21563];\r\nwidth_correct = 10797;\r\nsum_correct = [678175; 1356350];\r\nnprime_correct = 7550;\r\nassert(all(diff(f)\u003e0))\r\nassert(isequal(indx173,indx173_correct))\r\nassert(isequal(width(y),width_correct))\r\nassert(isequal(sum(y,2),sum_correct))\r\nassert(isequal(length(find(isprime(y))),nprime_correct))\r\n\r\n%%\r\nn = 811;\r\ny = Farey(n);\r\nf = y(1,:)./y(2,:);\r\nindx773 = find(y==773)';\r\nindx773_correct = [80 892 1458 2014 2538 3078 3588 4124 4644 5160 5682 6200 6724 7254 7768 8266 8792 9298 9844 10358 10880 11388 11918 12434 12950 13470 13986 14504 15018 15540 16062 16592 17106 17628 18142 18656 19176 19700 20204 20720 21238 21772 22264 22802 23320 23846 24364 24888 25400 25916 26438 26956 27476 27992 28514 29028 29542 30046 30584 31098 31632 32136 32656 33174 33688 34202 34724 35240 35766 36286 36794 37318 37838 38360 38874 39396 39920 40428 40942 41452 41986 42500 43026 43554 44062 44534 45098 45618 46134 46652 47142 47692 48196 48722 49236 49754 50258 50778 51308 51826 52342 52860 53410 53900 54420 54940 55462 55980 56508 57032 57528 58054 58570 59092 59606 60104 60646 61164 61646 62196 62708 63256 63744 64270 64786 65310 65828 66354 66792 67376 67904 68406 68932 69454 69976 70492 71008 71544 72050 72566 73078 73586 74122 74632 75128 75678 76196 76718 77232 77738 78268 78784 79300 79836 80308 80848 81378 81892 82406 82924 83466 83968 84484 84992 85522 86040 86566 87100 87602 88118 88638 89138 89670 90188 90714 91228 91748 92266 92786 93306 93820 94330 94858 95394 95890 96412 96936 97456 97964 98486 99004 99532 100146 100532 101062 101586 102110 102626 103140 103664 104174 104702 105220 105732 106256 106786 107294 107812 108326 108848 109350 109878 110396 110916 111436 111946 112462 112996 113512 114030 114480 115056 115570 116094 116616 117132 117648 118168 118698 119202 119726 120196 120754 121278 121796 122314 122836 123342 123870 124384 124904 125422 125940 126470 126978 127480 128014 128536 129054 129576 130090 130616 131120 131646 132172 132694 133246 133570 134214 134744 135270 135788 136300 136820 137350 137862 138378 138894 139416 139934 140454 140968 141488 142014 142536 143080 143566 144092 144600 145124 145678 146154 146674 147192 147712 148236 148752 149262 149792 150250 150826 151348 151858 152382 152898 153420 153936 154450 154966 155490 156006 156524 157044 157564 158082 158602 159130 159644 160248 160668 161194 161712 162226 162762 163262 163792 164304 164826 165344 165860 166374 166930 167414 167934 168456 168974 169508 170004 170526 171040 171578 172068 172586 173118 173620 174160 174668 175194 175708 176226 176748 177254 177780 178288 178812 179332 179854 180368 180894 181406 181932 182438 182958 183476 183996 184512 185026 185552 186066 186588 187100 187622 188142 188660 189188 189708 190222 190742 191254 191768 192306 192816 193330 193860 194366 194886 195402 195924 196438 196958 197482 197998 198528 199054 199592 200282 200362 201052 201590 202116 202646 203162 203686 204206 204720 205242 205758 206278 206784 207314 207828 208338 208876 209390 209902 210422 210936 211456 211984 212502 213022 213544 214056 214578 215092 215618 216132 216648 217168 217686 218206 218712 219238 219750 220276 220790 221312 221832 222356 222864 223390 223896 224418 224936 225450 225976 226484 227024 227526 228058 228576 229066 229604 230118 230640 231136 231670 232188 232710 233230 233714 234270 234784 235300 235818 236340 236852 237382 237882 238418 238932 239450 239976 240396 241000 241514 242042 242562 243080 243600 244120 244638 245154 245678 246194 246708 247224 247746 248262 248786 249296 249818 250394 250852 251382 251892 252408 252932 253452 253970 254490 254966 255520 256044 256552 257078 257564 258108 258630 259156 259676 260190 260710 261228 261750 262266 262782 263294 263824 264344 264856 265374 265900 266430 267074 267398 267950 268472 268998 269524 270028 270554 271068 271590 272108 272630 273164 273666 274174 274704 275222 275740 276260 276774 277302 277808 278330 278848 279366 279890 280448 280918 281442 281946 282476 282996 283512 284028 284550 285074 285588 286164 286614 287132 287648 288182 288698 289208 289728 290248 290766 291294 291796 292318 292832 293350 293858 294388 294912 295424 295942 296470 296980 297504 298018 298534 299058 299582 300112 300498 301112 301640 302158 302680 303188 303708 304232 304754 305250 305786 306314 306824 307338 307858 308378 308896 309416 309930 310456 310974 311506 312006 312526 313042 313544 314078 314604 315122 315652 316160 316676 317178 317720 318238 318752 319266 319796 320336 320808 321344 321860 322376 322906 323412 323926 324448 324966 325516 326012 326522 327058 327566 328078 328594 329100 329636 330152 330668 331190 331712 332238 332740 333268 333852 334290 334816 335334 335858 336374 336900 337388 337936 338448 338998 339480 339998 340540 341038 341552 342074 342590 343116 343612 344136 344664 345182 345704 346224 346744 347234 347784 348302 348818 349336 349866 350386 350890 351408 351922 352448 352952 353502 353992 354510 355026 355546 356110 356582 357090 357618 358144 358658 359192 359702 360216 360724 361248 361770 362284 362806 363326 363850 364358 364878 365404 365920 366442 366956 367470 367988 368508 369012 369546 370060 370598 371102 371616 372130 372652 373168 373688 374206 374728 375244 375756 376280 376798 377324 377842 378380 378872 379406 379924 380440 380944 381468 381865 381988 382349 382502 382813 383016 383281 383538 383759 384052 384239 384582 384715 385104 385211 385626 385683 386140 386171 386645 386658 387125 387174 387609 387694 388101 388210 388579 388726 389073 389256 389561 389764 390045 390286 390541 390800 391039 391346 391549 391852 392043 392378 392537 392876 393019 393390 393517 393920 394035 394444 394535 394962 395045 395484 395547 396000 396055 396520 396563 397056 397091 397566 397589 398106 398125 398630 398641 399186 399193 399752 399755 400564 400565];\r\nwidth_correct = 200321;\r\nsum_correct = [54206832; 108413664];\r\nnprime_correct = 112653;\r\nassert(all(diff(f)\u003e0))\r\nassert(isequal(indx773,indx773_correct))\r\nassert(isequal(width(y),width_correct))\r\nassert(isequal(sum(y,2),sum_correct))\r\nassert(isequal(length(find(isprime(y))),nprime_correct))\r\n\r\n%%\r\nn = randi(134);\r\ny = Farey(n);\r\nm = width(y);\r\nb = y(2,:);\r\nassert(abs(sum(b(1:end-1)./b(2:end))-(3*m-4)/2)\u003c1e-5)\r\nassert(abs(sum(1./(b(1:end-1).*b(2:end)))-1)\u003c1e-5)\r\n\r\n%%\r\nfiletext = fileread('Farey.m');\r\nillegal = contains(filetext, 'assignin') || contains(filetext, 'assert'); \r\nassert(~illegal)","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":46909,"edited_by":46909,"edited_at":"2024-06-10T05:07:53.000Z","deleted_by":null,"deleted_at":null,"solvers_count":8,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2024-06-10T05:03:32.000Z","updated_at":"2024-06-10T05:07:53.000Z","published_at":"2024-06-10T05:03:55.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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eProblem statement\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 Farey sequence of order \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 consists of fractions between 0 and 1 expressed in reduced form in increasing order and with no denominator greater than \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. For example, the Farey sequence of order 3 is {0/1, 1/3, 1/2, 2/3, 1/1}. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to compute the Farey sequence of order \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. Put the numerators in the first row of a two-row matrix and denominators in the second row. \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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eFurther comments\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\u003eFarey sequences are connected to \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/60266\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eStern-Brocot\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e trees, but unlike some other problems of mine (e.g., CP \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/59791\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e59791\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/60311\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e60311\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e), this one was not inspired by a problem of minnolina’s. Instead it arose out of reading \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eThe Riemann Hypothesis:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eThe Greatest Unsolved Problem in Mathematics \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003eby Karl Sabbagh. Geologist John Farey noted, in a half-page 1816 paper in \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ePhilosophical Magazine\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, a relationship between a fraction in the sequence and the fractions to its left and right. In discussing the connection between the Riemann hypothesis and Farey sequences, Sabbagh writes that, mathematician G.H. Hardy “said, somewhat cruelly:\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:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eJust once in his life Mr. Farey rose above mediocrity, and made an original observation. He did not understand very well what he was doing, and he was too weak a mathematician to prove the quite simple theorem he had discovered. It is evident also that he did not consider his discovery…at all important…He had obviously no idea that this casual letter was the one event of real importance in his life. We may be tempted to think that Farey was very lucky; but a man who has made an observation that has escaped Fermat and Euler deserves any luck that comes his way.” \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eStunned by this mean-spirited statement—which Hardy read in a 1928 lecture in New York City, I decided to write a problem on the sequences named for Farey.\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:\"mediant\"","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:\"mediant\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"mediant\"","","\"","mediant","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007faf50b238e0\u003e":null,"#\u003cMathWorks::Search::Field:0x00007faf50b23840\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007faf50b22440\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007faf50b23b60\u003e":1,"#\u003cMathWorks::Search::Field:0x00007faf50b23ac0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007faf50b23a20\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007faf50b23980\u003e":"tag:\"mediant\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007faf50b23980\u003e":"tag:\"mediant\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"cody-search","password":"78X075ddcV44","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"mediant\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"mediant\"","","\"","mediant","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007faf50b238e0\u003e":null,"#\u003cMathWorks::Search::Field:0x00007faf50b23840\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007faf50b22440\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007faf50b23b60\u003e":1,"#\u003cMathWorks::Search::Field:0x00007faf50b23ac0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007faf50b23a20\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007faf50b23980\u003e":"tag:\"mediant\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007faf50b23980\u003e":"tag:\"mediant\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":60486,"difficulty_rating":"medium"}]}}