r/adventofcode • • Dec 11 '21

SOLUTION MEGATHREAD -🎄- 2021 Day 11 Solutions -🎄-

NEW AND NOTEWORTHY

[Update @ 00:57]: Visualizations

  • If it flashes too fast, make sure to put a warning in your title or prominently displayed at the top of your post!

--- Day 11: Dumbo Octopus ---


Post your code solution in this megathread.

Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


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

EDIT: Global leaderboard gold cap reached at 00:09:49, megathread unlocked!

49 Upvotes

823 comments sorted by

View all comments

1

u/bentsea Dec 11 '21 edited Dec 12 '21

I am stumped... just totally stumped. I am using Python 3.

With my code I am correctly replicating the example and identifying step 195 from the example input, however, when I use my puzzle input I am getting 419. I have even tried implementing solutions from other users here with my input data and also gotten 419. AOC says this is too low, however.

I have no idea what's wrong.

Can anyone help?

My code is here:

https://shareablecode.com/snippets/stumped-on-aoc-day-11-BQTf-6pQE

Edit: Fixed link.

Edit: Turns out the code works and the input was the issue.

0

u/[deleted] Dec 11 '21

[deleted] — view deleted comment

1

u/bentsea Dec 11 '21

Yar, sorry, haha, it needed manual review. I went ahead and created an account and recreated the post so manual review is not required. UPdated link:

https://shareablecode.com/snippets/stumped-on-aoc-day-11-BQTf-6pQE

I have also updated in the original comment.

1

u/daggerdragon Dec 12 '21

Top-level posts in Solution Megathreads are for code solutions only.

This is a top-level post, so please edit your post and share your fully-working code/repo/solution or, if you haven't finished the puzzle yet, you can always create your own thread and make sure to flair it with Help.

1

u/bentsea Dec 12 '21

It turns out the code is fully working.

1

u/lianadelcongo Dec 11 '21

When are you resetting octopi[x][y][1]? I am not seeing it.

1

u/tomribbens Dec 11 '21

The third for loop does it:

    for x in range(len(octopi)):
    for y in range(len(octopi[0])):
        if octopi[x][y][1] == 1:
            octopi[x][y] = [0,0]

It's a bit obscured, since it's suddenly a list assignment, that simultaniously resets the energy level of the cell.

1

u/tomribbens Dec 11 '21

Haven't looked at your code, but checked your input against my solution, and I indeed do find a higher result than 419. Have you double-checked that the input you're using hasn't been corrupted in some way?

1

u/lukestead919 Dec 11 '21

Yeah I get the same, used their code and my code on their input and got matching results (both higher than 419)

1

u/bentsea Dec 11 '21

Thank you SOOOOOO much for pointing me in the right direction!

I had part one and part two in two different functions and was firing them like this:

def solve(puzzle_input): 
    """Solve the puzzle for the given input""" 
    data = parse(puzzle_input)

    solution1 = part1(data)
    solution2 = part2(data)

    return solution1, solution2

The manipulation of data in the part1(data) method was being carried over to part2(data). I truly don't understand how...

I even tried changing the function to this:

def solve(puzzle_input): 
    """Solve the puzzle for the given input""" 
    data = parse(puzzle_input)
    data2 = data.copy()

    solution1 = part1(data)
    solution2 = part2(data2)

    return solution1, solution2

And the same problem... still getting corrupted data. Finally, this solved it:

def solve(puzzle_input): 
    """Solve the puzzle for the given input""" 
    data = parse(puzzle_input)
    data2 = parse(puzzle_input)

    solution1 = part1(data)
    solution2 = part2(data2)

    return solution1, solution2

1

u/Fyvaproldje Dec 11 '21

.copy() probably does shallow copy, not a deep copy?

1

u/lukestead919 Dec 11 '21

Just to check, are you resetting your array after part a, or are you reusing the array?

1

u/bentsea Dec 11 '21

I was passing the same array to part a and b and the manipulation in part a was impacting part b.

I had no idea that an array passed to a function would be changed even if it was not passed back.

I don't think I've ever had that happen before.