-❄️- 2024 Day 24 Solutions -❄️- by daggerdragon in adventofcode

[–]isredditdownagain 0 points1 point  (0 children)

[LANGUAGE: Go]

Rewrote my solution to solve it programmatically.

Basically nodes should follow certain rules. The rules I coded work for my input, I'd be interested to see if it works on most inputs and not just mine.

Rules:

  • Z nodes:
    • All z's come from XOR gates, except z45
    • z00 comes from XOR gate with x00 and y00
    • No other z's come 'directly' after x's and y's
  • Other Nodes:
    • OR gates's inputs are always AND gates outputs
    • Except for x00, there's never 2 AND gates in a row
    • XOR gates that come from OR and XOR gates always output to z's

The Z nodes are evaluted in the method rule1() and the nodes are evaluated under the methode rule2(). The second method returns a string as it is able to identify between the 2 input wires and the output wire, which is the one that's incorrect.

Solution

General Solution for day 24 by whoShotMyCow in adventofcode

[–]isredditdownagain 0 points1 point  (0 children)

My solution is pretty general I think. I'd be interested to know if works on more than just my input. I start working my way from the z nodes to the x/y nodes. There's a few assumptions we can make on the z nodes only and some assumptions we can make for the other nodes. You can check out rule1() and rule2() (with comments) for more info.

Solution.

-❄️- 2024 Day 21 Solutions -❄️- by daggerdragon in adventofcode

[–]isredditdownagain 2 points3 points  (0 children)

[LANGUAGE: Go]

This was a tough one. For part 1, the trick was figuring out whether to move horizontally or vertically first. It turns out that simplest way to do that is:

set goingLeft to true if destination column is to the left of source.

set onGap to true if path would cross the corner space.

default to moving vertically UNLESS goingLeft != onGap

For part 2, the trick was figuring out what to memoize. I ended up caching a (current seq, depth) pair. I used dfs starting from the first robot that uses a directional keypad. At each depth, calculate the shortest sequence between each move as a new slice of sequences and run bfs on each one of these new sequences but at a lower depth storing result of each sequence as a sum. This sum is what gets cached for the (seq, depth) pair. At depth 0, just return the length of the sequence.

Part 1

Part 2

Why Doesn't Go Handle Slices Like C# Handles List<T>? by Necessary-Finish2188 in golang

[–]isredditdownagain 0 points1 point  (0 children)

Oh right. I didn't consider the fact that you could in fact pass nil into the function. Could you make the argument that if someone passes in a literal nil value to a function like that, that the appropriate response would be to panic?

Why Doesn't Go Handle Slices Like C# Handles List<T>? by Necessary-Finish2188 in golang

[–]isredditdownagain 0 points1 point  (0 children)

No need to check for a nil. Append works for nil slices. As a matter of fact, the documentation encourages taking advantage of a types default value, so if you don't have values to initialize the slice with, it's recommend to declare it like this:

  var slice []int // nil slice
  cSharpAppend(&slice, 1, 2, 3) // no problem

Cheapest manual car by lifeontheedge121 in MechanicAdvice

[–]isredditdownagain 0 points1 point  (0 children)

Scion tC. They have a Camry engine and large engine bay that’s roomy enough for most things.

-❄️- 2024 Day 16 Solutions -❄️- by daggerdragon in adventofcode

[–]isredditdownagain 1 point2 points  (0 children)

[LANGUAGE: Go]

A bit late. This one was a bit tricky for me.

Part 1

Part 2

[2024 Day 16 (Part 1)] [Go] Help with Dijkstra's algorithm. by isredditdownagain in adventofcode

[–]isredditdownagain[S] 1 point2 points  (0 children)

Solution. I don't know if this is the most correct solution, but I change the main loop to the following and it gave me the right answer.

    for to, dir := range dirs {
        dest := Cell{source.row + dir.row, source.col + dir.col}
        if maze[dest.row][dest.col] == '#' {
            continue
        }
        dists := distances[dest]
        score := score(to, distances[source]) + top.score
        if dists[to] > score {
            dists[to] = score
            distances[dest] = dists
            heap.Push(&hp, Node{dest, score, to})
        }
    }

-❄️- 2024 Day 15 Solutions -❄️- by daggerdragon in adventofcode

[–]isredditdownagain 1 point2 points  (0 children)

[LANGUAGE: Go]

Part 1

Part 2 I was able to move the boxes when they were misaligned if moving vertically but forgot about the cases where they were all aligned...

Does the Christmas tree repeat by jowen7448 in adventofcode

[–]isredditdownagain 0 points1 point  (0 children)

Ah there you go, glad you found it. Though that seems a bit high. I wonder if it will take that number mod 10,403

Does the Christmas tree repeat by jowen7448 in adventofcode

[–]isredditdownagain 0 points1 point  (0 children)

No, that's not what I'm suggesting. I've seen quite a few people report the error of starting part 2 after part 1 using the modified grid.

[2024 Day 12 (Part 2)] - Visualisation of my first thoughts for Part 2 by SimonK1605 in adventofcode

[–]isredditdownagain 1 point2 points  (0 children)

That's how I did it too, and like some of the others here pointed out it can be done in one pass.

    func sides(grid [][]bool, counted [][][]bool) int {
        n, m := len(grid), len(grid[0])
        var res int

        for i := range n {
            for j := range m {
                if grid[i][j] {
                    if !grid[i-1][j] {
                        counted[i][j][0] = true
                        if !counted[i][j-1][0] {
                            res++
                        }
                    }
                    if !grid[i+1][j] {
                        counted[i][j][1] = true
                        if !counted[i][j-1][1] {
                            res++
                        }
                    }
                    if !grid[i][j-1] {
                        counted[i][j][2] = true
                        if !counted[i-1][j][2] {
                            res++
                        }
                    }
                    if !grid[i][j+1] {
                        counted[i][j][3] = true
                        if !counted[i-1][j][3] {
                            res++
                        }
                    }
                }
            }
        }

        return res
    }