2020-10: Adapter Array

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

Part 1

df <- df[order(df$jolts),]
count1 <- 0
count3 <- 0
for(r in 1:(nrow(df) - 1)) {
  if(df[r+1,1] - df[r,1] == 1)
    count1 <- count1 + 1
  else if(df[r+1,1] - df[r,1] == 3)
    count3 <- count3 + 1
}
count1 * count3
[1] 2414

Part 2

df$paths <- 0
df$paths[1] <- 1
for(i in 2:nrow(df))
  for(x in 1:3)
    if((df$jolts[i] - x) %in% df$jolts)
      df$paths[i] <- df$paths[i] + df$paths[match(df$jolts[i] - x, df$jolts)]
format(df$paths[nrow(df) - 1], scientific=FALSE)
[1] "21156911906816"