 alright welcome to the stream we're doing it on a new computer this time because my desktop died so it's on a laptop but we're gonna be doing it via cloud server so it should work out but we'll see so yeah because the computer died I couldn't actually copy my setup over but let me know if the audio levels are bad or I need to do something that's why I have you here also the audio quality and it should be fine I used to use like a whole compressor setup before and but now it's just being compressed via a plug-in so I should work out see if I talk this way you can still hear but it's a bit teeny but yeah alright let's get to it we're gonna do an advent of code I think we do two days today thank you little Annie she is my biggest fan she's also my wife which is good and anyway we're gonna try and do two days today maybe three you know stream for two hours some years like the first two days take only 30 minutes so maybe we do three days or four days we don't know but we're gonna get started and I hope you learn some Haskell alright let's get started live the code day one see it's not green so I unclipped it but I did support you gotta support people that are doing things that you like alright day one so let's see what is happening Trebuchet something is wrong with a global snow production well and you've been selected to take a look the elves have been given even given you a map on it they've used stars to mark the top 50 locations that are likely to be having problems you've been doing this long enough to know that to restore snow operations you need to check all 50 stars by December 25th okay we collect stars by solving puzzles we get a puzzle second puzzle on me a lock this is all standard and we're the code stuff you're going to ask try to ask what they can choose a weather machine where they're sending us to the sky okay so a lot of blank hang on did you just say the sky there's a quick good funny text when you realize that the elves are already loading you into a trebuchet oh my god they discover okay so calibration puzzle okay has been amended oh no when we was just really just excited to show up their art skills they're having trouble reading the values on the document the newly improved calibration document consists of lines of text each line originally contained a specific calibration value now need to recover on each line the calibration value can be found by combining the first digit and the last digit to form a single two-digit number okay huh let's just go we're gonna make it simple I am just going to copy paste it this time so we're here on the server and let's say here module main where input is gonna be a list of strings input equals we are just going to do it this way let me see if it's simple you know need to go full parser day one okay and these are all strings now and we are supposed numbers and in school that is really easy we import data.char is digit right main so main equals map yeah actually we are gonna say filter uh-huh map filter is digit input and let's print cub so we're gonna do ghc percent oh day one and we're gonna run day one but it's an end so we're only gonna run if it compiles let's see what happens compiling okay we got all the digits now we are going to read add int dot we're gonna read add int first after we filter let's see for this we actually need I think a ghc 2023 what was this thing called 2021 of course hey mad flash so what do I do in my phd I study programming languages I'm actually been working on program synthesis program repair which involves fault localization so finding out so we have a code base you want to figure where the bug is you want to replace probably you know suspicious locations with new code that's code synthesis and then you want to test it again we do this in a loop so I have a paper called proper which is property based program repair it's very cool so my goal with my phd is it's so I'm the title is like type-directed program reprogram repair I think but the idea is you know in a language like asco we have so much information already there like the types we have sometimes we have tests we have a lot of constraints everything we have but we're not using all of it right so my phd is all yeah just reuse recycle just make full use of all the stuff that's there alright we have the numbers now oh no and then it's only the first and last digit see I ran it and says one two three four five what will you do after compiler dev I actually I'm not 100% sure but you know there are some high school shops out there I could do compiler dev and you know you can do a lot of just general like if you know if you know programming languages you can so the the way programming language works are basically you take a problem you design a language that describes the solution and then you write the program that in that language right to kind of make make it trivial to to do the stuff like here right we are actually saying map read filter right we kind of we have a language to talk about lists and then we just use that to make this all very easy but yeah compiler dev maybe you know work for epic games making that cool new language they have which I always forget the name of but it's very cool and then you know we can do OCaml it's really open so it's either that or I just do a postdoc and kind of continue working on program synthesis yeah let me see now we are going to before we read we are just gonna take the list take first and okay so I mean it's gonna work okay so we don't need to do it let's just say we're gonna apply this function here which is gonna say you know take the first of the list and do a x combined with last x's boom do do do do do do do all right and now I need to do it like this okay so now we just take the first element and then we take the last element and we create a list of those two and then we read that as an end oh no empty list let's go again to the definition yeah so two-digit number right so we want the first let me see okay so it might be the case there's a single digit number so we are just going to do f so we are gonna do and let's just write f out f is gonna be some function where f of x is equal to x so fx let's see so like a non-empty list it's gonna be non-empty list is equal to x comma last x is f of anything else is just that interested in graphics programming graphics program is cool oh yeah I have to do let I do like graphics I did I used I did one graphics class it's just my problem with graphics is that it's quite hard to test and then because you need like a good GP I it's just a lot of work I'm super fast and just make it work let's see now we're getting 72 which is indeed ah so if it's m1 it's supposed to be x comma x 142 J x message I do not know what you mean by J please explain okay I always have an error that just no J is not the f so I'll trick I learned recently is if you're making an error message it's good to have the name of the function that it's in the message makes it a lot easier to find let me see it's called epic games programming language verse it's called verse it's quite cool it's it's not so it's kind of like Haskell functional it's not lazy though so I don't know but it's got built-in constraint solving so you can kind of say exists variable where and you just define a bunch of constraints and it will kind of branch out in multiple paths depending on the values that satisfy those constraints and it's kind of Tim Sweeney's brainchild and it's it's super cool so it's like functional programming and prologue wrapped into one I don't know quite how it works and also like constraint-based programming is not my forte so I don't know I don't know why it's good but prologue was quite it was quite popular in its day so I just I haven't wrapped my head around it okay so we did the we did the first one now let's get our input what is the sum of all the calibration values boom actually this is a lot of like so let's the file here input set paste important in Vim Wow okay and then so here we are going to let part one equal in equal this okay I think it's just like this actually so and let's do print part one example you see if it still works yes and now we do read file and to print dot part one dotted lines read file input so now read the file and we're gonna take the file and take all the lines in the file and then we're gonna run part one on all the lines and then print it play you know we gotta be on you're gonna run time on this it's gonna write the memory and stuff 55816 in I think this is one millisecond let me see hey something I did wrong there let's just say time huh 11 milliseconds not bad if I do say so myself a but let's see if we're actually correct here 5586 816 boom part one easy 20 minutes with all explanations of my PhD and stuff maybe we can do three days today mostly in this example okay part two it looks like some of the digits are actually spelled out with letters oh my god this is crazy stuff okay 16 even wow let's see okay so two nine eight two three one three two four nine eight seven one wait so this is one eight and then four yeah okay so it's just six right it's not like because he's not taking like 16 and then turning that into one six and then taking the last of that you know let's just see what happens if we if we do it with let me see sample two so here it's like you know now we should be getting a parser or something but I don't feel like it we got a look up the luck I think I think we're gonna get away with it okay let's write the replacement function wrap all string to string we were planning to use Haskell but this part changed your mind but why I think we can do like a pattern match here so we're gonna do stir and we're gonna say a case so we're gonna say a one take length one of string it's gonna be equal to let me see a do-do-do-do-do I think it's not span using JavaScript well that is crazy now it's split yeah so then we can actually no okay so I want to end to so I want to you know a list of ways to int actually I think it's into list of ways to a comma a split at yes split at this is gonna be equal to one and then repel rest so x axis okay and now we are going to copy paste this ten times it's what you got to I mean there are probably better ways to do the feels like they would take time one two three six seven yeah I guess it would it drive it crazy but it's also a good exercise you know what's this how is this easier in JavaScript is my question right two three four five six seven eight nine otherwise we are just going to X repel axis you know there's probably we could say something about skip many or something like feels a bit much bunch of for loop yeah that makes sense so let's see here print map repel example two let's see what happens non-exhaustive patterns because repel we didn't catch the we didn't have the base case eight will three okay seems to work map what if you do now part one on the example 281 keep switching to the wrong tap which is exactly the right answer here the input is the same let's just see what it does be slow no 55 milliseconds not bad at all but let's see if we still got it maybe we messed up some base case it's too low damage one two three four five six seven eight nine so it was correct for the example but not for the real input messed up I want to line all these so it worked it replaced everything but then it didn't do the two one nine ah it's saying eight whoa three do you think that is supposed to be like eight and two and three or just eight two three see one three two one four so we can we can do it you know but we change it like this then it's gonna two one nine eight two three three I think it might work let's just copy it and see that was the right answer cool we just had this tiny where it could be part of two numbers at the same time boom 30 minutes how do I debug Haskell there is a module called debug dot trace I do oh id and then it's gonna print out all the lines right and then you know if I so I do a lot of just debugging by just looking at the input and how it's behaving but there's more stuff I want to make it faster there's a tool called profiture so you're basically generate a profile with like with stuff so you generate a program you can get a heat mapping you can figure out what is slowing it down there are more advanced debuggers but I usually don't have to resort to them but so yeah so this is that's a trick here like here the map the rebel is a pure function right but this trace function is basically doing unsafe perform IO print on the value so you're printing in a pure function right which is great night so you can see every value that's going on day one 30 minutes let's keep this marathon going because we have some catching up to do day two module main where let me just prefix it right away return to the advent calendar let's go to two all right but did that answer your question madness like the trace show ID it works quite well actually let me see you're launched high into the atmosphere the apex of your trajectory just barely reaches the surface of a large island floating in the sky it's quite cold but you don't see much no okay oh it's no island it's no snow there though and so you have to walk oh now we're playing a game okay as you walk the elf shows you a small bag of cubes which are the right green or blue we will hide a secret number cuz he's gone in the bag and don't figure out the number of information also okay we all will reach in the bag grab a handful of orange you shown to you and put him back he'll do this a few times per game you play of several games and record the information from each game it's gaming this is with ID number followed by a semicolon separate so the cubes have already gone from a bag three great free blue for red one red two green six blue two green okay let's see two two three four five so he shows us I guess he grabs a handful and then in first hand there was three and four and then he puts them back into the bag and then we we see them again three sets of cubes reveal from the bag three blue and four cubes second one yeah exactly two green a six blue the third set is only two green cubes the elf would like to know which games would have been possible which wow oh okay would have been possible because a one two and five would have been possible game three would have been impossible 20 rage I'll show you 15 blue okay and it seems okay I like this playlist by the way this is a stream beats low-fi Christmas music and it is the RM free so I'm allowed to stream it which is important you are not allowed to break the law while streaming but like when I actually not usually listening to low-fi I'm usually listening to like pop songs that I've heard a million times before and then I'm just vibing you know but sadly if I did that on this oh you can't hear the music oh that's sad I think it's because I'm misconfigured something the music is supposed to be on the correct one ah we'll figure it out for the next stream because I don't want to put it on the main one because it might get there there's no music and put it a bit higher we'll see cuz it showed up in the recording anyway I gotta figure out the twitch of VOD we'll figure out before next time it is good that a very low-fi Christmas by Harris Heller on stream beats by Harris Heller Spotify it's quite good let's see let's parse this parse so data game equals game so the GID is gonna be an int and then a hands and list of hands and we're gonna derive show for this and then a data hand oh so I it's a list of hand all list of hands a sequel hand alright thank you for hanging around Mad Flash I love it when people actually interact also that is why I am doing this stream teaching and just having company while programming okay let's say they're writing show so parse and this is gonna take a string to a game parse okay first we are going to say string and we're gonna do a game space is split at length game space okay and we're gonna split at a game link game space of string then we are going to say ID string rest is gonna be take so it's gonna be span again we need import data.char is digit so we're gonna take while is digit we're gonna span so we take until it's not a digit and is digit let's name this rest now this is gonna work I believe in the cards it might not work though okay we're gonna believe I think it's gonna work the scoping here but I'm not entirely sure so we're gonna span is digit rest no this is gonna look sorry rest one rest two no let's believe we believe okay and then we are going to say rest is a drop two of is equal to now let's just say here game comma string because I just want to see what's going on here game read ID string GT is equal to read at int ID string hence equals empty we're just not gonna do that comma rest okay now main is gonna be main equals print parse map parse example now let's do this again but this time is day two one two three huh so the scoping did work out very nice okay so now we're gonna do actually has close kind of annoying it doesn't have the split at function so we we can't just the split at the semicolons directly we actually have to write that function split on char a string this strings split on CSTR is equal to and so we're just gonna say here is gonna be span not equal to see so it's a not equal to this character we are going to take a string and then we are going to say are split on CRS okay if if it matches and there is something at the end then we do like a split on C empty is equal to empty split on CSTR is true let's see this a turn this into strings and I am going to split on okay let's see okay it does seem to work except it it has spaces in it also but that's okay okay now so a hands hand stirs is equal to split on semicolon rest and this is gonna be hands equal parse and stirs the parse okay and now we are gonna not do this okay then parse hand stir take a string into a hand parse hand stir is equal to okay first we do we clean it up right so X axis is drop a while is space stir okay import char is space I think it's just called his space let's see space yes okay so first we clean up okay else is gonna be split on and then comma and we are actually gonna say map drop while is space okay so we're not just gonna do this directly actually space after we split on the axis let me add define addition for two hands at hands and a b1r1g1 and b2r2g2 is equal to hand b1 plus two r1 plus or two g1 plus g2 so now I'm gonna say parse parse simple hand string okay so now we're gonna say a xs is gonna be take while span is digit string so hg so num axis now this is gonna be equal to case axis of space green at the hand green is equal to read add int radical 0 blue equals 0 red red blue green okay then we do so we're gonna drop while is space and then parse simple hand okay so now we have a list of elements of hands so now we're just gonna say fold l prime at hand and let's see the empty hand is hand 0 0 0 is gonna be equal to fold at hand hands 0 0 0 on else okay I think we got it let's run it 38 I just forgot to do this we should add hands and fold l prime it's not defined okay where the learning scope axis stir so this is actually map parse and nice so three grid we managed to parse all the hands hey you don't need to go to a full parser for for this so the Jamie defines all blue 163 212 yeah okay so these are correct okay now let's justify possible game to say hand to game to bull okay possible hand let's actually say here green equals G red equals red blue equals low and then we have the game game we don't care about the idea you care about the hands equal hands is equal to all possible hand hands where possible hand of a hand green so it's it's blue red green right I should really have it I was thinking okay a red green blue let's just write here and RGB possible hand our RC GCBC is equal to RC lesson equal to our and let's just say all we can actually just say and and then we want GC to be less than equal to G BC to be less than equal to be okay so we map filter possible and then we do GID so which of these games are possible alright filter most example hand 12 13 14 let's see 125 that part one equals some and now we're gonna say do we're gonna say print part one example 8 okay 12 13 14 okay puzzle input input page state cancel let's see we forgot to do set paste maybe we don't manage to parse some of these but that's okay okay now let's do read file input into part one dot lines print 2683 no parsing errors either not bad alright day two part one done took a bit longer parsing took longer but you know we're so we're on track we're on track okay what is in okay as you continue walk that post in each game you played what is the fewest number of cubes of each color that could have been in the bag to make the game possible mm-hmm let me just take the maximum right let me just see a fine add hands now we're gonna do max and hand R1 G1 B1 and R2 we G2 P2 it just has to be the same order as you go to hand max I think it's just max maximum is for the list right yeah max R1 R2 max G1 G2 max B1 B2 so now we are gonna say so let's see a map parse part two okay we're gonna do print map folder max hand and here's your zero over the games let's just see what it says here this is gonna be example three two four red two green six blue four red two green six one three four one three four twenty thirteen six twenty thirteen six fourteen three fifteen fourteen three fifteen six three three six three two yeah okay so it's correct for all those okay the power of a set of cubes is equal to the numbers of red green and blue cubes multiply together the power of the minimum set of cubes in game one is 48 and RGB R times G times B this is running right right 48 12 15 16 okay and then some two two eight six let's see let's go to a dot here and dot here let's see fire each game find the minimum set of cubes must have been present what is the sum of the power of these sets it's gonna be a big number right let's see 497 10 boom day two done in one hour let's see so we're catching up we've done day one we've done day two let's do day three and then we call it a day right I think we should be able to do day three today also but I don't want to sleep too late but yeah it's good we're catching up you and the elf eventually reach a gondola lift station he says they're gonna lift a good water source doesn't like okay I think they're probably not moving it's not easy alpha the wrench it's not working the lift okay we're gonna help fix the lift cool the engine part seems to be missing from the engine but nobody can figure out which one let me actually see now we have a short break and I'm just gonna try and figure out the the VOD I messed it up so the VOD for this one is not gonna be possible so what it's supposed to do okay I say so we're gonna do like this and like this now you should hear the music but yeah so what I was doing is I was sending just the music to twitch video on demand but now then that was exactly the opposite I think so you want to send you want to send everything except the music to video on demand okay okay so I was just sending the wrong thing to the OD so sorry about that if you're watching this on the VOD you did not have any audio until now and I'm surprised you're still watching but you should have a it should work now let me lower the music again because now it's working right so it's not it shouldn't be too high okay music is working yeah so but I'll upload this to the YouTube so we just finished day one it worked out great but yeah sorry about the audio mess on the VOD stream has been okay except there was no music now there is music yeah everything should be correct all right let's go to day four okay if you can add up all the part numbers in the engine schematic the engine schematic your puzzle input consists of visual representation the engine lots of numbers and symbols but apparently any number adjacent to a symbol even diagonally is a part number should be included in your sum okay two numbers are not part numbers because they are not adjacent to symbol 114 and 58 every other number is adjacent to a symbol and so is a part number their sum is 4361 okay that is this is gonna be a mess but let's see let's see how it works out for us ah what we're doing good we're doing quite good a make your day three three dot h s uh no dot h s language dc 2021 module mainware example equals and then we just oh you know uh paste it in is a list of strings this should be we have got to we got to read the numbers first so and then we got to figure out the symbols and we're gonna get the ranges and something like that okay let's see let's just get the symbol locations first so um a symbol looks it's just gonna be a list of strings to a list of uh inch symbol logs nothing is equal to nothing symbol logs x x is equal to s l of x symbol logs x is okay where s l of x is equal to i think in data dot list is like a index function somewhere the tink tink tink tink tink lm indexes uh find indices nice equals uh find indices as import data dot list find indices a f x so f of x is equal to uh case x of let's say uh is digit x equals false if it's a dot it's gonna be false let's see data char has a i think it's a function called just like alpha numeric is alpha now i think it's okay uh is alpha numeric so we're gonna do these okay now let's just uh find all the indexes do uh print symbol logs simple day three okay there's an error on the input here because i didn't put the start list thing okay let's see uh is digit is alphanum is alphanum right i need it like this oh this is not fine this is x is it's fine this is s so three six three five three and five okay now we are going to now let's find uh so symbol logs and so instead of doing this we're gonna return a list of pairs so we're not gonna do this we're gonna say symbol logs string to uh list of pairs of ints so string and this is gonna be zip width we're gonna do here zero and then stars and then it's gonna be a zip with s l and it's gonna be i here map i comma okay okay we're doing something wrong here um so zip width is gonna get the index and uh okay let's see again the error message uh couldn't match type this is supposed to take an int and a string and it's gonna return me a list of uh i need to concat so one three three six four three five five three eight five okay um um that's the location of the symbols now let's have the line empty equals empty let's just see here okay there's gonna be string so let's just go again now x is drop while x error is span uh not is digit string so we drop until we reach the digit and then we um y's is gonna be span these digit x's okay so we're gonna have parse line parse line prime zero string where okay now we span is digit uh parse line prime so we're just gonna keep the running index here okay and uh so and this is gonna return so the string itself uh is equal to okay so we're gonna have the read add int of y we're gonna have the start of the string which is length x plus i length x plus i think let's just do like this i plus length x and then the end of the string is i start index is length of x this is gonna be a end index is si plus length of y it's gonna be i plus si i plus si plus e i um it's actually just gonna i plus length x as the si and e y concatenated with parse line prime e i string no y's okay and uh let's just oh i need one more here parse line prime empty list equals empty list each dollar map parse line example preload dot read no parse okay now we're gonna debug twitter so four six seven one one four uh and then it's just uh okay um um this is gonna be fine so if there is no empty string parse line prime do we even i don't think so let me see okay let's do it this one starts at zero and ends at three i think we're doing okay here let's remove this trace show id so four six seven starts at zero and ends at three actually let's say print the example also map and print example okay so it starts at zero and then see zero uh key bind also now i gotta test the alerts um i hope they work for the rest of you so it starts at zero so and then this is zero one two and then three i think it should be okay zero one two three four and this one starts at five six seven and then it ends at eight um i think it should not be like that i think it should be and it takes minus one i mean it's correct for the so it's correct like this so it starts at zero zero one two three four five six seven eight nine okay zero one two three yeah exactly okay and then 35 so zero one two and three okay um i think we should have like a running window huh go the qualities keep bind some icelandic on stream that's good i'm icelandic i'm also wearing the icelandic colors representing um so what i'm seeing now is that it's probably super bad to actually so like so two symbols can only touch one above and one below right so i should have like kind of a sliding window of three uh otherwise we get like quadratic quadratic quadratic like yes happening okay so let's just create the window function window string two that's gonna be take a list of strings to a list of list of strings and then we just do everything within the window window of a x y z axis is equal to uh it's gonna be x x y z concatenated to window y z axis and if we don't have three things that's gonna be window anything else is just empty list let's say uh print windows window example then my first yeah exactly and now we're gonna operate on each window we're not gonna kind we are just gonna and we're not gonna do the we're just gonna have a there's a list of hints okay and then we just remove this we remove this remove this and then it's not going to be zipped with it's just gonna be a little string sr our strings and let's see what we get now yeah exactly so now we have the we just have the things so it's probably gonna generalize somehow and i'm gonna have to work through that again but i just want to see what's gonna happen now okay so um let's see operate so solve window okay so it's gonna be l1 l2 l3 a l1 l so let's see the window when when we w is equal to uh so where as a symbols s1 s2 s3 is equal to symbol looks window and then uh line the lines are gonna be l1 l2 l3 is equal to map parse line let's just write it like this actually and then then we have to write map here also map map parse line w let's just write here i'm just gonna see a print let's just look at the first window comment these out so first one says that there's a one symbol in line two now let's see here uh we have to say uh touches so we're gonna have the symbol which is gonna be just an index s e and then we're gonna have the number we don't care about the number itself but we're gonna have the number start and number end it's equal to so s e is so ns less than equal to s i and so it's supposed to be within the range right and s1 less than equal to any okay so for the so we're gonna solve window part one this is not gonna generalize but let's just see what happens i just want to know more about second first okay so here um this is so first of all so we're gonna be filtering out the symbols okay so okay first we have all the touches so line one can only so line one can touch line one s1 and s2 line two can touch all three line three can touch s2 and s3 okay so um let's say so uh for s1 we're gonna say map touches a check one let's say check check one it's gonna be map we're gonna say map touches a1 map touches a1 so we're gonna concatenate that with map touches l2 so there's gonna be a list of functions okay um okay so and then check one where f's equal okay so then we have to check and it's gonna be a list of functions so we're gonna say filter and we're gonna take a function so any s we're just gonna apply the functions there's an i we could probably use dollar here also any dollar fs s1 s2 c2 equals filter uh let me see c2 and then this is gonna be s3 a l1 l2 exactly yeah okay so we can just map touches l1 l2 l3 map touches l1 l2 and then c3 it's the same but it's just uh let's say so c takes in symbol list and wait so it takes in a number list and symbol list and it's gonna say filter any dollar fs concat sl let's just say symbol list where fs equals map touches no this is gonna be number list and this is gonna be symbol list okay and then c1 is equal to c of l1 l2 c and s1 s2 c of l1 l2 oh hey oscar i am hard coding challenge for day three now actually so we caught up it's not gonna generalize probably but i i don't know what part two of day two is gonna be so um so this one takes a int int int oh sorry so this is actually actually it's not like this so it's just s1 here and then this is s2 and this is s3 we don't want to check all of them yeah it's kind of it's been a bit hard actually but uh we've been doing fine we've been doing quite fine so far we should have it because now we're gonna get duplicates of the numbers it would be a lot better and could kind of reverse this to say you know l1 is going to be touched by the symbols in s1 and s2 l2 is going to be touched by the symbols in s1 s2 and s3 and l3 is going to be touched by s2 and s3 let's see okay so now we have a the number list i think this will work it's going to be c2 c3 but we're still going to get duplicates of the numbers because it's uh because it's per window like this window i didn't work guys i messed this up f fs um let's see yeah it's gonna it's been a bit hard today uh let's see okay maybe i'm messing it up by doing the window um because i don't need a window for the so i should really just do each line and then um just check the ones that it touches let me the long time on this but uh i don't think it's working let's just uh let's look at it all again the what do we what do we have here let's actually do a map map and print what did it say oh right okay so this first is the symbols and we have the then we have the lines okay a hey why do you use haskell it's functional i like to think about things in a functional way it's got a good type system so i can write down a partial specification of what i'm thinking of and it's lazy which means that you need to be pure it can kind of work easily with infinite data structures that's why i use haskell okay so uh let's see we can still use the windows why does anyone do anything yeah i like to think about things functionally i also like to have things i don't want to map it directly to the machine i want to be declarative i just want to say what i want and then uh not for me right but it's an internal debate rust is good for where you really need to map it directly to the machine but the type system is not as expressive in rust so we got that going for us okay let me just see uh so i'm just first we're gonna function let me take in a solve line take in a string and it takes in a list of like simple locations and returns a list of numbers in that line okay solve line is equal to rust where um nums is equal to parse line uh let's go line sims numbers is parse line ln and then we have this touches function okay and now we're so filter any f so we have a number any f and fs nums n add i comma number and then we're gonna map okay a fs is equal to map touches sims touches as i this thing we're not going to use it anymore okay so let's see and we're gonna do uh fs l1 it's gonna be a concat map concat dollar map symbol logs dollar take three example and then l1 is equal to be take one example and then we're gonna print solve line l1 fs l1 and let's just take ahead here and see example oh some ssh glitch is happening yeah so it doesn't touch any symbol on that line okay so now we are just have to um chop it up into pairs so let's go let's have um solve and so now we're gonna walk through oh okay so let's see um um sorry i'm also getting a bit tired but uh it's okay we're gonna do this part one maybe we'll finish part two tomorrow unless we just get it uh quite fast okay so let's see this will be very nice if we had just indices but we want to kind of stream it uh so window okay so we have x y said rest okay then we are gonna do um okay so we're gonna say actually solve first uh let's just x comma y is equal to solve line and then it's just x1 and um map symbol logs a x comma y okay this is our first function so window x y said rest is equal to um so we assume we solve that so that's it's gonna be solve line y and then we look at the functions in symbol so solve line y um it's just it's just this empty list okay it's not even that so this is gonna be a solve line and then map symbol logs uh x y said is it gonna be concat map concat map and this concatenated with solve window y uh y said rest okay and then we're gonna do solve windows this is gonna be the last one uh x comma y solve line y concat map symbol logs x comma y okay um and yeah let's actually make this we're solving and we're gonna do uh is equal to solve x y said x y rest is equal to solve first x y concatenated with a solve window home okay uh okay where let's see uh print solve for example 51 I think I just need a more parenthesis here it's going to get my so symbol logs takes a solve takes a list of strings and returns a list of lists of ints uh just returns a list of ints okay um symbol logs parsed line and takes a list of takes a string actually and returns a list of int comma int comma int couldn't match expression uh solve window okay line 55 solve window x y said rest list of list of strings a list of ints um okay couldn't match the type char with why is y a char here I had too many parentheses okay couldn't so solve line solve window 52 what is it doing there solve line yeah okay this just has to be x 35 63 664598 63 664598 uh okay it's because um so the so the one in the current line it has to it has to do a bit differently okay um okay so then we have to say we just have to we have to specify like which one is the current line okay um we just do x a symbol we just do it we're parsing it a lot more times but it's okay symbol logs x and map symbol logs and x comma y just y okay so then we so solve line so these are the ones so same ellen sims and other ellen sims okay um so it worked for uh so touches same line so this is basically if si is equal to ns minus one or si is equal to ne plus one okay so then I just want to concatenate and I want to say filter and okay and then we just say touch the same line and you have like this map touches other ellen sims okay so solve window so this is your solve line and this is just and then this is why did I concat map there oh I think I need to do that okay let's see so now it catches six one seven let's say uh third numbers are not part numbers because they are not adjacent to a symbol one one four top right okay so so this one is actually because it's adjacent like this like to do okay so we just have to yeah we didn't need to do this at all we just uh we just have this here okay uh because you can touch yeah it doesn't matter if it's just uh okay uh whatever okay four six seven one one four is not there 35 63 six one seven 58 is not there five nine two is there 255 is there 64 okay and then um this is actually some okay four three six one yes okay now we get the puzzle input e that's a lot of symbols let's see what happens um print read file print dot so let's see all right all right boom day three part one done that took a long time let's see if we can finish part two okay uh okay my gear is any star symbol that is adjacent to exactly two part numbers oh my god okay uh let's see then it's not enough to then it's not enough to just do it like this hey you can see during the broadcast my hair gets more frazzled anyway there are two gears we're gonna get there we are going to get there I think we'll give it another I'll finish this part I think I think I know how to do it so now instead of just um so now we are gonna so the touches here is correct um we're just gonna we're gonna add to all the we're gonna like identify the symbols thanks for the follow w w v w v man that is a lot I'm not gonna say all that well I guess it's pronounced you should let the Microsoft Sam test it out okay so now um we are going to just in I'm going to uh let's see I am going to uh let's see this was part one we're doing part two we are going to add an identifier to each line so uh x y rest is equal to sip okay and now we are going to we're gonna write solve line two and uh okay it's actually correct this way so concat map symbol looks x y accept and let's see I was editing the this one which I should not have been doing um solve two let's see I don't use the solve line anywhere else so I'm just gonna move it into the definition here let's see if this still compiles what I'm gonna do is I'm just gonna add a I just need just a little bit more space I need a bit more uh let me see okay so now what we're gonna do is we're gonna add an identifier and then we're gonna like we're gonna take fiddle with it I take personal offense yeah I just like concat map because we're actually using lists we're concatting and mapping uh we could so concat map is actually the bind operator on lists uh see and then if we look at concat map at uh then you see how it's just the same function but flipped but uh yeah I like it because it's actually telling us what it's doing anyway it's fine okay I also I don't want to make it too complicated hey Fabian nice to meet you that's all one now we're doing solve do and we're just gonna take on the whole here and we are going to say that x y that x that x y or s is equal to sip with home so we're just gonna add an identifier to every line and then let's see so now so symbol looks we're gonna modify it a bit so s looks prime is equal to so this is gonna take an identifier and a line and we are gonna map to symbol looks of axis okay so now we use symbol looks prime everywhere let's see if it compiles and defined okay let's see solve window looks prime takes in int string and returns int right expected int string to int actual right and that's just because I have the wrong type here int comma int now that identifier like the line number doesn't matter here and this is also gonna be an int par's line second okay so what are we gonna try to do we are gonna try and so for so instead of multiplying the numbers in the end we're just gonna uh we're just gonna return the uh we're gonna try and return so we need to figure out which ones are stars first of all uh second gear is in the lower right its gear ratio is 451490 the star so now we don't care about all the symbols we just care about uh the the ones that are stars okay so let's see symbol looks xx is let's see so symbol looks let's just write here find indices equals star so those are the gear looks okay so we're actually gonna call this like this and so now we've found all the stars and we have the identifier for them and because we don't want to mix up the identifiers okay so now we are the so how to solve each line we are going to uh there's a list of it's okay so so here we're just going to return and number and which symbols you touched okay so uh we have the numbers which are these um you know with the start and the end location okay so and then for each number let's actually i'm gonna use the 4m here uh so let's see we don't care about this so for the numbers we're gonna do a so for each number we are going to take all the symbols we're gonna say filter flip touches since flip touches and sims okay so now then we have a list of symbols which uh touch and then so we're gonna say case of so if this was empty and we just return empty we're not gonna do anything with that number otherwise we are going to say uh map and let's say here i we're gonna uh this is value actually so the value of the number otherwise uh otherwise we could also just say null here but okay otherwise um we're just gonna return v comma uh touching sims v sims okay let me see if this is type checks and i'll actually just say yes okay because we need we need there a salt also uh okay no we are just gonna say v we're just gonna filter it out later okay let's see here uh so solve line okay and then filter not null a second okay and let's see we're not gonna do some but we're gonna say concat i just want to see what this says here if it even type checks why did i copy this here i was gonna change it but i changed it okay hmm it doesn't like me saying this why illegal type uh yeah okay because it's a list of pairs of ins not did i dot traversable four is by the way just uh it's just traverse uh okay let's see four is supposed to take uh takes a list of nums and then a that to some um to a list and then uh let's see here um f equals v comma f takes in as one of those number things uh because it doesn't return a function right so i wanted to just return okay then we just do map right map f nums and this is because uh type of notation here is wrong that's why i rest okay so it's returning the right it's returning for each number which here is touching it okay so um concat and then filter right so here i want to say filter not okay uh so now i just need to basically flip this data structure so these are where the so 755 and 598 why are they not uh yeah okay there are two gears okay good so now i have to flip this data structure let's see let me see okay we're just making a map or data dot map dot strict qualified map import data dot map dot strict okay and then we're gonna we're gonna create the map with all of them so we're gonna say we're gonna fold l map map dot empty okay and now this is gonna be a map of uh these gear identifiers to a list of numbers yeah sorry uh so we're uh we're helping them figure out some gears okay so we were trying to do so first we had to find all the numbers that were adjacent to a symbol and then multiply them together but now we're only looking at numbers that are adjacent to stars and only there's only gonna be two of them exactly two right so now we're gonna you know we we've so we found all the numbers and we found which star they're connected to so now we're gonna flip it and say we're gonna say for each star we're gonna see what numbers they're connected to okay and then add to map so this fold l to map i never remember the type of fold l ggi no fold l i should actually have fold r here probably fold r uh so it's gonna be this is gonna be um int and this is gonna be the map int comma int list of ints and we're gonna return a map of int comma int to list of ints add to map okay so uh this is gonna be v uh keys okay so first of all we're just gonna say um where nm is equal to add up from list sip keys repeat v okay so now we have the and then we're just gonna uh old map now we have to say map a b map a b map a b uh i think it's just called union with exactly so so this is gonna be a union with com a new map old map old map new map where comb uh yeah union so comb uh x is yeah so we're just gonna concatenate the two lists let's just see so this can actually just be uh union with of uh uh no let's let's just keep it like this okay uh let's see what this gives us now this is very annoying a install lib containers so i'm running this on a new uh machine and if you do gt up like containers are not like there by default not exposed globally uh so i have to install them like this let's see doot doot doot doot doot doot i kind of thought i thought this was in containers apparently not i specifically tried this with int map so like uh okay apparently i did not maybe i was using some other i turned off these settings do do do do i think i was using another gc version which is why it worked then but not now but anyway uh so it should and we just need to find the keys where there are exactly two it's not just cabal hell like why is it taking so long to build containers i don't understand okay uh oh this is also not correct so now we have the uh comp map so we have the combined map and now let's filter the map we say map dot filter comp map uh and we say uh m is actually value uh length v equals two and then okay now we have containers actually uh it's just about union with yeah that is true oscar okay see now we have the two gears and the two parts that it touches and we filtered out the ones that had length exactly two then we just have to uh okay so now we just have to get the map dot keys here right now we get the map dot values is the old input a i think it's just the i think it's let's go to google again map k a to list of a lm's okay map dot lm's there's gonna be a list list of ints so we're gonna map product so we're gonna take the sum of the map of product of these okay what is it what's it give now this should be a list of list of ints okay and then if i do okay i just wrote something wrong right 467 835 which is exactly here now truth 33 milliseconds not bad is it correct though yes we finished day one day two day three took us two hours and a half or 45 minutes which is slightly longer than i had said i had said do i would do it in well i was gonna two days in two hours and we did do that uh in an hour and a half but now we finished day three and uh yeah so the chatter online is that it's very hard these first ones like it's it's harder than regular so i'm not sure we're gonna do four and five and six all tomorrow but you know hopefully two days we're always you know we did three today so we are catching up day five is a toughy okay so we do day four maybe half of day five but we're gonna catch up eventually we have the weekend also we can do a little bit longer than anyway three days of end of the code i'll upload this to youtube yeah and that one will be correct but the video on demand of this one will be missing sound for day one but only music so anyway thanks for tuning in see you tomorrow um huh today was very easy okay cool so maybe you know we finish yeah so we have maybe we do four five four and five and then we can do six and seven and eight all at once somehow let's see but tune in tomorrow again eight o'clock and let's see how it goes but i think we had a lot of fun we were i mean we didn't like go too much over the solutions but i think this one was nice because i tried to hard-code it really hard-code it in beginning but then we could we we waited work but it's all right all right thanks again for tuning in click that follow button if you want to get notified but i'll also tweet it out or i'm gonna have fun all right thanks for the day see you tomorrow hopefully