Last active
July 13, 2019 02:54
-
-
Save BroVic/edb9bf1af375fb995b3084d181f0884e to your computer and use it in GitHub Desktop.
R implementation of CS50x's Problem Set 6 - mario, more comfortable
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
# mario.R | |
printCharInSeq <- function(char, num) { | |
for (n in seq_len(num)) { | |
cat(char) | |
} | |
} | |
prompt <- "Height: " | |
repeat { | |
if (interactive()) { | |
height <- readline(prompt) | |
} | |
else { | |
cat(prompt) | |
height <- readLines("stdin", n = 1) | |
} | |
height <- suppressWarnings(as.numeric(height[1])) | |
if ((height > 0 && height < 9) && !is.na(height)) | |
break | |
} | |
for (numblocks in seq_len(height)) { | |
spaces <- height - numblocks | |
printCharInSeq(" ", spaces) | |
printCharInSeq("#", numblocks) | |
printCharInSeq(" ", 2) | |
printCharInSeq("#", numblocks) | |
cat("\n") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment