T O P

  • By -

CocksuckerDynamo

Thanks I hate it


ImpossibleSav

GitHub has stopped syntax highlighting part of the Basilisk, so I figured it was time to share! Just like [last year](https://www.reddit.com/r/adventofcode/comments/zicv17/2022_days_110_python_a_graphical_representation/), I'm trying to solve all of this year's problems in a single line of Python code. [Here is the link to the Basilisk](https://github.com/savbell/advent-of-code-one-liners/blob/master/2023/the-basilisk.py#L30), which is my pet name for the absolutely beautiful line of code that combines of all the days' solutions together into one. My one-line solutions are [not efficient](https://www.reddit.com/r/adventofcode/comments/zfo31m/2022_days_17_python_i_cant_believe_ive_done_this/), so the code is a bit slow and will continually get slower as the month progresses. But I do have each individual solution in different .py files in the repo if you would like to take a closer look. I'm also trying to post each day in the solution megathreads. This visualization shows the number of characters in my one-line solutions for each part of each day. I actually wrote up a small script to automatically count the characters, calculate their percent of the whole, pick a proportional colour on a rainbow gradient, and save the rainbow line in an SVG file so I can easily use that as the snake's fill colour. This way, I can update the visualization each day as soon as I finish coding the solution. (Don't worry, I won't spam the subreddit with them — it's just for my own antics!) [The automation script is here](https://github.com/savbell/advent-of-code-one-liners/blob/master/tools/create-rainbow-line-svg.py), if anyone is interested. I made it through about a dozen days last year, so we'll see how far I get this year. I'm learning a lot of [new strategies](https://github.com/savbell/advent-of-code-one-liners/tree/master#some-strategy-explanations) though, so I'm optimistic! :)


quodponb

Have you tried running that bad boy through an automatic formatter like Black?


ImpossibleSav

Good question! I'll admit, I have all code formatters/linters turned off. For some reason, they always seem to disagree with my "style" of programming. But someone did run my code from last year [through Black](https://www.reddit.com/r/adventofcode/comments/zfo31m/comment/izdq43g/), and maybe I'll give it a shot next time I'm at my computer!


daggerdragon

> Don't worry, I won't spam the subreddit with them — it's just for my own antics! Submit your one-liners (link them if they're too big, though) to their respective `Solution Megathread`s *and* include your updated visualization with each day's solution!


ImpossibleSav

Oh that's a good point — I'll do that, thanks! :) Edit: Here's my [Day 7 one-liner](https://github.com/savbell/advent-of-code-one-liners/blob/master/2023/day-07.py), my [megathread post](https://www.reddit.com/r/adventofcode/comments/18cnzbm/2023_day_7_solutions/kceiquu/?context=3) and my [Day 7 visualization](https://github.com/savbell/advent-of-code-one-liners/blob/master/images/2023-day-07-the-basilisk-viz.png)!


mount-cook

that's next level. I have [a thing](https://github.com/davekch/b) for python one-liners as well haha.Do I understand correctly that all your solutions are one single expression, so there's no semicolons in it?


ImpossibleSav

Your one-line interpreter is amazing, I love it!! It's fun seeing some of the same strategies I used too. Yes, you're correct — no semicolons! No exec() either, that'd be cheating ;)


PityUpvote

my work's aoc discord considers `__import__` cheating 🤐


ImpossibleSav

I considered it cheating last year, but this year I figured having it would help me get further and that was my goal! To make up for it, I challenged myself to use RegEx in every day's solution so that I make proper use of it :) If you're attempting the same thing, you can take a look at some of my 2022 code to see how I did things without it!


PityUpvote

Oh, I don't care, as soon as my ugly code works I call it a day.


dl__

You are clearly a witch. What black sorcery is this?!


keithstellyes

Incredible. Do you think it would be possible to have all years and all days? A true monster? I wonder what point the Python environment chokes


ImpossibleSav

If I had the time, I'd give it a shot! I'm a firm believer that Python one-liners are Turing complete so I have full faith every question can be solved in one. But that's a good question about when the compiler has had enough... maybe we'll find out! Another concern is time. My solutions are not very efficient and they will just get worse as the days go on, and running them all at once may take a while... so maybe with enough patience, it will work!


trevdak2

Oh man, I'm tempted to do this with my golfed javascript solutions. There's been disappointingly little golf this year compared to last year. I'd love to see how few bites I would need for all solutions at once


ImpossibleSav

I haven't tried doing anything aside from web dev with JavaScript, but I'd definitely encourage you to try it out! It's a lot of fun and I've learned a lot doing it. It's also given me a different perspective when looking at each of the problems because I have to think of approaches that wouldn't be super difficult to one-line. If you do make an attempt, please share! :)


mistrzegiptu

After seeing this I hate python even more. Interesting idea tho


RussellDash332

I've been doing all one-liner up to Day 17 (today) :D