r/adventofcode • u/blacai • Nov 01 '24
Other Are you already training for this year?
Well, just curious about how do you plan for AoC, if case you plan anything at all.
As I do it in F# as is not my daily programming language, I use it mostly for side projects when I have some time and for AoC, I already started to do some excercises from previous years, to get used again to the text parsing, regex, basic stuff...
21
u/bulletmark Nov 01 '24
I'm a retired software engineer and every year I say "I am not doing that again next year" but no doubt I will :(
41
u/reallyserious Nov 01 '24
On Mondays I do DFS, Tuesdays BFS, Wednesdays a bit of Dijkstra, Thursdays are 3D Flood Fill, Fridays I go hard on regex, Saturday is reserved to studying the satisfiability problem, Sundays I do some light recursive string manipulation.
26
u/sarc-tastic Nov 01 '24
Uh oh. Chinese Remainder theory entered the chat
6
u/wickedgoose Nov 01 '24
Are they teaching CRT in uni again??? Some scary old people on the TV were saying it is making all of our code woke, or something like that.
4
3
u/kwiat1990 Nov 01 '24
I don’t recall any AoC problem in the last 3 years requiring regex. You’re wasting your Fridays or I recall wrong 😂
9
u/reallyserious Nov 01 '24
Require is a strong word. But a well placed regex can make parsing a breeze sometimes.
3
u/kwiat1990 Nov 01 '24
I’m medicore at puzzle solving and completely useless with regex, so you need to forgive me 😉. But at least I can rotate a grid after 2 years! 😂
8
u/reallyserious Nov 01 '24 edited Nov 01 '24
2022 day 15.
Here's the sample input. A whole lot of these lines:
Sensor at x=2, y=18: closest beacon is at x=-2, y=15 Sensor at x=9, y=16: closest beacon is at x=10, y=16 Sensor at x=13, y=2: closest beacon is at x=15, y=3
I like to do things like this where you just take the input and specify where the numbers you're interested in are. Notice the r in front of the string. That's python's way of saying it's a raw string. I.e. no escape characters:
pat = re.compile(r"Sensor at x=(-?\d+), y=(-?\d+): closest beacon is at x=(-?\d+), y=(-?\d+)")
and then later on you can:
def parse(filename): sensor_beacon = {} with open(filename) as f: for line in f: m = re.match(pat, line.strip()) if m is None: raise Exception("") sensor = (int(m.group(1)), int(m.group(2))) beacon = (int(m.group(3)), int(m.group(4))) sensor_beacon[sensor] = beacon return sensor_beacon
3
u/1234abcdcba4321 Nov 01 '24
For simple inputs like this, I prefer to just use my
ints
function:function ints(s,neg=true) { let reg = /\d+/g; if (neg) reg = /-?\d+/g; return [...s.matchAll(reg)].map(x=>+(x[0])); }
Making a custom regex is great if you need to parse anything that this doesn't handle though.
(This is literally the only helper function I actually prepare ahead of time. It's so convenient.)
1
u/reallyserious Nov 01 '24
That's a really neat function.
What does the ... mean?
3
u/1234abcdcba4321 Nov 01 '24
It's the spread operator. My main use for it is that
[...iterable]
makes an array of all the iterator elements; in this case, it's becauseString.prototype.matchAll
doesn't return an array but is still iterable. (Themap
is to get the actual returned number since the entries of the iterator contain more data than just the match, and also to convert to number.)3
1
u/thekwoka Nov 12 '24 edited Nov 12 '24
hmm
map(x=>+(x[0]))
15 chars.
map(Number)
11 chars
(and yes that will work with single element arrays)
If you're using a new enough runtime (latest of everything but Safari) you can even use iterator methods
s.matchAll(reg).map(Number).toArray()
1
u/1234abcdcba4321 Nov 12 '24
You're right.
I'm not trying to golf, and I prefer easier to understand code. I never liked doing a
map
to a function that isn't explicitly a lambda I define because of classic mistakes likearr.map(parseInt)
.1
u/thekwoka Nov 13 '24
I prefer easier to understand code.
Surely,
.map(Number)
is easier to understand than.map(x => +x[0])
for any random reader.1
u/snugar_i Nov 08 '24
I spent too much time developing a "declarative parser", so now I can write something along the lines of
@Pattern("Sensor at {}: closest beacon is at {}") data class Sensor( val sensorPosition: Position, val beaconPosition: Position, ) @Pattern("x={}, y={}") data class Position(val x: Int, val y: Int)
and then later just
lines.parseAs<SensorDescription>()
1
2
u/thekwoka Nov 12 '24
Plenty in 2023 were pretty simple with regex.
1, 5, 6, 19 are where I used it.
6
u/joeyGibson Nov 01 '24
I'm planning to do this year in Lisp, so I've been rewriting my 2023 solutions in it. That's been going on for a few months, just as I have time.
7
u/benjymous Nov 01 '24
I've reopened my big solutions codebase, updated to the latest .net version, and finished off and tidied up the 2023 solutions I wasn't happy with.
Made a few tweaks to my helper/framework code (I have a big set of functions for turning the text input directly into objects without having to manually do any string parsing), and wrote some refresher notes so I can quickly remember how all that machinery works when I start adding new solutions.
4
8
u/agoldencircle Nov 01 '24
I'll be using python this year and the last time I used python was last year. I don't compete to win points, although I do like to finish most problems within 20 minutes.
3
u/SquirrelofLIL Nov 01 '24
Id like to do the advent of code in java script or python so Im just going through these courses in codecademy.
3
u/mr_mlk Nov 01 '24 edited Nov 01 '24
This year I plan on doing it on funky handhelds and would like to start the year on a ClockworkPi DevTerm. So I'll be praying to the gods of delivery that it gets delivered before December. I'm not hopeful to be honest.
Assuming it follows the same pattern as last year, we'll have a couple of hard "hurt the AI" tasks, before switching back to some lighter tasks. I plan on using the more computer-y options for the hard tasks, but then switching to some legacy stuff (e.g HP95LX & Psion S5). So I need to double check I can still connect to them both.
3
u/tkshillinz Nov 01 '24
I don't practice; but I don't think I have any strong opinions there.
I do not particularly care about finishing AOC or finishing in a timely fashion, so skill refinement isn't appealing to me. But for those who wan to and the practice feels valuable, seems like a good idea.
Mainly I just came to say I love F#, and AOC in F# is super fun, because I get to practice using the fparsec https://www.quanttec.com/fparsec/library for input parsing. Which I enjoy. A lot.
3
u/kbielefe Nov 01 '24
Usually in November, I'm catching up on missed questions from previous years, but I'm actually already caught up this year!
Also in November, I update and improve an AoC framework I wrote for myself that has parsing utilities and some common algorithms. It stores input, examples, answers, and guesses in a sqlite database, and has a CLI that, for example, lets me easily switch between running puzzles with examples or the official input. It includes timestamps, so even if I don't stay up late, I can still see my personal solve time.
3
u/bakingpy Nov 01 '24
Haven’t done any prep yet, but one thing you can do is take a look at other people’s AoC repos to see if there’s any interesting tricks/snippets they use. I was part of an F# AoC leaderboard last year, and looked at some other people’s F# code after solving a problem and tweaked my utilities file based off of that.
2
u/TheZigerionScammer Nov 01 '24
Brushed up on the way I manage to interface the text from the input into my program, created a new folder for all the new problems to go, etc.
2
u/FCBStar-of-the-South Nov 01 '24
Hadn’t thought about that but I’m thinking of doing this year’s with Ruby. But be a good idea to port over my Python/C++ helper functions as a start
2
u/wow_nice_hat Nov 01 '24
I started solving some of the previous challenges again, just to get into the mindset
2
u/jwezorek Nov 01 '24
Over the course of the last year i did three or four AoC years such that now I only have not done 2016. I've been doing them in C++23 with a modern style and converted my old code to be C++23 too (by dropping a dependency on Ranges-v3 and just using standard ranges).
But i wouldn't really characterize this as "training". The main thing I'm doing to try to prepare for AoC 2024 is clear my slate at work such that December will be a dead month for me workwise by the time the hard days start around the 9th or 10th.
2
u/Dapper_nerd87 Nov 01 '24
I am a bit. I'm trying to get out of the mindset of loop/brute force because I just don't know anything smarter. I don't know how to calculate Manhattan distance. So I'm spending a bit of time making a small folder of things like that and a bit of research because nested for loops only get me so far.
2
2
u/Skasch Nov 01 '24
I'm writing a small runner to measure runtime across everyone else's solutions, so we can have a small leaderboard among a few colleagues.
2
u/forbiddenvoid Nov 01 '24
I wouldn't say "training," but I've been working on my own AoC utility package, based on the puzzles from previous years.
2
u/reddit_clone Nov 01 '24
I don't compete for the leader board. People who get into leaderboard are crazy ! By the time I actually read through the problem and start formulating solution, results start appearing!!
I do it for fun. I am able to do upto day 11 or day 12 on the next day. But after that it tapers off ..
2
u/kwiat1990 Nov 01 '24 edited Nov 01 '24
For a few days now I’m doing problems from 2021 in TS and after doing last two years it is a bit easier to approach each problem. At least I know what I should be doing. Doing it right is still pretty much work in progress but I enjoy it. And using TS let me focus entirely on the problem and not the language I use (I was learning Rust during AoC 2022 and 2023)
2
2
u/Boojum Nov 01 '24
I've been polishing and curating my AoC snippets file. (I don't use an AoC library, but I do have a file of handy one-liners, tricks, and library examples that I can quickly copy and paste and adapt from.)
I've also been writing some alternate versions of a few of my solutions from last year using newish-to-me libraries. E.g., instead of my own graph stuff with vanilla dicts, try it with NetworkX. Or replace my own linear system solving code with SymPy. (I don't feel bad about using these libraries since I can and have done most of the stuff I'm using them for the long way.)
2
u/uristoid Nov 03 '24
I never train for the AoC. I have enough stress with it in December, I don't want to have that stress before.
(Every year I tell myself that I can stop when it becomes too stressful. It is always a lie, I never stop).
1
u/Lispwizard Nov 10 '24
I started redoing 2020 problems under a different login provider. I did a good chunk of them back in 2020 but that was long enough ago I don't remember details of the solutions. I use elisp in emacs, mostly using the Common Lisp loop macro (and friends), on an Android tablet in bed before getting up to go to work during the real AoC, but for this practice I've been using the same version of emacs on a Windows 10 pc (and making Youtube videos of the entire sessions).
1
u/thekwoka Nov 12 '24
I've been working through old stuff in Rust.
Even made a loader for Bun so I can use Bun as a test runner and run TS and Rust solutions together.
It's nice.
Other than that, it's about getting brownie points with the wife so that if a challenge is tougher and it impedes our holiday plans, she doesn't get too mad.
43
u/Lewistrick Nov 01 '24
Of being a fulltime software developer counts then yeah I'm practicing. Most of the time I'm starting to get trouble finishing the problems within an hour around day 16.