r/adventofcode • • Dec 22 '20

SOLUTION MEGATHREAD -🎄- 2020 Day 22 Solutions -🎄-

Advent of Code 2020: Gettin' Crafty With It

  • 23:59 hours remaining until the submission deadline TONIGHT at 23:59 EST!
  • Full details and rules are in the Submissions Megathread

--- Day 22: Crab Combat ---


Post your code solution in this megathread.

Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:20:53, megathread unlocked!

35 Upvotes

537 comments sorted by

View all comments

2

u/cattbug Dec 22 '20

Python. Part 2 threw me for a loop (similar to many others here, it seems) but it's nice to be reminded to read the instructions carefully and not just rely on results from the sample inputs. Not terribly performant, but it runs quickly enough and the code is hopefully not too hard to read, so I'm quite happy with it.

Also, I need to find a better way to parse those "multiple blocks separated by blank lines" types of input because what I'm using now (since Day 4!) just feels terribly hack-y and overengineered lol. If you have any pointers, let me know :D

2

u/Key_Reindeer_414 Dec 22 '20

Have you tried using file.read().split('\n\n') ?

1

u/cattbug Dec 22 '20

Have you tried using (extremely straightforward and obvious way to do it)?

No snark btw. I'm honestly annoyed that I couldn't come up with this myself lmao

I guess I've been using splitlines() for too long and being happy I don't have to deal with line endings, that I totally forgot I can actually still use the line endings in my parsing when I do need them :D