Advent of Code 2021 🎄 Day 6 🎄 Golang TDD

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello good morning or afternoon everybody um back here for day six um and let's get started see what it says it's a little bigger all right so seafloor is getting steeper oh i forgot that we were in search of the keys to the sleigh um it has gone quite a ways this uh these keys matching school of lanternfish those those guys with the little dangler thing come on give me give me a picture of the lanternfish no no lanternfish all right um [Music] they grow exponentially creates a new lanternfish once every seven days however this doesn't necessarily synchronize between each fish one lanternfish must okay so they're just they're in spread out um each fish is a single number that represents the days until it creates a new one all right a baby needs long enough to baby needs two extra days to have their first baby lantern fish um two lanternfish at eight and then those two fish would have five for the original one and seven for the progeny okay so and it goes to six not seven because zero is is our index okay i think we can do this i think we do this with a map right so for example with this one we would have a map with the value one or key one equals one two equals one three equals two four equals one and then we could loop through that and sort of make temporary maps that save over themselves right um where we shift it down right so index zero right however many are zero day when it comes in uh we add to the new map one or you say the value at zero is at key 0 the value at key 0 is 5. we would then in the new map add a key that said 6 with a value of 5 and 8 with a value of 5 right and then we would go to um yeah index up to one and so on and shift that down to zero and two and shift it down to one and three and we get tricked up there for the seven when we shift it down to six we'd have to add it right because the ones that were at seven that are going to now get added to six are going to be combined with the pre-existing um ones that just had the babies now right so um that i mean that seems like pretty simple right this seems like it's gonna get crazy but really we're just gonna have nine keys right a map of nine keys with values that say how many are in each one so who cares if there's like a billion on each one that doesn't take much time or space right i think i think that's good that's simple enough that if they do something super crazy uh for [Music] day or part two then we won't get too screwed all right let's um minimize this when it was five yeah let's let's let's take let's copy five and call it six and so we don't forget change that to day six all right all right and i don't know really if this is going to be a good one to test we could do individual um we could do individual ones where we're not going gonna like do the huge maps right so just you know pass in you know one of day zero and make sure that it spits out the right ones at six and eight um you know one at zero and one at seven to make sure that it combines the one at seven you know that sort of that sort of thing right so all right let's let's see what we got here we're going to want to check we're going to want to make a slice though we're probably going to oh you know we're going to want a one-liner for this aren't we let's uh let's grab that one liner from our template wait i guess we should look at the puzzle input i just assume yeah okay it's one line let's throw that into input text real quick save that um input text save that okay let's see right for wait where are my main.go multiple okay one line so what we're gonna do is grab main.go here and i'm going to change load inputs to this one because it's just one line so we're sort of thinking about it a little bit differently um [Music] i'll close out of that again all right so what do we got here um we got clear um [Music] what i'm going to want to return in this load input is just a list of ends or do i want to just return the map um yeah let's do let's do all the work like we did yesterday in this load input stage um and sort of branch off that so what it'll be is a map um vince is the key and int is the value and okay uh obviously all this is going to be off a little bit let's we'll we'll do that we're over optimizing we're doing too much right now all right we got to get rid of some of these things that aren't relevant to today's um we'll rename these when it's time um let's paste that can i think that's the last thing i said yeah um all right so okay this is wrong but we'll we'll get to that in a second [Music] so what are we going to do obviously it's going to pull off a string we're going to make that slice of it by splitting it on the commas i think that's what our input looks like right yep um and then we're going to want to iterate we'll make the int as we like make the map right um let's pull up our tests okay so lots of these gonna go away it's too big all right um [Music] so my input that i want i don't know so this was a problem i've had before with some of these is it isn't always a consistent order for things like this um let's let's do it anyways so what should this look like um so i think it typically is an order right um one one we do two one three two four one all right um i don't know if i need to do all this okay let's see let's see what we need to do so the first thing we're gonna do is we got that one string right a long string of um right we're gonna split it so this will be a string and we want to get out you want to get out that so let's save that and test it let's just pull this off condition right now um and then pull this out oh that passes so what tests do we have right now we have um we can make ins we can make slices we can turn those slices into ends we don't really actually want to do this do we um we're going to go directly into this one um i don't want this we want to load input all right so here we go um we're going to have file all right now we got to get so data is going to equal that string right um you know i wonder if we could just do string file zero i'm going to try it so then we don't need this like sort of pointless for root loop um data stream equals all right let's um test it i know that it's going to fail but we'll see um okay so it fails but we got a 51. hmm okay there we go um what is that what is that right there am i telling it to do that that's just some formatting okay so got a data string we are going to want to um data slice equals make slice of we'll just combine this into one here okay see what that looks like okay we got what we want there and now we need to make our map all right so let's actually undo this and we'll just um so we have that slice we're going to for each one of those we're going to add it to a map right um and say if so value i don't think we need a value um okay in input make inch num alright so this is what happens if it's in there right then we're going to um let's just copy this and add one to it else [Music] equals one all right and we will return input let's go ahead and test it now and it tests okay good so we are oh people are home um so we are now successfully grabbing that all right and i think that that's all we need to do to really get oh we could do some geez do some other tests um so one test we're gonna have to do is to see if we can like promote you know like add a day right so let's go ahead and make it that's for that i really think that this is going to be like the only test that we have um next day and what we'll start with is so let's have an input um let's see one one easy peasy right and then we want our expected you know what we should um we should make these lines shouldn't we and the output should equal remember we're shifting these down a day so it should be 0 1 right should be the let's make a little room all right so there's a couple things i want to test right that if we've got 0 and 1 that we actually are going to have a 8 1 and also a six one right because that's when the next day after this right the baby is born so that's the one at day eight and then the parent is back at day six right so this sort of shuffles them hello core activities how are you doing so that's one thing that we have to do and then we're also going to have to test whether if we have one at day seven and then also [Music] one at day zero that they don't like step on each other right so what we would want here would be at day six to have two right because the one at day seven is going down to day six the one at day zero is also going oh and we need i would have gotten me i also want a day eight right um because the one at day zero all right so i mean i think that these are enough test cases for us right so test it fails obviously let's make the method for it next day and again what we're passing in is going to be a map and what we're outputting is going to be and also a map all right but what we want is next day oops okay okay so let's start uh iterating through this right um all right so we're going to do a for loop on these um we do care about the index and i'm just going to say key keep things straight in range data so then we're gonna do special stuff right so basically everything else is going to be so there's two special cases right if the day equals uh zero we have to add it to two places if the day equals seven we have to anticipate that there could be something there right um but we could still we could still do that same sort of um loop right here regardless and you know add add it to it but we can't do that with zero right so we do have to make uh a catch here so if index equals zero then and we don't have to be crazy about this right we know that this is the first one we're starting with right um so we're we're fine with that we're gonna have two additions um day no next day six equals data zero right because that's what the key is and then also next to eight equals that right actually do we care about the key kind of do we care about the key or is this a value i think that's the value and we'll see all right so we're taking care of index zero right and then else for the rest of our stuff um so this is this is now where we're shifting everything down um i'm going to write it as if we're going to overwrite day 6 for right now [Music] and then fix it later right but actually no let's let's keep working um so now we're hitting index one and so what we want to do is say uh [Music] next day index minus 1 equals is that the key or is that the value let's just make this a string and see what this says okay it is the value um equals keep well we call it value because that's what it is all right so what we're doing is we're adding that to can we just do that and account for six let's try it no we can't um so we only failed one test so that means we might be able to do it let's see what we failed on 26 all right so we failed this one oh it's because i have a 2 here oh no i want to have a 2 there so i want six to go down so seven didn't pop down to six um why didn't seven pop down to six so what probably happened was we got up to so we did the zero added it to the eight and added it to the six then we got to index two oh that's because it's index two not not the key hmm [Music] how do we find the key it wouldn't be index minus one it would be data let's sh let's just look it up let's see or key an element in range oh well i'm a dummy all right so index is what that key is well then that should work because the index should be seven minus one is six so next day six plus equals value hmm let's um the value is the value of like seven right okay let's run it again um okay so this is working right we're saying if index which is the key equals zero x86 next to eight i'll change this to key maybe that'll help me make sense of it all right so we're going to iterate through this map if the key equals zero then this is right this is what we want to do if the key does not equal zero then next day one minus one value equals let's just look at key i'm a little bit twisted right now i'm sure i'm sure that i'm like looking at the wrong arrays so let's um let's just print uh data and then just print next day and see what we get here so why is it doing it twice oh it's doing it a couple times right because um i have a couple tests right this one [Music] it doesn't have an else this one it does right it only has it doesn't have an else i'm going to comment these guys out that's not the one that i'm having problems with um right so that's what i'm passing in and i currently have a six one and an eight one and i'm currently on [Music] seven one what i want to do is set next day key minus one which would be seven minus one is six so i want to set six to [Music] plus whatever that value is oh it passed geez what why did it pass now maybe i was getting a different one wrong hold on now passes what did i don't know what i did differently we're gonna go with it all right so now i am able to um so now i'm able to do the operations where i can successfully sort of do all the test cases for my my following day okay so now i think we're ready to actually run part one right um what are we actually returning total number of fish okay so let's let's uh just change all these to fish t-o-t-a-l okay so push total equals zero now what are we gonna do uh we're gonna get this initial map um never make a test first hold on um input equals load test input part one and put and we want the output of this to be oh and we should also have like a turn value here um so [Music] after 18 days there are a total of [Music] 26 fish and after 80 days there's a total of five nine three four okay so we i'm sure this is going to be like a part two it's like oh how about a million days we'll have to look into that all right so this now is going to get um days into days int um 80 for part one all right you so comment this stuff out now um all right so what we're going to do so we have that map um and that is our day zero amount right um so we need to make uh let's call it new um do i need to i could make like no i don't want to make recursive one um let's think hold on okay so i know i need to make something that's not data to loop through on the outside right um so fish map and we're gonna we're gonna bulldoze over this um every time i think all right so let's do a for loop um i equals zero i is less than days i plus plus all right so this should iterate through whatever number of days we pass through and we're going to say fish map equals next day fish map right so oh we can't have this okay so what it's gonna do is oh we need to make that like a copy so maybe just do that because we don't want to copy the reference to the map all right so for you can do this quick and dirty like they're doing it um range data fish map key equals value okay so now we've got a copy of that and now we're going to transform it i think um but now we gotta count it right um so finally we're gonna do for don't care about the key uh value in range fish map fish total plus equals value all right let's go ahead and test it it's not happy about it why isn't it happy about it um oh man you know what the next part might be might be some nonsense like they die after five times reproducing or 13 days or some crap that'll be horrible i hope it's not let's just hope it's not all right um what's problem here let's go ahead and we know what our we're gonna grab this and um to save ourselves a lot of horror we're going to um just make this like five all right test that and we'll be able to see hopefully these all right so after day one one one well there's not a zero why isn't there a zero oh because i started i started with the first one right so i'm starting with the initial state that was the first one i passed in before i so that would be one one two one three two four one all right second day zero one one one two two three one good now we're gonna start reproducing zero one one two two one six okay it's it's doing this i just gotta make sure that when we hit this okay day three zero two one one five one six one seven one eight one all right zero one four one five one six 2 and it says 6 3. all right so i am thinking that my problem is this one i should have six two so let's pass in pass in the case that i'm failing right which is this one right here okay um and what i want to get out in return is oh shoot that's what i actually want to get no i did that wrong i want to pass in this one book and i want to get out jeez oh my goodness what is happening all right there we go all right and i want to get out [Music] this but i believe instead of i think the only thing that's wrong is the six why is it didn't copy that oh my goodness oh i know what i'm doing not copying this correctly okay this is gonna be a three okay it's really weird because i thought that i had settled that with having one like why why why wouldn't that work right because why wouldn't that work specifically for this one i have food waiting upstairs and i want to eat it but i also know i need to finish at least part one here um i mean this only matters you know what i'm gonna do i'm going to cheat and say next day six equals um [Music] data zero plus data seven right else this will be everything else right [Music] next day minus one equals data sequence value let's test it by failing all of them now 26 and 27. all right so for this one why would i be getting six three why would i be getting six three passing in zero push it over there i care about those i mean i should i'm getting mixed up now this is taking longer than it should all right let's think through it again we're making a new map and we're setting each of the keys to be different things this works successfully starting with key zero and that should be the order that we're iterating through oh unless it's not if 0 is not the first yeah geez um no but that's not what it's doing next day equals data zero right that's works when we just have a zero kids going to preschool all right so what would what we want to do is set the next day key with the exception of right there's two special cases when the previous day is zero because it sends it to two places or the previous day is seven because it has to deal with like input coming to two places when it goes to six now i don't know i suppose what order those are going in i'm just saying range data i mean when i when i look at these maps it looks like they're always in order right so it should always hit day zero and put that stuff in day six and day eight before i do anything else so after this operation zero stuff is in the new array at day six um let's go ahead and hello people watching you enjoy me fight the struggle bus all right let's go ahead and comment out some of these and make sure that this is like doing what we think it is um but what man go 45 no all right all right so those are working as intended um from zero it pitches them back from one it goes down to zero right let's look at this one this is one that i believe is failing yep uh what does it do it grabs zero one and seven one and it should be combining them okay so it hits the first one and does this operation six one one then it should go to the next one in data which is one it equals seven so what it should be doing is setting at the next day six which already exists and setting it oh geez all right so it's still not passing why would it next day six equals wait well now that's confusing because the first time it passes through it should have next they should have both of these it's six and eight did i scroll too far oh no there's no reason for this unless it did it out of order can i [Music] well maybe just prints it in that order but doesn't actually keep it in that order so let's um that would explain everything data equals let's just sort [Music] wait and data why is it not happy with that m equals map keys oh i don't know that's horrible that's horrible that's too many okay sort of map by its values don't want to print it out by its values um oh that that sucks oh all right so let's just let's just not care about the order because apparently doing this in order is a pain in the butt all right so um so we'll just do it explicitly right um if key equals all right i'm going to change this loop to um just a regular um i equals zero i is less than eight uh no nine i plus plus all right um what's the problem with this just i don't use it all right um all this all right so um we don't care about the order anymore we're just going to iterate through this list and we're going to say next day if if i so we're going to sort of do it in the opposite right if i equals um eight so that's the last one next day i equals data zero well i guess it can't be an elsa um now let's do it else if i equals six next day i equals data zero plus data seven now the problem is is i'm going to have to ensure that those exist right um else next day i equals data um now where could our problems be uh oh we need to we already did eight right so we're never gonna we're gonna hit eight at the very end and then be done we won't ever get to that right um and this is the eye of the new new day one um all right so the problem with this will be is that there might not be those keys in data right so let's go to our [Music] um stuff here i mean i don't think it's gonna be long before there's one in everyone right so it doesn't take up more time does it right not really um so we're gonna have to do a sort of a data hold on [Music] six seven eight all right um this line is extraordinarily long okay let's see let's test this doesn't like oh that's because that's what we'll do to make it a little easier on the eyes um and what will be passing on one one so that should go to zero one this should be zero okay all right so now we're passing that we'll do a similar thing but we're going to delete all these right and we're just going to copy this test boy that's ugly okay so what were we testing before we need to test that oh this is our first one one here makes it over to eight and six we wanna make sure that if there is one on both zeros zero and seven that it shows up on two there and the one there and save that for later all right 29 it's the second one it's not passing it oh i didn't get rid of the the one here same thing with this one all right 34. so this is the one that we've been having trouble with right we're passing in one in the zero spot not one in the one spot that might be part of the problem and we want the seventh spot we want eight and two and zeros all right passes all right um let's see if we can pass now what's this um 18 days oh it's not going to work because we have to change our input to return um 0 0 1 1 2 2 3 3 four [Music] and we'll just grab five six seven eight right here um fail because our load input is not doing that all right so all right so now we're gonna do one more for loop here right or i equals zero i is less than nine um you know i like doing less than or equal to eight um i plus plus okay if just need the eye here i is not there right so this is um seeing if that's not if that's not a valid key then we're gonna do um input i equals zero okay now we're gonna test it again um did i mess up some yeah i mixed up some braces um okay pass all right we're we're good now let me get rid of those all right we have a winner we're now able what oh all right passing our tests wait did we do both of them did i do both of them no um great uh now let's run it for real um [Music] 80 days great go run [Music] main main.go gold star all right part two live forever oh thank goodness ah this is so this is way better than i ever imagined 256. save we're just gonna still do part one we're not gonna need part two because we have parameterized the number of turns uh add another test case to 56 go test passes go around main go there we go oops gold star yes yes we did it that was beautiful i didn't have to change anything all right um i'm going to ask you if you're watching and you enjoyed it to go ahead and subscribe usually i try to do these either in the morning or at lunch time um or if it takes too long in the evening that hasn't happened yet um i'll definitely be doing it in the morning on uh wednesday thursday and friday of this week because i will be unemployed um so you can join me then let me find um let's see here someone to send people to let's see you know most people stream this either you know in the morning um there might not be anybody no pointer there we go i don't know uh if you're here who's here in the chat room um currently let's see but uh if you're watching i'm going to send you to a french person let's see i don't know if you know french but if you don't know french then here is your big chance to start thank you for watching um have a really lovely day take care you
Info
Channel: misterjacko
Views: 27
Rating: undefined out of 5
Keywords: AdventOfCode, Golang, LearningInPublic, Programming, TDD, twitch
Id: 9ox2XtHAHfs
Channel Id: undefined
Length: 92min 58sec (5578 seconds)
Published: Mon Dec 06 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.