Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- s <- sample(0:9, 4, replace = FALSE)
- while (TRUE) {
- g <- readline('Please input your guess! Guess number:')
- if (!grepl("\\d{4}", g)) {
- cat('You should input 4 digit number.')
- next
- }
- g <- strsplit(g, "")[[1]]
- cnt_a <- sum(g == s)
- cnt_b <- sum(g %in% s) - cnt_a
- if (all(g == s)) {
- cat('You are right!!!!!!!')
- break
- } else {
- cat(sprintf("%iA%iB", cnt_a, cnt_b))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment