{"id":18079278,"url":"https://github.com/ashawley/nqueens-scala","last_synced_at":"2025-04-05T21:42:43.543Z","repository":{"id":150092961,"uuid":"173740602","full_name":"ashawley/nqueens-scala","owner":"ashawley","description":"N-Queens problem","archived":false,"fork":false,"pushed_at":"2019-12-17T12:36:30.000Z","size":981,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-12T02:10:03.226Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://ashawley.github.io/nqueens-scala/2.13.0-M5/api/","language":"Scala","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ashawley.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":"2019-03-04T12:26:11.000Z","updated_at":"2020-11-05T08:45:50.000Z","dependencies_parsed_at":"2023-06-05T07:45:19.227Z","dependency_job_id":null,"html_url":"https://github.com/ashawley/nqueens-scala","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashawley%2Fnqueens-scala","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashawley%2Fnqueens-scala/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashawley%2Fnqueens-scala/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashawley%2Fnqueens-scala/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ashawley","download_url":"https://codeload.github.com/ashawley/nqueens-scala/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406080,"owners_count":20933803,"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-10-31T12:42:08.865Z","updated_at":"2025-04-05T21:42:43.519Z","avatar_url":"https://github.com/ashawley.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"N-Queens problem in Scala\n============================\n\n[![AppVeyor](https://ci.appveyor.com/api/projects/status/github/ashawley/nqueens-scala?svg=true)](https://ci.appveyor.com/project/ashawley/nqueens-scala)\n[![Circle](https://circleci.com/gh/ashawley/nqueens-scala.svg?style=svg)](https://circleci.com/gh/ashawley/nqueens-scala)\n[![Travis](https://img.shields.io/travis/ashawley/nqueens-scala.svg)](https://travis-ci.org/ashawley/nqueens-scala)\n\nProblem: Place ''N'' queens on a board so no queen threatens another queen.\n\n    _|_|_|_|_|Q|_|_\n    _|_|_|Q|_|_|_|_\n    _|_|_|_|_|_|Q|_\n    Q|_|_|_|_|_|_|_\n    _|_|_|_|_|_|_|Q\n    _|Q|_|_|_|_|_|_\n    _|_|_|_|Q|_|_|_\n    _|_|Q|_|_|_|_|_\n    \nSolving the problem for a 8 queens:\n\n```scala\nNQueens.solve(8)\n```\n\nIt's possible to solve for other board sizes:\ndecimal.\n\n```scala\nNQueens.solve(10) // 10 queens on a 10-by-10 board.\n```\n\n### Overview\n\nThis solution is written in [Scala] 2.12 and only depends on the Scala\nstandard library, and [Java 8].\n\nThe primary routine is called `solve`.  It can give the set of all\nsolutions for the problem in decimal:\n\t  \n```scala\nNQueens.solve(6).foreach(println)\nVector(1, 3, 5, 0, 2, 4)\nVector(2, 5, 1, 4, 0, 3)\nVector(3, 0, 4,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91\n_|_|_|_|_|_|_|Q\n_|_|Q|_|_|_|_|_\nQ|_|_|_|_|_|_|_\n_|_|_|_|_|Q|_|_\n_|Q|_|_|_|_|_|_\n_|_|_|_|Q|_|_|_\n_|_|_|_|_|_|Q|_\n_|_|_|Q|_|_|_|_\nSolution #92\n_|_|_|_|_|_|_|Q\n_|_|_|Q|_|_|_|_\nQ|_|_|_|_|_|_|_\n_|_|Q|_|_|_|_|_\n_|_|_|_|_|Q|_|_\n_|Q|_|_|_|_|_|_\n_|_|_|_|_|_|Q|_\n_|_|_|_|Q|_|_|_\nFound 92 solutions\n```\n\n### Getting started\n\nUse [sbt] to interact with the build.\n\n```\n$ sbt\n```\n\nYou can run Scala from the sbt console:\n\n```\nsbt\u003e console\nscala\u003e Main.main(Array(\"4\"))\n```\n\n```\nSolution #1\n_|Q|_|_\n_|_|_|Q\nQ|_|_|_\n_|_|Q|_\nSolution #2\n_|_|Q|_\nQ|_|_|_\n_|_|_|Q\n_|Q|_|_\nFound 2 solutions\n```\n\nAlternatively, you can interact with program as if it was built as a\ncommand-line application but from sbt:\n\n```\nsbt\u003e run 6\n[info] Running Main 6\nSolution #1\n_|Q|_|_|_|_\n_|_|_|Q|_|_\n_|_|_|_|_|Q\nQ|_|_|_|_|_\n_|_|Q|_|_|_\n_|_|_|_|Q|_\nSolution #2\n_|_|Q|_|_|_\n_|_|_|_|_|Q\n_|Q|_|_|_|_\n_|_|_|_|Q|_\nQ|_|_|_|_|_\n_|_|_|Q|_|_\nSolution #3\n_|_|_|Q|_|_\nQ|_|_|_|_|_\n_|_|_|_|Q|_\n_|Q|_|_|_|_\n_|_|_|_|_|Q\n_|_|Q|_|_|_\nSolution #4\n_|_|_|_|Q|_\n_|_|Q|_|_|_\nQ|_|_|_|_|_\n_|_|_|_|_|Q\n_|_|_|Q|_|_\n_|Q|_|_|_|_\nFound 4 solutions\n[success] Total time: 8 s, completed Mar 4, 2019 9:30:06 AM\n```\n\n### Caveats\n\nPassing the empty string as an argument:\n\n```\nscala\u003e Main.main(Array(\"\"))\njava.lang.NumberFormatException: For input string: \"\"\n```\n\nPassing an argument that is something other than an Integer:\n\n```\nscala\u003e Main.main(Array(\"f\"))\njava.lang.NumberFormatException: For input string: \"f\"\n```\n\nPassing an argument that isn't a valid Integer:\n\n```\nscala\u003e Int.MaxValue\nres1: Int = 2147483647\n\nscala\u003e Main.main(Array(\"2147483648\"))\njava.lang.NumberFormatException: For input string: \"2147483648\"\n```\n\n### References\n\n1. \u003chttps://en.wikipedia.org/wiki/Eight_queens_puzzle\u003e\n2. \u003chttps://rosettacode.org/wiki/N-queens_problem#Scala\u003e\n\n[Java 8]: http://docs.oracle.com/javase/8/docs/api/\n[sbt]: http://scala-sbt.org\n[Scala]: http://scala-lang.org\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashawley%2Fnqueens-scala","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashawley%2Fnqueens-scala","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashawley%2Fnqueens-scala/lists"}