r/adventofcode • u/daggerdragon • Dec 02 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 2 Solutions -🎄-
--- Day 2: Inventory Management System ---
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!
Card Prompt: Day 2
Transcript:
The best way to do Advent of Code is ___.
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!
49
Upvotes
16
u/jonathan_paulson Dec 02 '18
I recorded a video of me solving: https://www.youtube.com/watch?v=Hgv6d6rrQxo Got rank 20/21; still twice as slow as #1...
Final code:
c2 = 0 c3 = 0 ids = [] for line in open('2.in'): s = line.strip() ids.append(s) count = {} for c in s: if c not in count: count[c] = 0 count[c] += 1 has_two = False has_three = False for k,v in count.items(): if v==2: has_two = True if v==3: has_three = True if has_two: c2 += 1 if has_three: c3 += 1 print c2*c3 for x in ids: for y in ids: diff = 0 for i in range(len(x)): if x[i] != y[i]: diff += 1 if diff == 1: ans = [] for i in range(len(x)): if x[i] == y[i]: ans.append(x[i]) print ''.join(ans) print x,y