Every good programming exercise book should include the fibonacci
numbers!
One possible solution:
(0..i).fold((0, 1), |(a, b), _| (b, a + b)).1
Signed-off-by: Corin Lawson <corin@responsight.com>
fix(installation): Fix rustlings installation check
fixes#147
I did some quick testing with the `-x` check:
```sh
if [ -x "$(notrustlings)" ]
then
echo "notrustlings does not exist"
else
echo "notrustlings appears to exist!"
notrustlings
fi
```
which produced:
```
./test.sh: line 12: notrustlings: command not found
notrustlings appears to exist!
./test.sh: line 17: notrustlings: command not found
```
(consistent with comments in issue)
Using `if ! [ -x "$(command -v <command>)" ]` appears to be the standard way to perform this type of check.
chore: Minor text updates
- Make the default rustlings executable text consistent with the README and install script by adding `--force`.
- Remove a missed highlighting character from Issue #133.
Add errors to exercises that compile without user changes
Hi !
I played a bit with rustlings, and I felt that some exercises were incorrect because they passed the tests without me needing to edit the files!
This gave me the feeling that the exercise was skiped! Especially when I use `rustlings watch`, it is easy to miss an exercise because the compilation error that is displayed is the one of the next exercise ...
It is easy to identify "broken" exercises with:
```bash
% find exercises -name "*.rs" | xargs -n 1 rustlings run
...
✅ Successfully ran exercises/move_semantics/move_semantics4.rs
✅ Successfully tested exercises/test2.rs
```
My suggestion is to make sure that these files trigger a compilation error by adding a simple syntax error (e.g. with `???` in the code that must change) so that our Rustacean can then play with it!
Canonicalize paths to fix path matching
This PR should fix#126. The main solution to the issue was using `canonicalize()` on the paths we create for the exercises from `info.toml` and any user-specified paths, so that path `ends_with` matching will work correctly.
As adding calls to the canonicalize function everywhere requires unwrapping, I also decided to extract a struct representing an exercise and use serde to deserialize the paths from the `info.toml` file up front. I also tried to move the path handling out into the `exercise.rs` file and down into `main.rs` so that it doesn't create as much clutter. There was already a lot of unwrapping and path handling in the other files and I felt like it was getting a bit too repetitive.
If the approach is going too far (too many changes etc.) I'm happy to try to produce a smaller PR that fixes the bug without any refactoring.