|
| 1 | +# Algorithm Exercises (Rust 🦀) |
| 2 | + |
| 3 | +[](https://github.com/sir-gon/algorithm-exercises-rust/actions/workflows/rust.yml) |
| 4 | + |
| 5 | +[](https://github.com/sir-gon/algorithm-exercises-rust/actions/workflows/markdown-lint.yml) |
| 6 | +[](https://github.com/sir-gon/algorithm-exercises-rust/actions/workflows/yamllint.yml) |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +[](https://codecov.io/gh/sir-gon/algorithm-exercises-rust) |
| 13 | + |
| 14 | +[](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-rust) |
| 15 | +[](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-rust) |
| 16 | +[](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-rust) |
| 17 | +[](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-rust) |
| 18 | +[](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-rust) |
| 19 | + |
| 20 | +## TL;DR |
| 21 | + |
| 22 | +Algorithms Exercises solved in [Rust](https://www.rust-lang.org/) |
| 23 | +Developed with TDD. |
| 24 | + |
| 25 | +[](https://gcc.gnu.org/onlinedocs/gcc/Standards.html#C-Language) |
| 26 | +[](https://www.docker.com/) |
| 27 | + |
| 28 | +Go to [Install and run](#install-and-run) |
| 29 | + |
| 30 | +## What is this? |
| 31 | + |
| 32 | +This repository is part of a series that share and solve the same [objectives](#objetives), |
| 33 | +with the difference that each one is based on a different software ecosystem, |
| 34 | +depending on the chosen programming language: |
| 35 | + |
| 36 | +- [Modern Javascript: algorithm-exercises-js](https://github.com/sir-gon/algorithm-exercises-js) |
| 37 | +- [Typescript: algorithm-exercises-ts](https://github.com/sir-gon/algorithm-exercises-ts) |
| 38 | + |
| 39 | +- [Python 3.x: algorithm-exercises-py](https://github.com/sir-gon/algorithm-exercises-py) |
| 40 | +- [Go / Golang: algorithm-exercises-go](https://github.com/sir-gon/algorithm-exercises-go) |
| 41 | + |
| 42 | +- [Java: algorithm-exercises-java](https://github.com/sir-gon/algorithm-exercises-java) |
| 43 | +- [.NET / C#: algorithm-exercises-rustsharp](https://github.com/sir-gon/algorithm-exercises-rustsharp) |
| 44 | +- [C++17: algorithm-exercises-rustpp](https://github.com/sir-gon/algorithm-exercises-rustsharp-cpp) |
| 45 | + |
| 46 | +## Objetives |
| 47 | + |
| 48 | +### Functional |
| 49 | + |
| 50 | +- For academic purposes, it is an backup of some algorithm exercises |
| 51 | +(with their solutions), proposed by various sources: |
| 52 | +[leetcode, hackerrank, projecteuler](#algorithm-excersices-sources), ... |
| 53 | + |
| 54 | +- The solutions must be written on "vanilla code", that is, |
| 55 | +avoiding as much as possible the use of external libraries (in runtime). |
| 56 | + |
| 57 | +- Adoption of methodology and good practices. |
| 58 | +Each exercise is implemented as a unit test set, |
| 59 | +using TDD (Test-driven Development) and Clean Code ideas. |
| 60 | + |
| 61 | +### Technical |
| 62 | + |
| 63 | +Foundation of a project that supports: |
| 64 | + |
| 65 | +- Explicit **typing** when the language supports it, even when it is not mandatory. |
| 66 | +- Static Code Analysis (**Lint**) of code, scripts and documentation. |
| 67 | +- Uniform **Code Styling**. |
| 68 | +- **Unit Test** framework. |
| 69 | +- **Coverge** collection. High coverage percentage. Equal or close to 100%. |
| 70 | +- **Pipeline** (Github Actions). Each command must take care of its |
| 71 | +return status code. |
| 72 | +- **Docker**-based workflow to replicate behavior in any environment. |
| 73 | +- Other tools to support the reinforcement of software development **good practices**. |
| 74 | + |
| 75 | +## Install and Run |
| 76 | + |
| 77 | +- (⭐️) [Install and run directly with make](#install-and-run-directly-with-make) |
| 78 | +require Rust tools installed in your SO. |
| 79 | +<!-- |
| 80 | +- [Install and in Docker](#install-and-running-with-docker-) require Docker and |
| 81 | +docker compose installed. |
| 82 | +- [Install and in Docker with make](#install-and-running-with-docker--using-make) |
| 83 | +require Docker, docker compose and GNU make installed. --> |
| 84 | + |
| 85 | +<!-- ⭐️: Prefered way. --> |
| 86 | + |
| 87 | +### Install and run directly with make |
| 88 | + |
| 89 | +It is assumed that the following tools have already been installed: |
| 90 | + |
| 91 | +- [**Install Rust**](https://www.rust-lang.org/tools/install) |
| 92 | + |
| 93 | +Using Rust tools in your SO. You must install dependencies: |
| 94 | + |
| 95 | +```bash |
| 96 | +make dependencies |
| 97 | +make lint # optional |
| 98 | +make build |
| 99 | +make test |
| 100 | +``` |
| 101 | +<!-- |
| 102 | +#### Test run with alternative behaviors |
| 103 | +
|
| 104 | +Not implemented yet |
| 105 | +
|
| 106 | +#### Examples running tests with alternative behaviors |
| 107 | +
|
| 108 | +### Install and Running with Docker 🐳 |
| 109 | +
|
| 110 | +Build an image of the test stage. |
| 111 | +Then creates and ephemeral container an run tests. |
| 112 | +
|
| 113 | +```bash |
| 114 | +docker compose build algorithm-exercises-rust |
| 115 | +docker compose build algorithm-exercises-rust-lint |
| 116 | +docker compose build algorithm-exercises-rust-test |
| 117 | +docker compose build algorithm-exercises-rust-dev |
| 118 | +``` |
| 119 | +
|
| 120 | +```bash |
| 121 | +docker compose --profile testing run --rm algorithm-exercises-rust-test |
| 122 | +``` |
| 123 | +
|
| 124 | +### Install and Running with Docker 🐳 using make |
| 125 | +
|
| 126 | +```bash |
| 127 | +make compose/build |
| 128 | +make compose/lint # optional |
| 129 | +make compose/test |
| 130 | +``` --> |
| 131 | + |
| 132 | +## About development |
| 133 | + |
| 134 | +```sh |
| 135 | +rustc --version |
| 136 | +``` |
| 137 | + |
| 138 | +```text |
| 139 | +rustc 1.89.0 (29483883e 2025-08-04) |
| 140 | +``` |
| 141 | + |
| 142 | +--- |
| 143 | + |
| 144 | +```sh |
| 145 | +cargo --version |
| 146 | +``` |
| 147 | + |
| 148 | +```text |
| 149 | +cargo 1.89.0 (c24e10642 2025-06-23) |
| 150 | +``` |
| 151 | + |
| 152 | +--- |
| 153 | + |
| 154 | +```sh |
| 155 | +rustup --version |
| 156 | +``` |
| 157 | + |
| 158 | +```text |
| 159 | +rustup 1.28.2 (e4f3ad6f8 2025-04-28) |
| 160 | +info: This is the version for the rustup toolchain manager, not the rustc compiler. |
| 161 | +info: The currently active `rustc` version is `rustc 1.89.0 (29483883e 2025-08-04)` |
| 162 | +``` |
| 163 | + |
| 164 | +## Algorithm excersices sources |
| 165 | + |
| 166 | +- [Leetcode](https://leetcode.com/) online platform for |
| 167 | +coding interview preparation. |
| 168 | +- [HackerRank](https://www.hackerrank.com/) competitive programming challenges |
| 169 | +for both consumers and businesses. |
| 170 | +- [Project Euler](https://projecteuler.net/) a series of computational problems |
| 171 | +intended to be solved with computer programs. |
| 172 | + |
| 173 | +Use these answers to learn some tip and tricks for algorithms tests. |
| 174 | + |
| 175 | +### Disclaimer. Why I publish solutions? |
| 176 | + |
| 177 | +As Project Euler says: |
| 178 | + |
| 179 | +<https://projecteuler.net/about#publish> |
| 180 | + |
| 181 | +```text |
| 182 | +I learned so much solving problem XXX, so is it okay to publish my solution elsewhere? |
| 183 | +It appears that you have answered your own question. There is thing 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. |
| 184 | +
|
| 185 | +However, 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. |
| 186 | +``` |
| 187 | + |
| 188 | +If you have better answers or optimal solutions, fork and PR-me |
| 189 | + |
| 190 | +Enjoy 😁 ! |
| 191 | + |
| 192 | +## Status |
| 193 | + |
| 194 | +### License |
| 195 | + |
| 196 | +[LICENSE.md](LICENSE.md) |
| 197 | + |
| 198 | +### Coverage |
| 199 | + |
| 200 | +[](https://codecov.io/gh/sir-gon/algorithm-exercises-rust) |
0 commit comments