TDD Pair Programming with AI - Advent of Code - Day 2

Sublayer Team · Intermediate ·🤖 AI Agents & Automation ·1y ago

Key Takeaways

The video demonstrates TDD pair programming with AI using the Sublayer AI agent framework in Ruby, solving Advent of Code Day 2 and Day 3 puzzles, utilizing tools like Advent of Code, Ruby, and RSpec.

Full Transcript

okay getting started here I'm going to share out some info of The Stream before we get going um let's see here should be available somewhere right let's see teams Channel we're live and chel let's copy that and share in Discord uh and then we'll get going everyone live the agent hang out and let's see where else should we share at for now um to do second stream of the T pairing pairing with the TD agent here we go and oops that's the wrong link see what's the link here day one yeah so that's day two okay that's right okay um shared that Shar that and let's get going I guess uh um okay so for day two we've got uh I told I was told there would be no math um the elves are running the the elves are running low on wrapping paper so they need to submit in order for more they have a list of the dimensions length width and height for each present and only want to order exactly as much as they need fortunately every present is a box a perfect right rectangular prism which makes calculating the required wrapping paper for each gift a little easier find the surface area of the box which is 2 * length * width plus 2 * width * height plus 2 * height * length the L's also need a little extra paper for each present the area of the smallest side for example a present with Dimensions 2x 3x 4 requires 2 * 6 + 2 * 12 + 2 * 8 = 52 ft of wrapping paper Pap plus 6 ft of slack for a total of 58 ft the present width Dimensions 1x1 by 10 required blah blah blah for total of 43 ft all numbers in the El's list are in feet how many total square feet of wrapping paper should they order okay so let's get set up here in the editor uh we still have yesterday or the day one's project so um let's go ahead and create a new folder for day two and uh let's create um let's see so what are we let's say we've got presents let's switch back to browser so we've got um we're going to get a we're going to get a list of presents subit order for more list of dimensions of each present only one to order as much as they need okay so we we're going to have presents that have dimensions and we need to know how many square feet of um wrapping paper we need so the seems like a good start uh so for Here We Go day two we're going to have a new file of present. RB and new file of present spec spec. RB and let's go ahead and move present. RB over here and close santa. RB from yesterday or from day one and we can require our back and require relative present. RB and let's go ahead and set up a pair here so testing agent pair on uh day two slash present RB and day two present specb well in test of passing and we can get going okay so let's say describe back agent uh present to and save and so we've got our present class and so we're going to have a couple methods here one we're going to we're going to initialize it with a dimension looks like a dimension string so 2 by 3 by four um and so we can and we also want [Music] to get let's see present is a box the surface area of the box and then we need a little extra paper so the area of the smallest side so let's say right okay so we need Dimensions describe dimensions and let's go ahead and or actually we have Dimensions we want square feet Dimension requires oh we want the surface area of the Box surface area and we can say um it is 52 when given 2 by 3x 4 and it is 42 when given one by one by 10 and if we do present equal present. new 2X 3x4 and then expect present. surface area 2 = 52 and present present 1 by one by 10 and expect present. surface area to equal 42 um those are the tests we've got from the example so we might as well uh throw these in uh looks like it's going to uh test are still failing and looks like we might need to give it um a little bit of help oh The tester passing cool does it do it right oh it actually gets the smallest side in the surface area um sides that some sides that why does it get the smallest side there but okay um let's do um let's try to create that smallest side uh also need a little extra paper for each press the area of the smallest side small side area and it is uh six when given 2 by 3x 4 and it is one when given one by slack by one by 10 area this little set okay present equals present. New 2 by 3 by4 and expect present smallest side area toal six present present. new by 10 expect solal one okay so now the tests are failing again because the method doesn't exist uh we've got the smallest side area and test failing tests are passing and looks like it got the smallest side area out of there and um let's go ahead and create this final method here of uh and so this is wrapping paper uh square foot total and let's say it is 58 when given 2x 3x 4 and it is 43 when given 1 by 1 by 10 and present equals present new expect 58 and that expect and here we go tests are passing uh paper total and test are passing and interestingly it wanted to actually just call the wrapping paper method so um yeah uh can run with it test or passing um I guess we can go ahead and get the puzzle input and new file input and we can do our uh solution. [Music] RB require present typing is bad today and um this is going to be Let's see we want over here um let's see it's presents or let say total square feetal zero input and and present equals present. new line total square feet plus you just W paper total and let's put total square feet and seems like it should work let's say and solution RB 1588 178 let's see over to the browser put the answer in 1588 178 that's the right answer cool we got a gold star and now on to part two the elves are also running low on ribbon ribbon is all the same width so they only have to worry about the length they need to order which they would again like to be exact the ribbon requires to wrap a present in the ribbon required to w present is the shortest distance around its sides or the smallest perimeter of any one face each present also requires a bow made out of ribbon as well the feet of ribbon required for the bow is equal to the cubic feet of volume of the present don't ask how they tie the bow though they'll never tell for example a present with dimensions of 2x 3x 4 requires 2 + 2 + 3 + 3 ft of ribbon to wrap the present plus 2 * 3 * 4 ft of ribbon ribb for the bow total of 34 ft present with Dimensions 1X 1 by 10 requires ft of ribon to wrap the present for the bow for total 14 feet how many feet of ribbon should they order so let's see here let's go back to the editor and to the present or present spec and back to to the testing agent and we need a couple more methods here we are going to need looks like this problem is a little bit in uh in the training set or in in the uh training data so we're able to cheat here a little bit uh so maybe this Advent of code isn't a great uh isn't a great problem to to tdd with uh AI but uh here we are let's let's keep going with it and see see if we can get into a place where it doesn't know the answers um so we want to get ribbon length we want to get ribbon wire shortest distance around inside um describe uh smallest [Music] perimeter perf posal to cubic feet volume present describe cubic feet volume okay so for the smallest perimeter it is 10 when given 2x 3x 4 and it is four when given one by one by 10 and it is let's go ahead and do this here um present present. new present smallest perim equal 10 present equals present. new expect present most equal four so now we are getting two failing tests smallest perimeter Test passing um let's go ahead and get cubic feet volume it is um 24 when given 2 by3 by four present. new it is 10 I'm given one by one by 10 here for a second just want to make sure cool um let's see so given 1 by 10 10 cool and test are failing we've got cubic feet volume cool and so ribbon length is uh 34 when given uh 2x 3x 4 and uh this let's see it's going to finish that huh it is 14 when given one by one by 10 present new expect present 14 right okay the test are still passing because it did it's not actually using any of these uh any of the helper methods we we wrote but um it looks like it doesn't matter for now um maybe as the problems get harder to we'll get um we'll get into a situation where um we need to come up with a few few new test cases and um it won't be as straightforward um but we need to get this puzzle input for the second day for the second problem save that and let's go ahead and create um solution 2. RB uh require relative present require let's say total ribbon zero um and total ribbon equals present ribbon length and puts total ribbon all right and solution 2B let's go back to the browser put in 378 3758 and submit and we got the right answer for day two um cool looks like we're still like I mentioned we're still in the kind of training data for all of the uh Advent of code Solutions but um we still kind of haven't really written any we haven't written any mentation code um so I think it'll be really interesting to get to a place where we uh have to um and see where this starts to fall down so um if it doesn't maybe we'll come up with a couple other problems and start to tdd that but uh until then let's go move on to day three and um yeah let's see the problem um Santa is delivering presents to an infinite two-dimensional grid of houses he begins by delivering a present to the house at his starting location and then an elf at the North Pole calls him via radio and tells him where to move next moves are always exactly one house to the north south east or west after each move he delivers another present to the house at his new location however the elf back at the North Pole has had too a little too much eggnog and so his directions are a little off and S Sant ends up visiting some houses more than once how many houses receive at least one present for example greater than sign right arrow delivers presents to two houses one at the starting location one to the east up down up right down left delivers presence to four houses in a square including twice to the house at his starting and ending location and then up down up down north south north south delivers a bunch of presents to some very very lucky children at only two houses uh um okay so let's see what kind of objects we have here so we have we have Santa and then we have movement and some how many houses receive at least one present um so so this is the number of houses Okay so we've got Santa we've got moves we have we have directions for him to move and then we have um then we want to ask how many unique houses delivered to um so let's go back back to the project let's do a new file and we've got santa. RB and new file Santa spec. RB let's go back here and change this to Santa spec3 and santa. RB day three and this move this over [Music] here relative Santa and let's get the agent going cool tests are passing and let's see um so we saying we want a RP Santa do and describe uh let's say unique houses delivered to and and it is two when he moves that it is for when it moves up right down left lower case v lower and it is two when I'm going to copy and paste uh two when it's up down up down up down Okay so let's say Santa equals santa. new santa. move that santa. unique houses delivered expect 2 equal 2 Santa equals santa. new Santa move that expect Santa before and Santa equals santa. new Santa move that and expect Santa to equal two and tests are failing and now we've got move directions current position visited houses uh is a set um it keeps a position uh huh that's cool used a two-dimensional array for that cool um adds the current position to the set and counts the uh visited houses. size cool um and so for how many houses receive at least one present so I think we might be able to jump over to our uh solution. RB get the puzzle input which is that not there um save that let's do new file input paste that there and then in solution. RB we will do um let's say require relative Santa we want to Santa equals santa. new um this is actually contents equals file. read input and santa. move content or say directions directions and then put s. unique house is delivered to so this one seems pretty straightforward let's see day3 Ruby solution. RB uh initialize constant Santa Set that's interesting um why would that be why would the test pass and the test pass in this solution. RB not initialize constant Santa Set spec it did work see Wonder what it's probably something very simple um Ruby solution. RB I really don't want to mess with the implementation files but I kind of want to figure out what's going on here initialize constant why would it be in that main space okay I'm going to try to change the implementation file here to figure out what's going wrong andiz constant set why is it not giving me do not have the right Ruby version yeah must have been huh some weird versioning what ruby did we have running before 3.1 it's very weird um I don't know I'm G to write myself a note to figure out what was going on there but we can move on um okay so let's see here um so we got 2572 and go to the browser 2572 submit that's the right answer of course um but now on to part two uh next year to speed up the process Santa creates a robot version of himself robot s Robo Santa to deliver presents with him Santa and Robo Santa start at the same location delivering two presents to the same starting house then take turns based on instructions from the elf who is nugged Le reading from the same script as the previous year this year how many houses receive at least one present for example up down delivers presents to three houses because Santa goes north and then Robo Santa goes south uh Santa and Robo Santa start at the same location then take turns moving based on instructions from the elf who is egg nugged reading from the same script as the previous year okay so how should we write a test for this so we've kind of got a new class here that Santa goes up so in the second problem Santa goes up and down in the second problem Robo Santa goes right and left so what we want to do is one two two three so we probably don't want Santa to we want Santa to move I mean want to know the visited houses but we also want to break the movements up and compare the two let's see what's the name of this project so we have we' got all the functionality to do this but what we need to do do is figure out what's the best way to write a test for this or what's the what's the object we're dealing with we've got Santa team um or let see we've got a Santa team or we've got houses we've got the house grid that we can then send Robo Santa's delivering to um and really how many houses receive at least one present how do we break this problem down um yeah maybe if we give Santa let's say let's give Santa a unique house is delivered to um maybe we want to change the Santa spec to return the visited houses and then we have a delivery team that sends the movements to the Santas and then takes the set of visited houses um so let's let's do that let's change this to uh visited houses or we can leave visited houses delivered to and and create a new method visited houses and uh it is the position oh I'm not showing the editor okay so um we have a visited houses method it's going to give us the or basically enable us to get access to that visited houses set um but let's uh let's make sure that works so it is it Returns the visited houses when given right arrow move East so Santa santa. new santa. move East expect houses to equal that and that yep it Returns the correct visited houses when given up right down left visit houses to equal that um up is sub one + one so that's this one um right adds one to zero so that's one one let's see so let's get rid of what copilot's giving us here let's see um so we start at 0 0 we go up which is+ one so 0 one we go right which is um got some issues with streaming here got some buffering um hopefully that goes away [Music] soon um cool so let's see here so we've gone starting position we've gone up so 01 we go right which is uh one one and then we go down which is one Z and then then we go back which is 0 which shouldn't be in the set of visited houses okay so then um so then it Returns the correct visited houses for and let's copy and paste this one this and so if we do if a an individual Santa does this then we wanted to expect santa. visit houses to equal that right okay and so those tests should pass once we add the visited houses actually let do this now we should be able to restart those tests get it to edit the right visited house is 2 a cool so now we have access to visited houses so that then what we want to do is we want to create a new class and we can create a new um terminal here and let's [Music] do um delivery team. RB here and new file delivery team. RB move delivery team over here we can start testing agent hair on day three uh delivery team RB and day three delivery team spec RB um um get that going no failures um require RPC require relative delery team and are we going to need to require s here I don't know we'll find out um rcri delivery team and and so let's say um let's see what what methods do we want for this delivery team to do so we want um yeah so we're going to do some dependency injection here so we'll require relative Santa and what we'll do is describe um let's see so we're going to initialize a Santa we're going to um we're going to give it Santa and Robo Santa we're going to expect that each one gets called with the correct movements okay so let's say um what do they call it they call it take turns moving based on instructions let's say um so we're going to want to initialize the delivery team with two Santas and then we're going to call delivery team dot um present with start at the same location deling two presents and take turns moving based on instructions um we want delivery team [Music] to let's say just see what happens if we start ready name and it sends Santa on given up down and it sends Robo Santa down okay so let's say delivery team equals Team new delivery team do yeah just move and let's say or we want to do Santa equals Santa new Robo Santa Santa new Santa Santa actually we can do it named parameters for our sake um and then expect Sant to receive move up and then deliver to up move and then we'll do same thing here and do expect Robo to move down delivery to move up down and let's save the file and see what happens cool uh so we got those directions and then what we want is to also have a uni house delivered to um and it is three when down it is three one given up right down left it is 11 up down down stream Okay so we've got santa santa santa news Robo Santa Santa new delivery team that we going do that in all three of these and then uh let's see what else we're going to do here uh move and then delivery team deler to three and we're going to do the same here move right and then delivery T move and expect delivery t two 2 2 = 11 and save so we've got a few failing tests now we got looks like it's do something else here um test are still failing okay so maybe we found something where it's going to have some trouble here um okay so we're going to need to give it some more guidance on what to do and this also points to a a feature we probably need in the um in the arpc agent of being able to stop this uh stop this looping when we need when it keeps rewriting test and it runs into something here so going to write that down of stop stop after a few failures um and it's still going and it's still got let's see it's changing threading specs and everything um okay so let's kill this and um maybe let's just delete everything in the delivery team file and try this again it's also interesting that it adds uh the Santa class to this file um okay so let's kill that and maybe dependency injection is also a bit of an issue um because it doesn't know the Santa um Santa interface um even if we're has setting an expectation for it um well um we're coming up on an hour here and uh in the first half with the previous problem uh it seemed like it was a little too easy and now we've kind of run into something interesting um couple different things potentially happening here um I could be this design could also not be very good um it looks like I was thinking with dependency injection we could get away with not having having to uh or I guess just passing it's not even be uh not having to pass in uh the definition of the Santa class but it looks like that might not be the case um um I'm not sure um so one learn that passing other classes in without a defined interface isn't might not necessarily be the right move um we have the tdd agent needs to um the tdd agent needs to be able to stop and kind of signal because it looks like it gets into this Loop that I've run into in the past where it just keeps churning and trying but uh just keeps adding more and more um I wonder wonder if maybe being able to try a different model as well or um maybe a different a different design maybe the tests are not correct it going to be 11 Direction CER up down up down up down up down um let seems like a good place to stop um maybe let me see um well I guess maybe it makes sense to switch over to the agent and let's do something like um Let's do let's get it to stop at three attempts so attempts equals zero and um F atts less than three do this and t+ one save that and 01 two right right um and then let's see do I need to rebuild or will that just work one two three four I might need to reel yeah okay let's do puts attempts and testing agent cool that should work I think three in install agent agent cool and try again looks like I need to get my process down for updating the testing agent done as well but we're coming up right on an hour and that seems like uh a good spot to stop and pick this up next time but let's see here let's kill this and got 10 got 11 and uh looks like we might need a couple more maybe a couple more examples could fix this as well but uh with it going into like adding a Santa implementation to this file uh that might not be uh it might not be able to figure it out um but if you made it this far thanks for watching um this a fun uh fun exploration of pairing in a tdd way with uh with AI uh if you'd like to join me one time uh in the future we are you know definitely interested in doing some remote Trio programming with an AI uh doing tdd so uh let me know might have some guests on here pretty soon um and yeah let us know what you think let us know if you get a chance to play with the tdd agent as well um

