Discuss Scratch
- applejuiceproduc
-
Scratcher
1000+ posts
Advent Of Code 2024
Yeah I literally just looked that up lol. I also did such an inefficient sort because I wanted to see how long it would take to run. Turns out it was only about 5 seconds.My advice: just use the built-in sort function. It is a lot simpler and faster. For your filterbot issue, put it out of a code block.I can now because the day is over so here it is:Day 1 - DiscussionWhy?
I cant post my solution yet, I will post it tomorrow, but it contains an if statement that runs 180 million times just to get the answer.
Also, I will not be posting my solutions here to not dox myself.It says “Sorry, this post appears to include unsuitable language and will not be posted.” when I try to post the whole thing, so I'm just posting the function where it sorts the list from lowest to highest in a very silly way.# Sorts list from highest to lowest def sort_from_lowest_to_highest(list): sorted_list = [] iteration = 10000 while iteration != 99999: for item in list: if item == iteration: sorted_list.append(item) iteration = iteration + 1 return sorted_list
The if statement is the one that runs 170 million times in each run. I know that function is coded very stupidly, but I thought “that will technically work” so I decided to do it.
I decided to upload my (very bad) solutions to github here: https://github.com/michaeleldar/advent24 along with some functions in the functions folder which might be able to be used in later days.
- ideapad-320
-
Scratcher
1000+ posts
Advent Of Code 2024
Day 2 - DicussionYeah, me too. I got an undercount. I also ended up with a brute-force loop (with early exit when valid, of course).
I tried to not just use a loop for the second part, which ended up taking me several hours just for me to keep finding another bug. I conceded and just used a loop after that
(Also, I'm putting all my solutions on GitHub at https://github.com/mybearworld/advent2024)
If it is valid without the dampener, it is valid with the first or last removed, I didn't check for the case of nothing removed. Did you?
Last edited by ideapad-320 (Dec. 3, 2024 03:52:53)
- mybearworld
-
Scratcher
1000+ posts
Advent Of Code 2024
(#22)I should've thought of not checking the no numbers removed case… Though honestly, I was already fed up with trying to optimize it and it not working lol
Day 2 - Dicussion
Yeah, me too. I got an undercount. I also ended up with a brute-force loop (with early exit when valid, of course).
If it is valid without the dampener, it is valid with the first or last removed, I didn't check for the case of nothing removed. Did you?
- gilbert_given_189
-
Scratcher
1000+ posts
Advent Of Code 2024
I slept over AoC 2024-3 because I was so sleepy, whoops
Day 2 - Discussion
I tried solving Day 2 with Excel - not a good idea. I guess I'm not that fluent at it.
Day 2 - Discussion
I tried solving Day 2 with Excel - not a good idea. I guess I'm not that fluent at it.
- gilbert_given_189
-
Scratcher
1000+ posts
Advent Of Code 2024
Day 3:Bonus points if you can do the day with a single expression.
https://xkcd.com/208/
- applejuiceproduc
-
Scratcher
1000+ posts
Advent Of Code 2024
Day 3 - Discussion
I got both parts first try, but it took me about an hour to do them. I had never used regular expressions before, and I ended up using 8 of them. I had 113 lines of code in my second part, because I decided to parse all the characters one by one in dozens of if statements.
I got both parts first try, but it took me about an hour to do them. I had never used regular expressions before, and I ended up using 8 of them. I had 113 lines of code in my second part, because I decided to parse all the characters one by one in dozens of if statements.
- ideapad-320
-
Scratcher
1000+ posts
Advent Of Code 2024
Day 3 - DiscussionWhat regexs did you use?
I got both parts first try, but it took me about an hour to do them. I had never used regular expressions before, and I ended up using 8 of them. I had 113 lines of code in my second part, because I decided to parse all the characters one by one in dozens of if statements.
- ideapad-320
-
Scratcher
1000+ posts
Advent Of Code 2024
How???Day 3:Bonus points if you can do the day with a single expression.
https://xkcd.com/208/
- mybearworld
-
Scratcher
1000+ posts
Advent Of Code 2024
(#29)Something like this can do (it's what I actually did), where you then have to check for the actual names of the functions when handling the matches.
How???
/* this is a spoiler tag, scroll right to see it */ /(mul|do|don't)\((?:(\d{1,3}),(\d{1,3}))?\)/g
- ideapad-320
-
Scratcher
1000+ posts
Advent Of Code 2024
That makes more sense.(#29)Something like this can do (it's what I actually did), where you then have to check for the actual names of the functions when handling the matches.
How???/* this is a spoiler tag, scroll right to see it */ /(mul|do|don't)\((?:(\d{1,3}),(\d{1,3}))?\)/g
Last edited by ideapad-320 (Dec. 3, 2024 20:31:09)
- davidtheplatform
-
Scratcher
500+ posts
Advent Of Code 2024
My version of day 3 part 2 with a single regex:
It returns “do” or “don't” for each mul statement.
spoilers, scroll right --> /(mul\(\d{1,3},\d{1,3}\))(?<=(do(n't)?)\(\).*?)/gs- ninjaMAR
-
Scratcher
1000+ posts
Advent Of Code 2024
(#29)I usedHow???Day 3:Bonus points if you can do the day with a single expression.
https://xkcd.com/208/
Spoiler -> Scroll Right: mul\(\d*,\d*\)|do\(\)|don't\(\)
Last edited by ninjaMAR (Dec. 3, 2024 22:27:49)
- gilbert_given_189
-
Scratcher
1000+ posts
Advent Of Code 2024
Day 4 - Discussion / Solution
I'm going to post my solution early here since I don't feel like keeping my tabs open.
(encrypted of course, no cheating)
IV: max 2763^x, x in Z+
Question asked for overlapping search; re.findall isn't. I guess not everything can be done with regex.
I'm trying not to use NumPy on part 1, but I decided to use it on part 2 since that would be more practical.
I'm going to post my solution early here since I don't feel like keeping my tabs open.
(encrypted of course, no cheating)
IV: max 2763^x, x in Z+Question asked for overlapping search; re.findall isn't. I guess not everything can be done with regex.

QfncEohkhudtwm7uPwpmAjdEiiCT8vdzRX6qaAooxVuhKrWiN6S1LQLehOHRCypZ1410s79S0zL9+N2DPhSekPBffwWHzexhp/ytJsTF2mkHVQPZUQsi9EFM694+ESv7Wl3BrZuGFESwMtCldfW/ekTfux8bDMnQHPU8UdJGrgpvnSyBuuXMfV98lGOxNY1iRBy5nPI6ZsEtjigVIYFmOiX8di8ULB/sIFpVd0Zp3HMhLXy86hxPm/nO5TZVsLqtf2NXUAcfobj0DTTlovuPHt4Rxtr9p7v4GXVhSAUOHp1PpMnYUWLzkF3fU7f5RtRaz+nNsp2FakjFeBfbDDjcflUN+TlOykxEW5ypzaMYKgbX6JDOsjzwhcdcHV0IPoj57YX9cPXXyTB5GrFHmOfAPhVRj7fDsYsCxj80MMmGV2mM8ir+/15GbpqKRKQ1SYEw5DzG/28oJyOrNe1FUBkwpu+U7hi+YGgsvabQxXTfAcgIuacxhBDaHvQTcrmQd3gJxY1QFbmWx0rmp9bzj/vHPs1Lx8eOk+tAR4mJX3cwLTLp0MmL/cepkj2Uah/pW/QF9fCyZ1or87HTtCGxq4qlxCJ5QzDLQmmIn4qajv02Hms92oEOXxHxMBfGoq7YwAqRWo/YSLjkB36AKFfIjIqASwIG7Y/1p+THKCG3oNndvNW54tBURMXjW/0clFT/p9JCOBn6nHNJxgcl/uEkNfPfqLgX78SXzK+7JYDNHogfYRP1Bvg6cACZSokmL9EbdPvOwTaphjvKd/5DMWpIgk3a8a+Bg4HFRv006PWmgLQW4z0hV4FYqQziROrE8agcjHOQHBbJtRL6zJrDtF8SkND83m3DrbAdQ6XN2AQ4aGgdwbM9/vl42C7ec7bJ7TL3D5EDhn2aGRQL8eEGOGU7jLHI3wFAEIpsBXSf8JJWawV1YFM=
I'm trying not to use NumPy on part 1, but I decided to use it on part 2 since that would be more practical.
CmpO2Ag1YI7Qw3yedAooI8qIec4GScn4Zm7ri1bXYLivXcE5DvxPJlLyz1ju4sy/xX45acbfukIrLjH69JPoOtLpB0vSFq9tXE18TBOvzYMlJuv1CxTkWpESZk6QYkwshm84CBmx0dN/4G6R+yxjYTKYd5YRAYAr9HJ1GXHv4cAV/gm5auRQ9Z7xmoBPZWyM4BgXpN88jvo8iE/KGcEZcklxNY+EEhdQsjsOugu7J7vUSpZdnX2mqOg7+ptTVWpgtqloAuzDbWwZxuDr8Gdm5PDKcQgnDv3Wz0BYkynzFsmsdlbBtCUO/sNwzUs8qGVmQR/nBpAeP9Wd6sa0eBFSeeJugh+ePa0h1LDi2PFNjuUcT6AS0i//DV4Y/YctAtarCsSxZXkSBpR9bFj6ZXYtr19epU92X4yqrPDKqF0/fQ8Jjm2l2ov1dQ9O+MRSwbdmWVN0pnByn4wOaKQ0FiXVkBRH4Z48Msx/ooJvi8YZVq4Ja8GM0P/GoW76qdGBspQDqsYXMM9IG308524E2g5iZ8V8qWl9bpLUaizm7Hs+yhaa+OJKu1AHZfdj85yckwSROT+V9VmH0go6w9sqWp0FaM5kohu0hoF7fcq1ECJ+NF2LnVtTu7G5hvwEaJy/qV3V1XyQKGLtDF0RSFRZjKD91WZF+AfLXnRYnHcrEt+GOVbTOLbFN/NoB8mne5hDgZMhiqx700Mj7BdWmfJ2lY3AKgs3u2l0AEU9c1dWNse/LZcOJnUzEJX5InZuiS35yxDafB727LpRf29ZCYwTWC2STEO/nYiA/piir0f1k751NrLchyN51Ooot5Z04i0DHjkj0OLVnXLVo1jJIip0C2ylbSdOoiQAv0INxsdzGL2VOZCyl9Gxd74uu9gmPdtezFgi25P+Fk8IbQi1Zj5n3Y0bhKkvJjXIE7e/YuL9r6LVOwoO150mT8xnTdpAzvTuL/WEwdSTs9oyi5asf9EOFwc6KYfUZTQvkuLmkgD/xrFOIL6dwVh1joOS7GtNYkK+G4UkBnCoCmLs1bDIxQoS/LkQrKrJsJVITNYC45eoJj4bSu+wDQxlP/3mARcNUdVX3qvH40aYSpQ3ibU+5uSd12Lq65aFDlCaGvvLrM4HFZLNSHqbDmQ2Z0AIQRyDklhy/KS0KKi+guXmXCR+xXK5TqiIPgrsQs1pzwtqN3R36tCdlUwZTehKGarXpAFt0GiaiIAhPD3CsBf0/BEwoAgln4jerNdz3dLag0y6KJsOvOkJvB90J8HPoaV+7NxV68nCLPGjndWVyA/mf5tDtbdiC+onU8/Zwna4BY4yxE6mWH0F3zE=
Last edited by gilbert_given_189 (Dec. 4, 2024 10:11:13)
- mybearworld
-
Scratcher
1000+ posts
Advent Of Code 2024
Day 4 - Discussion
Part 2 felt way easier than part 1 for me. Fewer lines of code, too.
Part 2 felt way easier than part 1 for me. Fewer lines of code, too.
- ideapad-320
-
Scratcher
1000+ posts
Advent Of Code 2024
Day 4 - DiscussionWhat did you do for part 1? I used 2 for loops, one for the x direction, one for the y direction.
Part 2 felt way easier than part 1 for me. Fewer lines of code, too.
- applejuiceproduc
-
Scratcher
1000+ posts
Advent Of Code 2024
I coded it so that it would go through each letter and if it found the possible start of a function it would start reading it. So the regexs are:Day 3 - DiscussionWhat regexs did you use?
I got both parts first try, but it took me about an hour to do them. I had never used regular expressions before, and I ended up using 8 of them. I had 113 lines of code in my second part, because I decided to parse all the characters one by one in dozens of if statements.
five of
[\d]
The rest were:
mul\([\d]+ mul\([\d]+, mul\([\d]+,[\d]+
- applejuiceproduc
-
Scratcher
1000+ posts
Advent Of Code 2024
deleted, I found my mistake
Last edited by applejuiceproduc (Dec. 4, 2024 20:23:16)
- ideapad-320
-
Scratcher
1000+ posts
Advent Of Code 2024
I used one regex for each function, making the first one that matched in string position go into effect.I coded it so that it would go through each letter and if it found the possible start of a function it would start reading it. So the regexs are:Day 3 - DiscussionWhat regexs did you use?
I got both parts first try, but it took me about an hour to do them. I had never used regular expressions before, and I ended up using 8 of them. I had 113 lines of code in my second part, because I decided to parse all the characters one by one in dozens of if statements.
five ofFour to detect if the current character is a number and one to look for the numbers when trying to multiply the 2 parts together.[\d]
The rest were:Which were used to check what was in the current string where I recorded the progress towards getting a valid mul() function.mul\([\d]+ mul\([\d]+, mul\([\d]+,[\d]+
- davidtheplatform
-
Scratcher
500+ posts
Advent Of Code 2024
Same. Here's my part 2 code:Day 4 - DiscussionWhat did you do for part 1? I used 2 for loops, one for the x direction, one for the y direction.
Part 2 felt way easier than part 1 for me. Fewer lines of code, too.
bGluZXMgPSBbXQoKd2hpbGUgKGkgOj0gaW5wdXQoKSkgIT0gJyc6CiAgICBsaW5lcy5hcHBlbmQoJy4uLi4uJyArIGkgKyAnLi4uLi4nKQoKbCA9IGxlbihsaW5lc1swXSkKZm9yIGkgaW4gcmFuZ2UoNSk6CiAgICBsaW5lcy5hcHBlbmQoJy4nICogbCkKICAgIGxpbmVzLmluc2VydCgwLCAnLicgKiBsKQoKcyA9IDAKdCA9IDAKICAgIApkZWYgY2hlY2soYXJyYXksIHgsIHkpOgogICAgI3ByaW50KHgsIHkpCiAgICBidWlsdF9zdHJpbmdzID0gWycnXSoyCiAgICBmb3IgaSBpbiByYW5nZSgzKToKICAgICAgICBidWlsdF9zdHJpbmdzWzBdICs9IGFycmF5W3kraV1beCtpXQogICAgICAgIGJ1aWx0X3N0cmluZ3NbMV0gKz0gYXJyYXlbeStpXVsoeCsyKS1pXQogICAgI3ByaW50KGJ1aWx0X3N0cmluZ3MpCiAgICBpZiAoYnVpbHRfc3RyaW5nc1swXSA9PSAnTUFTJyBvciBidWlsdF9zdHJpbmdzWzBdID09ICdTQU0nKSBhbmQgKGJ1aWx0X3N0cmluZ3NbMV0gPT0gJ01BUycgb3IgYnVpbHRfc3RyaW5nc1sxXSA9PSAnU0FNJyk6CiAgICAgICAgcmV0dXJuIDEKICAgIHJldHVybiAwCgpmb3IgeCBpbiByYW5nZShsZW4obGluZXNbMF0pIC0gMTApOgogICAgZm9yIHkgaW4gcmFuZ2UobGVuKGxpbmVzKSAtIDEwKToKICAgICAgICBzICs9IGNoZWNrKGxpbmVzLCB4KzUsIHkrNSkK
I agree that part 2 was easier, I'm not sure why it didn't come first.
Does anyone know who 3kh0 is?