Advent of Code 2024 (Python) - day 25
55:19
12 сағат бұрын
Advent of Code 2024 (Python) - day 24
4:05:09
12 сағат бұрын
Advent of Code 2024 (Python) - day 23
1:05:28
16 сағат бұрын
Advent of Code 2024 (Python) - day 22
52:55
19 сағат бұрын
Advent of Code 2024 (Python) - day 21
3:39:28
19 сағат бұрын
Advent of Code 2024 (Python) - day 20
1:01:00
21 сағат бұрын
Advent of Code 2024 (Python) - day 18
1:06:22
Advent of Code 2024 (Python) - day 17
2:40:14
Advent of Code 2024 (Python) - day 16
1:33:54
Advent of Code 2024 (Python) - day 15
2:02:35
Advent of Code 2024 (Python) - day 14
1:08:10
Advent of Code 2024 (Python) - day 13
1:35:13
Advent of Code 2024 (Python) - day 11
34:14
Advent of Code 2024 (Python) - day 12
1:17:24
Advent of Code 2024 (Python) - day 10
52:17
Advent of Code 2024 (Python) - day 9
1:21:54
Пікірлер
@RedXGMR777
@RedXGMR777 2 күн бұрын
@biray4710
@biray4710 5 күн бұрын
I am a bit late to the party, I just started the Advent of Code today. If anyone is curious about the regex questions, in part one you can catch the numbers directly by using capturing groups(put numbers in separate parathesis). (\d{1,3}) or (\d\d?\d?) to capture the first number for example. {1,3} = {min 1, max 3} occurrence. Doing a re.findall(pattern,data) will give you a list of tuples if you grouped both numbers. Then loop through tuples and do the calculations. In part two I used regex to catch anything between a do() don't() block using positive lookbehind, and positive lookahead. Make sure to add the string until the first occurrence of don't. Since do() is implied at the beginning and there is no written do(), regex misses that first part. It will be something like clean_data = data[:first_dont] + str(re.findall(pattern, data)). After the clean data is set, repeat part 1 with clean_data as the data.
@FuerstOpus42
@FuerstOpus42 7 күн бұрын
You came so close to my solution, but then saw the problem with the for loops before you actually implemented them. They cost me almost 40 seconds vs your solution for counting the bananas.
@FuerstOpus42
@FuerstOpus42 9 күн бұрын
What? The picture is OBVIOUSLY a snake! Why would it be a 10? ;-)
@kuntsevichsergey
@kuntsevichsergey 9 күн бұрын
In get_num_good_cheats you can go over points/coordinates in shortest path - no need in looping over grid, extra get and # comparison: good_cheats = 0 for cheat_start in from_start: for ik in range(-max_cheat_length, max_cheat_length + 1): jk_max = max_cheat_length - abs(ik) ....
@hextree
@hextree 9 күн бұрын
Yup, that's true
@fastwebcam
@fastwebcam 11 күн бұрын
26:30 Silver star means they solved part 1 but not part 2. It is not a failure rate. It is difficulty of part 2 compared to part 1. A better way to estimate difficulty is to compare with the previous day. Days 7,10,13,18 are easyer. Days 6,9,12,15 are harder.
@fastwebcam
@fastwebcam 11 күн бұрын
28:07 And my comment goes to waste, lol
@hextree
@hextree 11 күн бұрын
Yes, I mainly use the stars to judge the difficulty of part 2, because that's the part I tend to be interested in. At least, in earlier years I usually felt like part 1 was a light 'warm up' for the real thing, but admittedly this year that doesn't tend to be the case, part 2 feels a lot less predictable.
@heartmelt_dancer
@heartmelt_dancer 11 күн бұрын
I know who it was:)
@Questron64
@Questron64 12 күн бұрын
I may have gone overboard. To solve day 12 I wrote a JSON parser by hand in C.
@hextree
@hextree 12 күн бұрын
Haha, nice.
@FuerstOpus42
@FuerstOpus42 12 күн бұрын
You can use underscores in numbers and Python will ignore them. Type 100_000_000. Easyish for you to read, and Python sees 100000000
@hextree
@hextree 12 күн бұрын
Oh, nice
@fastwebcam
@fastwebcam 12 күн бұрын
This one was brutal. I spent 5 hours trying to figure it out. Then I managed to solve part 2 in four lines in Python. It was hidden in the plain sight.
@hextree
@hextree 12 күн бұрын
What was your solution?
@fastwebcam
@fastwebcam 12 күн бұрын
​@@hextree My input.txt is similar. It divides A by 8, outputs B % 8 and jumps from the end to 0. B and C are reset every iteration. The length is also 16. I have been experimenting in python's command line for a few hours before I noticed it. I found the answer in a very complicated manual way. Then it hit me. # The function execute(a,b,c,program) is defined in part 1 # This is the entire part 2 a = [0] for i in reversed(range(len(program))): a = [j*8+k for j in a for k in range(8) if execute(j*8+k,0,0,program) == program[i:]] return min(a) It calculates the answer 3 bits per iteration. The trick is you can take first N digits of the answer, run the program and it should output the last N numbers of the program. Then you shift it 3 bits to the left and add the next octal digit.
@hextree
@hextree 12 күн бұрын
Nice, this is a lot more compact. And easier to understand now that I've had 1 day to clear my head of nonsense haha. Definitely I was a bit too hung up on using binary digits, which wasn't necessary, but I guess it reflected how I was visualising the number.
@ОлександрЧеревко-п4з
@ОлександрЧеревко-п4з 14 күн бұрын
Very atmospheric game, I'm glad you mentioned this classic.
@FuerstOpus42
@FuerstOpus42 17 күн бұрын
One night in Bangkok? kzbin.info/www/bejne/iny5gWmHraqZY5I
@FuerstOpus42
@FuerstOpus42 17 күн бұрын
OMG! You've been posting on GitHub?!? I've been pausing/replaying to copy your code so that I can play with it.... Maybe better my way though because I've keyed it in and understand it better. But I need to learn how to use Git.
@FuerstOpus42
@FuerstOpus42 20 күн бұрын
Ok, I''ve changed twitch names
@Questron64
@Questron64 21 күн бұрын
I opened this video to see if I'd gone completely insane. I somehow got stuck on the very first problem. I've been programming for almost 40 years, and I got stuck on the first problem. How? HOW? No, I'm not crazy, there's no trick I'm missing. The problem? Somehow, and I don't really know why, copy and pasting a large amount of parentheses from Firefox into vim is not reliable. I should have just saved the file from Firefox.
@hextree
@hextree 21 күн бұрын
Oof, yes I usually copy and paste these days but I really should save file to be safe.
@FuerstOpus42
@FuerstOpus42 21 күн бұрын
It looks like XKCD comic #353 came out Dec 5 2007, and the antigravity module was added to Python in Oct 2008
@fastwebcam
@fastwebcam 22 күн бұрын
8:16 About disallowing antinodes on the 'insides'. You can think about the 'twice as far away' condition as if it was a geometric vector. It means the direction must be the same. An antinode 'inside' would need 'negative twice as far away'.
@hextree
@hextree 21 күн бұрын
Hmm. Interesting thought, but I'm not convinced people use the term that way. For instance in casual conversation if I had a shop 1 mile North of my house, and a park 2 miles South of my house, I would comfortably say "the park is twice as far away as the shop". It seems valid to me.
@povijarrro
@povijarrro 23 күн бұрын
Hello. Nice videos. I just made wraper Int class with __lt__(self,other) that returns (self.value,other.value) in self.orders And uses lambda x:Int(x,orders) as key for sorted function orders is list of tuples (int(a),int(b)) where a|b is line of input
@FuerstOpus42
@FuerstOpus42 24 күн бұрын
GPT cheaters, VIDEO or it didn't happen! That's the only way, but how do you automate/verify that?
@FuerstOpus42
@FuerstOpus42 24 күн бұрын
My sorting for this was totally naive, but I have to boost Umaro's recommendation of dequeue. I have preferred it's methods in many algorithms over the basic queue. My understanding is that Queue has been designed to be "threadsafe", while dequeue is just a basic workhorse datastructure.
@hextree
@hextree 24 күн бұрын
Yeah, I've used dequeue for a couple of problems for FIFO stuff, usually when it's a Stack though I'm too lazy to import it.
@wiktortumilowicz
@wiktortumilowicz 25 күн бұрын
instead of constructing the diagonals like you did in your first attempt you can construct a new matrix by incrementally padding each row by 1 character: new_mat[i]= "0"*i +mat[i] then take the amount of matches in the vertical and reverse the padding(0 for the bottom) for the other diagonal:) for part 2 i had to write completely different code tho haha
@FuerstOpus42
@FuerstOpus42 26 күн бұрын
Thanks for going the regex route. I was afraid to go that way because I couldn't remember how to implement, I need to work on that. Regex looks much cleaner than what I wrote. The input was a bit forgiving. They didn't use numbers with more than 3 digits (which would have messed up my answer) and didn't have any do or don't without the parentheses which I think would have messed up yours.
@hextree
@hextree 26 күн бұрын
Yes, I realised afterwards that I had forgotten the parentheses.
@Reinault
@Reinault 27 күн бұрын
I would love more explaining about the resolution in future videos. I am not a pro, and can't really understand how such a simple solution works.
@matheusf3115
@matheusf3115 27 күн бұрын
Why use counter? In my code i Just use count()
@hextree
@hextree 27 күн бұрын
Counter is more efficient because it makes a single linear-time pass through the data, and stores the counts in a hash table, so that in all future queries you can access the count in constant time. The count() method recomputes the count each time it is called, so uses linear time each call. So for 1000 items of data, you'd be doing about 1,000,000 operations with count() instead of 1000 with Counter. For this problem it didn't matter, as the input size is small, however for later problems in AoC you may need that linear-time efficiency.
@vlinden1
@vlinden1 26 күн бұрын
Thank you for your clear explanation. I was wondering the same thing and it makes so much sense after reading your reply!
@lsw_tex
@lsw_tex 27 күн бұрын
I see you remembered your coffee today! 😄
@Ohmaha
@Ohmaha 29 күн бұрын
Hi. Thank you for the great approach to the solution.
@4kMikle
@4kMikle Ай бұрын
You know what, although this video has ZERO views with you having 352 subscribers (i subbed), just wanted to say: I love your haircut
@julianvision6705
@julianvision6705 Ай бұрын
3:02 3:02 3:03
@thisentity7945
@thisentity7945 Ай бұрын
how come when I shoot the purple pads I don;t get teleported
@hextree
@hextree Ай бұрын
Hmmm, I don't remember many of the details. You could ask in the Kitatcho Discord, the devs of the game might be able to help you: discord.com/invite/Jw35VzkjCA
@fastwebcam
@fastwebcam 2 ай бұрын
15:50 What a f.... Oh my God!
@davidalden4114
@davidalden4114 2 ай бұрын
This one was hard
@TheRetroEngine
@TheRetroEngine 2 ай бұрын
Why is watching this so addictive.
@MARStheFORSAKEN
@MARStheFORSAKEN 3 ай бұрын
Leave the skeletons alone! they already died once,that even worse then kicking someon whil hey are down. XD
@hextree
@hextree 3 ай бұрын
Nah man, I heard these skeletons used to be humans who would always applaud when their airplane lands - they must suffer for this.
@JetLagRecords
@JetLagRecords 4 ай бұрын
HexTree, you're on a roll with your videos
@brother4lifeb4l42
@brother4lifeb4l42 4 ай бұрын
wo bekomme ich das Spiel her ?
@PietWoldinga
@PietWoldinga 5 ай бұрын
Part2 of Day11 can be done much easier after analysing what's in the grid. Possible values are -5, -4, -3, -2, -1, 0, 1, 2, 3, 4. Each value appears about 30 times per row. (r153): {-4: 30, 1: 30, -3: 31, 3: 31, -2: 31, 4: 30, 0: 29, -5: 29, 2: 29, -1: 30} total 300 (r1): {-4: 30, 1: 30, -3: 31, 3: 31, -2: 31, 4: 30, 0: 29, -5: 29, 2: 29, -1: 30} total 300 (r122): {4: 29, -2: 29, 2: 29, -4: 29, 1: 32, -5: 31, -1: 31, 3: 31, 0: 28, -3: 31} total 300 (r300): {1: 30, 2: 30, 3: 30, 4: 30, -5: 30, -4: 30, -3: 30, -2: 30, -1: 30, 0: 30} total 300 4 is the maximum value a power cell can get, in that case a square of 30x30 would give the maximum value of 2700. But that will not be the case as any square will not only be filled with 4'ths but also with a couple of -5'ths and -4'ths as well as 2'ths and ... Therefore the square containing the maximum will be of a size between 3 (that one we found in part 1) and 31. So my search don't have to be from 4 to 301 but can be reduced to from 4 to 31. Takes about 10 seconds, worked for my SN. Your SN solution however is strangely different from mine using yours. SN = 2866 Day 11 Part 2: Chronal Charge. The X,Y,S size identifier of the square with the largest total power 90 is (238, 277, 10). [Done] exited with code=0 in 10.687 seconds
@hextree
@hextree 5 ай бұрын
Interesting approach. I'm not entirely sure how you are able to fully rule out squares larger than 31x31 having max values. It is theoretically possible a 32x32 square could be filled with 4s and 3s. But I suppose your argument is more of a statistics one: the data appears to be roughly randomly distributed, so the chances of a large square being positive-dominant is vanishingly small.
@PietWoldinga
@PietWoldinga 5 ай бұрын
@@hextree Indeed theoretically everything is possible but in the end the power calculation is the hundred bit or zero. So the bit (or not) is [0-9] and that minus 5 give a cell power of [(-5)-4]. Statistically indeed when 300 every cell power value occurs 30 times, Because it is a well out thought calculation the theoretical maximum square must be around the 30x30 but in case of the calculation that won't occur and so the maximum square must be lower than 30x30.
@hextree
@hextree 5 ай бұрын
@@PietWoldinga I still don't quite understand why the theoretical maximum square would be 30x30. Wouldn't it be 120x120? I.e. a square where each row has 30 4's, 30 3's, 30 2's and 30 1's.
@PietWoldinga
@PietWoldinga 5 ай бұрын
​@@hextree That won't happen. Let's say we have 10 numbers in a row. Than by calculation we get i.e. -5, -4, -3, -2, -1, 0, 1, 2, 3, 4 or maybe -5, -4, 1, -2, -1, 0, 1, 2, 3, 4 or .. but it will be filled with an average of 1 per value. So in case of 300 digits in a row and having 10 possible values (from a well thought calculation I may presume as AoC is)(or just print the grid and you'll see) every value appears by 30 times average. In a hypothetical world there would be a square in the grid that consists of 900 4th's. But sadly this nice and beautiful hypothetical world doesn't exist we have to deal with all kinds of setbacks! So, a 30x30 square is statistically the utmost appearance of that beautiful world. A square of 3x3 is investigated in Part1 so I let my code search for 'for s in range(4, 31)' (I have a grid of 301x301 and I just don't use the zero row and column). That search will take (my laptop) me about 10 seconds. Actually that's not acceptable but hey! (I want my code to be within 2 seconds done.)
@hextree
@hextree 5 ай бұрын
@@PietWoldinga right, but my theoretical 120x120 square is only using 30 instances of each of 4, 3, 2 and 1, so it is not exceeding the 30 average per digit per row.
@Zoolar
@Zoolar 5 ай бұрын
Great, Thanks.
@lionelmidrouillet7088
@lionelmidrouillet7088 6 ай бұрын
Hi HexTree, Thank u so much for sharing. I'm really intersting in Challenges from codingame. Sseeing and hearing your videos is very enriching. I am working on your code to try to understand it. I would like to get your advice about this (in video day 2) : return {"UP": jump_state, "LEFT": run_states[0], "DOWN": run_states[1],"RIGHT": run_states[2]} wouldn't be replace by return {"UP": jump_state, "LEFT": run_states[0], "DOWN": run_states[1],"RIGHT": run_states[-1]} to be get the really pos and really stun from right next step. Tanks from France and please keep on sharing your videos.
@lionelmidrouillet7088
@lionelmidrouillet7088 6 ай бұрын
Sorry, wrong copy from clipboard . I wanted to say: return {"UP": jump_state, "LEFT": run_states[0], "DOWN": run_states[1],"RIGHT": run_states[len(run_states)-1]}
@hextree
@hextree 6 ай бұрын
Hi @lionelmidrouillet7088, thanks for your interest. Just to be clear, are you asking whether it's fine to access the final run_state using index [-1] instead of [2]? Yes, I think this would be fine. Normally, I only use the [-1] index if the list is sorted in some order, and I specifically want the one at the rightmost position. In this case I would probably prefer [2], because the list isn't in any particular order, and maybe in the future I might add new states to the list, which would cause [-1] to point to the wrong thing. Nevertheless, both methods are fine as long as you are aware of the context.
@lionelmidrouillet7088
@lionelmidrouillet7088 6 ай бұрын
@@hextree Hi Hextree' Thanks for your answer. In fact i tried to debug your code, from this video. By using break points I saw a run_states with more than 3 records (5 exacttly). And then, if we take the run_states[2] for the RIGHT movement, we won't get the real next state for the right movement. For example, to be more clear, let's get the HURDLE_TRACK "......#...#....#....#........." and my playe'rs position 3. With this code, run_states = [] for dist in range(1 , 4): for pos in range(self.pos+1,self.pos+dist+1): if is_hurdle(pos): run_states.append(HurdleState(pos, 2)) break else: run_states.append(HurdleState(self.pos+dist, 0)) #return {"UP": jump_state, "LEFT": run_states[0], "DOWN": run_states[1],"RIGHT": run_states[2]} we will have run_states[2].pos=5 and run_states[2].stun=0 ....although, for a rght movement from 3, in this HURDLE_TRACK,we will have pos 6 and stun 2. So i tried to change: return {"RIGHT": run_states[2],"UP": jump_state, "LEFT": run_states[0], "DOWN": run_states[1]} for return {"RIGHT": run_states[len(run_states)-1],"UP": jump_state, "LEFT": run_states[0], "DOWN": run_states[1]} But... it is not a good idea. It doesnt work. The better idea - i think - to get a run_states with 3 records for the las state for each movement, is to insert else: --->>>>> if pos==self.pos+dist: run_states.append(HurdleState(self.pos+dist, 0))
@lionelmidrouillet7088
@lionelmidrouillet7088 6 ай бұрын
it can be read at 1:26:24 , lines 30..35
@iamnoob7201
@iamnoob7201 6 ай бұрын
i don't really understand the case of game_over and score can you explain it
@koopanique
@koopanique 6 ай бұрын
I love that you play the original -- it's pretty rare to see it on KZbin. Usually people play the FreeSpace port (which is technically the best option, but the actual original game has its charm too)
@hextree
@hextree 6 ай бұрын
Yes, the original game is required for the speedrun. And thankfully the original game seems to function better than the original Freespace 2 does. If I play the game casually I would probably opt for the port.
@stephenberg6438
@stephenberg6438 7 ай бұрын
There was another way to complete that brutal water gem island puzzle. At 4:30:27 you died on the spikes on the exact same frame that the box arrived at the bottom of the waterfall, and for some reason when you revived the box moved back one square. At that point all you had to do was push the box up onto the button and the puzzle was solved! I'm glad you went for the intended solution, though, since that's definitely a glitch. By the way, thanks for posting this! I've nearly 100%ed the game, but that screen was giving me a ton of trouble and it's so new that no full guides are out yet.
@Luckmage26
@Luckmage26 7 ай бұрын
I tried to complete the puzzle at 3:56:00 for a good 40 minutes to no avail... I've just closed the game, opened your video and immediately figured it out AHAHAH Great video! Hope you continue playing the game (I'd love some help on the biome you haven't visited yet)
@FuerstOpus42
@FuerstOpus42 7 ай бұрын
Congrats! Surprised that you managed it manually as easily as you did. After mapping it out, I created a list of commands to input that would navigate the ship, pick up all items, and leave me at the security gate so that I could play manually at that point. After a few tries manually, I gave up and added a function that would generate commands to try all possible combinations of items. So, yes, you can just automate it. And, yes, they've obsfucated the text in the intcode. Took a quick peek, and didn't bother trying to figure it out. Dating myself, but I was reminded of looking at memory contents of Scott Adams' text adventure games in 1980. In those games, the verbs and nouns were visible in the clear (verbs could be some help) but the game text was not. I'm working on 2020 and will then do 2022. Will probably wait until you start 2021 before starting that. More fun to watch you when the problems are fresh in my head.
@hextree
@hextree 7 ай бұрын
Nice. I can now see how it would just be a few more lines to automate all the way up to clearing the checkpoint. Yes, probably some time in the next few months I will try to clear 2021.
@LeroyZee
@LeroyZee 7 ай бұрын
I have seen everything. A Teletubbies speed run?
@FuerstOpus42
@FuerstOpus42 7 ай бұрын
You were going to solve this by multi-threading, and I was starting to think 'Wow, it's that easy to do?' And then the Pickler couldn't pickle the thread.lock object?!??!? So I went back to thinking I'll avoid threads for now. There was a problem (might have been 2017 Day 18) where you had 2 programs that were sending and receiving. After I solved it, I saw that people were using co-routines (in Python) to solve it. I'm not sure if I knew about yield or generators at that point, but I sure didn't understand co-routines (still don't really). For this problem (2019 Day 23) I knew that my intcode was a generator because it returned values with yield. When it was locking up, I thought back to that other problem and wondered if I needed to turn my IntCode into a co-routine. I don't know if I accomplished that, but I did get my answer. I already had a yield for opcode 4 sending the output, so for opcode 3 getting the input I added: if not self.inp: yield else: and then the original code here I'm using a list instead of a queue. I think your first line would be. if self.q.empty() I didn't test it on older days, but it's a minimal change that I don't think would break them, and it didn't cause a problem with Day 25.
@FuerstOpus42
@FuerstOpus42 7 ай бұрын
Nice job! If I ever learned any modular arithmetic it was in an Abstract Algebra class that I didn't do very well in 30+ years ago. Didn't remember/recognize any of this. So I needed more hints and did a lot of reading about the math online. Kicked myself when you solved for a and b so simply (running inverse on 0 and then 1). My inverse shuffle routine used a formula with c and d for each technique (like what you wrote in Paint) that were then used to update the overall a and b values for the full shuffle. It got me there, but with a bunch of extra work/code. I was too deep in the minutia of the problem to be able to step back and see the easier solution.
@Glitchesftw
@Glitchesftw 7 ай бұрын
beast
@FuerstOpus42
@FuerstOpus42 8 ай бұрын
You seem to be in the other camp, OK, but I *loved* the IntCode days because they were a black-box that allowed Eric to make puzzles that he couldn't do otherwise. On this day, if you could just see the map of the hull, you could quickly program the bot. But having to use the bot's input made it a different experience. I actually laughed out loud when I got to IntCode Day 25
@hextree
@hextree 8 ай бұрын
Yes, I am enjoying the IntCode too, I think they are very original problems and a refreshing change from what I'm used to. Did I say otherwise in the video? I can't remember. But if so, I probably meant that a sense of dread comes up when IntCode comes up, because I know I might have to use my brain for something tricky. But still overall enjoying them. Back in the Google Code Jam they sometimes had 'online algorithm' problems, which is sort of similar as you had to make continuous requests and receive responses from a black box program online.
@FuerstOpus42
@FuerstOpus42 8 ай бұрын
@@hextree I think it was the dread coming through. Mainly, I've just enjoyed the IntCode problems more than the virtual machines that we've made in other years and then had to disassemble their input as the puzzle. Plus, I'm not sure how much Python I learned from those others. With the IntCode problems I've been surprised at the power of Python generators (still learning), and working on understanding coroutines. Thanks again for the vids!
@daniellesmith3796
@daniellesmith3796 8 ай бұрын
I like your videos
@FuerstOpus42
@FuerstOpus42 8 ай бұрын
Knew you'd have a quick solution (faster than me) once you wrapped your head around Part 2! Was on my way to finishing 2019 and then hit day 22 (very happy with the class I built for Part 1, but not a clue how to approach Part 2) Then you got me on Planet Crafter, so I'll probably finish that before returning to AoC.