r/adventofcode • u/ImpossibleSav • Dec 11 '22
Visualization [2022 Days 1-10] [Python] A graphical representation of The Beast, a single line of code that solves every day's challenge so far!
230
Upvotes
54
u/ImpossibleSav Dec 11 '22
As a personal challenge, I'm trying to solve every Advent of Code problem in a single line of Python code. I'm proud to say I've been successful for all of them so far! I've been combining them all into a single, absolutely blasphemous line of code I've affectionately called The Beast. I thought it would be fun to visualize this monstrosity, so I made this graphic that shows how many characters in The Beast are used for each day/part! If you want to follow along, I've been posting my progress on my GitHub repo.
Fair warning: This code is disgusting. It's the worst thing I've ever written and probably ever will. But I'm having a lot of fun with it and honestly learning a lot! If I have the time, I'm considering doing a write-up for the MisTILtoe Elf-ucation event explaining some of what's going on. But we'll have to wait and see how long I can keep this up! :)
5
u/kaa-the-wise Dec 11 '22 edited Dec 11 '22
I am writing python one-liners for this year too, but my rules are slightly different: the code has to be a single expression apart from imports. Here's my solution for 10.2, for example:
print(*('\n'[i%40:]+'.#'[-2<i%40-r<2] for i,r in enumerate(accumulate(stdin.read().split(),lambda r,c:r+(not c.isalpha() and int(c)),initial=1))))and here is 9.2:
print(len(set(map((lambda t:t[-1]), accumulate((l[0] for l in stdin.readlines() for _ in range(int(l[2:]))),(lambda t,p:[*accumulate(t[1:],(lambda a,b: ((d:=a-b),b+(abs(d)>=2)*((d.real>0)-(d.real<0)+1j*((d.imag>0)-(d.imag<0))))[1]),initial=t[0]+{'R':1,'L':-1,'U':1j,'D':-1j}[p])]),initial=[0]*10)))))UPD here is the repo that will contain all my solutions: https://github.com/kaathewise/aoc2022
8
u/alexcwarren Dec 11 '22
This is delightfully awful! I look forward to the remaining blasphemous solutions!
6
u/[deleted] Dec 11 '22
I love the "I'm sorry" comment right before dropping the scariest line of code in Python known to man.
5
u/fred256 Dec 11 '22
They're actually surprisingly readable (especially the earlier days).
2
u/ManaTee1103 Dec 11 '22
The later solutions are almost evolving into a new programming language, with recurring idioms and design patterns. After looking at one long enough, the others start to feel borderline readable.
2
u/hnost Dec 11 '22 edited Dec 11 '22
Cool!
I do golfing this year (haven't done day 11 in golf yet), have a look of you like ugly code 🤪
https://github.com/hildenost/advent-of-code/tree/main/2022
1
u/morgoth1145 Jan 05 '23
Out of curiosity, have you made any progress past day 14? I need more Python abuse in my life!
1
u/daggerdragon Dec 11 '22
If you haven't done so already, consider posting your solutions in the relevant
Solution Megathreadwhich helps us keep every day's solutions in one easy-to-find spot.0
u/[deleted] Dec 11 '22
[deleted] — view deleted comment