2020-01: Report Repair

library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.4.0      ✔ purrr   0.3.5 
✔ tibble  3.1.8      ✔ dplyr   1.0.10
✔ tidyr   1.2.1      ✔ stringr 1.4.1 
✔ readr   2.1.3      ✔ forcats 0.5.2 
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
df <- read.csv("Input.csv")
head(df)
  values
1   1768
2   1847
3   1905
4   1713
5   1826
6   1846

Part 1

key <- NA

for(x in 1:200) {
  for(y in 1:200) {
    if((df$values[x] + df$values[y]) == 2020) {
      print(paste(df$values[x], df$values[y]))
      key <- df$values[x] * df$values[y]
      print(key)
    }
    if(!is.na(key))
      break
  }
}
[1] "1825 195"
[1] 355875

Part 2

key <- NA

for(x in 1:200) {
  for(y in 1:200) {
    for(z in 1:200) {
      if((df$values[x] + df$values[y]) + df$values[z] == 2020) {
        print(paste(df$values[x], df$values[y], df$values[z]))
        key <- df$values[x] * df$values[y] * df$values[z]
        print(key)
      }
      if(!is.na(key))
        break
    }
  }
}
[1] "346 1380 294"
[1] 140379120