2020-03: Toboggan Trajectory

library(stringr)
df <- read.csv("input2.csv")

Part 1

x <- 1
pounds <- ""
xVals <- c()

for(y in 1:323) {
  pounds <- paste(pounds, as.character(df[y, x]), sep = "")
  if(x + 3 > 31)
    x <- x + 3 - 31
  else
    x <- x + 3
  xVals <- append(xVals, as.character(x))
}

str_count(pounds, "#")
[1] 228

Part 2

over <- c(1, 3, 5, 7, 1)
down <- c(1, 1, 1, 1, 2)
running_total <- 1

for(z in 1:5) {
  x <- 1
  pounds <- ""

  for(y in seq(1, 323, by = down[z])) {
    pounds <- paste(pounds, as.character(df[y, x]), sep = "")
    if(x + over[z] > 31)
      x <- x + over[z] - 31
    else
      x <- x + over[z]
  }
  running_total <- running_total * str_count(pounds, "#")
}
running_total
[1] 6818112000