{"id":15950098,"url":"https://github.com/adonig/backfish","last_synced_at":"2026-03-17T23:03:27.938Z","repository":{"id":240363765,"uuid":"802445706","full_name":"adonig/backfish","owner":"adonig","description":"A flexible and powerful backtracking library for Elixir.","archived":false,"fork":false,"pushed_at":"2024-05-19T10:10:57.000Z","size":403,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-31T14:45:36.365Z","etag":null,"topics":["backtracking","elixir","elixir-library"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/backfish/Backfish.html","language":"Elixir","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/adonig.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":"2024-05-18T10:10:51.000Z","updated_at":"2024-05-18T18:48:00.000Z","dependencies_parsed_at":"2024-05-18T10:39:26.446Z","dependency_job_id":"9c7dbf72-0285-4de0-a957-3520f5c8fc7a","html_url":"https://github.com/adonig/backfish","commit_stats":null,"previous_names":["adonig/backfish"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/adonig/backfish","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adonig%2Fbackfish","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adonig%2Fbackfish/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adonig%2Fbackfish/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adonig%2Fbackfish/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adonig","download_url":"https://codeload.github.com/adonig/backfish/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adonig%2Fbackfish/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30635093,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T22:38:22.569Z","status":"ssl_error","status_checked_at":"2026-03-17T22:38:11.804Z","response_time":56,"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":["backtracking","elixir","elixir-library"],"created_at":"2024-10-07T12:58:02.138Z","updated_at":"2026-03-17T23:03:27.906Z","avatar_url":"https://github.com/adonig.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Backfish\n\n**Backfish** is a flexible and powerful backtracking library for Elixir, designed to solve combinatorial and constraint satisfaction problems. Whether you're working on puzzles like Sudoku, N-Queens, Word Search, or graph problems like the Hamiltonian Path, Backfish provides the tools you need to implement efficient solutions.\n\n## Features\n\n- Easy-to-use API for defining problem states, goals, and next steps.\n- Supports finding the first valid solution or all possible solutions.\n- Extensible to a wide variety of problem domains.\n\n## Installation\n\nAdd `backfish` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:backfish, \"~\u003e 0.1.0\"}\n  ]\nend\n```\n\n## Usage\n\n### Defining a Problem\n\nTo define a problem, you need to create a module that uses `Backfish.ProblemDefinition` and implements the required callbacks: `initial_state/1`, `is_goal?/1`, and `next_steps/1`.\n\n#### Example: N-Queens\n\n``` elixir\ndefmodule Backfish.Examples.NQueens do\n  use Backfish.ProblemDefinition\n\n  @default_size 8\n\n  def initial_state(args) do\n    size = Keyword.get(args, :size, @default_size)\n    %{board: [], size: size}\n  end\n\n  def is_goal?(%{board: board, size: size}) do\n    length(board) == size\n  end\n\n  def next_steps(%{board: board, size: size}) do\n    row = length(board) + 1\n\n    1..size\n    |\u003e Enum.filter(fn col -\u003e valid_position?(board, {row, col}) end)\n    |\u003e Enum.map(fn col -\u003e %{board: [{row, col} | board], size: size} end)\n  end\n\n  defp valid_position?(board, {row, col}) do\n    Enum.all?(board, fn {r, c} -\u003e\n      c != col \u0026\u0026 abs(c - col) != abs(r - row)\n    end)\n  end\nend\n```\n\n### Finding Solutions\n\nUse `Backfish.find_first_solution/2` to find the first valid solution or `Backfish.find_all_solutions/2` to find all possible solutions.\n\n#### Example: Solving N-Queens\n\n``` elixir\nopts = [args: [size: 8]]\n\n{:ok, solution} = Backfish.find_first_solution(Backfish.Examples.NQueens, opts)\nIO.inspect(solution)\n\nsolutions = Backfish.find_all_solutions(Backfish.Examples.NQueens, opts)\nIO.inspect(length(solutions))\n```\n\n### Additional Examples\n\n- [Eight Puzzle](lib/backfish/examples/eight_puzzle.ex)\n- [Graph Coloring](lib/backfish/examples/graph_coloring.ex)\n- [Hamiltonian Path](lib/backfish/examples/hamiltonian_path.ex)\n- [Knapsack](lib/backfish/examples/knapsack.ex)\n- [Sudoku](lib/backfish/examples/sudoku.ex)\n- [Word Search](lib/backfish/examples/word_search.ex)\n\n## Contributing\n\nContributions to improve Backfish are welcome. Please fork the repository and submit pull requests.\n\n## Documentation\n\nDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found [here](https://hexdocs.pm/backfish).\n\n## License\n\nBackfish is released under the [MIT License](LICENSE).\n\n## Credits\n\nSpecial thanks to [ChatGPT 4o](https://chat.openai.com/) for helping me build this library in 3 days.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadonig%2Fbackfish","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadonig%2Fbackfish","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadonig%2Fbackfish/lists"}