Attaching package: 'data.table'
The following objects are masked from 'package:dplyr':
between, first, last
The following object is masked from 'package:purrr':
transpose
library(compositions)
Welcome to compositions, a package for compositional data analysis.
Find an intro with "? compositions"
Attaching package: 'compositions'
The following objects are masked from 'package:stats':
anova, cor, cov, dist, var
The following objects are masked from 'package:base':
%*%, norm, scale, scale.default
Today was bad. I misread the instructions, forgot a bunch of basic functions, and so much more. I couldn’t get any of the base reading functions to read my input properly so I ended up with fread from data.table. I also haven’t been able to make any significant speed improvements from my initial solution.
I’m not sure why readLines wasn’t working last night but I also switched to str_split_fixed from stringr and it’s so much faster now.
Fastest solution
library(dplyr)# part 1dt <- stringr::str_split_fixed(readLines("input.txt"), pattern ="", n =12)dt <-data.frame(apply(dt, 2, as.integer))getModeMin <-function(x)return(ifelse(mean(x) > .5, 0, 1))getModeMax <-function(x)return(ifelse(mean(x) > .5, 1, 0))strtoi(paste(apply(dt, 2, getModeMax), collapse =""), base =2) *strtoi(paste(apply(dt, 2, getModeMin), collapse =""), base =2)