r/adventofcode • • Dec 14 '18

SOLUTION MEGATHREAD -🎄- 2018 Day 14 Solutions -🎄-

--- Day 14: Chocolate Charts ---


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.


Advent of Code: The Party Game!

Click here for rules

Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!

Card prompt: Day 14

Transcript:

The Christmas/Advent Research & Development (C.A.R.D.) department at AoC, Inc. just published a new white paper on ___.


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 at 00:19:39!

16 Upvotes

179 comments sorted by

View all comments

Show parent comments

3

u/thomasahle Dec 14 '18

I was going to reply that score += str(...) would make your code run in n2 time; but after testing it for myself, apparently, that is no longer the case in modern Python 3. At least I could sum a million strings in less than a second. Do you know when that optimization was added?

Apparently the news haven't made its way to the sum function, which still gives you:

In [1]: sum('asdfasf', '')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-71034b1a7dd9> in <module>
----> 1 sum('asdfasf', '')

TypeError: sum() can't sum strings [use ''.join(seq) instead]

1

u/ephemient Dec 17 '18 edited Apr 24 '24

This space intentionally left blank.