From bfacf6ec83c8687fc8c41e80636b616f3520e8e1 Mon Sep 17 00:00:00 2001 From: lee Date: Fri, 22 Jan 2021 15:47:54 +0000 Subject: [PATCH] rust exercise: inv_pyramid --- subjects/inv_pyramid/README.md | 91 ++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 subjects/inv_pyramid/README.md diff --git a/subjects/inv_pyramid/README.md b/subjects/inv_pyramid/README.md new file mode 100644 index 00000000..c5105286 --- /dev/null +++ b/subjects/inv_pyramid/README.md @@ -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$ +```