LOADING: An error occurred. Update Chrome, try Firefox, or visit this post for more details.

⚠️Reddit changed how removals work, which breaks Reveddit's website. Install the extension to track removed content:Add to chromeAdd to firefoxWhat changed?
✖︎
about reveddit
⚙F.A.Q.add-ons
r/
status
copy sharelink
[+] show filters
48
SOLUTION MEGATHREAD-🎄- 2021 Day 11 Solutions -🎄-(self.adventofcode)
submitted 4 years, 1 month ago* (edited 1 hour, 2 minutes after) by daggerdragon to /r/adventofcode (134.8k)
826 commentsredditother-discussionssubreddit-indexmessage modsop-focus

NEW AND NOTEWORTHY

[Update @ 00:57]: Visualizations

  • Today's puzzle is going to generate...

... view full text

since 4 years, 1 month ago
9 of 9

Tip Reveddit Real-Time can notify you when your content is removed.

your account history
(check your username's removed content. why?)
Tip Check if your account has any removed comments.
view my removed comments
you are viewing a single comment's thread.
view all comments
[–]ViliamPucik9 points4 years, 1 month ago

Python 3 - Minimal readable solution for both parts [GitHub]

import sys

octopuses = {
    complex(row, col): int(number)
    for row, line in enumerate(sys.stdin.read().splitlines())
    for col, number in enumerate(line)
}

step, part1, part2 = 0, 0, None

while step := step + 1:
    flashing, flashed = set(), set()

    for o in octopuses.keys():
        octopuses[o] += 1
        if octopuses[o] > 9:
            flashing.add(o)

    while flashing:
        o = flashing.pop()
        octopuses[o] = 0
        flashed.add(o)

        for i in (
            -1 + 1j, -1j, +1 + 1j,
            -1,           +1,
            -1 - 1j, +1j, +1 - 1j
        ):
            if (x := o + i) in octopuses and x not in flashed:
                octopuses[x] += 1
                if octopuses[x] > 9:
                    flashing.add(x)

    if part2 is None and len(flashed) == len(octopuses):
        part2 = step

    if step <= 100:
        part1 += len(flashed)
    elif part2:
        break

print(part1)
print(part2)
permalinkhide replies (1)author-focusas-ofpreserve
[–][deleted]3 points4 years, 1 month ago
[removed] mod/auto

[removed] content loading...

(check your username's removed content. why?)
spin
permalinkparentcontexthide replies (3)as-ofmessage mods
[–]mstumpf2 points4 years, 1 month ago

Does it actually work reliably? (Aren't complex numbers in python floats? And floats as indices are prone to off-by-rounding equality issues)

permalinkparentcontexthide replies (1)author-focusas-ofpreserve
[–]roboputin2 points4 years, 1 month ago

Doubles can represent the same number of integers as a ~54-bit signed integer type. In other words, it sholud be fine.

permalinkparentcontexthide replies (1)author-focusas-ofpreserve
[–]mstumpf1 point4 years, 1 month ago* (edited 3 minutes after)

I'm not talking about the amount, I'm talking about the fact that `7/3/3/3*3*3*3` is not `7`, bit `6.9999999`. Rounding errors. You can't reliably do equality comparisons on floats.

permalinkparentcontexthide replies (1)author-focusas-ofpreserve
[–]roboputin1 point4 years, 1 month ago

Multiplication and addition of integers are exact (if the result is representable). Division should also work if the numbers are divisible.

permalinkparentcontexthide replies (1)author-focusas-ofpreserve
[–]mstumpf1 point4 years, 1 month ago

Yes you are right! My bad. Just re-read IEEE spec and you are absolutely right.
I think the numbers I had in my head are 0.1, 0.2, 0.3 and similar. Those are not representable by IEEE floats.
Great idea then! Nice thinking outside the box.

permalinkparentcontextauthor-focusas-ofpreserve
[–]SquintingSquire2 points4 years, 1 month ago

A dict with an (x,y) tuple as key is a nice way to represent a grid. I think it is more readable than complex numbers. Check out this solution from day 9.

permalinkparentcontextauthor-focusas-ofpreserve
[–][deleted]1 point4 years, 1 month ago

I'm not sure it actually saves any space or anything though? (At least the way it's used here.)

permalinkparentcontextas-of
r/revedditremoved.substack.com
🚨 NEWS 🚨
✖︎

Important: Reddit Changed How Removals Work

A recent Reddit update makes mod-removed content disappear from profile pages, which breaks Reveddit's website.

Install the browser extension to receive removal alerts.

Add to chromeAdd to firefox

What changed?

r/revedditremoved.substack.com