top | item 38490491

(no title)

Foivos | 2 years ago

The main difficulty of part 2 is that there are edge cases that are not covered by the examples. I have appended the example list with some edge cases, so use this list instead:

two1nine eightwothree abcone2threexyz xtwone3four 4nineeightseven2 zoneight234 7pqrstsixteen eighthree sevenine oneight xtwone3four three7one7 eightwothree oooneeone eight7eight

discuss

order

codr7|2 years ago

I don't get the amount of effort people out into the replacement-strategy, I did perfectly fine without it and the code is about as complex as the examples I've seen.

https://github.com/codr7/swift-interpreter/blob/main/part10/...

messe|2 years ago

Yeah, all the talk of replacement seems like people masively overthinking or abstracting a day one problem. My C++ solution was a simple search using the <algorithm> header. It's a little less neatly abstracted out as yours, and could be cleaned up a fair bit, as I wasn't bothered to deduplicate the code after getting it working (and I will if this turns out to be useful tomorrow), but the essence is the same:

https://gist.github.com/joedavis/3d6f2b87bae4809ef8a062caff7...

C++'s .rbegin() / .rend() reverse iterators made the search fairly trivial.

Levitz|2 years ago

>replacement-strategy

Oh so THAT is what is causing people problems.

brynbryn|2 years ago

Ahh, people are trying to do a replacement before finding tokens. I wondered why so many people were saying this was difficult. My head went straight to token parsing, which given the limited set of tokens made it trivial. Thought I was missing something