Algorithms + Data Structures = Programs - Episode 142: 🇸🇮 SRT23 - Lake Bled & Bled Cake + Haskell, Rust & C++
Episode Date: August 11, 2023In this episode, Conor and Bryce record live from Slovenia while driving and review Lake Bled and Bled Cream Cake and solve one problem in Haskell, Rust and C++!Link to Episode 142 on WebsiteDiscuss t...his episode, leave a comment, or ask a question (on GitHub)TwitterADSP: The PodcastConor HoekstraBryce Adelstein LelbachShow NotesDate Recorded: 2023-06-18Date Released: 2023-08-11Lake BledBled Cream CakeMastermind Board GameGašper Ažman on TwitterRamanujan Numbers“Point-Free or Die: Tacit Programming in Haskell and Beyond” by Amar ShahLambdaDays 2023: Composition Intuition - Conor HoekstraC++17 std::transform_reduceC++98 std::inner_productC++98 std::equal_toC++98 std::equalC++98 std::plusHaskell zipWithHaskell fromEnumHaskell sumBQN LanguageAPL LanguageexactMatches Tweet from Composition Intuition Talkexact_matches Rust TweetRust Iterator traitRust str::chars()Intro Song InfoMiss You by Sarah Jansen https://soundcloud.com/sarahjansenmusicCreative Commons — Attribution 3.0 Unported — CC BY 3.0Free Download / Stream: http://bit.ly/l-miss-youMusic promoted by Audio Library https://youtu.be/iYYxnasvfx8
Transcript
Discussion (0)
We'll do it in Haskell first. Why not? Because we're a Haskell podcast, aren't we?
Uh, sure.
Secretly.
So the blood cake is a cream cake.
Alright, back to Rust. So the whole point of this...
No, no, no. You can't tell men. It was a mallard duck.
The ones that don't have the shiny green heads are the moms.
I didn't have my glasses on, so it was a blob.
Are we going back to Rust?
Alrighty. Let's get back to Rust.
They know that I would never do anything to stress out or offend some waterfowl.
To get back to why Rust is so amazing.
Welcome to ADSP The Podcast, episode 142, recorded on June 18th, 2023.
My name is Connor, and today with my co-host Bryce, we record live on the road from Slovenia during our Slovenia 2023 road trip.
In this episode, we review Bled Lake, Bled Cake, and solve one problem in Haskell, Rust, and C++, and talk about why Rust is so awesome.
We are back, and we are finally in Slovenia.
Listen, folks.
Bryce is not bringing the adequate amount of enthusiasm
to the Slovenia 2023 road trip.
Depending on how the podcast got edited,
this might be in the middle of a podcast where Bryce got lost because a cycling race messed up
our directions. So bring it back here. Bring it back here. Or this might be the start of episode
two or episode three. We don't know. But guess what, folks? The last two episodes or one and a half episodes were live from Austria.
Now we are in Slovenia.
It's beautiful.
Guess what?
We're the number eight.
Last time we checked.
Technology podcast in Slovenia.
We're here.
We made promises and we delivered.
We just got finished at Bled Lake.
We had some Bled cake.
Apparently, we're taking a right-hand turn.
I'm pretty sure we're taking a right-hand turn. I'm pretty sure we're taking a...
I don't think we're taking a right-hand turn.
It says we're going left in five or six minutes.
Nope.
You have made a tactical mistake.
Don't listen to that because that's going to take you...
No.
Yeah.
I can't tell how bad the mistake is that you just made,
but we just went from an ETA of one hour to one...
Holy shit, I added
23 minutes? Hang on.
Dude.
Get off here.
Dude,
you're so fired.
It was set... Did it not say
go left 500? Yeah, yeah, yeah.
No, no, no. I agree it was unclear. Oh, 500? Yeah, yeah, yeah. No, no, no. I agree it was unclear.
Oh, look.
Yeah, yeah, yeah.
So it just wants us to go back.
So it's only out in six minutes.
Sure, yeah.
It's supposed to 30.
Anyways, folks.
How do we get out of here, though?
I don't know.
You figure that out.
It's a truck stop.
It can't be that hard.
So apparently it's very hard to find a grocery store on Sundays in Austria.
And also they told us in Austria that we had to get this little sticker thing to go into Slovenia. And that they told us every gas station will have a little sticker.
Well, Connor, did every gas station have a little sticker?
No, but we only went to one gas station.
No, we went to two gas stations.
They both told me no sticker.
Is that true?
Yes, they both told me no sticker.
We went to the Shell and what was the other one?
The other one earlier.
Oh, the Turmoil.
Yeah, the Turmoil.
Yeah, that's right.
Get it?
Turmoil.
We love you, Austria oh man we the the the drive the
part of the drive where we cross from from austria to slovenia you're you're driving in between like
in this this pass between these two mountains and man that was some of the most gorgeous uh driving that i've ever been a part of it was quite beautiful i mean i've also
done yosemite i've also done switzerland but it's up there it was it definitely felt like we were
in a mazda commercial there were 270 degree angle turns it you know it was i think more intensive
than yosemite and that's like i think prior to this, the, the, the sort of
wildest drive I've ever done, you know, and we were talking about this a little bit earlier.
I got to wonder like, what's it like to be the guy who designed or the guy or girl, the entity,
an entity who designs roads. What's it like to be a road engineer like like you you you come to this
mountain pass and you're looking at it and like what what like expertise were you taught where
you're like you know what right here we're gonna do like a 270 degree turn and then another 270
degree turn and then another one and then like we're gonna do like this weird thing here like
how do you like let's look at the mountain and be like yeah that's that's what we should do
that's exactly how this should work it was a little uh uh you wanted to nope nope you have
made a mistake again oh you're man do not give me the mic dude you bryce telling me i made a mistake
almost got me to drive straight into oncoming traffic.
This guy, he's like, don't worry, I won't make you drive the whole thing.
There is no way we're letting you get behind the wheel, man.
I'm definitely.
You were like going the wrong way.
Okay.
Maybe.
You almost made me go straight into oncoming traffic.
Maybe you are correct.
Jeez Louise.
Romana yells at me about this too.
I tell ya. All right. traffic maybe you're correct jeez louise formana yells at me about this i tell you all right so
um so we drove through this mountain pass and it was beautiful and then we got to the uh the lovely
town city of bled and uh what did we do in bled we don't i dove multiple times into the water
we swam a couple little baby ducklings, a couple ducks.
It was actually just a mom duck.
We don't know what happened to dad.
It looked like it was a solo mom duck.
Maybe it was dad and no mom.
No, no, no.
You can't tell men.
It was a mallard duck.
The ones that don't have the shiny green heads are the moms.
I didn't have my glasses on, so it was a blob to me.
How do you not?
Man, you do not need glasses to be able to tell a female duck from a male duck.
And that was definitely Mom
with her two baby ducklings.
And Bryce got a little bit too close a couple times,
was upsetting the baby ducks and Mom duck.
Excuse me.
I was keeping a respectful distance.
It was Connor who wanted to go over to them
in the first place and was bothering those ducks.
I was not bothering any ducks.
We love the ducks.
Look, my followers know that I love waterfowl.
They know that I would never do anything
to stress out or offend some waterfowl.
I know how to say,
Ja lubię kaczka,
which means I like ducks in Polish.
We're not in Poland,
but I don't know how to speak Slovenian,
so that'll have to do.
Slovenian listeners,
I apologize for Connor.
Look at this nice little river here.
Oh man, look at these mountains.
I gotta say, look,
our Austrian listeners,
we love you dearly.
You have a beautiful country.
We had a great time in Vienna.
However.
However.
We're in Slovenia, baby, and it's way better.
It's true.
That once we got through the pass, once we came out of the tunnel,
the border is in a tunnel,
and once we came out of that tunnel into the Slovenia side,
it was a lot better. Let's do a, uh, let's do a live review of the
after we swam with the ducks in the beautiful electric blue blood lake. Highly recommend.
We then went and had, we almost forgot we were supposed to have the blood cake and we're looking
for gelato and ice cream. And then I was like, wait a second. I saw some guy eating what looked
like blood cake. And I was like, we forgot we went and had it. What's your review, Bryce?
Well, so the blood cake is a cream cake.
The base is sort of like a light, fluffy, some sort of custard something.
It's definitely got agonist.
I'll tell you that.
And then there's a layer on top of it of, I think it's probably whipped cream.
And then on top of it is like a flaky, a layer of like flaky pastry crust.
Yeah, yeah.
Like pie crust.
I don't know if it was like pie crust.
It's more like, it's a lot flakier than pie crust.
All right.
I think.
And then a little bit of powdered sugar on top.
So first of all, let's break this review down into a few pieces.
So first, let's talk structurally.
So the bottom two layers, they're a little jiggly and don't really have shape.
And then on the top, you've got this, like, pie crust layer that you kind of got to cut through.
And that was a little challenging.
Wow, look at those mountains there.
Wow.
Damn. Wow. Wow, look at those mountains there. Wow. Damn. Wow. We'll take pictures for you, dear listener. What Bryce is trying to say is that dessert lacked structural integrity.
Yeah, but in terms of taste, it was not a heavy dessert. I'll say that.
It was a little sweet.
I didn't find it too sweet.
But, you know, I'm not a good judge of that.
Bottom layer was, it was good.
It wasn't maybe my favorite flavoring.
But, you know, it was light and sort of refreshing.
So I would maybe give it a 6 or a 7 out of 10.
What do you think?
Why are we doing this out of 10?
It's out of 5.
3.5 or 3 out of 5?
I would give it a 3.7, 3.8 maybe.
All right. You heard it here from Bryce.
3.7 or 3.8 out of 5 connor's review 5 out of 5
yeah you might be thinking why is this a 5 out of 5 well that's because upon looking at this
bled cake this cream cake if you will i thought to myself one thing and one thing only there's no
way in hell i'm gonna like this because i don't don't typically like, you know, I hate custards.
You discarded a whole donut earlier.
That's true.
Just because of that crack.
I had to get my Austrian donut because we were only in Austria for like 24 hours.
And so I bought one.
It looked like a sugar donut.
It turned out it was a vanilla donut, which is like a sugar donut.
But it was a donut with a hole in it sugar donut but it had it was not it was a
it was a donut with a hole in it yet somehow they put cream inside the donut and i don't like cream
in my donuts i was just about to say now you listener might be thinking what is connor talking
about you know he clearly you know if a donut's got filling inside because if it has no hole in it
no hole but this donut it looked like a regular donut
it had a hole i was surprised to learn there was cream in it yeah but anyways back to the blood
cake yeah so uh back to the blood cake so anyways i don't like i don't like multiple textures
especially jellies inside of things i hate custards if you are in a country like america or canada
and you know what costco is you know that they have these Costco cakes.
And I'm sure this is in other countries in the world.
And instead of having like icing on the outside and icing in the middle, it's icing on the outside and custard in the middle.
I hate custard in the middle of my cakes.
And so I took one look at this blood cake, and it looked like custard on the bottom, some kind of whipped cream in the middle, and then this flaky thing.
And I thought to myself, the only thing I'm going to like about this is the flaky thing.
And it turns out it was fantastic. The custardy thing didn't taste like custard at all, at least
not the cheap stuff that you get in the Costco cakes. It was light. It was lovely. The whipping
cream like thing, also super light. Didn't really taste like much. So like it's five out of five
because I liked it, folks. Not because it is as good as anything I've ever tasted. I was just, it was delightful.
Bryce finished his in about a fifth of the time that it took me to finish mine. But overall,
five out of five. Would recommend even if you're thinking, you know, this doesn't look like it's
for me. Surprise yourself, folks. You got to always be willing to try things.
Put yourself outside of your comfort zone.
That's what I'm all about here on ADSP, the podcast.
I'm all about taking this podcast on the road
and putting myself outside my comfort zone.
Boom.
All right, what are we talking about now?
Are we going back to Rust?
All righty, let's get back to Rust.
All right, so we were...
Mike.
I have all the power now.
Yeah, but you're just providing a bad audio experience for our listeners
if you don't put the mic when the person's talking.
So Rust, we were talking about Rust earlier.
We were doing a live version of Mastermind.
Should we resume that?
No, I do not.
I think that we do not need to torture the listeners
with me failing to crack a code.
But depending on how this gets edited,
I kind of messed up because initially I actually described the problem
as using the digits.
Oh, man.
Look at that.
Wow. Damn. Damn. It damn damn the rockies folks these are some
beautiful mountains and uh and i think we're heading up into them uh we should say i do not
think we're driving up there that around them we should say the way, our entire itinerary for this trip was gifted to us
by our good friend Gaspar, who is from Slovenia. And we asked him for some recommendations. And,
you know, if he'd sent back, you know, oh, go to maybe check out this restaurant and do this or
that, you know, we would have, that would have been enough. I would have, you know, we would have checked it out.
Maybe we would have done some of the things.
But that's not what he provided us.
No, he gave us a detailed plan.
Itinerary.
Itinerary for what we should do.
And, you know, when somebody gives me that, my gut is just to be like, you know what?
We're just going to go with that.
And so that's what we're going with.
And thus far, it is not disappointed.
Not disappointed at all.
It's been fantastic.
Gasper, we love you.
Thank you.
We love Slovenia.
We love the Slovenians.
And for those of you that don't know Gasper,
he's a member of the C++ committee.
And so C++ developer.
Does he work at Citadel with?
He does work at Citadel, yeah.
I wasn't going to say because Barry works at Jump. But anyways,
Gaspar Asman, we'll put his Twitter
in the show notes. If you want to go give him
a follow on Twitter, show him some love
for the love that he's shown us by giving
us a little itinerary to tour through
his country. It's been great so far.
Yeah. And back to Russ.
Enough about C++. So
we don't need to resume that Mastermind
game. This might be the same episode, might be a different episode.
What a reprieve for me.
Yeah.
That I don't have to embarrass myself.
If you've been waiting for like a week or two, though, to know if you guessed the code correctly,
the code was the first Ramanujan number, 1729,
which technically violates the initial rules that I set because Mastermind has eight colors,
and I said we'll use the numbers one to eight,
and nine is not in that range.
And then at one point you asked,
is zero a valid digit?
And I said yes,
and I realized we were now playing ten-color Mastermind,
not eight-color.
It's all right, though.
The point is,
you got the gist of how that game works,
and ooh, look, some motorcycles passing us.
I gotta say,
lovely country, lovely people thus far
minus all the people on the motorcycles as a former actuary uh i just want to let all the
folks know you should not drive motorcycles if you are concerned about mortality risk that is
for those that are not informed of the actuarial terms the the risk of dying, which typically most people are not.
They're pretty not interested in dying.
And if you are interested, you are 80 times.
That's 8-0 multiplicatively.
We're not talking 80%.
We're talking that's like 800, no, 8,000, 8,000%,
a.k.a. 80 times more likely to die on a motorcycle than you are inside a vehicle.
Also very likely to die inside a vehicle.
But my point is, it's not very safe.
I understand why people are doing it, though, because it's very beautiful to zip through these mountains, the views.
Anyways, back to Rust.
So 1729, the first Ramonajan number.
We love it it even though
we violated the problems but you should get the gist of when bryce would guess and he got exact
matches the right number in the right place or the right color in the right place that is a function
that was shown in a talk called point for your die which i borrowed and then basically replicated
and solved in both uh haskell and i believe bN, or maybe it was APL, in my composition intuition
talk. So you can think about this function. You're given two strings. In the classic example,
it's like letters that represent the colors. So like blue, blue, green, green would be BBGG.
That would be the code. And then your guess might be blue yellow green red so b y g r so you
got two strings bbgg and bygr and you need to return a single integer value given these two
sequences these two strings that returns the number of characters that match exactly in this
string so you're not you're not worried about the ones that aren't exact matches. This is just a function that returns you
the number of red pins that you would have done.
So in
Haskell,
we'll do it in Haskell first. Why not?
Because we're a Haskell podcast, aren't we?
Sure. Secretly.
Haskell.
Give me the mic back.
I'm not
sure if we should. I'm not sure if we should.
I'm not sure if we should subject our users to Haskell.
So Haskell, this is a...
Well, actually, how about you?
What would you do to solve this?
We'll do it in C++ first, and then we'll do it in Haskell.
How would you do this?
So it's a function that takes two strings.
They're length four, but you could arbitrarily solve this for any length strings
or, you know, sequences or ranges.
And you want to check how many are equal
and return that number back.
So for BBGG and BYGR,
you're going to turn back two
because the first B matches
and the first G matches.
Nothing else matches.
But this is just checking whether they match,
but not necessarily whether they match in place.
No, it's making sure that they match
exactly in the right positions.
Hang on.
I think we just made a tactical mistake.
Oh, yes.
Wasn't looking at the directions.
We are now four minutes slower, but it's all right.
We're going to do a little U-turn at the next round.
All right.
So this function, okay, so just go.
This one is just checking whether these match.
It's not whether they're in the right place.
Correct.
So an alternative example is
if you don't want to use characters
because that's too confusing,
if you have the sequence 1, 2, 3, 4,
and 4, 4, 4, 4,
your answer is?
You're supposed to guess what the answer is.
The answer is 1.
Because you've only got one number
that matches the sequence.
If you're given the sequence 1, 2, 3, 4,
and 2, 2, 4, 4, your answer is sorry one two because all right but if it's like
two two four four and four four four four um two exactly yeah so you're basically just doing an
element wise comparison and counting how many of these oh exactly. Okay, I guess that's...
You've given away
what you want to do there, which is
I guess you just
I mean, you could just do like a
Play along, listener. Play along, listener. I mean you could just do like a uh play along listener
play along listener
think about it
first let's zip them
and then um
uh
and then we'll do a
a reduce with
uh no I guess I'm to need like a transform reduce. Um,
yeah, I guess it can just be like a binary transform reduce, right? This is the binary
transform reduce where your, um, where your transform just compares whether or not they're equal and returns 1 if they are and 0 otherwise.
And then your reduction operator just sums.
That is absolutely correct, Bryce.
Except for the fact that in C++ we have...
Huh?
Two words.
One starts with an I, and one starts with a C.
Implicit conversions.
And therefore...
I mean, you can...
Yeah, sure.
You can just use a comparison as your first function.
It doesn't need to be a
custom written function. It can just be equals and reduce your first function. It doesn't need to be a custom written function.
It can just be equals, equals and reduce.
Exactly.
Not equals, though.
Equals is an algorithm.
Stood equal to is your binary operation.
Sure, equal to, yes.
Ooh, a little waterfall here.
Ooh, that's nice.
Yeah.
But that is, it's beautiful.
You can solve this in a single line, transform, reduce.
Your first binary operation
That's going to do the zipping is equal to stood colon colon equal to your second binary
Binary operation is stood colon colon plus and you're done. That's it
So it's a transform reduce or an inner product and C++ in Haskell
You don't have a single algorithm for this so you're going to do a zip with
which is the equivalent of our zip transform and C++23 with range adapters, and you're going to provide it the equal equal in order to do an equality comparison, and that's going to return you back trues and falses.
You can then either map from enum.
I just don't want to hit these bikers here.
You can map from enum, which will turn your booleans into integers because Haskell does not have implicit conversions.
It's also not hit the car.
Yeah, that's good.
Oh, there's another waterfall.
Wow.
Beautiful.
And then you just do a sum after that.
So why did we go through all this, you know, solving it in Haskell,
solving it in C++?
It's because three hours ago,
or whenever the last time we were recording back in Austria,
we were talking about Rust
and why it's so awesome and how the
tool chain
and the ecosystem and the experience.
Wow, look at this lake. It's so beautiful.
It's a pretty nice lake, yeah.
This entire series of podcasts
is just going to be...
Talk, talk, talk, talk, wow!
Talk, talk, talk, talk, wow!
But so, in Rust, I tweeted something.
What's this person doing?
They're parking there.
Go take a little walk.
Go take a little gander.
Yeah, we don't have time for that.
We are not late, but we're're not we're not not late all right back back to rust so the whole
point of this one hour including the blood cake reviews the blood reviews the restaurant reviews
was to get back to why rust is so amazing so someone posted on Twitter when I think I, I, I screenshotted a,
uh, slide from my composition intuition talk. And I said, this might be one of my favorite slides.
And it showed a couple different solutions. The one in, uh, Haskell Q maybe C plus plus,
and then like BQN or APL. And someone commented, Oh, like, you know, wait until, you know you know or like or rip rust or something like
that like you know rust doesn't have a good solution for this and i was like oh let me go
let me go pound out the solution to this and rust and i knew immediately though i was like ah this
is with strings though and i do not know rust well enough i have not mastered the string types
they have like they have a lot of them, yeah, they've got like the library string. Then they've got the language string slice and, and there's a bunch of other string
stuff. And I just, I can never know. I never know which one you're supposed to use, but I,
I coded up my function in the Rust playground and, and then what happened? Then basically,
uh, I did it with string slices, which is the ampersand STR.
And I did that and immediately started trying to call iterate or like iter functions, the ones that implement the iterator trait.
And that was a two lane road.
Yeah.
OK, let's make sure.
And basically, you can't do that.
So I was trying to do it with a zip, a map, and like a sum,
and immediately, you can't call zip on a string slice.
But what does, take a guess at what, you're not going to know,
so I'll just tell you.
But I mean, the rest of the listeners will know what the compiler tells you.
The compiler says, unfortunately, you can't call,
you know, the string slice doesn't implement the iterator trait,
call.cars.
It tells you exactly what you need to do.
There's no like, hey, this might be what you want.
It just knows if you're trying to call this function that requires the iterator trait
and you're working with a string slice, it just goes ahead and tells you,
hey, you need to go call.cars before you can call.zip, and you're good to go then.
Okay.
Why don't they just make calling.zip on it work?
Hey, that's not the point.
The point...
I don't know.
I want an answer to my question, Connor.
I'm not a Rust expert.
I don't have the answer.
My point here though is that like,
you know, when you're starting with C++
and you do something with, you know,
something you're not super familiar with,
you're just going to get a mess.
Whereas in Rust, you do the wrong thing
and if they think they know what you're supposed to do,, you're just going to get a mess. Whereas in rest, you do the wrong thing.
And if they think they know what you're supposed to do,
they just tell you.
And it's, I almost swore.
I almost swore.
Kids, don't swear.
This is not a family-friendly podcast.
Yeah, there's a few times you swore and I had to mark it explicit.
So I think our podcast is now marked as explicit.
Anyways, point is...
Whoa, whoa, whoa.
Episode one, you said,
we said that this was not a family-friendly podcast.
You said that we could swear.
I think I bleeped out your...
I used to put, like, duck sounds whenever you would swear for a long time,
and then I got just tired at one point.
Anyways...
So, now you've been marked as explicit?
Yeah, I think at, like, episode, like, 120 or something.
Oh, my God.
Damn.
Now, do they do that...
Do they do that automatically?
Like, they just detect it, or...?
No, so you mark your own episode as explicit,
but I think once you mark one episode as explicit,
the podcast in general gets marked as explicit.
Well, now people can't listen to the podcast with their kids.
I would actually be interested...
You know, we joke about it,
but if there is anybody who listens to the podcast
with their children in the car or something,
let us know.
We can censor ourselves.
But yeah, point is is rust is awesome the folks that spend time making the beginner experience fantastic you're doing great work i would go and open up the github repo and you know
leave a smiley face but uh we're on a very windy road on the side of a mountain. Very windy road. And we're doing our best not to get in a car accident.
Very windy, narrow road.
Yep.
Oh, I mean, you're a little, okay.
All right.
When there's a car next to me, we're going to drive a little bit off.
You know, at least we're not on the outer edge.
Yeah, okay.
Look at this guy.
He's like, you know, he's in my lane.
You know, I got a, I'm either going to hit him.
Dude, there are not lanes on this road.
There's a faded dotted line.
Yeah, yeah.
Sure.
Anyways, that wraps our first episode of being in Slovenia.
I mean, did we just wrap?
Damn.
I don't actually know.
Look at that mountain.
Wow.
And look at those mountains.
Is that snow?
Yeah.
Wow.
Damn.
Well, I wish you all could see this, but this is a podcast, so not the best format for...
Slovenia, 2023 road trip.
Yep.
Be sure to check the show notes either in your podcast app or at ADSP the podcast dot com for links to anything we mentioned in today's episode, as well as a link to a GitHub discussion where you can leave comments, thoughts and questions.
Thanks for listening.
We hope you enjoyed and have a great day.
Low quality, high quantity.
That is the tagline of our podcast.
It's not the tagline.
Our tagline is chaos with sprinkles of information.