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!

20 Upvotes

257 comments sorted by

View all comments

0

u/[deleted] Dec 12 '18

[deleted] β€” view deleted comment

18

u/trwolfe13 Dec 12 '18

As a native English speaker, I also couldn’t understand the explanation.

I’ve completed a lot of the Advent of Code puzzles, and this is the first one I struggled with. They’re usually much more clear.

7

u/zirtec Dec 12 '18

I found this one easy to understand. In contrast, the one with the marbles and the repeating "x marbles left of marble y" was hard on the non-native speaker. YMMV.

→ More replies (1)

2

u/[deleted] Dec 13 '18

Yeah, honestly the diagrams made me doubt what I had read in the text. I decided to write code to process generations of plants but I don't care enough to follow up on why there are multiple 0s in the diagram.

→ More replies (1)

23

u/jorosp Dec 12 '18 edited Dec 12 '18

It took me way too long to realize that

Adding up all the numbers of plant-containing pots after the 20th generation produces 325.

After 20 generations, what is the sum of the numbers of all pots which contain a plant?

actually meant to add the indexes of the pots with plants, and not to eg. sum up the number of plant pots in each generation up to 20.

4

u/[deleted] Dec 12 '18

So what would the sum be for this?

###..#...##..............#...##...................................#.....#......#.#.........###.#.#.

Is it 877 (left one is index 0) or is it 841 (left one is index -2) or is it 823 (left is -3 as in the example)? I have read the problem description 5 times and still have no clue how I should number the pots.

​

0

u/[deleted] Dec 12 '18

[deleted] β€” view deleted comment

→ More replies (2)
→ More replies (1)

4

u/[deleted] Dec 12 '18

If I add the indices of my pots, my solution does not get accepted.

s = 0
for i,c in enumerate(pots):
    if c == "#":
        s += i
print(s)

Is this wrong?

6

u/branfili Dec 12 '18

pots can have negative indices

→ More replies (14)

2

u/lazyear Dec 12 '18

Same here. I would've shaved a couple minutes off my time.

1

u/randomwalker2016 Dec 17 '18

omg, thanks man. i couldn't get the number of plants to add up to 325. now adding up the indexes make sense. why couldn't this be more clear?

6

u/[deleted] Dec 12 '18

Finally solved it after 2 hours and 20 minutes with lots of help from here. I feel so stupid now

3

u/zirtec Dec 12 '18

Don't be. You learn. That's part of the fun. It will be 1 hour next time, then half and hour.

→ More replies (1)

3

u/nirgle Dec 13 '18

My only issue with Day 12 is the sample data is missing the => . notes so you don't have a usable test input, that's always really helpful to test your solution on

8

u/T_D_K Dec 12 '18

I can certainly sympathize that it might be hard to understand for those who are English-second-language speakers, but for this (and all previous puzzles) I feel like (as a native English speaker) they have been perfectly clear. In the couple problems where I wasn't immediately certain, a brief (attentive) re-read has cleared up any questions.

What I'm trying to say is that your English comprehension is the problem (or speed reading to try and solve quickly), not the actual language in the problem. Not trying to be judgmental, I know from experience that reading technical material in a foreign language is very difficult

10

u/SolsKing Dec 12 '18

Nah I'm a native speaker too and these problems give me a tough time

10

u/fatpollo Dec 12 '18

I'm a native english speaker too, and I feel like the descriptions are going way out of their way to express things in confusing ways.

I can deal with it fine, but to tell other people the descriptions are perfectly fine/easy seems borderline dishonest.

4

u/[deleted] Dec 12 '18

Same here. I still have no solution because I do not know how my resulting string should be numbered. It seems very random to me that the example starts with -3 to the left.

Also it is unclear how many rules can be applied in each generation.
If only one: How to chose?
If more than one: Do all rules of generaion n+1 have to be applied to the result of generation n or to the previous result of the current generation?

It is embarrasing that I still have nothing for part 1 because I just don't get the problem.

5

u/T_D_K Dec 12 '18

From the problem text:

