Hardest Advent of Code 2020 Problem (day 20 Jigsaw, backtracking)

Solution for Jurassic Jigsaw, which was the hardest problem in Advent of Code 2020 adventofcode.com/2020/day/20. Two more problems to practice backtracking: leetcode.com/problems/n-queens/ & cses.fi/problemset/task/1625.
I stream coding every even weekday! / errichto
0:00 Intro
0:18 Statement
1:07 Corners (easy)
2:06 Backtracking
3:54 Small Visualization
4:11 Code
7:00 Big Visualization
8:15 Sea Monsters
10:32 Outro
- Github repository: github.com/Errichto/youtube
- Streaming schedule: calendar.google.com/calendar/...
- Past streams: / errichto2
- Frequently Asked Questions: github.com/Errichto/youtube/w...
- Discord server: / discord

Пікірлер: 81

  • @williamlin2861
    @williamlin28613 жыл бұрын

    Would love a lecture on Chinese Remainder Theorem!

  • @refeez3700

    @refeez3700

    3 жыл бұрын

    Yeah, that one was a head scratcher.. I remember looking at someone else's solution and then... I wept.

  • @Errichto
    @Errichto3 жыл бұрын

    The cool animation from outro: kzread.info/dash/bejne/dJWEpKmCctWufLA.html All codes are in my GitHub repository: github.com/Errichto/youtube/tree/master/AOC-2020/20-jigsaw

  • @programmer2835
    @programmer28353 жыл бұрын

    Wow that visualisation was very nice 🤩

  • @Errichto

    @Errichto

    3 жыл бұрын

    Thank you :)

  • @harshkr007
    @harshkr0073 жыл бұрын

    You are my inspiration.

  • @wedding_photography
    @wedding_photography3 жыл бұрын

    You can also put all edges (forward and reversed) of every tile into a hashmap. That reduces the complexity to linear. You instantly know who is the neighbor of whom.

  • @Errichto

    @Errichto

    3 жыл бұрын

    Good point. I would say that the "should line up exactly with its adjacent tiles" condition wasn't precise enough and I expected possibly more edges in this graph, hence backtracking. I agree that if degrees are all as small as possible then everything is linear (if we find edges in a smart way first).

  • @sebastien_lemieux

    @sebastien_lemieux

    3 жыл бұрын

    I had the same concern as @Errichto! So first I built my hashmap for edges by using a flip-invariant hash (thus one hash per edge) and then counted the number of tiles sharing each hash. Corner tiles are tiles with two unshared edges (part 1). Then it was simple to verify that all edges are shared by either 1 or 2 tiles, confirming that there was no ambiguity and suggesting a linear solution. (btw, great explanation!)

  • @CarrotCakeMake

    @CarrotCakeMake

    3 жыл бұрын

    @@sebastien_lemieux Yes, and if it is really size 10 edges like in the example, then a perfect hash is possible.

  • @anthonytonev1357
    @anthonytonev13573 жыл бұрын

    Love the # visualisation in the console. Very nice video and explanation.

  • @chcharitos
    @chcharitos3 жыл бұрын

    What a lovely explanation!

  • @harshsamoliya1954
    @harshsamoliya19543 жыл бұрын

    Errichto : The code isn't scary , it is around 100 lines Me : 😭😭😭😭

  • @Errichto

    @Errichto

    3 жыл бұрын

    Imagine that it's just 5 easy problems, each requiring 20 lines of code :)

  • @harshsamoliya1954

    @harshsamoliya1954

    3 жыл бұрын

    @@Errichtoi use java so for me it is 10 easy problem 😏😏😏

  • @techwiki1512

    @techwiki1512

    3 жыл бұрын

    haha google service have 1.8 -2billion lines of code 100 lines take about 2 mins and if your typing speed is 100wpm and your thinking is fast enough to keep up I can see someone doing this in a few seconds if you already solve it and just coding it

  • @pictureus

    @pictureus

    3 жыл бұрын

    @@techwiki1512 Pretty sure it's for the memes.

  • @techwiki1512

    @techwiki1512

    3 жыл бұрын

    @@pictureus Oh ... um hahaha?

  • @markojozic3944
    @markojozic39443 жыл бұрын

    instead of the can_right and can_below function you could do a byte comparision. The tiles are 8x8 so each tile would have 4 bytes representing each edge. You could describe a tile with a 32 bit int and for the rotation you just would have to bit-shift the representation. With that aproach you can check all edges of a tile at once for any given rotation :-)

  • @prakash_77
    @prakash_773 жыл бұрын

    Every other video for Day 20 (this one) was more than 35 min long. Thank you for this one. Please make video for Day 13 (Chinese Remainder Theorem) and Day 23.

  • @jakuplus7227
    @jakuplus72273 жыл бұрын

    Visualization is very food! You very good master🙂🏆🎉✨🎖️

  • @napoleonbonaparte5972
    @napoleonbonaparte59723 жыл бұрын

    @Errichto Can you please explain how the problems are in Div3 contests on Codeforces? Like, what are the necessary prerequisites for participating in them? What should be the learning level to take part in it? I have been attempting to take part in an online contest for some time now, just too afraid to take the step, so hope that you can provide help:)

  • @boywithacoin
    @boywithacoin3 жыл бұрын

    Have you considered performing affine transformation on the tiles?

  • @EvgenyBobkin
    @EvgenyBobkin3 жыл бұрын

    Hi, what program do you use for drawing/writing your explanations on gnu/linux?

  • @dipukrishnan6383
    @dipukrishnan63833 жыл бұрын

    Can you suggest one good book on data structures and algorithms? I have searched on internet and find like so many books and it's really confusing. If you can suggest one book which is going to cover everything and can be used as a good reference for preparing for coding interviews then that will be great. And if that book is written for c++, then that's even better.

  • @Sebmen4

    @Sebmen4

    3 жыл бұрын

    I strongly recommend Algorithm Design Manual by Skiena. It covers all the important topics, the code is in c++ and it contains an amazing catalog of commonly seen problems.

  • @nickstabz8755
    @nickstabz87553 жыл бұрын

    Umm bro could you pls explain why my fb email changed into blackhole null woth numbers what does it mean?

  • @simondwilkinson
    @simondwilkinson3 жыл бұрын

    There are eight possible solutions when you are putting the tiles together. Depending on which tile and orientation you choose for the first tile, you could get the same connections but with the whole patchwork of tiles flipped over, or rotated. This is why in the problem statement says you might have to rotate or flip to find the sea monsters. Probably with your code you just got lucky that the solution you found was already oriented correctly (1/8 probability).

  • @ElephantHannibal

    @ElephantHannibal

    2 жыл бұрын

    YES! Thank you. I'm looking at this now, and was wondering the same thing. And that's why he's exiting 0 at that return. I thought I was crazy. :D Thanks for confirming that I'm not. :D

  • @RadomPlayers
    @RadomPlayers3 жыл бұрын

    Hey. I want to learn competitive programming but I'm not good at maths. Where can I start?

  • @pikzel
    @pikzel3 жыл бұрын

    Is it possible to use this backtracking technique without exit(0) or throwing exceptions?

  • @tomaszzielinski1704

    @tomaszzielinski1704

    3 жыл бұрын

    I think he uses 'continue' for that. You could also use 'break'. I would rather saperate this to other function and use return.

  • @vlahovivan
    @vlahovivan3 жыл бұрын

    Hey Errichto, what do you think, if this problem was on Codeforces, what would be its rating? Advent of Code problems were quite different from typical Codeforces problems so I'm not quite sure if they are more suited for Div. 3, Div. 2 or Div. 1.

  • @prakash_77

    @prakash_77

    3 жыл бұрын

    Actually they are very different from the CF problems. A good part in AOC is parsing the input correctly. The input is very small, there's just one case to run in AOC. Most of them don't probe your algorithmic skills but only your implementation skills. No wonder, quite a few participants do it to learn and get better at a new language. But baring Day 13 part 2 and Day 20 part 2 (this one), there weren't any hard problems. Maybe you can add Day 23 part 2 also. Rest would fall in the easy part ( initial questions ) from Div 3 CF. Still this comparison isn't fair.

  • @Errichto

    @Errichto

    3 жыл бұрын

    It's hard to say because AOC problems aren't difficult in terms of algorithms. Even Codeforces div2-C (div1-A) already requires a more tricky idea/insight than this Jurassic Jigsaw problem. On the other hand, CF problems require much less implementation and thus quite a lot of time. Maybe it's fair to say that this is around div1-AB level because it would take me around 15-20 minutes to implement during a contest.

  • @ayaz.unstoppable
    @ayaz.unstoppable3 жыл бұрын

    I love u sir

  • @thedankest1974
    @thedankest19743 жыл бұрын

    You can optimize this a bit by only trying all the orientations of tiles with degree of 2 at the top right corner.

  • @flamendless
    @flamendless3 жыл бұрын

    "code not scary" yeah, just really killing

  • @docstyagi7775
    @docstyagi77753 жыл бұрын

    please provide amazon link of the chair you've got

  • @Mr-jj9xn
    @Mr-jj9xn3 жыл бұрын

    Wyrazy podziwu za wiedzę jaką posiadasz :) czy są jakieś strony dla totalnych laik'ów z tej dziedziny, którzy chcieli by zacząć przygodę z programowaniem?

  • @Errichto

    @Errichto

    3 жыл бұрын

    There are hundreds of free programming courses online. Later, after you learn any programming language, read this to start with competitive programming: cses.fi/book/book.pdf

  • @deepeiton6112
    @deepeiton61123 жыл бұрын

    Hi Errichto! any suggestions for a beginner preparing for google code jam??

  • @Errichto

    @Errichto

    3 жыл бұрын

    I wrote down my long advice some time ago: github.com/Errichto/youtube/wiki/How-to-practice%3F

  • @deepeiton6112

    @deepeiton6112

    3 жыл бұрын

    @@Errichto Thank YOU!

  • @ujjwalsrivastava9702
    @ujjwalsrivastava97023 жыл бұрын

    Which keyboard do u use?

  • @Gotinox
    @Gotinox3 жыл бұрын

    Is the diagonal pattern always there?

  • @Errichto

    @Errichto

    3 жыл бұрын

    I used colors only to make it easy to see where tiles are. Treat them as random colors, there's no diagonal pattern.

  • @mathankumar6276
    @mathankumar62763 жыл бұрын

    I have any project available

  • @korosensei3780
    @korosensei37803 жыл бұрын

    how does he have one note on linux ??

  • @korosensei3780

    @korosensei3780

    3 жыл бұрын

    that too with the dark mode

  • @ufukyenilmez
    @ufukyenilmez3 жыл бұрын

    Dude, you're looks like Ed Snowden. 😁

  • @programmer2279

    @programmer2279

    3 жыл бұрын

    Yeah 😀

  • @mohammedriyadh5152
    @mohammedriyadh51523 жыл бұрын

    Some people just like to tap dislike button.. they make it a habit .. we should ignore them..

  • @sayanghosh6996
    @sayanghosh69963 жыл бұрын

    how (/why) are you using onenote for windows on a linux system?

  • @mathankumar6276
    @mathankumar62763 жыл бұрын

    Bro I need project

  • @abikarthick601
    @abikarthick6013 жыл бұрын

    Bro u can calculate the edge with binary with . As 1 # as 0 and store the result and check compare with other

  • @Errichto

    @Errichto

    3 жыл бұрын

    That's not a bottleneck of a program so no need for extra code to speed it up.

  • @petertillemans2231
    @petertillemans22313 жыл бұрын

    There is no need for backtracking: just bless one corner as top left, rotate/flip it to match top left position. Now repeatedly go down -> left column, now go right for each tile in left column.

  • @yixing2301

    @yixing2301

    3 жыл бұрын

    underrated

  • @rachitsingh8040
    @rachitsingh80403 жыл бұрын

    Can you consider making some content on educational DP problems from AtCoder? Here's the link to it. atcoder.jp/contests/dp/tasks . These questions are very basic, but they do teach beginners on how to frame a thought process to answer questions using dp. Learning this from you will be impactful.

  • @sanjaykumar-6547
    @sanjaykumar-65473 жыл бұрын

    Hii sir my name is Saurabh priyadarshi from Kaimur Bihar please help me sir. I am in class 9 and I want to prepare for International Olympiad in informatics. I belongs to backwards area and here I can't learn competitive programing. Next year I want to participate in IOI. These are My question 👉👉 1. How I can prepare for IOI for beginners. 2. Which books are required for CP. 3. From where I can learn CP. Please give me your email address sir Thanking you My biggest inspiration is your are sir. I hope you will really reply me.

  • @laraibanwar1618
    @laraibanwar16183 жыл бұрын

    U became newbie in codeforces right 😂😂😂

  • @vildanhuseynov6492
    @vildanhuseynov64923 жыл бұрын

    hey google?do you wanna algho engineer?

  • @Gotinox
    @Gotinox3 жыл бұрын

    Oh, funny that you mentioned the chinese remainder theorem. I wouldn't have known it, if it wasn't because of a cryptography security ctf challenge.

  • @_______6398
    @_______63983 жыл бұрын

    dO yOu wAnT tO bE a sOfTwARe eNgINeEr aT gOoGLe?!?

  • @TrolekAmatorek
    @TrolekAmatorek3 жыл бұрын

    POLSKA GUROM

  • @stunseed2437
    @stunseed24373 жыл бұрын

    Why bother trying when you can just buy an Errichto?

  • @Errichto

    @Errichto

    3 жыл бұрын

    This is what I did and it works fine for me :)

  • @OptimisticForce

    @OptimisticForce

    3 жыл бұрын

    ​@@Errichto I bought petr mitrichev few days ago, So I am safe as well

  • @c0rlea
    @c0rlea3 жыл бұрын

    Bro you should stop doing those useless problems and get a job at Space-X where you will solve important problems. Or maybe you already are?