Browse Source

first pass exam 1 for rust

content-update
Chris 3 years ago
parent
commit
ec8b2a8aa9
  1. 17
      subjects/insertion_sort/README.md
  2. 11
      subjects/matrix_transposition_4by3/README.md
  3. 7
      subjects/reverse_it/README.md
  4. 7
      subjects/rpn/README.md

17
subjects/insertion_sort/README.md

@ -2,15 +2,15 @@
### Instructions
The insertion sort algorithm:
- Implement the insertion sort algorithm by creating a function `insertion_sort(slice, steps)` which executes the iterations of the algorithm **up to** the number of steps indicated by the parameter `steps`. See the **Usage** for more information.
- To sort an array of size n in ascending order:
The insertion sort algorithm to sort an array of size n in ascending order:
1. Iterate from slice[1] to slice[n] over the slice.
1. Iterates from slice[1] to slice[n] over the slice.
2. Compare the current element (key) to its predecessor.
2. Compares the current element (key) to its predecessor.
3. If the key element is smaller than its predecessor, compare it to the elements before. Move the greater elements one position up to make space for the swapped element.
3. If the key element is smaller than its predecessor, compares it to the elements before. Move the greater elements one position up to make space for the swapped element.
Here is a visual example of sorting a slice step by step using the insertion sort algorithm.
@ -18,18 +18,17 @@ Here is a visual example of sorting a slice step by step using the insertion sor
**Figure 1** - Step by step execution of the algorithm insertion sort
- Implement the algorithm insertion sort by creating a function `insertion_sort(slice, steps)` that executes the iterations of the algorithm the number of steps indicated by the parameter `steps`. See the **Usage** for more information.
### Expected Function
```rust
pub fn insertion_sort(slice: &mut [i32], steps: usize) {
}
```
### Usage
Here is a possible program to test your function
Here is a possible program to test your function,
```rust
fn main() {
@ -47,7 +46,7 @@ fn main() {
}
```
And it's output:
And its output:
```console
student@ubuntu:~/[[ROOT]]/test$ cargo run

11
subjects/matrix_transposition_4by3/README.md

@ -4,7 +4,7 @@
- Define the structure matrix as a tuple of tuples of `i32`'s
- Define a function that calculate the transpose matrix of a 4x3 matrix (4 rows by 3 columns) which is a 3x4 matrix (3 rows by 4 columns).
- Define a **function** which calculates the transpose matrix of a 4x3 matrix (4 rows by 3 columns) which is a 3x4 matrix (3 rows by 4 columns).
- Note:
@ -19,13 +19,13 @@ Example:
( j k l )
```
- Matrix must implement Debug, PartialEq and Eq. You can use derive
- Matrix must implement Debug, PartialEq and Eq. You can use derive.
- Remember that you're defining a library so you have to make public the elements that are going to be called from an external crate.
- Remember that a library has to be defined so the elements mube made public in order to be called from an external crate.
### Notions
[Chapter 7](https://doc.rust-lang.org/stable/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html)
[paths for referring to an item in the module tree](https://doc.rust-lang.org/stable/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html)
### Expected Function and Structs
@ -44,12 +44,13 @@ pub struct Matrix3by4(
);
pub fn transpose(m: Matrix4by3) -> Matrix3by4 {
}
```
### Usage
Here is a possible program to test your function
Here is a possible program to test your function,
```rust
fn main() {

7
subjects/reverse_it/README.md

@ -2,8 +2,7 @@
### Instructions
Create a function called `reverse_it` that takes a number and returns a string with the number backwards followed by the original number. If the number is negative you should
just add the char `-` to the beginning of the string.
Create a function called `reverse_it` that takes a number and returns a string with the number backwards followed by the original number. If the number is negative a char `-` has to be added to the beginning of the string.
### Expected Functions
@ -15,7 +14,7 @@ pub fn reverse_it(v: i32) -> String {
### Usage
Here is a program to test your function
Here is a program to test your function,
```rust
fn main() {
@ -24,7 +23,7 @@ fn main() {
}
```
And its output
And its output:
```console
student@ubuntu:~/[[ROOT]]/test$ cargo run

7
subjects/rpn/README.md

@ -2,8 +2,8 @@
### Instructions
Write a program that takes a `string` which contains an equation written in `Reverse Polish Notation` (RPN) as its first argument,
that evaluates the equation, and that prints the result on the standard output followed by a newline (`'\n'`).
Write a **program** which takes a `string` which contains an equation written in `Reverse Polish Notation` (RPN) as its first argument,
which evaluates the equation, and which prints the result on the standard output followed by a newline (`'\n'`).
`Reverse Polish Notation` is a mathematical notation in which every operator follows all of its operands. In RPN,
every operator encountered evaluates the previous 2 operands, and the result of this operation then becomes the first of
@ -14,7 +14,7 @@ The following operators must be implemented : `+`, `-`, `*`, `/`, and `%`.
If the `string` is not valid or if there is not exactly one argument, `Error` must be printed on the standard output followed by a newline.
If the `string` has extra spaces it is still considered valid.
All the given operands must fit in a `int`.
All the given operands must fit in a `i64`.
Examples of formulas converted in RPN:
@ -67,3 +67,4 @@ $ cargo run " 1 3 * 2 -"
$ cargo run " 1 3 * ksd 2 -"
Error
```
````

Loading…
Cancel
Save