{"id":22433779,"url":"https://github.com/nlitsme/mpmp7_solver","last_synced_at":"2026-04-30T17:31:34.819Z","repository":{"id":71128435,"uuid":"267957294","full_name":"nlitsme/mpmp7_solver","owner":"nlitsme","description":"Solving Matt Parker's Unique Distancing Puzzle","archived":false,"fork":false,"pushed_at":"2023-08-22T20:05:55.000Z","size":71,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T07:48:55.508Z","etag":null,"topics":["cpp","puzzle","python","solving"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nlitsme.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2020-05-29T21:20:00.000Z","updated_at":"2024-12-24T15:02:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"2a297be5-0216-4fbf-ab1e-3c01ba307f88","html_url":"https://github.com/nlitsme/mpmp7_solver","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nlitsme/mpmp7_solver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlitsme%2Fmpmp7_solver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlitsme%2Fmpmp7_solver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlitsme%2Fmpmp7_solver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlitsme%2Fmpmp7_solver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nlitsme","download_url":"https://codeload.github.com/nlitsme/mpmp7_solver/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlitsme%2Fmpmp7_solver/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32472396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"ssl_error","status_checked_at":"2026-04-30T13:12:06.837Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["cpp","puzzle","python","solving"],"created_at":"2024-12-05T22:15:53.399Z","updated_at":"2026-04-30T17:31:34.805Z","avatar_url":"https://github.com/nlitsme.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Solver for n-dimensional variants of the MPMP7 Unique Distancing problem.\n\nProject with tools for the 7th [Matt Parker Math Puzzle problem](http://think-maths.co.uk/uniquedistance).\n\n * Solution for the problem stated in the MPMP7 youtube video.\n * Solutions for smaller and larger grids.\n * Solutions in 3 or more dimensional grids\n * Can I fit more markers on the grid?\n * Can I solve this on an 8x8 grid?\n * Do solutions exist for larger 2D grids?\n\n\nYay, Matt mentiond my solution in [MPMS: Unique Distancing Problem](https://www.youtube.com/watch?v=G0i_YSFvMb0\u0026t=666s)\nBTW, note the time offset 🤘\n \n# The problem\n\nArrange N counters on an NxN grid, such that all the\ndistances between the counters are different.\n\n# First a solution to the problem stated in the MPMP7 youtube video:\n\n[The video](https://www.youtube.com/watch?v=M_YOCQaI5QI)\n\n    python3 mpmp7_unique_distances.py --width 6 --verbose\n\nThis will output these two solutions.\n\n    *.....\n    *.....\n    .....*\n    .*....\n    ......\n    ...*.*\n\nor\n\n    *.....\n    ......\n    *.....\n    ...*..\n    ....**\n    *.....\n\nThe script will not terminate immediately, since it will keep searching for more solutions, \nwhich it will not find.\n\nI also wrote a C++ program to do the same, but much faster:\n\n    ./mpmp7-unique-distances -p 6\n\n\n# Solutions for smaller and larger grids.\n\nFirst, as stated by Matt in his video, for the 3x3 case there are 5 solutions:\n\n    ..*    ...    .**    ...    *.*\n    **.    ..*    ...    *.*    *..\n    ...    **.    *..    *..    ...\n\nThough you could argue that the first two, and also the last two look identical,\nwith respect to translation. I did not look into counting those as duplicates.\n\n\nThen the 2x2 grid, this one is pretty obvious, these are the two solutions:\n\n    *.   *.\n    *.   .*\n\nThe simplest grid, being the 1x1 grid has 1 solution:\n\n    *\n\nOr is that the simplest?  what about a 0x0 grid:\n\n\nWell, I am not sure if that counts as 0 or 1 solution.\n\n\nHere is a table listing the number of solutions for the remaining grid sizes:\n\n| size  |  solution count    |\n| -----:| ------------------:|\n|    0  |     0 or 1         |\n|    1  |       1            |\n|    2  |       2            |\n|    3  |       5            |\n|    4  |      23            |\n|    5  |      35            |\n|    6  |       2            |\n|    7  |       1            |\n|    8  |       0            |\n\nHere is the solution for the 7x7 grid:\n\n    *..*...\n    .......\n    **.....\n    .......\n    .......\n    .....*.\n    ..*...*\n\n\n\n# Solutions in 3 or more dimensional grids\n\nNow Why stop at flat grids, you can solve this for 3-D 'grids' as well:\n\n\n| size  |  3D solution count    |\n| -----:| ------------------:|\n|    2  |            3 |\n|    3  |           50 |\n|    4  |         3983 |\n|    5  |       \u003e=1185 |\n|    6  |              |\n|    7  |       \u003e=3446 |\n\nThen in 4-D I was only able to solve this for 2x2x2x2 and 3x3x3x3 grids.\nThe following table list the number of solutions found for the various higher\ndimensional grids:\n\n| size  |    4D     |       5D  |       6D  |       7D  |\n| -----:| ---------:| ---------:| ---------:| ---------:|\n|    2  |         4 |       5   |       6   |       7   |\n|    3  |       261 |    \u003e=255  |    \u003e= 37  |    \u003e=16   |\n|    4  |     \u003e=766 |    \u003e=81   |           |           |\n\nin 5-D there are 5 solutions for the 2-sized grid. and more than 800 for the 3-sized grid,\nI did not wait for my program to complete it's search.\n\n\n\n# Can I fit more markers on the grid?\n\nFor the 3D and higher dimensional grids you can,\nhere is a table of the most markers you can fit for a given size and dimension:\n\n| size/dim  |    2D   |      3D     |    4D     |   5D  |   6D   |   7D   |\n|  ----:|   --------:| ----------:| --------:| ----:| -----:| -----:|    \n| 2     |        2   |      3     |    3     |  3   |  4    |  4    |\n| 3     |        3   |      4     |    5     | \u003e=6  |  \u003e=6  |  4    |\n| 4     |        4   |      6     |   \u003e=7    | \u003e=4  |  \u003e=3  | \u003e=3   |\n| 5     |        5   |     \u003e=7    |          |      |       |       |\n| 6     |        6   |     \u003e=8    |          |      |       |       |\n| 7     |        7   |     \u003e=8    |          |      |       |       |\n\n\nThe empty slots in the table were computationally too expensive to determine.\n\n\n# Can I solve this on an 8x8 grid?\n\nNot with 8 markers, but there are 927 ways you can solve this with 7 markers.\n\nHere is one solution:\n\n    *......*\n    *.......\n    ........\n    *.......\n    .*......\n    .......*\n    ..*.....\n    ........\n\n\n# Do solutions exist for larger 2D grids?\n\nWith less markers you can solve this ( obviously ).\nHere is a table listing the maximum number of markers you can fit on 2D grids:\n\n| grid size   |  max counters |\n|  -----:|  -----------:|\n|  2     |    2      |\n|  3     |    3      |\n|  4     |    4      |\n|  5     |    5      |\n|  6     |    6      |\n|  7     |    7      |\n|  8     |    7      |\n|  9     |   \u003e=8     |\n| 10     |   \u003e=8     |\n| 11     |   \u003e=9     |\n| 12     |   \u003e=9     |\n| 13     |   \u003e=9     |\n| 14     |   \u003e=8     |\n| 15     |   \u003e=8     |\n\n\n# Build the C++ project\n\nSimple really: just pass the c++14 flag, there are no other dependencies.\n\n    clang++ -O3 -std=c++14 mpmp7-unique-distances.cpp -o mpmp7-unique-distances\n\n\n# BUGS ( that may never be fixed )\n\n * parameters  2 7 2  take really long --\u003e most time spent rotating arrangements.\n * most solutions are found in the first 10% of the running time --\u003e maybe i am generating way too many arrangements,\n   and i could stop searching way earlier.\n * some, like 6 3 6,  make a very wrong 'approxpersecond' estimate.\n * Everything i wrote in the document might be wrong.\n\n# AUTHOR\n\nWillem Hengeveld \u003citsme@xs4all.nl\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnlitsme%2Fmpmp7_solver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnlitsme%2Fmpmp7_solver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnlitsme%2Fmpmp7_solver/lists"}