Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion subjects/adding_twice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The type of the arguments are missing. Use the example `main` function to determ

```rust
pub fn twice<T>(F: _) -> _{

todo!()
}
```

Expand Down
3 changes: 1 addition & 2 deletions subjects/closures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Using closures and iterators create a **function**, that returns the first 50 ev

```rust
fn first_fifty_even_square() -> Vec<i32> {

todo!()
}
```

Expand All @@ -20,7 +20,6 @@ Here is a program to test your function.
use closures::*;

fn main() {
println!("Hello, world!");
let v1 = first_fifty_even_square();

println!("All elements in {:?}, len = {}", v1, v1.len());
Expand Down
19 changes: 10 additions & 9 deletions subjects/get_products/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@

### Instructions

Create a function named `get_products` that takes a vector of integers, and returns a vector of the products of each index.
Create a function named `get_products` that takes an array of integers, and returns an array of the products of each other index.

You'll need to return the product of every index
except the current one.
For each element, you'll need to return the product of every other index.

If an array of one element is given, the same element should always become `1`.

### Example:

For `[1,2,3,4]`, we get:

- for the number `1` we get `2*3*4 = 24`.
- for the number `3` we get `1*2*4 = 8`.
- The element `1` becomes `2*3*4 = 24`.
- The element `3` becomes `1*2*4 = 8`.

### Expected functions

```rust
pub fn get_products(arr: Vec<usize>) -> Vec<usize> {

pub fn get_products(arr: [usize; _]) -> [usize; _] {
todo!()
}
```

Expand All @@ -29,8 +31,7 @@ Here is a program to test your function.
use get_products::get_products;

fn main() {
let arr: Vec<usize> = vec![1, 7, 3, 4];
let output = get_products(arr);
let output = get_products([1, 7, 3, 4]);
println!("{:?}", output);
}
```
Expand Down
40 changes: 25 additions & 15 deletions subjects/highest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,44 @@

### Instructions

In this exercise, a `Numbers` struct will be given.
In this exercise, a `Numbers` struct will be given. This struct will contain an array of `u32` numbers.

These methods have to be written for it:

- `new`: create a new instance of `Numbers`.
- `List`: which returns an `array` with every number in the struct.
- `Latest`: which returns an `Option<u32>` with the last added number.
- `Highest`: which returns an `Option<u32>` with the highest number from the list.
- `Highest_Three`: which returns a `Vec<u32>` with the three highest numbers.
- `inner`: which returns the inner array as a slice.
- `last`: which returns an `Option<u32>` with the last added number.
- `highest`: which returns an `Option<u32>` with the biggest number from the list.
- `highest_three`: which returns an `Option<[u32; 3]>` with the three biggest numbers. These numbers should be ordered. If there aren't three numbers in the array, return `None`.

### Expected functions

```rust
#[derive(Debug)]
pub struct Numbers<'a> {
numbers: &'a [u32],
pub struct Numbers {
numbers: [u32; _],
}

impl Numbers {
pub fn new(numbers: &[u32]) -> Self {}
pub fn new(numbers: [u32; _]) -> Self {
todo!()
}

pub fn list(&self) -> &[u32] {}
pub fn inner(&self) -> &[u32] {
todo!()
}

pub fn latest(&self) -> Option<u32> {}
pub fn latest(&self) -> Option<u32> {
todo!()
}

pub fn highest(&self) -> Option<u32> {}
pub fn highest(&self) -> Option<u32> {
todo!()
}

pub fn highest_three(&self) -> Vec<u32> {}
pub fn highest_three(&self) -> Option<[u32; 3]> {
todo!()
}
}
```

Expand All @@ -42,8 +52,8 @@ use highest::*;

fn main() {
let expected = [30, 500, 20, 70];
let n = Numbers::new(&expected);
println!("{:?}", n.list());
let n = Numbers::new(expected);
println!("{:?}", n.inner());
println!("{:?}", n.highest());
println!("{:?}", n.latest());
println!("{:?}", n.highest_three());
Expand All @@ -57,7 +67,7 @@ $ cargo run
[30, 500, 20, 70]
Some(500)
Some(70)
[500, 70, 30]
Some([500, 70, 30])
$
```

Expand Down
31 changes: 11 additions & 20 deletions subjects/iterators/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ Take any positive integer `n`.

Repeat the process indefinitely. The conjecture states that no matter which number you start with, you will always reach 1 eventually.

But sometimes the number grow significantly before it reaches 1. This can lead to an integer overflow and makes the algorithm unsolvable within the range of a number in u64. You will not have to worry about that in this exercise.

Given a number `n`, return the number of steps required to reach 1.

Examples:
Expand All @@ -27,6 +25,8 @@ Starting with n = 16, the steps would be as follows:

Resulting in 4 steps. So for input n = 16, the return value would be 4.

Depending on the input, the number can grow significantly before it reaches 1. This can lead to an integer overflow and makes the algorithm potentially unsolvable within the range of a u64. We should handle overflow by returning `None`. If the input is invalid, we will also return `None`. We will only consider valid input any positive, non-zero integer.

### Notions

- [Trait Iterator](https://doc.rust-lang.org/std/iter/trait.Iterator.html)
Expand All @@ -35,18 +35,9 @@ Resulting in 4 steps. So for input n = 16, the return value would be 4.
### Expected functions

```rust
#[derive(Copy, Clone)]
pub struct Collatz {
pub v: u64,
}

impl Iterator for Collatz {}

impl Collatz {
pub fn new(n: u64) -> Self {}
pub fn collatz(n: u64) -> Option<usize> {
todo!()
}

pub fn collatz(n: u64) -> usize {}
```

### Usage
Expand All @@ -71,12 +62,12 @@ And its output:

```console
$ cargo run
0
0
2
5
8
16
9
None
Some(0)
Some(2)
Some(5)
Some(8)
Some(16)
Some(9)
$
```
38 changes: 22 additions & 16 deletions subjects/markdown_to_html/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@

### Instructions

Create a function which converts markdown into HTML.
Create a function which converts markdown to HTML.
We will be using a modified, simpler version of the [CommonMark](https://commonmark.org/) specification.

To make the task easier you'll only have to account for the first three titles (`#`, `##`, `###`) and for `bold` and `italic` (`**` and `*`).
Here's how your parser should behave:

Parsing and converting markdown can be very tricky and some edge cases can require a lot of time to solve, for this reason we will limit the tests to correct and simple inputs.
- Headers (`# `, `## `, `### `) should be converted to `<h1>`, `<h2>`, `<h3>` tags respectively.
- Bold (`**`) and italic (`*`) should be converted to `<strong>` and `<em>` tags respectively.
- Blockquotes (`> `) should be converted to `<blockquote>` tags.
- Separators (`****`) should be converted to `<hr />` tags. Separators are inline elements, which means there's no content inside them. This means that a `****` should be literally converted to `<hr />`.
- All whitespace should be trimmed and all consecutive newlines should be transformed into a single newline.

No tests will be more complicated than the one showed in the usage example.
Parsing and converting markdown can be particularly tricky for some edge cases. For this reason, we will keep the inputs fairly simple.
No test will be more complicated than the one showed in the usage example.

### Expected Function

```rust
pub fn markdown_to_html(s: &str) -> String {
todo!()
}
```

Expand All @@ -24,7 +31,7 @@ Here is a possible program to test your function,
```rust
const EXAMPLE: &str = "# This is a nice converter

## It handle *all* titles
## It handles *all* titles

## From # to ### with no problems

Expand All @@ -33,15 +40,20 @@ const EXAMPLE: &str = "# This is a nice converter

> Blockquotes are handled too
>if well formatted of course
> test!

And **bold** and *italics* of course work as well.
And **bold** and *italics* of course work as well.

****

**bold on
multiple
lines
also**";


also**

";

fn main() {
println!("{}", markdown_to_html(EXAMPLE));
Expand All @@ -53,21 +65,15 @@ And its output:
```console
$ cargo run
<h1>This is a nice converter</h1>

<h2>It handle <em>all</em> titles</h2>

<h2>It handles <em>all</em> titles</h2>
<h2>From # to ### with no problems</h2>

<h3>With attention to details ;)</h3>
###With attention to details ;)

<blockquote>Blockquotes are handled too</blockquote>
>if well formatted of course

<blockquote>test!</blockquote>
And <strong>bold</strong> and <em>italics</em> of course work as well.

<strong></strong>

<hr />
<strong>bold on
multiple
lines
Expand Down
67 changes: 31 additions & 36 deletions subjects/project_motion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,49 @@

For this exercise, you will have to create a [projectile motion](https://cimg2.ck12.org/datastreams/f-d%3Abb024be6673110b31e78b46819e792adaed8dc661e082a61f0a6d64e%2BIMAGE%2BIMAGE.1).

Two structures will be provided. A structure called `ThrowObject` that will contain all the variables that are
essential for the projectile physics (initial position, initial velocity, current position, current velocity and time).
Two structures will be provided. A structure called `ThrownObject` that will contain all the variables that are
essential for the projectile physics (initial position and velocity and time elapsed).

A structure called `Object` which will have the corresponding values of X and Y of the initial position, the initial velocity, the current position and the current velocity.
A structure called `Vec2` which represents a scalar with X and Y components. You can use it to represent positions and velocity.

You must implement :
You must implement:

- A function `new` that will initialize the ThrowObject with a given initial position and an initial velocity.
- The trait Iterator with the `.next()` in which the position and speed of the object must be calculated after 1 second.
It will return an `Option` with the ThrowObject, or it will return `None` if the ThrowObject has already reached the floor.
- An associated function `new` that will initialize the `ThrownObject` with a given initial position and velocity.
- The trait `Iterator` where the new position and velocity of the object will be calculated and returned for each second.
It should return the new position and velocity as a tuple, or `None` if the `ThrownObject` has already reached the floor.

Consider the value of gravity is 9.8m/(s*s) and that the position (p) in the instant s of an object is given by:
Consider the value of gravity is 9.8m/s^2 and that the position (p) in the instant s of an object is given by:

![Position Formula](position_formula.png)

and velocity (v) in the instant s of an object is given by:

![Speed Formula](speed_formula.png)


### Notions

- [trait Iterator](https://doc.rust-lang.org/std/iter/trait.Iterator.html)
- [iter](https://doc.rust-lang.org/rust-by-example/trait/iter.html)

### Expected Function

```rust

#[derive(Debug, Clone, PartialEq)]
pub struct Object {
pub x: f32,
pub y: f32,
#[derive(Debug, PartialEq, Clone, Copy)]
pub struct Vec2 {
pub x: f64,
pub y: f64,
}

#[derive(Debug, Clone, PartialEq)]
pub struct ThrowObject {
pub init_position: Object,
pub init_velocity: Object,
pub actual_position: Object,
pub actual_velocity: Object,
pub time: f32,
#[derive(Debug, PartialEq, Clone, Copy)]
pub struct ThrownObject {
initial_position: Vec2,
initial_velocity: Vec2,
elapsed: f64,
}

impl ThrowObject {
pub fn new(init_position: Object, init_velocity: Object) -> ThrowObject {
impl ThrownObject {
pub fn new(position: Vec2, velocity: Vec2) -> Self {
todo!()
}
}

impl Iterator for ThrowObject {
// next
impl Iterator for ThrownObject {

}

```
Expand All @@ -67,8 +59,7 @@ Here is a program to test your function
use project_motion::*;

fn main() {
let mut obj = ThrowObject::new(Object { x: 50.0, y: 50.0 }, Object { x: 0.0, y: 0.0 });
println!("{:?}", obj.next());
let mut obj = ThrownObject::new(Vec2 { x: 50., y: 50. }, Vec2 { x: 0., y: 0. });
println!("{:?}", obj.next());
println!("{:?}", obj.next());
println!("{:?}", obj.next());
Expand All @@ -80,10 +71,14 @@ And its output:

```console
$ cargo run
Some(ThrowObject { init_position: Object { x: 50.0, y: 50.0 }, init_velocity: Object { x: 0.0, y: 0.0 }, actual_position: Object { x: 50.0, y: 45.1 }, actual_velocity: Object { x: 0.0, y: -9.8 }, time: 1.0 })
Some(ThrowObject { init_position: Object { x: 50.0, y: 50.0 }, init_velocity: Object { x: 0.0, y: 0.0 }, actual_position: Object { x: 50.0, y: 30.4 }, actual_velocity: Object { x: 0.0, y: -19.6 }, time: 2.0 })
Some(ThrowObject { init_position: Object { x: 50.0, y: 50.0 }, init_velocity: Object { x: 0.0, y: 0.0 }, actual_position: Object { x: 50.0, y: 5.9 }, actual_velocity: Object { x: 0.0, y: -29.4 }, time: 3.0 })
None
Some((Vec2 { x: 50.0, y: 45.1 }, Vec2 { x: 0.0, y: -9.8 }))
Some((Vec2 { x: 50.0, y: 30.4 }, Vec2 { x: 0.0, y: -19.6 }))
Some((Vec2 { x: 50.0, y: 5.899999999999999 }, Vec2 { x: 0.0, y: -29.400000000000002 }))
None
$
```

### Notions

- [trait Iterator](https://doc.rust-lang.org/std/iter/trait.Iterator.html)
- [iter](https://doc.rust-lang.org/rust-by-example/trait/iter.html)
Loading
Loading