 Hello, and welcome to AdWords of Code Day 19. I forgot to start recording, so let's go again. And what we are doing, what we've done so far, is boobing. We're just parsing the input. We are creating robots to mine minerals. Currently, I'm trying to parse these robots. And so we get some blueprints, and then we draw it, and then we're supposed to figure out how to get the maximum amount of geodes or something like that. I'm eating amazing cookies. I'm going to read the input. It's going to be file path to file input. Read input equals, what's going to be? I'm going to parse the first dot read P to S, and parse blueprints over read file. This might work to read input day 19, explain better in a bit what we're trying to do here. Okay, this is annoying. Maybe it is working, but it's not. Let's do here, but it's not doing it. Quite or not, let me just change the example to be nothing the same as the input. Okay, map. Okay, we're not going to do this. We're just going to do, okay, 42, 314, 2, 7. Now you parse the input. I'm guessing we can. Yes, input was parsed. Okay, so we have these, we're trying to collect geodes, and we're trying to collect the, to collect geodes. We need geo-collecting robots to make those. We need obsidian collecting robot to make, need obsidian. So we have obsidian collecting robots. And then we have clay collecting robots to make any type of what we need or so we need and we have an or collecting robot. Each robot can collect one or so we can make robots, but we need robots to collect resources to make more robots, right? You need to figure out which will be the maximum number of open robots at 24 minutes by figuring out which robots to build and when to build them. Okay, so we have, we can select actions at each step. Okay, I have a cut on my, okay, let's model the state. So I did a state, it was SD, SD, R state. Okay, so this is a four robots in clay robots in obsidian robots. And geode robots in. Okay, let's actually make this just the robots in comma, in comma, in comma it. Okay, and then it's or a clay obsidian geode. Now stocks is going to be the same in update state, update state. Now let's say this is our state, our state, this is going to be RS comma STS. And I can just add these all like I cannot. If I have like one clay robot, right, one more robot, I will have one more on that, right? RS at OC, OC, or clay obsidian geode, or robot clay robot, obsidian robot, geodrobot. OCBG time update, this is the time update. Okay, and this is just going to be O plus OR, B plus CR, B plus G plus GR. So when the time passes, I'm going to start building the clay robot. And then we get the one war. Okay, now let's do a factory. This is just what the factory is doing in comma, in comma, in comma. Let's call this mining. Okay, so this is actually going to be a bit different. Empty factory. Okay, the factory is going to be called the empty factory. Now let's include the factory here. FO, FC, FB, FG, robots equals OR plus FO, GR plus FC, BR plus FB, BR plus FG. Now let's have these actually be the actual cost. It's OR robot, it's clay and OR. Okay, so this is going to be the OR cost. This is going to be obsidian robot, OB rock, OBRCC, 0, 0. And then this is GROC, so GR robot cost OR 0, 0, GRCC type, crypto. ok this is how we update the state now let's actions data action ok a pass build a this is the last one build kill we're having it usual or whatever now key action takes the state and the action and we turn to state take action as the maybe I want to have it like this let's just have like this a RS at our state in which okay take okay so build or it's gonna be a RS factory equals one comma zero comma zero zero add quipo quipo, quipo, quipo, add quipo a, a, b, c, b, x, y, z, w, a plus b, a plus x, a, b plus y, b plus add b plus b so stocks is just gonna be our state stocks is add quipo a stocks robots robots equals add quipo factory the factory is okay this is simpler the build so then we add one factory is like that that's how the input here the blueprint BL BL and let's actually have this more or robot a player robot OB robot and G or robot that's gonna be O equals or robot or CR if I want to build an OR the factory negate quipo is equal to less stocks is equal to RS stocks equals stocks add quipo negate negate BL dot negate quipo exactly the same for build clay is out there it's the O C the CR and then build ops is gonna be the same and then build geo is gonna be now let's say stimulate the example what do they actually do in the example let's keep this here and keep this here so every minute let's see and ex acts is a list of action ex acts so first day pass pass pass and then a build clay then pass and then build clay and pass and then build clay pass pass build OBS let's say here let's review it I want to go too far okay so pass pass or clay pass pass or past play pass clay rápido past play past clay past clay past clay past clay past clay Pass, pass, clay. Pass, clay, pass, clay. Pass, pass, pass, yes clay. Pass, pass, yes. Pass, pass, bill, geo. Pass, pass, geo. Pass, pass, bill, geo. Pass, pass, bill, geo. Because we have pass, pass, bill, geo. Pass, pass, pass. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18, 19, 20, 21, 22, 23. 24. Okay, so run around. We're going to take the state and take the action and give a state. Round is equal to a sd. Equals takes action. And I need the current blueprint also input. Take action, bill act. Take action, bill act. And then we do mine. Take action, bill sd act. And this. And then we did the thing where we do mining. Do, do, do, do, do, do, do. Okay, now let's do initial state is equal to our state. So I have the RS. And I have the key one. So I have robots. Stocks equals factory. Let's not call it empty factory. Let's call it empty. Quaple, quaple. Empty, empty. Empty, quaple, the robe. So the factory is equal to empty, quaple. But robots are equal to 1, 0, 0, 0, 0. RS state. Let's make this bigger. Let's call this here script. Now, so what I think this is going to be some sort of dynamic programming, like schedule optimization, cost constraints, all of that. Okay, so we have the script. Now, what I want to do is I want to do a bold L. Okay, and then we have the exact script. I'll take the input. I take the initial state. I take the action and return the final state. Exact script. B-L-A-I state. X equals fold L. Run around. B-L-A state. Exact script. And it's going to be up. The inputs are actually here. I don't need to take in the I state because I know what that one would be. Okay. Exact script. A init job. Initial state. It's okay. E-X, E-X, E-X. It doesn't look good because it cannot print. For short state. Deriving true. Let's... Oh, day 19. But I just... We're running through. Unexhausted patterns and function take action. Take action. Okay. R-S-S equals R-S. Okay, it seems like... There's something wrong here. 1 or collecting robots. 4 and then 2 and 2. I have 6 or I have 41. I collect 8 obsidian and 9 open geodes. Each robot... I'll just read this. I just want to know what the inputs are. Make sure we got them correct. E... Move this trace show here. So each robot costs... 4 or... 2... 2... 4 or 2 or... It's 0 because 3 or and 14 clay. It's 2 or and 7 obsidian. Okay, so this one is correct. Take action. Stocks equals adcouple. Stock robots. Robots equals adcouple robots. Factory equals empty couple. I just... It's probably because I'm folding L, but I should be folding... Okay, let's see. Let's just take that first one. So I start away with 1, 0 and then 2. Okay. 1 or collect... You don't have 1 or, you have 2 or. You don't collect this one. You don't have 1 or. You don't collect this one. How about you know have... 1 of them. Then I have 2 or and 1 clay. Then I have 1 or and 2 clay. Geodes, they produce geodes. Okay. There you get 9 at the end here. 2 and 3 and 3 and 12. They're probably not the same. Okay, I haven't actually computed. Yeah, okay, so it's not the same. Theater for actions. All right. Now let's say... Compute the possible actions in the current state. We are going to be doing... Let's see. Possible... Possible... Action. Possible... Actions. Inputs of the blueprint. We need the state. And then we get a list of actions. Possible actions. BLST. Compare a... Can... Pay... Quibble... Quibble... And... Let's pair these up. It pairs... It... Causes... It takes an action and returns... Okay, so for actions I should actually do... Make use of your word and... You know. Okay. Cost of action. A... Input to action. To a... Quubble. Now cost of... Pass equals empty... Quubble. Cost of BL. A... BL and a... Bailed... Or... Is equal to... BL.OR Cost of BL.BL and... BL Clay equals BL.GL Clay robot cost of BL.Build... A... Geo... No, OBS equals BL. OBR and... Cost of BL... Build a... Geo equals BL.OBR No, Geo. Geo robot. Okay, now a... Possible... Actions... Given an input... And a state is equal to... Is payable... Takes... Two quubbles... A... Quubble. Let's just say word quubble. Compare... Quubble is... Ordering. Now, compare... Quubble. Quubble. Now, let's not do it like that. Is payable. Quubble, quubble, build... X... So A, B, C, D... X, Y, Z, W... Is equal to A... Larger than X... A... A larger than equal to... And... B... B larger than equal to... Y... C larger than equal to... Z... And... D larger than equal to W. Okay, possible actions... Action... Possible actions... A... B, L, S, T... Equals... Now, we won't do... We will enumerate the tuples. Pass to... Okay, so these are all the... Build... Geo... Let me see... Enum... Enum... Haskell... Enum from two... What is it? Error here. Main bound to... Ah, maybe it's not that good. I think this might be actually a... Error... Like the older record dot here. Okay, but let's say here... An... Enum... Filter... Is payable... S.T.Dots. Dollar... Map... A... Cost of bill... These are the possible actions in this state. Enum... So let's now, during our time... Thing... Let's just do a... Trace show... R.S. prime equals... Trace show... R.S. comma... Possible actions... Ah, we can't do it here. Okay, R.S. prime... XX script... A... S.T... No... S.T.A... Run around... S.T.A... But I also want to hear... Trace show... S.T. comma... Possible actions be hell... S.T. So in each of the... In each of the ones we take one... So first we can pass. Then we can pass. Then we can pass or build clay. Then we can pass. Then we can pass. Pass or build clay. And... S.T. Let's do A. Okay. What do we did? Okay, pass. Build clay. Pass, build clay. Pass, build clay. Pass, build clay. Pass, build clay. Pass, build clay. Okay, and now... I want to... Search the space. How do I do that? Well, I can just generate all the possible routes. And then we do that. We're gonna get a lot of combinations. Okay, so let me check here. Explore... Space. And put current state. And generate... Generate a list... Of actions. Okay, so first of all... Where pass equals... Possible actions be L.S.T. Now... Then I want to do for each of these. So... T.A.A. equals a... X. So, explore space, a BL. Take action. So, run. Round. So, this one will do BL.S.T.A. Run around BL.S.T.A. Explore space, BL. T.A.A.A. Okay. Run cat, map. Pause. Okay, and now... These are all the actions. Quite a lot. Let's do... Okay, and now we're gonna explore... Explore the space, BL. Initial state. And I'm gonna map. Take... 24. T.A.A. Is gonna be a lot of paths. Let me just start by saying... Where are the possible paths? There's not gonna be a lot, right? Because the first thing we can do is just... Okay, this is not being lazily valued at all. Because it's exploring first all the paths. First all the paths. And I'm not actually T.A.A. And I'd never actually... I'd never actually turn anything. I need to see here. This is not being evaluated in the way that I thought it would be. Okay. Maybe it's because I don't follow... Okay, so let's be very careful here. Map. A2. T.A.A. Pause. Where's the one to select next? Okay, we have the possible actions. And then we... Let... Let... S.F.A. State from here. Because T.A.A. State from here is a list of actions. S.F.A. If... F.P. From here... V.A. equals... Map. A. S.F.H. Does this not give a list of actions? But it is concat map, right? Because... But this will not give me the... Oh, now it did. And now it's just always giving me the... First one. Let me see. So it's something like this. T.A.A. is the A.A. action. And two. Where's the possible actions? Okay, well let me... What if I just have the number here? So I need to... Explore. More space. And... Zero. I'm going to just... Do the empty list. Concat map. T.A. Concat map. T.A. Boys. So here I have to... Or not the empty list. The empty empty list. How many possible paths of 24 are there? Maybe not trace... Go then. Scratch out. Link type. Path of links. Fireboard. Okay, can I... Eliminate a lot of them after 12? Maybe? Let's say, you know, if they haven't... Started generating... Geode at time 12. They're obviously not doing well. Let's see. The best one here... Builds their first geode cracking robot. Minute 18. I do get up to 18. But of course it's a lot harder for the input because... Okay, let me see. Eval. Action. Input. State. Where is... Let's make a... Here. Let's make a... We have input. Bestie. Act. That's equal to... Where... Final state equals run script. Agh, check. script. a... Act. a... b, l. ah, state. Let's make this take in... a... a state. Let's see. This is... 1000 times... a... sl dot geode. sl.sdocs sdocs f0 fc fb fg is equal to a final state dot stocks but let's talk about, you know, one million times fg plus a 10 000 fb now let's say input a state list list of actions now it's prune and let's just say that a blst equals a take let's take the top 10 100 take top 10 reverse a sort by compare on eval blst import data dot list a sort by import data dot function on print so print a path is this now we're gonna print prune we're gonna take a top n right prune and let's just say print take the past five paths of a path one bl2 bl1 initial state in etal state initial state in etal state in etal state let's do it for okay we're taking the top 10 let's take the top 100 okay now a let's take the top 10 now we are gonna say a final path is equal to is equal to so map ma'am so we're gonna take the packer but one of us acts and we're gonna do a explore space 12 bl1 and then this is gonna be xx script a initial state i get that when i'm running it again and again but it's okay explore space bl xx script bl1 the initial state that's gonna be the state and we're gonna do this on the what is it company about here the last statement okay and print prune link bl1 this is extremely naive search right okay now this is the first one best one is equal to this now let's print xx script best one bl1 initial state what's the final state here that certainly is the best one but it is not wrong it's run right okay pass pass don't play why is it a oh maybe it didn't didn't work right if i didn't hold it right you'll have to have this he is the and then okay i seem to find the same maximum as the first one so pass pass don't pass okay what about bl2 oh wow little lanny saying okay think the little lanny and you highlighted your message with all your channel points not bad this is like iffy right right because we we um i didn't do the two here probably not enough fusion going on either right and here i'm still just taking the top 10 i should definitely be able to cut some one of them off um at the end as you can see here okay let's now do some optimization a possible actions let's just have that be if it's payable 50.docs cost of bl build geo then this is our one the process will not die let me see here yeah it's not killed okay so we build geo if we can no need to explore anything else there now let's just see here to use let's go i'll be all two here now bl1 bl2 and let's have this bl2 use equal bl1 okay so you know if we can't build the geo robot we are going to build the geo robot okay that's uh as simple as that really let's see here okay i'm also like keeping a lot of them around right which i don't need i think the memory usage here is what kills it actually what if i do it in a couple of steps a little enemy can only chat if she highlights her message ah i got seven viewers thank you for tuning in how is everyone is my chat how's it going hey christian it's not going great i'll tell you that i keep running out of memory which is not great okay so paths so okay so i'm going to do this a couple of times okay uh we're going to do the a run round in a and then we're going to have a initial we're going to have the state and the state and then the well the input actually input and taking a list of actions and we're going to return a list of actions okay run okay this is our run round this is going to be a a run a few okay so run a few is going to be a where okay we're going to do paths okay so uh let's see this is a a moves and then we're going to we're going to look up so i had some moves and then we're actually going to do a plus a hundred times fc plus f o f o for paths equals a explore space moves a after prune to moves at bl to use there's going to be bl for bl and then a state bl a state prune equal prune after prune st sorry and then this is not state this is actually a a so far okay i'm actually gonna do here uh first i'm gonna prune uh prune after prune so far and then a a equals concat map so far uh let's do just say exactly the same act map act daughter explore space a moves bl xx script and this is false act bl moves after prune bl st so far prune okay this is going to be actually this prune after prune oh i need the view here let's see here now okay so let's do um let uh let fst equals a and let a bl to use equal to bl one now run run res equals a run a few we're going to do six moves and we're going to prune to the top 10 of the bl to use the initial state and we're going to start off with the empty act and let's print out what we get from that it's always a bit unhappy after it like runs into memory issues okay so these are the first few let's say what if i just do uh three here okay now a run res prime it's gonna be i'm gonna do three after that and i'm gonna give it run run res run res prime now okay let's do this a couple of times six six okay that was quite fast a and now we're just taking very few steps at a time from the last one i actually so this is valid only if like the uh the heuristic that we chose means that the like the eventually best path is in the top 10 after six steps which there is no guarantee of let's go geodes and put state action int geos and then i need to give it all the stuff bl to use initial state uh initial date best one okay we get to a print a print a maximum so here it gets to eight okay so that was too bad let's pop this up to a hundred each step that was not even in the top 100 what if we do a 25 but here we run a few but we do it three times eight and we do find the best one but what do we do bl to the one we did initially right and it's gonna run out of memory i could uh you know exact the space and then like not remember the like not remember the actions just uh just give it the int kind of explore space a zero st equals okay and then here instead of doing concat map we got the possible actions t a it's a action return at least the wins we're gonna see then let's just do explore max print explore max a 24 bl to use a initial stage but here's no pruning i mean that's really slow right because then it has to kind of fully evaluate everything before and we can't take but this is the one that will like will definitely work right maybe we can like uh jump it right so we find the best strategy to get uh to get one geo right then we don't have to go don't have to go all the way i think that could work yeah there's a bl to here and there's nothing after eating there either they get what i mean right so we find like the best one to go get to one yeah this is something you would probably use like some dynamic programming scheduling algorithm okay let's see like a reddit and event of code i want to see what people are doing maybe i could do like a shortest path algorithm where the destination is i want to find yeah when i with the destination is uh oh okay so yeah okay let's try and do this with the bfs okay and so the neighbors function take the neighbors here neighbors let neighbors equals a to take a list of acts and we do uh possible actions uh bl possible action bl to use and and then xx script equals act a initial state okay this is the neighbors okay a latch where possible this and a map plus p this is the neighbors function i will have to modify modified bfs import data dot set import qualified data dot map as map import data dot set import data dot map map okay now uh this bfs here will be the this is not the neighbors or neighbors mm-hmm neighbors e they will take input and state action to list of action neighbors bl sd equals and here we do this uh oh yeah take a list of actions to list of list of actions uh maybe i should do it differently neighbors take a state and the list of actions to a list of state comma action now i'm gonna i'm gonna say so not end this is gonna be p to o you know do that here p to o this bfs prime so instead of the end here i'll have and a to o now so then i'll not have q is equal to equal to end i'll have a and f q otherwise it's the same so it's bfs with the end condition now let us use bfs here bfs a let p raise equals so i have this neighbors function somewhere i'll be just under anything here okay let's say a st comma act for possible pl to use and then this is actually pl comma act this is actually st and here i'll have so this takes the p and they will go and say run round pl sd p comma x plus plus this is the neighbors function let me just say that bfs bfs is equal to b prime a n s e n s n s a compare and then we're just gonna say a eq equals compare eq compare eq this is the neighbors it's gonna be this and bfs bfs p p is equal to so the neighbors function is going to be a bfs prime and i have to export it bfs prime and the neighbors function uh n s b l to use okay and then the start state is initial state and empty list and in the end function is going to take in an st and the list of acts i don't care about list of acts but i'm gonna say that what i'm looking for here is a what i'm looking for here is a st our state stocks equals don't care g g is larger than zero if there's no sword state okay let's just derive that now let me do that here and let me just print bfs p okay it's actually quite slow or um again n s b l let's try and find it like the what is the shortest path to make a clay okay so the shortest path to build this is shortest this is the shortest path to get clay and then we just go here uh just okay and i actually just care about the last there just a bfc f clay bf clay print f clay bf clay so this is the first this is the shortest path yet clay now uh starting from there what is the shortest path to get a obsidian f obs bf obs and then we're gonna start off with f clay bf clay i didn't print it out okay and now let's see if we can use this to say best first geo bf geo i need to print it out reverse these actions to make it so that you pick something else first i like how we're doing all these optimizations and now we're we're still worse than when we started we started off with the wrong path oh and now it worked quite well let me see pl to use what if i use below one here okay so and then i want to do um then let me do actually something here let me so from this starting point explore okay maybe i don't need to even reverse here okay and now i'm gonna do uh print explore max a length bf and geo bf geo so 24 minus bf geo and the initial field to use and we have the bf geo hi rickard what are you doing so i think these are okay let me what if i bump up here i am doing and the advent of code day 19 and it it's a lot harder than yeah and i even said i said i would stop right at this point but i feel like i'm almost not doing something here thank you for the follow let me just see okay and then i'm gonna say uh xx script false and what does it say xx script xx script false and now i'm going to because it like the last action that it does might be bad xx script false and then a init bf geo and we are going to say pl pl init initial state one step one step back a bf build a clay build xx script init bf clay and this is bl to use so from here i'm actually gonna say not believe you i'm gonna say a first clay i'm gonna say a clay and i'm gonna say a init bf clay okay now we're gonna do this but we're gonna say play ob s g and we're gonna say ob s and geo like a clay build clay build let's paste it and say ob s and geo g and then we say play ob s g we take a step back but it's still saying that yes we've been at it for three hours already not stopping right not stopping so far let's see uh b geo build xx script init bf geo build to use fg o geo build ah there we got nine oh very good oh does it say for build two uh seems like rushing to build the first geo is not the best option for for the what do we just do here then we need geo ob s g ob s a clay that is funny that um they're rushing the first ob s build the first rushing to build the first ob s i'm from iceland record but i'm in suede right now okay now i know what because i copy too much that is a bit sad actually i always try to do something when i can but then it says seven there okay so this one was if i search for the first pass to build one no zero what if i search i want to be as passive as possible i'm hoping yeah this works for the example so we kind of rush we find the shortest path to but it's really bad at kind of figuring out because now it's like trying to actually see if i can speed this up a bit xx script just place this call it prime this is xx script prime verbose xx script now i don't have to reverse it he let's see here initial state and then i just run the last a bit quicker because i'm not like adding to the back of the list and i'm always adding to the front of the list but it's giving me well i have to add to the neighbors works now why does this not work yeah how about not checking the stocks but checking the robots okay so now i found the best one to get to one let me just actually use the i don't care about this in it here mm-hmm why did that take so much more than so much time okay gio bfgio bfgio this is the quickest pass to two robots okay can i get to three robots i can get to three okay i cannot get to three robots what about okay floor max 24 minus okay so who's going too far that one this is this is a bit irritating right so we find a path it's the first fastest path to build the geo robot okay so can i somehow like take this path and optimize it what is the a script what is the actual path that we want pass pass build play pass pass build play yes build play build play what if i um what if i skip this one you need shell state okay so if i rush yeah that doesn't matter right but okay so um i think i've tried this before it was very slow possible actions okay i mean so well i do know that you know rushing clay in the beginning is the best thing to do there's no need to look at anything else i mean according to the script this is the um this is the like the correct right so so like that on turn 18 build geo so question is can i somehow kind of take the path that i um that i have and uh improve it that's not it mm-hmm a larger chamber okay 12 let's not okay let's see let's write depth first search audio write depth first search at least empty sets at least okay so let's see depth first search let me just refresh okay e okay depth first search i have this scene in psq dfs prime or this is the scene here it says it's a discovered function okay so uh let me let me see ends equals neighbors start dfs prime and then this is that doesn't seem to happen to me well dfs prime scene the path is empty then we get okay let me get nothing well let me get left scene dfs prime a scene a as equal to case dfs prime scene dfs scene a and then this is curve j's and s neighbors curve off there are any neighbors there are any neighbors then we do off so nothing then we just do left scene a as case dfs prime scene set dot insert a set dot insert scene of case filter not set dot member lip set dot member if there's no new neighbors that we haven't seen before and otherwise even they seem okay so let's say work dfs prime i think dfs is like that now let me try doing something here and dfs dls t is equal to where pause equals possible actions blst okay i should put that there in tfs bl now let me run this dfs and bl and we give it the starting point which is gonna be zero initial state and the end function is supposed to be this the same as here it's a how long does it take for it to figure out the the path does not exist for bl one that is okay let's now see we just write this loop here go equals a case so if nothing we return n minus one just something yeah this is like the brute force right just search it until you find something me it was quite fast for that one but here we wanted to see it to get to 12 let me see let's see if we can like prune this even farther let max or equals a maximum bl dot or bl dot or don't try this at home kids okay let's see now the max or reserve it's gonna be the maximum zero this is gonna be the zero index of index q over this list bl dot or bl dot over bl dot this is the obsidian robot bl dot here and bl dot here that bl is supposed to be able to use in okay so i'm gonna prune away those states where ndfs bl so if i have more or i have not built a robot then if i could have built a robot but i didn't then i don't want to take a look at that state wow that finished really fast okay so i think this one works actually task one input task one takes in this input bl to use okay go zero and let's comment out all this best per search something now let's just say print dollar map dot map task one dfs we're not using dfs res here and it doesn't like this this is my simple heuristic map task one to int and we do sip with and then what i want to do is only get the ad and the value and i want to return five times v and we're gonna take the sum of this we did try a lot right okay we get the result here now let's let's try this for the input my year six are two yeah see it doesn't work for the example but why is it giving zero here it's horrible costs for or it's clear about costs for or it's gonna cost for 19 right okay so maybe the right answer here is uh okay yeah no way right because the heuristic is just off what if i do here uh four times or as if i could bail any robot i will be a lot slower right and i uh accelerated by saying here i can't write because i might be okay so let's go back to the separate it see if we can find some good heuristics okay so robots or cr br okay so if and well that's what they're saying if or is larger than or equal to res is zero okay and i'll be okay i just say that if or or is larger than res is of zero so if i'm if i've built more robots then i'll ever need cr larger than res is of one or br larger than res is or any resource that's on r that's not a cheer if you already have x robots creating resource r and no robot requires more than x of resource r to build then you never need to build another robot many are anymore okay so yeah so this is basically big i've built too many robots okay now for the second heuristic and okay brand new resource we are the x robot another average right where one said so x times t or a number of robots times the earth time minus n plus a plus o no t is a time minus n t or times t plus plus o larger than a t times well but then it returns okay let's see was it the uh no this one is two so let's check the first one here a equals something okay if a larger than or equal to res is or res is of zero okay let me see here and dfs the pause equals a pause prime is equal to heuristics heuristics a st heuristics equals h of st nst pause prime for h of n and r state as the stocks equals or stocks clays stocks obsidian stocks robots or robots clay robots and obsidian robots equals now um the h and a so a empty equals empty h and f pass equals h s s of h and h m n s t a r s now okay let's say that i'm looking at the um the a build i always want to so i don't care if i'm looking at um build if i'm looking at build geo i always want to pass build geo okay that's pretty simple okay now if i'm looking at a build or rest equals h and n s t at h n s t r s okay and then i want to say if if or larger than equal to um res is of zero or let me just do it like this then rest else build or rest okay let's just start with these heuristics case a a a a a a a a a a a a a c case build or a c s you can build clay now then I want to see if uh if clay robots are larger than one obs so here's here's the very obs Br then okay so this is the first two and now I want to boom in the second one oh this one says times t plus a larger than or equal to t just do like this let's hope this works it's slower for sure let's hope that means that it's considering more things right just making some chess move contrast this thing go I want to assure that's completely lost to do sacrifice my queen yes I do believe this one is lost as well let me resign rematch that is just what happens hmm what did I say last time 1257 too low let's see 1404 we did task one we were almost there we had the DFS but we needed the good heuristics we got them you live on the phone you're very you probably need to have 32 minutes okay so task two task and task to task one this one takes in time as well task one input to end task one equals as n 24 okay task to it's equal to task and but this time with 32 and big three let's see what happens we got this we just see alright is gonna run for a while let's actually not care about this let's just care about this 32 and let's just leave it running after we've built the first obsidian robot don't even look at building any or robot let's see let's try these some of these crazy heuristics build or if OR is it a little or it's a simple one if we bolt the first obsidian robot don't even look at building any or robot a we are larger than equal to one if we built the first gout don't build or anymore play robots if you are okay that's also one good point I can I can I can immediately during update and kind of unify these update we bfs okay we delete all this stuff the eval and the first base where we build if possible wait I don't I don't I never okay run around okay so okay this can actually then be just G and so instead of saying GR is larger than equal one I just G okay and now I never need this VR okay then I want to say run round in here I want to say time minus head so much time staff run around time minus it okay and then we find run round what did I put it and I put it here yeah he int take action T no action T take action take action so here I'm gonna say an int again is that much time is left I don't care in this case I don't care in this case I don't care in this case I care in that case I actually preferred yes T-minus one right that's how much it's gonna make okay thank you for joining it's going okay and I had to take a hint it's still very slow and we're still waiting for it to solve task to people are saying I added these your six and it went from one seven seconds to one second the mine is taking seven minutes I'm hoping yeah so I went on the subreddit right thank you get get it wrong but the answer is like oh take a look at the subreddit and so I took a look at the subreddit so and I'd already kind of I was doing breadth first search first and then I was doing like death first search and I kind of knew okay this works but I need to prune a search base I went to the subreddit and they there they talk about a bunch of heuristics which I'm implemented here which is the you know I don't know not it's not as nice you know but this is really just kind of all let's take you know domain knowledge about this and put it in there and I feel like you know that's that's fine right you can we can dump in some domain knowledge there some heuristics yeah exactly how are you Aaron I want to say the 57 this is the advent of code 20 22 day 19 we used to be like the first few days took us a half an hour or so and now it's taking many hours I think yeah on Saturday took like seven hours oh it's this a it's fun it's this a science does this create advent calendar right so you get you get one you get one programming problem per day and the story is that you're like on the North Pole Helping Center doing stuff anyway yeah so first it starts off quite easy I would say and then it gets harder and harder and harder yeah it's been fun and then every year since 2020 I've a streamed live on Twitch and there is a competition so if you go on leaderboard these are like the people who solve it right away and then you get like stats but I'm not competing with anyone I'm just doing it or the part of it I mean it's all I ask actually let me see I want to short circuit this even further so this one ends up being just the past right okay so I want to say here that I don't care and the our state so our our state of M let me see so stocks FG FG last a last of P press show in and FG we're gonna go FG plus one so now instead of like when it finds something that's higher doesn't have to search again and again again for that right you I have a no I don't have one yet I am working on getting one an important distinction what do you do with that qualification well I do research like the other day I got my paper got accepted I mostly do work on automatic program repair oh what will I do with it I mean yeah I mean we do research right I might work at like at a consultancy doing Haskell stuff but it's also you know it's it's more like I want to say joining a church right it's like you know you get a master's so you can get a job with your degree right but you don't do a PhD because of the qualifications I'm sure if you want to do like if you want to do something like you want to be an academic you want to be for professor or something yeah then then you need a call like PhD is a qualification but it's also just about you know being able to do research right being able to come up with ideas you write a paper about them and you work them out right and then you can kind of take a and that's what research is right you've done like if you do your research and it's this idea of how do we you know in a good way kind of further humanity's knowledge right and that's what I like you know I was when I was thinking about it I finished my master's and I thought a do I want to just get that money or do I want to do something that's I want to say meaningful right yeah I mean it's like normal science but it's a it's a bit different in the sense that it's more like math right so we're more trying to figure out like you know making up systems and then discovering their properties right whereas normal science you know you're more talking about systems that actually exist right like the body or the cell or a virus right whereas we're more like huh you know what if I might a program and language that they did like this what if I you know if I have a system that has these properties what can I do with it what it is an example of research that you would do well good question I have a bunch of papers there's like what this is what's that's about a published at XE and there we had this program called proper which does automatic program repair right where so you have some properties about your program right and then we we fix it right we we take the program we poke holes in it we run quick check which is like a testing framework that generates test cases basically you have properties we can take those properties we can take the test we can localize in your code where it fails and then we can repair that right and then we can synthesize code right to replace your old code as well like here right so here we replace product with link and here we replace product with some and it kind of works you know we made we could solve stuff you know non-trivial programs like adding the not a space that's quite nice but you know and then that's just that's our thing right like we spent so much time debugging right and repairing programs right so what if we could automate that right and you know no one knows how to do it well I mean we have ideas some people are using like neural networks I'm doing more classical stuff kind of like constraint based AI and then like the paper that got accepted two days ago that was it was on generating properties or synthesizing properties using these say this new data structure called easy TAs where you can actually I'll just show you searching in my god searching entangled entangled program spaces so this is the data structure we used those is Jimmy's paper this guy James couple and then this is 90 a polar couple and she is super good at program synthesis Armando he is the guy who invented what's called sketches which is this type home-based thing or you yeah so use that to generate the property so question is what would it work to complete fix heal something the knowledge of what's supposed to be there needs to be known right yes that's why we are doing the that's why you don't use to unit tests right we do properties so you actually specify I mean you have to specify what your program should do right you can give it a type the type can tell you what the program can do you can give it and you give it a spec in the form of like a quick check spec and a and that's why you know our follow-up paper right was kind of how do we generate more tests right like how can we take your code generate a bunch of properties now like one property that will generate data and then test that your code like like it will test that when your code holds like the output has some properties right so it's not just one unit test right it can be the equivalent of a hundred or a million unit right we take your program we generate those properties right and then we can feed that into the automatic repair to repair the program right and of course the properties can only be generated if your program already works so you know that's one of the things you could do right you take like a known version that you knew worked right now it's not now and then you find something that doesn't work and then you can generate the properties and then you can find okay you know what how can I fix it so that it still like has the old properties so it's like right creative AI the right stories or makes arch yes except right so that's the thing right the AI is super confident and it gets the big picture right like it's convincing it seems like it's correct but it will get the get the details wrong like you will just say one plus one is not to I mean we will look to generate a whole paper and we'll just have random errors but the general outline is correct right so that's what we were we want to come in right we want to I mean and that's kind of the future right you take these AI generators that generate something that's general like the outline is correct it's almost correct but the details don't make sense and then we feed it into this more classical system like I'm working on to repair the general outline right and and after that you don't you just write the yeah I mean these are good questions right is this further along than chat GPT I mean it's different right I don't think you can so I mean the guarantee is also that like if the program is repaired it's correct according to the spec right chat GPT makes no guarantee that the output is correct right and you know there's a huge difference in almost correct and looks correct right and that's and that's where you know that's how why it's hard right because biggie you know if you want to run a code on an airplane you cannot ask chat GPT to generate the code because it might be wrong and then a lot of people might die right so that's not what we want right so you want to be able to be confident that our code worked and then yeah okay I think this will get the one for this one let me cancel it for the example let me just run it for the input beginning concept for nano machine I don't really know so what do you mean by nano machines here yes well a little bit yeah we're writing the tools that kind of the synth you have to synthesize the the nano machine has to be able to understand what are the possible shapes that you could become in order to repair whatever you're trying to repair right and but yeah so that's why I like doing research right because you know you're not constrained to current events you can be like okay what do we really want right not like what can I do with the tools available to us now but like you know if I could create the tools what what would I want right I mean that's kind of the idea right with integrating something like chat GPT right they give a prompt and then they can generate a bunch of stuff and then you can fill in the details right that's also the part point with science right is like the chat GPT people are working on chat GBT and I'm working on the part where takes that output and makes it complete right so I'm filling in the details yeah I mean it's a it's it's cooperate right I had I had contacts at co-pilot right the GitHub people and we were thinking of doing something with them but yeah it's always hard because like the person I knew and they weren't they didn't have contacts high enough so they couldn't really like host me as a research intern and then if I'm not hosted there it's really hard to get good feeling for what they're doing and how it works so let me just make sure that yes code takes up so much memory yeah I think it's cool right and then you know it's also like yeah I'm doing a PhD but also you know I do get paid for it right so not as much as I probably would you know on the market but it's still okay you know for this streaming setup that is something I'm not supposed to multiply with the quality levels we'll need to get the what other cool things am I working on yeah I can show you the spectacular paper so this one just got it stepped it to ICST there's that of the double blind so I can actually talk about it now this is the one where we're generating properties so you give it some kind of thing to reason about so the idea is and then yeah later we have to the plan is to be able to kind of take in a full program and it would kind of pick out the interesting parts and run do those and then this is the easy to a stop and as well we do right we create this data structure that can efficiently represent all terms and the key here is efficiency right because if you're a if you're generating programs like there's a lot of programs so you want to be able to represent you know a billion programs by you know something that's a lot less than a billion bytes right with these easy days you can do it in log time so you know 25 bytes or whatever to represent a million programs or billion put like 20 yeah produces a size a lot right and then you can operate on the easy days and do operation of them and then you that's as if you are doing operations on all the billion programs in one time right and it's makes it super fast and we can kind of enumerate the programs it's called right so you can kind of say okay what are the programs and you represent and then we can take those and we can use quick check to generate these laws right and then we generate stuff like you know series a little length of the empty list would be empty adding to empty list to be empty and then this one is cool so if you map over the if you map over the reverse of a list that's of same as take like reversing that's the same as doing the reverse and then like take mapping first and then reverse right and these are all like kind of laws that make sense if you right and so this one's also cool kind of right so if you map over a list of concatenation of a list of lists then that's the same as mapping a function the mapping the map over that list and thank goodness there's a lot of like these laws that we discover and then we have some data and we are a lot faster than our main competitor quick spec particularly for very huge programs like huge lists which has like a hundred hundred things in scope we take 91 seconds where as quick spec crashes and we've seen it crash and taking up like 250 gigs what are laws laws are kind of thing that laws are like these properties right where you say you know this is equal to this right so that's the idea was a law right yeah okay so it was this is the huge one that crashes one of the quick-spec game just can't handle runs out of memory but we can that's one of the things I'm working on a the thing I just did is this a CSI Haskell this is a poster only actually where you know here you have like a classic error in Haskell doesn't tell you anything but what we can do is we can we can actually figure out what exactly was going on when it happened and then I'll put that right so you can add these traces right and this is a very key in functional programming because things are like generated lazily and then they are consumed lazily those like the distance I'll call it from values being produced to values being consumed is a lot higher than in imperative languages right where you kind of generate a value and eat it up right away and but it's also in some way it's closer right because you only generated right before you generally use it but like the distance in code might be very far but like the distance in time is very close so by saying okay when you generate it let me know what you did this is like this is like a ghc fork and then I wrote this a paper on type laws like being able to sometimes weaken the type system in languages like Haskell in the sense that you can tell it or you can kind of make it so that you can do things that should not be allowed but if you like you know that they won't break at runtime and this allows us to test things that would all this voice be very hard to test and then of course if you boot up Haskell you go GTI and you say huh I want a function that goes from string to IO it searches the scope for you and it tells you off you can use put string put string a land read IO print fail and this is a ghc and this is what's called valid whole fits even though set f if I meant level whole fits equals one or higher and then it would actually not just tell you things that like directly have the type also things that like you know if I you know right file if I give right file something that takes a file path like some file path right then it will actually have that type and then that is a valid whole fit yeah and I added that and this is my paper on that suggesting valid whole fits for type tools and we had these ah yeah super good for lens actually um and I had this super nice thing called subsumption graphs that kind of would give you the perfect order like the most relevant ones first but uh and it would be really cool in the sense that you could you could even if you use type level hackery you could even find um you know you could you sort by time complexity of functions uh and I added this to Haskell and now you know you go to repel it Haskell you know you have you have it there right so you know it's not just my g it's here right it's everywhere that's what I added um yeah and that's also like you know that's where it started that's why the title of my listen sheet which is like the the halftime degree we do here it's called the whole story it's quite nice ah I like this picture anyway I don't think you have to be smart I think you just have to have the patience let me take this number here number one was 21 or two was and I think uh yeah I mean and that's why you know are you asked like what are the qualifications of phd gives you and I think it's really you know it's this right it's so that I don't understand any of these things either but I know how to uh not understand things right so I know so I you know this guy calls me up he's like I got these ectas I heard you do testing stuff do you want to use them should we do we let's write a paper together I'm like okay let me just look up this state of the art and synthesis stuff and you know become an expert in it they cited me and then let me do something brand new with it right and that's what you do in a phd right you're you're comfortable with not be understanding things right and then you can just do yeah cool things that no one other than that no one else is doing right because but then you know if you go to Haskell the holes guy right eh ah that's just me uh I remember Eisenberg was like hey Matty you are the holes guy do it so you own a feature right yeah and this is you know this is you get to work on the I can give a Christian what you're saying right you get to work on the cutting edge right and also you know like this prepare program like you can't you can't right but it's not like you can just download it and start using it right away right uh it's more like ah it's out there we're trying to figure out how do we make these things what are the things that we should not do right so there's a lot of mistakes and what what can we do that makes it work right and then once you figure that out uh like like these right um look at this this is version space algebra vsa by guvani okay this is how this is how we represent expression okay this is how they represent expressions in version space algebra now where have you seen version space algebras ah if you use excel that magic feature where you can drag down and it just makes things up for you that just work that's vsa's right that's this guy here guvani a legend in the biz okay and then you know and and let's look at that uh guvani uh guvani well these are like locked behind walls uh which i do have access to at work but here we go automatic string processing spreadsheet using input output examples okay i mean i don't even have access to this one i do have it in my draw box i should probably not share that on stream seeing as it's super copyrighted and not by me anyway uh this is open i mean so it's cool right like it's these column one into the currency shown in column two it's these these features right like these magic features that come out of research which is why we do it which is why we must do it anyway uh do i recommend doing a phd probably not uh it's very long uh i'm in my final year now but it's taking me it's it's it's a five-year program uh you do get some papers accepted but usually you don't get them accepted like you put a lot of work in you have to learn how to write papers you have to learn how to you know convince people that are a lot smarter than you that your paper should be accepted you know while someone else who also is very smart submitted paper uh their paper did not get accepted right and that you have to sell your paper right they learn a lot of good writing you learn how to do that right you learn how to do the work so that your idea right you're you're uh let me let me make tight holes right how do you take that kind of idea and like because you know a lot of these just end up like oh you write something and i get a fork right and then it never ends up anywhere how you take it from to completion and then yeah you get a job in microsoft you add it to excel um a lot of haskell is actually funded by microsoft because they were paying seven piton johns and microsoft research cambridge because you know excel is like a functional programming language actually it's all about data flow it's all about functions um and yeah i think so i think that's the fun part right like you know you you don't call up a phd in computer science and have them work on your problem right uh it's not like i have an idea for an app let me get a phd it's more like uh you know where the people in the background right you know doing the work and then that ends up you know like like c right or like c is written by two phds right there's a lot of phds involved in russ there's a lot of phds involved in haskell a lot of phds involved you know at facebook making facebook fast making typed script you know now i'm saying programming language things because i'm a programming language researcher right uh you know all that machine learning stuff it's all phds but like you don't you don't see them right and because they're not kind of they're not i think that's also the point right like if you do a phd you're not really you're not so much in for the glory right you're more in it because you feel like you don't know enough about the world right and we need to we need to know we should know and we must know this is hillburt's quote yeah yeah but it's fun i i mean i recommend it if you enjoy it it's really fun if you don't enjoy it it can be very hard to do uh and yeah so it's also about it's also about stamina right it's like great chess players right uh you know great chess players they're you know they're smart they're good at thinking but they have excellent memories uh and the best ones are just really good at playing for really long times right like they'll just playing chess for eight hours right i think that's the same with research right you have to have uh not just stamina like per day but like you know you have to take a problem um and you have to not understand it for months right and you don't have an answer and uh you know it's an unanswered problem right like if if there was an answer uh you would not be writing or trying to write about it right so there's no one there you can you can't ask anyone you can't be like oh let me go to read it and get a hint right it's not it's not like that you have to you have to be okay with that like uh and i think that's a lot well a reason why a lot of people stop being they drop out of phds it's not like you know they can be very smart but that's not really what a phd is about it's about uh being comfortable with not knowing right and i think that can be very hard for some people right if you're always the smartest and you always knew everything and then you do a phd and you were sitting with professors you know they're like and you're like you know like me on like 31 no yeah and there's people there that like they were full professors at 27 right like and they these are extremely smart people right you'll be bashing your head in on a problem for a week and they take one look at it they have no context and they're like ah what about this and it's like oh yeah okay that's exactly you know and you get to interact with those people right and you get to you know and you get to be the dumbest person in the room right and i i and i love that right i want you know i think that's someone said that like if you're the smartest person in the room like you should find another room right because uh you're not gonna learn anything if you know everything already right and i think i like it i like being able to you know not know anything and then you know nobody else knows anything so it's it's fine you know i really should have written this uh oh thanks christian yeah i think this will be over soon and then i'm gonna go i really should have written this dfs and not as a kind of look at the path and then check i should have just been like search this part of the space and then give me the biggest number but i don't want to cancel it now find out yeah that's kind of exactly what i should be doing let me just check if this works uh so this one was third one was 39 but i want to see what this one does val start okay now this one takes a left gene a a a set a insert right and then you want to do max val a val a val m a s prime now i'm gonna have the n function here actually this one's supposed to be the val function right which is first let me see it's 39 plus 21 plus 7 let's see if it's correct uh multiply them together 39 times 21 times it didn't work well okay let me see what dfs max does hi sorry yeah you can program these and rides right they should not be too bad yeah it took half an hour to run it gave the wrong but some of the assumptions must be wrong uh yes sorry because i thought this would work right i did it just a slow way and but it did not work 21 7 39 5 7 3 3 this is how much i could open each and each of the first three blueprints just talk make sure you believe it i don't need energy it was 32 minutes right maybe that make only geode if you can it's wrong for one of my okay i'll take that away i'm thinking of uh seeing it good for the night let's be saying iceland i don't know what's wrong now i removed this the one part that's possibly unsafe and now i'm just going to i'm just gonna run it for for the night and see what happens tomorrow and then i guess i'll have to do a part two for this one we already spent yeah almost seven hours a day and we only test one but i have to say we're not the only ones okay but uh yeah it was nice to have someone here uh you know chat about research while waiting for this to finish because you know otherwise you just sit on your program not chatting with anyone uh hope to see you tomorrow again uh you know follow and then you'll see when i'm online uh and everyone did follow and then you know tune in next time and let's continue the conversation right and then maybe i'll maybe this will be done and i'll see what went wrong or something but yeah it's gonna run for to the night and then hopefully not crashed all right i'm getting super tired also i think that's where that's why my my energy is falling also yeah but also ask questions you know um that's why we're also doing this in haskell we're gonna see if it's good stuff or not yeah stay yeah the sleep is calling to me all right good night erin good night the rest of you and see you next time all right