- 158
- 28 273
Wekoslav Stefanovski
Приєднався 26 тра 2013
Advent Of Code 2024 - Day 9 (Part II) - Debugging
Day 9 - Of course, the error was trivial to fix, but not so trivial to notice. I did some investigations, and then it was obvious what the problem is, and also, how to fix it. #adventofcode
- The task description adventofcode.com/2024/day/9
- The code that was shown github.com/sweko/AdventOfCode/blob/master/2024/ts/day-09/code.ts
- The task description adventofcode.com/2024/day/9
- The code that was shown github.com/sweko/AdventOfCode/blob/master/2024/ts/day-09/code.ts
Переглядів: 43
Відео
Advent Of Code 2024 - Day 22 (Part I) - Monkey Business
Переглядів 4119 годин тому
Day 22 - So, we had to do some business dealings with monkeys, and it turned out, it's a simple generational algorithm, that was complicated by JavaScript's bit management support. BigInt to the rescue #AdventOfCode - The task description adventofcode.com/2024/day/22 - The code that was shown github.com/sweko/AdventOfCode/blob/master/2024/ts/day-22/code.ts
Advent Of Code 2024 - Day 14 (Part I) - Rowing Robots
Переглядів 8621 годину тому
Day 14 - Well, I'm back in the saddle. After a few days off after the final task was announced, let's get the stars that got away, starting with this simple simulation task for the first part. #AdventOfCode - The task description adventofcode.com/2024/day/14 - The code that was shown github.com/sweko/AdventOfCode/blob/master/2024/ts/day-14/code.ts
Advent Of Code 2024 - Day 25 - Chief Historian Located
Переглядів 3714 днів тому
Day 25 - For the last puzzle of the year we got a fun task, where we actually had to brute force our way to the answer, in addition to some convoluted parsing of the input. We did manage to find the Chief Historian (who was sleeping in his office all this time), but I still lack 15 stars in order to complete and take the historical chronicle to Santa. Don't worry, we'll get to that in the comin...
Advent Of Code 2024 - Day 24 (Part I) - Logic Circuits
Переглядів 4914 днів тому
Day 24 - Today we got some logic circuits simulations that we needed to execute for part I, and that part was easy and successful. For part II we would need to do some analysis, which might not be so easy #AdventOfCode - The task description adventofcode.com/2024/day/24 - The code that was shown github.com/sweko/AdventOfCode/blob/master/2024/ts/day-24/code.ts
Advent Of Code 2024 - Day 23 (Part I) - There's no party like a LAN party
Переглядів 3614 днів тому
Day 23 - The first part of the task was quite easy, once we got a proper data structure to load our input into. I feel the structure will be useful for the second part as well, just don't know how yet #AdventOfCode - The task description adventofcode.com/2024/day/23 - The code that was shown github.com/sweko/AdventOfCode/blob/master/2024/ts/day-23/code.ts
Advent Of Code 2024 - Day 21 (Part I) - Simulation
Переглядів 8414 днів тому
Day 21 - Some good news, some bad news. We successfully implemented a class that simulated the robots, and were able to verify any input sequence. We did not get a star (yet), but it's not far off #AdventOfCode - The task description adventofcode.com/2024/day/21 - The code that was shown github.com/sweko/AdventOfCode/blob/master/2024/ts/day-21/code.ts
Advent Of Code 2024 - Day 20 (Part I) - Utter failure
Переглядів 5814 днів тому
Day 20 - Total and utter failure in our race condition. Well, somewhat. We managed to parse and prepare the input, unfortunately there's a small bug hiding somewhere so that our implementation gives the wrong result. The good news is we get to debug our solution for Part II #AdventOfCode - The task description adventofcode.com/2024/day/20 - The code that was shown github.com/sweko/AdventOfCode/...
Advent Of Code 2024 - Day 19 (Part II) - Fancier Recursion
Переглядів 2514 днів тому
Day 19 - Another fun task, where our simple recursion worked for the demo input, but not on the real one. Fortunately, some dynamic caching solved the problem, and we managed to salvage most of it for part II - #AdventOfCode - The task description adventofcode.com/2024/day/19 - The code that was shown github.com/sweko/AdventOfCode/blob/master/2024/ts/day-19/code.ts
Advent Of Code 2024 - Day 19 (Part I) - Fancy Recursion
Переглядів 4214 днів тому
Day 19 - Another fun task, where our simple recursion worked for the demo input, but not on the real one. Fortunately, some dynamic caching solved the problems (for now). We'll see what we can salvage for part II - #AdventOfCode - The task description adventofcode.com/2024/day/19 - The code that was shown github.com/sweko/AdventOfCode/blob/master/2024/ts/day-19/code.ts
Advent Of Code 2024 - Day 18 (Part II) - Flooder fill
Переглядів 4321 день тому
Day 18 - Turns out we can just do a linear search and re-execute the first solution until it stops working - and that's the point we're looking for. Of course, we can improve this to a binary search, but for now, that's on the back burner #AdventOfCode - The task description adventofcode.com/2024/day/18 - The code that was shown github.com/sweko/AdventOfCode/blob/master/2024/ts/day-18/code.ts
Advent Of Code 2024 - Day 18 (Part I) - Flood fill
Переглядів 6721 день тому
Day 18 - I was a bit scared by my first read of the description, but then it turned out to be a simple flood fill, which worked quite well, and we got some nice matrices on the screen as well - #AdventOfCode - The task description adventofcode.com/2024/day/18 - The code that was shown github.com/sweko/AdventOfCode/blob/master/2024/ts/day-18/code.ts
Advent Of Code 2024 - Day 17 (Part II) - Input Analysis
Переглядів 6921 день тому
Day 17 - That was indeed extremely fun - and after the source code analysis and a lot of octal math, we even got to use recursion! #AdventOfCode - The task description adventofcode.com/2024/day/17 - The code that was shown github.com/sweko/AdventOfCode/blob/master/2024/ts/day-17/code.ts
Advent Of Code 2024 - Day 17 (Part I) - Emulation
Переглядів 16621 день тому
Day 17 - That was extremely fun - we got to use our computer to emulate a different computer, and it worked - we are masters of virtualization! Unfortunately, we'll need to do some weird source code analysis for the second part. #AdventOfCode - The task description adventofcode.com/2024/day/17 - The code that was shown github.com/sweko/AdventOfCode/blob/master/2024/ts/day-17/code.ts
Advent Of Code 2024 - Day 16 (Part I) - Pathfinding
Переглядів 7621 день тому
Day 16 - A bit late and a bit short - the solution for the first part of Day 16 is a simple pathfinding once we transformed our matrix to a graph with a bit weird nodes, and once I remembered that we're looking for the cheapest, and not the shortest path #AdventOfCode - The task description adventofcode.com/2024/day/16 - The code that was shown github.com/sweko/AdventOfCode/blob/master/2024/ts/...
Advent Of Code 2024 - Day 15 (Part I) - Warehouse simulation
Переглядів 12221 день тому
Advent Of Code 2024 - Day 15 (Part I) - Warehouse simulation
Advent Of Code 2024 - Day 13 - System of linear equations
Переглядів 6921 день тому
Advent Of Code 2024 - Day 13 - System of linear equations
Advent Of Code 2024 - Day 12 (Part I) - Flood fill
Переглядів 4221 день тому
Advent Of Code 2024 - Day 12 (Part I) - Flood fill
Advent Of Code 2024 - Day 11 (Part I) - Path finding
Переглядів 7428 днів тому
Advent Of Code 2024 - Day 11 (Part I) - Path finding
Advent Of Code 2024 - Day 10 (Part II) - Path finding
Переглядів 7028 днів тому
Advent Of Code 2024 - Day 10 (Part II) - Path finding
Advent Of Code 2024 - Day 10 (Part I) - Path finding
Переглядів 4028 днів тому
Advent Of Code 2024 - Day 10 (Part I) - Path finding
Advent Of Code 2024 - Day 9 (Part I) - Index Arithmetic
Переглядів 9328 днів тому
Advent Of Code 2024 - Day 9 (Part I) - Index Arithmetic
Advent Of Code 2024 - Day 8 (Geometry and primes)
Переглядів 45Місяць тому
Advent Of Code 2024 - Day 8 (Geometry and primes)
Advent Of Code 2024 - Day 7 (Recursion is recursive)
Переглядів 104Місяць тому
Advent Of Code 2024 - Day 7 (Recursion is recursive)
Advent Of Code 2024 - Day 6 (Brute Force 2: Bruter Force)
Переглядів 169Місяць тому
Advent Of Code 2024 - Day 6 (Brute Force 2: Bruter Force)
Oh 1080p!! Thank you!
I can neither confirm or deny that a silly mistake made my previous videos look like they were filmed with a potato. I can confirm that I have found the bug in this task - and of course, it's because I've misread a part of the description.
Hello Wekoslav. you seems to be a very good developer and someone where it´s possible to learn a lot from but the quality of your video unfortunately makes this ability disappear. the proble isn´t that it´s just 480p. the probles is more that it´s more like a diashow or just running in like 10fps. i don´t know which recording tool you use but i recemmond you to change it or to work on the setting to get rid of these. anyways i´ll give you a like because you seems to be a nice guy and i hope you´ll grow to be able to reach more people and to help more people on they´re way. enjoy it. :)
I'm using OBS and I'm still playing around with the settings. The unedited stream-of-consciousness feel is by design, but the quality issues are on me :D
this is the best video ever
@@mavsocc tnx :)
Najdobre si bratle
Фала, фала :D
You do what takes me a couple hours in minutes. I love watching you solve the problem though. Thank you for recording and sharing!
It's basically enough experience making all possible mistakes (and some I still do).
You are so smart! I wish i code like you. Cheers from Brazil.
Mostly it's experience and practice :D
Add metal music as a sound effect each time you say "brute force \m/" :D
Totally :D
Happy to see that you are finishing up the serie
Thanks for the kind words, Day 17 coming soon
It was something really good I saw after quite a while. I'm gonna stick around.
Thanks for the kind words
The part 2 was really a wake up call for me, that I need to really significantly improve in programming, because I didn't even think of oneight 18, actually lost for words. You are a great programmer.
Don't worry, and practice and then practice some more :) Also note that I didn't think of that at first, as well - that's why this is a Part II :D
Shoelace theorem.
We're gonna definitely need that for the second part :)
hm, I did not have an offset I am pretty mad that it's ambiguous that every starting element only ever went over the same "element with last char being Z" and not any other, and not in random cycles I don't think "curious fact: the number of nodes with names ending in A is equal to the number ending in Z!" tells us enough to be of any value I dislike the fact that it's more of a cat and mouse, finding out that each element ever only went over the same element ending with Z and all of the starting ones had one for itself I think that should've been written in the task I tried to solve it by thinking that every every starting element can go in random cycles over many elements that end with Z, now that would be problematic to solve and it's still in line with the tasks problem explanation
Yes, the goal of solving it was to do an analysis of the input. AFAIK, all input sets were heavily fitted to the problem, so that we could just use simple LCM, and not something like the Chinese Remainder Theorem. I have it plainly in the solution code: // We abuse the facts that // 1. All cycles have a common factor which is the length of the cycle (which is a prime number) // 2. All cycles have a common offset which is 0 // 3. Each cycle length divided by the number of directions is a prime number
Very happy to see that, for once, our solutions are very similar. Means I understood the problem.
I feel I might have gone overboard with all the classes, but sometimes a guy just wants some good ol' polymorphism...
Very nicely explained, backed with an example. Thanks Weko 😊
Nice one! I really enjoyed watching your explanation ;)
Tnx, glad you like it. Make sure to check out part II to see where the bug was :D
clever solution! looking forward for part2!
Tnx! I could not do part 2 yesterday (had to party with some friends), but I'll publish it today.
great explanation
My brute-force Rust solution ran in 9 minutes. Watching this because I'm curious how to optimize the solution without making it ludicrously complicated
Instead of working with every single number, we work with intervals. This solution takes around 3ms.
Found this channel by chance, as a computer science student this is amazing to watch, I appreciate your efforts to record it and share it online.
Thanks, I have fun doing it, and I try to keep it halfway between theoretical and practical.
You can watch the optimization of the second part here: ua-cam.com/video/JtKQ44qzzhQ/v-deo.html
I recognise that shirt! Hi from a fellow Geek! :)
I wear the shirt in the channel thumbnail as well, one of my favorites :D
@@swekster hope to see you next year at TGG
Love you :-D. #1 subs provider -> "PromoSM"!!
Круто!
Why don't you finish day 7? BTW your explanations for the puzzles are extremely good.
Real life keeps getting in the way. My current plan is to do it tomorrow, but, no promises :D
Are you going to post Day 07? I have problem with that, actually I get proper result from example but not from the input data :/
Most likely I'll be doing #7 tomorrow - And I definitely plan to have a full set of stars by new year :)
I am just starting with JS and I only got very little of what you're doing , but your videos are satisfying to watch. Keep it up
Awesome Explaination !! Can typescript be used for industry scale applications ?
Tnx. And typescript was specifically designed for large applications - I've been using it in such a role for almost a decade.
So quirky
🙋 P r o m o S M!!!
I'm happy that I finally found an explanation that I understand. Thanks for working it out in detail, it helped me a lot!
Tnx and glad that I helped :)
45:42 tip: In notepad++, if you hold ctrl+shift you can move 1 or more lines up and down with the arrow keys. No need to copy-paste :)
Tnx for the tip :D
Thanks for sharing your solution!
Very nice explanation of this problem! You got a good way of explaining things. I am not familiar with ts, but it was easy to follow and makes this problem way better to understand. Thanks!
Tnx. The algorithm is clear, but very slow. Once I have the time, I'll try to post an optimization video. As it is, it's 99.3% of the total runtime of all the tasks up to now :)
gods code kudos
For the first we can search near the median for the target value. As for the second one, I used mean and it worked, but don't know why though- My Haskell Solution- {-# LANGUAGE OverloadedStrings #-} import Data.List (sort) import Data.Maybe (fromMaybe) import qualified Data.Text as T import System.IO (hFlush, stdout) prompt :: String -> IO String prompt text = do putStr text hFlush stdout getLine -- O(n lg n) median :: (Ord a, Num a, Fractional a) => [a] -> Maybe a median [] = Nothing median xs = Just $ if even l then ((xs' !! l') + (xs' !! (l' + 1))) / 2 else xs' !! l' where l = length xs l' = div l 2 xs' = sort xs mean :: (Num a, Fractional a) => [a] -> Maybe a mean [] = Nothing mean xs = Just (sum xs / fromIntegral (length xs)) costs :: Num a => (a -> a -> a) -> [a] -> a -> [a] costs costFn xs y = [costFn x y | x <- xs] cost :: Num a => (a -> a -> a) -> [a] -> a -> a cost costFn xs = sum . costs costFn xs solver :: (Ord a, Num a) => (a -> a -> a) -> [a] -> [a] -> a solver costFn xs ys = minimum [cost costFn xs y | y <- ys] solvePart1 :: [Int] -> Int solvePart1 xs = solver (\x y -> abs (x - y)) xs xs solvePart1' :: [Int] -> Int solvePart1' xs = solver (\x y -> abs (x - y)) xs [tgt - 1, tgt, tgt + 1] where tgt = floor . fromMaybe 0.0 . median $ map fromIntegral xs sum1ToN :: Int -> Int sum1ToN n = div (n * (n + 1)) 2 solvePart2 :: [Int] -> Int solvePart2 xs = solver (\x y -> sum1ToN (abs (x - y))) xs [minimum xs .. maximum xs] solvePart2' :: [Int] -> Int solvePart2' xs = solver (\x y -> sum1ToN (abs (x - y))) xs [tgt - 1, tgt, tgt + 1] where tgt = floor . fromMaybe 0.0 . mean $ map fromIntegral xs main :: IO () main = do filename <- prompt "Enter file name: " nums <- map (read . T.unpack) . T.splitOn "," . T.pack <$> readFile filename let part1Ans = solvePart1 nums part1Ans' = solvePart1' nums part2Ans = solvePart2 nums part2Ans' = solvePart2' nums putStrLn $ "Part1: " ++ show part1Ans putStrLn $ "Part1 (Another Solution): " ++ show part1Ans' putStrLn $ "Part2: " ++ show part2Ans putStrLn $ "Part2 (Another Solution): " ++ show part2Ans'
Oh .. I think I understand, the cost function for the second part is quadratic in the distance (abs (x - y)), and distributions are generally normal, which is quadratic. So I guess that's the reason, I really don't know why
Searching near the median in some pathological values with even length, eg. 0,1,999,1000 will have solutions 1 and 500 respectively, and a median (and a mean) of 500. You'll need to take both the middle numbers as candidates.
Actually, upon drawing some plots, for even length input, ALL the points between the two middle elements have the exact same metric :D
Keep the good work !👌
Во првата задача ако во инпутот во првите броеви има 1010 ќе добиеш грешка резултат.
Зошто?
@@swekster па ја врти низата во два циклуса и проверува дали збирот е 2020 така да ако првиот во низата е 1010 ќе го исполни условот уште на почеток и после ќе си го помножи и ќе имаш грешен резултат
@@TheRu5H, не бе, +1 е вториот услов, не може исто бројче двапати.
@@swekster не видов дека е +1, ако е така тогаш нема баг