Skip to content

Instantly share code, notes, and snippets.

@MrEnder0
Created March 21, 2024 02:58
Show Gist options
  • Save MrEnder0/5ac652f42238579eeea0e0f6960f05db to your computer and use it in GitHub Desktop.
Save MrEnder0/5ac652f42238579eeea0e0f6960f05db to your computer and use it in GitHub Desktop.
Square Triangle (I was bored in school)
use std::num::NonZeroU64;
fn main() {
triangle(40);
cube(40);
}
fn cube(size: u64) {
match NonZeroU64::new(size) {
Some(_) => {},
None => {
println!("Invalid size");
return
}
};
for _ in 0..size {
println!("{}", "*".repeat(size as usize));
}
}
fn triangle(size: u64) {
match NonZeroU64::new(size) {
Some(_) => {},
None => {
println!("Invalid size");
return
}
};
for row in 0..size {
println!("{}{}", " ".repeat(((size - row) /2) as usize), "*".repeat((row as usize) + 1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment