Advent of Code(x) | Day 1 - Go | Using OpenAI's Codex to solve Advent of Code

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone in this recording you will see me solving the advent of code using codex i'll be using the playground and i will be implementing it in replits and we start with this challenge where we are asked to count how many measurements have a value that is larger than the previous one and clicking here i'm getting my own personal input which i will just copy paste into a new replica file measurements dot seriously why not and paste all right so for now nothing is happening just yet and we'll start with setting the engine and for today we'll be inside my comfort zone using go so let's just try giving the instruction as is and i will be doing my best to reuse the language of the exercise itself using go count the number of times a measurement or a number increases from the previous number and the temperature will be low because i don't want it to get too creative and the response length will be rather high because you need quite some characters for this and in the file named measurements dot dot so it opens the file in the right name so that's great and it seems to convert that separated by a comma which is actually not the case but it might just work still well let's just copy paste that and run i have a package main here i don't so i'm going to copy from import onward and replace that here let's see what happens new line 33 right it attend it assumes that i have at least two values per line which is not the case so let's see if i can change the instruction exam in the financially there is one integer per line let's see if it changes the behavior in any way so i deleted the space because i don't want it to get creative but as you can see it still got creative so i'm trying something else and where there is one integer per line let's try it like this it still gives me more instructions instead of implementing code so i'm going to give it a small push and i'm going to start with the word import and then basically it means start writing code don't go on explaining things in the comments and i see that it again reads the file with the correct name and it scans the lines and this time it does not try to split that by a comma so that's good let's see if that works so same as before i am going from here and deleting the comments and let's see okay i got a number one three eight eight let's see that's right one three eight eight that's not the right answer okay let's see if we can change this a little more to say maybe print some comments on the way use as input file where there is one integer per line rent the count as you go and i'm starting again with import because i'm telling it don't get creative and continue scala now um that might just work but we aren't go here so i'll start with package main and import this might be a better push to use the go language so we see that it opens the file correctly does some scanning and it looks like it's just going to print in the end not inside the loop and run interestingly printed again the same counter so it looks like it's doing the same thing let's see if we can print this just move this inside the loop so this is a little bit of cheating but it might help us and i don't count run well we could have expected this so my next guess would be or my next attempt would be to add the instruction print the in case the current value is higher than the previous one print both numbers and package main and import so in case you wonder why does it say here go but it still did color once the answer would be that this is for syntax highlighting as you can see and it's not an instruction of what programming language to use so we need to add that into the context so now i can see that the condition is here let's see if that performs better and run so i can see here that the instructions to print previous and current and previous here is one two nine seven so where is one two nine seven one two nine seven so this is here we have only two of those and if it started with printing it i guess it just shows the last few lines and not everything so maybe we can go to the end just to be sure no and actually well it seems not to do the first few numbers i wonder if this because it's just increasingly going up and i can see that already no we should have caught this but i don't see this happening here so what i'm going to do for the purpose of debugging easier is limit this first to just 30 numbers instead of 2 000 and i'm going to run this again but it will help me debug better whoop okay so as we said the instruction is that if the current number is larger than the previous then print both and add one to the counter and i see here that it prints that the previous is zero and the current is 162 so that's good and it prints then this one so that's also good and this one that's good that's good because quick sanity check return to day one yeah we need to print count the number of times that the measurement increases or even a better sanity check just to use their simple example here so i want to get seven i'm going to change this so i suspect that it should not count the first line because it says here not available not first measurement and it did print in here so there is a good chance that we're off by one and to validate this assumption i will type what was the answer one three three eight i think i will try one three three seven that is also not the right answer but i'm no longer sure whether this was the right one or not so what i'm going to do now is with this example input i'm going to run this and i guess control k does not work here but i'm running this on this code and i see that this is a so this is indeed a potential problem so in case you missed it because i was thinking a bit in my head we print this one and we count this eight times so one two three four five six seven eight but in the example it says do not measure this one because we don't have a previous measurement so it's actually not zero so one thing i can do is go and change the code but that's not what we gathered here for so the question is how do i communicate this better to the computer and i probably should add that as a comment in the instructions there is no measurement before the first measurement let's see if that changes anything there's no measurement before the first measurement so don't count the first row the first line i see i've been using this word throughout the code the instructions so i'm going to stick to this package main let's see if it changes anything that i'm not even adding import well it knows to do that so that's wonderful oh look at that the code even has comments now that's fun split the line into numbers so i can see from the comments that it's doing slightly more than it should and from here i see that it accesses values that it shouldn't be accessing so we're gonna try this but we're also going to expect for this not to work because this this is not even an existing place but let's see yeah this does not exist so you cannot access something that you split like this because you don't have there's only one line and there's only one value in each line so now comes the fun part of prompt engineering which is let's see what we can change so that the computer will understand me better one thing i do already as an attempt is to add import and let's see small changes like maybe uppercase and let's read this entire instruction our comment again and see if we can improve this a little bit so count the number of times a number increases from the previous number let's change this line into excluding the first line use as an input the file measurements.csv where there's one line one integer per line and in case the current value is higher than the previous one print both numbers so this is our debugging comment let's see if this changes anything okay so it opens the file correctly and i still see a split but it says by a new line so maybe it might just work let's try and go so it printed nine lines and that's still not what we want because in our example we know that we want seven to be an answer and so i can see for example that it printed 260 will although it's decreased so let's see if we print here to 60 we do so just one more sanity check is 200 printed in our example it is so looks like right now just prints everything again not what we want let's see how we can re change this and the first thing i can already do is change the comment because i had a typo here and language is a big deal while your colleagues who read the comments will understand that the computer not necessarily will to my hunches again that it might not work just from quickly looking at it because i don't see a comparison between the two values but let's see again nine indeed no comparison between the two values so the problem is something around this line because this is uh this is actually the debugging line so maybe this is a bit confusing let's see if i can rephrase this because this used to work well it did correctly the part of comparing the first and the second the current and the previous value don't count the first line and let's see if that goes better so read the file split into lines okay current and previous so looks like here it assumes that our csv has two values per line and then it can split that by a comma and assume that the first and the second one are the values but obviously we have a a single value per line so we expect this error let's try again explaining this better so maybe the first thing that i can do as a quick solution and deduct one from the answer so this is kind of cheating because i already saw in the guts of it how does it perform and we'll just run this and see if that does correct what it should be doing it's kind of complicated about to try again and generate read the file convert to a string okay split into an array of strings already unnecessary convert the array of strings into an array of integers we don't really have an array count the number of times and number increased from the previous number deduct one well at least it got this instruction right let's see if it does what it should be doing okay this is something i will remove now and see if that helps with anything six that is also not the answer we wanted we want to see seven so this time looks like it did the right thing and we just need to remove one from the answer so let's run this once see that we right we do want to print we just don't want to deduct this let's change this to rent the answer seven and as an attempt to see if this hack around works i'm going to put now the full file and run the whole thing 1387. so that was my mistake i did the i remembered the value wrong one three eight seven one three eight seven all right so that was the right thing and actually the suspicion was correct a while ago but that i typed instead of one three eight seven one three three seven because i remember that it was one three three eight so let's see if we manage to get the correct answer once again this time without the plus one minus one manipulation so go so now it's a little easier because we know what is the number that we expect to get and we can already here see whether we're getting one three eight seven or not go so one three eight seven is the number we want and yes finally we succeeded it took something like 10 15 iterations and the only thing that i was changing is the instruction and maybe the first one or two lines of code which is a stretch to call package main and import the code and i only need to know how on a very high level go code looks like and then i have this done the tricky part is asking the computer to do this in the way that it does what i want it to do so explaining the comment in this example and this is what prompt engineering is about thanks for joining me on this fun adventure today
Info
Channel: Natalie Pistunovich
Views: 216
Rating: undefined out of 5
Keywords: golang, go, codex, openai, no code, nocode, replit, adventofcode, adventofcodex
Id: 5Vl5uOy4oQ4
Channel Id: undefined
Length: 22min 13sec (1333 seconds)
Published: Wed Dec 01 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.