rust-lang / rustlings

:crab: Small exercises to get you used to reading and writing Rust code!
https://rustlings.cool
MIT License
53.72k stars 10.11k forks source link

Canonical Solutions #820

Closed dustinroepsch closed 7 months ago

dustinroepsch commented 3 years ago

Hello!

It would be great if after you complete a file, it showed you a "good" solution. Sometimes it's hard to tell if I cheated on accident, or didn't learn the lesson I was supposed to.

The hints feature is great and kinda serves this purpose, but I'd still appreciate solutions to the problems after I do them myself :)

itayperry commented 2 years ago

I'm voting for this! 🌻

It's nice to see different ways to solve a problem, we can even put several solutions for each exercise.

For example - primitive_types3.rs Creating an array with at least 100 elements- a short Google search would yield something like:

let a = [0; 500];

but the hints also say:

Bonus: what are some other things you could have that would return true for a.len() >= 100?

I didn't have any idea.. and it'd be cool to encounter a different approach :)

kaiuri commented 2 years ago

@itayperry I guess taking advantage of rust's awesome features like monomorphization, std, core, generics, traits, etc, is the way to go.

itayperry commented 2 years ago

@kaiuri I just started learning :) so it would take a while. In short, regarding the issue at hand, I'm absolutely up for adding canonical solutions for all the exercises.

kaiuri commented 2 years ago

@kaiuri I just started learning :) so it would take a while. In short, regarding the issue at hand, I'm absolutely up for adding canonical solutions for all the exercises.

Hmmm... I think Rust is too expressive for canonical, maybe the most idiomatic solution would result in something approaching uniqueness.

rytheo commented 2 years ago

Possible duplicate of #293

pbaettig commented 2 years ago

That would be such a great feature! Rustlings is a awesome for learning the language but it would be great to compare ones own solution with an idiomatic "optimal" solution

mo8it commented 7 months ago

Duplicate of https://github.com/rust-lang/rustlings/issues/293