-
-
-
-
-
day 10 takes under a second, which I think I'm happy enough with. Didn't even need to specify an extra large stack size.
-
-
-
My day 8 part 2 takes 2m40s
-
day 6 didn't seem so bad
local seqlen = 14; local uniq(arr) = std.length(arr) == std.length(std.set(arr)); local findfirst(arr, x) = std.find(x, arr)[0]; local finduniqseq(arr, len) = [ uniq(arr[offset:offset + len]) for offset in std.range(0, std.length(arr) - len) ]; findfirst(finduniqseq(importstr 'input', seqlen), true) + seqlenNot very performant (it computes uniqueness over the whole input, then finds the first occurrence)
-
Just tidied up my day 4 solution. for-comprehension-tastic.
local input = std.rstripChars(importstr 'input', '\n'); local is_pair_overlapping(pairs) = local p1_l = pairs[0][0]; local p1_r = pairs[0][1]; local p2_l = pairs[1][0]; local p2_r = pairs[1][1]; (p1_l <= p2_r && p1_r >= p2_l) || (p2_l <= p1_r && p2_r >= p1_l) ; std.length(std.filter(is_pair_overlapping, [ [ [ std.parseInt(x) for x in std.split(range, '-') ] for range in std.split(line, ',') ] for line in std.split(input, '\n') ])) -
local uniq = function(arr) std.length(arr) == std.length(std.set(arr)); local finduniqseq = function(arr, n) [ uniq(arr[offset:offset + n]) for offset in std.range(0, std.length(arr) - n) ]; std.find(true, finduniqseq(std.rstripChars(importstr 'input', '\n'), 14))[0] + 14Always nice when solving part 2 involves changing a couple of numbers
-
-
-
jsonnet still, day 5:
local input = std.rstripChars(importstr 'input', '\n'); local lines = std.split(input, '\n'); local is_not_space = function(x) x != ' '; local parsemove = function(move) local words = std.split(move, ' '); { from: words[3], to: words[5], qty: std.parseInt(words[1]), }; local stack = { items: [], pop:: function(x) local s = self; { values: s.items[0:x], stack: s { items: s.items[x:], }, }, push:: function(x) local curr = self.items; self { items: x + curr, }, }; { moves: [ parsemove(line) for line in lines if std.length(line) > 0 && line[0] == 'm' ], stacks: local rows = [ line for line in lines if std.length(line) > 0 && line[0] != 'm' ]; local n_rows = std.length(rows); { [std.toString(col + 1)]: stack { items: std.filter(is_not_space, [ row[col * 4 + 1] for row in rows[0:n_rows - 1] ]), } for col in std.range(0, std.length(rows[n_rows - 1]) / 4) }, move(qty, from, to):: local src = self.stacks[from].pop(qty); local dest = self.stacks[to].push(src.values); self { stacks+: { [from]: src.stack, [to]: dest, }, }, do_moves():: std.foldl(function(acc, m) acc.move(m.qty, m.from, m.to), self.moves, self), get_message:: function() std.join('', [self.stacks[stack].pop(1).values[0] for stack in std.set(std.objectFields(self.stacks))]), }.do_moves().get_message() -
Parser wasn't too bad, logic is going to be a pain for me: https://github.com/rhowe/aoc/blob/main/2022/05-supply-stacks/05part1.jsonnet
(logic not implemented at time of posting)
-
-
I mostly used emoji for day 2
I guess you could say it's Advent of Unicode
-
-
Day 4 getting us looking forward to geometry (which I do not look forward to)
local input = std.rstripChars(importstr 'input', '\n'); local sum = function(a, b) a + b; local sumarray = function(arr) std.foldl(sum, arr, 0); local splitlines = function(str) std.split(str, '\n'); local splitcsv = function(str) std.split(str, ','); local splitrange = function(str) std.map(std.parseInt, std.split(str, '-')); local is_pair_overlapping(pairs) = local p1_l = pairs[0][0]; local p1_r = pairs[0][1]; local p2_l = pairs[1][0]; local p2_r = pairs[1][1]; (p1_l <= p2_r && p1_r >= p2_l) || (p2_l <= p1_r && p2_r >= p1_l) ; std.length(std.filter(is_pair_overlapping, std.map(function(line) std.map(splitrange, splitcsv(line)), splitlines(input)))) -
-
Here we go again, day 1 in jsonnet: https://github.com/rhowe/aoc/tree/main/2022/01
-
-
Didn't realise they allowed pornography on YouTube