Advent of Code 2021- Day 8

Aloha, the submarine is broken. At least our seven digit display.

raw_data <- readLines(con = "day_eight_one")
## Warning in readLines(con = "day_eight_one"): unvollständige letzte Zeile in
## 'day_eight_one' gefunden
raw_data <- strsplit(raw_data, split = "[|]")

Part 1:

output_signals <- lapply(raw_data, function(x) {
  unlist(strsplit(x[2], split = " "))[-1]
})

# 1, 4, 7, 8 signals

count_chars <- lapply(output_signals, function(x){
  sum(nchar(x) %in% c(2, 3, 4, 7))
  
})

(answer <- sum(unlist(count_chars)))
## [1] 504

Part 2:

To be updatet

Avatar
Moritz Mueller-Navarra

A Data Scientist using R

Related