News for hackers. Stuff that matters.
Re:Advent of Code 2023 is nigh by frantathefranta on Friday December 01, 2023 @11:29AM (#38488588)
Yeah I was sort of lucky that my edge case was on the last line, still took a full hour of wondering why my solution was wrong though.
Re:Advent of Code 2023 is nigh by cjauvin on Friday December 01, 2023 @11:44AM (#38488807)
I find some problems of AoC are sometimes on the thin line between "it's interesting and I might learn something new" vs "wasting my time with under-specified or ambiguous problem specs".. Part 2 of Day 1 lies dangerously in the latter, for me.
Re:Advent of Code 2023 is nigh by wjholden on Friday December 01, 2023 @11:39AM (#38488740)
What was this edge case you encountered? My code worked...after I finally read the problem closely enough.
Re:Advent of Code 2023 is nigh by shever73 on Friday December 01, 2023 @11:47AM (#38488867)
For me it was a lack of specific instructions on how to handle overlaps. The edge case that frustrated me for a while was "oneight" at the end of a line. My initial code made it look like this "1ight", when it should have been "18".
Re:Advent of Code 2023 is nigh by WJW on Friday December 01, 2023 @12:58PM (#38489874)
When searching for the last number in the line I just reversed the line and scanned through it looking for the reversed strings for the number:

one -> eno

two -> owt

three -> eerht

etc

It makes the entire solution extremely simple, though a little verbose.

Re:Advent of Code 2023 is nigh by nucleardog on Friday December 01, 2023 @10:41PM (#38495669)
Yeah I was a little confused about all the people saying they've already given up on day 1. Seems like everyone's just really overcomplicating this. Why is everyone jumping to "replace the word strings with the digits" instead of just doing exactly what the problem says and... finding the first and last occurrence?

1. Build a list of values with corresponding string matches: [ 0 => ['zero', '0'], 1 => ['one', '1'], ...]

2. Loop through that and find the index of each within the input string, maintaining the lowest seen index + associated value.

3. When done, return value.

To find the last occurrence... just reverse the input string and all the search strings.

I'm not even sure it's all that verbose. If you exclude the part where I hardcoded an array of ten digits, it was... 11 lines of code, a third of which are closing braces. I'm sure I could cut it in half if I used some builtins for mapping/reducing/etc.

Re:Advent of Code 2023 is nigh by skydhash on Friday December 01, 2023 @10:52PM (#38495721)
> I'm not even sure it's all that verbose

Mine is. But that's because I don't bother DRYing it and making it more clever (yanking and pasting is faster than thinking)

Re:Advent of Code 2023 is nigh by skydhash on Friday December 01, 2023 @10:49PM (#38495708)
Same here. I'm using regex and I was wondering how to make it go backwards. After a moment of thought, that seems silly, so I just reversed the string and the regex and do the scan.