2020-09: Encoding Error

df <- read.csv("input.csv")

Part 1

goodNum <- FALSE
for(i in 26:1000) {
  for(r1 in (i-25):(i-1)) {
    if(df[r1,1] < df[i,1])
      for(r2 in (i-25):(i-1))
        if(df[i,1] - df[r1,1] == df[r2,1]) {
          goodNum <- TRUE
          break
        }
    if(goodNum)
      break
  }
  if(!goodNum) {
    print(df[i,1])
    break
  }
  goodNum <- FALSE
}
[1] 69316178

Part 2

goalNum <- 0
goodNum <- FALSE
for(i in 26:1000) {
  for(r1 in (i-25):(i-1)) {
    if(df[r1,1] < df[i,1])
      for(r2 in (i-25):(i-1))
        if(df[i,1] - df[r1,1] == df[r2,1]) {
          goodNum <- TRUE
          break
        }
    if(goodNum)
      break
  }
  if(!goodNum) {
    goalNum <- df[i,1]
    break
  }
  goodNum <- FALSE
}
breakFlag <- FALSE
for(start in 1:1000) {
  for(end in start:1000) {
    if(sum(df$num[start:end]) == goalNum) {
      breakFlag <- TRUE
      break
    }
  }
  if(breakFlag)
    break
}
smallest <- max(df$num)
largest <- min(df$num)

for(r in start:end) {
  if(df$num[r] < smallest)
    smallest <- df$num[r]
  if(df$num[r] > largest)
    largest <- df$num[r]
}

smallest + largest
[1] 9351526