{"id":18885342,"url":"https://github.com/sir-gon/algorithm-exercises-go","last_synced_at":"2025-07-08T00:33:43.604Z","repository":{"id":36983796,"uuid":"502806156","full_name":"sir-gon/algorithm-exercises-go","owner":"sir-gon","description":"Algorithms Exercises solved in Go, running in built-in Go test suite. Developed with TDD.","archived":false,"fork":false,"pushed_at":"2025-07-04T14:45:56.000Z","size":1293,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-04T16:08:47.384Z","etag":null,"topics":["algorithm-challenge","algorithm-challenges","algorithms-and-data-structures","algorithms-datastructures","algoritmhs","exercise-solutions","exercises-code-go","go","golang","hackerrank","hackerrank-challenges","hackerrank-go","hackerrank-golang","hackerrank-solutions","projecteuler","tdd","test-driven-development","test-driven-development-with-go"],"latest_commit_sha":null,"homepage":"","language":"Go","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/sir-gon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null},"funding":{"github":["sir-gon"],"buy_me_a_coffee":"gonzalodiaz"}},"created_at":"2022-06-13T04:35:05.000Z","updated_at":"2025-07-04T14:33:57.000Z","dependencies_parsed_at":"2023-09-24T07:25:11.195Z","dependency_job_id":"b956c248-887f-47d8-a31f-d563c554645b","html_url":"https://github.com/sir-gon/algorithm-exercises-go","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/sir-gon/algorithm-exercises-go","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sir-gon%2Falgorithm-exercises-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sir-gon%2Falgorithm-exercises-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sir-gon%2Falgorithm-exercises-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sir-gon%2Falgorithm-exercises-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sir-gon","download_url":"https://codeload.github.com/sir-gon/algorithm-exercises-go/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sir-gon%2Falgorithm-exercises-go/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264169175,"owners_count":23567265,"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":["algorithm-challenge","algorithm-challenges","algorithms-and-data-structures","algorithms-datastructures","algoritmhs","exercise-solutions","exercises-code-go","go","golang","hackerrank","hackerrank-challenges","hackerrank-go","hackerrank-golang","hackerrank-solutions","projecteuler","tdd","test-driven-development","test-driven-development-with-go"],"created_at":"2024-11-08T07:17:59.626Z","updated_at":"2025-07-08T00:33:43.519Z","avatar_url":"https://github.com/sir-gon.png","language":"Go","readme":"# Algorithm Exercises (Golang)\n\n[![Go CI](https://github.com/sir-gon/algorithm-exercises-go/actions/workflows/go.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-go/actions/workflows/go.yml)\n[![Markdown Lint](https://github.com/sir-gon/algorithm-exercises-go/actions/workflows/markdown-lint.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-go/actions/workflows/markdown-lint.yml)\n[![YAML lint](https://github.com/sir-gon/algorithm-exercises-go/actions/workflows/yamllint.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-go/actions/workflows/yamllint.yml)\n\n![GitHub](https://img.shields.io/github/license/sir-gon/projecteuler-go)\n![GitHub language count](https://img.shields.io/github/languages/count/sir-gon/projecteuler-go)\n![GitHub top language](https://img.shields.io/github/languages/top/sir-gon/projecteuler-go)\n[![CodeFactor](https://www.codefactor.io/repository/github/sir-gon/algorithm-exercises-go/badge)](https://www.codefactor.io/repository/github/sir-gon/algorithm-exercises-go)\n[![codecov](https://codecov.io/gh/sir-gon/algorithm-exercises-go/branch/main/graph/badge.svg?token=U3N3HSC3YC)](https://codecov.io/gh/sir-gon/algorithm-exercises-go)\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fsir-gon%2Fprojecteuler-go.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fsir-gon%2Fprojecteuler-go?ref=badge_shield)\n[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/6194/badge)](https://www.bestpractices.dev/projects/6194)\n\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-go\u0026metric=alert_status)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-go)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-go\u0026metric=coverage)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-go)\n[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-go\u0026metric=bugs)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-go)\n[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-go\u0026metric=code_smells)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-go)\n[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-go\u0026metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-go)\n\n## TL;DR\n\nAlgorithms Exercises solved in [Go](https://go.dev/),\nrunning in built-in Go test suite. Developed with TDD.\n\n[![Go](https://img.shields.io/badge/go-%2300ADD8.svg?style=for-the-badge\u0026logo=go\u0026logoColor=white)](https://go.dev/)\n[![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=for-the-badge\u0026logo=docker\u0026logoColor=white)](https://www.docker.com/)\n\nGo to [Install and run](#install-and-run)\n\n## What is this?\n\nThis repository is part of a series that share and solve the same [objectives](#objetives),\nwith the difference that each one is based on a different software ecosystem,\ndepending on the chosen programming language:\n\n- [Modern Javascript: algorithm-exercises-js](https://github.com/sir-gon/algorithm-exercises-js)\n- [Python 3.x: algorithm-exercises-py](https://github.com/sir-gon/algorithm-exercises-py)\n- [Typescript: algorithm-exercises-ts](https://github.com/sir-gon/algorithm-exercises-ts)\n- [Go / Golang: algorithm-exercises-go](https://github.com/sir-gon/algorithm-exercises-go)\n- [Java: algorithm-exercises-java](https://github.com/sir-gon/algorithm-exercises-java)\n- [.NET / C#: algorithm-exercises-csharp](https://github.com/sir-gon/algorithm-exercises-csharp)\n- [C++17: algorithm-exercises-cpp](https://github.com/sir-gon/algorithm-exercises-cpp)\n\n## Objetives\n\n### Functional\n\n- For academic purposes, it is an backup of some algorithm exercises\n(with their solutions), proposed by various sources:\n[leetcode, hackerrank, projecteuler](#algorithm-excersices-sources), ...\n\n- The solutions must be written on \"vanilla code\", that is,\navoiding as much as possible the use of external libraries (in runtime).\n\n- Adoption of methodology and good practices.\nEach exercise is implemented as a unit test set,\nusing TDD (Test-driven Development) and Clean Code ideas.\n\n### Technical\n\nFoundation of a project that supports:\n\n- Explicit **typing** when the language supports it, even when it is not mandatory.\n- Static Code Analysis (**Lint**) of code, scripts and documentation.\n- Uniform **Code Styling**.\n- **Unit Test** framework.\n- **Coverge** collection. High coverage percentage. Equal or close to 100%.\n- **Pipeline** (Github Actions). Each command must take care of its\nreturn status code.\n- **Docker**-based workflow to replicate behavior in any environment.\n- Other tools to support the reinforcement of software development **good practices**.\n\n## Install and Run\n\nYou can run tests in the following ways:\n\n- [Install and run directly](#install-and-run-directly) require runtime tools\ninstalled in your SO.\n- [Install and run with make](#install-and-run-using-make) require runtime tools\nand \"make\" installed in your SO.\n- [Install and run in Docker](#install-and-running-with-docker-) require Docker and\ndocker-compose installed.\n- (⭐️)\n[Install and in Docker with make](#install-and-running-with-docker--using-make)\nrequire docker-compose and make installed.\n\n⭐️: Prefered way.\n\n### Install and Run directly\n\nUsing a golang stack in your SO. You must install dependencies:\n\n```bash\ngo mod download -x\n```\n\nEvery problem is a function with unit test.\n\nUnit test has test cases and input data to solve the problem.\n\nRun all tests:\n\n```bash\ngo test -v -count=1 ./...\n```\n\nTo collect coverage and generate reports, do:\n\n```bash\ngo test -v -count=1 -coverprofile=coverage/c.out ./...\ngo tool -func=coverage/c.out\ngo tool -html=coverage/c.out\n```\n\n#### Test run with alternative behaviors\n\nYou can change test running behaviour using some environment variables as follows:\n\n| Variable | Values | Default |\n| ------ | ------ | ------ |\n| LOG_LEVEL  | `debug`, `warning`, `error`, `info` | `info` |\n| BRUTEFORCE | `true`, `false`| `false` |\n\n- `LOG_LEVEL`: change verbosity level in outputs.\n- `BRUTEFORCE`: enable or disable running large tests.\n(long time, large amount of data, high memory consumition).\n\n\u003e [!IMPORTANT]\n\u003e BRUTEFORCE environment variable only works running test with make,\n\u003e due golang mechanism to conditionally running test relays on\n\u003e \"conditional build\" using a parameter in \"go test\" command.\n\nTo enable brute force tests running golang directly,\nyou should add \"-tags ...\" parameter to \"go test\".\n\nSee next examples.\n\n#### Examples running tests with alternative behaviors\n\nIn go, test runs are cached. So, to re-run a test with different behavior,\nyou must add \"-count=1\" parameter in \"go test\"\n\nRun tests with debug outputs:\n\n```bash\nLOG_LEVEL=debug go test -count=1 -v ./...\n```\n\nRun brute-force tests with debug outputs:\n\n```bash\nLOG_LEVEL=debug go test -count=1 -v -tags bruteforce ./...\n```\n\n### Install and Run using make\n\n`make` tool is used to standardizes the commands for the same tasks\nacross each sibling repository.\n\nRun tests (libraries are installed as dependency task in make):\n\n```bash\nmake test\n```\n\nRun tests with debug outputs:\n\n```bash\nmake test -e LOG_LEVEL=debug\n```\n\nRun brute-force tests with debug outputs:\n\n```bash\nmake test -e BRUTEFORCE=true -e LOG_LEVEL=debug\n```\n\nAlternative way, use environment variables as prefix:\n\n```bash\nBRUTEFORCE=true LOG_LEVEL=debug make test\n```\n\n### Install and Running with Docker 🐳\n\nBuild an image of the test stage.\nThen creates and ephemeral container an run tests.\n\nBRUTEFORCE and LOG_LEVEL environment variables are passing from current\nenvironment using docker-compose.\n\n```bash\ndocker-compose --profile testing run --rm algorithm-exercises-go-test\n```\n\nTo change behavior using environment variables, you can pass to containers\nin the following ways:\n\nFrom host using docker-compose (compose.yaml) mechanism:\n\n```bash\nBRUTEFORCE=true LOG_LEVEL=debug docker-compose --profile testing run --rm algorithm-exercises-go-test\n```\n\nOverriding docker CMD, as parameter of make \"-e\":\n\n```bash\ndocker-compose --profile testing run --rm algorithm-exercises-go-test make test -e LOG_LEVEL=DEBUG -e BRUTEFORCE=true\n```\n\n### Install and Running with Docker 🐳 using make\n\n```bash\nmake compose/build\nmake compose/test\n```\n\nTo pass environment variables you can use docker-compose\nor overriding CMD and passing to make as \"-e\" argument.\n\nPassing environment variables using docker-compose (compose.yaml mechanism):\n\n```bash\nBRUTEFORCE=true LOG_LEVEL=debug make compose/test\n```\n\n## Development workflow using Docker / docker-compose\n\nRunning container with development target.\nDesigned for development workflow on top of this image.\nAll source application is mounted as a volume in **/app** directory.\nDependencies should be installed to run so, you must\ninstall dependencies before run (or after a dependency add/change).\n\n```bash\n# Build development target image\ndocker-compose build --compress algorithm-exercises-go-dev\n\n# Run ephemeral container and override command to run test\ndocker-compose run --rm algorithm-exercises-go-dev go test -count=1 -v ./...\n```\n\n## Run complete workflow (Docker + make)\n\nFollowing command simulates a standarized pipeline across environments,\nusing docker-compose and make.\n\n```bash\nmake compose/build \u0026\u0026 make compose/lint \u0026\u0026 make compose/test \u0026\u0026 make compose/run\n```\n\n- Build all Docker stages and tag relevant images.\n- Run static analysis (lint) checks\n- Run unit tests\n- Run a \"final\" production ready image as a final container.\nFinal \"production\" image just shows a minimal \"production ready\"\nbuild (with no tests).\n\n## About development\n\nDeveloped with runtime:\n\n```text\ngo version\ngo version go1.22.4 darwin/amd64\n```\n\n## Algorithm excersices sources\n\n- [Leetcode](https://leetcode.com/) online platform for\ncoding interview preparation.\n- [HackerRank](https://www.hackerrank.com/) competitive programming challenges\nfor both consumers and businesses.\n- [Project Euler](https://projecteuler.net/) a series of computational problems\nintended to be solved with computer programs.\n\nUse these answers to learn some tip and tricks for algorithms tests.\n\n### Disclaimer. Why I publish solutions?\n\nAs Project Euler says:\n\n\u003chttps://projecteuler.net/about#publish\u003e\n\n```text\nI learned so much solving problem XXX, so is it okay to publish my solution elsewhere?\nIt appears that you have answered your own question. There is nothing quite like that \"Aha!\" moment when you finally beat a problem which you have been working on for some time. It is often through the best of intentions in wishing to share our insights so that others can enjoy that moment too. Sadly, that will rarely be the case for your readers. Real learning is an active process and seeing how it is done is a long way from experiencing that epiphany of discovery. Please do not deny others what you have so richly valued yourself.\n\nHowever, the rule about sharing solutions outside of Project Euler does not apply to the first one-hundred problems, as long as any discussion clearly aims to instruct methods, not just provide answers, and does not directly threaten to undermine the enjoyment of solving later problems. Problems 1 to 100 provide a wealth of helpful introductory teaching material and if you are able to respect our requirements, then we give permission for those problems and their solutions to be discussed elsewhere.\n```\n\nIf you have better answers or optimal solutions, fork and PR-me\n\nEnjoy 😁 !\n\n## Status\n\n### License\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fsir-gon%2Fprojecteuler-go.svg?type=large\u0026issueType=license)](https://app.fossa.com/projects/git%2Bgithub.com%2Fsir-gon%2Fprojecteuler-go?ref=badge_large\u0026issueType=license)\n\n### Coverage\n\n[![Codecov](https://codecov.io/gh/sir-gon/algorithm-exercises-go/branch/main/graphs/tree.svg?token=U3N3HSC3YC)](https://codecov.io/gh/sir-gon/algorithm-exercises-go)\n","funding_links":["https://github.com/sponsors/sir-gon","https://buymeacoffee.com/gonzalodiaz"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsir-gon%2Falgorithm-exercises-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsir-gon%2Falgorithm-exercises-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsir-gon%2Falgorithm-exercises-go/lists"}