Skip to content

Instantly share code, notes, and snippets.

@JakeKalkman
Created July 27, 2019 04:17
Show Gist options
  • Save JakeKalkman/b4e0787923e477322a8f4438ba465986 to your computer and use it in GitHub Desktop.
Save JakeKalkman/b4e0787923e477322a8f4438ba465986 to your computer and use it in GitHub Desktop.
input <- scan("day1Input.txt") # each line is an integer.
sum <- 0
results <- c()
flag <- FALSE
while(flag == FALSE){
for(line in input){
sum = sum + line
if(sum %in% results){ # If we find a duplicate sum print it.
print(sum)
flag <- TRUE
break
}
results <- c(results,sum) # Keep track of past sums
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment