inst/run-day22.R

library(adventofcode17)
input <-
"....##.#.#.#...#.##.##.#.
##.####..###..#.#.#.###.#
.#.#...#.##....#......###
...#.....##.###....##.###
#.########.#.#####..##.#.
.#..#..#.#..#....##.#...#
.....#.##..#.#.....##..##
....###....###....###.#..
..#..#..#..#.##.#.#..##.#
.##......#...##.#.#.##.#.
.#####.#.#.##...###...#..
#..###..#....#....##..#..
###..#....#.##.##.....#..
##.##..#.##.#..#####.#.#.
#....#.######.#.#.#.##.#.
###.##.#.######.#..###.#.
#...###.#.#..##..####....
###...##.###..###..##..#.
..##.###...#.....##.##.##
..##..#.###.###.....#.###
#..###.##.#.###......####
#.#...#..##.###.....##.#.
#..#.##...##.##....#...#.
..#.#..#..#...##.#..###..
......###....#.....#....#"

grid <- input %>% read_text_lines() %>% virus_grid()
grid$step(10000)
stopifnot(grid$get_infect_count() == aoc17_solutions$day22a)

# Part B takes forever!
seriously <- FALSE
if (seriously) {
  grid <- input %>% read_text_lines() %>% evolved_virus_grid()
  left <- 10000000
  while (left > 0) {
    if (left %% 100000 == 0) message(left)
    grid$step(1000)
    left <- left - 1000
  }
  stopifnot(grid$get_infect_count() == aoc17_solutions$day22b)
}
tjmahr/adventofcode17 documentation built on May 30, 2019, 2:29 p.m.