{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-08-14T00:13:02.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-08-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":61445,"title":"Gear ratio of a gear pair","description":"Let's assume that we have a pair of two gears(pinion-bigger gear). The goal is to calculate the gear ratio(i) given the number (z) of the teeth on both gears. The number of teeth on pinion will be zp and the number of teeth on the bigger gear will be zg. Also assume that the starting gear is the pinion. \r\nTips:\r\n1)BE CAREFULL OF THE REAL WORLD LOGIC!!! (The output can also be:'Not a gear' or 'Not a pair of pinion and gear').\r\n2)The only unreasonable thing is that one gear can have almost infinite teeth.\r\n3) If you find the logic of tip 1, the messages should be in order. First you shoul write about the 'Not a gear' message and then about the 'Not a pair of pinion and gear message.\r\nGOOD LUCK!!!!!!!!!!!!!!!!!","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 234px; display: block; min-width: 0px; padding-block-start: 0px; padding-inline-start: 2px; padding-left: 2px; padding-top: 0px; perspective-origin: 469px 117px; transform-origin: 469px 117px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; 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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 31.5px; text-align: left; transform-origin: 445px 31.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eLet's assume that we have a pair of two gears(pinion-bigger gear). The goal is to calculate the gear ratio(i) given the number (z) of the teeth on both gears. The number of teeth on pinion will be zp and the number of teeth on the bigger gear will be zg. Also assume that the starting gear is the pinion. \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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 10.5px; text-align: left; transform-origin: 445px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eTips:\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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 10.5px; text-align: left; transform-origin: 445px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1)BE CAREFULL OF THE REAL WORLD LOGIC!!! (The output can also be:'Not a gear' or 'Not a pair of pinion and gear').\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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 10.5px; text-align: left; transform-origin: 445px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e2)The only unreasonable thing is that one gear can have almost infinite teeth.\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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 21px; text-align: left; transform-origin: 445px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e3) If you find the logic of tip 1, the messages should be in order. First you shoul write about the 'Not a gear' message and then about the 'Not a pair of pinion and gear message.\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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 10.5px; text-align: left; transform-origin: 445px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGOOD LUCK!!!!!!!!!!!!!!!!!\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function i = gearRatio(zp,zg)\r\n  \r\nend","test_suite":"%%\r\nzp = 20;\r\nzg = 80;\r\ny_correct = 4;\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = 0;\r\nzg = 100000;\r\ny_correct = 'Not a gear';\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = 0;\r\nzg = 30;\r\ny_correct = 'Not a gear';\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = -80;\r\nzg = 80;\r\ny_correct = 'Not a gear';\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = 40;\r\nzg = 120;\r\ny_correct = 3;\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = 80;\r\nzg = 160;\r\ny_correct = 2;\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = 300;\r\nzg = 30;\r\ny_correct = 'Not a pair of pinion and gear';\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = 11;\r\nzg = 110;\r\ny_correct = 10;\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = 190;\r\nzg = 160;\r\ny_correct = 'Not a pair of pinion and gear';\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = -9000;\r\nzg = -8000;\r\ny_correct = 'Not a gear';\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = 80.1;\r\nzg = 160.32;\r\ny_correct = 'Not a gear';\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nnum_tests = 10; \r\n\r\nfor test_idx = 1:num_tests\r\n    \r\n    case_type = randi([1, 4]);\r\n    \r\n    switch case_type\r\n        case 1 \r\n            zp = randi([12, 40]);\r\n            zg = randi([zp, 120]);\r\n            \r\n        case 2 \r\n            if rand \u003e 0.5\r\n                zp = randi([-20, 0]);\r\n                zg = randi([10, 50]);\r\n            else\r\n                zp = randi([10, 50]);\r\n                zg = randi([-20, 0]);\r\n            end\r\n            \r\n        case 3 \r\n            if rand \u003e 0.5\r\n                zp = 12 + rand; % παράγει δεκαδικό π.χ. 12.43\r\n                zg = randi([20, 60]);\r\n            else\r\n                zp = randi([12, 30]);\r\n                zg = 25 + rand;\r\n            end\r\n            \r\n        case 4 \r\n            zp = randi([40, 80]);\r\n            zg = randi([10, 35]);\r\n    end\r\n    \r\n    if zp \u003c= 0 || zg \u003c= 0 || floor(zp) ~= zp || floor(zg) ~= zg\r\n        i_correct = 'Not a gear';\r\n    elseif zp \u003e zg\r\n        i_correct = 'Not a pair of pinion and gear';\r\n    else\r\n        i_correct = zg / zp;\r\n    end\r\n    \r\n    i_user = gearRatio(zp, zg); \r\n \r\n    if ischar(i_correct) || isstring(i_correct)\r\n        assert(ischar(i_user) || isstring(i_user), ...\r\n            sprintf('Failed for zp=%g, zg=%g. Expected string output.', zp, zg));\r\n        assert(strcmp(char(i_user), char(i_correct)), ...\r\n            sprintf('Failed for zp=%g, zg=%g. Expected: \"%s\", Got: \"%s\"', zp, zg, i_correct, i_user));\r\n    else\r\n        assert(isnumeric(i_user), ...\r\n            sprintf('Failed for zp=%g, zg=%g. Expected numeric output.', zp, zg));\r\n        assert(abs(i_user - i_correct) \u003c 1e-4, ...\r\n            sprintf('Failed for zp=%g, zg=%g. Expected: %.4f, Got: %.4f', zp, zg, i_correct, i_user));\r\n    end\r\n    \r\nend","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":5158730,"edited_by":5158730,"edited_at":"2026-08-22T18:35:44.000Z","deleted_by":null,"deleted_at":null,"solvers_count":0,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2026-08-22T17:18:07.000Z","updated_at":"2026-08-22T18:35:44.000Z","published_at":"2026-08-22T18:35:44.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLet's assume that we have a pair of two gears(pinion-bigger gear). The goal is to calculate the gear ratio(i) given the number (z) of the teeth on both gears. The number of teeth on pinion will be zp and the number of teeth on the bigger gear will be zg. Also assume that the starting gear is the pinion. \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\u003eTips:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1)BE CAREFULL OF THE REAL WORLD LOGIC!!! (The output can also be:'Not a gear' or 'Not a pair of pinion and gear').\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2)The only unreasonable thing is that one gear can have almost infinite teeth.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e3) If you find the logic of tip 1, the messages should be in order. First you shoul write about the 'Not a gear' message and then about the 'Not a pair of pinion and gear message.\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\u003eGOOD LUCK!!!!!!!!!!!!!!!!!\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":{"problems":[{"id":61445,"title":"Gear ratio of a gear pair","description":"Let's assume that we have a pair of two gears(pinion-bigger gear). The goal is to calculate the gear ratio(i) given the number (z) of the teeth on both gears. The number of teeth on pinion will be zp and the number of teeth on the bigger gear will be zg. Also assume that the starting gear is the pinion. \r\nTips:\r\n1)BE CAREFULL OF THE REAL WORLD LOGIC!!! (The output can also be:'Not a gear' or 'Not a pair of pinion and gear').\r\n2)The only unreasonable thing is that one gear can have almost infinite teeth.\r\n3) If you find the logic of tip 1, the messages should be in order. First you shoul write about the 'Not a gear' message and then about the 'Not a pair of pinion and gear message.\r\nGOOD LUCK!!!!!!!!!!!!!!!!!","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 234px; display: block; min-width: 0px; padding-block-start: 0px; padding-inline-start: 2px; padding-left: 2px; padding-top: 0px; perspective-origin: 469px 117px; transform-origin: 469px 117px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; 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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 31.5px; text-align: left; transform-origin: 445px 31.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eLet's assume that we have a pair of two gears(pinion-bigger gear). The goal is to calculate the gear ratio(i) given the number (z) of the teeth on both gears. The number of teeth on pinion will be zp and the number of teeth on the bigger gear will be zg. Also assume that the starting gear is the pinion. \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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 10.5px; text-align: left; transform-origin: 445px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eTips:\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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 10.5px; text-align: left; transform-origin: 445px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e1)BE CAREFULL OF THE REAL WORLD LOGIC!!! (The output can also be:'Not a gear' or 'Not a pair of pinion and gear').\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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 10.5px; text-align: left; transform-origin: 445px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e2)The only unreasonable thing is that one gear can have almost infinite teeth.\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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 21px; text-align: left; transform-origin: 445px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e3) If you find the logic of tip 1, the messages should be in order. First you shoul write about the 'Not a gear' message and then about the 'Not a pair of pinion and gear message.\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; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 445px 10.5px; text-align: left; transform-origin: 445px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGOOD LUCK!!!!!!!!!!!!!!!!!\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function i = gearRatio(zp,zg)\r\n  \r\nend","test_suite":"%%\r\nzp = 20;\r\nzg = 80;\r\ny_correct = 4;\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = 0;\r\nzg = 100000;\r\ny_correct = 'Not a gear';\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = 0;\r\nzg = 30;\r\ny_correct = 'Not a gear';\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = -80;\r\nzg = 80;\r\ny_correct = 'Not a gear';\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = 40;\r\nzg = 120;\r\ny_correct = 3;\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = 80;\r\nzg = 160;\r\ny_correct = 2;\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = 300;\r\nzg = 30;\r\ny_correct = 'Not a pair of pinion and gear';\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = 11;\r\nzg = 110;\r\ny_correct = 10;\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = 190;\r\nzg = 160;\r\ny_correct = 'Not a pair of pinion and gear';\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = -9000;\r\nzg = -8000;\r\ny_correct = 'Not a gear';\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nzp = 80.1;\r\nzg = 160.32;\r\ny_correct = 'Not a gear';\r\nassert(isequal(gearRatio(zp,zg),y_correct))\r\n%%\r\nnum_tests = 10; \r\n\r\nfor test_idx = 1:num_tests\r\n    \r\n    case_type = randi([1, 4]);\r\n    \r\n    switch case_type\r\n        case 1 \r\n            zp = randi([12, 40]);\r\n            zg = randi([zp, 120]);\r\n            \r\n        case 2 \r\n            if rand \u003e 0.5\r\n                zp = randi([-20, 0]);\r\n                zg = randi([10, 50]);\r\n            else\r\n                zp = randi([10, 50]);\r\n                zg = randi([-20, 0]);\r\n            end\r\n            \r\n        case 3 \r\n            if rand \u003e 0.5\r\n                zp = 12 + rand; % παράγει δεκαδικό π.χ. 12.43\r\n                zg = randi([20, 60]);\r\n            else\r\n                zp = randi([12, 30]);\r\n                zg = 25 + rand;\r\n            end\r\n            \r\n        case 4 \r\n            zp = randi([40, 80]);\r\n            zg = randi([10, 35]);\r\n    end\r\n    \r\n    if zp \u003c= 0 || zg \u003c= 0 || floor(zp) ~= zp || floor(zg) ~= zg\r\n        i_correct = 'Not a gear';\r\n    elseif zp \u003e zg\r\n        i_correct = 'Not a pair of pinion and gear';\r\n    else\r\n        i_correct = zg / zp;\r\n    end\r\n    \r\n    i_user = gearRatio(zp, zg); \r\n \r\n    if ischar(i_correct) || isstring(i_correct)\r\n        assert(ischar(i_user) || isstring(i_user), ...\r\n            sprintf('Failed for zp=%g, zg=%g. Expected string output.', zp, zg));\r\n        assert(strcmp(char(i_user), char(i_correct)), ...\r\n            sprintf('Failed for zp=%g, zg=%g. Expected: \"%s\", Got: \"%s\"', zp, zg, i_correct, i_user));\r\n    else\r\n        assert(isnumeric(i_user), ...\r\n            sprintf('Failed for zp=%g, zg=%g. Expected numeric output.', zp, zg));\r\n        assert(abs(i_user - i_correct) \u003c 1e-4, ...\r\n            sprintf('Failed for zp=%g, zg=%g. Expected: %.4f, Got: %.4f', zp, zg, i_correct, i_user));\r\n    end\r\n    \r\nend","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":5158730,"edited_by":5158730,"edited_at":"2026-08-22T18:35:44.000Z","deleted_by":null,"deleted_at":null,"solvers_count":0,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2026-08-22T17:18:07.000Z","updated_at":"2026-08-22T18:35:44.000Z","published_at":"2026-08-22T18:35:44.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLet's assume that we have a pair of two gears(pinion-bigger gear). The goal is to calculate the gear ratio(i) given the number (z) of the teeth on both gears. The number of teeth on pinion will be zp and the number of teeth on the bigger gear will be zg. Also assume that the starting gear is the pinion. \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\u003eTips:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1)BE CAREFULL OF THE REAL WORLD LOGIC!!! (The output can also be:'Not a gear' or 'Not a pair of pinion and gear').\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2)The only unreasonable thing is that one gear can have almost infinite teeth.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e3) If you find the logic of tip 1, the messages should be in order. First you shoul write about the 'Not a gear' message and then about the 'Not a pair of pinion and gear message.\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\u003eGOOD LUCK!!!!!!!!!!!!!!!!!\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\"}]}"}],"errors":[],"facets":[[],[{"value":"unrated","count":1,"selected":false}]],"term":"tag:\"gears\"","page":1,"per_page":50,"sort":"map(difficulty_value,0,0,999) asc"}}