{"id":26871718,"url":"https://github.com/eocode/queens","last_synced_at":"2026-04-27T12:01:35.826Z","repository":{"id":126329636,"uuid":"292673904","full_name":"eocode/Queens","owner":"eocode","description":"The N Queens problem with Flask, SQLAlchemy, Docker and Pytest","archived":false,"fork":false,"pushed_at":"2020-09-11T23:37:38.000Z","size":335,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T07:34:07.198Z","etag":null,"topics":["flask","nqueens-problem","pytest","python","software-engineering","sqlalchemy","travis"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eocode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-03T20:32:03.000Z","updated_at":"2020-09-11T23:37:41.000Z","dependencies_parsed_at":"2023-06-16T08:00:13.595Z","dependency_job_id":null,"html_url":"https://github.com/eocode/Queens","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/eocode/Queens","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eocode%2FQueens","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eocode%2FQueens/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eocode%2FQueens/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eocode%2FQueens/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eocode","download_url":"https://codeload.github.com/eocode/Queens/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eocode%2FQueens/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32335297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"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":["flask","nqueens-problem","pytest","python","software-engineering","sqlalchemy","travis"],"created_at":"2025-03-31T07:30:30.823Z","updated_at":"2026-04-27T12:01:35.821Z","avatar_url":"https://github.com/eocode.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"64\" src=\"https://image.flaticon.com/icons/svg/862/862737.svg\" alt=\"Queens\"\u003e\n  \u003ch3 align=\"center\"\u003eNxN Queens Puzzle\u003c/h3\u003e\n  \u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/eocode/Queens/blob/master/LICENSE\" target=\"__blank\"\u003e\n      \t\u003cimg src=\"https://img.shields.io/badge/License-BSD3-blue.svg\"  alt=\"license badge\"/\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://travis-ci.org/eocode/Queens\" target=\"__blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/travis/eocode/Queens.svg?label=flask-queens\" alt=\"Build Status\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/eocode/Queens\" target=\"__blank\"\u003e\n        \u003cimg src=\"https://codecov.io/gh/eocode/Queens/branch/master/graph/badge.svg\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/ambv/black\" target=\"__blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/code%20style-black-000000.svg\" /\u003e\n    \u003c/a\u003e\n    \u003cimg alt=\"GitHub release (latest by date)\" src=\"https://img.shields.io/github/v/release/eocode/Queens\"\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\nProblem details: https://en.wikipedia.org/wiki/Eight_queens_puzzle\n\n1. Determine all possible solutions for a given N where N ≥ 8 (within 10 mins on a laptop). Bonus points for a higher N where N is the size of the board / number of queens\n2. Iterate over N and store the solutions in postgres using SQLAlchemy\n3. Write basic tests that at least verify the number of solutions for a given N match what's online. I recommend using pytest\n4. Docker-ize the solution, so that I can run the code and tests without any assumption of my local setup (including running a postgres instance in docker-compose)\n5. Setup Travis CI (or similar) for your public GitHub repo to run the tests automatically\n\n## Summary\u003c!-- omit in toc --\u003e\n- [Demo N Queens](#demo-n-queens)\n- [Project solution](#project-solution)\n  - [File structure](#file-structure)\n  - [The algorithm](#the-algorithm)\n    - [Steps to solve this](#steps-to-solve-this)\n  - [Results of algorithm](#results-of-algorithm)\n    - [For 14*14 board](#for-1414-board)\n    - [For 15*15 board](#for-1515-board)\n- [How it is build?](#how-it-is-build)\n  - [Dependencies](#dependencies)\n  - [Features](#features)\n  - [Development](#development)\n    - [Considerations](#considerations)\n- [Cookiecutter](#cookiecutter)\n- [How to use](#how-to-use)\n  - [How to clone](#how-to-clone)\n  - [Development configuration](#development-configuration)\n  - [Use on local](#use-on-local)\n  - [Install app](#install-app)\n  - [Dockerized app](#dockerized-app)\n  - [Run migrations](#run-migrations)\n  - [Prepare enviroments](#prepare-enviroments)\n  - [Run tests](#run-tests)\n  - [Ejecute coverage report](#ejecute-coverage-report)\n- [To develop](#to-develop)\n- [How to contribute](#how-to-contribute)\n- [License](#license)\n\n# Demo N Queens\n\nMain view, choise n board and simulate the game, if it has been calculated, the answer show in moment\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"/app/img/demo.png\" alt=\"Demo Queens\"\u003e\n\u003c/div\u003e\n\nAll possible solutions paginated, with option to regenerate. (You can improve the algorithm and see the new result)\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"/app/img/demo_2.png\" alt=\"Demo Queens\"\u003e\n\u003c/div\u003e\n\nSee board of processed solutions with your elapsed time, support n queens until 10 mins\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"/app/img/demo_3.png\" alt=\"Demo Queens\"\u003e\n\u003c/div\u003e\n\n# Project solution\n\n## File structure\n\n* **core** (Flask configurations project)\n  * **envs** (Configuration environments)\n  * **requirements** (Project dependencies)\n  * **extensions** (Instance for access to db in modules)\n  * **img** (Images of project)\n  * **init** (Base config app)\n  * **database** (Settings for SQLAlchemy)\n  * **settings** (Injectable settings in app)\n* **modules** Project modules\n  * **queens** (Main blueprint with clean implementation) \n    * **algorithms** (Switch algorithm)\n    * **connections** (Utilities for database connection)\n    * **simulation** (Core elements of the project)\n    * **solutions** (Manage results of the algorithm)\n    * **utilities** (Project utilities)\n    * **templates** (Project templates)\n    * views\n    * models\n    * forms\n* **migrations** (Database version app - Don't tracked)\n* **labs** (Codding problem and test solutions to pass in module queens, this folder won't pass for testing)\n* **tests** (Test of project)\n\n## The algorithm\n\nYou can see the algorithm in ``modules/queens/algorithms``\n\nThis is the solution Number 4, see all solutions in ``labs folder``\n\n```python\ndef __n_queens(self, board, col, positions):\n    \"\"\"Last N Queens Algorithm\n    Development by @eocode\n    Version 4\n    \"\"\"\n    if col == len(board):\n        self.__solutions.add_solution(\n            board, len(self.__solutions.get_solutions()) + 1\n        )\n        return True\n\n    for row in range(len(board)):\n        if row in positions.keys() and col in positions[row]:\n            apply, values = Queen.attack(row, col, copy.deepcopy(positions))\n            if apply:\n                board[row][col] = 1\n                self.__n_queens(board, col + 1, values)\n                board[row][col] = 0\n```\n\n### Steps to solve this\n\n* Brute force\n* Minimum conflict\n* Memorization\n* Backtracking\n\n## Results of algorithm\n\n### For 14*14 board\n\nTest algorithm with n boards \u003e 8\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"/app/img/res_2.png\" alt=\"14*15 Queens\"\u003e\n\u003c/div\u003e\n\nTime in minutes\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"/app/img/res_2_time.png\" alt=\"14*14 Queens\"\u003e\n\u003c/div\u003e\n\n### For 15*15 board\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"/app/img/res_1.png\" alt=\"15*15 Queens\"\u003e\n\u003c/div\u003e\n\nTime in minutes\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"/app/img/res_1_time.png\" alt=\"15*15 Queens Time\"\u003e\n\u003c/div\u003e\n\n# How it is build?\n\n## Dependencies\n\n* Flask\n* python-dotenv\n* Flask-sqlalchemy\n* Psycopg2\n* Pytest\n* Flask-migrate\n* Bootstrap\n* Pytest\n* Coverage\n* Setuptools\n* Numpy\n\n## Features\n\n* N Queens Problem algorithm with labs to analyze problem\n* Dockerized (test and development envs)\n* Travis-CI and codecov integration\n* Flask Blueprints\n* TDD (Test Driven Development) Testing with 10 n*n and every core part of the app for up coverage\n* Divide envs \n* Extensible\n* PostgreSQL\n* Paginate results for show solutions\n* Web application for view solutions and interact\n* Show list of board with all solutions procesed\n* Simulate n*n boards until 10 minutes\n\n## Development\n\n* Pycharm - IDE\n* Black - Code style\n* Conventional commits - https://www.conventionalcommits.org/en/v1.0.0/\n* Full documented app\n\n### Considerations\n\n* Coverage \u003e 85%\n\n# Cookiecutter\n\nThis microservice has been generated since a cookiecutter development by eocode (me) for this project with the next command \n\n```bash\ncookiecutter https://github.com/ActivandoIdeas/Cookiecutter-Flask\n```\n\nSee the details here: https://github.com/ActivandoIdeas/Cookiecutter-Flask\n\nYou can base your next developments on that template or contribute to improve it\n\n \n```bash\n# Only execute this (keep the code cleen)\nblack .\n```\n\n# How to use\n\n## How to clone\n\nYou can clone this repository\n\n    git clone https://github.com/eocode/queens\n\n## Development configuration\n\nRename .env.example to .env file\n\nAnd add your configuration\n\n## Use on local\nTo install this project just type\n\nCreate virtual enviroment:\n\n    $ python -m venv env\n\nActive your enviroment\n\nInstall dependencies\n\n    $ pip install -r app/requirements/prod.txt\n    $ pip install -r app/requirements/test.txt\n\nRun the project\n\n    $ flask run\n    \n## Install app\n\nIf you want to install the app use\n\n```bash\npython setup.py develop\n```\n    \n## Dockerized app\n\nStart app\n\n```bash\ndocker compose up -d\n```\n\nStop app\n\n```bash\ndocker compose down\n```\n\nRebuild app\n\n```bash\ndocker-compose up -d --build\n```\n\nAccess to command line interface\n\n```bash\ndocker exec -it flask-app bash\n```\n\n## Run migrations\n\nBy default migrations foldar has been add to .gitignore\n\nOpen Terminal\n\n```bash\ndocker exec -it flask-app bash\n```\n\nInit database migrations\n\n```bash\nflask db init\n```\n\nGenerate migrations\n\n```bash\nflask db migrate\n```\n\nRun migrations\n\n```bash\nflask db upgrade\n```\n\nShow more commands\n\n```bash\nflask db\n```\n\n## Prepare enviroments\n\nConfigure for test, execute sqlite db\n\n```bash\npython app/enviroment.py test\n```\n\nConfigure for dev or production, execute data in postgresql instance\n\n```bash\npython app/enviroment.py prod\n```\n\n## Run tests\n\nOn Docker\n\n```bash\ndocker-compose exec queens-app pytest\n```\n\nor only\n\n```bash\npytest\n```\n\n## Ejecute coverage report\n\n```bash\ncoverage run -m pytest\ncoverage report\ncoverage html\n```\n\n# To develop\n\n* Improve algorithm\n* Create API (optional)\n* Add production env\n* Configure deploy\n\n# How to contribute\n\n* See contributting file\n\nhttps://github.com/eocode/Queens/blob/master/CONTRIBUTTING.md\n\n# License\n\nView in https://github.com/eocode/Queens/blob/master/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feocode%2Fqueens","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feocode%2Fqueens","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feocode%2Fqueens/lists"}