Created
October 4, 2019 00:46
-
-
Save dwhdai/d98dc1955f774c1601ca8324872c00e0 to your computer and use it in GitHub Desktop.
advent of code 1
This file contains hidden or 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
| captcha <- function(x){ | |
| #input 1122 | |
| #return 3 | |
| #input 1111 | |
| #return 4 | |
| first_digit <- substr(x,1,1) | |
| x <- paste0(x, first_digit) | |
| t <- vector(mode = "character") | |
| for (i in 1:(nchar(x)-1)){ | |
| current_digit <- substr(x,i,i) | |
| next_digit <- substr(x, i+1, i+1) | |
| if (current_digit == next_digit){ | |
| t <- append(t, next_digit) | |
| } | |
| } | |
| nums_to_add <- as.numeric(t) | |
| return(sum(nums_to_add)) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
xis the input stored as a character, since R has a maximum value for numbers