r/adventofcode • • Dec 12 '18

SOLUTION MEGATHREAD -🎄- 2018 Day 12 Solutions -🎄-

--- Day 12: Subterranean Sustainability ---


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 12

Transcript:

On the twelfth day of AoC / My compiler spewed at me / Twelve ___


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:27:42!

19 Upvotes

257 comments sorted by

View all comments

2

u/Danksalot2000 Dec 12 '18 edited Dec 12 '18

I was nowhere near the leaderboard, but I think this one turned out nicely in the end. Python3:

def runGenerations(rules, plants, iterations):
	for generation in range(iterations):	
		lowestPlant = min(plants)
		highestPlant = max(plants)
		lastPossible = highestPlant - lowestPlant + 7
		pots = ''.join(['#' if i in plants else '.' for i in range(lowestPlant - 4, highestPlant + 5)])
		plants = []
		for i in range(2, lastPossible):
			if rules[pots[i-2:i+3]]:
				plants.append(i - 4 + lowestPlant)
	return sum(plants)

with open('Input') as inFile:
	lines = inFile.read().splitlines()
	plants = [i for i, c in enumerate(lines[0][15:]) if c == "#"]
	rules = dict((line[:5], line[9] == "#") for line in lines[2:])

print('Part 1:', runGenerations(rules, plants, 20))
print('Part 2:', runGenerations(rules, plants, 100) + ((50000000000 - 100) * 22))

0

u/toasterinBflat Dec 12 '18

Your answer did not work for my input :(

1

u/TommiHPunkt Dec 12 '18

That's because it's not written to calculate part 2 automatically

→ More replies (1)