mirror of https://github.com/01-edu/public.git
exam-01: first 3 exercises
This commit is contained in:
parent
7ffb5f13a6
commit
0375bd79bd
Binary file not shown.
Before Width: | Height: | Size: 66 KiB |
Binary file not shown.
After Width: | Height: | Size: 119 KiB |
|
@ -14,10 +14,11 @@ The insertion sort algorithm:
|
|||
|
||||
Here is a visual example of sorting a slice step by step using the insertion sort algorithm.
|
||||
|
||||
![](Insertion-Sort-demo.jpg)
|
||||
![image.png](Insertion-Sort-demo.png)
|
||||
|
||||
**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](#usage) for more information.
|
||||
- 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
|
||||
|
||||
|
@ -32,17 +33,17 @@ Here is a possible program to test your function
|
|||
|
||||
```rust
|
||||
fn main() {
|
||||
let mut target = [5, 3, 7, 2, 1, 6, 8, 4];
|
||||
// executes the first iteration of the algorithm
|
||||
insertion_sort(&mut target, 1);
|
||||
println!("{:?}", target);
|
||||
let mut target = [5, 3, 7, 2, 1, 6, 8, 4];
|
||||
// executes the first iteration of the algorithm
|
||||
insertion_sort(&mut target, 1);
|
||||
println!("{:?}", target);
|
||||
|
||||
let mut target = [5, 3, 7, 2, 1, 6, 8, 4];
|
||||
let len = target.len();
|
||||
// executes len - 1 iterations of the algorithm
|
||||
// i.e. sorts the slice
|
||||
insertion_sort(&mut target, len - 1);
|
||||
println!("{:?}", target);
|
||||
let mut target = [5, 3, 7, 2, 1, 6, 8, 4];
|
||||
let len = target.len();
|
||||
// executes len - 1 iterations of the algorithm
|
||||
// i.e. sorts the slice
|
||||
insertion_sort(&mut target, len - 1);
|
||||
println!("{:?}", target);
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
|
||||
- Note:
|
||||
|
||||
- The transpose of a matrix `A` is the matrix `A'` where `A'`'s columns are `A`'s row and the rows are the columns:
|
||||
- The transpose of a matrix `A` is the matrix `A'` where `A'`'s columns are `A`'s row and the rows are the columns:
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
```console
|
||||
( a b c ) __ transposition __> ( a d g j )
|
||||
( d e f ) ( b e h k )
|
||||
( g h i ) ( c f i l )
|
||||
|
@ -25,22 +25,22 @@ Example:
|
|||
|
||||
### Notions
|
||||
|
||||
[Chapter 7]( https://doc.rust-lang.org/stable/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html )
|
||||
[Chapter 7](https://doc.rust-lang.org/stable/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html)
|
||||
|
||||
### Expected Function and Structs
|
||||
|
||||
```rust
|
||||
pub struct Matrix4by3(
|
||||
pub (i32, i32, i32),
|
||||
pub (i32, i32, i32),
|
||||
pub (i32, i32, i32),
|
||||
pub (i32, i32, i32),
|
||||
pub (i32, i32, i32),
|
||||
pub (i32, i32, i32),
|
||||
pub (i32, i32, i32),
|
||||
pub (i32, i32, i32),
|
||||
);
|
||||
|
||||
pub struct Matrix3by4(
|
||||
pub (i32, i32, i32, i32),
|
||||
pub (i32, i32, i32, i32),
|
||||
pub (i32, i32, i32, i32),
|
||||
pub (i32, i32, i32, i32),
|
||||
pub (i32, i32, i32, i32),
|
||||
pub (i32, i32, i32, i32),
|
||||
);
|
||||
|
||||
pub fn transpose(m: Matrix4by3) -> Matrix3by4 {
|
||||
|
@ -49,17 +49,17 @@ pub fn transpose(m: Matrix4by3) -> Matrix3by4 {
|
|||
|
||||
### Usage
|
||||
|
||||
Here is a posible program to test your function
|
||||
Here is a possible program to test your function
|
||||
|
||||
```rust
|
||||
fn main() {
|
||||
let matrix = Matrix4by3((1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12));
|
||||
let matrix = Matrix4by3((1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12));
|
||||
println!("Original matrix {:?}", matrix);
|
||||
println!("Transpose matrix {:?}", transpose(matrix));
|
||||
}
|
||||
```
|
||||
|
||||
And it's output:
|
||||
And its output:
|
||||
|
||||
```console
|
||||
student@ubuntu:~/[[ROOT]]/test$ cargo run
|
||||
|
|
|
@ -8,7 +8,9 @@ just add the char `-` to the beginning of the string.
|
|||
### Expected Functions
|
||||
|
||||
```rust
|
||||
fn reverse_it(v: i32) -> String {}
|
||||
pub fn reverse_it(v: i32) -> String {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
|
|
@ -2,20 +2,16 @@
|
|||
|
||||
### 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 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'`).
|
||||
|
||||
`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
|
||||
the two operands for the subsequent operator. Operands and operators must be
|
||||
spaced by at least one space.
|
||||
`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
|
||||
the two operands for the subsequent operator. Operands and operators must be spaced by at least one space.
|
||||
|
||||
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` 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`.
|
||||
|
@ -30,7 +26,7 @@ Examples of formulas converted in RPN:
|
|||
|
||||
Here is how to evaluate a formula in RPN:
|
||||
|
||||
```
|
||||
```console
|
||||
1 2 * 3 * 4 -
|
||||
2 3 * 4 -
|
||||
6 4 -
|
||||
|
@ -39,7 +35,7 @@ Here is how to evaluate a formula in RPN:
|
|||
|
||||
Or:
|
||||
|
||||
```
|
||||
```console
|
||||
3 1 2 * * 4 -
|
||||
3 2 * 4 -
|
||||
6 4 -
|
||||
|
@ -69,5 +65,5 @@ Error
|
|||
$ cargo run " 1 3 * 2 -"
|
||||
1
|
||||
$ cargo run " 1 3 * ksd 2 -"
|
||||
Error```
|
||||
````
|
||||
Error
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue