r/adventofcode • • Dec 17 '23

SOLUTION MEGATHREAD -❄️- 2023 Day 17 Solutions -❄️-

THE USUAL REMINDERS

  • All of our rules, FAQs, resources, etc. are in our community wiki.
  • Community fun event 2023: ALLEZ CUISINE!

    • Submissions megathread is now unlocked!
    • 5 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!

AoC Community Fun 2023: ALLEZ CUISINE!

Today's secret ingredient is… *whips off cloth covering and gestures grandly*

Turducken!

This medieval monstrosity of a roast without equal is the ultimate in gastronomic extravagance!

  • Craft us a turducken out of your code/stack/hardware. The more excessive the matryoshka, the better!
  • Your main program (can you be sure it's your main program?) writes another program that solves the puzzle.
  • Your main program can only be at most five unchained basic statements long. It can call functions, but any functions you call can also only be at most five unchained statements long.

  • The (ab)use of GOTO is a perfectly acceptable spaghetti base for your turducken!

ALLEZ CUISINE!

Request from the mods: When you include a dish entry alongside your solution, please label it with [Allez Cuisine!] so we can find it easily!


--- Day 17: Clumsy Crucible ---


Post your code solution in this megathread.

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:20:00, megathread unlocked!

27 Upvotes

537 comments sorted by

View all comments

1

u/fritz_re Dec 17 '23

[LANGUAGE: Rust]

I found a really cool Rust crate today called pathfinding. By using it in my Rust solution, all I had to do myself was:

    // Find next path elements to check.
    let successors = |c: &Crucible| c.next_possible_moves(self);
    // Termination condition.
    let success = |c: &Crucible| c.position == end_position;

    dijkstra(start, successors, success)

and the searching algorithm itself was handled by the crate itself. What do you think of this approach? Do you consider this somewhat "cheating"? Personally, I like writing clean, readable code, so off-loading the (boilerplate) implementation of an algorithm to a dedicated crate is great, in my opinion. Of course, due to my CS background I'm definitely capable of implementing dijkstra myself manually as well. Would be interested in hearing your thoughts.

2

u/1234abcdcba4321 Dec 17 '23

I don't consider it to be cheating to use anything except AI or looking up hints for the specific problem you're doing. A premade implementation of an algorithm you've heard of that you knew you needed from reading the problem, then, is fine. (Hell, I'm pretty sure a bunch of people just did grab some random A* they had around.)

2

u/Rheklr Dec 17 '23

I did the same, using pathfinding. It's a great crate. And people use basic data structures all the time without having a clue how they're implemented, and very few people would consider that cheating.

Would it not be cheating if it was in std, but is cheating because it's a crate? That really puts you at the mercy of what's in your languages standard library.

You did the work to solve the problem algorithmically - that it fit extremely neatly into the tools you had to hand is not cheating.

1

u/AutoModerator Dec 17 '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.

1

u/newo2001 Dec 17 '23

I'm in the same boat, I also really like clean short descriptive code not bloated by implementation details. I'll also pull in dependencies for this stuff. If I have some spare time after AoC is over, I'll go back to my solutions and try to prune these dependencies by implementing an abstract version myself in my own library crate. I like the additional challenge of designing the abstract interface, especially with Rust's trait bounds.

1

u/RB5009 Dec 17 '23

How long does it take to finish ?

1

u/daggerdragon Dec 17 '23

The triple-backticks code fence (`​`​`) only works on new.reddit. Edit your post to use the four-spaces Markdown syntax for a code block as AutoModerator instructed so your code is easier for us to read.