{"id":16950174,"url":"https://github.com/sbplat/reciprocal","last_synced_at":"2025-07-30T07:09:28.769Z","repository":{"id":161374678,"uuid":"510775311","full_name":"sbplat/reciprocal","owner":"sbplat","description":"Find all unique positive integer solutions to a reciprocal equation of the form: 1/x_1 + 1/x_2 + ... + 1/x_n = k.","archived":false,"fork":false,"pushed_at":"2024-01-13T19:13:16.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-05T04:19:23.986Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://sbplat.github.io/reciprocal/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sbplat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-05T14:39:00.000Z","updated_at":"2024-01-13T19:14:53.000Z","dependencies_parsed_at":"2024-01-13T19:16:35.451Z","dependency_job_id":null,"html_url":"https://github.com/sbplat/reciprocal","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sbplat/reciprocal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbplat%2Freciprocal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbplat%2Freciprocal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbplat%2Freciprocal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbplat%2Freciprocal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sbplat","download_url":"https://codeload.github.com/sbplat/reciprocal/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbplat%2Freciprocal/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267827505,"owners_count":24150350,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T21:57:00.388Z","updated_at":"2025-07-30T07:09:28.731Z","avatar_url":"https://github.com/sbplat.png","language":"JavaScript","readme":"# Reciprocal Equation Solver\n\nFind all unique positive integer solutions to a reciprocal equation of the form: $\\frac{1}{x_1}+\\frac{1}{x_2}+\\ldots+\\frac{1}{x_n}=k$. Try it out [here](https://sbplat.github.io/reciprocal/)!\n\n## How does it work?\n\nWe use a combination of brute force and narrowing down the search space to find all the solutions.\n\nLet's start with a simple example, with $n=2$ terms and the right hand side $k=1$. We are asked to solve the equation $\\frac{1}{x_1}+\\frac{1}{x_2}=1$.\nWithout loss of generality, let's assume $x_2\\geq x_1\\implies\\frac{1}{x_2}\\leq\\frac{1}{x_1}$.\nThen, we have the following inequalities:\n```math\n\\tag{1}\n\\begin{aligned}\n    1=\\frac{1}{x_1}+\\frac{1}{x_2}\\leq\\frac{1}{x_1}+\\frac{1}{x_1}=\\frac{2}{x_1}\\implies x_1\\leq 2\n\\end{aligned}\n```\n```math\n\\tag{2}\n\\begin{aligned}\n    1=\\frac{1}{x_1}+\\frac{1}{x_2}\\geq\\frac{1}{x_2}+\\frac{1}{x_2}=\\frac{2}{x_2}\\implies x_2\\geq 2\n\\end{aligned}\n```\nObserve that $(1)$ is extremely crucial, while $(2)$ is not. This is because $(1)$ gives us an upper bound on $x_1$, and since $x_1$ is a positive integer, we just need to brute force all the values of $x_1$ in $[1, 2]$. This significantly narrows down the search space and makes it a much easier problem.\n\nNow, what if $k$ is a rational number? We can still follow the same approach as above to narrow it down. There's only one extra step: we need to make sure the last term ($\\frac{1}{x_2}$ in this case) is a reciprocal of a positive integer. If it's not, then it's not a solution.\n\nFinally, what if we had $n=3$ terms and the right hand side $k\\in\\mathbb{Q}$? We can follow a similar approach and reach the conclusion that $x_1\\leq\\frac{3}{k}$. Recursively following this approach gives us an algorithm to find all the solutions. You can check out the implementation [here](https://github.com/sbplat/reciprocal/blob/main/js/index.js).\n\n## How do I run this from source?\n\n1. First, clone the repository and change into the directory:\n```sh\ngit clone https://github.com/sbplat/reciprocal.git\ncd reciprocal\n```\n2. Open `index.html` with your browser.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbplat%2Freciprocal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbplat%2Freciprocal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbplat%2Freciprocal/lists"}