Advent of Code 2021 🎄 Day 13 🎄 Golang TDD

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
everybody welcome to day 13 getting off to a late start um i uh started my first day new job today very busy um but i don't want to skip out on admin of code so let's see if we can get to it real quick before i put my kids to bed all right day 13 transparent origami you reach another volcanically active cliff would be nice to you know that's true get out of the cliffs we're going to activate codes large sheet of transparent paper i don't know what that is oh yeah i do know what that is all right uh marked with random dots it includes instructions on how to fold up your puzzle all right and then some instructions good to know and what we can do is we can iterate through this until we get you know empty line and then use some sort of different scheme to add that to a different list um first section is a list of dots starting at zero zero um it's nice that they make zero zero at the top so that we can iterate easier instead of at the bottom that would just be a pain in the butt wouldn't it x increases to the right so x is um column y is rho first value x what first value x increases to the right so 3 0 okay so that's a little different um i'm actually going to write that down because i'm going to screw that up x y is row okay coordinates where's the dot okay there's a list of fold instructions each full instruction integrates a line on the transparent pair we want you to fold the paper up or horizontal y equals or left okay so it's going to be collapsing in on zero zero um zero one two three four five six seven okay so line seven is basically yeah it's basically erased and this stuff is like folded up over top of it right so um okay now only 17 dots are visible okay although some dots are overlapping the dots merge together and become a single dot then we fold along x equals five so row is five the fifth row fifth sorry column index erasing that ensuring okay uh right what's up a little shape pretty big just the first fold instruction oh did i log out of this hold on on here all right so this should there we go okay so what is our input decently long list oh what should we do let's um let's use 12 again um ooh i don't want to do that i uh cut it instead of copying it thirteen my things aren't docking oh because i don't have them set to dock iron tile hold on after being away i've forgotten all of my peck okay so i'm on thirteen let's go ahead and paste here okay that's nice there's i mean clearly what we're going to do is the first instruction and then we're going to do all the instructions right i'm going to hedge my bets a little bit by keeping track of the number of dots at each spot even though it says that they like disappear um because i am just sort of expecting that that's going to be the uh gotcha all right i'm going to rename this back to just test number two delete those i thought i deleted two of them all right okay let's close out of this close out of this why is this a different color oh because it's on tracked probably right so we got our things let's go look at our tests we're gonna need a part two at some point but we can get rid of it for now um that's not what i wanted to do i wanted to put it here all right um get rid of all this extra stuff let's look at our 17. okay uh we don't quite care about that yet so we're going to comment it out but it's nice to have it um don't need to care about uppercase load input we do care about let's um well i guess we're gonna have two inputs right um so [Music] results uh let's see we've got um dot input and instructions equals load input dot test uh and we'll have our input output two different things one is um what i'm gonna say is a map of the instructions um and that is going to be a map containing the type chords with a int and we're going to oh this is going to be annoying setting this up um because i have to make all these types here here let's um okay we're gonna make a new one here and it's going to only include like two of them or something that way we can test this but not in some sort of ridiculous way all right so input tests uh short all right let input instructions all right so dot result is gonna be sort of that dot input let's so this is what our two tests gonna look like um so what is this going to be uh it is going to be a map of well let's make this is going to be ugly unless we make this struck first [Music] type chord rocked and it's going to be i'm going to call them rowan column it's going to be um yeah we want to be an int and i think i can do this call row int okay that's our struct now let's see if that okay so it's not mad at us anymore that's good um all right so let's populate that with um chord row let's start with call um and i think we just kept these first two right so the first one is call equals six row is 10 and that should be one right that is our map reverse map value good all right i did good at that the next one is 0 and 14. all right all right so that is uh what we want for dot result and then what we want for instruction [Music] results is going to be um probably just like a list um it's kind of annoying because it's going to be mixed because i don't think that i can do a um i'm just going to make an instruction uh struct why not so i did with the other one let's make it instruction we got [Music] bold which is going to be a string and um location which is an int actually i don't think those belong there okay so now we got that um construction um that will include instruction what i call axis why isn't it oh fold fold in location bold is going to be x no y for the first one um [Music] location will be the integer seven and get another one here all that exit location five okay um let's go ahead and test it fail two variables we knew that oh we gotta go through and clean this up um don't need our recursive function from yesterday i really need to start getting away from global variables all right all right so let's look at this load input um okay so we're gonna get the string we're gonna break on the new lines and then we're going to start going through it we need two things we need the dots and that is going to be a map of cord into and we're also going to be returning a list of instruction all right parentheses okay okay all right um so let's um [Music] start with a little switch um right so for line range data okay so we're iterating through the lines right okay so this will be the dots instructions right um [Music] here we're going to split this um comma right and then we are going to we need to make an int integers here don't we um we'll just include that in our uh so these could be a list of strings and um let's say dots i need to make this chord um column equals string to inch which is a function that i'm going to be making um line slice zero right and row is going to be at position one and we need to make um oh this needs to be in here right so let's make string to inch i feel like i've done this enough times that i hopefully don't need to so air and return info all right i think that that will help us pass test one oh oh we need to get rid of some stuff here just add a continue all right what do we got oh because we probably got to fold here um [Music] let's let's add in that logic so if line equals this which will be that um empty string what we're going to do is instruction switch equals true and break i think all right let's go and test it again all right good we got some stuff looks like it didn't we're passing out six ten zero fourteen uh we should be adding to this map let's split this out into two lines this is just going to be the um coordinate here and then we'll throw chord vowel into here maybe that'll give us this hmm let's say main instructions oh because oh because the instruction test is failing and not me making these coordinates the coordinate one is coming back um fine let's uh let's go ahead and comment this out and we'll see that the test should pass now what did i just do the result oh because i let's get ready and that passes okay good let's uh undo these commented out things why is it mad about this i'll figure that out later okay so now we have um opt-in to make this simple again okay else uh we're popping now into um [Music] the what's happening with our instructions right so let's go ahead and do um i think they all say fold along right they'll have fold along space so let's go ahead and replace that um so we're going to replace um string is line right fine with old string which is going to be bold space long space right we're going to get rid of that and we're going to replace it with nothing and we're going to do it negative one times which is all the times um it's only going to happen once but who cares all right um so this is a string hold on all right so looking at this i'm definitely not gonna have time to do this before 7 30. this makes me sad though most of it's getting your stuff together okay we're going to call this um line right because it's still a string right line string the string right line slice is going to equal [Music] strings split line and we're going to split it on the equals all right um [Music] so we're going to split that on equals and then we're going to do a uh [Music] instructions today instructions equal pen to instructions and what we're going to append is um [Music] instruction with what was i what was our elements uh fold bold equals line slice zero that's the fold that does and that doesn't need to be converted into a string and location is going to equal string to end line slice one now let's go ahead and test that it fails where does it fail um old location and that's an end should do it let me save these things i do have full along x y there x seven the problem is not giving me anything in the actual let's see oh oh that's not good you guys can hear that um [Music] hold on [Music] no i can't hear it anymore thank you all right um [Music] why isn't it doing this maybe it's breaking all right so here we go um it's not oh that should fix it yes okay all right let's get rid of this all right we've got our input the way we want it let's get cracking with our um result so this is what i want to do i want to i've made a map right so i got my map um dots map board and all right and then instructions we are going to return it so this is what i want to do um basically what i want to do is now that i have these coordinates set what i want to do is for part one i'm just gonna i'm not gonna loop through the instructions right i'm just gonna do instruction zero right um and what i'm going to do is i'm going to look at these dots right there x and y coordinates and what i'm going to do is for [Music] um don't care about the index dot in range dots okay um what i want to do is change them right is all right if so there's two kinds of things we're gonna do uh if instructions dot what is it all right so remember this is the first one right instruction zero dot fold right that's the string equals x all right let's start with y that's the first one in our instructions okay then what we're gonna do is we're gonna put this above all right uh if it's a fold in the y what we're gonna do is go through each of them and say um if dot we care about the okay chord dot um remember y is the row so we're going to say dot row is less than we'll set those points just to make a little more verbose instructions this is still going to be zero dot location all right this is an inch yeah so if the coordinate if the row coordinate of this value is less than um less than the fold location right we're not going to do anything with it right we're just going to continue i'm not doing anything else if you know we're going to switch this around make a little make a little more sense um if it's greater than that we're going to have to do a calculation right um let's think about it we need to make it a new coordinate right [Music] and what we'll be doing is keeping the same column right but we need to set a new row and that's going to be equal to so let's think about it we need to find the distance from the fold to the dot right in positive integers so we gotta have chord rho minus fold location right so that's how far away um like from this line there is so for example so for example this one right here is um one two three away so whatever this is minus whatever that is three right and then we have to find the distance on this side that's away so um fold location minus that all right so that should be what the new row is and again we're just talking about rows because we're talking about a y um so why change here right the column the column is that okay so what we want to do is make a new map right so dots right is the name of it docs with a key value column [Music] equals chord column it's the same thing right and row is new row and the value of that is going to be plus plus and that will just we do plus equals dot okay so plus equals dot that means if there's nothing that exists it's going to assign dot value which is the value of that key if something does exist it'll add on to it okay um else if oh we got to do another thing too we gotta remove that original one um how do we remove i'm trying to get this done before delete okay um delete and the map is dots and the value is chord right okay um yeah because that's the key so we're going to delete that right we've added a new one and we're going to delete it uh okay so else if board we're talking about rows um equals fold location we're just going to delete that too because it's gone right um there shouldn't there should there shouldn't be any right but whatever um else we're just not gonna do anything that means it's within within the parameters um so here for the example of um well this is funny right because it has so we're basically going to copy this or all right so what's our main input here on x1 so i guess we gotta do the next one all right so copy this fold instructions equals x and basically we're going to change huh so this is going to be the same thing for fold location but instead it's going to be call we've already set fold location as um what that value is there dots column equals going to be new call and this is actually going to be chord row plus equals dots delete dots chord good else if chord [Music] so what i'm going to add so this is just i'm going to add a parameter in here um i'm going to pass in cycles number of times that we're going to do this and add a for i equals we're going to start at one um let me just do a count is less than cycles plus and all right so what is what are we actually counting um [Music] the number of dots right uh so what we're going to be returning is length of dot dots and let's throw into our tests uh some parameters here um okay we got here all right so we're going to pass in these two guys and then we're going to in in this case two uh we're gonna do all of them we hope to get 17 and then if we let's just run it actual two that's oh i know why because we're using short pass all right that's it right i'll be able to get 17 i pass it in twice um [Music] i could probably also do like instructions length or something like that all right well anyways let's um go look at what we're doing here all right um let's pull this back so that we can see these and we're going to set um [Music] length of instructions right because that'll just that'll just pass it in that's going to do oh no we just want to do one here right we only want to do one that's what the instructions were all right let's go run it 716 got it our first gold star let's see if we can continue get part two done what time is it 7 30. okay uh finish folding the paper oh jeez this is the first time i think that we've had like letters for things right um [Music] okay so let's um let's do all of the instructions i guess we're gonna do part one we're still gonna do um uh i don't quite know how to test this let's um doesn't seem right there's no reason it should be the same number oh because i need to grab reset the values no that can't be that can't be finish folding the paper how could folding the paper all the rest of the times result in length of that that doesn't seem i mean it's taking longer right all right um all right i'm going to copy this call it part two we're gonna do all the same things but we're gonna do um [Music] all of them right so for [Music] oh i know why for instructions this is why all right we can do this again there we go okay 97 now good we got it so that's the dots um what i'm gonna do here is throw those dots into part two um and we're going to return nothing what we're going to return is um [Music] just an output that we're gonna see okay so what do we need um so we need to make a grid right we need to make a grid so this is what i'm thinking just like this made a zero right here we're going to make a grid that is like the length right so for but we don't care about the value anymore um is greater than max call max call equals dot call if not row is greater than max row max row equals oh okay so after this is done we'll know how big we need to make a grid right and so we're going to make an array it is all right so this is going to be the number of rows [Music] i can't do that can i hmm i'm going to cheat this i'm going to cheat i'm going to look at the input and look at the long ones and i'm going to know that y the number of rows is six or less and forty right so six rows forty six citroes now can i populate an array i'll just populate it with a space okay um i'm just i'm just i'm just going fast now um we'll make it equal to a dot just to stay consistent all right so we're populating this i'm sure that there's a better way to make it with these strings right all right now we're going to iterate through um or um [Music] chord range dot all right i think just do this right okay whatever um i'll just make this uh what part two dots were passing in dots right part two dots you got the rest of the dots um oh that's um look at what we're actually doing let's get rid of this i don't want this anymore part one okay let's run it again and see what happens runtime error on 121 which is what i'm what oh i need to be a pending that's right um [Music] that's right there we go all right we got it i just gotta shrink it down i see it i see you give it to me r p c k f b l r shoot i want to see that more clearly you gotta just copy it all out and dump it now all right we're just gonna do this way [Music] all right that's it lots of what's a what's a walrus operator spider-x you still here i'm not familiar with uh with a walrus operator let me know what that is you're still here um some of the chats there's lots of walrus operators i'm not familiar with that term um i am however going to put that output there save it um i'm gonna undo this and i probably could have done something like um oh yeah i don't want to do that anyways all right got my star time for me to go gotta put my kids to bed so we'll stay here where i am thank you for joining um let me see if there's anywhere i can send you to raid anybody else doing this right now but me nope doesn't look like it oh just me just me oh wait no that's past video okay well either way then thanks for joining um if you enjoyed watching go ahead and subscribe that's nice feels good um follower whatever you do on twitch um i'll be back tomorrow with day [Music] 16 or 14. oh also today with my 26 stars um is a momentous event because it is the farthest i've ever got um so good for me all alright take everyone
Info
Channel: misterjacko
Views: 7
Rating: undefined out of 5
Keywords: AdventOfCode, Golang, LearningInPublic, Programming, TDD, twitch
Id: nIjHApm7O8E
Channel Id: undefined
Length: 77min 4sec (4624 seconds)
Published: Mon Dec 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.