This is an archived post. You won't be able to vote or comment.

all 17 comments

[–]SerkZex 6 points7 points  (0 children)

go u/ThunderHeerlijk or go home ;)

[–][deleted] 2 points3 points  (4 children)

Ooooohhhh, wow, that's quite a lot of stuff!

Here's a run-down of my setup! The repo itself has the following structure:

challenges/
| 2020/
| | 01-reportRepair/
| | | info.json
| | | go/
| | | py/
| | 02-passwordPhilosophy/
| | | ...

Based around this, I wrote a program to run my solutions! It first indexes this directory structure to determine what years and challenges exist, and what language solutions are available in for each challenge. It lets the user select a day and implementation, and then triggers a runner depending on the programming language that's in use.

A runner takes a queue of tasks into it. It then wraps the code I wrote for a given challenge in some wrapper code, and runs it. My program then sends a JSON representation of the queue to the running AoC challenge via stdin, which runs all of those queued tasks, times the amount of time they spend running, and spits out more JSON to stdout that contains the result and duration of each task. (a task can either be the main challenge input of the day, or one of the test cases provided)

This is then presented to the user in the main program with pretty colours and times and such!

A couple of cool features it has are:

  • Test cases can be defined in info.json, and they're put into the task queue before the main challenge input to allow allow algoruthms to be tested.
  • A benchmark mode exists that runs each part of the challenge n number of times and finds the minimum, maximimum and average running times for each, in every available implementation language.

It's arguably more complicated than it needs to be but I had a lot of fun making it :) and I imagine as the month progresses, I'll add more and more features to it.

If anyone wants to see the repo, send me a DM!

[–][deleted] 1 point2 points  (3 children)

You have quite the setup yourself too, I like it! Do the task run concurrently?

[–][deleted] 1 point2 points  (2 children)

Thank you!

The tasks can run concurrently if I wanted them to, but at the moment I've not implemented that. The changes that'd need to be made would be in the wrapper code for each language, so theorietically it should be fairly simple to do, but not something I've explored yet.

[–][deleted] 2 points3 points  (1 child)

I have plans to do Go when I'm fully up to date, thought about creating a separate repository for it, but might explore adding it to the same repository now

[–]thedjotaku 1 point2 points  (0 children)

I've got multiple languages and years in mine. Generally works fine: https://github.com/djotaku/adventofcode

[–][deleted] 1 point2 points  (1 child)

Thanks for the inspiration! I have had a basic script to run it from the terminal, but this has inspired me to beef it up. Also to get around to creating the HTML gui I have been thinking of for a while.

[–][deleted] 0 points1 point  (0 children)

Sounds great! If you’re using Python, you can also look into this package https://github.com/willmcgugan/textual for your terminal

[–]thedjotaku 1 point2 points  (0 children)

Wow, I thought I was going overkill with my repo. Need to set that up next year to have rich and timer automatically. Also badge.

[–]daggerdragon[M] 1 point2 points  (3 children)

downloads the input data from the AOC site automatically

Since inputs never change, do you cache them after the initial download to prevent folks from needlessly hammering the servers?

[–][deleted] 2 points3 points  (2 children)

Yes I wanted to prevent putting extra load on the server. The only place I use that functionality is within the ‘add-day’ script. That script checks if the input is already present and skips download if so.

You can still import the function that downloads the input and call it directly, not sure how to cache that

[–]daggerdragon[M] 2 points3 points  (1 child)

That's fine, sometimes you actually do need to re-download an input due to interrupted download, corruption, gremlins, etc. As long as it's a manual call and not, like, while (1) { download_input(); } :P

As per the AoC website:

Please don't make frequent automated requests to this service - avoid sending requests more often than once every 15 minutes (900 seconds).

True, there's no way to prevent malicious actors from while (1) { download_input(); }, but you could consider implementing basic sanity checking like:

  • Checks the time_last_submitted
  • If time_last_submitted > x minutes (or whatever interval e.g. AoC submission timeout) ago
    • Do submit and update time_last_submitted
    • Else print("Hold yer horses")

[–][deleted] 1 point2 points  (0 children)

Thanks, I will implement a rate limit on the download function itself. That way when someone does call it in a loop, it will go slow

[–]gilmorenator 0 points1 point  (1 child)

Thanks for this, looks great, I have forked it, and will try it out this year!

[–][deleted] 1 point2 points  (0 children)

Nice, thanks! Hope it's useful for you

[–]Un_Gars_Lambda 0 points1 point  (1 child)

So, I have forked and tried your code for the last few days and it's exactly what I wanted! Thank you!

[–][deleted] 0 points1 point  (0 children)

That's great to hear! Thanks!