 See? That was the intro Now I don't need to cut the YouTube video Because I just started recording once I played the intro. It all works out Also, it didn't work out. OBS is having some issues with muxing right now, so Actually didn't work out. Wait, let me... I had some coffee. I'm gonna get some more coffee. Hold on This is the Icelandic way of drinking coffee You just Drink it until you drop Actually, I heard that the white people Are more likely to be addicted to coffee Than other people It's a very high correlation. So I'm an addict, but you know, it's okay As long as it's not weighing me down in life, you know About to spend all my cash It's a sweet sweet coffee black gold as it's called We're gonna do a day 11 Let's have a sip pretty cold coffee. Anyway, uh Day 11, let's go. Ooh Wow, we're gonna be parsing So okay now we're in the plane again So we were on the plane And then for for some reason we were like taking a ferry Apparently something happened in day 12 Let's see So you're playing lands with plenty of time to spare a fun leg of your journey. It's a oh, okay So we just like okay that goes right through the tropical island where you can finally start your vacation Reservating out of the board a ferry you realize they're so early. Nobody else has even arrived yet By modeling the process people used to use to choose or abandon their seat in the waiting area Pretty sure you can predict the best place to sit you make a quick map of the seat layout Seat layout fits easy up on a grid each position is either floor and it's a seat or an occupied seat For example the initial layout might look like this Now you just need to model the people who will be arriving shortly Fortunately all people are either and are entirely predictable and always follow a simple set of rules All decisions are based on a number of occupied seat adjacent to a given seat One of the eight positions immediately up down left right or diagonal on the seat Holders are lied to every seat simultaneously if a seat is empty And there are no occupied seats nice decent to it That seat becomes occupied if a seat is occupied and four or more seat adjacent to it are also occupied The seat becomes empty You guys recognize these rules I think it's the game of life. I think it's literally the game of life update rules Any live cell with fewer than two neighbors dies unless it was two or three neighbors lives on Okay, so it's not quite but it's a cellular automaton. We're gonna be doing cellular cellular automatons Which is good. They're good. The good stuff Okay floor and our changes sees the moon always is on the floor After one round of these rules every seating example layout becomes occupied Second round seat with four or more occupied adjacent to become empty again This process continues for three more rounds At this point something interesting happening the chaos stabilizes and further applications of these rules Causes no seats to change state Once people stop moving around you count 37 occupied seats Simulate your seating area by applying these seating rules repeatedly until no seats change state How many seats end up occupied? All right, let's go I love that smiley it it it's me Uh, maybe I should put like a notification on twitter that I'm up again Because nobody showed up. I told people Show up. They're not here. Let me see Hey, let me see here All right After a short break We're back up with Day 11 of hashtag advent Of code in hashtag casco. It's all about the hashtags Yeah, oscar. You're here. I think it's you to me When we're probably just you okay, we're doing it for you oscar Let's just Let's get it. Let's get it done Let's get this done So What am I trying to do this thing right? Yeah, okay day 10 To me, you know my grandma she used to drink coffee right before bed and uh Excuse me if I channel some grandma today get At day let's add these first day. We always else we will Lest we forget so we're actually do star.hs and then get star star input star Wow optimal get commit and He's doing dishes That is a classic very classic uh day 14, you know As long as I have to me and oscar You know now we have like half of the half of the viewers are active chatters, you know, it's about quality All right, let's see day 11 Uh, yeah, let's create new file day 11.hs Let's create another file test Input so to me I assume I think I restarted the stream So it changes colors. It's like picks random colors for you. Oh, hey billy billy Cake coffee. Yeah What about the coffee, right? Sorry test input So, Tim, I assume you just simulated it, right? Toot toot toot toot toot toot toot and that's not too bad, right? Or did you have to wait five days It's still running. Is it? I think it's still running. No, I think probably took dozens of milliseconds That's not too bad module main that may wear. Okay, now we're going to treat this as an array. Import data.array. Thought on a box. We are going to be doing 2200 milliseconds. Shoot. That's two seconds. Ta-da. Okay, we actually need data.array.unboxed. Let's see. U array. So we are going to say here. So let's first get the input. Get data. No, get input. File path to U array, IO U array. We're going to have integers. And we're going to have integers, booleans. We can't do booleans, right? We need three values. Let's have chairs. Let's just do it crazy style. Input fp equals, okay. So we are going to say, you know, where, so we're going to, so we're going to take the line. So we're going to fmap lines over read file. Now, from lines, it's going to be a 2D array, right? And we need a vector, I think. I think vectors have, I don't think we have vectors. U array. I don't think we can do two dimensional indexing. Okay. We'll just have to update the point of error, right? So, I mean, the trick is, I guess, figure out when it will stop. Let's see. You count 37 occupied seats. Okay, let's look at it for a bit and see if we can like detect when it's going to stop. I mean, but it's like a chaotic system. I think it's got to be super hard. So four or more seats adjacent to it. An adjacent given seat up, down, left, right, or diagonal. Whoosh. I'm thinking how we can do this. We just have a set, right? Set of pairs. I think I'm going to try and use a set. This is using a set, not a set of pairs. So, let's write that. Um, pairs neighbors howdy neighborino int2 Let's wait for this. int2 int set of int comma int import a data.set as set import qualified data.set as set then this should be like this. neighbors neighbors of hex comma y equals set.fromList how is word defined for pairs 0 comma 1, 0 comma 2. This is less than is equal. This is less than. So it compares on the first one first and then on the second one. set.fromList has a list so we will have let's see let's see a zip x minus 1 x so minus 1 comma minus 1, 0, 1 1 1 minus 1, 0, 1 this is this can we do fmap x fmap of the x y x comma y applicative applicative woosh so what is a type of applicative this is like a cool trick with applicatives to do all make all the pairs import a set x type type a application need to do a calling what is it called type applications so this at the list constructor takes in a list of a comma b so we are going to say fmap this is a function f of a all of this what was the trick maybe we just skip the f yes there is going to be a list of functions what was the trick oh we have to use a star there we go minus 1 comma 0 comma 1 nice nice ok so this is going to be so get a minus 1 minus 1 0, 1, 0, 0, 0, 0 1, 1, 1, 1 set from ascending list dollar xy 2 x no this is going to be x plus a y plus b this applied to minus 1 comma 0 comma 1 star applied to minus 1 comma 0 comma 1 going to be a set of neighbors yeah but no this is ok I need it for the generation right let's try this out oh we are still in week day 11 so we got the minus 1, 1, 1, 3, 2 2, 1 and 2, 2 is missing because it is just the neighbors works it works let's see let's check ok so so we will read here get input this is just going to be a set of int comma int so we are going to get from lines so this is going to be zip lines fmap yeah I know you like list comprehension I do not like them ok I don't want to use list comprehension anyway let's I should be talking more here let me have some coffee I mean I like just mapping things doing it that way that's my that's what I do so this is going to be i comma here I need to say some tuple syntax stuff filter equal L second I need something called tuple sections like this and now it's complaining that set dot from list from line takes in i int comma strings and returns list of int comma int wrong yeah so this is the list of characters it's going to be zip a1 comma a let's just map it directly what's the issue here I don't care about the character here that works so read the file what's the issue here so from lines should take a list of strings should take a string into set of int command lines and it's because I don't okay now this line is correct and what's the type of this whole to take a list of integer comma string to a set of int this whole should take a list of lists of int all right I have to join or just use concat map right so let's see do print neighbors to do get input just input into print windows using backslash for paths it's always so weird okay so yeah 0 1 2 3 5 sweet and let's see 0 and 0 1 is not there 0 1 is not there yeah good so in fact it's gonna be x coordinate so this is gonna be the y coordinates let's let's say let's not mix those up so it goes so this is gonna be so this is gonna be y comma x actually let's say here j j comma i otherwise we'll get confused later I think so we have 0 0 0 0 0 0 0 1 0 2 3 okay yeah this set is in order anyway okay let's do like this nah I mean okay it's gonna be fine and like constructing this input is gonna take nothing so we don't have to do like ask list stuff all right if you're just joining us we're doing day 11 of having to code because I took a break to travel those two days day 11 and day 12 haven't done any yet we have done 13 and 14 you can find them on the channel and soon we'll be done with day 11 so this is gonna be a give us a set of map okay so update set so it's gonna be the map it's gonna be the occupied and it's gonna be the new occupied update map occupied equal so let's call this seating seating and then occupied okay so for every note we're going to generate its neighbors and check if four of those are in the seating so we're gonna say it's gonna be set.fromList from ask list actually set from distinct ask list that is crazy stuff that's gonna be fast bro set from distinct ask list now this list here is going to be so for each note so we map over the set this is actually gonna be do we have filter for sets filter set filter yeah we have set.filter so we're gonna we're gonna filter will be occupied we're gonna define that and we're gonna filter the seating and we're gonna where will be occupied int,int to will be occupied so for a given given look we're gonna say okay we're gonna check we're gonna say we're gonna take the neighbors of look so we're gonna take the only the ones that are intersect set.intersection of seating these are the ones who are not floor okay where a valid neighbors so this is gonna be so the set.size of valid neighbors set.intersection with occupied order than what? if a seat is empty and there are no occupied seats adjacent to it okay so let's see what we're thinking here if a seat is empty and there are no occupied seats okay so so this here non occupied neighbors is gonna be this set here so we're if a set is seat is empty so we will say if look set.member so if it is occupied so if it's not occupied let's say that because that's how it is in the instructions if it's not occupied then we return if it is not occupied and there are no occupied seats adjacent to it then we say then we say valid neighbors after set.size of non occupied neighbors so then that means if this seat is not occupied and there are no occupied non occupied neighbors so then we say okay let me just say non occupied neighbors equals zero so if it's not occupied there are no occupied seats adjacent to it if the seat becomes occupied else so if it is not occupied then we check if four or more seats adjacent to it are also occupied then the seat becomes empty set.size set.size this is already an integer four or more so if it if it is an element of occupied and there are more than four let's do it actually like this okay if the seat is empty and there are no occupied seats adjacent to it then it becomes occupied if a seat is occupied and four or more seats adjacent to it are also occupied the seat becomes empty so if it is occupied let's see so if it is occupied and so the seat becomes empty so we want this to return true if it should keep being occupied right and what is going here what why the seating is a set expected type list of int oh is it from distinct access list we don't need that okay so we did fix eq before also so we will say fix eq that takes an eq a and a function from a to a an initial element and returns an a so fix eq f a false case a is equal to f of a that is a otherwise fix eq f f of a so we will print now we have update yeah print eq fix eq so the seating is the test input okay we want to see here print fix eq update seating set at empty it is going to be a function what is the size of this 37 okay nice so let's just apply this to the input do do do do do do do do file like that let's see oops this should be pretty fast right just set operations sure come in day 11 exit okay oh yeah I didn't compile gtc day 11 dot x day 11 semicolon measure come in taking so long not good oh 2183 it took 314 seconds damn bro how long was yours Timmy 14 seconds seems excessive 12 seconds 2183 let's see if it's the right answer and you were just what updating an array or how are you doing it just a list do do do do do do do valid neighbors okay I don't actually need to do the intersection with seating here right because they will never be occupied let's see but then I never look at the seating right was that coffee it's coffee I just like the taste of coffee you know so Timmy is using an array what I'm wondering is like you know we are just updating we're just updating a set right and we're just talking about the set without updating anything it's a bit weird right let's see I mean we could start off with saying seating here right because in the first time everything will be easier fix oh yeah no that's true I don't think it is I mean I think it might be twice as fast works for the testing put at least pretty fast yeah okay now it's 4 seconds you can actually skip the first iteration but just saying seating here because in the first one all of them will be full 3.6 let's see what I want essentially is that I want it to be like subject to list fusion that's what I want it I like want all of this to just be just chug on through but it still takes 3 seconds even with optimizations and I think it's because we look at we look at everyone in the map right you guys have any ideas on how to speed this up yes not yeah I have an idea let's stop talking about pairs talk about insets so it will be inset we will map x times 3 plus y times now this doesn't work right yeah I think so it's not using a hash ALG right what it's doing is that it's forward class because you know what I'm disappointed with is that because we're not actually array I'm disappointed that because we're essentially doing the same as to me but instead of keeping an array around we're just we're just looking at we're just looking at the thing itself because now I'm worried that if I don't fix this right now the second part will be super slow let's see I like this formulation of the problem like it's just a set and then you update the set so what we could do is like can we change the integers to be something different I think it's also yeah I also think it's just because they put a lot of effort into optimizing data.array whereas set is like it's because it's so general you can't really do so much like yeah the sets is not a hash map now how can we turn them into so how many are there per line and then so what I'm thinking is we could turn them into what's the length of a line so the length of a line is going to be the string here and we filtered out the ones so what I want to do here is instead of picking this list of ints I'm going to do like the index in the line which is going to be i now yeah so the j the j is going to be length of ln so you see what I mean you know I want to make so if this is we have I can transform this into you know 12 if I knew that there's only 10 elements in a line but I need to know how many lines I need to know the number of elements in a line so that's going to be the the length of ln here the length of ln times j is going to be because of the set of ints this is because of the set of ints and then neighbors neighbors will become a bit more complex neighbors will just take in an int let's let's figure it out here so it's going to take in an int and then ln ln okay and now well let neighbors set into section occupy neighbors look ln ln neighbors will take in an int now this is we don't want this so so to from ln it's going to take in you know a line length and an int and a pair from ln ln ln that's going to take that's going to take a i it's going to be i mod ln it's going to become i div ln ln 2 ln ln yeah okay i'll look at part 2 i think i'm spending too much time here right wait a minute they don't care about jsd they care about the first seed they can see in each of those 8 dot oh my god for example the mc will see 8 occupied seeds this is this is a bunch you said 220 milliseconds for for the second part it was fast it was faster than your first part that's impressive that's very impressive to me let's see this will take in oh okay yeah 2200 oh yeah yeah yeah yeah like this so here we're going to delete we're going to delete x set this with xs and then we do length of the head of xs set dot from list of concat map of like this and now what is it saying that this x is not used wet uh um um now this will be seeding line then update seeding update line and then seeding we still get the same answer but not as much faster let me say set int we're going to change every set into int set so here here here here here and that is going to be let's check if it's actually the the pairs that we're doing oh wow see we change it to integers and it's much faster we were like spending so much time messing around with the I think because the int sets are actually not int sets are not like they don't use the ord class and they don't like use unbox ints and stuff instead so it takes 426 milliseconds and that's the same that's you know that's the same as to me you know and that's the thing you know that's like this was weird we were doing correct things but not quickly enough so check your data types if you if it's going slow probably because it's not int set let me show you int set data.int set that was coca-cola yeah nice so this was faster can we say not meant probably not faster right I mean wow to me you can't just keep upping the bar you know we had a deal so here we will say then we will return null null occupied neighbors I think it's quicker to see if it's null and to check if the size is 0 uh what is set.null otherwise otherwise you do this okay it doesn't matter too much we don't think we don't need to okay this is fine I think this is fine null checks and no it's not null we're checking if it's so null here null here is just a function right it's set.null right it's a set empty so it doesn't it doesn't actually check if it's an all point or anything it's just a function called null I really wish this chat here showed all the smileys it's a bit of a shame okay so now we've we've uh we've done this quite fast okay let's let's get status get day 11 let's push part one now let's see okay now we need to figure out these line of sight stuff now instead of considering just the immediately adjacent seats consider the first seat in each of those eight directions the empty seat below would see eight occupied seats the leftmost item would say we only see one empty seat we cannot see any of the occupied ones okay she she she she she it's going to be something right the empty seat below would see no occupied seats okay now you're going to have to discern between an empty seat and floor yeah that is true at least we have the inset going right let's see let's see what's going to happen here as soon as you start drawing people just consider the first seat they can see in each of the directions I was a bit more more visible occupied seats to become empty let's copy this so solution one is going to be we're going to take in an inset and we're going to take in line length and we're going to do this solution one seating line length is equal to fix you this is going to be set.size print solution one seating line length now we're going to have to change our occupied function I'm glad we didn't spend super much time on like figuring out like some rule I mean we could have done that and that would have been useful here like now we have to change in all the rules so update to solution two is going to be what's going to be the empty seats it's just everything from okay so let's just check here this is actually just going to be taking in a string let's see get inputs inset int three ints here and from lines this is going to return it's going to be some ii we're going to return from lines of i we're going to do the length of the lines of i like this yeah okay now get input here line ln and then it's going to be num lines this is going to take int and another int okay this is going to be num lines so where empty seats equal that is going to be zip zero to this is the x coordinate line ln and zero to num lines this is the y coordinate we're going to say set dot from distinct ask list wait we're going to map map two lines what do we call it? two line ln two line ln line ln it's going to be so the empty seats are the seats so these are all the seats so everything on the map seat and then we're going to say set dot difference with seating what is wrong here set set dot from distinct ask list dollar these are going to be the empty seats okay because they're going to be fixed okay now let's see here let me just reply to one message some people are going to bed that's okay we aren't finished yet so hopefully we finish soon this is going to be a solution too this is going to be we're going to say update to it's going to take in the line length and the seating and the empty empty floor actually it's it this is floor floor now it's asking me to can I just do control period on this okay now it's like trying to apply the hint whatever and now it's telling me to do zip with curry zip with curry to line ln that just works all the regulations of update too okay so this is going to take solution to seating line ln and it's going to take in num lines let's see let's see what we can make happen here because I'm a bit I'm interested oh now it's saying 32 it's supposed to say 37 right we still get the right answer for the input so it gives the right for the input but not it's disturbing that it's very disturbing we just check try and see what happens and like hope it doesn't hope it doesn't crash and burn I mean okay so let's just try it and then and let's figure out what will happen right if it doesn't work on the input at least we know that we can change everything around so that it becomes back to the 37 it was earlier i think it's probably something here see line ln let's make this just bigger times 10 maybe that's what happening let's see yeah okay so the thing is i think we need to go up to line ln plus one otherwise it will like be a factor or something like that oh no Jesus okay it works with 10 let's just i think because like it just has to be big enough what about times two let's let's have it some nice prime number 17 big prime number oh yeah sheet that's what we were wrong about when you do both sides let's say here where factor equals line ln plus one div factor mod factor let's see what happens now it's 70 geez oh yeah because we didn't change that it's gonna be factor equals factor fun of line ln and it's gonna be factor fun line ln times j or fun line ln equals line ln plus one because i think i think it's enough to go up just to the one but uh yeah nice so we just we just we weren't going up far enough but it just so happened that for the input that that didn't matter which is weird but okay okay now oh now it's a lot slower well a little slower because we have a way bigger number here why is it a lot slower oh yeah we're doing we're doing it twice makes sense let's see yeah it's still in the still in the range right okay now scene occupied scene that's the function we have to create okay now solution two update two needs num lines because solution two update two needs a num lines it needs so it needs line ln num lines and seating and floor line ln num lines seating floor which is going to be an int and an int and yeah okay so how are we going to do this okay so let's generate the lines you can see from the it's going to be similar to neighbors in the sense that we're just gonna like aggressively generate what you might see but uh and then filter it out scene line ln lines num lines this is gonna take in another int so instead of saying here minus one zero one we say this is for the this is the a's that's the x's so we say minus line ln up to line ln there's gonna be minus num lines up to num lines uh so let's say here bound line that is going to be uh bound line x that's going to be a x larger than equal to zero and x less than line ln plus one bound lines bound so this is going to be bound x because you don't want to be don't want to be checking too many of them bound y equals y is larger than equal to zero and y is less than num lines plus one so we don't have to generate exactly but we have to generate filter bound x we have to make sure that we generate them they're not too bad right because like at the at the ends we will be like discarding almost all of them filter it's gonna be filter bound y like this and that'll generate like all the lines you can see right no it will generate uh it will generate this will generate everything because it won't generate like only the diagonals um i mean so yeah the problem here is the diagonals right so it's gonna be we're gonna hold x fixed and that's gonna take all of the x's right okay so let's see here uh so okay let's just say horus is going to be that's going to be um x comma just map x a no this is gonna be y x comma yeah this is gonna be no it's gonna be x so the horizontal one that's gonna we're gonna keep the y fixed or we're gonna just map over the x and this is gonna be a we're gonna map this over the this minus a line ln comma zero oh shoot line and this is a bit dot line ln right like this that's what we were supposed to be doing earlier also so here we hold x fixed here we hold no so here we're holding x fixed a y fixed but for vertical we're holding x fixed and we go from minus num lines to num lines and we're gonna apply that filter bound bound yeah so we're gonna filter here filter bound no okay so so this is actually we don't have to do this we just had to go zero up to line ln plus one and this is gonna be from zero uh and then we don't need to bound them because we will we generate them such that they are in the are in the range and then we have to generate the diagonals we generated this and now they generate the diagonals so it's gonna be like minus one minus so it's gonna be zero zero right minus one one minus two minus two minus three minus three minus four minus four and that's just zip yeah exactly so this is one diagonal and how is the other diagonal to r is equal to zip so the x coordinates go from minus line ln uh two line ln so it's just like this and these y coordinates go from a minus num lines to num lines is this just like x minus line n to so this is like x plus minus line n to x plus line n plus one is going to be y minus num lines y plus num lines and the other diagonal goes like this so it's zero zero all right that was okay so if we have one one then we want to go to zero comma two so then it's minus and plus so then it's minus and plus right i think so uh so then this would go from uh so here's the first diagonal right so if you have you're at one one and you go minus one zero zero now you want to go uh you want to have five two two zip oh shoot does this even work no let's see no this is too much okay so then first if you write one one you want to go to x plus one y minus one yeah so this is going to be reverse this okay now we have all these so we are going to map uh that's just debug.txt we should we have to map you know so scene is going to be set dot unions of harris rurdy dyag l2r and dyag r2l but we have to first map a two line ellen of line ellen here so this is not going to be even i'm just it's going to be distinct but it's i don't know what it's not going to be i don't work so we're just gonna say delete the input from scene map this is not correct because we mapped int so this just creates all the integers and then we have to say yeah okay so this is just going to be set dot problem list but the problem with this okay we have to map concat map or this map dot let me see what should this be this hole needs to go from a list of int comma int to a list of ints so it's going to we're gonna map to line ellen line ellen yeah nice we don't need to bound this is a dumb advice now let's with these diagonals you're in the middle are you going to see from the middle of the list i mean i'm gonna i am going to filter it out with the set stuff right i mean this is just like this is these are the entire lines uh i just want to see what happens if i if i do this debug trace show id trace show id trace show id kissing so solution two update two update number occupied scene it's just gonna be seen line ellen num lines let's just give it 0.0 to line ellen line ellen 0.0 i don't see what happens for 0.0 oh my god there's something wrong here yeah import debug dot trace trace show id let's see oh shit i didn't want it for the input okay test input so this is the horizontal one right so we're we're looking at from zero comma zero we see those lines then we keep the x so here we're keeping the y fixed so we that's what we see this line and then this is the vertical one which is going to be this line then we have this diagonal and we have the other diagonal because what i want to do here is then i want to say right so so we can see here like this this starts at zero zero and goes okay let's let's do it for 1.1 instead zero zero is not a good example here so then we're at 1.1 and then we should see so we're holding fixed so we see zero one one one two one so here we're holding the y fixed this is going to be the vertical one this is the horizontal one this is the so yeah so we see 0.1 0.0 here exactly we see 0.3 we see 0.3 and we see one one two uh so we see yeah right so we see the y corner three zero three yeah so we one one we say zero three or three zero and we want to see uh we want to see two one yes three zero yes okay once you have all the seats in these lines how are you going to find out which ones you can see because you can't see the yeah i mean i know i'm just working on it uh but let's let's first let's bound all of these somehow uh first of all we don't need this this can be zero and this can be zero do it so this is a diagonal goes from the one one and this is the other diagonal which is also supposed to go from zero okay now we have forgotten rid of all the negative numbers this is the vertical horizontal vertical nice wait no yeah this is the horizontal yeah yeah so here x is going yeah and then here y is going up let me see that i diagonal up to the left and down to low uh so this is reversed for some reason uh but i mean it is we call reverse but what do we why did we need it reversed all right so it's gonna be x minus that's what you wanted right let's do it for somewhere that's not in the middle so zero one we keep the y fixed horizontal vertical diagonal so zero of your third zero one then you're here okay right then you shouldn't be seeing all these are wrong diagonals so if you're at one one if you're at zero one if you're at zero or here then yeah then you should see at zero one you should be seeing you should be seeing uh one zero oh you should be if you're zero zero one geez all these diagonals are a bit rough so uh let's do it a bit differently so this is gonna be west comma east span we're gonna do break equals x comma y north and south that's gonna be break equals this comma y map of this stuff here then it's gonna be a south west to northeast that's what this is intended to be and then we break on the thing here let's just use southwest northeast and and then as you know people know the directions right you don't have to specify directions west east southwest northeast uh we don't want the one and then how do i intend to use it to me i'm gonna i'm gonna like find the first one from the direction i'm seeing that that is in that is the it is an element of the occupied set break x comma y uh draw a map y a x comma y no like this and this is going to be northwest to well this starts at southwest to northeast this door said northwest it goes down to southeast and it should be reverse this now seeing it's going to be all of these v comma e comma n comma s comma southwest comma northeast come on northwest comma southeast and we are going to say trace show i d all of these so if you're starting at 0.1 so let's see then you're then you're like you know then you are here 0.1 right makes sense so you don't see anything to the west and this is all to the east why oh yeah this is the result and then we will drop 0.1 here now to the north you see 0.0 and to the south you know you get yourself and then these okay now to the northwest uh you see so to the northwest you know that's here and that's nothing there right so those should all be those shouldn't be those shouldn't really be there so uh wait that's south that should supposed to be southwest all right doing it the wrong so this is actually this is actually northwest to and then it goes to 1 comma 2 so it starts at you and it goes one two it's going southeast northwest to south southeast okay uh will be only ever like we want to start at zero and this is what we want to start at zero let's we're gonna we're gonna we're not gonna look at that part okay so from so okay so the northwest zero zero two zero three four this is the so horizontal this is a vertical and then this is northwest southeast but this is actually this is actually southeast uh let me see okay so we want to to take the up to the line numbers let's just do it let's not do this plus one thing I think it's let me see ggi 0 to 2 yeah we don't have to do this plus one okay okay now we've generated the the uh the pairs um but we want to map it we won't actually map it so that we're gonna say here it's gonna be map x comma y now a comma b to x plus a comma y plus b of the sip a which is going to be the same as sip with of this function here this is we don't need this dollar we don't need this dollar uh what is wrong here oh my god I don't want to use that couldn't match expected type int to int int first argument of sip with oh yeah okay this doesn't take this actually takes in two numbers a and b okay this now we're getting somewhere oops I split it actually let's see what we're getting all right this is not great content I'd have to say this is just like me hacking around just looking at all the output but this is like this is 80% of programming right it's just just trying to figure out what you're trying to do okay so here is the vertical here's the horizontal this is so this is going to be zero one yeah and then it's so starting from there one two two three southeast yes nice and then there's nothing to the northwest that is absolutely like we want it northeast southwest that is going to be x is it just like this minus uh let's see you know exactly now that doesn't work so what it calls a little right so this is west east north south northwest southeast northeast southwest because we want it to be kind of in the order we're defining it otherwise the trace because the trace is actually shown when it's evaluated right and that is yeah so that's it that's gonna be something else this is a northwest southeast now this is the northeast so we want this to be one right we want that to be one and because so for that one we want to go like this so we go to the northeast then we go zero one let's see where we are and we go one zero exactly okay but I think this actually only works for the northeast because so south so we had southeast that went down that went down right yes north so this is gonna be this this is not northeast this is south it should be southwest so northeast is going to be that's just going to be um I think that's how we have to do it and then southwest is going to be a minus a y plus b and here we want this so this should be zero up to y and this should be zero up to this should be so it starts with zero yeah I think that's it oh I think we have to do this for all of them so northwest is actually going to be northwest then we are adding to both and then what is it southeast then we are we are no northwest that's this direction then we're deducting from both so this should go from zero up to x and to y southeast then we are adding to both so this should go from up to x minus line ellen and this should go to y minus non lines okay for the northeast this should go to x minus line and so this is gonna go so north north means we're going up here northeast yeah this is correct so but it should start so y minus zero up to y yeah this is so up to x and then it should be and y minus non lines I think that's exactly the directions we can't do the brick stuff uh okay yes so west east north northwest southeast northeast southwest we started at 0.1 and we got this zero okay so we go and then this is the vertical one here we go one up okay so northwest we can't go anywhere except itself uh this should be wait y minus non lines oh yeah okay this should be line line minus x we did wrong why right otherwise because we saw that the the return empty there the lists themselves exactly so this should be the northwest we can't go anywhere so this should exactly be just the point southeast should be that northeast and southwest okay it's all coming together yes okay uh but because we don't want x in there we can just start all of these at one and then we won't get the uh wait no we need we need that actually so uh because we need we need it for the other one right I think we can start all of these out at one we'll work out we start off at one and let's see see what happens here so we got horizontal so northwest there's nothing there right there's nothing here southeast that is so one two yeah and then the next coordinate is two three yeah nice okay uh so northwest and northeast seem to work our south is in the northeast yeah that's only one coordinate and then southwest is also empty okay sweet how can you fix this couple sections I don't want to use two sections okay these are all the ones like these are all the ones we can possibly see from our from where we start and crucially uh so what we so okay so we need to we need to generate this as a list so seen we need to consider it as a list oh chiral chiroptical is that like a chiral packer and a some opt decision something like that you gotta explain your name or not you know I'm gonna say it's a free country but I don't I don't know what that is PR on the declarative programming streams wow yeah I'm just trying to keep Haskell cool because I do all my research in Haskell and if nobody uses Haskell then my research won't be used so I'm just trying to show people that all the advert of code stuff like you can do it Haskell it's gonna be look a bit different but you can do it and that's what we're here for so uh the west uh let's let's try for another point let's try for two two now we want to flip these around so that they are exactly in the order that you're seeing them from so okay so the west horizontal solve these so so because we don't see we see one two first right when you go to the west so to the east it's okay to the south it's okay uh but it's gonna be west and it's gonna be so uh west it's gonna be reverse west prime and north is gonna be reverse north prime I mean there's so many streamers oh is there a PR am I am I on uh oh cool no I didn't I didn't I didn't submit it must have been Tristan yeah yeah he's been watching so but it's cool wow so many okay I was gonna say so many but wow there's a couple it's definitely a couple that's nice okay let's uh I like the effort yeah I like the I like I like that someone's collating them you say calling collecting looking at them all because there's not yeah there's a bunch of us but there's not too many of us right okay so northwest is in the correct direction southwest southeast is in the correct order now northeast is also in the correct order and southwest is in the correct order so this is how it's going to be okay so oh we have a discord send the link I bet a lot of people on the stream wanna wanna join okay so let's uh so now we've we generated the scene now let's let's check let's see here uh now we're no longer gonna so this is gonna be we're gonna take in the we're not in addition to the lines we're gonna take in uh we're gonna take in sitting we're gonna take in floor we're gonna take in occupied so this is gonna be in set to in set to in set uh oh sweet I will join the discord not right now well can I if I push it does it work no okay I don't want to do it because it's gonna it's gonna show like a QR code I can take a picture of on my phone and I don't want that on the stream but I'll join uh I'll join after this one I think I'm almost about to be finished okay so what is the first one you see so you can see over uh that makes sense I'll merge that PR yeah uh I think so I think I will either keep doing advent of code like from previous years or even do you know some more practical stuff you never know but yeah merge it so I mean the plan is to continue but I am still in the process of thinking about what the content will be I think it also will depend a bit about on you know what people want to see uh but what I want to do first after AOC is uh that came out this is new stuff from Amazon so you can like write like container API stuff so that you can like run lambda containers in any language as long as they implement this interface and I'm gonna make a task called interface for that so we can like very easily run Haskell programs on Amazon lambda because you know it's Amazon lambda and it's it's really hard to run uh it's really hard to run Haskell I'm like you should be able to run lambda code Amazon lambda okay geez so what we're gonna do is that we're gonna filter all of these because we don't need we don't need the ones that we can't see or like we we we don't need to look at the ones which are floor do I even need to know what is the floor I mean I just have these so let's uh let's check it let's see um so okay first scene takes in a list of int comma int and returns maybe int comma int first scene empty list is nothing first scene uh loc locs so so okay uh now if it is the case that loc is you know I don't I don't need to check the floor I think I'm just not gonna check the floor so if it is a case that loc is occupied it's gonna be set dot member occupied is occupied he's empty he's gonna be set dot member seating I need for instance is about this so okay if the loc is occupied occupied loc then then I want to and then I want to return it's going to be a maybe let's say so the the first scene in this direction it's going to be either empty or it's going to be occupied or there's nothing in that direction so this is just going to be a maybe int so if it is occupied we add one to the number of if it is empty we don't add anything to the number uh set dot member occupied right so we have to do here if it otherwise we otherwise otherwise like if it's not occupied it's not empty it's going to be the floor so let me say first scene scene of the locs and now where is loc inset a line loc this is going to be a two line ellen two line ellen a line line ellen of loc line loc line loc so here set dot member seating uh let's see is occupied should no is it occupied here am I doing the same thing again uh no it is occupied takes in an int and returns the ball right is empty takes an int returns the ball what is wrong with seating here like a line so int num like this oh oops takes in an int and I don't use floor because I don't need floor so I'll just I'll just keep around but I'm not going to use it okay so I'm not going to return an int set this is going to return an int and it's going to be some map maybe first scene we're going to map this first scene on the list of north but how do you go north east south west no let's start from north let's go north northeast you go like the opposite way right when you're talking about compasses let's go there let's north west west southwest south and next up is southeast then east then northeast and it has an issue with this because map maybe what is what is it complaining about use a type annotation northwest is a list of yeah map maybe takes a uh okay so first first scenes let's just it doesn't know what the sum here should be that's it's a bit weird right uh first scenes is indeed uh this event okay we're gonna use a first scenes but it's saying that it can't it doesn't like this for some reason because map maybe here is not in scope that is the thing imported at maybe okay now then we can just use some dollar of this okay now this is going to check the first scenes by checking the inner direction which ones uh you see first and then count the number of occupied seats you see that's actually i think that should be better right let's let's count it like this maybe int comma int so if we if we find something occupied it's going to be one comma zero otherwise it's going to be one zero comma one and then instead of saying sum we say fold l this is going to be just actually just so it's going to be fold l of x comma y to uh so we have x comma y and we have the a comma b and we return x plus a comma y plus b so we update it all starts here comes zero and it doesn't like that well we'll even just do fold l one it doesn't like that for some reason because uh because uh these uh what what is going on here oh right and then we want to return okay so scene let's stack here okay well we'll be occupied okay so we're gonna check here we're not gonna check valid neighbors occupied neighbors occupied scene blah blah blah we're just gonna say uh occupied ock comma and it's going to be scene of line ellen num lines seating floor occupied and let's let's just remove this floor here let's remove the floor here as well a floor we don't need floor or we're going we don't need floors it's num line seating floor no this should be num line seating like this okay and now it's complaining that the scene we put in line ellen we put in num lines we're putting the seating uh we put in floor and and this is gonna be look so no checking here we'll be occupied next turn so this is going to check okay if we saw so it now takes five or more visible occupied seat for an occupied seat to be empty so if ock larger than equal to five then false wait did we do it we did it somehow differently right we did it somehow by saying gave it we didn't see so if the current one is occupied so let's see if loc set dot not member occupied so if it's not occupied and we see and empty equals zero then it's going to be occupied next so we see no false seats else uh ock less than equal to five you think we got it let's see let's see what happens 28 let's see what happens if we do run this on the input did it along does it take it takes 480 milliseconds and we turn three 36 let's see let's actually test it on this input first uh these notebooks okay but wait for the test input that was the one we had right what do we get then we got We got something wrong. I think I think we got 28 when we should be getting 26 I've got 28 and not 26 Did it work? Let's just check Nope, that wasn't right right at all Because so we we're getting a wrong number here Why is that? Is it because we're not using the floor? Oof, this is taking long right? We were gonna do an easy one, but There are some nice smaller test examples for the seeing purge Yeah, that is true The empty seat below it's the eight occupied seats Let's test that Uh, let's see Uh, ti scene one Let's see Uh So this is gonna be zero one two three Zero Let's see What is the coordinate here? Zero one two three Zero one two three four It's gonna be four comma three Let's test it Let's test how many Oops, this is day 14, right? Yeah Oh, I put it in the wrong direction, didn't I? Yeah Ti scene one Uh Trace show ID, let's see Trace show ID And uh Trace, let's let's just write here Res Now that's what we were testing earlier, right? Trace show Uh, so we're gonna say scene line ellen num line seating occupied four comma three uh two line ellen Line ellen four three and the res Trace show I want Trace show Oh, I trace show where I want to show this for four three If I run it on ti input, okay, let's let's just do it differently Let's not do it that way Let's uh, let's just Use it directly, right? ti Scene one Then we just want to print scene line ellen Uh num lines Seating What is it gonna be seating occupied, uh, but the seating Uh, the seating only checks for those which are l So let's change that Uh, what's wrong with this? To do to do to do to do They should work Uh, no now we'll think yeah, okay. Well, we're not looking at that. Anyway, uh two Line now I'll like think that Occupied ones line ellen four comma three What we need so we have seating and we will have seating again as occupied Let's see So it says that That this one sees So let's print seating That it sees three occupies and zero empty Which makes sense But so this one would see eight occupied seats Okay, so Let's let's uh Trace show all of these Which one is it looking at? So it's looking at three three two three one three zero three Now let's print map From line ellen From line ellen and num lines No, what is it? What is it? From line ellen uh line ellen and uh, yeah Uh search dot map to do to do to do uh, I didn't like that because Oh, this is too line ellen What? So I want from line ellen. Yeah, so I have a map a set of uh Yeah, so this should be from line ellen from line ellen And then What does it want there wants a whole type set key to set key? Yeah Uh Okay, so this is gonna be an inch to an inch Okay, I can only map over the keys map From line ellen from line ellen line ellen A dollar set dot two list Let's see What are the seats here? So zero seven one two two four three one three four three eight three four zero seven That is This one So that should be in the Okay, so so this is the horizontal one, right? So it goes Uh, no, which one is this? This is This is a Okay, let's actually change this a bit Okay, s e n e s v trace show maybe And and it doesn't like it because I thought I Did that already Now let's see which ones are which so West three three, uh two three One three zero three Did I just give it the wrong coordinate? so the x should be zero one two three Yeah, I think I gave it four three It should be three four and it says eight So it works for that one So let's say it's both over west. It says she's two four one four and then zero four And then two four is in the occupied So it sees that one Okay, that was ti scene one The leftmost empty seat. Let's see here Uh, let's make a new file ti scene two Okay day 11 Let's see here ti scene one ti scene two get input two and it's saying That the leftmost empty seat would be below it see one empty seat But can't see any of the occupied one. So that one has coordinate Uh one one Let's see one One so it should see one empty seat and nothing else So it should we should we get zero one out of it ti scene two And indeed we do get Uh, oh shit accidentally pasted it Uh That we then we get what we get one zero because I don't I don't distinguish occupied From empty No, wait, that was that's not the same Yeah, I I just don't distinguish occupied from empty in the Parsing stage Okay, I'm okay. I'm gonna take us two two seconds Hello again. So we need to change our parsing a bit to distinguish Empty and from line so Empties So let's see Now it's gonna be a equal equal to c And it's gonna be we're gonna pass c here So and then we're gonna say from lines it's gonna be Empties and It's gonna be from lines Uh Occupy And then like this right? Do-do-do-do-do-do-do-do-do-do-do-do-do-do-do-do-do-do-do Oh sheet right It's set come on like this Oh my god, this is such bad code y'all So this is gonna be empty seats And then it's gonna be occupied And the line length is going to be the same and then on lines. So this is going to be Empty seats is going to be seating and then it's going to be occupied seats Based this except we change this to two And we change this to one point one And it didn't even compile well no it compiled just we didn't try to compile Yeah, see and now it says zero point one. So it says sees one empty seat to the right The empty seat below would see no occupied seats new file ti scene three Okay, let's see Let's actually have it solve everything as well seating Occupied whatever from lines And in see a ti scene three we say The x is going to be zero one two three y is going to be zero one two three three point three Let's see what happens. Let's see what it does uh Oh Ti scene three Oh fold l1 empty list E Toot toot toot Okay, that happens if there's nothing, right? Let's see again. We don't want it to crash That would be bad. Oh, no, it's doing the trace For the solution as well. Let's not do the solution. Uh, so I mean I Seems like it's doing everything correct, right? What is this three three here? Uh, that is the print of the empty seats So for tsc in tune we have two empty seats tsc one we have one empty seat at three point four And uh, okay, so the vision Like according to the test examples the scene part seems to be correct So I don't think I don't think that is the issue here We seem to be counting those correctly. Um Could it be this Okay, they still work Now let's uh Stop the trace Bill says 28 Now, uh Do we have to start with empty seating? Oh, okay update two Oh, this should be lesson five, right? I mean now it gets Uh, but we have to now we got seven Oh my god, I just wanted back to when it said 26 So what are we what are we tracing here trace? Sure Oh, okay I just wanted back to when it said What did I change? I changed this to fold out. I think I because I don't think I oh, yeah, no That shouldn't matter, right? Okay, so so if If the seat is not occupied if the seat is empty And there are no Let's just check that right so if it is If if the location is not occupied And there are no occupied seats adjacent to it the seat becomes occupied Okay, so if it is not if it is occupied And four or more seats adjacent to it are also occupied that seat becomes empty But now it only says seven It said 26 before Otherwise the seat state does not change This is solution one being line island num lines sitting occupied Yeah What did I change? You make it You make it like this I changed this right? What happened here? Yeah, yeah So because I think it's correct now I was just I had this lesson five here wrong But now I can't figure out What I changed To make it uh, let's just save as Day 11 backup now, let's just undo I already had all this change Okay Uh, no Okay, why? It like reset my buffer That is not what I want to do if I do save as Do do do do do Why does it keep saying zero you keep changing this? Oh, it just stops after one iteration sitting Now it says four Okay, so this this this one here should be a five But it's like it's not tracing Anything because it seems to like it's not running trace show id update two Oh, here it is. Okay It starts with these occupied That's right here res equals and then we just say trace show uh Show dollar set dot from so map to line ellen line ellen a A set dot From list press No That to list res res This it doesn't like because pretty much type int with int int as it's supposed to be from it starts with Oh, okay So it starts with zero zero zero one zero eight zero nine nine seven nine nine What if I but did I start off with set dot empty? So it should uh, it should put all of them there, right? The first one should be no the first one shouldn't be all of them so zero zero zero one zero eight zero nine Okay, so it says all of them so all of them will be here after the first one This is a backup Yeah, this should be set dot empty Good thing to make sure okay the trace show uh map from line of res res is Up the line solution to seeding by print So it just gets an empty list do do do do do do That's the seeding but then it seems like The ones that this says won't be occupied Is somehow wrong Okay, so occupied is nothing so in the beginning this will be Trace show ID Let's just see all the traces here if it sees Oh, I think I have something wrong with it if a seed is so if a seed is Not occupied And there are no occupied seeds adjacent to it So if you there you can see Oh, so this should be so if it's not occupied this should be if it is occupied So if it's so if a seed is empty and there are no occupied seeds adjacent to it That seed becomes occupied I think this should be equal to zero If a seed so if it's if it's not occupied then it is empty And there are no occupied seeds next to it adjacent to it then let's see if you can stop If the seed is occupied And four or more seeds adjacent to it are also occupied So I just not need to count the empty Oh, now it says 26 Which is the right answer, right? Then we don't need to count this But why do we need to count it? We did need to count it here either we said why why were we counting the empty seeds? Oh, we were just counting it for like the if we could see it, right? Okay Uh Then let's remove the trace try it again trace Okay, now this says Printing We don't need to print let's Do you see this? We don't need occupied And we're going to look at input test input versus the input I'm just going to run it see if I get the correct answer and if it works Then I can just remove like the count of empty that was only used for For um That was only used In the in the like in the visual tests, right? Let's see. All right. We finally did it Damn Okay, so we generated to these diagonals and lines and stuff and then we got the wrong answer for a while Uh But it was only because of this awk so we like we screwed up just this part And we were like trying to figure out Where the error was in this part? Uh, which is you know, it's it was sad. It's actually sad and it runs in Four seconds. So we're not even close to to me Uh But we're doing a lot of set operations and stuff But uh, yeah, I'm just empty happy. I finished it because damn And that was That was rough Rough actually, um So let's see here. Um Yeah, okay Anyway, we made it It's been quite a marathon of a day. We've been doing And a bit of code streaming for six hours today Uh, I want to thank Timmy We're sticking around the entire time Uh, but yeah It was uh, I don't know. I don't think this was good stuff actually. I don't This is just a bunch of stuff we had to do Yeah But you know This was the best you could find me streaming I'm but I'm grateful. It's a It's nice Why are you unimplied though to me? You're a good programmer. You should should be getting Getting offers. I would hire you that's for sure but uh Unfortunately, I don't Have a company Right now But four seconds. That's that's lame. You know, I I I'm surprised I thought that I thought that it wouldn't be like that So, okay. First of all first seeing loak loaks Now my question here is Why are we doing? Why are we why aren't we just uh, what we should be doing here? It's just These both should be inp Uh, this should be Two line loak line Ellen Two line. Oh shit Two line Ellen Same for all of these Two line Ellen line Ellen And then this is going to be is occupied Line loak. I mean it doesn't doesn't matter When we do it, right? Uh, let's just all let's all we don't need to this Let's just say We'll go uh find I don't know. I don't know and there's nothing here I'm just like, there's nothing here. I see that's like, oh, this is causing the slowdown Oh, shit, let's uh, let's fix all of these Let's uh try to profile gt profile Then we do something. Let's just see where to spend all its time a gt prof Never done this on windows though. So let's see if it works day 11.hs You compile with profiling Good stuff. We run it with profiling Day 11.hs Plus rts minus p it runs And now it will tell us where it's spending all its time But of course it takes a lot longer Because we're doing profiling As long as it's not racial profiling Okay, I don't know. I don't know if that was appropriate. That was probably politically not appropriate thing to say on the street But you know the cops Do that and that's not okay Yeah, so it's been 31 of its time in two line scene dot period period so line 55 56 Is where it's spending all its time 55. Oh, okay this stuff We could fix this stuff, right? You think it's it might be the the the break Let's say west We don't even need to reverse the west. It's just gonna be yeah, we need to re West is just gonna be math X goes to x comma Y of zero So and it doesn't start at zero it starts at It's going to so it's this is west so it's going to start Right, so it's going to go from X minus a so this is gonna be just a And we're gonna start at x And we're going to go Up until x minus the line line ln minus x right So then we hold y fixed and we go like this we go we start from x And so we go No, no, no, we don't start we start This is gonna be plus no, this is gonna be minus. Yeah We start from x And we want to go x minus x is going to be zero and then We want to go all the way up to x So it's going to go up to zero So it's going to be zero To x and this is actually we're the one to x reverse Of this and then we have to reverse it again Uh west prime No, okay east Now, okay, let's just define north Because that's going to be the exact same Except then we're We're doing here and we're going to reverse one up to y Okay, now east then we're going to be adding We're going to be adding one And we're going to be adding all the way up to line ln Minus x right so that will take us all the way to the end and then south Zoom again plus a one How about the little num lines minus Why Why though let me see uh, and it doesn't like this because It's already defined here So west north east south Let's see if it's any faster now Let's see if it even gives the same result Now it doesn't even give the same result Why is that? Because Maybe it's because we reversed too many times here let me see Why can't we What is the difference here? So going to west we hold y fixed And we're going We're going one so we end up at zero So it becomes a you know x minus one That becomes x minus x and then x minus one This should actually we should not reverse these I think that's the issue So it's looking at the wrong first All right, that's still wrong So first we see okay, we know. Yeah. Yeah, then we don't reverse this That's still wrong. Okay, so I think west and east now and I'm right okay, so Okay, so for when we're going east then we start with x plus one right and that's This is I think this might be it No reversing anywhere Yeah, that was correct. Let's see Now what is the issue I can follow it again. Let me see plus rts slash play Day 11.xc plus rts dash p Compile it and run it Because I I you know I I feel like these Shouldn't be that bad In some sense, you know, all right Is it working? Okay, this is just frozen. Let me see Let's just compile it And then run it Why is it so slow? It's way faster earlier, right? Delete this Okay, now let's run it profiling So two line ellen is taking a long time. Yeah, I mean that makes sense We're using that a lot, right? And then we go like back and forth here Which I feel we probably shouldn't right? Let's say profiling again Okay Now it took 10 seconds with profiling on There's a lot of its time in neighbors And then generating all these lines since it's empty seen that so you'll be missing Yeah, generating all the lines takes a lot of time What if we we memo we can memoize it, right? And it's gonna be a map of a int To list of list of int command Right, let me see Because we're like every iteration we're computing it all right So first of all, I'm going to then We're gonna make these We're going to map to line ellen Line ellen on these all And then It's gonna be This is just gonna be Loc Loc and it's gonna be Just an int Or a list of ints. Let's see Yeah, I mean this will be fused Okay, now seen map int to This list of ints memo. So we were gonna see A It's gonna be here. So we're gonna see A Dears is gonna be this thing Gears So we're gonna say case look up A Map dot map dot look up Uh, no, we're gonna just say case Memo map map dot We're gonna look up the input just Dears d's Is equal to d's otherwise We are going to We are going to Say a We're gonna say like this So we're gonna say Import data dot int map Import qualified Int map as i am Data dot int map So then we're gonna make this into a Int map And i am dot this Now this is gonna be an int map Do So We're gonna return the result and the int Map int Okay, and now we return this Uh memo i am dot insert Uh i am dot insert uh imp uh So Let ds equal In a ds comma I am insert ds memo Now we return this comma memo prime Okay, so now we don't calculate any of these unless we've never calculated them before So this is gonna be we're oc comma Memo Is the result of this Uh But it needs It needs memo prime Memo So it takes in an oc inset and it should take in this int map int And we turn inset Int map int We return res Memo prime And we take in occupied and we take it we take in memo And Memo Defined but not used memo prime Oh, okay Right Actually, let's just not Use scene ever So we're gonna say compute Diags equals something and then compute Diags is equal to where we have to take in the line and the Int and the seating We're gonna take in the line ln we're gonna take in the num lines and the seating No, we don't need to take in the seating So we calculate all of these And we just say memo I am dot insert input And then Northwest southeast northeast southwest west northeast south memo And we have to calculate x and y here Okay, and so we compute the diagonals Now this is going to be Diags We don't actually need these Now we are going to say a Theors is going to be Diags map dot period of the input i am dot hip This is wrong because Can you match type key inset with int? Okay, yeah, it's because We took taking too many things now. So we take in the diags We don't need anything else We don't need we don't need these two So we compute the diags first and then we pass that along to the scene Now this will be sitting We'll be Diags it's not going to be memo eyes. We're just going to pre-compute it once So we don't need they're going to be Diags and then this is not going to be anything And then we are not going to return the memo eyes thing It's going to be fine. So dot num line seating Diags So I don't think we need we don't we're not going to even do it this way. We're just going to say Just give me all the diags Because we don't need this and then we're going to say int here And then we're going to say Update to Solution two is Where diags equals I am dot from List We have to map it all over all Uh map So we're going to say compute diags line ellen num lines over the Over over everything in seating, right? A of a set dot ellens of seating and it's complaining That it wants to list a list of ints Uh, so this is going to say map I over to compute diags line ellen i And it's going to be you know i comma Set dot ellens seating Now this will be Uh This will be an int map Uh, but let's list of int and now this should be Okay, so you computed this We're not going to return this We just return this you remove these being uh occupied Um, what is it complaining about? Yeah, okay, I can remove this here fusion Okay, uh, there's a res here because we're only going to return Yeah, that's it. We're not going to be memorizing anything We don't need the num lines. We don't need these anymore We just need the diagonals Now update this is going to take Line ellen and it's going to take sitting in diags Uh, so compute diags. Let's see Uh Yeah, okay, this is going to be like this We are all going to see Now let's see because we were spending most of our time Uh, recomputing those diagonals Which was totally unnecessary, right? Now let's uh, let's run the profiling thing Uh, that was for the test input, right? Let's compile it again and run it on the real input So see what happens Uh Because now it should be much faster, right? That was not 10 seconds scene Line 55 to 65 Yeah, I mean it makes sense that we spend a lot of time in scene But at least we're not recomputing diagonals We just look them up We're spending a lot of time in scene 55 to 65 Uh And we're folding Let's see And we're not going to test this anymore Let's see. Let's see how it just runs regularly Now with like the speed up and uh, let's actually Optimize it as well Dude, dude, dude. Okay now it runs in 1.5 seconds Which is a lot better than the previous three seconds Now What can we fix? Uh, wait it was running so and we're also doing we're doing both Let's see how fast we are with Only the second part. Oh no I keep doing this All right now it's down to one second or Uh, 850 sometimes 850 that's about the same time as you timmy, right? Uh, I think so he's tim has been saying That the new estimate is to 850 milliseconds and now we are there It's pretty good, right? I think so. Uh, Let's see how what how more now we're like digging a bit into gsc profiling, right? It's occupied takes a lot of time That makes sense, you know Let's see if it is empty I think so I think we could check We would so yeah, I think because like here we're like this these sets We'll overlap uh, they will overlap a lot. So So let's check Um seen Hmm 450 milliseconds. Yeah, that's good But yeah our 850 with a bunch of set stuff. That's uh, that's not bad, right? Now. Let's see here. Um Rummeline ln uh, where so what are we paying for? Let's let's compile it and optimize it and profile it How do I pass 032 cheese? I I'm not sure. I mean, that's why I I don't really use Stack I only just I just use cabal Because that's what works for me Spending 32.5 percent of its time in is occupied That's a bit much, right? I mean well, no, but uh like Just deers like it takes uh eight eight percent of the time. It's just Just looking up the directions Dears diags. I am in I think like in the stacked on jammal there is like a There's a field you can change to set that That should work Okay, now I'm going to stop computing the The the second one here because we don't need it. So first scene It's gonna be like if it if it is occupied it's gonna be One if it's empty it's gonna be zero Otherwise it's gonna be the rest Now this is not gonna be this This is just gonna be some Of uh map may be So first scene here will be Zero and this is just like a list of ints to Int now this is the list takes a list of ints Let's list of ints But it's complaining. Yeah, because it I it's uh, I want to return this Now scene We'll just return ock that's gonna be fine actually We don't even need to do this right we don't We just need to check if there's if it's more than five That's that 1.52 seconds Uh, I'm not sure that will help my uh any occupied and five or more occupied are taking six and seven percent for me as well All right, but six and seven percent for you But uh 36 percent for me What are you spending your time on that's a question, right? So what I want to do here is instead of this int set of occupied Like that they would be nice, right? So because like now i'm checking if it is a member of the set But I really just want to check like this integer What is it? But then I need to like update the map and stuff. So I think I think I mean, I think it's not You're not wrong I mean, so you set up member. I mean, it's not that bad though, right? Okay, so So for scene So this is sitting occupied. Okay, let's see here. So update two so Uh, so occupied and empty Is going to be Seating and then the set dot difference with Occupied So instead of saying here seen based on occupied. So instead of saying you're seating We'll just look at empty That should be a slight slightly it's a much not a much it's a It's a much smaller set, right? And then it takes with profiling odd. It still takes the same I mean, this is just slightly smaller Okay Update two will be occupied. Yeah It's just so weird that it like just this line here takes Takes 11 of the time just looking up in the map. Let's see Yeah That's that's a bit disappointing actually But maybe it's because it's like looking at any ints and Yeah, I mean, anyway, this is quite fast So let's let's just kind of fold this here And just say Set dot member of occupied And then here we say Locate Set dot member of seating No, I have empty This is Yeah, I think I'll I'll go to bed too very soon I think I think this is as good as it gets For us uh today It it does quite well Tim is array based approach Was quite good But I think our our set based approach, I mean it wasn't It's not bad, you know It's running in like 800 milliseconds Which which is pretty fine I think it's I think it's I think that's not not bad enough Not not too bad at least And let me just see and the profiling says that you know it's spending most of its time In the functions that Make sense In the sense he I mean so it goes a lot of times into this Goes so many times into first scene Oh, shoot. My keyboard is going. Wow. Do you see how Crazy it's going. I think it's because I had to so I like having it like this But Yeah, I was going wild So wait, let me see So we go we go a lot of times in the first scene We go a lot of times Yeah, because it's for every direction And we compute the diags But like computing the diags. Yeah, that's I mean that's like a fraction of the time because we just we don't do it that often Get input Now is occupied. Can we somehow Optimize is occupied I think we can By figuring out the floor We had the floor earlier and then sending that into the compute diags Because if there's a lot of floor So we don't need to check Whether there's an empty seat or not on the floor, but there's not so much floor But let's see. Let's see that one last optimization we can do It's it now I think we had Where how do we calculate the floor again? You know, this is not supposed to be like this. It's supposed to be It's it like this floor Okay, and then we say Map filter set on lm Set dot member floor And we will we will make sure that we are only looking at the ones that are not on the floor Okay, uh So compute diags will have to change so okay, so so Floor is equal to So we essentially generate all the coordinates by doing x y into x comma y And doing this trip again, so it's going to be zero to line ellen as star to zero crew num lines And so this is going to be all the coordinates And then we're going to say map to line ellen Line ellen and then we're going to say set dot from Askelis even uh compute diags num lines floor Let's see. Let's see if this speeds it up a tiny bit. It didn't work. Not really It's even a bit slower now Oh, right. So This is everything But then we have to from that set dot difference seating To move all the seats from that All right. Now it's running in 300 milliseconds and we To me is running at 450 milliseconds We beat it. We did it We got faster than to me And it's that Oh, no, it's giving the wrong result. Damn it. I think this needs to be set from list It seemed so good. Um But if it doesn't work, no, it didn't win to me It's giving the wrong result now a Trace show I mean, this is not gonna. Yeah, it's gonna return All the numbers So seven or the input zero one two three four five six seven zero one two three four five six seven eight nine ten The first one should be like zero times the first one should be ten But ten is not even on list Let's see. Let's see what we're doing wrong now Uh x's they go from zero to line learn. Yes This goes to zero to num lines Let's see, uh Let's not trace your ID here. Let's trace Show ID here And let's just see what we get Wow, so many lines um, let me see So 34 goes all the way up to 91 Are there how many am I like screwing it up? Let's say let's say let's run it on the test input And let's see for the test input So then it goes from zero There's 10 lines. Is there 10 columns one two three four five six seven eight nine ten Yeah, okay. That doesn't tell us anything Let me just see if I add a dot then we'll be 11 Is it wrong? Oh, no. Yeah, so we run it again Yeah, okay, so the x's go from zero to 11 so okay What is the Okay, so I look is I think the floor is being computed correctly And so we take the set of everything Remove everywhere Remove everywhere that's a seat Then what do we get? let's run it for test input And let's Let's see uh trace show ID And let's see what happens zero one two three four five six seven eight nine ten 10 12 13 17 14 zero Uh, okay, this is We can't read this. Let's uh Hey, we're gonna say No, did we we want not member here and this should be not an ask list We already fixed that earlier We're still getting 71. Let me see We don't filter for the floor We get the correct 26 Okay, fill fill. I mean am I going crazy filter filter Returns the list of those elements who do not satisfy the predicate. Yeah, this should be set not member floor That's for sure Now this oh sheet When we did it so this should be set dot difference Should be okay 26 sweet Is it okay for it to be an ascending list? I think we generated that way but Will it work? Yes, it still works now. Let's run it for the input Let's tell him as we can do this Hey I mean, yeah, it's running running even slower now 750 and scrolling up scrolling down 450 yeah, okay Didn't help that much But it does something So now we're only looking so we only look now for When it actually matters, okay, let's Profile it again Now I think we've kind of applied all the domain specific knowledge we we have Let's see what day one lemon proff works out to me Uh, I think we need to Open it again. It spends all of its time in scene Uh, and that's because it's spending all of the time not in first scene but it's like Hmm, so it's taking the sum in the map of Can I do any Uh, let's see Well, how about if instead of doing some I just do Length of the filter of any no lengths a So any This is essentially going to say any is occupied, right? So first scene is going to be any first scene is equal to Uh any Is Look set dot member Occupied Of the Yeah, so this is going to be length of the filter id First scene, uh, let me see Filter first scene Of dyags First scene takes a list of int Whoa Any look, uh any Oh, this is creepy dears We don't need to do this case match thing here We don't use empty either But are we getting the right result still? Let's check Check it No, we're not we're not getting the right result even This is running on the input though. So if this were working This would be crazy fast No, okay, maybe not So this returns one If there's any so first scene Any is occupied Oh, no, no, that will let's not let's not run returning the right one That's not even returning the right thing Yeah, okay, let's go back to this Let's go back to this and let's Let's go back here So we're checking if they're this they're Occupied or empty Yeah, okay, that didn't work. All right Thanks for being Let's see. This is the only allocations Uh, so just I know it's gonna be cheating because I think Timmy didn't do parallelism. Let's see par Parallel map Haskell I always go up the L's The L's How do we parallelize? This is a parallel package Let me see here I'm gonna show you all how easy it is to parallelize Haskell Jesus GCI import A Importing for the follow I've been here for like Geez like seven hours today streaming All of this good stuff Uh Import control into parallel L that's strategy Yeah, okay, we don't have that so Parallel map it does I don't remember how we did it I think it's just here and control and base par Gigi conk Yeah, okay, let's not do it Because also like it's not enough to just set put par in there We also need to like run it in parallel with the right command line arguments and stuff like that Okay, anyway, we finished day 11 Uh, we finished day 14 earlier today. So now we just have day 12 To catch up on and then we're back On the business All right, thanks for today's session. Sorry for how extremely long it was Uh, we tried we did it in not such a long time, but then we tried so many things to make it fast. So Uh, and they made it a bit faster, but not maybe quite as fast as we would have liked Let me just add this to get add a day 11 At hs a git add star input star gets this Let's add all these ti scenes git add input git add ti Get status get come away. Why am I why? Uh, did we add the input before? Get commit Get commit Day 11 Push. All right. Now it's up on the uh it's it's up on the the uh, the github repository and big so jammin, thanks for following and uh And uh, yeah, I just want to remind you all like if you have prime gaming It's like click the subscribe button It gives me two dollars and I think it's hilarious to uh to get paid for just me programming because I like doing this, you know, it's not about It's not about the money, but it's Money that you can make I mean, okay, you can't make money Uh, in the sense that I don't think there's enough Crowd, you know that will watch programming live like there's so many people who enjoy watching games But you know, maybe this is a new genre Maybe we just started it right now Anyway, thanks again for watching And catch you tomorrow for day 15 All right. See you all. Bye. Bye