Did this in rust too:
fn main() { let diamond_size = 17; println!("{}", gen_diamond(diamond_size)); } fn gen_diamond(size: u8) -> String { if size % 2 == 0 || size < 3 { return "i i\nn n\nv p\na u\nl t\ni\nd".to_string(); } let fill = "*"; let blank = " "; let mut output = String::from(""); let mut i = 1; while i <= (size - 2) { let blank_space = blank.repeat(usize::from((size - i) / 2)); let filled_space = fill.repeat(usize::from(i)); let line = format!("{0}{1}{2}\n", &blank_space, &filled_space, &blank_space); output.push_str(&line); i += 2 } output = format!( "{0}{1}{2}", &output, fill.repeat(usize::from(size)), &output.chars().rev().collect::<String>() ); output.to_string() }
On invalid input, it returns -
i i n n v p a u l t i d
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Did this in rust too:
On invalid input, it returns -