Discuss Scratch
- ideapad-320
-
Scratcher
1000+ posts
Advent Of Code 2024
Day 5 - DIscussionFor me day 5 was harder than day 4. Day 4 was easier that day 3 for me, too.
Day 4 seems to have been an outlier in being weirdly more difficult? This was easier again.
- ideapad-320
-
Scratcher
1000+ posts
Advent Of Code 2024
Day 7
Straightforward, my part 2 solution took longer than I would have hoped sadly. I know how to make it faster, though.
Straightforward, my part 2 solution took longer than I would have hoped sadly. I know how to make it faster, though.
- gilbert_given_189
-
Scratcher
1000+ posts
Advent Of Code 2024
Day 8 - Discussion
Whoa, this problem is really hard to read. The antinode thing really puzzled me. Perhaps I should've paid attention on my physics class.
[I have no idea how many resonances I had to consider for part 2, but I figured the largest axis of the box would do just fine (times two just to be safe)]
Day 8 - Solution
Whoa, this problem is really hard to read. The antinode thing really puzzled me. Perhaps I should've paid attention on my physics class.
[I have no idea how many resonances I had to consider for part 2, but I figured the largest axis of the box would do just fine (times two just to be safe)]
Day 8 - Solution
N3q8ryccAASMDnP8sQIAAAAAAAAjAAAAAAAAAMRnPgZbqiuhoIgOs6AzHffvdIyvJd7a3nGiRdqA
eOftu8WRgmx7IMhvXOpeM1oEj1ZpTMEutXu3HRsnNd3/11KkSR0eAS6ddavgE96fmiI4uPehAeV4
kchIanGEvJmKdYbyFsO0V2ecOxlvpcmVSLCUJHnjazwuCcY5cn7G49a4ceE9ySbgt4oAvuPk8WGY
y/A3tVWLCAdpQ3/DcJEwhxY3ZRCZp46v1DV3GxN6N9WT6jEQlLNlrHc9ncRQg/eW/vS9UCnebDXs
9AP/LkimVvxbbKcc/frwnmnRpuGazczSWnDTKaGk+iO6ucSra/Tn+t2xNxDcoFaL3abtGOIDtv2W
qcQUqvaV6k7QXVUNUXXPrHXSKpoDPXlQ5EdbKFVYy5wlPp1PL7nDultTnGIsel+FClYI2n6bWcC0
90C153lsxghIEMvcG3YBSBvh4ndbX0cJLGOzPs08QTYc4J7Jn2v2vtl5hyDkFdmrp6a8QmHV4Tj+
+6ts0/HuBBMjts0EJrljACQkPG+1lSxBbdj98tvo98d5GCz8oDaD6ANxJ2sBTKTeCy7EQ+vBGV1u
LiOjUuC68PKY4nyPpnzCwwsRVua2Hnn6Q4Y+2uMhCA4v5SUafCJ9gA6zSeubNm4vF1H14VMzokqq
H+Z/bajCoTTuqntLD71IHj3QqS8ymQUSJ21K34tSaUTdcidoDBwq1LhxbjjwcoXcotegMVbuEqDy
q2bI5EDuetixvLLJUbqVNCJ2+gR4HwAAgTMHrg/VQ+KdFyTRz+QEK5AzLNQ8qRzFxuP2P+nVDElf
l4maumqq8xl/Gu7Qxgf+HewRkYA9/v4sdbIOkh91qr2+c8YF7O8NNMlahdNzkZM0iDQgDYrPAi9P
WOlWQygABWPROkCt0U/uPIJVH6XX7TJjPZyIAWKn3dHgUtoAABcGgjABCYCBAAcLAQABIwMBAQVd
ABAAAAyAngoB0Rqg0gAA
Last edited by gilbert_given_189 (Dec. 8, 2024 07:55:28)
- davidtheplatform
-
Scratcher
500+ posts
Advent Of Code 2024
Day 7 discussion
I did part 1 on my phone. It wasn’t as bad as I thought it would be.
I did an iterative approach so it was kind of slow, although not as bad as day 6. I thought of some optimizations that could be done easily with a recursive approach but didn’t implement them since my version is fast enough and hard to optimize.
Day 8 discussion
I did this completely on my phone. Could have done it a lot faster on a computer but I’m too lazy to walk to it
Reading the problem, this one felt like it would be hard but it really isn’t. I [looped through every set of antennas, found the offset between them, and put a anti node at a1-offset and a2+offset]. For part 2 I [made a loop to put antinodes at every n * offset. My bounds checking code was somewhere else, and since I was using a phone it was easier to just run 500 iterations of this, which is more than enough.].
Time complexity/runtime: [This problem was much faster for me than the last few days, if I lower the iterations in part 2 to 50 it runs in ~1s, 600ms of which is just importing numpy. I don’t think there are ways to make it much faster or slower, unless you iterate over every tile and check every other set of tiles for matching antennas or something. Overall easier than I would expect for day 8.]
I did part 1 on my phone. It wasn’t as bad as I thought it would be.
I did an iterative approach so it was kind of slow, although not as bad as day 6. I thought of some optimizations that could be done easily with a recursive approach but didn’t implement them since my version is fast enough and hard to optimize.
Day 8 discussion
I did this completely on my phone. Could have done it a lot faster on a computer but I’m too lazy to walk to it
Reading the problem, this one felt like it would be hard but it really isn’t. I [looped through every set of antennas, found the offset between them, and put a anti node at a1-offset and a2+offset]. For part 2 I [made a loop to put antinodes at every n * offset. My bounds checking code was somewhere else, and since I was using a phone it was easier to just run 500 iterations of this, which is more than enough.].
Time complexity/runtime: [This problem was much faster for me than the last few days, if I lower the iterations in part 2 to 50 it runs in ~1s, 600ms of which is just importing numpy. I don’t think there are ways to make it much faster or slower, unless you iterate over every tile and check every other set of tiles for matching antennas or something. Overall easier than I would expect for day 8.]
- davidtheplatform
-
Scratcher
500+ posts
Advent Of Code 2024
Day 8 - Discussion[A limit of 50 (or whatever the larger dimension is) works, since you can’t change a coordinate by 50 and still be on the map, and all offsets are at least 1. I did 500 which is way overkill but still ran in a few seconds on a raspberry pi]
[I have no idea how many resonances I had to consider for day 2, but I figured the largest axis of the box would do just fine (times two just to be safe)]
- mybearworld
-
Scratcher
1000+ posts
Advent Of Code 2024
Day 8 - Discussion
[I definitely agree that the phrasing of this one was really weird. I'm glad the examples were there, I probably wouldn't have been able to get it without them.]
[I definitely agree that the phrasing of this one was really weird. I'm glad the examples were there, I probably wouldn't have been able to get it without them.]
(#63)[I just added antinodes until another antinode would be out of bounds.]
[I have no idea how many resonances I had to consider for part 2, but I figured the largest axis of the box would do just fine (times two just to be safe)]
- mybearworld
-
Scratcher
1000+ posts
Advent Of Code 2024
Day 9 - Discussion
Amusingly, my part 2 actually ran faster than my part 1 today, because part 2 forced me to do some optimizations I had ignored for part 1
Amusingly, my part 2 actually ran faster than my part 1 today, because part 2 forced me to do some optimizations I had ignored for part 1

- gilbert_given_189
-
Scratcher
1000+ posts
Advent Of Code 2024
Day 9 - Discussion
I started a bit late because I had a class today. The first part seems like it's meant to be used with linked lists. I tried to be clever with the second part [by representing the disk as file indices much like filesystems], but that didn't work out so I had to do it data recovery style.
Also, this day made me think of a weird feature for for-loops (and any other loop really): a break that return some value. So something like this:
In this example, when the condition is met, the for-loop breaks, and execution continues on the `catch` block first. Otherwise, it continues to the `else` block (if it's defined). After that, execution goes as usual.
I think this is best fit with pattern matching, but that doesn't feel like JavaScript, so no examples for that here.
Day 9 - Solution
I started a bit late because I had a class today. The first part seems like it's meant to be used with linked lists. I tried to be clever with the second part [by representing the disk as file indices much like filesystems], but that didn't work out so I had to do it data recovery style.
Also, this day made me think of a weird feature for for-loops (and any other loop really): a break that return some value. So something like this:
for (let i in something) { if (something[i] == solution) break i; } catch (i) { // do something with i } else { // what to do when the break carries no value } // everything else is normal
I think this is best fit with pattern matching, but that doesn't feel like JavaScript, so no examples for that here.
Day 9 - Solution
N3q8ryccAAQjU+2pMgMAAAAAAAAjAAAAAAAAAGiKfpxzxGepcmxlWEBQfjejkTh5vEbe54laLsWP
pxUAoEI8XZRw+zEhRd/g5i8yMtCghQyaWz6m/62QjxIGnDhnxlRKXWJI+vsLY6tbXhqMISF5sUo6
tr4qjQ6JtGQCO0UECWuBtx0xwRq0/mnxBMVO1bm6lQgGKZUROD492OoZs/VU7p1b0MlE6GP5SByy
YqJtTQ4+WsIwQSMrHtO71XInRLZISFySTySlhVBHx9vY6NGP6NW5FSGDP16j60+Cye0jUA9aFXqx
olawg2pk7MLRxRh0SZv/equrBBQ1BCJJ5w4NlIzZjZoHWaaMVTUyqUa7QZPNfieZsgCq+qKEYP2Z
ozqV168N1zFGunLfDNw9WYIhd6Sbqk88khEt4GK0/b22zw7TJ0qP0in4ScOUD3aI963iLMZIfA8s
+KCtls2WQkTiRkpDPBrqEeycSoagIp8SFuAdmTubMGEfiwZr1AqgoWsvhyK/cC5DOLKohVVxedcG
gU/Rr8KsQxK7WJEeG0RqZu2c8hMHK8goGTfrS93pSQSjgnwQKNGb535uFI/mgzPTHwLsbwMEN920
qtBIi1Bvu4Vneu0pblwjrDvDlS/Zoo4RbaIOh6Ivx7E6A69+ZoU//Icn/IU7DoOrxZAxJw7s9HSB
OFBEK5rTT/JbZCevOCzBs8VvZtp1IPir5Lhlyyc2KHtsWq8bGPcE2lhVXXe/zyq0B0EduJJ/Flss
yqacpcRKyZPGQdS6+oFP09ipmgT9YKZ3Jawedl/aD3F2atTH7VDKqd2ULRUIcn1GH7ueaLjhfOdI
/8EVlZB/HM88JTcwCJMTlR/GokZR6kuNHsm3XM3iq2pSDEK2nMWqjpw+NJLjT13blghJpMnrD1wU
l0zQ+gMHusxVjO4gpHx22Nvwn9ozfmjazHfqKkEdhPCopgTLAACBMweuD9VGuL0XJNHP5AQoBS8X
doGNpdK1le2rybDuzhjh/LzKuv1bFOUIMVl6RjtydxgBSuukZ0wamvvqVmPfem8Nrby5VlLxYn86
x5qSrk1jWV0vkhbp0or7ld3eKNaQkFt9lvYCIJMlJ/32YtCSF7G0BnXjlhDkzCtsDQAAABcGgrAB
CYCCAAcLAQABIwMBAQVdABAAAAyAngoB2QsaJAAA
Last edited by gilbert_given_189 (Dec. 9, 2024 13:32:49)
- mybearworld
-
Scratcher
1000+ posts
Advent Of Code 2024
(#68)How do you decode these?
Day 9 - SolutionN3q8ryccAAQjU+2pMgMAAAAAAAAjAAAAAAAAAGiKfpxzxGepcmxlWEBQfjejkTh5vEbe54laLsWP
-snip-
CYCCAAcLAQABIwMBAQVdABAAAAyAngoB2QsaJAAA
- gilbert_given_189
-
Scratcher
1000+ posts
Advent Of Code 2024
See the first 2 bytes.(#68)How do you decode these?
Day 9 - SolutionN3q8ryccAAQjU+2pMgMAAAAAAAAjAAAAAAAAAGiKfpxzxGepcmxlWEBQfjejkTh5vEbe54laLsWP
-snip-
CYCCAAcLAQABIwMBAQVdABAAAAyAngoB2QsaJAAA
- ideapad-320
-
Scratcher
1000+ posts
Advent Of Code 2024
Day 9 - DiscussionWhyyyy? Why don't you just put some code before the break? Also, it is a good idea to put curly braces even for 1 like long loops.
I started a bit late because I had a class today. The first part seems like it's meant to be used with linked lists. I tried to be clever with the second part [by representing the disk as file indices much like filesystems], but that didn't work out so I had to do it data recovery style.
Also, this day made me think of a weird feature for for-loops (and any other loop really): a break that return some value. So something like this:In this example, when the condition is met, the for-loop breaks, and execution continues on the `catch` block first. Otherwise, it continues to the `else` block (if it's defined). After that, execution goes as usual.for (let i in something) { if (something[i] == solution) break i; } catch (i) { // do something with i } else { // what to do when the break carries no value } // everything else is normal
I think this is best fit with pattern matching, but that doesn't feel like JavaScript, so no examples for that here.
Day 9 - SolutionN3q8ryccAAQjU+2pMgMAAAAAAAAjAAAAAAAAAGiKfpxzxGepcmxlWEBQfjejkTh5vEbe54laLsWP
pxUAoEI8XZRw+zEhRd/g5i8yMtCghQyaWz6m/62QjxIGnDhnxlRKXWJI+vsLY6tbXhqMISF5sUo6
tr4qjQ6JtGQCO0UECWuBtx0xwRq0/mnxBMVO1bm6lQgGKZUROD492OoZs/VU7p1b0MlE6GP5SByy
YqJtTQ4+WsIwQSMrHtO71XInRLZISFySTySlhVBHx9vY6NGP6NW5FSGDP16j60+Cye0jUA9aFXqx
olawg2pk7MLRxRh0SZv/equrBBQ1BCJJ5w4NlIzZjZoHWaaMVTUyqUa7QZPNfieZsgCq+qKEYP2Z
ozqV168N1zFGunLfDNw9WYIhd6Sbqk88khEt4GK0/b22zw7TJ0qP0in4ScOUD3aI963iLMZIfA8s
+KCtls2WQkTiRkpDPBrqEeycSoagIp8SFuAdmTubMGEfiwZr1AqgoWsvhyK/cC5DOLKohVVxedcG
gU/Rr8KsQxK7WJEeG0RqZu2c8hMHK8goGTfrS93pSQSjgnwQKNGb535uFI/mgzPTHwLsbwMEN920
qtBIi1Bvu4Vneu0pblwjrDvDlS/Zoo4RbaIOh6Ivx7E6A69+ZoU//Icn/IU7DoOrxZAxJw7s9HSB
OFBEK5rTT/JbZCevOCzBs8VvZtp1IPir5Lhlyyc2KHtsWq8bGPcE2lhVXXe/zyq0B0EduJJ/Flss
yqacpcRKyZPGQdS6+oFP09ipmgT9YKZ3Jawedl/aD3F2atTH7VDKqd2ULRUIcn1GH7ueaLjhfOdI
/8EVlZB/HM88JTcwCJMTlR/GokZR6kuNHsm3XM3iq2pSDEK2nMWqjpw+NJLjT13blghJpMnrD1wU
l0zQ+gMHusxVjO4gpHx22Nvwn9ozfmjazHfqKkEdhPCopgTLAACBMweuD9VGuL0XJNHP5AQoBS8X
doGNpdK1le2rybDuzhjh/LzKuv1bFOUIMVl6RjtydxgBSuukZ0wamvvqVmPfem8Nrby5VlLxYn86
x5qSrk1jWV0vkhbp0or7ld3eKNaQkFt9lvYCIJMlJ/32YtCSF7G0BnXjlhDkzCtsDQAAABcGgrAB
CYCCAAcLAQABIwMBAQVdABAAAAyAngoB2QsaJAAA
- davidtheplatform
-
Scratcher
500+ posts
Advent Of Code 2024
Also, this day made me think of a weird feature for for-loops (and any other loop really): a break that return some value. So something like this:You can make this with exceptions (at least in python, and this is untested but the concept should work):In this example, when the condition is met, the for-loop breaks, and execution continues on the `catch` block first. Otherwise, it continues to the `else` block (if it's defined). After that, execution goes as usual.for (let i in something) { if (something[i] == solution) break i; } catch (i) { // do something with i } else { // what to do when the break carries no value } // everything else is normal
class LoopReturnException(Exception): def __init__(self, value): self.value = value try: for i in range(10): if i == 5: raise LoopReturnException(some_value) except LoopReturnException as e: print(f'Loop returned {e.value}') else: print('Loop did not return a value')
Last edited by davidtheplatform (Dec. 9, 2024 19:14:55)
- davidtheplatform
-
Scratcher
500+ posts
Advent Of Code 2024
Day 9 - Discussion
I felt like part 1 and 2 were very similar in difficulty, unlike previous days. My part 2 solution was slow again, around 30s. I think its possible to do part 2 in a single pass by [finding all of the file sizes, then repeatedly finding the highest file id that fits in the next free space, updating the free space list whenever you add a file to it.]
The defragmentation method used in the problem isn't very good. Shifting each file all the way left, starting with the leftmost file would be a lot better and would only require a small amount of memory (enough to store one block)
I felt like part 1 and 2 were very similar in difficulty, unlike previous days. My part 2 solution was slow again, around 30s. I think its possible to do part 2 in a single pass by [finding all of the file sizes, then repeatedly finding the highest file id that fits in the next free space, updating the free space list whenever you add a file to it.]
The defragmentation method used in the problem isn't very good. Shifting each file all the way left, starting with the leftmost file would be a lot better and would only require a small amount of memory (enough to store one block)
- ideapad-320
-
Scratcher
1000+ posts
Advent Of Code 2024
Why not:Also, this day made me think of a weird feature for for-loops (and any other loop really): a break that return some value. So something like this:You can make this with exceptions (at least in python, and this is untested but the concept should work):In this example, when the condition is met, the for-loop breaks, and execution continues on the `catch` block first. Otherwise, it continues to the `else` block (if it's defined). After that, execution goes as usual.for (let i in something) { if (something[i] == solution) break i; } catch (i) { // do something with i } else { // what to do when the break carries no value } // everything else is normalclass LoopReturnException(Exception): def __init__(self, value): self.value = value try: for i in range(10): if i == 5: raise LoopReturnException(some_value) except LoopReturnException as e: print(f'Loop returned {e.value}') else: print('Loop did not return a value')
for(int i = 0; i < count; i++){ if([something]){ puts("Early Exit!"); goto early; } } puts("Normal Exit!"); early: ; //null statement does nothing. Here because a label must not be at the end of a code block. Not required if there is more code below it other than an end of a blocks.
normalExit=true for i in range(10): if [something]: normalExit=false print("Early Exit") break if normalExit: print("Normal Exit")
Last edited by ideapad-320 (Dec. 9, 2024 20:48:01)
- davidtheplatform
-
Scratcher
500+ posts
Advent Of Code 2024
~snip~Using exceptions results in significantly cleaner code, IMO. But I agree this isn't what they're supposed to be used for and that can be a good reason not to use them here, it's just the first thing I came up with.
Exceptions are for error handling, not exiting loops.
- gilbert_given_189
-
Scratcher
1000+ posts
Advent Of Code 2024
You can make this with exceptions (at least in python, and this is untested but the concept should work):That's kinda what I did with the part 2 solution. It's kinda hacky, sure, but you couldn't tell me otherwiseclass LoopReturnException(Exception): def __init__(self, value): self.value = value try: for i in range(10): if i == 5: raise LoopReturnException(some_value) except LoopReturnException as e: print(f'Loop returned {e.value}') else: print('Loop did not return a value')

- 50_scratch_tabs
-
Scratcher
1000+ posts
Advent Of Code 2024
Anyone aware of for-else syntax in Python? The else runs unless you break.
- gilbert_given_189
-
Scratcher
1000+ posts
Advent Of Code 2024
Anyone aware of for-else syntax in Python? The else runs unless you break.I forgot that's a feature in Python! Yeah, I learned that in May, but I seem to have forgotten that.
Last edited by gilbert_given_189 (Dec. 10, 2024 04:03:29)