Original Description

Sublayer is an open source AI agent framework in Ruby that makes it possible to create powerful AI automations to augment you in your work. Check it out here: https://docs.sublayer.com/docs/quick_start To demonstrate how this agent framework works, we've created and open sourced an agent that effectively pair programs with you by allowing you to write tests and it writes the implementation. Join Scott from the Sublayer team as he works through Advent of Code problems in Ruby using the TDD Pairing agent, adding functionality and fixing bugs in the agent along the way. Grab your own copy of the testing agent here: https://github.com/sublayerapp/testing_agent
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

This video teaches TDD pair programming with AI using the Sublayer AI agent framework in Ruby, covering concepts like agent foundations, tool use, and multi-agent systems. It demonstrates how to solve Advent of Code puzzles using AI agents and autonomous workflows.

Key Takeaways
  1. Create a new folder for the project
  2. Set up a pair with the testing agent
  3. Describe the present class and its methods
  4. Create test cases for Day 2 puzzle input
  5. Implement a solution for Day 2 using Ruby
  6. Define a new class for Day 3
  7. Create a new file for Day 3
  8. Define a method to count unique houses visited by Santa
💡 Using AI agents and autonomous workflows can enhance problem-solving capabilities and improve coding efficiency.

Related Reads

📰
How to Build an AI Agent for Real Estate Automation: The 2026 Production Playbook
Learn to build a production-ready AI agent for real estate automation, moving beyond chatbot demos to create a valuable tool
Dev.to AI
📰
GitLab 19.2 Puts AI Agents to Work on the Security Backlog
GitLab 19.2 leverages AI agents to automate security and review tasks, reducing the backlog generated by AI coding tools
InfoQ AI/ML
📰
NVIDIA Releases Cosmos 3 Edge: A 4B-Parameter Open World Model That Reasons and Generates Robot Actions On-Device
Learn about NVIDIA's Cosmos 3 Edge, a 4B-parameter open world model for on-device robot action generation and reasoning, and its potential applications in robotics and AI
MarkTechPost
📰
Real-Time AI Pipelines: Building a Kafka + Kubernetes + Databricks Stack for Agentic AI Systems
Learn to build real-time AI pipelines using Kafka, Kubernetes, and Databricks for agentic AI systems, enabling automated decision-making
Medium · Machine Learning
Up next
Hermes Agent - Ultimate Crash Course for Beginners (AI Agent)
Adrian Twarog
Watch →