Live data from Hacker News

Advent of Code 2023 is nigh

adventofcode.com

281–290 of 319 posts

Re: Advent of Code 2023 is nigh

#281

Earlier quoted context omitted.

Last year I did my run in J (Jsoftware.com) and it was very interesting. This year my initial desire is to do it in raku, which seems suited to the first task at least (although I haven't managed to get to it). I did another year in common lisp. All in all I really can recommend doing them in non-typical languages, it expands your mind.

I can recommend raku. Always fun.

The only problem with these kinds of languages is finding the place where the experts publish their solutions, if they do. I'd love to see what an expert can do and what I can learn from them.

Re: Advent of Code 2023 is nigh

#282

As others have said, part 2 of today's was really difficult. I finally solved it using Python regex `overlapped=true`, but it was very tricky. The irritation of having all of the test cases passing, but it failing for my challenge input! I hope it doesn't scare off newcomers, but I already know a few who have given up on part 2.

I think it's tricky for those of us trying to be a bit too clever. Certainly it's designed to catch out the obvious replacement strategy.

However the 'naive' solution still feels quite nice. Some python, at the risk of sharing spoilers:

    fixes = { "seven":"7", "two":"2", "one":"1", "nine":"9", "eight":"8", "three":"3", "four":"4", "five":"5", "six":"6" }
    cands = set(fixes.keys()) | set(fixes.values())

    total = 0
    for line in Path("input/1.txt").read_text().splitlines():
        matches = list(filter(lambda k: k in line, cands))
        first, *_ = sorted(matches, key=line.index)
        *_, last = sorted(matches, key=line.rindex)
        total += int(fixes.get(first, first) + fixes.get(last, last))

    print(total)

Re: Advent of Code 2023 is nigh

#284
post #226

Python should be excluded! I force myself to use Go, but it's just not competitive.

I like powerful languages without a too many built in convenience features. That way I get to enjoy solving the problems myself without too much effort.

Some of the solutions are quick and dirty, mostly dirty. And that's not art, but programming kitsch.

Re: Advent of Code 2023 is nigh

#285

Seems to me that people made part 2 harder than it us. Just define an array containing the digits: "one", "two", and so forth. Then check for substring matches, position by position. Maybe not elegant, but effective.

I just placed digits in the middle of the words instead of replacing them. This way I didn't "break" any overlapping words, and the order of digits is still the same.

Re: Advent of Code 2023 is nigh

#286
post #89
post #76

Day one part 2 was relatively rough. Things I learned from it: rust regex crate doesn't support look-ahead, rust onig crate is currently broken in many ways and shouldn't be used (the version in crates.io doesn't compile and the version on GitHub is failing tests and look-ahead isn't working). It was a very frustrating time for me. After 2 hours of troubleshooting the above I used the same approach in python and it t…

Easy mode for this use-case is to match on a reversed version of the regex on a reversed version of the string, but yeah, negative lookahead would be great.

Yeah, that was exactly was I was doing. For the left number do everything as normal, while walking through the string. For the reverse part, just walk through the reverse of the string and match the reversed keywords.

Re: Advent of Code 2023 is nigh

#287
post #76

Day one part 2 was relatively rough. Things I learned from it: rust regex crate doesn't support look-ahead, rust onig crate is currently broken in many ways and shouldn't be used (the version in crates.io doesn't compile and the version on GitHub is failing tests and look-ahead isn't working). It was a very frustrating time for me. After 2 hours of troubleshooting the above I used the same approach in python and it t…

Rust regex crate author here. fancy-regex is built on top of the regex crate and supports look-around. The regex crate doesn't support arbitrary look-around because it isn't known how to implement efficiently. See: https://swtch.com/~rsc/regexp/regexp1.html

Ah jeez I totally missed this crate! Thanks!! I had originally gone with Onig because of a SO post you made years ago. Fancy-regex substituted right in and worked immediately. Much appreciation for all you do

Re: Advent of Code 2023 is nigh

#288
post #261
post #76

Day one part 2 was relatively rough. Things I learned from it: rust regex crate doesn't support look-ahead, rust onig crate is currently broken in many ways and shouldn't be used (the version in crates.io doesn't compile and the version on GitHub is failing tests and look-ahead isn't working). It was a very frustrating time for me. After 2 hours of troubleshooting the above I used the same approach in python and it t…

Was regex even necessary?

Definitely not but it was the most elegant solution that I could think of right away, so I committed to it. In hindsight, it would've been relatively easy to solve with some loops and no dependencies but hey, I wouldn't have learned so much about the rust regex ecosystem that way.

Re: Advent of Code 2023 is nigh

#289
post #89
post #76

Day one part 2 was relatively rough. Things I learned from it: rust regex crate doesn't support look-ahead, rust onig crate is currently broken in many ways and shouldn't be used (the version in crates.io doesn't compile and the version on GitHub is failing tests and look-ahead isn't working). It was a very frustrating time for me. After 2 hours of troubleshooting the above I used the same approach in python and it t…

Easy mode for this use-case is to match on a reversed version of the regex on a reversed version of the string, but yeah, negative lookahead would be great.

Yeah I mean I did think of that but after spending all that time figuring out Regex I was decided to commit as fully as I could until it was 3am and I had to go to bed. There were lots of alternative solutions I thought of but chose to ignore out of stubborness. I'm admit, a good bit of the frustration was my own fault (but also c'mon this was way harder than any day 1 we've had before)

Re: Advent of Code 2023 is nigh

#290
post #76

Day one part 2 was relatively rough. Things I learned from it: rust regex crate doesn't support look-ahead, rust onig crate is currently broken in many ways and shouldn't be used (the version in crates.io doesn't compile and the version on GitHub is failing tests and look-ahead isn't working). It was a very frustrating time for me. After 2 hours of troubleshooting the above I used the same approach in python and it t…

It's a Regular Language, in the mathematical sense. All you need is the greedy match anything sequence, I don't know why so many people jumped to non-Regular regex extensions.

I'm sorry I'm not familiar with the mathematics behind regular expressions. Can you give an example of what your approach would look like?
Post reply on HN