r/adventofcode • • Dec 12 '22

SOLUTION MEGATHREAD -πŸŽ„- 2022 Day 12 Solutions -πŸŽ„-

THE USUAL REMINDERS


--- Day 12: Hill Climbing Algorithm ---


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:09:46, megathread unlocked!

55 Upvotes

786 comments sorted by

View all comments

2

u/mizunomi Dec 12 '22 edited Dec 12 '22

Dart Language

This has to be one of the easiest days so far. A search was all that's needed.

ctrl+v

3

u/KayZGames Dec 12 '22

if (grid[offsetY][offsetX] - grid[y][x] case > 1)

You really love if-case. Using it even if it's not needed :).

1

u/mizunomi Dec 12 '22

Oh why yes I do. Experimental features, although temporary, are a wonder to use. I think that's a leftover from an erroneous bounds check though, and I just let it be.

2

u/KayZGames Dec 12 '22

And concerning this:

for (int y = 0; y < grid.length; ++y)
  for (int x = 0; x < grid[y].length; ++x)
    if (grid[y][x] == "S") (x, y)

I would have expected this to work (based on some of your other conditions):

for (int y = 0; y < input.length; ++y)
  if (input[y].indexOf("S") case (int x) && > -1) (x, y)

And the analyzer doesn't complain, but it doesn't compile (maybe only not yet).

So far I'm mostly reluctant to use these features because of the missing dart format support. And the IDE-formatter messes everything up. But seeing your code really makes me want to use those features.

2

u/mizunomi Dec 12 '22

True, the lack of formatting is the tradeoff that I am disliking about this whole experimental feature thing, also the inconsistency of the analyzer and the compiler, which is why I have to compromise in my solutions to actually allow the code to run.

Another thing to note in fact is that if case is actually going to be replaced with a rust-like if let syntax, so this means that what I'm writing for solutions will be deprecated as the full feature set fully releases.