{"id":23699760,"url":"https://github.com/techmmunity/water-jug-solver","last_synced_at":"2025-07-01T04:08:21.808Z","repository":{"id":57711705,"uuid":"514611848","full_name":"techmmunity/water-jug-solver","owner":"techmmunity","description":null,"archived":false,"fork":false,"pushed_at":"2023-02-27T12:14:24.000Z","size":613,"stargazers_count":0,"open_issues_count":7,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-22T18:33:45.357Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@techmmunity/water-jug-solver","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/techmmunity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-16T15:14:00.000Z","updated_at":"2022-07-16T18:48:39.000Z","dependencies_parsed_at":"2025-02-20T03:41:11.509Z","dependency_job_id":"6c1a49ee-ed8b-4d72-a1ff-6a639aa9bbbd","html_url":"https://github.com/techmmunity/water-jug-solver","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":"techmmunity/base-project-packages","purl":"pkg:github/techmmunity/water-jug-solver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techmmunity%2Fwater-jug-solver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techmmunity%2Fwater-jug-solver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techmmunity%2Fwater-jug-solver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techmmunity%2Fwater-jug-solver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/techmmunity","download_url":"https://codeload.github.com/techmmunity/water-jug-solver/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techmmunity%2Fwater-jug-solver/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262893666,"owners_count":23380712,"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","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-12-30T08:15:42.463Z","updated_at":"2025-07-01T04:08:21.778Z","avatar_url":"https://github.com/techmmunity.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n\u003cimg src=\"https://github.com/techmmunity/water-jug-solver/raw/master/resources/banner.jpg\" width=\"600\" height=\"450\"\u003e\n\n# Techmmunity - Water Jug Challenge Solver\n\n\u003ca href=\"https://github.com/techmmunity/eslint-config\"\u003e\n\t\u003cimg src=\"https://img.shields.io/badge/style%20guide-Techmmunity-01d2ce?style=for-the-badge\" alt=\"Style Guide: Techmmunity\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://coveralls.io/github/techmmunity/water-jug-solver?branch=master\"\u003e\n\t\u003cimg src=\"https://img.shields.io/coveralls/github/techmmunity/water-jug-solver/master?style=for-the-badge\" alt=\"Coveralls\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://github.com/techmmunity/water-jug-solver/actions/workflows/coverage.yml\"\u003e\n\t\u003cimg src=\"https://img.shields.io/github/workflow/status/techmmunity/water-jug-solver/tests?label=tests\u0026logo=github\u0026style=for-the-badge\" alt=\"Tests\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/@techmmunity/water-jug-solver\"\u003e\n\t\u003cimg src=\"https://img.shields.io/npm/v/@techmmunity/water-jug-solver.svg?color=CC3534\u0026style=for-the-badge\" alt=\"Npm\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/@techmmunity/water-jug-solver\"\u003e\n\t\u003cimg src=\"https://img.shields.io/npm/dw/@techmmunity/water-jug-solver.svg?style=for-the-badge\" alt=\"Downloads\"\u003e\n\u003c/a\u003e\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n\u003c/div\u003e\n\nGiven two water jugs with capacities X and Y litres. Initially, both the jugs are empty. Also given that there is an infinite amount of water available. The jugs do not have markings to measure smaller quantities.\nOne can perform the following operations on the jug:\n\n- Fill any of the jugs completely with water.\n- Pour water from one jug to the other until one of the jugs is either empty or full, (X, Y) -\u003e (X – d, Y + d)\n- Empty any of the jugs\n\nThe task is to determine whether it is possible to measure Z litres of water using both the jugs. And if true, print any of the possible ways.\n\n## Install\n\nWith Yarn:\n\n```sh\nyarn add @techmmunity/water-jug-solver\n```\n\nWith NPM:\n\n```sh\nnpm i @techmmunity/water-jug-solver\n```\n\n## Usage\n\nWith TypeScript:\n\n```ts\nimport { solveWaterJugChallenge } from \"@techmmunity/water-jug-solver\";\n\nconsole.log(\n\tsolveWaterJugChallenge({\n\t\tfirstJugCapacity: 2,\n\t\tsecondJugCapacity: 10,\n\t\tdesiredAmount: 4,\n\t})\n);\n\n// Output\n\n{\n\tsolvable: true,\n\tminSteps: 4,\n\tsmallerJugCapacity: 2,\n\tlargerJugCapacity: 10,\n\tsteps: [\n\t\t{\n\t\t\tsmallerJugContent: 2,\n\t\t\tlargerJugContent: 0,\n\t\t\tindex: \"2,0\",\n\t\t\taction: {\n\t\t\t\ttype: \"FILL\",\n\t\t\t\tjug: \"SMALLER\",\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tsmallerJugContent: 0,\n\t\t\tlargerJugContent: 2,\n\t\t\tindex: \"0,2\",\n\t\t\taction: {\n\t\t\t\ttype: \"TRANSFER\",\n\t\t\t\toriginJug: \"SMALLER\",\n\t\t\t\tdestinationJug: \"BIGGER\",\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tsmallerJugContent: 2,\n\t\t\tlargerJugContent: 2,\n\t\t\tindex: \"2,2\",\n\t\t\taction: {\n\t\t\t\ttype: \"FILL\",\n\t\t\t\tjug: \"SMALLER\",\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tsmallerJugContent: 0,\n\t\t\tlargerJugContent: 4,\n\t\t\tindex: \"0,4\",\n\t\t\taction: {\n\t\t\t\ttype: \"TRANSFER\",\n\t\t\t\toriginJug: \"SMALLER\",\n\t\t\t\tdestinationJug: \"BIGGER\",\n\t\t\t},\n\t\t},\n\t],\n}\n```\n\n## How to contribute?\n\nAll the details about contributing to the project are [described here](https://github.com/techmmunity/base-project-services/blob/master/CONTRIBUTING.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechmmunity%2Fwater-jug-solver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechmmunity%2Fwater-jug-solver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechmmunity%2Fwater-jug-solver/lists"}