YTread Logo
YTread Logo

Advent of Code 2022 in Python, Tag 1

Apr 02, 2024
Yes hello and welcome here to another episode of The Beautiful Coaching and today we want to discuss the beautiful topic of the Advent of the Code, today is the first of December and everyone knows that on December 1st you open the first door of your Advent calendar and For the programmers There is Eric Wastestal's Advent calendar, that is, the one you see here right now and the Advent address on

code

.com, now we have different puzzles that we must solve from day 1 to day 25. Every day a new window is activated . , so for that, on the second of December, it takes 12 hours and 17 minutes before the door opens and then you can click on the corresponding window and then look at the problem description and solve the problem with any programming language that know You can also use Solve Excel or use large pieces of paper that you then spread on the living room rug.
advent of code 2022 in python tag 1
There are the larger variants and the inventor Eric wasted. I've included some photos here. There aren't many photos of him. , but that's the idea finder for the whole topic and I've actually been doing this every year for six years, I'm going to address the issues here, it's a little different from what you know on hot beautiful, I've always really liked it . I have a German channel, so it is programmed in German. I explain it in German and the variable names are in German. In the case of

code

, I'm a little different. Still moderate in German. I also explain it in German, but the problem is completely in English and the key terms mentioned there are what I normally count like that.
advent of code 2022 in python tag 1

More Interesting Facts About,

advent of code 2022 in python tag 1...

Much more importantly, when the English word for gnome comes up, I use it one by one. This simply has the background that you can always wonderfully combine the task and the program code about what is really happening here or not have to constantly translate what is written in the original description of the problem to an English word, what does it mean? in German, where can I find it in the program code and so on? This is to make it understandable when I have the text completely in English, which is what I always do when I have something in English as a problem.
advent of code 2022 in python tag 1
So these elements are also used in the program. Code one by one to make it easier to find. It is very important before starting. Here there are so-called leaderboards, that is, tables that you can consult. This is basically the points table after first Every day All over the world, every time you have a solution within a certain time limit, you get points in order and if you are first you get the most points, and so on , and the top 100 always get points I think, but they have to. In Germany you sit in front of the computer at 6 in the morning and then staple the solution.
advent of code 2022 in python tag 1
In other countries, because of the time difference, it is much more pleasant than in the afternoon at 7 in the morning or something like that, but we are at 6 in the morning. It does not necessarily correspond to my biorhythm. That's why I set up a private song board here and you can enter it by clicking on Leaderboard here in the code event, then on private leaderboard and then you enter the things that are here and I. We'll put the stapler back at the bottom Video description of this code and if you type it here, then it's a member of this table and then we have a sort of ranking list of the people involved in the

advent

