library(tidyverse)
library(BMS)
my_file <- here::here("2021", "data-2021-16.txt")
x <- readLines(my_file)
y = strsplit(x, "")2021 Day 16
— Day 16: Packet Decoder —
As you leave the cave and reach open waters, you receive a transmission from the Elves back on the ship.
The transmission was sent using the Buoyancy Interchange Transmission System (BITS), a method of packing numeric expressions into a binary sequence.
Decode the structure of your hexadecimal-encoded BITS transmission; what do you get if you add up the version numbers in all packets?
Loops with lots of rules? Wish me luck.
z = c()
for (e in y) {
z = c(z, hex2bin(as.character(e)))
}
z[1:100] [1] 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 0
[38] 0 0 0 1 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 1 1
[75] 1 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1
Paste part two here