Your solution to have an enabled state variable for part two was a nice elegant solution - I really liked it! my solution there was clunky and required a list of index position for the ends of do's and don'ts so I can then find what the most recent do or don't was.
yes today I had to cheat and look at your code. Your's is the best example I''ve found. Some solutions are overly complex yet they type it out on the screen like there is no problem. I managed to get the first part done myself (in julia using regex) but the second part was nearly impossible. I'm still not sure why I couldn't get mine to work, my regexes looked fine. maybe I just needed to strip out the newlines, having now cheated I'm going to try to figure out what I needed to do in my own version. So thanks for sharing this video it probably helped my mental and physical health.
To shave off a few more seconds before the regex, instead of if D[j-1] not in ['1', '2', '3', '4', '5', '6', '7', '8', '9'] writing if D[j-1] not in '123456789' (to be thorough, list('123456789') but it's a singe char so it works here) should have done the same. Might have helped win a few places. I always watch your solution right after I finish mine, learned a lot of python "shortcuts" from it. And it's fun to watch someone compete. Good luck with the leaderboard!
Hi, rough day when regexes aren't your strong suit I saw you miss the p2 answer when double clicking/copying, maybe you could have something that automatically copies the last printed thing? Either by aliasing print or with some shell config. Seeing how close the leaderboard is on those first days, it could earn you some points Have fun this year!
I had the opposite problem, too much regex. Used regex to modify the input for part two and removed between the first don't() and do(), however there were some newlines sneaked into the input which messed it up. That was so annoying to debug.
@jonathanpaulson5053 I understand that, I'm wondering why it doesn't pick the same match multiple times. If you have fjdjdjdjmul(123,132) isn't the match function picking up the mul? It only matches when you reach with i?
Hi, there is another error in your regex. The ‘+’ can stand for any number of numbers. But the task says that it should only be 1-3 numbers. Your regex would be ‘mul(1234,1234)’ accept, but that would not be correct. For Part 1 you can also use only regex. part1 = 0 x = re.findall(r ‘mul\(\d{1,3},\d{1,3}\)’, data) for i in x: a, b = i[4:-1].split(‘,’) # cut mul( and the ) part1 += int(a)*int(b) There are very good regex builders on the Internet that help you to create the appropriate excerpt.
Your solution to have an enabled state variable for part two was a nice elegant solution - I really liked it! my solution there was clunky and required a list of index position for the ends of do's and don'ts so I can then find what the most recent do or don't was.
yes today I had to cheat and look at your code. Your's is the best example I''ve found. Some solutions are overly complex yet they type it out on the screen like there is no problem. I managed to get the first part done myself (in julia using regex) but the second part was nearly impossible. I'm still not sure why I couldn't get mine to work, my regexes looked fine. maybe I just needed to strip out the newlines, having now cheated I'm going to try to figure out what I needed to do in my own version. So thanks for sharing this video it probably helped my mental and physical health.
To shave off a few more seconds before the regex, instead of
if D[j-1] not in ['1', '2', '3', '4', '5', '6', '7', '8', '9']
writing
if D[j-1] not in '123456789' (to be thorough, list('123456789') but it's a singe char so it works here)
should have done the same. Might have helped win a few places.
I always watch your solution right after I finish mine, learned a lot of python "shortcuts" from it. And it's fun to watch someone compete. Good luck with the leaderboard!
Hi, rough day when regexes aren't your strong suit
I saw you miss the p2 answer when double clicking/copying, maybe you could have something that automatically copies the last printed thing? Either by aliasing print or with some shell config. Seeing how close the leaderboard is on those first days, it could earn you some points
Have fun this year!
good idea I'll try it
Glad I wasn't the only one who had trouble with regular expressions. :^)
I had the opposite problem, too much regex. Used regex to modify the input for part two and removed between the first don't() and do(), however there were some newlines sneaked into the input which messed it up. That was so annoying to debug.
thanks! this actually helped me find the bug...
you can do Ctrl+z and fg to switch between vim and the terminal faster
true but not sure its faster
Why doesn't the solution require an increment to i after matching the mul expression?
The for loop is incrementing i. I’m checking for a match in all possible starting positions.
@jonathanpaulson5053 I understand that, I'm wondering why it doesn't pick the same match multiple times. If you have fjdjdjdjmul(123,132) isn't the match function picking up the mul? It only matches when you reach with i?
Never mind, it's the re.search function that would match my example and return a Match object.
You can press ctrl+z to suspend vim and type fg to come back
Wow, you used a regular vim (i.e. no language support from the editor) to write python, that means you knows python very very very well.
Dude also knows vim itself pretty well 😂
Hi, there is another error in your regex.
The ‘+’ can stand for any number of numbers. But the task says that it should only be 1-3 numbers. Your regex would be ‘mul(1234,1234)’ accept, but that would not be correct.
For Part 1 you can also use only regex.
part1 = 0
x = re.findall(r ‘mul\(\d{1,3},\d{1,3}\)’, data)
for i in x:
a, b = i[4:-1].split(‘,’) # cut mul( and the )
part1 += int(a)*int(b)
There are very good regex builders on the Internet that help you to create the appropriate excerpt.
He changed it to \d{1,3} later if you didn't watch that far
@@pashi47 oh sorry. Yes, he changes it in minute 12. I wish I'd watched it to the end.
i used "+" and got the right answer for both parts. i don't think it matters
Hmm. It seems my input didn’t have long digits and \d+ worked