of the code. and those who follow my channel, beautiful code in Python, we can do that too.
Take a look at what the current state looks like and you can see Oops, I already set this up last year but pointed it out too late. That's why there are not many, but they are from last year and Motus already has them today. Obviously the problem was solved because I got six points immediately and of course I still haven't solved anything. I want to do it now and then somehow it would appear on the table here, but I'm definitely not the first because I wasn't as fast as Moritz. I already did, no, that's how it all works and like I said, you can enter. there, you can also sign up and sign up for Event of Code and the good thing about Wendorf Code is that it's totally free, there are no ads, there are no spam stories or anything else that they then send you or anything else, but just stop by like this, you don't hear anything from Eric Waistle all year, it's Advent again in the code, so that's enough of the preface and now let's do an assignment today and I have to read it through first because, like, "I haven't solved anything yet, which always good given the whole topic.
The important terms are shown here in yellow. Obviously it's about stars in some way, it's about 50 stars oh. So first of all, the explanation. It's also great that you get a star for each puzzle you solve per day, so for each individual task you can get two stars for tasks A and B, divided into two-part tasks and because you will get a maximum per day if you can earn two stars, you get 50 stars at the end when you have completed the 25 days and then Christmas is assured because you have to save Christmas somehow and I didn't let myself go through all that, I just took a look at something.
Here's the thing, so somehow I have an example here where some calories are listed here and there's a strange list here and the list somehow shows the calories of the food which is obviously carried by 5 elves, the first elf to usa appears 2003000 oh, because those in the final come the second 4000 the third 5006000 yes because everyone can if the next one has 78009000 and the fifth has 10,000 if some F gets hungry and needs extract and then goes to some elf and asks If you can get something and we should only calculate how many calories the 11 that has the most calories in the previous example is the one that has 24,000 calories or that the fourth eleven is the r1234 and the sum of this here is the highest sum that a eleven and then now we should find the elf who carries the most calories and we have to answer the question how much does he actually carry and this is an example task here is always our puzzle entry this is our task you can see UPS this is a There is a slightly longer list.
Let's say control A to check everything, control C to copy everything, and then let's switch to Visual Studio Code. I can now prepare a file called Day 01 txt and we have everything there, so it's easily 2236 lines. , damn many elves and the question is always how much is the total in the respective section and what I have prepared is my standard framework for these tasks. First of all, it's always reading into a text file, which is why I have a function here called read puzzle, which is also the puzzle input that we're talking about here and then you should open this file and then read it somehow.
Then there is a function called solve the puzzle. Puzzle is then what reads and returns some number and then prints it out and we'll see it here Prince Soul Fried Puzzle so first I read the personal um the text file that you have on this day is 01 t XT and then it basically says out loud the The result is that it comes back from reading the puzzle, the Souls solution, um the soft version too or the function and then it returns some solution and we do everything with time measurement, that's why we start here PC for performance counter and FC less.
He explains to us how long it took us to find this solution. Well, yes, what we have to do is relatively simple. By the way, the tasks are also based on the level of difficulty. The first day is very easy. I have to say it, but then they get a little more and more difficult and mainly until the publication I don't know anymore 20 21 or something, tear your hair out and sit for 18 15 hours to solve all these tasks, all that already happened, this It won't take 15 hours, it will be relatively easy. Our task is simply to say, "Okay, we prefer some text file here." Let's read here, here the SF arrow will be at the top and um, now we have this situation where we actually need a list of numbers here, this list of numbers and we always need a new list of numbers if there is a double number change here there is a timer behind each number, but then here comes a number change there is another line change, the next number comes and with two line changes obviously there is the next 11 and that's what it's all about, we want to find the next 11 and that has to carry calories somehow and we want to have the total, so let's say, give me another list of all the totals that the elves carry and we do it again with a fulfillment list and we say, we checked this file, we have sorted the file with the variable F and then we say advantages or not, we say First, before the section in F and F, we split it so that F reads, which is basically reading the entire file and this huge text file that is huge.
Splitting the string was done once after changing the double number and saying peak, which again after the backslash n The change is the double time change, so now I have split it into relatively long strings that now only contain numbers and changes of individual numbers and then I say now we have every eleven that we go over like this and then we enter the calories in front of Carlos. in 11 divisions and then a number circuit, that means that after each individual area we now have all the numbers here in calories and these calories that are taken.
Let's open it up and say we're going to make an integer value out of that and return it. and that's what we're going to put here under the puzzle and I'd like to print it out first or I'll give it back to you now so you can see what our list that we've created here and I look like right now. I want to have the list in the list, so I think it's even possible, so I say these calories, the divisions here and I'll add them right away and then I'll go through each one individually eleven in these sections and then I have a list that now just contains the totals of all the totals of the eleven in calories and let's see if that works yeah that's mainly because I didn't call day 01 at all but day 01 so let's say here day 01. so run it again and What do we see here?
Now we only see the numbers here, which means that these are the sums of the respective elves. Whatever sum appears here and what you must then Recover should give us the maximum of this list because you ask. How many calories does the 11 with the most calories have? So we say that and then we get a 67,450 here and everything took 0.004 seconds tenths 110,000 14,000 seconds, let's see if that's correct. I'll copy this 67 450. into my puzzle here Tip, this one says yes or says yes, that was the correct answer and now I got a gold star and now I'm going to Part 2 of the whole assignment so somehow it can be I wrote the eleven with the 11 wrong, by the way, we will do the eleven again later so that the eleven with the most calories somehow at some point will not have anything left because they are all closed they ran towards it and to avoid that.
We would like to know how many calories they have because the three main elves in the previous example which was this example here are the first 3 help the top 3.11 is the fourth F with 24,000 calories the third F with 11,000 5.11 with 10,000 and the sum of the three calories it's 45,000 find exactly how many calories the 3 main dead elves carry 11 oh, I didn't know that 11 in the plural is written like this and 11 in the singular is written like this, okay, great, I already knew if I don't do all this in English, so English it's not necessarily my forte, I have to be honest, okay, then we say we return the maximum and then there is a second variant where we don't just return the maximum. but also the 3 main themes and what are we doing then?
Let's say we actually have to sort and no, we sort the list and return the first entry which should be the maximum and then we return the top 3 which should be the sum of the top 3. 3 themes, yes, which really should be. Simply say, puzzle is the same as jigsaw puzzle, but the inverse equals true. I want to sort from the largest element to the smallest element. Then we have that and what do we return? Let's go We go back to the puzzle and input 0 which is the largest element and on the other hand we return the sum of the puzzle from the beginning to the third element, so you want to have the first 3, that means for the prices you sum the elements with index 01 and 2 and that's exactly what we want and now let's go in here and then we get our 67,450 back and we get 199,000 357 and this second number is the solution for part 2, I would say and then we go in here and yes, we actually have a second gold star and then we go to Advent with odds, then we see that they have two gold stars here, then we go to our leaderboard, we look at our private and we look at the view and we realize, ah.
I also solved the first day's task and got four points and then I am on the second place in the table. My ambition, of course, is not natural, since in the end I finish in first place in the table, but only ahead. from me because it resolved it faster when I said yes and like I said everyone can still sign up there and then participate and um that's supposed to be it from my end it was a short implementation for the whole topic and I've sorted it out with you and I will do it later. When it comes todifficult tasks, I don't want to leave you hanging so you can just watch me think about it for two hours and try out how to do it.
I would definitely resolve the issue beforehand and then just show them the finished solution. That would be clear faster, but I can do it live this first day. If you want me to post more videos on the topic, write it in the comments because I do. anyway, so it's fun for me to solve these tasks and then I can publish it, I found out that at some point no one is interested anymore, so it may be too complicated and so on, but there is its own repository which is also shown in the bottom of the video description, which means that not all tasks are solved as of Advent of Code

2022

and then you can always take a look at it, even if there is no video about it, you will simply see a in this leaderboard and also in the repository in which I have continued working on it.
Yes, that should be it. I would love for you to like it, if you would give it a thumbs up, a notification, a notification, a subscribe, and if you are interested, we will contact you next time when it is beautiful, see you then ciao

If you have any copyright issue, please Contact