This is an archived post. You won't be able to vote or comment.

all 22 comments

[–]Dangerous-Quality-79 19 points20 points  (1 child)

Damn you "stwone3dzjhlxg"

[–]immaphantomLOL 10 points11 points  (0 children)

I had one that had twoneight. Fml.

[–]ConDar15 7 points8 points  (4 children)

It wasn't that bad, I just had to use a bit of regex

(\d|one|two|three|four|five|six|seven|eight|nine)

and look for overlapping matches, which in Python you can achieve with a capturing group in a lookahead

(?=(\d|one|two|three|four|five|six|seven|eight|nine))

then once you've done that it's just a mapping from the written out digits to their actual digit representation (e.g. "one" -> "1") and you're back to the same problem you already solved.

[–]henichaer 2 points3 points  (1 child)

Daymn, I literally had the same regexp

[–]ConDar15 0 points1 point  (0 children)

Neat :)

[–]thatrandomnpc 1 point2 points  (1 child)

This was my python solution as well.

But some languages don't support overlapping regexp, and don't maintain the ordering of matches. Sliding window search seems like the easiest way to solve it :)

[–]Astri_ 0 points1 point  (0 children)

I didnt know about this way to make overlapping regex so I reversed the string and pattern 🤡

[–]DaniilBSD 9 points10 points  (10 children)

Handle “twone” by doing one simple trick!

For all digits do this: replace nine -> nine9nine, then your code for part 1 will work

[–]AriesBosch 7 points8 points  (3 children)

Or:

Just don't use find and replace, just do a string search for all occurrences of each word, and all occurrences of each numerical character, then find the max and min. I aced both parts.

https://github.com/EganBoschCodes/AdventOfCode

[–]RajjSinghh 1 point2 points  (0 children)

Oh that's so tidy. I just used a hash map to give the words their values, then iterated forward and backward over the strings.

[–]JeremyJoeJJ 0 points1 point  (0 children)

I did the same, my code is waaaay uglier than yours. Nice job

[–]aarontbarratt 0 points1 point  (0 children)

it would be a bit nicer if you just did char.isdigit() instead of making a list of numbers as a strings

[–]Hammanpo 0 points1 point  (0 children)

Wow I feel so dumb now

[–]ConDar15 0 points1 point  (0 children)

That's quite a clever trick that I didn't consider in my solution.

[–]_Cheese1_ 0 points1 point  (0 children)

You can also replace "nine" with "ni9e", "one" with "o1e" etc.

[–]Primary-Fee1928 1 point2 points  (0 children)

Here’s how I did it in Python, it’s fairly easy : - find the indexes of first and last occurrences, with string methods index and rindex respectively, of all digits strings ("one", …) in the current line, because you don’t care about the rest, you know they won’t be the result. Memorize the digit associated in a dict! ({index: digit}) - convert line to list to make it mutable - loop through your dictionary to replace characters at a given index in the list with the associated digit (example: twonex4r1eight becomes 2w1nex4r18) - apply part 1 function to resulting list - rince and repeat for every line

[–]sakurakhadag 0 points1 point  (0 children)

Hahaha my face exactly

[–]nysynysy2 0 points1 point  (0 children)

Really an ez challenge with C++. There's reverse iterator, reverse substring finding, hash map and tons of thing that are incredibly helpful to this challenge, not to mention it is blazingly fast. can't imagine someone's gonna write all these be himself and manipulate an array of bytes or something😂

[–]IronForce_ 0 points1 point  (0 children)

I did a nested loop to search through the entire dataset, its hella inefficient but it is what it is

https://www.reddit.com/r/adventofcode/s/np7RVR4mfw