I’ve never taken part in #AdventOfCode before, but I’ve been doing it this year after some colleagues mentioned it. It’s a fun way to start the day, if you like that sort of thing. (I.e. easy coding exercises; though I think maybe they’ll get harder later on?)
I wish it were released at a less antisocial hour so I could play the competitive aspect of it more easily. This morning I happened to be awake at 5, and made it onto the day’s leaderboard for the first time.
I’m just hoping I don’t get so competitive about it that I have to start getting up at 5 every morning between now and Christmas. That would be bad.
I’ve realised that all my solutions so far are either short enough to fit in a tweet, or can be made short enough with a bit of rewriting. Would it be interesting if I were to tweet them?
Okay, I’ll post ’em. They’re mostly in Python so far, except one that uses Sage and one that uses Perl. I’ll post them a day late, to make it a bit less spoilery, but obviously – SPOILER ALERT – don’t read on if you’re more than a day behind.
Ah, it turns out that Twitter lets you use tabs in your tweets, but then strips them out – or at least doesn’t display them.

I’ll change the tabs to spaces, and try again.
#AdventOfCode day 1

import math

nums = {*map(int,open("input"))}
co_nums = { 2020 - x for x in nums }
sums = { a+b for a in nums for b in nums if a < b }

print(math․prod(nums & co_nums))

print(*{
a * b * (2020-a-b)
for a in nums for b in nums
if a+b in (co_nums & sums)
})
(I had to turn the . in http://math.prod  into a U+2024 ONE DOT LEADER to stop Twitter from treating it as a link, so if you copy and paste this code it won’t work unless you change it back. Sorry about that.)
#AdventOfCode day 2, both parts

import re

def v(s):
a,b,c,d=re.match(r"(.+)-(.+) (.):( .+)",s).groups()
return (
int(a)<=d.count(c)<=int(b),
(d[int(a)]==c)!=(d[int(b)]==c)
)

D=[*open("input")]

print(len([x for x in D if v(x)[0]]))
print(len([x for x in D if v(x)[1]]))
#AdventOfCode day 3, part 1

arr = [
[c == "#" for c in line.strip()]
for line in open("input")
]

print([
row[y*3 % len(row)]
for y, row in enumerate(arr)
].count(True))
#AdventOfCode day 3, part 2

import math

arr = [
[c == "#" for c in line.strip()]
for line in open("input")
]

def c(dx, dy):
return [
row[i*dx % len(row)] for i, row in enumerate(arr[::dy])
].count(True)

print(math․prod(
c(1,1), c(3,1), c(5,1), c(7,1), c(1,2)
))
You can follow @robinhouston.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.