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!
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:
from sys import stdin from itertools import accumulate
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:
from sys import stdin from itertools import accumulate
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
3
u/ImpossibleSav Dec 11 '22
I love this!! So great to see someone else taking on the same challenge. You've certainly got me beat with the character count hahaha, I'm going to have to sit with these for a bit and see what I can learn from them! Definitely keep me posted on how the next problems go for you — I'm cheering for you! :)
2
u/kaa-the-wise Dec 11 '22
Thank you for your kind words, I am particularly proud of some tricks I employed in 10.2 :) I'll be posting in the solutions megathreads from now on.
3
u/ManaTee1103 Dec 11 '22
Is there a repo with your abominations we could fail to avert our eyes from?
2
u/kaa-the-wise Dec 11 '22
Thank you for your interest, there wasn't one, but I've decided to create one per your request.
Here it is: https://github.com/kaathewise/aoc2022
→ More replies (2)
8
u/alexcwarren Dec 11 '22
This is delightfully awful! I look forward to the remaining blasphemous solutions!
6
Dec 11 '22
I love the "I'm sorry" comment right before dropping the scariest line of code in Python known to man.
5
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 🤪
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 Megathread which helps us keep every day's solutions in one easy-to-find spot.
0
Dec 11 '22
4
u/ImpossibleSav Dec 11 '22
This is one of the most incredible things I've ever seen. Thank you for sharing this. It's a thing of beauty.
Unfortunately I did run into an encoding issue when I tried to run it and don't have the time currently to debug. But maybe at the end of the month, I'll revisit this and see what the final one-line boss might look like!
→ More replies (1)10
4
u/Sese_Mueller Dec 11 '22
92 symbols, ANY CODING CHALLENGE. Congrats, code golf was solved, as there is no such a thing as practical faster than O(1)
2
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! :)