Discuss Scratch

ideapad-320
Scratcher
1000+ posts

Advent Of Code 2024

Advent of code is an advent calendar of christmas themed coding problems. This topic is for getting and giving help with and discussing Advent Of Code 2024.

Please do the following (not hard-and-fast-rules):
Don't just post solutions. At least add a little bit about how it works and/or your thought process.

Put the puzzle and post number in big text at the top of your post. If you are quoting someone and it is the same, do not do this, even when quoting more than 1 level deep. To get big text, use [big]text goes here[/big]. Use one of the following, and replace “Puzzle Number” with the puzzle number:
Puzzle Number - Solution
Puzzle Number - Give/Get Help
Puzzle Number - Discussion
General Discussion
Reusable Code
(dont forget to use big text. You may also make it something else if you think it is a better fit/)
Append “ - Spoilers” if you spoil a lot of a puzzle.

Avoid spoiling too much until 24-48hrs after the puzzle is released. Helping people is fine though.

Reusable code means it was used for 3 or more days.

Have Fun!

First post from each day:
Day 1
Day 2
Day 3
Day 4
Day 5
Day 6
Day 7
Day 8
Day 9
Day 10
Day 11
Day 12
Day 13
Day 14
Day 15
Day 16
Day 17
Day 18
Day 19
Day 20

Last edited by ideapad-320 (Dec. 21, 2024 03:39:48)

ideapad-320
Scratcher
1000+ posts

Advent Of Code 2024

Useful reusable code
gonna put links to useful reusable code here.
ideapad-320
Scratcher
1000+ posts

Advent Of Code 2024

