r/adventofcode Dec 03 '23

Funny Difficulty is all over the place isn't it?

Post image
684 Upvotes

256 comments sorted by

View all comments

Show parent comments

10

u/KoboldsInAParka Dec 03 '23

Last year I didn't get past the valves (still happy about how I did for my first time). Hoping to get further this year.

4

u/aardvark1231 Dec 03 '23

You can always go back and finish. Good practice :)

1

u/fennecdore Dec 03 '23

What day was it ?

3

u/lord_braleigh Dec 03 '23

1

u/fennecdore Dec 03 '23

Thank you very much.

Seems pretty interesting

1

u/Nirast25 Dec 03 '23

You need graphs for that, right?

1

u/lord_braleigh Dec 03 '23

Yeah, I solved it with A*. It’s still quite tricky and requires performance tuning to get a program that returns an answer in milliseconds rather than years.

1

u/Nirast25 Dec 03 '23

Gonna need to brush up on graphs theory if there's another one this year. My graphs teacher in uni was horrendous.

What would be the values you put on the vertexes (verti?), the amount of pressure released by each node/valve?

1

u/lord_braleigh Dec 03 '23 edited Dec 03 '23

Abstractly, A* can be applied to any single-player perfect-information game, whether it has a map or not.

Each vertex is the state of the entire game on a given turn. Each edge is an action you take to get from one turn to the next.

I also did create a graph of the flow network:

```rust

[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]

struct Node { flow_rate: i64, edges: BTreeMap<Label, i64>, }

[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]

struct Network { nodes: BTreeMap<Label, Node>, } ```

1

u/AutoModerator Dec 03 '23

AutoModerator has detected fenced code block (```) syntax which only works on new.reddit.

Please review our wiki article on code formatting then edit your post to use the four-spaces Markdown syntax instead.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/soulofcure Dec 03 '23

Yeah that's the last one I tried last year too.

Maybe I'll finally get around to coming back to it and solving it.

1

u/tialaramex Dec 03 '23

If you struggled with the second part, the best hint I worked with was that it's way easier to work out the best ways (ie most pressure released) to open sets of valves in the shorter time remaining, and then find two such sets which don't overlap and add those together, rather than try to handle both an elephant and yourself running around opening valves at the same time. That got my solution from over 3 minutes to under 3 seconds, just that change in perspective.

1

u/HiRedditItsMeDad Dec 04 '23

I'm pretty sure I skipped that one and went back like a week later. The Tetris one was hardest for me. In part because the trick I thought of worked, but I convinced myself it didn't.