AoC2020 Days 1-2 and Buckwheat Pancakes


As mentioned in the previous post, the Advent of Code 2020 started yesterday. As expected the first two days were quite simple (the challenges tend to ramp up pretty quickly though). Day 1 consisted on a bit of integer manipulation, while day 2 was about string manipulation. You can find my solutions in R in my code repository.

One interesting bit is that, as often, most of the code on those simple challenges is spent on input parsing. In this case, in day 2 challenge, the input had a form as follows:

1-2 a: ahgtnkjz
3-12 j: asjdladajsdsjdaslj

Obviously, given the inconsistent column separator, the easiest here was to use a tailored regex. So I whipped up that ol' function from the help file of ?regexpr that I remembered from an old StackOverflow answer of mine:

input <- readLines("input02.txt") <- function(res, result) {
  m <-, lapply(seq_along(res), function(i) {
    if(result[i] == -1) return("")
    st <- attr(result, "capture.start")[i, ]
    substring(res[i], st, st + attr(result, "capture.length")[i, ] - 1)
  colnames(m) <- attr(result, "capture.names")
parsed <- regexpr("^(?<lb>[0-9]+)-(?<ub>[0-9]+) (?<let>[a-z]+): (?<p>[a-z]+)$", input, perl=TRUE)
tab <-,parsed)
tab <-

What does is just a modification of regmatches that allows the capture of "named" group, PERL-style; i. e. it allows me to use that weird regex trick of (?<name>group). Once done and transformed into a data.frame, the columns are already named correctly and are instantly usable.

From my experience in the last 3 days, it tastes brilliant, either alone, or with some spicy sauce (sriracha) if in a savoury mood, or some Pflaumenmuss (if in a sweet mood).

In other news, I've been cooking buckwheat pancakes for breakfast/lunch recently, and I am quite happy with the result. To 100g of buckwheat flour, I added an egg, 20cL of milk, 10cL of water, salt, pepper and a bit of dill. Once whipped up to a flowing but thick mixture, a small laddleful of it is placed at the center of a very hot pan. When bubbles appeared on the surface, flip and let cook another 30s/1min.