How to read a file in many languages
If your language is missing, post how to do it!
Python:
(issues with filterbot, can't use code blocks)
=======================
file=open(“file.txt,”r")
text = file.read()
file.close
=======================
I need code for more languages.

Last edited by ideapad-320 (Dec. 2, 2024 18:16:50)

ideapad-320
Scratcher
1000+ posts

Advent Of Code 2024

reserved
davidtheplatform
Scratcher
500+ posts

Advent Of Code 2024

EDIT: This is outdated, instead use this better method by gilbert_given

Pro tip: put everything related to your solution in [code] tags and add a bunch of spaces at the beginning, so people have to scroll to see it.
Example:
                                                                                                                                                             this text is hidden until you scroll right

Also, heres a leaderboard code for scratch (join leaderboards at https://adventofcode.com/2024/leaderboard/private):
4320286-dd2a1cad
Make sure the account you use to sign up doesn't have personal details in it (or select the anonymous username option at https://adventofcode.com/2024/settings before joining)
note to ST: leaderboards don't allow any communication or sharing of info, they just show usernames and scores

Last edited by davidtheplatform (Dec. 6, 2024 21:41:13)

ideapad-320
Scratcher
1000+ posts

Advent Of Code 2024

General Discussion

davidtheplatform wrote:

Pro tip: put everything related to your solution in [code] tags and add a bunch of spaces at the beginning, so people have to scroll to see it.
Example:
                                                                                                                                                             this text is hidden until you scroll right

Also, heres a leaderboard code for scratch (join leaderboards at https://adventofcode.com/2024/leaderboard/private):
4320286-dd2a1cad
Make sure the account you use to sign up doesn't have personal details in it (or select the anonymous username option at https://adventofcode.com/2024/settings before joining)
note to ST: leaderboards don't allow any communication or sharing of info, they just show usernames and scores
Please don't try to hide your stuff in code tags, people can just read over it. I changed the first post to say mark if spoilers.
davidtheplatform
Scratcher
500+ posts

Advent Of Code 2024

ideapad-320 wrote:

General Discussion

davidtheplatform wrote:

Pro tip: put everything related to your solution in [code] tags and add a bunch of spaces at the beginning, so people have to scroll to see it.
Example:
                                                                                                                                                             this text is hidden until you scroll right

Also, heres a leaderboard code for scratch (join leaderboards at https://adventofcode.com/2024/leaderboard/private):
4320286-dd2a1cad
Make sure the account you use to sign up doesn't have personal details in it (or select the anonymous username option at https://adventofcode.com/2024/settings before joining)
note to ST: leaderboards don't allow any communication or sharing of info, they just show usernames and scores
Please don't try to hide your stuff in code tags, people can just read over it. I changed the first post to say mark if spoilers.
I'm saying you should put spoilers in indented code tags. The post subject/day #/other metadata should still be visible.
ideapad-320
Scratcher
1000+ posts

Advent Of Code 2024

davidtheplatform wrote:

ideapad-320 wrote:

General Discussion

davidtheplatform wrote:

Pro tip: put everything related to your solution in [code] tags and add a bunch of spaces at the beginning, so people have to scroll to see it.
Example:
                                                                                                                                                             this text is hidden until you scroll right

Also, heres a leaderboard code for scratch (join leaderboards at https://adventofcode.com/2024/leaderboard/private):
4320286-dd2a1cad
Make sure the account you use to sign up doesn't have personal details in it (or select the anonymous username option at https://adventofcode.com/2024/settings before joining)
note to ST: leaderboards don't allow any communication or sharing of info, they just show usernames and scores
Please don't try to hide your stuff in code tags, people can just read over it. I changed the first post to say mark if spoilers.
I'm saying you should put spoilers in indented code tags. The post subject/day #/other metadata should still be visible.
Yeah, but having to scroll is annoying, especially for large explanations.
davidtheplatform
Scratcher
500+ posts

Advent Of Code 2024

ideapad-320 wrote:

davidtheplatform wrote:

ideapad-320 wrote:

General Discussion

davidtheplatform wrote:

Pro tip: put everything related to your solution in [code] tags and add a bunch of spaces at the beginning, so people have to scroll to see it.
Example:
                                                                                                                                                             this text is hidden until you scroll right

Also, heres a leaderboard code for scratch (join leaderboards at https://adventofcode.com/2024/leaderboard/private):
4320286-dd2a1cad
Make sure the account you use to sign up doesn't have personal details in it (or select the anonymous username option at https://adventofcode.com/2024/settings before joining)
note to ST: leaderboards don't allow any communication or sharing of info, they just show usernames and scores
Please don't try to hide your stuff in code tags, people can just read over it. I changed the first post to say mark if spoilers.
I'm saying you should put spoilers in indented code tags. The post subject/day #/other metadata should still be visible.
Yeah, but having to scroll is annoying, especially for large explanations.
* You only have to scroll once per text field
* Avoiding spoilers is really hard if they aren't hidden, especially if you have to look closely at the post to figure out what the spoilers are about. The post topic thing sort of mitigates this, but IMO it isn't enough
ideapad-320
Scratcher
1000+ posts

Advent Of Code 2024

davidtheplatform wrote:

ideapad-320 wrote:

davidtheplatform wrote:

ideapad-320 wrote:

General Discussion

davidtheplatform wrote:

Pro tip: put everything related to your solution in [code] tags and add a bunch of spaces at the beginning, so people have to scroll to see it.
Example:
                                                                                                                                                             this text is hidden until you scroll right

Also, heres a leaderboard code for scratch (join leaderboards at https://adventofcode.com/2024/leaderboard/private):
4320286-dd2a1cad
Make sure the account you use to sign up doesn't have personal details in it (or select the anonymous username option at https://adventofcode.com/2024/settings before joining)
note to ST: leaderboards don't allow any communication or sharing of info, they just show usernames and scores
Please don't try to hide your stuff in code tags, people can just read over it. I changed the first post to say mark if spoilers.
I'm saying you should put spoilers in indented code tags. The post subject/day #/other metadata should still be visible.
Yeah, but having to scroll is annoying, especially for large explanations.
* You only have to scroll once per text field
* Avoiding spoilers is really hard if they aren't hidden, especially if you have to look closely at the post to figure out what the spoilers are about. The post topic thing sort of mitigates this, but IMO it isn't enough
We disagree, thats fine. Ima add a rule to not post spoilers at all till 24-48hrs after puzzle release.
davidtheplatform
Scratcher
500+ posts

Advent Of Code 2024

Day 1 - Discussion
Challenge 1 is live as of 8 minutes ago, I just solved it. Somehow 1500 people beat me.
EDIT: my actual rankings:

Last edited by davidtheplatform (Dec. 1, 2024 05:16:34)

applejuiceproduc
Scratcher
1000+ posts

Advent Of Code 2024

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.

Last edited by applejuiceproduc (Dec. 1, 2024 21:11:08)

ideapad-320
Scratcher
1000+ posts

Advent Of Code 2024

Day 1 - Discussion
I spent 1 hour of headbanging to realize that I forgot that a newline counts as a character :(
ideapad-320
Scratcher
1000+ posts

Advent Of Code 2024

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.
davidtheplatform
Scratcher
500+ posts

Advent Of Code 2024

ideapad-320 wrote:

Day 1 - Discussion
Also, I will not be posting my solutions here to not dox myself.
How could posting your solution dox yourself?
gilbert_given_189
Scratcher
1000+ posts

Advent Of Code 2024

Is this supposed to be get progressively harder? Seems easy so far.
davidtheplatform
Scratcher
500+ posts

Advent Of Code 2024

gilbert_given_189 wrote:

Is this supposed to be get progressively harder? Seems easy so far.
Yes. You can also play previous years by changing the 2024 in a url to 2016-2023, and all levels will be unlocked
applejuiceproduc
Scratcher
1000+ posts

Advent Of Code 2024

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.
ideapad-320
Scratcher
1000+ posts

Advent Of Code 2024

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.

Last edited by ideapad-320 (Dec. 2, 2024 17:43:16)

mybearworld
Scratcher
1000+ posts

Advent Of Code 2024

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)

Last edited by mybearworld (Dec. 2, 2024 18:52:07)

Powered by DjangoBB