DEV Community

Colin Fay
Colin Fay

Posted on • Originally published at colinfay.me on

1

Advent of Code 2019-06 with R

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
Enter fullscreen mode Exit fullscreen mode

Part two

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

## SAN
## YOU 229
Enter fullscreen mode Exit fullscreen mode

JS solution

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

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more