The pots are numbered, with 0 in front of you. To the left, the pots are numbered -1, -2, -3, and so on; to the right, 1, 2, 3.... Your puzzle input contains a list of pots from 0 to the right

He added padding on the left because some of the displayed iterations have pots down to -2 filled.

Also it is unclear how many rules can be applied in each generation.

This problem is an example of cellular automata. A famous example is Conway's game of life. Generally, they apply the rule set to each cell simultaneously (otherwise, like you pointed out, it would be difficult to decide where to start, as it would have a ripple effect on the other cells.

6

u/alexmeli Dec 12 '18

Yeah I'm still trying to figure out the problem myself. I've read it like 20 times already but I still don't get it. I mean I get part of it but how do you determine which pot is at the center after each generation?

→ More replies (1)

3

u/Dosamer Dec 12 '18

Do all rules of generation n+1 have to be applied to the result of generation n

yes

3

u/ButItMightJustWork Dec 12 '18

I try to explain it (am on mobile though)

Your first character in the initial state is pot 0. For each new step you also have two consider two (yet not existing) pots to the left. (non existing pots default to empty, i.e. '.').

Lets say your initial state starts with "##.##.##.". So, now you would compute if the pot at position -2 (two to the left) should have a pot in the next iteration: "....#" -> ?.

You also do this for the pot at position -1 ("...##" -> ?). Then you check pots 0 ("..##."), 1 (.##.#), ..., n. Afterwards also n+1 and n+2.

In this new state your pot 0 shifted to idx 2 (because idx 0 is pot -2). So you would need to keep track at what index pot 0 ist.

At the end, you sum everything up. If there is a pot at position -2, you substract 2 from the sum. If there is one in pot position 4 (NOT index 4), then add 4 to the sum.

Hope this helps, I'm on mobile so i cant give you nice ascii art for a clearer description.

→ More replies (1)

1

u/niclas0219 Dec 12 '18 edited Dec 12 '18

I struggled for a long time and first wrote a solution using strings and trying to keep track of the "middle" char in a group of five. I couldnt figure out the negative indexes either so I scratched all of it and redid it as an array of chars. I let the initial seed start at index 100 of this array so that it could grow as it pleased. Any pots below index 100 are in the negative area. So something like this for populating the array at first:

char[] pots = new char[500];
Arrays.fill(pots, 0, pots.length, '.');
    for (int i = 0; i < initialseed.length; i++) {
        pots[100 + i] = initialseed[i];
    }

After that i looped everything for 'n' generations

Making sure that all the changes was made in a temporary array. After the for-loop i save my changes in pots and reiterate.

int cycle = 0;
    char[] temp = pots.clone();
    while (cycle < 20) {
        for (int i = 2; i < pots.length - 2; i++) {
           char pot = match(pots[i - 2], pots[i - 1], pots[i], pots[i + 1], pots[i + 2]);
           temp[i] = pot;
           }
            pots = temp.clone();
            Arrays.fill(temp, 0, temp.length, '.'); // my input worked without this line
                                                    // don't know if that was just lucky
    cycle++;
}

My method match() takes five chars and returns either # or . according to the rules.

Anyways.. it was the "starting at 100" that helped me solve it. My string solution was pretty much the same but didn't calculate the points correctly.

1

u/zirtec Dec 12 '18

It's easy if you've played Conway's game of life before (although there's a variable set of rules here instead of a small fixed set in the original). Otherwise yes, it's not obvious all transitions occur at the same time, or even that using array indices to identify plants won't go well.

1

u/Matvalicious Dec 17 '18

Agreed. I've been fucking around with Part 1 for nearly three hours now and I can't even get Generation 1 right from the example. I am DEFINITELY misinterpreting the rules but I have no clue what it's supposed to be then.

For example:

 0: ...#..#.#..##......###...###...........
 1: ...#...#....#.....#..#..#..#...........

Pot 4 matches the rule ".#.#. => #"

So, according to what I understand from the explanation, the middle pot will be replace. Resulting in ".###." Yet for some obscure reason, in the next generation this results in "..#.." and I haven't got a single clue why.

→ More replies (2)
→ More replies (1)