# Advent of Code 2019-06 with R

December 5, 2019
By

[This article was first published on Colin Fay, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Solving Advent of Code 2019-06 with R (and no JavaScript this time).

[Disclaimer] Obviously, this post contains a big spoiler about Advent
of Code, as it gives solutions for solving day 6.

## Instructions

Find the instructions at: https://adventofcode.com/2019/day/6

## R solution

### Part one

``````library(magrittr)
library(igraph)
``````
``````##
## Attaching package: 'igraph'

## The following objects are masked from 'package:stats':
##
##     decompose, spectrum

## The following object is masked from 'package:base':
##
##     union
``````
``````ipt <- read.delim("input6.txt", header = FALSE, sep = ")", stringsAsFactor = FALSE)
grph <- ipt %>%
graph_from_data_frame()

grph %>%
distance_table() %>%
extract2("res") %>%
sum()
``````
``````## [1] 147807
``````

### Part two

``````distances(
grph,
v = V(grph)[["YOU"]],
to = V(grph)[["SAN"]]
) - 2
``````
``````##     SAN
## YOU 229
``````

## JS solution

Nop, no JS solution today… I didn’t feel like reimplementing igraph in
JavaScript, neither digging into the graph modules today 😉

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...