Advent of code Day 6

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)

Look for the most used per row


In [2]:
q1 <- paste(apply(data, 2, function(x) names(sort(table(x), decreasing = TRUE)[1])), collapse='')
q1


"qzedlxso"

Look for the least used per row


In [3]:
q2 <- paste(apply(data, 2, function(x) names(sort(table(x), decreasing = FALSE)[1])), collapse='')
q2


"ucmifjae"

Final Answers


In [4]:
paste("Q1 -- Code with most frequent char", q1, '\n')
paste("Q2 -- Code with least frequent char", q2, '\n')


"Q1 -- Code with most frequent char qzedlxso "
"Q2 -- Code with least frequent char ucmifjae "