Discuss Scratch

applejuiceproduc
Scratcher
1000+ posts

Advent Of Code 2024

ideapad-320 wrote:

applejuiceproduc wrote:

ideapad-320 wrote:

applejuiceproduc wrote:

Day 1 - Discussion

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.
Why?
Also, I will not be posting my solutions here to not dox myself.
I can now because the day is over so here it is:
# 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
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.

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.
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.
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.

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

mybearworld wrote:

Day 2 - Dicussion

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)
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?

Last edited by ideapad-320 (Dec. 3, 2024 03:52:53)

mybearworld
Scratcher
1000+ posts

Advent Of Code 2024

ideapad-320 wrote:

(#22)
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?
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
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.
ninjaMAR
Scratcher
1000+ posts

Advent Of Code 2024

gilbert_given_189
Scratcher
1000+ posts

Advent Of Code 2024

ninjaMAR wrote:

Day 3:
https://xkcd.com/208/
Bonus points if you can do the day with a single expression.
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.
ideapad-320
Scratcher
1000+ posts

Advent Of Code 2024

applejuiceproduc wrote:

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.
What regexs did you use?
ideapad-320
Scratcher
1000+ posts

Advent Of Code 2024

gilbert_given_189 wrote:

ninjaMAR wrote:

Day 3:
https://xkcd.com/208/
Bonus points if you can do the day with a single expression.
How???
mybearworld
Scratcher
1000+ posts

Advent Of Code 2024

ideapad-320 wrote:

(#29)
How???
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.
/* 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

mybearworld wrote:

ideapad-320 wrote:

(#29)
How???
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.
/* this is a spoiler tag, scroll right to see it                                                                                                                           */ /(mul|do|don't)\((?:(\d{1,3}),(\d{1,3}))?\)/g
That makes more sense.

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:
spoilers, scroll right -->                                                                                                                         /(mul\(\d{1,3},\d{1,3}\))(?<=(do(n't)?)\(\).*?)/gs
It returns “do” or “don't” for each mul statement.
ninjaMAR
Scratcher
1000+ posts

Advent Of Code 2024

ideapad-320 wrote:

(#29)

gilbert_given_189 wrote:

ninjaMAR wrote:

Day 3:
https://xkcd.com/208/
Bonus points if you can do the day with a single expression.
How???
I used
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.
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.
ideapad-320
Scratcher
1000+ posts

Advent Of Code 2024

mybearworld wrote:

Day 4 - Discussion

Part 2 felt way easier than part 1 for me. Fewer lines of code, too.
What did you do for part 1? I used 2 for loops, one for the x direction, one for the y direction.
applejuiceproduc
Scratcher
1000+ posts

Advent Of Code 2024

ideapad-320 wrote:

applejuiceproduc wrote:

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.
What regexs did you use?
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:
five of
[\d]
Four to detect if the current character is a number and one to look for the numbers when trying to multiply the 2 parts together.
The rest were:
mul\([\d]+
mul\([\d]+,
mul\([\d]+,[\d]+
Which were used to check what was in the current string where I recorded the progress towards getting a valid mul() function.
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

applejuiceproduc wrote:

ideapad-320 wrote:

applejuiceproduc wrote:

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.
What regexs did you use?
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:
five of
[\d]
Four to detect if the current character is a number and one to look for the numbers when trying to multiply the 2 parts together.
The rest were:
mul\([\d]+
mul\([\d]+,
mul\([\d]+,[\d]+
Which were used to check what was in the current string where I recorded the progress towards getting a valid mul() function.
I used one regex for each function, making the first one that matched in string position go into effect.
davidtheplatform
Scratcher
500+ posts

Advent Of Code 2024

ideapad-320 wrote:

mybearworld wrote:

Day 4 - Discussion

Part 2 felt way easier than part 1 for me. Fewer lines of code, too.
What did you do for part 1? I used 2 for loops, one for the x direction, one for the y direction.
Same. Here's my part 2 code:
bGluZXMgPSBbXQoKd2hpbGUgKGkgOj0gaW5wdXQoKSkgIT0gJyc6CiAgICBsaW5lcy5hcHBlbmQoJy4uLi4uJyArIGkgKyAnLi4uLi4nKQoKbCA9IGxlbihsaW5lc1swXSkKZm9yIGkgaW4gcmFuZ2UoNSk6CiAgICBsaW5lcy5hcHBlbmQoJy4nICogbCkKICAgIGxpbmVzLmluc2VydCgwLCAnLicgKiBsKQoKcyA9IDAKdCA9IDAKICAgIApkZWYgY2hlY2soYXJyYXksIHgsIHkpOgogICAgI3ByaW50KHgsIHkpCiAgICBidWlsdF9zdHJpbmdzID0gWycnXSoyCiAgICBmb3IgaSBpbiByYW5nZSgzKToKICAgICAgICBidWlsdF9zdHJpbmdzWzBdICs9IGFycmF5W3kraV1beCtpXQogICAgICAgIGJ1aWx0X3N0cmluZ3NbMV0gKz0gYXJyYXlbeStpXVsoeCsyKS1pXQogICAgI3ByaW50KGJ1aWx0X3N0cmluZ3MpCiAgICBpZiAoYnVpbHRfc3RyaW5nc1swXSA9PSAnTUFTJyBvciBidWlsdF9zdHJpbmdzWzBdID09ICdTQU0nKSBhbmQgKGJ1aWx0X3N0cmluZ3NbMV0gPT0gJ01BUycgb3IgYnVpbHRfc3RyaW5nc1sxXSA9PSAnU0FNJyk6CiAgICAgICAgcmV0dXJuIDEKICAgIHJldHVybiAwCgpmb3IgeCBpbiByYW5nZShsZW4obGluZXNbMF0pIC0gMTApOgogICAgZm9yIHkgaW4gcmFuZ2UobGVuKGxpbmVzKSAtIDEwKToKICAgICAgICBzICs9IGNoZWNrKGxpbmVzLCB4KzUsIHkrNSkK
I don't have the part 1 code, but it's mostly the same except the for loop in check runs 4 times, and built_strings is 8 elements long. Each element represents a different direction (0 is moving right, 1 is moving right and down, 2 is moving down, etc.). Also, the if statement just checks for ‘XMAS’.
I agree that part 2 was easier, I'm not sure why it didn't come first.


Does anyone know who 3kh0 is?

Powered by DjangoBB