Unable to load image

rDrama Advent of Code Day 16: Energized Edition

Summary for those just joining us:

Advent of Code is an annual Christmas themed coding challenge that runs from December 1st until christmas. Each day the coding problems get progressively harder. We have a leaderboard and pretty good turnout, so feel free to hop in at any time and show your stuff!

Whether you have a single line monstrosity or a beautiful phone book sized stack of OOP code, you can export it in a nice little image for sharing at https://carbon.vercel.app

What did you think about today's problem?

https://adventofcode.com/2023

Our Code is 2416137-393b284c (No need to share your profile, you have the option to join anonymously if you don't want us to see your github)

15
Jump in the discussion.

No email address required.

https://i.rdrama.net/images/17027096822458239.webp

Another quality-of-life feature of Nim: arrays can be indexed by enum values. This is because arrays can be indexed by any ordinal type, and enums are one of them.

@SleighOut

Jump in the discussion.

No email address required.

That's wild I've never seen that syntax before. Doesn't seem to be in the docs and I'm getting Error: invalid order in array constructor when I try to mess with it. Where did you read about it?

Jump in the discussion.

No email address required.

I found it through a quick search, but it's also in the Nim manual. You're getting that error because the indices have to be in the same order as the enum.

Also, apparently the syntax gets even better: [Up: Down, Up, Right, Left][dir] will also work. "If an index is left out, succ(lastIndex) is used as the index value."

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.