From ec8b2a8aa92465d6bc205335d41d3af506e89b99 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 Mar 2021 16:02:47 +0000 Subject: [PATCH] first pass exam 1 for rust --- subjects/insertion_sort/README.md | 17 ++++++++--------- subjects/matrix_transposition_4by3/README.md | 11 ++++++----- subjects/reverse_it/README.md | 7 +++---- subjects/rpn/README.md | 7 ++++--- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/subjects/insertion_sort/README.md b/subjects/insertion_sort/README.md index 916a39f5..d94c2e09 100644 --- a/subjects/insertion_sort/README.md +++ b/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 diff --git a/subjects/matrix_transposition_4by3/README.md b/subjects/matrix_transposition_4by3/README.md index 5bdf28d7..eaaae39e 100644 --- a/subjects/matrix_transposition_4by3/README.md +++ b/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() { diff --git a/subjects/reverse_it/README.md b/subjects/reverse_it/README.md index f344a23a..3930d09d 100644 --- a/subjects/reverse_it/README.md +++ b/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 diff --git a/subjects/rpn/README.md b/subjects/rpn/README.md index d73a60bd..1364d086 100644 --- a/subjects/rpn/README.md +++ b/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 ``` +````