Created
November 16, 2023 10:02
-
-
Save kennedymwavu/498fab89815e0d82a5f7fdd4c6062c95 to your computer and use it in GitHub Desktop.
Create a diamond pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n <- 10 | |
num_of_stars_per_row_upper_sequence <- seq(from = 1, by = 2, length.out = n) | |
row_length <- num_of_stars_per_row_upper_sequence[n] | |
num_of_stars_per_row_lower_sequence <- rev(num_of_stars_per_row_upper_sequence)[-1] | |
upper_and_lower_sequence <- c(num_of_stars_per_row_upper_sequence, num_of_stars_per_row_lower_sequence) | |
for (i in upper_and_lower_sequence) { | |
num_of_spaces <- (row_length - i) / 2 | |
spaces <- rep(" ", times = num_of_spaces) | |
stars <- rep("*", times = i) | |
cat(spaces, stars, "\n", sep = "") | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment