r/adventofcode • • Dec 06 '17

SOLUTION MEGATHREAD -πŸŽ„- 2017 Day 6 Solutions -πŸŽ„-

--- Day 6: Memory Reallocation ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Need a hint from the Hugely* Handy† Haversack‑ of HelpfulΒ§ HintsΒ€?

Spoiler


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

edit: Leaderboard capped, thread unlocked!

16 Upvotes

324 comments sorted by

View all comments

Show parent comment

1

u/KnorbenKnutsen Dec 06 '17

You can use the map function to handle your input a little cleaner:

args = list(map(int, "INPUT STRINGS HERE".split()))

Also, instead of copying the lists, I would append tuple(args) to previous. They're immutable, so you can trust that the comparison will be by value and not by reference (and they're hashable in case you'd want to use a dict or a set. Just some tips since you say you're learning Python :)

3

u/[deleted] Dec 06 '17

I tend to always use list comprehensions when I'm coding in python, they are really nice :)

args = [int(x) for x in "INPUT STRINGS HERE".split()]

2

u/PendragonDaGreat Dec 06 '17

Thanks for the pointers.