mirror of https://github.com/01-edu/public.git
augusto-mantilla
4 years ago
committed by
GitHub
5 changed files with 392 additions and 0 deletions
@ -0,0 +1,25 @@ |
|||||||
|
## brackets_matching |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a program that takes an undefined number of `string` in arguments. For each argument, if the expression is correctly bracketed, the program prints on the standard output `OK` followed by a newline (`'\n'`), otherwise it prints `Error` followed by a newline. |
||||||
|
|
||||||
|
Symbols considered as brackets are parentheses `(` and `)`, square brackets `[` and `]` and curly braces `{` and `}`. Every other symbols are simply ignored. |
||||||
|
|
||||||
|
An opening bracket must always be closed by the good closing bracket in the correct order. A `string` which does not contain any bracket is considered as a correctly bracketed `string`. |
||||||
|
|
||||||
|
If there is no argument, the program must print nothing. |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/[[ROOT]]/brackets$ ./brackets '(johndoe)' | cat -e |
||||||
|
OK$ |
||||||
|
student@ubuntu:~/[[ROOT]]/brackets$ ./brackets '([)]' | cat -e |
||||||
|
Error$ |
||||||
|
student@ubuntu:~/[[ROOT]]/brackets$ ./brackets '' '{[(0 + 0)(1 + 1)](3*(-1)){()}}' | cat -e |
||||||
|
OK$ |
||||||
|
OK$ |
||||||
|
student@ubuntu:~/[[ROOT]]/brackets$ ./brackets |
||||||
|
student@ubuntu:~/[[ROOT]]/brackets$ |
||||||
|
``` |
@ -0,0 +1,91 @@ |
|||||||
|
## inv_pyramid |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Create a function called `inv_pyramid` that takes a `string` as an `integer` and returns a vector of `string`s. |
||||||
|
This function should create a pyramid structure. Each element of the vector must be a combination of spaces and the string given |
||||||
|
|
||||||
|
### Example |
||||||
|
|
||||||
|
i = 5 |
||||||
|
|
||||||
|
```console |
||||||
|
[ |
||||||
|
" >", |
||||||
|
" >>", |
||||||
|
" >>>", |
||||||
|
" >>>>", |
||||||
|
" >>>>>", |
||||||
|
" >>>>", |
||||||
|
" >>>", |
||||||
|
" >>", |
||||||
|
" >" |
||||||
|
] |
||||||
|
``` |
||||||
|
|
||||||
|
### Expected Functions |
||||||
|
|
||||||
|
```rust |
||||||
|
fn inv_pyramid(v: &str, i: u32) -> Vec<&str> {} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a program to test your function |
||||||
|
|
||||||
|
```rust |
||||||
|
fn main() { |
||||||
|
let a = inv_pyramid(String::from("#"), 1); |
||||||
|
let b = inv_pyramid(String::from("a"), 2); |
||||||
|
let c = inv_pyramid(String::from(">"), 5); |
||||||
|
let d = inv_pyramid(String::from("&"), 8); |
||||||
|
|
||||||
|
for v in a.iter() { |
||||||
|
println!("{:?}", v); |
||||||
|
} |
||||||
|
for v in b.iter() { |
||||||
|
println!("{:?}", v); |
||||||
|
} |
||||||
|
for v in c.iter() { |
||||||
|
println!("{:?}", v); |
||||||
|
} |
||||||
|
for v in d.iter() { |
||||||
|
println!("{:?}", v); |
||||||
|
} |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/[[ROOT]]/test$ cargo run |
||||||
|
" #" |
||||||
|
" a" |
||||||
|
" aa" |
||||||
|
" a" |
||||||
|
" >" |
||||||
|
" >>" |
||||||
|
" >>>" |
||||||
|
" >>>>" |
||||||
|
" >>>>>" |
||||||
|
" >>>>" |
||||||
|
" >>>" |
||||||
|
" >>" |
||||||
|
" >" |
||||||
|
" &" |
||||||
|
" &&" |
||||||
|
" &&&" |
||||||
|
" &&&&" |
||||||
|
" &&&&&" |
||||||
|
" &&&&&&" |
||||||
|
" &&&&&&&" |
||||||
|
" &&&&&&&&" |
||||||
|
" &&&&&&&" |
||||||
|
" &&&&&&" |
||||||
|
" &&&&&" |
||||||
|
" &&&&" |
||||||
|
" &&&" |
||||||
|
" &&" |
||||||
|
" &" |
||||||
|
student@ubuntu:~/[[ROOT]]/test$ |
||||||
|
``` |
@ -0,0 +1,121 @@ |
|||||||
|
## road_intersection |
||||||
|
|
||||||
|
### Objectives |
||||||
|
|
||||||
|
The objective for this raid is to create a traffic control strategy and represent it with an interface/UI. |
||||||
|
Its up to you to decide which library and file system you want do use to create this simulation, but we recommend to use the library [sdl2](https://docs.rs/sdl2/0.34.3/sdl2/) |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
#### **Environment and Rules** |
||||||
|
|
||||||
|
You must create an environment which contains all the objects described in this section. You can display the objects as you wish. |
||||||
|
|
||||||
|
1. Roads |
||||||
|
|
||||||
|
There exists various shapes of intersections, we will focus on the widely seen four-lane intersection. For simplicity each lane will have two directions. |
||||||
|
|
||||||
|
```console |
||||||
|
| ↓ | ↑ | |
||||||
|
| ↓ | ↑ | |
||||||
|
| ↓ | ↑ | |
||||||
|
| ↓ | ↑ | |
||||||
|
| ↓ | ↑ | |
||||||
|
| r s l | ↑ | |
||||||
|
_______________| ← ↓ → | ↑ |_____________ |
||||||
|
| ↑ r |
||||||
|
← ← ← ← ← ← ← | ← s ← ← ← ← ← |
||||||
|
| ↓ l |
||||||
|
_________________________|_______________________ |
||||||
|
l ↑ | |
||||||
|
→ → → → → s → | → → → → → → |
||||||
|
r ↓ | |
||||||
|
_______________ | _____________ |
||||||
|
| | ← ↑ → | |
||||||
|
| ↓ | r s l | |
||||||
|
| ↓ | ↑ | |
||||||
|
| ↓ | ↑ | |
||||||
|
| ↓ | ↑ | |
||||||
|
| ↓ | ↑ | |
||||||
|
| ↓ | ↑ | |
||||||
|
``` |
||||||
|
|
||||||
|
For clarification reasons we will assume that a lane can have three different routes (consider you are in the vehicle position): |
||||||
|
|
||||||
|
- `r`, turning right |
||||||
|
- `s`, straight ahead |
||||||
|
- `l`, turning left |
||||||
|
|
||||||
|
2. Traffic lights |
||||||
|
|
||||||
|
Traffic lights are signalling devices positioned at road intersections that follows an universal color code, |
||||||
|
normally its green, red and amber, but for this project you will just use the colors **red** and **green**. |
||||||
|
|
||||||
|
You will then have to create some kind of representation for the traffic lights and distribute them for each lane in the intersection. |
||||||
|
|
||||||
|
You are free to decide what algorithm you want to implement for the traffic light system, but keep in mind that traffic congestion should not be to high. |
||||||
|
|
||||||
|
3. Vehicles |
||||||
|
|
||||||
|
``` |
||||||
|
______ |
||||||
|
/|_||_\`.__ |
||||||
|
=`-(_)--(_)-' |
||||||
|
``` |
||||||
|
|
||||||
|
Vehicles must obey this rules: |
||||||
|
|
||||||
|
- Vehicles must have a color depending on their route the colors are up to you to decide(ex:`r`- purple, `s`- Blue and `l`- Yellow). This must then be given during the audit |
||||||
|
|
||||||
|
- Autonomous, vehicles driving on a lane with a **given route** must follow the direction of |
||||||
|
that route, its not possible for the driver to change lanes or route. |
||||||
|
|
||||||
|
- Each vehicle must have a fixed velocity. |
||||||
|
|
||||||
|
- It must be kept a safety distance from other vehicles, if one vehicle stops the other vehicle thats |
||||||
|
behind him must stop and keep its distance. |
||||||
|
|
||||||
|
- Vehicles must stop if the traffic light is red and proceed otherwise. |
||||||
|
|
||||||
|
- Vehicles must have different routes, either `r`, `s` or `l`. |
||||||
|
|
||||||
|
- Other vehicles such as emergency vehicles are not considered. |
||||||
|
|
||||||
|
--- |
||||||
|
|
||||||
|
#### **Commands** |
||||||
|
|
||||||
|
The generating of vehicle must be done using the keyboard event. You must be able to generate |
||||||
|
vehicles in different lanes and with different routes. |
||||||
|
|
||||||
|
For this it must be possible to do the following: |
||||||
|
|
||||||
|
- The `Arrow` keys must generate one vehicle in a specific direction and with a random route ( `r`, `s` and `l`): |
||||||
|
- `Up` south to north. |
||||||
|
- `Down` north to south. |
||||||
|
- `Right` west to east. |
||||||
|
- `Left` east to west. |
||||||
|
|
||||||
|
- The `R` key must generate random vehicles with random lanes and routes. |
||||||
|
|
||||||
|
- The `Esc` key must finish the simulation. |
||||||
|
|
||||||
|
> Arrow keys must not let the user spam the creation of vehicles, vehicles must be created with a safe distance between them. |
||||||
|
|
||||||
|
### Example |
||||||
|
|
||||||
|
You can see an example [here](https://youtu.be/pC79E0fdzYo). |
||||||
|
|
||||||
|
### Bonus |
||||||
|
|
||||||
|
You can implement the following optional features : |
||||||
|
|
||||||
|
- Vehicle and traffic lights animation and image rendering. You can find some cool assets : |
||||||
|
- [limezu](https://limezu.itch.io/) |
||||||
|
- [finalbossblue](http://finalbossblues.com/timefantasy/free-graphics/). |
||||||
|
- [mobilegamegraphics](https://mobilegamegraphics.com/product-category/all_products/freestuff/). |
||||||
|
- [spriters-resource](https://www.spriters-resource.com/). |
||||||
|
|
||||||
|
### Notions |
||||||
|
|
||||||
|
- https://docs.rs/sdl2/0.34.3/sdl2/ |
@ -0,0 +1,87 @@ |
|||||||
|
#### Functionals |
||||||
|
|
||||||
|
##### Try and run the application, then generate a vehicle by pressing the `"Arrow Up"` key. |
||||||
|
|
||||||
|
###### Was a vehicle generated from the cardinal south? |
||||||
|
|
||||||
|
##### Try pressing the `"Arrow Down"` key. |
||||||
|
|
||||||
|
###### Was a vehicle generated from the cardinal North? |
||||||
|
|
||||||
|
##### Try pressing the `"Arrow Right"` key. |
||||||
|
|
||||||
|
###### Was a vehicle generated from the cardinal west? |
||||||
|
|
||||||
|
##### Try pressing the `"Arrow left"` key. |
||||||
|
|
||||||
|
###### Was a vehicle generated from the cardinal east? |
||||||
|
|
||||||
|
##### Try pressing the `"R"` key. |
||||||
|
|
||||||
|
###### Are vehicles generated randomly(random lane and route)? |
||||||
|
|
||||||
|
##### Try to generate tree vehicles in the same lane (do this to all lanes). |
||||||
|
|
||||||
|
###### Did all vehicles passed the intersection without any collision? |
||||||
|
|
||||||
|
##### Try to generate two vehicles at the same time, one using the `"Up"` key and the other using the `"Down"` key (to this at least 3 times). |
||||||
|
|
||||||
|
###### Did all vehicles passed the intersection without any collision? |
||||||
|
|
||||||
|
##### Try to generate two vehicles at the same time, one using the `"Right"` key and the other using the `"Left"` key (to this at least 3 times). |
||||||
|
|
||||||
|
###### Did all vehicles passed the intersection without any collision? |
||||||
|
|
||||||
|
##### Try to generate two vehicles at the same time, one using the `"Up"` key and the other using the `"Left"` key (to this at least 3 times). |
||||||
|
|
||||||
|
###### Did all vehicles passed the intersection without any collision? |
||||||
|
|
||||||
|
##### Try to generate two vehicles at the same time, one using the `"Up"` key and the other using the `"Right"` key (to this at least 3 times). |
||||||
|
|
||||||
|
###### Did all vehicles passed the intersection without any collision? |
||||||
|
|
||||||
|
##### Try to generate two vehicles at the same time, one using the `"Down"` key and the other using the `"Left"` key (to this at least 3 times). |
||||||
|
|
||||||
|
###### Did all vehicles passed the intersection without any collision? |
||||||
|
|
||||||
|
##### Try to generate two vehicles at the same time, one using the `"Down"` key and the other using the `"Right"` key (to this at least 3 times). |
||||||
|
|
||||||
|
###### Did all vehicles passed the intersection without any collision? |
||||||
|
|
||||||
|
##### Try to generate five vehicles using the `"Up"` key, at the same time generate two vehicles using the key `"Right"`. |
||||||
|
|
||||||
|
###### Did all vehicles passed the intersection without any collision? |
||||||
|
|
||||||
|
##### Try to generate one vehicle for all the lanes (to this at least 3 times). |
||||||
|
|
||||||
|
###### Did all vehicles passed the intersection without any collision? |
||||||
|
|
||||||
|
##### Try to generate vehicles randomly using the `"R"` key. Then wait for at least 1 min. |
||||||
|
|
||||||
|
###### Did all vehicles passed the intersection without any collision? |
||||||
|
|
||||||
|
###### Was there a low traffic congestion while running the application? (ex: high traffic congestion can be 8 or more vehicles in the same lane without proceeding)? |
||||||
|
|
||||||
|
##### Try to generate vehicles with lanes at your choice. |
||||||
|
|
||||||
|
###### Did all vehicles passed the intersection without any collision? |
||||||
|
|
||||||
|
#### General |
||||||
|
|
||||||
|
###### Is it not possible to spam the creation of vehicles(by pressing the arrow keys to many times)? |
||||||
|
|
||||||
|
###### Are vehicles assigned to their own route, and if so do they obey that route? (you can use the colors for each route to see this) |
||||||
|
|
||||||
|
###### Are vehicles kept in a safe distance(do not collide when ever one stops)? |
||||||
|
|
||||||
|
###### Do vehicles stop when ever there is a red light? |
||||||
|
|
||||||
|
###### Do vehicles proceed when ever there is a green light? |
||||||
|
|
||||||
|
#### Bonus |
||||||
|
|
||||||
|
###### +Is there any type of image sprite for traffic light? |
||||||
|
|
||||||
|
###### +Did the student implement some kind of animation and image sprite for the vehicle? |
||||||
|
|
||||||
|
###### +Did the student implement more features than those in the subject? |
@ -0,0 +1,68 @@ |
|||||||
|
## scytale_cipher |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Create a function called `scytale_cipher` that takes a `string` and an `integer` and returns a `string`. |
||||||
|
This function should create a scytale cipher also known as spartan cipher. In practice its a cylinder with a |
||||||
|
strip strapped around it on which is written a message, when removed the strip the message is coded. |
||||||
|
Depending on the size of the cylinder the message would change. So the only way to decipher the coded message is |
||||||
|
by using a cylinder of the same size. |
||||||
|
|
||||||
|
You function should recreate the scytale cipher, the string being the message and the size being the number of |
||||||
|
straps in the cylinder. |
||||||
|
|
||||||
|
### Example |
||||||
|
|
||||||
|
message : "scytale Code" |
||||||
|
size : 6 |
||||||
|
|
||||||
|
```console |
||||||
|
['s', 'e'] |
||||||
|
['c', ' '] |
||||||
|
['y', 'C'] |
||||||
|
['t', 'o'] |
||||||
|
['a', 'd'] |
||||||
|
['l', 'e'] |
||||||
|
``` |
||||||
|
|
||||||
|
output : sec yCtoadle |
||||||
|
size : 8 |
||||||
|
|
||||||
|
```console |
||||||
|
['s', 'C'] |
||||||
|
['c', 'o'] |
||||||
|
['y', 'd'] |
||||||
|
['t', 'e'] |
||||||
|
['a', ' '] |
||||||
|
['l', ' '] |
||||||
|
['e', ' '] |
||||||
|
[' ', ' '] |
||||||
|
``` |
||||||
|
|
||||||
|
output : sCcoydtea l e |
||||||
|
|
||||||
|
### Expected Functions |
||||||
|
|
||||||
|
```rust |
||||||
|
fn scytale_cipher(message: String, i: u32) -> String {} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a program to test your function |
||||||
|
|
||||||
|
```rust |
||||||
|
fn main() { |
||||||
|
println!("\"scytale Code\" size=6 -> {:?}", scytale_cipher(String::from("scytale Code"), 6))); |
||||||
|
println!("\"scytale Code\" size=8 -> {:?}", scytale_cipher(String::from("scytale Code"), 8))); |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/[[ROOT]]/test$ cargo run |
||||||
|
"scytale Code" size=6 -> "sec yCtoadle" |
||||||
|
"scytale Code" size=8 -> "sCcoydtea l e" |
||||||
|
student@ubuntu:~/[[ROOT]]/test$ |
||||||
|
``` |
Loading…
Reference in new issue