Look for the most/Least used Char in the messages Ref: http://adventofcode.com/2016/day/6
In [1]:
#Create the Matrix of char
data <- matrix(unlist(strsplit(readLines("data.txt"),"")),ncol=8,byrow=TRUE)
In [2]:
q1 <- paste(apply(data, 2, function(x) names(sort(table(x), decreasing = TRUE)[1])), collapse='')
q1
In [3]:
q2 <- paste(apply(data, 2, function(x) names(sort(table(x), decreasing = FALSE)[1])), collapse='')
q2
In [4]:
paste("Q1 -- Code with most frequent char", q1, '\n')
paste("Q2 -- Code with least frequent char", q2, '\n')