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

Поділитися
Вставка
  • Опубліковано 13 чер 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

КОМЕНТАРІ • 81

  • @williamlin2861
    @williamlin2861 3 роки тому +54

    Would love a lecture on Chinese Remainder Theorem!

    • @refeez3700
      @refeez3700 3 роки тому +1

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

  • @Errichto
    @Errichto  3 роки тому +7

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

  • @programmer2835
    @programmer2835 3 роки тому +13

    Wow that visualisation was very nice 🤩

  • @wedding_photography
    @wedding_photography 3 роки тому +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  3 роки тому +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 3 роки тому +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.

  • @harshsamoliya1954
    @harshsamoliya1954 3 роки тому +56

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

    • @Errichto
      @Errichto  3 роки тому +69

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

    • @harshsamoliya1954
      @harshsamoliya1954 3 роки тому +4

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

    • @techwiki1512
      @techwiki1512 3 роки тому +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 3 роки тому

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

    • @techwiki1512
      @techwiki1512 3 роки тому

      @@pictureus Oh ... um hahaha?

  • @harshkr007
    @harshkr007 3 роки тому +7

    You are my inspiration.

  • @anthonytonev1357
    @anthonytonev1357 3 роки тому

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

  • @markojozic3944
    @markojozic3944 3 роки тому +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 3 роки тому

    What a lovely explanation!

  • @jakuplus7227
    @jakuplus7227 3 роки тому +2

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

  • @prakash_77
    @prakash_77 3 роки тому

    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 3 роки тому

    @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 3 роки тому +1

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

  • @boywithacoin
    @boywithacoin 3 роки тому

    Have you considered performing affine transformation on the tiles?

  • @vlahovivan
    @vlahovivan 3 роки тому +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 3 роки тому +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  3 роки тому +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 3 роки тому +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 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

  • @thedankest1974
    @thedankest1974 3 роки тому

    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 3 роки тому

    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 роки тому +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 3 роки тому +1

    "code not scary" yeah, just really killing

  • @dipukrishnan6383
    @dipukrishnan6383 3 роки тому

    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.

  • @RadomPlayers
    @RadomPlayers 3 роки тому

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

  • @pikzel
    @pikzel 3 роки тому +1

    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.

  • @deepeiton6112
    @deepeiton6112 3 роки тому

    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!

  • @ayaz.unstoppable
    @ayaz.unstoppable 3 роки тому +2

    I love u sir

  • @ujjwalsrivastava9702
    @ujjwalsrivastava9702 3 роки тому

    Which keyboard do u use?

  • @nickstabz8755
    @nickstabz8755 3 роки тому

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

  • @docstyagi7775
    @docstyagi7775 3 роки тому

    please provide amazon link of the chair you've got

  • @Gotinox
    @Gotinox 3 роки тому

    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.

  • @mohammedriyadh5152
    @mohammedriyadh5152 3 роки тому

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

  • @mathankumar6276
    @mathankumar6276 3 роки тому

    I have any project available

  • @petertillemans2231
    @petertillemans2231 3 роки тому +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 3 роки тому +1

    Dude, you're looks like Ed Snowden. 😁

  • @abikarthick601
    @abikarthick601 3 роки тому

    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 роки тому +2

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

  • @korosensei3780
    @korosensei3780 3 роки тому

    how does he have one note on linux ??

  • @sayanghosh6996
    @sayanghosh6996 3 роки тому

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

  • @mathankumar6276
    @mathankumar6276 3 роки тому

    Bro I need project

  • @_______6398
    @_______6398 3 роки тому +5

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

  • @sanjaykumar-6547
    @sanjaykumar-6547 3 роки тому

    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 3 роки тому

    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 3 роки тому

    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 3 роки тому

    hey google?do you wanna algho engineer?

  • @laraibanwar1618
    @laraibanwar1618 3 роки тому

    U became newbie in codeforces right 😂😂😂

  • @TrolekAmatorek
    @TrolekAmatorek 3 роки тому

    POLSKA GUROM

  • @stunseed2437
    @stunseed2437 3 роки тому +4

    Why bother trying when you can just buy an Errichto?

    • @Errichto
      @Errichto  3 роки тому +4

      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
    @c0rlea 3 роки тому

    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?