Live data from Hacker News

Advent of Code 2023 is nigh

adventofcode.com

271–280 of 319 posts

Re: Advent of Code 2023 is nigh

#271

Earlier quoted context omitted.

Yeah, the overlapping case is the less common case in my experience. And even in the non-overlapping case, the "standard" approach is often not what you might expect. For example, if one were to use the Aho-Corasick algorithm to implement a regex like `samwise|sam`, the standard algorithm would yield incorrect results if you expect it to behave like, say, Perl or Javascript regexes. That's what led me to develop `Mat…

Oh yeah no, the issue was not with the API, it’s just that I got to the first example, figured “seems easy enough” making a bunch of assumption I did not validate in any way in the process, then when that didn’t work rather than check I was using the API correctly I made a bunch more assumptions (completely nonsensical too) of where the error might be. When I finally got to reading the docstring for `find_iter` the e…

Yup. Same kind of thing has happened to me many times. :-)

Re: Advent of Code 2023 is nigh

#272

Earlier quoted context omitted.

does it deal with cases like "twone", "nineight" and so on? it doesn't appear so to me because of the leading sed statements would commit the interpretation regardless of what happens next, but perhaps there is something subtle im not seeing.

It uses capture groups and puts them back in the replacement (the \1 ), so a match of "one" is replaced with (thematch)1(thematch). So eightwo would replace the two with two2two and end up like eightwo2two, so then the t is preserved and eight is found in a later step and then you end up with eight8eightwo2two, and can solve that using part1 only looking for numbers.

I see. Thank you for the explanation. I didn't know about that feature of sed.

Re: Advent of Code 2023 is nigh

#273
post #225

Earlier quoted context omitted.

Another option when using regex would be to use the lookahead[0] operator (as long as supported, which is the case for the python re module) (?=(one|two|three|[...])) would return `["two", "one"]` for the input string `twone` since the lookahead operator doesn't consume the next character. [0] https://www.regular-expressions.info/lookaround.html

Another trick is you can put some regex engines in right-to-left mode, so my lazy (and admittedly relatively expensive cpu-wise) solution was to match ltr for first and rtl for last.

Or just tack a greedy anything-matcher to the front of the regex: .*(?: ... )

Re: Advent of Code 2023 is nigh

#274

Earlier quoted context omitted.

does it deal with cases like "twone", "nineight" and so on? it doesn't appear so to me because of the leading sed statements would commit the interpretation regardless of what happens next, but perhaps there is something subtle im not seeing.

It uses capture groups and puts them back in the replacement (the \1 ), so a match of "one" is replaced with (thematch)1(thematch). So eightwo would replace the two with two2two and end up like eightwo2two, so then the t is preserved and eight is found in a later step and then you end up with eight8eightwo2two, and can solve that using part1 only looking for numbers.

okay that's very clever

Re: Advent of Code 2023 is nigh

#275
post #232
post #131

Earlier quoted context omitted.

I agree that using an auth provider is unnecessary for the problem faced. A bit ironic considering how AoC is all about programming challenges. Funny seeing the problem solved in 4 lines of Perl. If there were a trustworthy auth provider it wouldn't be as bad, but I don't really know of any... maybe something in the Fediverse?

Do you have a link? I've been looking for some nice Perl solutions, I imagine it's pretty much the optimal language for many of these problems.

Maybe re-read Stiray's post?

Re: Advent of Code 2023 is nigh

#276
post #241
post #147

Earlier quoted context omitted.

I think the issue is that they tried to separate the input into a list of tokens, like ["5", "nine"], and work from there, which doesn't work on something like "oneight".

It's funny how all of us used the `oneight` as the edge case to test our code on...

I used "eightwo"

Re: Advent of Code 2023 is nigh

#277
post #74

Genuinely curios why people are so into AoC ... Feels leetcode-y

I'm only into it because I know other people who are into it and it's fun to talk to them about it. It's actually my least favorite kind of programming problem, and the christmas elves conceit is very irritating to me

Re: Advent of Code 2023 is nigh

#278

Earlier quoted context omitted.

It uses capture groups and puts them back in the replacement (the \1 ), so a match of "one" is replaced with (thematch)1(thematch). So eightwo would replace the two with two2two and end up like eightwo2two, so then the t is preserved and eight is found in a later step and then you end up with eight8eightwo2two, and can solve that using part1 only looking for numbers.

okay that's very clever

For my own I did the same, but without capture groups. So replaced "one" with "one1one" naively without regex and did that for all numbers.

While it maybe is post-hoc clever, I think most of us ended up there because we tried naively to just replace "one" with "1", which broke on things like twone. So when down that path one had to amend it instead of going somewhere else.

Re: Advent of Code 2023 is nigh

#279
I solved the 2nd part pretty neatly in javascript today... I'm not a great programmer by any stretch but, maybe someone can take a peek and tell me what I can improve? This is my first time with JS-- I dislike the idea of it, but I know I should program in it before I write it off.

https://github.com/deafpolygon/advent-of-code/blob/main/2023...

Re: Advent of Code 2023 is nigh

#280
post #212

Most solutions I see are just blobs of code, which makes me wonder what their process looks like. I like to solve these kinds of problems in Lisp, which means I'm working in a REPL and dividing and conquering the problem to be able to test one piece of the solution at a time. The result is that my code tends to be mainly independent functions that I finally string together to solve the problem.

I'm solving in BQN, and my workflow is repeatedly re-phrasing a line until it does what I want in the repl, and then naming it, and then moving on.

Most often I end up with some enormous one-liner that I then break down into functions again.

Post reply on HN