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

Sdílet
Vložit
  • čas přidán 10. 06. 2024
  • 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

Komentáře • 81

  • @williamlin2861
    @williamlin2861 Před 3 lety +54

    Would love a lecture on Chinese Remainder Theorem!

    • @refeez3700
      @refeez3700 Před 3 lety +1

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

  • @Errichto
    @Errichto  Před 3 lety +7

    The cool animation from outro: czcams.com/video/BaPBGIBrHLM/video.html
    All codes are in my GitHub repository: github.com/Errichto/youtube/tree/master/AOC-2020/20-jigsaw

  • @programmer2835
    @programmer2835 Před 3 lety +13

    Wow that visualisation was very nice 🤩

  • @wedding_photography
    @wedding_photography Před 3 lety +21

    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  Před 3 lety +10

      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 Před 3 lety +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 Před 3 lety

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

  • @harshsamoliya1954
    @harshsamoliya1954 Před 3 lety +56

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

    • @Errichto
      @Errichto  Před 3 lety +69

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

    • @harshsamoliya1954
      @harshsamoliya1954 Před 3 lety +4

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

    • @techwiki1512
      @techwiki1512 Před 3 lety +4

      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 Před 3 lety

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

    • @techwiki1512
      @techwiki1512 Před 3 lety

      @@pictureus Oh ... um hahaha?

  • @harshkr007
    @harshkr007 Před 3 lety +7

    You are my inspiration.

  • @anthonytonev1357
    @anthonytonev1357 Před 3 lety

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

  • @markojozic3944
    @markojozic3944 Před 3 lety +3

    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 :-)

  • @chcharitos
    @chcharitos Před 3 lety

    What a lovely explanation!

  • @jakuplus7227
    @jakuplus7227 Před 3 lety +2

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

  • @prakash_77
    @prakash_77 Před 3 lety

    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.

  • @napoleonbonaparte5972
    @napoleonbonaparte5972 Před 3 lety

    @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:)

  • @EvgenyBobkin
    @EvgenyBobkin Před 3 lety +1

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

  • @boywithacoin
    @boywithacoin Před 3 lety

    Have you considered performing affine transformation on the tiles?

  • @vlahovivan
    @vlahovivan Před 3 lety +1

    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 Před 3 lety +1

      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  Před 3 lety +2

      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.

  • @simondwilkinson
    @simondwilkinson Před 3 lety +1

    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 Před 2 lety

      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

  • @thedankest1974
    @thedankest1974 Před 3 lety

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

  • @Mr-jj9xn
    @Mr-jj9xn Před 3 lety

    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  Před 3 lety +2

      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

  • @flamendless
    @flamendless Před 3 lety +1

    "code not scary" yeah, just really killing

  • @dipukrishnan6383
    @dipukrishnan6383 Před 3 lety

    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 Před 3 lety

      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.

  • @RadomPlayers
    @RadomPlayers Před 3 lety

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

  • @pikzel
    @pikzel Před 3 lety +1

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

    • @tomaszzielinski1704
      @tomaszzielinski1704 Před 3 lety

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

  • @deepeiton6112
    @deepeiton6112 Před 3 lety

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

    • @Errichto
      @Errichto  Před 3 lety

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

    • @deepeiton6112
      @deepeiton6112 Před 3 lety

      @@Errichto Thank YOU!

  • @ujjwalsrivastava9702
    @ujjwalsrivastava9702 Před 3 lety

    Which keyboard do u use?

  • @ayaz.unstoppable
    @ayaz.unstoppable Před 3 lety +2

    I love u sir

  • @nickstabz8755
    @nickstabz8755 Před 3 lety

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

  • @docstyagi7775
    @docstyagi7775 Před 3 lety

    please provide amazon link of the chair you've got

  • @Gotinox
    @Gotinox Před 3 lety

    Is the diagonal pattern always there?

    • @Errichto
      @Errichto  Před 3 lety

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

  • @mohammedriyadh5152
    @mohammedriyadh5152 Před 3 lety

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

  • @mathankumar6276
    @mathankumar6276 Před 3 lety

    I have any project available

  • @petertillemans2231
    @petertillemans2231 Před 3 lety +1

    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.

  • @ufukyenilmez
    @ufukyenilmez Před 3 lety +1

    Dude, you're looks like Ed Snowden. 😁

  • @abikarthick601
    @abikarthick601 Před 3 lety

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

    • @Errichto
      @Errichto  Před 3 lety +2

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

  • @korosensei3780
    @korosensei3780 Před 3 lety

    how does he have one note on linux ??

  • @sayanghosh6996
    @sayanghosh6996 Před 3 lety

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

  • @mathankumar6276
    @mathankumar6276 Před 3 lety

    Bro I need project

  • @_______6398
    @_______6398 Před 3 lety +5

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

  • @sanjaykumar-6547
    @sanjaykumar-6547 Před 3 lety

    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.

  • @Gotinox
    @Gotinox Před 3 lety

    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.

  • @rachitsingh8040
    @rachitsingh8040 Před 3 lety

    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.

  • @vildanhuseynov6492
    @vildanhuseynov6492 Před 3 lety

    hey google?do you wanna algho engineer?

  • @laraibanwar1618
    @laraibanwar1618 Před 3 lety

    U became newbie in codeforces right 😂😂😂

  • @TrolekAmatorek
    @TrolekAmatorek Před 3 lety

    POLSKA GUROM

  • @stunseed2437
    @stunseed2437 Před 3 lety +4

    Why bother trying when you can just buy an Errichto?

    • @Errichto
      @Errichto  Před 3 lety +4

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

    • @OptimisticForce
      @OptimisticForce Před 3 lety

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

  • @c0rlea
    @c0rlea Před 3 lety

    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?