{"id":20761832,"url":"https://github.com/james-p-d/magicsquare","last_synced_at":"2026-02-01T04:32:18.366Z","repository":{"id":218259623,"uuid":"745982826","full_name":"James-P-D/MagicSquare","owner":"James-P-D","description":"Magic Square solver in Prolog","archived":false,"fork":false,"pushed_at":"2024-01-20T18:49:27.000Z","size":553,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-10T09:45:20.089Z","etag":null,"topics":["magic-square","magic-square-solver","prolog"],"latest_commit_sha":null,"homepage":"","language":"Prolog","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/James-P-D.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}},"created_at":"2024-01-20T18:26:31.000Z","updated_at":"2024-01-20T18:51:37.000Z","dependencies_parsed_at":"2024-01-20T20:03:58.463Z","dependency_job_id":null,"html_url":"https://github.com/James-P-D/MagicSquare","commit_stats":null,"previous_names":["james-p-d/magicsquare"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/James-P-D/MagicSquare","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/James-P-D%2FMagicSquare","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/James-P-D%2FMagicSquare/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/James-P-D%2FMagicSquare/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/James-P-D%2FMagicSquare/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/James-P-D","download_url":"https://codeload.github.com/James-P-D/MagicSquare/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/James-P-D%2FMagicSquare/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28967927,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T03:46:10.227Z","status":"ssl_error","status_checked_at":"2026-02-01T03:46:01.693Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["magic-square","magic-square-solver","prolog"],"created_at":"2024-11-17T10:26:35.284Z","updated_at":"2026-02-01T04:32:18.353Z","avatar_url":"https://github.com/James-P-D.png","language":"Prolog","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MagicSquare\nMagic Square solver in Prolog\n\n![Screenshot](https://github.com/James-P-D/MagicSquare/blob/main/screenshot.gif)\n\n## Introduction\n\nThe [Magic Square](https://en.wikipedia.org/wiki/Magic_square) is a simple mathematical puzzle whereby the numbers `1` to `9` must be placed on a `3x3` board such that each row, column and diagonal add up to `15`.\n\nSo for example, given the following partial board...\n\n```\n 6 |   |   \n---+---+---\n   | 5 |   \n---+---+---\n 8 |   |   \n```\n\n...one possible solution is...\n\n```\n 6 | 7 | 2\n---+---+---\n 1 | 5 | 9\n---+---+---\n 8 | 3 | 4\n```\n\n...since summing the top row (`6+7+2`) is `15`, summing the left-most column (`6+1+8`) is `15`, and so on.\n\n## Running\n\nThe program was tested using on [SWI-Prolog](https://www.swi-prolog.org/). To load the script:\n\n```\n?- consult('C:\\\\Users\\\\jdorr\\\\OneDrive\\\\Desktop\\\\Dev\\\\MagicSquare\\\\src\\\\magic_square.pl').\n```\n\nWe can solve our example above with:\n\n```\n?- display_magic_square([[6,_,_],[_,5,_],[8,_,_]]).\n\n 6 | 7 | 2\n---+---+---\n 1 | 5 | 9\n---+---+---\n 8 | 3 | 4\ntrue;\nfalse\n```\n\nWe can also find all possible solutions for an empty board:\n\n```\n?- display_magic_square(X).\n\n 2 | 7 | 6\n---+---+---\n 9 | 5 | 1\n---+---+---\n 4 | 3 | 8\nX = [[2, 7, 6], [9, 5, 1], [4, 3, 8]] ;\n\n 2 | 9 | 4\n---+---+---\n 7 | 5 | 3\n---+---+---\n 6 | 1 | 8\nX = [[2, 9, 4], [7, 5, 3], [6, 1, 8]] ;\n\n 4 | 3 | 8\n---+---+---\n 9 | 5 | 1\n---+---+---\n 2 | 7 | 6\nX = [[4, 3, 8], [9, 5, 1], [2, 7, 6]] ;\n\n 4 | 9 | 2\n---+---+---\n 3 | 5 | 7\n---+---+---\n 8 | 1 | 6\nX = [[4, 9, 2], [3, 5, 7], [8, 1, 6]] ;\n\n 6 | 1 | 8\n---+---+---\n 7 | 5 | 3\n---+---+---\n 2 | 9 | 4\nX = [[6, 1, 8], [7, 5, 3], [2, 9, 4]] ;\n\n 6 | 7 | 2\n---+---+---\n 1 | 5 | 9\n---+---+---\n 8 | 3 | 4\nX = [[6, 7, 2], [1, 5, 9], [8, 3, 4]] ;\n\n 8 | 1 | 6\n---+---+---\n 3 | 5 | 7\n---+---+---\n 4 | 9 | 2\nX = [[8, 1, 6], [3, 5, 7], [4, 9, 2]] ;\n\n 8 | 3 | 4\n---+---+---\n 1 | 5 | 9\n---+---+---\n 6 | 7 | 2\nX = [[8, 3, 4], [1, 5, 9], [6, 7, 2]] ;\nfalse.\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjames-p-d%2Fmagicsquare","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjames-p-d%2Fmagicsquare","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjames-p-d%2Fmagicsquare/lists"}