feat: move vec exercises into their own folder

This commit is contained in:
mokou 2022-07-12 15:16:25 +02:00
parent 8e1f617d34
commit 2f7fd51304
5 changed files with 29 additions and 26 deletions

View File

@ -1,23 +1,11 @@
# Collections # Hashmaps
A *hash map* allows you to associate a value with a particular key.
Rusts standard library includes a number of very useful data
structures called collections. Most other data types represent one
specific value, but collections can contain multiple values. Unlike
the built-in array and tuple types, the data these collections point
to is stored on the heap, which means the amount of data does not need
to be known at compile time and can grow or shrink as the program
runs.
This exercise will get you familiar with two fundamental data
structures that are used very often in Rust programs:
* A *vector* allows you to store a variable number of values next to
each other.
* A *hash map* allows you to associate a value with a particular key.
You may also know this by the names [*unordered map* in C++](https://en.cppreference.com/w/cpp/container/unordered_map), You may also know this by the names [*unordered map* in C++](https://en.cppreference.com/w/cpp/container/unordered_map),
[*dictionary* in Python](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) or an *associative array* in other languages. [*dictionary* in Python](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) or an *associative array* in other languages.
This is the other data structure that we've been talking about before, when
talking about Vecs.
## Further information ## Further information
- [Storing Lists of Values with Vectors](https://doc.rust-lang.org/stable/book/ch08-01-vectors.html)
- [Storing Keys with Associated Values in Hash Maps](https://doc.rust-lang.org/book/ch08-03-hash-maps.html) - [Storing Keys with Associated Values in Hash Maps](https://doc.rust-lang.org/book/ch08-03-hash-maps.html)

15
exercises/vecs/README.md Normal file
View File

@ -0,0 +1,15 @@
# Vectors
Vectors are one of the most-used Rust data structures. In other programming
languages, they'd simply be called Arrays, but since Rust operates on a
bit of a lower level, an array in Rust is stored on the stack (meaning it
can't grow or shrink, and the size needs to be known at compile time),
and a Vector is stored in the heap (where these restrictions do not apply).
Vectors are a bit of a later chapter in the book, but we think that they're
useful enough to talk about them a bit earlier. We shall be talking about
the other useful data structure, hash maps, later.
## Further information
- [Storing Lists of Values with Vectors](https://doc.rust-lang.org/stable/book/ch08-01-vectors.html)

View File

@ -1,8 +1,8 @@
// vec1.rs // vecs1.rs
// Your task is to create a `Vec` which holds the exact same elements // Your task is to create a `Vec` which holds the exact same elements
// as in the array `a`. // as in the array `a`.
// Make me compile and pass the test! // Make me compile and pass the test!
// Execute `rustlings hint vec1` or use the `hint` watch subcommand for a hint. // Execute `rustlings hint vecs1` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE // I AM NOT DONE

View File

@ -1,10 +1,10 @@
// vec2.rs // vecs2.rs
// A Vec of even numbers is given. Your task is to complete the loop // A Vec of even numbers is given. Your task is to complete the loop
// so that each number in the Vec is multiplied by 2. // so that each number in the Vec is multiplied by 2.
// //
// Make me pass the test! // Make me pass the test!
// //
// Execute `rustlings hint vec2` or use the `hint` watch subcommand for a hint. // Execute `rustlings hint vecs2` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE // I AM NOT DONE

View File

@ -242,8 +242,8 @@ Now you have another tool in your toolbox!"""
# VECS # VECS
[[exercises]] [[exercises]]
name = "vec1" name = "vecs1"
path = "exercises/collections/vec1.rs" path = "exercises/vecs/vecs1.rs"
mode = "test" mode = "test"
hint = """ hint = """
In Rust, there are two ways to define a Vector. In Rust, there are two ways to define a Vector.
@ -256,8 +256,8 @@ of the Rust book to learn more.
""" """
[[exercises]] [[exercises]]
name = "vec2" name = "vecs2"
path = "exercises/collections/vec2.rs" path = "exercises/vecs/vecs2.rs"
mode = "test" mode = "test"
hint = """ hint = """
Hint 1: `i` is each element from the Vec as they are being iterated. Can you try Hint 1: `i` is each element from the Vec as they are being iterated. Can you try