{"id":20231476,"url":"https://github.com/mchaver/nqueens-java","last_synced_at":"2026-05-09T16:35:00.263Z","repository":{"id":146072740,"uuid":"136737164","full_name":"mchaver/nqueens-java","owner":"mchaver","description":"A solution for N-Queens and No-three-in-line in Java","archived":false,"fork":false,"pushed_at":"2018-06-10T17:22:26.000Z","size":31,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-03T13:47:47.805Z","etag":null,"topics":["gradle","nqueens-problem"],"latest_commit_sha":null,"homepage":"","language":"Java","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/mchaver.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-06-09T15:54:25.000Z","updated_at":"2018-06-19T14:14:49.000Z","dependencies_parsed_at":"2023-05-11T14:30:48.790Z","dependency_job_id":null,"html_url":"https://github.com/mchaver/nqueens-java","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mchaver/nqueens-java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mchaver%2Fnqueens-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mchaver%2Fnqueens-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mchaver%2Fnqueens-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mchaver%2Fnqueens-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mchaver","download_url":"https://codeload.github.com/mchaver/nqueens-java/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mchaver%2Fnqueens-java/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279011057,"owners_count":26084865,"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-10-12T02:00:06.719Z","response_time":53,"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":["gradle","nqueens-problem"],"created_at":"2024-11-14T07:48:18.166Z","updated_at":"2025-10-12T10:44:13.154Z","avatar_url":"https://github.com/mchaver.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nqueens-java\n\nGiven a board of height and width `N`, place `N` queens on the board such that no queen is threatenend by any other queen. As an added challenge, make sure that any three or more pieces do not form a line. This will be referred to as the `no-three-in-line` constraint throught the project.\n\nFor example, three queens `A` at `(1,1)`, `B` at `(2,3)` and `C` at `(3,5)` do not threaten each other, but they do form a line because the slope of `A` and `B` is equal to the slope of `B` and `C`. This violates the `no-three-in-line` constraint and would be consider as part of a solution. If `C` were located at `(3,6)` then these three pieces would not violate the constaint.\n\n## Calculate no-three-in-line\n\nGive three points, compare the slope of three points as follows:\n\n```\n(y1 - y0) / (x1 - x0) == (y2 - y1) / (x2 - x1)\n\n```\n\nThere are two issues to watch out for with this formula: division by zero and floating point comparison.\n\nWe can rearrange the formula to eliminate these issues:\n\n```\n(x0 - x1) * (y0 - y2) == (x0 - x2) * (y0 - y1)\n```\n\n## Projects\n\nBuild all the projects:\n\n```\n$ ./gradlew build\n```\n\n#### nqueens-core\n\nThe core library for solving the N-Queens problem and the N-Queens problem with the no-three-in-line constraint. It has a series of tests to prevent regressions and confirm that it produces the correct solutions.\n\nRun `nqueens-core` tests:\n\n```\n$ ./gradlew clean :nqueens-core:test\n$ ./gradlew :nqueens-core:javadoc\n```\n\n#### nqueens-cli\n\nA command line wrapper for the `nqueens-core` library.\n\nExamples of using the command line tool:\n\n```\n$ ./gradlew :nqueens-cli:run -Paargs=\"['-help']\"\n$ ./gradlew :nqueens-cli:run -Paargs=\"['-n=4']\"\n$ ./gradlew :nqueens-cli:run -Paargs=\"['-n=4', '-l']\"\n$ ./gradlew :nqueens-cli:run -Paargs=\"['-n=8']\"\n$ ./gradlew :nqueens-cli:run -Paargs=\"['-n=8', '-l']\"\n```\n\nAdding the `-l` flag will run the algorithm with the `no-three-in-line` constraint.\n\n#### nqueens-server\n\nA JSON API wrapper for the `nqueens-core` library.\n\nRun a server at `localhost:8081` that allows you to query for the answer of N-Queens Problem\n\n```\n$ ./gradlew :nqueens-server:run\n```\n\nIn another command line window you can perform a request while it is running.\n\n```\n$ curl localhost:8081/nqueens?n=4\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmchaver%2Fnqueens-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmchaver%2Fnqueens-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmchaver%2Fnqueens-java/lists"}