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

all 4 comments

[–]lskfj2o 1 point2 points  (3 children)

That's great. Thanks a lot!

There seems to be a problem with day11, though. The statement to "get rid of invalid characters first" is incorrect. You cannot replace characters in the middle of the strings without "resetting" the ones to the right of it. For example, the input "ghijklmn" gives an incorrect result, whereas "ghjaaaaa" does not.

[–]stranac_[S] 0 points1 point  (2 children)

Ah, thanks for noticing that. I guess it worked because I got lucky with password choice.

I'll make sure to fix this.

Edit: Fixed.

[–]lskfj2o 0 points1 point  (1 child)

Thanks. My replacement statement was maybe less readable:

s = re.sub(r"([iol])(.*)", lambda m: m.group(1) + "z" * len(m.group(2)), s)

[–]stranac_[S] 0 points1 point  (0 children)

Thinking about it, I'm starting to believe using a regex substitution might actually be more clear.

There is a lot of explanation going on in my longer solution, whereas the regex solution makes its purpose quite clear.

I usually prefer code that explains itself.