 alright welcome to today's stream give me a second I need to open the chat so I can see what you guys are guys and gals are saying let me put it up pop it out pop it pop lock it alright now it's on the screen let me prepare my cookie little Annie cookie it's called you got a good one today alright now yesterday hello fellow here is today's cookie perfect super good good stuff okay now let's start with today's problem what's it about you reach another volcanically active part of the cage let me just do a little bit alright it would be nice if you could do some kind of thermal imaging so you could tell ahead of time which case are too hot to save the enter fortunately the submarine seems to be equipped with thermal camera it's a very high-tech submarine when you activate you're greeted with congratulations on your purchase to activate the infrared thermal I want to know okay this is a classic okay apparently the elves never use this feature to use the price you manage to find the manual as you go through to open in the page one falls out it's a large sheet of transparent paper okay the transparent paper is marked with random dots and includes instructions on how to fold it your puzzle import for example okay this is gonna be some crazy stuff okay so 17 dots are visible okay also notes that some dots can end up overlapping this cost a dice okay so we have to fold did it do okay let's do this do okay new file example is our input okay so to parse the input I think we're gonna say read input file path to it's gonna be a pair of points data point type point x comma y no it's gonna be to end point eight comma in so okay we're gonna say a list of points let's just have it list of integers IO this of int comma int and then we get a fold along y equals and x equals let's actually look at the input let's just see what we can get for the puzzle we get a bunch of points and then fold along and then it's y x or y okay so we say okay let's do this data so okay data fold in stir equals a x int or y int now a parse import text dot parse x read p instance a read fold in stir where reads Prec read p to Prec parse where ours is going to be a read p fold in stir parse equals undefined okay so this is gonna be a list of points points and then a list of fold in stir okay so and so how do I parse a fold in stir well let me do read p to Prec what does this function do okay I don't care read p to s parse and we don't care about the first one and now this one is gonna be do we don't care about a string fold along okay and then we say so then we get the we have to try two of them so it's either gonna be y equals or x equals there's gonna be choice of the first one are gonna be do a string x equals and then a p so x over read s to p of read okay otherwise we do this one right off we're gonna be just like this so I will read a x and then it's an x or it's a string y equals and then y over read s to p read and that's how we parse a full instruction okay so now we want to so we just say data input and it's gonna be a list of points and it's gonna be a full list of fold instructions instance read input where parse reads correct we don't care about equal p to s parse where parse equals f type read p input now parse equals do so we are going to we are going to read the we're gonna say do many one so the points are gonna be many one of so how do we read a point well we we read an int right so many read p okay and let's say skip spaces read point is gonna be a right this is gonna be read int okay so read point just do a x read p char comma y read p return x come away so you say here read point and then we say let's just say input f map over this one combined with many one a read p read p to s and what doesn't it like this all right so this one has to be like this right all right it's the same here it's a read p all right this one is the wrong way around this is read s to p let's just do it like this read s to p a read there's some read under brackets here okay i think this should work uh might fail though let's see this one becomes um read input input becomes read input over f map read a file read file read input for example into a print let's try it probably gonna get the ambiguous parts no parts yeah as a gti day 30.hs so uh read well let's see uh read fold along x equals one x equals one and now this is how we did it let's see um what do we do then let's see fold along x equals one return x one two look at this one works this one works okay then we say um i'm cutting cooking my fault okay and then um why doesn't it want to read the next one why doesn't it want to read the hint am i doing wrong here we're still in the folding while we're still on the task one we're still on the parsing of the input it's not gonna be good today i think sorry guys let's at least do here let's see if we can work make this one the arriving show now let's see as a point what is going on today i just know i'm not it's just my some something that goes wrong here k munch true let's just do that i just want to see what what's left at this point okay so it's taking the uh string let's take the rest of the string now what do we do before we have a previous days right so read input we have that for all the days read p to ace reads preck delete this we just say it's the choice between these two what is the read end read as to p cd day 13 now read and why is the read ain't not working all right it's before right can this i don't understand anything here google it read as to p read that ain't oh my god i think it's reads okay that was a bit much okay and let's call this just parsing okay because it's the same here okay and at least we know we knew how to read the view so let's see here now let's sort back up here and just say call this parse point okay now this one's going to be a parse point okay so we say uh day 13.hs okay now uh bars point one comma two read p to s parse point apply this to the function one comma two okay and it parses let's say many one parse point we have this uh star bracket right something like this so how do i parse the input that's going to be do no points there's going to be many one a x comma y okay and now it's going to say many one parse point skip spaces a folds many one a fold insta s to p return input folds okay so what does it say now all right so it's fold instruction let's do it like this okay so we got the full instructions we just had to skip the spaces at the end okay great we're 30 minutes in and we've just managed to parse the input amazing anyway let's copy the input here okay so uh now there's a list of fold instructions okay so we have the top is a thousand transparent papers zero zero risk percentage top left coordinate first value x increases to the right so i'm going to increase each hour so coordinate three window okay where stars it out okay then there's a list of fold instructions these instructions in case i line will transfer you all the folder paper up for the left fold along y equals seven lines five vial positions where y is seven okay so so the x coordinates remain the same but i'm guessing it's like modulo seven okay so um apply insta fold insta just the points just the points apply insta so if it's it's if it's y and then we map a mod n it's not not okay all right we map it over the second so we do f map now let's see and let's do it do a input ps fs now print ps print fs now apply insta and then let's just do here the pattern let k okay f fs is equal to fs um that is fs prime so apply instructions f ps and we print this so we apply the first one and then uh so the six x so six ten it becomes so you want to see what zero so zero fourteen became zero zero yeah that was correct okay uh but so nine three which one is nine three one two three four five six seven eight nine three oh nine ten okay so nine those are fourteen nine ten okay that's this one i think one two three four five six seven eight nine zero one two three four five six seven eight nine ten so that's this one that one goes two nine three let's uh print the points or let's just see okay so for now only 17 points are visible okay so we do um well what if we do uh so we do set dot from list dollar set dot two no set dot two list set dot size of set dot from list now we have to report data dot set apply to this set dot from list set dot size we get 18 now only 17 dots are visible we should be getting 17 but we're getting 18 which ones uh disappear let's print print points to string okay now print points equals where uh equals map a maximum map s and d uh ps ps okay uh x max equals maximum map map fsd ps okay um and we do psp set equals set dot from list ps now we say uh so i would just map over the list um i think we do nothing x comma y and x from zero to five y from zero to five we zero zero one zero zero zero okay yep so we want to go map over x comma y so we're gonna have a string with the strings okay so we're gonna say for the uh y's in zero to y max this is gonna be the list uh x to x from zero to x max and the case here is going to be uh if x comma y set dot uh member p set then uh there should be a list of strings or it's actually a list of strings and then we just say let me say uh unlines okay let's print the first points uh print ps uh put stir ellen print points ps okay this is the first one let's print this one let's see how it can pass okay hashtag the first line is correct oh we're missing this one where are we missing this one that should be so this one which is a zero comma 13 where is it so uh let's sort the points okay zero comma 13 here becomes a what's a 13 mod what's 13 mod seven what's seven mod 13 though yes okay so uh okay we can't just take the modulus so you want a zero comma 30 so you want 13 to go to one how do you do that is it like minus 13 mod seven no that's minus six 13 mod minus seven how do we do the phone do you want zero 13 to go to zero one zero 14 to go to zero zero i mean zero six zero eight should go to zero six we want to find like the closest mode okay so okay let's just do it like this and apply instructions y and map f map moment okay so y and uh is this map f where uh f uh x comma y equals x comma and then uh f prime y f prime uh y equals so if if uh y so if it's less than n we want to if it's less than n then y else i think it's we do a so for seven we do let's do um n times two minus y then it's uh correct i think uh set dot size a f no links we get 17 okay let's do this no we're not gonna print the points it works for the example and uh we just do um so now we just care about the uh first fold and we're gonna say here uh fs f f underscore add and we say print set dot size apply in stir f ps now it's set dot from this to run this for the input non exhaustive patterns in apply in stir okay it's probably because the input has a x so for x it's the same right map f except we do f prime to x and then x if x less than equal to n then x else then minus two minus x we get 837 all right we got the first one whoop whoop now let's look at the second one page folding a paper according to the instructions the manual says the code is always eight capital letters okay um so yes nice so now we use the folder to apply all the fold instructions okay so we say uh fold r and uh no it's it's fold l right i think let's see yeah fold l fold left fold l um now it's fold r apply in stir fs ps right print points so fold r is a stir and then and now fold r takes an a and a b and a b oh yeah and we have to it's the points that we say fs i think it's because we keep saying that these are not functional things so he made the one that's literally a fold okay what does it do if you want an early example we get the zero now what do we get for the i think maybe our um wait so let's go over the input oh we get a lot of minuses that's not good why do they become minus and we've got the right amount of points but they all ended up being negative right like this okay we apply instruction ps all right i think it's because we didn't so for each of these we have to say set that to a list um set not for our list same as here it's not the a b s i think it's just we never we didn't remove the unique so we had some points left print p okay so when does this happen when does it become negative it becomes negative when um about nine times two mod then no there's nothing either it's uh it's just hard right because it works for the example i think i want the i don't want the um i think i want the distance of the point to the line i think that's the one that i want i think i want so minus n i think i just want the a b s of y minus n so okay so zero zero it's always good zero zero okay so i think it's the difference i think yeah this one is correct a b s y minus n why is this this shouldn't be so hard actually uh that's wrong okay so okay so if it's if it's uh less than n it should go to n that's for sure okay uh else it's the yeah it's the difference minus y i think so otherwise it's the difference from like twice of a b s n times two minus x everyone works what i don't get is that it says that it should be eight capital letters it's saying let's open out what do they mean by eight capital letters finish folding the transparent papers according to the instructions the manual says the code is always eight capital letters maybe if i change this to less than n maybe i just off by one or something that's still just random it's like it's not that we're getting the wrong i like i i don't even know what we're doing wrong maybe we're printing it out wrong it doesn't look like that has anyone done this do you know like we're supposed to read from the paper right that's like the final result here right okay so um so i i know what i what i'll do so for y of n i need to i need to figure out the max y okay that's going to be maximum of the second there's going to be ps maximum of the second of the ps now f is going to be a function we're going to say set to list set from list map f to the ps what's wrong with this one expected type okay max y maximum this is a list of points and max y is uh okay and then this one is comma y so if y is less than equal to n then we just return x comma y otherwise we do the uh otherwise it's the max y minus y the distance to the top modulus n x comma maximum map second right so max y is going to be on ps yes i think this is how we do it then we exchange y for x and then this one is going to be f x y then if x is less than equal to n and then x y otherwise it's a max x minus y minus x modulus n i'm just amazed that it kind of it's still it worked for the the previous one worked for the example okay now at least it's uh turning a lot fewer points applied to the example uh it's wrong on the example right so the so yeah okay so the sheet okay so we have so the sheet is marked with random dots and includes instructions how to fold it up your possible input first this is just in a transform point but that's your first value increases the right so i'm going to increase it on the corner three yeah corners in this example form of all our partner where x is a dot and paper and dot is an empty unmarked position then there's a list of fold instructions usually instructed okay i think i need to kind of compute the initial fold so apply instructions there's gonna be um you see what i mean like right because we might fold you know we might fall like not not at the edge right and then we might get something like this right so where the where the minimum one becomes the new maximum so we also have to fold the ones that are below okay so it's not okay for us to do and we can't do that we can't rely on max y either let's just focus on this one first okay so let's say we are folding like this so where does where does 0 0 end up if you know don't fold in the middle this case is not correct right but then we should have the negative amount right okay so i think it was correct before let's keep it like this i think it was correct when it was i think our first implementation of the fold was correct it's just that our printer doesn't know what to do so the printer has to find the x-men we go from x-men to then we print these points are we still doing it still correct here let's try changing the y's no like 0 0 will become 0 0 and then if we fold it like this whatever is here will become 0 0 right and then this one will become minus y something so it is i think it is correct to do it like this just that there's a lot of a lot of points like y for instance right so here but why don't we have any we don't have any star on this part right why is it showing up in the let's say normalize this point to list of points normalize ps equals so we do x-men we do y-men equals to minimum map s and d ps and we do uh right to x plus x-men y plus y-men i don't think this should matter at all but what's happening now min e me xm equals is if x-men less than equal to 0 then 0 else a b s x-men i am prime if y-men less than 0 then 0 xm let's see this doesn't make there's something something very weird that i'm missing here so here okay xm if x-men less than equal to 0 then 0 oh if this should be larger than equal to 0 then 0 let me look at the out okay now these are all positive points right like missing i'm just not getting it this is the first time i'm just not getting it and now it's no longer given 17 for the example that's because we did it twice right print because like i'm saying it because it it works for the example right so we do put strln apply in str fps right and then maybe i'm kind of losing the empty part of the sheet of course like at the end none none of them okay so this is a instance of like how to mirror yeah i mean that's the thing right if i fold the paper like this and i fold it like not at the half some of them will end up on the other side right so they will be negative right so i think it's they should end it and negative are you have you done this to me because like uh we're just we're stuck okay so all of the positions where y is 7 this is an instance of reflection mirror line measure from point to the mirror line measure the same distance against on the other side and place a dot then connect the new dot so when the mirror line is the x-axis when there was a y-axis yeah i think that's also what we should be getting okay um well let's see here um this is it's going to be one f okay and it's going to take an int to let's take some int and int to an int f so mirror mirror n x equals undefined okay so if it's for the axis then we say where axis we do unsip a ps unsip ps so x is a comma ys so if it's the axis then we map mirror n over the axis sip wise same for the ys except then it's the axis sip with map mirror n ys now how do we mirror across a a point across a line what's happening nothing happening let me sec so how do we mirror uh across a line just type it up now i have to write some things okay and okay now we just have a unit interval your coordinate is defined by mirroring over the unit interval okay so i have um x and i have how am i supposed to mirror it okay so first of all we only mirror those that are on the other side of the line right i think that we have to do that case x less than equal to n equals x so if it's on the line or if it's um if it's if it's not on the line yeah this is what i have but it it is wrong it gives me the wrong result let's do the back then minus x i mean what i do is i run it it works for the example and then i run for the input and it just returns a lot of garbage output and it doesn't work at all and i'm getting a lot of negatives right so like what is it saying like okay if i so i think maybe it's just the instructions that are unclear okay so if i fold it like this does this become the new zero and does that mean that the new fold instruction is relative to this new zero and not to the old zero maybe that's just it okay then i just do um let's see no it works for the example let me see that's what tim thinks it is i'm implying it in the wrong order okay whoo fold along y equals seven and then fold along x equals five okay and then the input says fold along x and fold along where okay maybe if i okay yeah so it's not the wrong order it's uh yeah i was using the wrong fold right so it says fold left and then it works okay cool so it says e p said g k c h u e p said g k e p e p said g said g k c h u okay we have to wait 36 seconds okay yeah it's very annoying that they have the wrong order in the example and it just works right at least we don't have to normalize we don't have to find the x min and y min yeah i think it's yeah so initially we were like oh we should use the fold l because it says fold left but i didn't think of uh that it could be the yeah we'd but obviously yeah that's how it does it if you fold in the wrong direction they are uh the operations get applied in the opposite order okay we learned our lesson but it was getting very frustrating right for a while there all right but yeah because i thought the mirror was wrong somehow and i kept focusing on that all right let's say git status git at day 13.hs input example okay that was very frustrating and i didn't think of all let's try the different order so thank you to me again for saving us a lot of frustration again yeah i don't know this is also like one of those i don't know like last year i felt it was more um kind of you had to you had to do it get the computation correct like the data structures and stuff but now it's just like here you know it's just you don't do anything right i mean there's no okay i mean we we parsed right but like this was the solution okay there's no kind of awe we have to be very careful with how we compute things so it it's fast right it's just now it's all about figure out what to do so we're not really being we're not able to show off you know what what what we're good at and whatnot but okay thank you for coming today i'm gonna relax i've been working all day see you again tomorrow seven o'clock and enjoy