 All right Good morning everyone or a morning. Good evening. I Start these things at six o'clock and It's officially evening at six o'clock, right? Let me just Fix the white balance on my keyboard camera You know, I'm pretty white, but I'm not that white, right? Yeah, like here a little bit Like this this is better. Oh No, I Push default. Let me Free five six four we want Yeah, this is good, okay So What is today's problem, let's check it out also We've been getting a lot of followers and I think I need six more and then I will be a twitch Affiliate it's pretty cool, right? All right, let's get going. What's today's problem? Added of code six Wow We're getting followers on stream. That's never happened before and now you can see the alert Looks like a pro streamer, right? Anyway, so, okay, so we We had to switch we're going to okay We're going to the regional part and we switch to a much larger plane And we have to fill out the customs declaration forms. I love how they're kind of Leaning into the whole travel thing because you know, it's like 2020 nobody's travel So they're like we want to get you to get the full travel experience For data, okay, so 26 yes or no questions marked a through Zed All you need to do is identify the question for which anyone in your group answers Yes, your group is just you this doesn't take very long However, the person said next use is to be experiencing a language barrier and ask if you can help For each of the people in their group You Write down the questions for which they answer. Yes one for line example ABCX ABC Y ABC said All right. Thank you so much for the follow-ups everyone So For in this group, there's six questions to anyone answered just a B said a why and said Okay Another group as well you all truly Collect answers from every group on board each group's answers separated by the line within each group Each person's answers are on a single line Okay, so Five groups. Yeah Three people they answered. Yes question to people. Yes Okay, so you have to count the number of answers All right Let's check it out. So This is gonna be our test input And Let's make that day six dirt dirt day six Touch may not HS It's gonna be day six. Let's say Let's touch the testing profile this based input right here and Now let's go back to let's close the day five ones Too many setting day three day three Okay, main dot ages. No, we don't want that we want We want to call it Dave six Oh, no day six Yeah, like that and So let's start So usually because I have an Icelandic keyboard, but then I usually switch it to English because Like programming languages are written with English keyboards in minds. You can see my keyboard here, right? And it has like And right here. So so when I when I write, you know, I Write like instead of going like semicolon it goes I right, but then I switch to the English keyboard and it actually makes sense So, yeah, I was just always done that like since I started programming it's So much nicer It's like programming languages are written by people usually in the US or in the UK and they all have British or like they all have normal keyboards and and Which means that that's how programming languages are kind of written, right? So all the symbols are accessible from those keyboards and then like on an Icelandic you put you have to go And I don't want that RSI. So, okay. Let's say get input There's gonna be a file pack. It's gonna list give us a list of strings and What do we want to do? So Let's go let's go for a list of list of strings Let's we want like they want each group in one get input Fp equals So this is gonna be read lines And then it's gonna be line we're gonna get the lines from the read lines But then we're gonna want us we want to split those at spaces and There there is no function in data.list that does this which is It is so weird I'm thinking yeah, because there will be an empty line So let's just write the function split I'm gonna take an a to bool list of a's And It's gonna return us a list of a's so split when a Conned So on an empty list, we're just gonna. Oh, no, it's gonna take an a you're just gonna take a list of list of a's It's gonna turn a list of list of a's So on an empty list we just return on the list Split to when so conned a A's so if it is the case that conned a So I think so we can say so here we say conned okay We just say As let me see So this is gonna be take take a while So take while takes in the con and it like Takes a thing where okay, let's say here undefined So you guys all doing I think Yeah, so okay, so contest so take while Let's see Yo need a babe that is a great nickname You guys remember when it was hot girl summer like how not to be type theory summer That was a good joke Anyway Yeah, I'm doing good. Well Yeah, I think I have like slight Slight coronavirus symptoms actually But I haven't been seeing anyone So who knows maybe I'll just not finish the admins of code because I'll be dead But at least my final days were well documented And that's all I asked for right, okay, so Take while Let's see here T take while yeah, yeah, I'm perfectly perfectly fine. It's just a It's just how it is. Okay. Let's see. We actually don't want to take why we want span We didn't rewrite this function right before Let's say so here we're gonna have So so x and y I don't know how we were never we We we say this so let's say span con of AS so this is gonna be Suspan, okay, so it's I think it's break break does the opposite we wrote this exact function before But so we're gonna break on the console it takes until the con holds and And So, okay, so then we want to say here Case and why of So if we if we we ended up with the end to be the list when do we have everything So then we are gonna say Just the list that contains x Otherwise We will say x concatenate it to Split when con of and then we are gonna we're gonna say split when equals empty line So what is it complaining about? Do it in Oh, yeah, we have to We have to fmap this right We always had to fmap lines, right? But now it's saying What is it complaining about here, right fmap lines? Okay, and then we want to apply something here, right? So what does this whole say a List the string to any yeah, and then we say split when On equals empty list, right and this What is What is going on here? Empty that's going to be you know a list of strings to list of lists of strings and on empty is equal to split when Like this, right, and then we're On empty, right? Well, let's just let's just apply it later Wait, so this is gonna be list of strings, right? Maybe I'm fmapping wrong. Oh I Put in the argument here This is gonna be split to win and read lines read file, right? Read lines doesn't exist. That's why we had to use the lines operator. Anyway, so now we are Getting the input we're splitting it up And let's just see what we get. Let's see See if we get the groups to get input Uh Test input and to print We don't need this GHC day six side HS. Oh day six oh Day six and then we are gonna time running a six whoops That is an infinite output Now my terminal is completely frozen Shit Let us let oh no Let's just kill kill the editor and task too much memory that was crazy Okay Let's just Try it again What where did we go wrong? So? So so we didn't Okay a Maybe this is supposed to be oh I Think it's because we didn't we didn't take the first element of Of why so this has to be like so this is gonna be an element that satisfies the con like this Crazy stuff right? Let's say a six Can't wait until then and all right that worked See in Haskell Difference between infinite evaluation and something that actually works is just two characters, okay So this is the input and our our So there's six questions, which I would answer the SA B said x y duplicate answers so another group Okay So okay, so I'm just gonna put this stuff into a set Import data dot list no data dot set I am just going to Solution Fixing a list of list of strings So for each group it takes a list of strings We're going to And it's gonna return on it so the solution Of the stores It's going to be so we could use nub here But I think I think it's easiest to just say could just concat string So just wanted to be all one strings and then we say Import the set and I would say import Qualified data dot Set and then we're gonna say concat strings And we're gonna say set dot from the list and then we're going to say Length what is links actually do is like define generally Let's let's just look at data dot set Cuz it you know doesn't just have size Yeah, let's just say size it like makes more sense for set and Then we are going to it's gonna be set dot size and then we are going to print map Solution, what does it do 3 3 3 1 1 3 3 3 1 1 so it works for the test input So we want to sum it up Okay 11 Now let's do it with a real input see what happens Input and let's actually create the input new file And put Okay, and let's run it 6 6 3 3 seems reasonable All right We got the first one 20 minutes only this time Most of it spent writing split one All right, we're on the track so I hope my hoping like this set thing that we did is gonna It's going to help us do the second part very easily Let's see part two Okay, you notice that you misread one word in the instruction. You don't even try to find question which anyone answered. Yes You need to identify the questions to which everyone answered. Yes. Oh No Because we made this a set We very heavily optimize it for like anyone like for exists now it's gonna say for all So we need to We need to fix that So my question is like let's look at the input. Are they all sorted? No, they're not sorted Do So we're gonna have to do for which everyone answered Yes, okay Let's see Let's see here So what if we what if we take the input and we sort it so we take the input we sort it And Then we go like, you know check if the first one is in all of them and if it is in all of them It should be the first one in all of them, right because we sorted it So we take a list of strings this is gonna be an integer also to to okay So we have the strings there, okay, so we're gonna say Sort did equal sort stirs We're gonna import data on list not we're gonna put data on list. So we have the sort Okay, and then we compare so this was the very imperative algorithm You know checking ahead of all of the lists. Yeah, is it I think it's too It's a bit too imperative I'm wondering if we can like jitch Create some sort of data structure To do this, I mean, I guess we could like generate all the letters in the alphabet generate a set Put all everything put all of them In the set with like a counter and then check Check the counters for which the elements are synced but that seems Too much work So anyone have any good ideas about like a functional way to do is like I'm gonna get started on the non functional way But I wish I'm gonna I will I want you guys to Tell me if there's a Functional way Right. No, so what we can do what we can do we can generate sets from all of them and We really we only need to walk over the shortest string because And then we just check if if the elements in the shortest strings are our elements in all of the other ones Yeah intersection between all the sets that is good also that is cool But you see my approach right so we find the shortest string we check and then we check Okay, yeah, I think we could also just do intersection for all of them. Yeah, let's do it Thanks chat Let's see intersection Data that's it just fold intersections Oh and log and plus one. Yeah, this works Let's see. I Feel like cheating a bit. I feel like I'm cheating by This one word intersection But yeah, so if we just a map to the strings We map a set from list to the strings and This will return a list of sets And then you fold L Intersection And then we say Intersection on and that's the thing and then we need we need to have instruction with a what well fold L one Okay, why is this is gonna be set dot intersection and this is essentially what we were trying to do right We'll look at the first string and we check if it's the others are elements in it But this kind of just does that from the top So map Let's see Let's not map to do the sum Let's see Three zero one one one three zero one one one one. Yeah So I just think this is the answer. So what is the idea here? Let's just try it. I think I think it will work We did the second one. This is the shortest one so far. I I Think I should not ask Chad for help. I think it's I mean, it's not wrong, but like In the sense that Because you know people might have solved this already Because like I'm doing it way after everyone else and Then it's you know, it's a bit of cheating if they spent too much time thinking about it We got through the intersection, but intersection is exactly what I was describing, right? So I Check us to use fold L1. So fold L1 is essentially just fold L except it takes the first element As the initial element, which is exactly what we were thinking, you know, we were thinking let's walk over the first string And let's check if that is an element like in the rest You know in each of the other sets but that is exactly The same as checking if each element in that one is this is a member of the intersection of all the other sets So instead of you know going check for element in all the sets all the time It's way better to just check for it. Just compute the intersection of all of them and It just works All right. That was a short one today. I hope you're Sunday Progressing nicely. It's second of Advent Got two candles lit Or I did earlier these days they were they were like tiny candles. I don't have the proper Proper advent candles so I can't I Can't have them lit all day But let's see right. Let's commit this Yeah They six We want to add the testing put Six Yeah, this is the 2020 moving cup I got it. I got it for my birth. No, not my birthday. I got it for the valley Yeah, and I like that that's Let's see if you can guys can see it properly if I hold it all the way up here It's like the moving snow day That's what it's called in Icelandic the movement The movie. I just think he's just called the moving troll In English or something like that. Yeah, he's like he's not walking through a the biggest snow blizzard you've ever seen right and Oh my god Feels very on point for 2020. So But it's nice. Yeah, so I've been wondering also, you know, what should we do if we finish This early I because I wish that bit of code was a bit harder This year because like last year at this point We were writing this big virtual machine GitHub treat low advent of code 2019 Didn't want to search GitHub I wanted to search Google because Yeah, okay, let me let me just go to get up and find But like I Google is better at searching GitHub than GitHub is searching GitHub Because it is like it never finds anything that I want AOC 2019, right? So by day five over day six, right We were hard at work Ah When let me knock When did the int machine start? Because I think it was Yeah, here we already had the reader ray like we had the start of the int machine and Then on day three We were like writing Yeah, so like this is day three of Of Advent of code last year, you know, we were writing hundreds of lines of code a lot of 100 for 100 lines of code right day four I Don't know it seems seems like it was harder last year at least, you know like this This is the entire int machine. It's a hundred and five lines, right? And it was a lot trickier But yeah, I guess it will get harder Next couple of days I wonder what this is graphic will turn out to be I think it's gonna be like Santa Sitting on a lounge chair on this vacation island finally after we helped him through all the issues he had to deal with It's a very I mean he's just trying to get to this vacation island, right? but it's been a very Rough sort of going Right, it's been very He's had to do very computationally intensive tasks to get there Okay, not computationally intensive, but like you need to you need to know what you're doing Yeah, set intersection that was a trick and you know, this is This is just a one-liner, right? We could we could even like I mean yeah, we wrote this split one function, but We don't Like that's like a there's there is a library with that function somewhere. So we could have just imported that and then just like Boom We don't even use this sort of let's clean this up a bit. All right, so there won't be much more today But you can catch These sessions on YouTube I have a playlist there and You can like See the ones I've done so far and I think I Think this is a bit fun, you know, it's admit of code while while streaming is It's a It's like good for practicing interview questions, right because then you're not just sitting there writing you have to be talking about What you're writing, you know, it's so it's like a it is a skill you'd like to develop You know how to Talk about code while you're coding and You know, it's a lot of fun. So Let's see. Anyway, so here's the playlist of the video so far Yeah, you want to catch it and I think you know, I think this is fun, but of course It's all about you guys But yeah, I learned my lesson now there There's it's too easy if you ask the viewers. I think I also have very high quality viewers because like I post this on on on my Twitter and like my Twitter is Essentially just Haskell not okay, not just Haskell people but like functional programming researchers Right so you're I'm cheating a bit when I'm asking for questions asking for help right because Those people they know what they're doing you guys know what you're doing Anyway, that's gonna be all for today If you are here, I would like you to it'll be nice if you follow I need three more followers and Then I I Get to twitch affiliate And I think then they I can start selling subscriptions or something and then I can be like hey Use your free Amazon Prime subscription. I don't know. I Just I just think it's funny that I'm just sitting here writing Haskell code and People are Watching it. That's the dream, right? to just code all day and Be able to talk about it because like that's the thing with coding you can be a bit lonely sometimes but You feel like you can talk to someone It's a lot. Yeah, thanks, you need a babe That is such a great negative. Okay. I have to explain it to the rest of you, right? So there's this lemma in Category theory called the you need a lemma I thought this would take like an hour so we have we got time and it's called a you need a lemma and What does it say? It's arguably the most important result in category theory Now that's a big statement, right? So There's a lot of puns. It was a paper by Jeremy Jeremy all you need you need a What was it Jeremy all you need all you need to know about Jeneda By Jeremy Gibbons he gave this talk at ICFP and Man by Shulong Boiseau I don't know how to pronounce it. I Yeah, but Jeremy Gibbons He's the one who gave the talk. I think that's why I remembered and So you need a lemma is You can tell a lot about the person by the company they keep and That is essentially the you need a lemma the the you need a lemma essentially states that if you know everything about how an object behaves You know the object itself which is a That's my understanding of it, right that That and I recommend this paper I hope I hope other people can chime in If if I'm explaining it wrong, but like that's essentially my after we have watching this talk that's like That's how I understand that you need a lemma there that That the more that if you know everything about it's kind of like a Statement to saying, you know, if you know everything there is to know about something you know What that is so if you know Every way that thing relates to other things Like you don't need to know the thing itself you you have the thing itself in some sense So what is the statement for a locally small category C set up a lot of life is similar to f of a naturally in a said for sexy and locally small category, so So this is this is the like what you need and then this is the actual setting, right? So it's like How do you read this? It's like the the all the isomorphisms or all the all the morphisms From C to set. Yeah, I don't I'm not I don't need I don't actually know how to read this Excel is quite formidable leaders But let's say section two This is good content, right? Just us reading papers about that. You need a lemma That is my research Essentially, this is just what we do all day But okay. Yeah, I think this is a good This is a good idea It's like That's how we know Boolean functions. All right, so if I were to define so if I say here okay, and I Don't think we can write it with big letters. Let's say And let's say and so it's that's gonna take that's gonna take two bulls And it's gonna output something And if we say and so it's gonna be and let's just and prime so and prime Functions for the bullions, right? So we just write the truth table. We just say false false equals false and prime false true equals false and Prime of true false equals false and and prime of true Equals true and here we're essentially this is this is kind of the application of the you need a lemma We're saying I have defined this function in a case-wise manner for every single Input and That means we know everything there is to know about the function I think that is also like the you need a lemma somewhere hidden there. It's That's the trick like if you define something So and then we're looking at like at the category of booleans and this is the category of boolean pairs and And it's just so happens that We can define the function case by case by case basis that we can define every relation between every single object So in the category of boolean to boolean a boolean pair comma boolean to booleans and The you need a lemma essentially says that then you know everything there is to know about that function If you know how all of its inputs behave that is You know, it seems very obvious, but like the you need a lemmas proven formally, which is That's how I understand it, but I really recommend this paper by Jeremy and Shalom boy, so Hope I'm pronouncing that correctly You know, my name is a Mahdi as a pot. You should also Almost no one can pronounce that correctly So I try my best to pronounce names, but if I'm getting them wrong Please forgive me. I know how it feels, right? So, okay, let's see. Let's see This is section two. So and like this is I think Jeremy in particular. He's very good at this I really respect Jeremy as a researcher He he digs a lot into category theory and then he kind of extracts stuff from there and explains it for the rest of us This is what a Phil Waller did also like he did it with Monads, right? He was just like guys guys and gals, you know There is a Function like there's a concept here called Monads in math by Mahdi We can use it to model Computation and then we did that and that's why we have such a nice fancy way of doing computation in In Haskell because Phil Waller really explained it to all of us And Jeremy is doing this as well and like also Nicholas move Let's color Let's go Nikolas move. I think he's also in the same department. I think they're both Nicholas who this is not This is not him. Let me see a ICFP 20 18 This was a good conference by the way Let's see. What are the papers here? This is problem with being Icelandic like I remember people's first names because that's how we That's how we track each other But then I have a hard time with last names accepted papers Yeah, Nicholas who he works a lot with Matt Pickering Is gay Let's just feel the PDF. This is also a good paper. I think it's song or is a song or is a legend Okay, I think he showed up. I think he's like super young. He's like I'm gonna say 21 22. I don't know and he's like showed up First day of his PhD. He was on stage at ICFP 2018 talking about super cool like this stuff generic deriving of generic traversals and it's just like You just use it and it just gives you lenses for everything, which means you can just You know use any dredger structures super easily and he had like a really good talk I think he was using like emacs and he just showed everything live. That was a really good talk I like that talk and Songer, you know, you just have the right attitude Anyway, I think that's enough chat for today Check out Songer's papers. They're really good. Check out Nicholas and boo's paper. Oh, yeah, they're it. So he's at Bristol And check out Jeremy Gibbons papers. They are all Good papers the ones I've seen are all good papers, but maybe I only seen the good papers All right, and yeah, see you all tomorrow for day seven of Admit of code and maybe we'll have some more research. We never know We never know. All right See you all