{"id":19758599,"url":"https://github.com/alvarogarcia7/kata-formulation-pool-balls","last_synced_at":"2026-03-02T09:33:23.409Z","repository":{"id":69481230,"uuid":"76122759","full_name":"alvarogarcia7/kata-formulation-pool-balls","owner":"alvarogarcia7","description":null,"archived":false,"fork":false,"pushed_at":"2017-07-03T18:08:03.000Z","size":500,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-28T09:24:23.638Z","etag":null,"topics":["description","kata","kata-description","kata-formulation","pool","pool-balls","problem"],"latest_commit_sha":null,"homepage":null,"language":null,"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/alvarogarcia7.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":"2016-12-10T16:02:26.000Z","updated_at":"2017-02-26T15:06:35.000Z","dependencies_parsed_at":"2023-05-12T14:31:07.162Z","dependency_job_id":null,"html_url":"https://github.com/alvarogarcia7/kata-formulation-pool-balls","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alvarogarcia7/kata-formulation-pool-balls","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvarogarcia7%2Fkata-formulation-pool-balls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvarogarcia7%2Fkata-formulation-pool-balls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvarogarcia7%2Fkata-formulation-pool-balls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvarogarcia7%2Fkata-formulation-pool-balls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alvarogarcia7","download_url":"https://codeload.github.com/alvarogarcia7/kata-formulation-pool-balls/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvarogarcia7%2Fkata-formulation-pool-balls/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29997213,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-02T01:47:34.672Z","status":"online","status_checked_at":"2026-03-02T02:00:07.342Z","response_time":60,"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":["description","kata","kata-description","kata-formulation","pool","pool-balls","problem"],"created_at":"2024-11-12T03:25:15.182Z","updated_at":"2026-03-02T09:33:23.374Z","avatar_url":"https://github.com/alvarogarcia7.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pool Balls kata formulation\n\n## Description\n\nThe pool balls must be distributed in a very specific fashion, according to the rules.\n\nThe balls end up inside the triangle in a random order (depending on the previous match).\n\nYour job is to arrange the balls in their correct order.\n\n## Problems\n\n### Problem 1\n\nCalculate **the minimum number** of necessary ball swaps from the initial state to the corect one\n\nHint: It does not matter which swaps if there are several paths to completion\n\n### Problem 2\n\nCalculate **which ball swaps** are the minimum necessary set to arrange the balls. \n\nSuggestion: solve problem 1 first\n\n### Problem 3 (:star:)\n\nCalculate **which ball swaps** are the longest path from the initial state to the correct one, without repeating intermediate states (i.e., there are not loops in the states)\n\nExample:\n  \n  * Assume `YRY` is the correct state\n  * Assume `RYY` is the initial state\n  * So you should rearrange the `RYY` balls into the `YRY` arrangement\n  \nThe solution is:\n```\namount:2\nswap:0,2\nswap:1,2\n```\n\nExplanation:\n\n  * From the initial state, `swap:0,1` (`RYY` -\u003e `YRY`) solves the problem\n  * From the initial state, `swap:1,2` (`RYY` -\u003e `RYY`) is a forbidden swap because it is idempotent (i.e., introduces no change in the state)\n  * From the initial state, `swap:0,2` (`RYY` -\u003e `YYR`)\n     * `swap:0,2` (`YYR` -\u003e `RYY`) is forbidden for repeating state (introduces a loop)\n     * `swap:1,2` (`YYR` -\u003e `YRY`) solves the problem\n \nGiven that there are two solutions (`amount:1` and `amount:2`), we prefer the one with the biggest `amount`\n\n\n## Business domain\n\n### Official pool arrangement\n\nThe desired shape should be:\n\n```RYRRBYYRYRRYRYY```\n\naltough this could be changed in a future release\n\n### Representation equivalence\n\nTheorem: A triangle of pool balls is equivalent to an array of ball representations\n\nProof:\n\n\u003cimg src=\"./images/1.jpeg\" width=\"400\" height=\"400\"\u003e\n\nPosition the balls in any disposition. Here, showing the final one.\n\n\u003cimg src=\"./images/2.jpeg\" width=\"400\" height=\"400\"\u003e\n\nTake the balls from left to right, starting at the top then going down.\n\n\u003cimg src=\"./images/3.jpeg\" width=\"400\" height=\"400\"\u003e\n\nFrom the notation used, replace it with `Y` for yellow, `R` for red, `B` for black. Make it an array of characters\n\n\u003cimg src=\"./images/4.jpeg\" width=\"400\" height=\"400\"\u003e\n\nUsing the previous notation, convert it from an array of characters to a String (which is an array of characters in some languages)\n\nIn this case, a `String` is enough to represent it.\n\n### Format\n\nThe valid format is:\n\n  * `Y` for Yellow\n  * `B` for Black\n  * `R` for Red\n\n### Constraints\n\nThese are the general constraints for the problem:\n\n  * All initial dispositions are correct in terms of balls: i.e., the order of the balls might have changed, but the amount of each ball is correct.\n  * All balls with the same color are considered the identical.\n  * The swap operation cannot introduce repeated states (see example above).\n  * The swap operation must produce a new state, different than the old one.\n  \n## Input and output\n\nExpected input format:\n\n```\nYYYYYYYBRRRRRRR\n```\n\n15 balls coded as a String, indicating the order.\n\nExpected output format:\n\n```\namount:$AMOUNT\nswap:$FROM,$TO\nswap:$FROM,$TO\n```\n\nSome rules about the output:\n\n  * Given that the swap operation satisfies this property: `swap:X,Y` == `swap:Y,X`, we'll write the smaller number first. Implies: `X \u003c= Y`\n  * Given that the swap with itself (`swap:X,X`) is not a valid operation, implies: `X != Y`\n  * Corollary: For every swap between `X` and `Y` (`swap:X,Y`), `X \u003c Y`\n\nExample:\n\n```\namount:2\nswap:1,2\nswap:1,8\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falvarogarcia7%2Fkata-formulation-pool-balls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falvarogarcia7%2Fkata-formulation-pool-balls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falvarogarcia7%2Fkata-formulation-pool-balls/lists"}