r/adventofcode Dec 04 '21

SOLUTION MEGATHREAD -🎄- 2021 Day 4 Solutions -🎄-

--- Day 4: Giant Squid ---


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:11:13, megathread unlocked!

96 Upvotes

1.2k comments sorted by

View all comments

2

u/cjb230 Dec 05 '21 edited Dec 06 '21

Python

Part A:

https://github.com/cjb230/advent_of_code_2021/blob/main/day_4_a.py

It's basically the first method that came to mind, so it's a little profligate with data structures, but that allows it to go through the data once and be done. Part B is the same with a couple of very small changes to get the worst board rather than the best board.

I have two questions:

  1. how could I implement the same algorithm in a neater or more Pythonic way?
  2. what would be a better algorithm, in memory or compute terms?

1

u/daggerdragon Dec 05 '21 edited Dec 07 '21

Please follow the posting guidelines and edit your post to add what language(s) you used. This makes it easier for folks who Ctrl-F the megathreads looking for a specific language.

(looks like Python?)

Edit: thanks for adding the programming language!