r/adventofcode • • Dec 16 '23

SOLUTION MEGATHREAD -❄️- 2023 Day 16 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!
    • 6 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!

AoC Community Fun 2023: ALLEZ CUISINE!

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

Visualizations

As a chef, you're well aware that humans "eat" with their eyes first. For today's challenge, whip up a feast for our eyes!

  • Make a Visualization from today's puzzle!

A warning from Dr. Hattori: Your Visualization should be created by you, the human chef. Our judges will not be accepting machine-generated dishes such as AI art. Also, make sure to review our guidelines for making Visualizations!

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 16: The Floor Will Be Lava ---


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:15:30, megathread unlocked!

24 Upvotes

557 comments sorted by

View all comments

2

u/RB5009 Dec 16 '23 edited Dec 16 '23

[LANGUAGE: Rust] 🦀🦀🦀

Nothing fancy.

🦀 Timing (old i7-4910MQ locked at 2.0GHz):

  • 🔥 Part 1: 205us
  • 🔥 Part 2: 55ms

🦀🔥🦀🔥🦀🔥 Bonus 🔥🦀🔥🦀🔥🦀

A Rayon-ized version, takes 1.4ms on a M1 MBP:

pub fn part_two(input: &Vec<&[u8]>) -> usize {
    let rows = input.len();
    let cols = input[0].len();

    (0..rows).par_bridge().map(|r| energize(input, r, 0, Direction::Right))
        .chain((0..rows).par_bridge().map(|r| energize(input, r, cols - 1, Direction::Left)))
        .chain((0..cols).par_bridge().map(|c| energize(input, 0, c, Direction::Down)))
        .chain((0..cols).par_bridge().map(|c| energize(input, rows - 1, c, Direction::Up)))
        .reduce(||0, |a, b| a.max(b))
}

0

u/AutoModerator Dec 16 '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/SwampThingTom Dec 16 '23

Very nice. I'm learning Rust and picked up some great optimization tips from your solution.

1

u/daggerdragon Dec 16 '23

We can see all of your Markdown and the code block is not correctly formatted. Please fix it.