Advent of Code 2015 - Day 14 (Part 1) - Golang TDD

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
it's been a couple days family's been at my house excited to get back to it though um [Music] we last left off a couple days ago it uh advent of code 2015 doing it and go uh day 13. um [Music] today we're going to do day 14. thanks for joining let's get to it okay so to the reindeer olympics reindeers go fast but they gotta pause for a minute you know this seems like a really bad idea if you got gotta run them as a team we'll see they can only either be flying at the top speed or resting not moving at all and always spend whole seconds in either state so comet can plot fly 14 kilometers per second for 10 seconds and has to rest for 128 okay just like some trains traveling in certain directions at certain speeds um let's see what our puzzle input looks like okay there's not there's not a ton of them and it looks like there are pretty standard formats name can fly number kilometer four number of seconds okay so that's good there's no like minutes there's no miles per hour they're all seconds okay that's good to know uh all right so i think what we're going to need to do here is we'll do each reindeer at a time what we can do is sort of maybe do some math with division and a remainder right so what we would do is so the sort of full comet cycle for example here is whatever this is seconds right so every 130 seconds he travels 14 times 10 kilometers right so what we'll do is we'll take the total time it by 137 get that multiply it by 14 times 10 right then we'll take the remainder and if that remainder is less than 10 right greater than 10 or less than 10 we'll multiply that like remainder of seconds by the 14 otherwise we'll just do the 10 times 14 because they'll be resting at that time and then we can do that for each deer um and uh find out what sort of the the highest number is doesn't seem to want to know what the name of the deer is just how far they've traveled all right so i think that'll be i think that'll be good um what are we gonna have to do we're going to have to do it i think like the last one what's the last one the input yeah so let's just copy day 13 um rename it to 14. input not that so let's grab this save it do we have a test yes we've got this do we have do both of these guys dancer and all right so they have they have different values right um [Music] let's just add these two separately i have to find out if they have um have those periods i need to get rid of they do okay you know actually it doesn't matter because we don't care about that um that value like we cared about bob and whatever before but we don't care about um seconds that's a standard standard value okay so we'll save this stuff as our input let's close out of them then go to our main tests um our load input should be the same making an array should be the same but we're not going to have to do this string replacement and cheating a little bit because we didn't make a test for that yet just know we're not going to need it [Music] get rid of that we don't need to make combinations make strings keys we are going to need to make an in from strings because these are going to be you know the the important parts 14 10 and 127 are going to be strings and not integers at first so we're going to need to have that function i'm not going to care about making relationships and we are going to want to return a distance so we're going to do that so we'll still comment that out but all right we've brought that back down to bare bones and now let's um sounds like i'm gonna have a child joining me in a moment we'll see okay so let's let's collapse this down we can see more and slide this over all right so don't need this function [Music] i don't need these functions do need string to end and we will eventually have a part okay so let's we'll just do one of these right um then here we're gonna just sort of copy this learning some tricks okay all right so let's go ahead and test uh those two i guess three well i'm gonna pull up a terminal okay that passes so it's run all these tests it's pulling in our input it's splitting it up based on the space um and now we're gonna care about actually parsing it right um so one thing i think the way that we're gonna call this because it would make sense for an additional um like part two is for them to change the uh time right you know what about 3000 seconds right um that would be super super low hanging fruit um for them to do right so we're gonna make sure that that sort of gets passed in as a uh you know a parameter but one thing that i am going to want to do is um so what we're going to do is we're going to iterate through our list of reindeer right it's going to look like this um and we need to get we need to get our first full like number of cycles right so let's let's think um what are we going to have to test we're going to have to test um let's grab this we're gonna test or they could even say like everybody has to go together at the same time right so they have to wait until all of them are arrested and only go as far as all of them aren't rested or something like that right because obviously santa's reindeer can't just my guess is the olympics right there they do different stuff when they're pulling the sled um so let's see test complete cycles okay so in [Music] the case of so what will we be passing in um maybe we can make a struct for for these guys no i just don't want you um let's think so for complete cycles um what we'll do is we'll do some magic behind the scenes in order to get um you know i'll do the math to plug it in right so so in the case of comet right here uh no i'll do them i'll do the math on the other side it would be what 10 [Music] 127 we'll say total cycles so 10 127 and then our like input right so um in this case we have let's say a thousand right so this this is our example right and comment is in the lead at actually let's all right so let's figure this out what do we want um so after a thousand seconds want to divide it by 37 right so that's how many complete cycles so we would want to return we'll return seven complete cycles um i wonder if this has a history uh and then the remainder which is 41. okay so that's what i want to do it's going to be seven full cycles will be the first piece of this slice the second piece of the slice is the number of seconds and then what we can do is look at [Music] we could have like the number of meaningful seconds right um [Music] hold on one second i have a child calling me let me pause this for a second all right i'm back let's pull this inside okay so here's the question do we want to have then the number of remaining seconds right so these are going to be numbers that we multiply by so cycles so this number will be multiplied by 10 and 14. and then this number is sort of going to be the remainder right um so how many seconds in there hold on one second okay okay so i guess the second the question is this number right here you have to turn that down thank you all right this number right here assumes the full 10 seconds right this number right here i think should be like the remaining number of seconds even if it is 10 right so in this case it should be 10 right because 41 is greater so we'll have some logic in there that says what's the remainder if it's greater than this number right return this number if it's less than this number return what the remainder is does that sound fair i think it sounds fair okay so that gives us what we want there um let's look at our other guy here so let's look at our amounts um 11 [Music] 162 i think 162. um and then also a thousand seconds here and we're expecting from this see here um 1 000 divided by one hundred and seventy three so five and five times 173 obviously wait oh minus 1000 it's 135. which is less than you know our total there which will mean 11 seconds um okay all right we'll have to come up with uh sort of an artificial test case um let's just make it super easy uh [Music] make this like 50 seconds 50 second sprint um and we'll make the time of their cycles 100 so that would mean 50 on 50 off right and i don't want it that would be another 50. um [Music] 50 on rest for 50 and our total time here is one little one right so in this case we would have one full cycle and one second of remaining time all right so let's go ahead and test it fails because we need to make our function i don't know remember what it's called but we'll get there all right funk complete cycles and then remember what we're going to pass in we're going to pass in a couple ins right the first is [Music] oh fly there's an int rest and um and then duration um and what we're going to be returning okay uh and then we're gonna return with um [Music] um and all right can you turn that down please all right um all right so that's what we're coming in what are we gonna do right so um we'll make a new variable cycle equals um fly plus rest right and called complete cycles it should be capitalized so what do we got um um duration divide the bicycle how do i get rid of the remainder floor right lower numbers round down um oh that's annoying because it needs to be a float 64. can i do that math math floor okay well let's do it um i don't know if it'll allow me to do this because those aren't okay because they need to be float um [Music] maybe i can do this is annoying can you hear that music in the background all right hopefully i don't get a copyright notice because of the child playing with the tablet in the background let's see what we got here [Music] i know i did this before um let's see all right so this is what i'll do um [Music] i don't necessarily well i do care about cycle okay so what i'm gonna do is make a variable floats um [Music] it's going to be quote cycles our float cycles equals duration plus cycle right can i do that okay not used okay so complete cycles is going to be floor because that should work right what's this oh i need to write float before here okay can i do that okay so do all these numbers need to be both 64s this is really annoying what's really annoying is there's no like reason okay so this is what we call a cycle time we're gonna have just cycle cycles and it's just going to be this should be a float 64 right because it can't be an n i'm doing this division right this i don't like this at all this is the annoying things because like you know when you know how to do it but you just need to figure out how to do it in the language um i guess that's why i'm doing what i'm doing right um maybe there's just the floor division [Music] we're gonna find it here um it's already the floor divisions okay well that's all we need to do right um because it's an int it's gonna make it the floor division nice okay so complete cycles will just be um duration divided by so this is something i've learned right so um [Music] because the type of these are ins and because the type of this is an int it's going to do floor division with this division here right um because it can only be all right wait let's round towards zero well we'll see when we test it right okay so complete cycles is the number of complete cycles now we need to get another one right which is the [Music] extra seconds and that's going to equal um duration remainder cycle time okay right so uh that's the remainder right and then we need to say if extra seconds is greater than or equal to y right so um complete cycles remember that was the first number and fly okay that was the fly time because it's going to be it's more than that amount of flag time then it's all the fly time right um else we will return and extra seconds we want um complete complete cycles here so complete cycles ah in extra seconds um right because if it's less than the fly time then we're only going to have that uh remainder there okay let's give it a try nope all right um cannot use directions i type int as the type i don't have a map floor all right and save it pass all right so now we're able to find out total cycles oh we want to call it total cycles don't we let's rename some of this stuff and then we'll rename this as well okay so now let's um make one more value here hey please stop please stop your dad um okay so we need to make a function no it's just going to be simple math isn't it all right let's just let's just see about part one let's uncomment part one our data is our test data and what we want is it to return the lead which is 120 okay let's look at part one we're passing in that string all right so four all right so we're gonna have uh a farthest distance to zero okay so that's we'll increment that up as we go if we hit anyone that's greater than right all right so um for we don't care about our index data okay we're going to find their total cycles right equals [Music] total cycles and then we um we're gonna have to do some weird stuff right uh because we have to make those hints right string to end string to end um reindeer well it's going to be ugly um let's count zero one two three four five six we need all this don't we 7 8 9 10 11 12 13. okay so those are the first two numbers and then our last number uh remember we're gonna have to pass that in um what do we call that on the other one duration duration all right so string duration and duration int so we're gonna have to save this go down here um let's look at our 2503 that's going to be our puzzle input distance on our test however we're going with a thousand so we got a thousand here um okay back here why is it unhappy why haven't i been able to do this oh all right let's just change it to um what we have up here string reindeer let's see if this works right so that works so let's make fly and this one's rest and it's 13. and here we're gonna add fly you know what we're going to do i just want to see one more thing all right um [Music] i don't want to do this string to end a number of times especially for this fly because we're going to be [Music] um doing it a number of times right so i'm going to do these here i could have made a function for that that accepted a byte and returned the right but too late okay so here we go we got cycles this is going to be the int that um oh we got two of these right uh oh no it's going to be the two digits all right so now we got our stuff now we have to assess it um distance equals um let's do this other one too variable um we'll call it sprint and it is index zero one two three okay so distance equals sprint times cycles zero right that's the total number of cycles plus sprint i'm sure i don't need these but they help me um collect my thoughts right sprint um [Music] times cycles one and this isn't right right because it's not sprint time cycles it's sprint times uh cycles times seconds right times fly okay splint times fry so the number of cycles they do is going to be the times they do for example 14 times 10 right and then we're going to add on sort of that remainder which is this times however many other seconds that might be one more cycle right but it might also just be one second right and what we're going to do is uh the logic um if distance is uh greater than r this distance then far this distance is now going to equal distance okay and then we're gonna return [Music] for this distance all right let's test it e uh not enough arguments to call part one oh this is supposed to be inside here okay i'm a test strong and this is in mango i probably did the same thing in mango did not pass failed we met about a2i so that means we're not able to turn a number into an inch all right so reindeer here oh um never turned it into an array uh it array equals what do we have array no that's not what i'm doing here doing down here okay all right now we should no it should be gravy there we go pass um i think we're ready to do the full full guy let's do it go run main.go all right so first one is two six hold on so [Music] to let's do this input two six nine six and we got our gold star all right let's see what part two is tim doesn't like the old scoring system instead at the end of each second he awards one point to the reindeer currently in the lead uh i'm gonna have to completely re-architect this so in the old way right i was going through and looking at each um each reindeer at a time to see what was the case at the end now we're going to have to do like an off and on range and i think i know how i can do that right so um what i'm going to do is make a i know how to do this in python right so you can make like a string or an array or something like that and what i would have would be um you would do say 14 10 times in a row right and then zero 127 times in a row right i could make that for each um each reindeer right and what i could do is um then iterate over a range you know and look at the index and say you know comet is plus 14 comma is plus 14. common is plus 14. common is plus 14. oh 10 sec comma plus zero plus zero and then i could look to see which number was the greatest each time right um so [Music] i think that's what i think that's what we'll do don't know if i'll have time for it i'm gonna make a struck right for each of the reindeer and i'm going to have each reindeer have you know like their name and each reindeer will have their um their value right can i do that they're um each one will have their name they're like slice that's their you know 100 and you know the k in the case of who was it comet 137 you know index thing with a 14 14 14 000 right and then as i iterate through i think i can i can i can do that and then i could say you know and then a total that'll change at the bottom each time after i do each of them um oh or i could just do like a cumulative total so do comment the whole way through at each index so i'm like appending a pending to comment all of those you know 14 uh 28 etc etc and then have that repeating itself that just might be too much work though and it's almost been an hour and i thought this would be a short one so actually i'm gonna think about this some more and come back to it um but i think that's what i'll do promise i won't do any work um maybe i'll think about it while i'm gone um [Music] but i'll drop tomorrow at lunch time i'm going to get back on the schedule um december 1st is coming up um as soon as defense december 1st hits um i will be instead of doing 2015 i will be doing um 2021 in 55 hours and 35 minutes so that's coming up quick um at midnight i'm not gonna do it at midnight i'm still gonna do it at lunch um so i'm not gonna be one of those certainly i wouldn't be a speedrunner right but um yeah i'll be doing that just a couple days what's that four days five days so anyways um i'm gonna keep on with uh 2015 until we get there you know maybe we'll get to day 18 or so and then we'll get started on uh 2021 all right until then i will see you guys later
Info
Channel: misterjacko
Views: 1
Rating: undefined out of 5
Keywords: AdventOfCode, Golang, LearningInPublic, Programming, TDD, twitch
Id: wJuJzjKUATI
Channel Id: undefined
Length: 54min 36sec (3276 seconds)
Published: Mon Nov 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.