Awenat brilliantly transforms a spreadsheet into a laboratory for information theory, turning the simple act of shuffling into a rigorous study of randomness. It is a masterclass in quantifying chaos through the elegant application of Shannon entropy.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Live attempt at Every Day I'm Shuffling (Director's Cut) by Karim AwenatAdded:
And welcome. Today, I'm going to live stream an attempt at a case called everyday shuffling by Karim Aouana. So, it's going to be a live attempt at the director's cut only because I played the original case before.
But, I'm going to do them both just for the sake of completeness. So, I've got them both here.
Um Do do do do do. Yeah, so uh Oh, look at this. It even tells you do do the round two case. Make the shuffles in lambdas. Skip level if you hate it.
>> [laughter] >> Okay, I have not read level eight yet, but we'll see. Win Flex complained it was [laughter] too long.
Okay. Uh well, anyway. So, I'm going to start over here.
Everyday shuffling.
Um Let's see. I I tested this a little while this case just got played in the UK round this weekend, but I tested a little while back. So, let's just quickly refresh my memory.
Uh This one is all about cards.
Uh we've had card case before. We can't play decent card game without being able to shuffle the deck. In this case, we've got two simple shuffles that most people will will already know. But, actually modeling them up maybe a bit trickier than you expected. However, for the sake of everyone's sanity as well as my own personal safety when I'm due on September, we've removed the stupidly hard parts. I might still release these into the wild though. Well, that's what I'm here for.
In each game, the deck of cards will start in the new deck order which can be found on the new deck and example sheet.
So, here we've got new deck order which is position, card suit name, suit color, and card value.
And then, we've got examples of what happens after cuts, but we'll get to those later. So, I'm just going to make this into a table.
Uh ba ba ba bum. And we'll call this T cuz I like short table names.
Uh and I'll just make that value.
So, I think card and value are really mostly what I'm going to be using. Okay.
Um ba ba ba ba bum.
Okay.
Your best friends in this game are likely to be sequence take drop, but it is perfectly solvable by a more model building approach. Nah, we're going to go go sell here.
>> [snorts] >> Until maybe we get to the director's cut. We'll see.
Text manipulation. Yes, good luck and have fun.
Uh I think note explaining uh [ __ ] That Yeah, that was my last Karim card case live solve. Anyway, all right. Uh we'll start with the levels and then we'll go to the bonuses. So, we're starting with the deck in new deck order, find the card at the given position. So, that should just be index T card by this numbers.
All [clears throat] good. Uh each game starts with a new deck in new deck order. The code C num tells us we're doing a cut C. Uh so, we're going to take num cards from the top of the deck and put them at the bottom of the deck in a single block. So, for this one, there are lots of different ways you can do it. Um you know, index and mod and things like that. But, um if say I'm interested in cutting the top 23 cards to the bottom of the deck, then I could do something like sequence uh sorry, sequence 52 less than or equal to 23.
That will give me uh trues all the way down to uh to card number 23 and then falses thereafter.
Uh and so, if I sort the list of cards by this, uh trues and falses sort in alphabetical order. So, false will come first then true. So, it'll just shift all the trues to the bottom of the pile.
Uh and so, Ba ba ba ba ba. I'm just going to make this a lambda right from the start.
So, I'll mark that as input. Uh and then, I'll say actually let's do T card also and make that part of the input too. Oops, move over to where we have a little more space.
Uh Just mark that as input.
Uh and then, we'll say um Oh, wait. I'll say sort by uh this by sequence 52 is less than or equal to Uh oops, sorry. Is less than or equal to um I guess we can say one times text after or mid or whatever. Lots of different ways you can do it. Text after this C.
Uh and hopefully, we'll find that we have what? 23 cards here. So, the jack of diamonds goes to the top.
Yes. And after another 29 cards, we should get that there.
Yeah, right here the ace of spades after 29 cards. Good. Okay. So, then that is my uh cut shuffle I think it's called or something like that. Um So, I'm just going to actually wait. I want I want these to be in the opposite order because then it'll be handier for reduce. Uh so, I'm going to rename this to uh cut.
We've got cards and cut and it does that. We say okay.
And we're going to call it cut. No, no. Wait. I think cut might be a reserved name or something funny like that. I've tried to call things cut before and gotten trouble.
Uh so, we'll call this I don't know.
SH cut.
Shuffle cut.
Uh so, then we should be able to say Oh, and actually, let's let's take this a little further.
Let's uh say if cards then T cards otherwise cards cuz then it'll make it a little easier to work with.
And that leaves the arguments not the ideal way around to be omitting the first one and not the second one, but whatever, I guess.
Um that seems to work.
So, now we can say index of shuffle cut that cut by that number.
And that works.
And copy down. All right. Okay. Level three. That was nice warm up. Let's perform a series of cuts as before start with the new deck in new deck order each time. Okay. So, this is why I wanted to um this is why I wanted to put the arguments in that order because now it'll be much more natural to feed them into reduce. So, we can say reduce uh from T card um this for now is my array and I'll update that to handle the flexible size in a second. And the function is SH cut.
Uh and that should do my shuffle as many times as I need and then we'll index on that by position six and hopefully get a two of spades. And we do.
Uh and now instead of this, we'll do to call of this three. So, it'll drop the blanks.
Uh and then, we should be all set on level three.
There we are. Okay.
Level four. Overhand underhand shuffling free.
We now move on to the overhand shuffle.
Each game starts with a new deck as before. Overhand shuffles are shown by S num one num two.
As with the cut, take the top num one cards from the deck. Place these to one side for now. Now, take the top num two cards from the remaining cards. What is the total found card value for this group of cards?
Okay. So, we'll regex extract from here /d+.
All of them multiply by one to convert to numbers. So, we're going to drop 38 cards and then take eight cards.
Uh so, we can And then, we want to sum them up. So, we'll take drop starting from T card.
Uh we will drop 34.
And then, we'll take eight.
>> [snorts] >> And then, we'll sum them up.
Comes to zero. Right? Oh, right. Cuz I'm doing the cards. I should be doing the values.
Uh okay. 51 looks good.
>> [clears throat] >> Happy days. All right.
Where are we? Level five. You now identify a single group, but we need multiple groups for the full overhand shuffle.
Start as in level four, take the top num one cards and put them on side. Then, take the next num two cards to make your first group. Then, take the next num two cards from what's left. That's your second group. Repeat until there's no cards left. Your final group may be smaller than num two. That's okay.
Find the total card value for each group excluding the num one cards. What is the highest total card value of all these groups?
Card values can be found in the new deck tab.
Okay.
So, we're going to drop 34 cards. Then, we're going to take group of eight and group of eight and then the rest will be two.
So, I think Just trying to think what is the cleanest way to do this.
Um So, what I want is I'm going to say if sequence Well, I sorry. First, let's just quickly regex extract from here /d+.
Uh plus one times one.
So, I want if sequence 52 is less than or equal to this, then whatever X. Those are the ones set aside. Otherwise, I want um round up of sequence 52 minus 34 divided by eight to zero decimal places.
So, I get 34 cards of X.
Okay. Well, I'm just going to just plow right through that, but never mind.
Then, I got a bunch of ones, a bunch of twos, and two threes. That seems good.
Um So, then I'm going to say let GPs be that and I want uh to filter uh T value where GPs is not equal to X.
Nah, wait.
One more closing bracket.
Um No, I guess I want to filter each stack.
GPs and T value where GPs is not equal to X.
There we go. Uh so, this is going to be to group.
Uh and then I want to group by uh take to group uh first column take to group last column uh sum.
And then 0 0 -2.
Uh I don't even need the minus two. I do need the zero so that it doesn't do an overall total and then I just want the max of that.
Cool.
Okay, happy days. Uh all right. Now, overhand all the way down. We now have everything we need to do the full overhand shuffle. Take the top num one cards as before and set them aside. This is now the bottom of the deck.
For the remaining cards, take the top num two cards and place those on top of the cards from the last step. Then take the next num two cards.
Okay, so we're going to Yes, oh so we're going to invert our groups. So, this is the last group, second last group, first group, and then the cards that got moved to the bottom. Okay.
So then, I think a quick modification on this will do the trick.
Um but first, I guess I need to pull these all together.
So, let uh skip me regex extract from here by /d+ * 1 uh and GP size GP SC can be 1 * text after this after colon.
Uh and then just replace all of these.
This is skip.
Um this is skip.
This is GP SC.
Good.
Hm, actually, let's be a little more disciplined and say uh cut is this and then we only have one reference, which makes it a lot easier to turn into a lambda.
Turn into a lambda in a minute.
So then, take cut, put it there, put it there.
Okay.
Uh and then I'm not actually interested in the two group bit.
I just want two groups.
Uh and I also want this to now be X. That's [snorts] going to be the first group and all the rest can be plus one.
Uh and then let's just output GPS and see what it looks like.
And we'll need to move it to fit it.
So, we get 34 ones and then some twos.
Eight twos, yes. Eight threes, yes. And two fours, yes.
So, then we just want to sort in the opposite of uh yeah, in the opposite of that direction. So, we'll do sort by uh T card uh by minus GPS.
And then we start with the two of hearts, then the ace of hearts, yes. And then should be the 10 of hearts.
And eight cards later, the three of hearts, yes.
And then the five of club, yes. The jack of hearts will be the next eight.
Yes. And then next eight is ace clubs to the eight. No, no, sorry. [clears throat] Then it's into the last 34. Okay, good.
So, now then that worked. So, now we're going to make this a lambda. We're just going to say lambda uh of uh cards cut uh wait, sorry. Have we used No, I haven't used cards. Okay, fine. Cards cut.
Uh I can kill this.
Um and then we're going to say if is omitted uh cards then T card, otherwise cards.
Uh sorry, that closes there and this one closes there.
Okay, and then we'll save lambda.
Uh and we'll call that SH. What is this one called? I don't remember.
Uh let's go Wait, it's the overhand.
Right.
Uh so, we'll save lambda, we'll call it SHOH.
So, then we should be saying index SHOH uh that cut by that number.
And we are. All right.
So, take that, put it over here.
Pull it down.
I just noticed the clues here. These shuffles are the same shuffles as in level five. Okay.
What are the clues are there?
Okay, how many cards are left over after the cut? How many groups is it split into? Work out the starting card for each group and go from there.
Sensible.
Any other clues?
Um the the thing I should have mentioned here, uh I didn't do it because of my approach, but um if you think about how the cuts work, uh any any cut followed by any other cut is just going to be a different cut. So, like you take five cards and put them to the bottom and then you take another five cards and put them to the put them to the bottom, it's the same as if you just taking 10 cards and put them put them to the bottom at the start. So, you can just like add up these numbers, I guess mod 52.
Um and then you get the equivalent of of just one cut, but since I had a a cut function, it was easy to just apply it two, three, or four times.
All right. So, level seven. Now, let's do multiple overhand shuffle shuffles.
So, this should be very simple.
So, we'll say reduce uh starting from T card uh through the array and I just like before, I'll do the two call trick just to ignore uh anything omitted and then we'll do SHOH.
Uh close and the index number is going to be the position, which is here.
And that works.
Cool.
All right, let's do bonuses and then we'll go on to the hard part. Which [snorts] suit appears most often in level one answers? Give the suit name.
Okay. Um So, we'll do XLOOKUP at group by uh right of this uh this rows 0 0 -2. So, that'll I'm always torn between a desire to just write formulas the way that feels natural to me, which is this is one block versus to be vaguely more helpful and educational, I guess. Since I'm not in a rush, let's be vaguely more helpful and educational and actually spill it out.
Uh so, the the inner group by uh that I was going to put the at on, uh is just counting how many of each uh suit occurs.
Uh the minus the zero means no totals and the minus two means it's sorted in descending order by the count. Uh and then I put an at on that, that just gives me the first symbol and then I want to XLOOKUP that in T suit.
Ooh.
Ah, okay, got it. Right. Uh so, we'll look it up in T card returning from T suit.
Uh I'm going to just do a uh regex match so it'll match partial.
Uh so, in other words, that looking up a diamond with regex just means looking up for anything that contains diamond, so it'll just match on the first diamond.
Uh whatever it comes to here, the ace of diamonds, I guess.
Um which will do just fine. So, cut that out of there, bring it over here.
Okay. Uh what single cut would bring the pack back to the new deck order after a C17 cut? Give your answer in C number notation. So, this is basically, if you take 17 cards and put them to the bottom, it's equivalent to taking uh 35 cards from the bottom and putting them on top. So, to reverse that, you take 35 cards from the top and put them on the bottom.
Um And then, if you do all the shuffles in level three excluding examples, what single shuffle would bring the pack back to NDO?
Uh so, this is one you can With my setup, it's not that hard to to do it sort of directly. Um So, uh da da da da da da da I'm trying to think.
You could think about So, you could quickly figure out what is the deck's position after all this. So, we could say reduce T card uh through two call all of these three uh and the function is SH cut.
And that'll give you where the deck ends up.
Uh and then you can just think about uh the number of cards you need to put to the bottom is the location of the ace of hearts, I guess.
Uh so, we could uh let's just copy that.
Uh so, we could XMATCH that against that.
Uh that would say 15 and put a C in front of it.
Um I think that's the right answer, but it'll be more smooth if I prove it first. Uh the alternative is you can do um So, first we'll do sum of I just get the numbers out, so we'll regex extract from uh I guess again from two call to drop the blanks.
Uh just /d+ um * 1 that gives 1337 uh and then we can take Basically, you want to think what can you add to this to get to a multiple of 52. So, equivalently you can say mod of minus that by 52.
That will also give you 15. And then you can put a C in front of that.
Um Yeah, it's I mean, this one is actually conceptually the easier one to to write and implement, I think. But this one is, you know, if you had 10 squillion of these or something like that, it's much more efficient to just add up the numbers. So, you know, highs and lows. Total card value of the answer cards in level six. Okay, so that's just sum of X lookup all of level six is here.
In T card, oops, card returning from T value.
Good. And then let's do a magic trick.
You ask the audience to name a card, any card. You then perform the shuffles below from left to right starting from the new deck order. Bottom card will be the card they named. Okay. So, for this, and I suspect I'll need this in the director's cut as well, I'm going to write a function that can do both cuts.
And that's just going to be Uh so, let's start with SH cut.
Actually, no, let's just do lambda.
Uh cards cut.
Uh I'm going to say if left of cut uh equals C, then SH cut.
Otherwise, SH OH.
Uh I'll probably need to make this a switch later. Should I just do it now?
Yeah, let's do it now.
So, let's slightly differently. Let's do choose uh search left of cut in CO.
Um sorry, CS even.
Uh and then if I need to add more letters here, I can do that. Um and yeah, then if it matches the first one, that's cut. If it matches the second one, that's overhand.
Uh That closes.
Oh, wait. Why are these brackets not colored? Come on. There we go.
Uh that closes the choose. And then I want to apply that to cards and cut.
Uh Did I do that right? I think so.
No, apparently not. Uh Oh, sorry. I missed closing bracket here. That's the problem.
>> [sighs] >> Uh okay. So then if I save lambda, uh Uh what do I want to call this? I want to call this, I guess, SH.
Just SH. Any shuffle.
Um fine. So then I want to do all these, so I want to reduce uh T card start through this array Are there any merged cells here? No, that's fine.
Uh and SH.
And then the bottom card is going to be the 52nd card, I guess.
Let's say index of this by 52.
All right. Okay. So, that's the original. That's the easy part.
Now, let's get on to the meat of this.
Um So, first I'm going to go ahead and name make this a table and also name it T.
Uh do that.
Um Slightly sloppy design the way I had my lambdas reference a named range in here, but never mind. So, I'm just going to copy my lambdas over. H O M Bring it in here.
Uh 20 is fine.
I don't need to create a copy.
Delete that sheet.
And then I'll probably need to edit them, so let's do that.
Yeah, just two. So, SH cut.
Edit lambda.
Should have some crazy big Yeah, there we go.
External reference. Just make that T card.
Save lambda.
And then let's do the same thing for SH OH.
Edit lambda.
Mm.
Boom.
Boom. Mm boom boom.
Okay.
Cool.
Save lambda.
Right. So, now we are ready, I think, to dive on into this one.
Uh good news everyone. For those of you recovering from my free key So, I think this is the same.
Uh hopefully you're all participating in the minute of C round two. You all already know how to cut the deck and do a simple overhand shuffle. Just in case some of you've had it too easy. Welcome to the director's cut.
Level eight kicks off with no new shuffling, just reusing what you learned in the main case. If you haven't already, you may want to think about converting whatever shuffling logic you have to a lambda as you'll be doing multiple shuffles from the get-go. If level eight freaks you out, stress you not, head on to level nine as it's unrelated.
Uh okay, yeah. So, we've got very hard, hard, stupidly hard and go away hard.
>> [laughter] >> Uh okay, I see Shannon here, so I guess this there's some entropy something going on here. Anyway, we'll get to that. Uh okay.
It starts with new deck order. Yes.
Yes. Good luck and have fun. Yes. Okay.
So, recap. Yes. Yes. Riffle shuffle level nine onwards. Okay.
>> [snorts] >> So, let's dive in. More magic tricks.
You ask an audience member to pick a card and place it in the deck. While they look at the card, you swap the top and bottom of the deck, so their card is now between between card 50 two Wait, what?
E.g., if they pick card 33, you'd swap the deck so cards 30 Oh, got it. Got it.
Got it. Then their card Huh? Okay.
Huh?
>> [laughter] >> Um What?
Okay.
So, both examples start the same way.
Card 33 is chosen. You make sure they put it back on top of cards 1 to 32.
34 to 33 1 to 32. Okay.
Oh, got it. Got it. Got it. Got it.
Uh fine. So, if it is after the ace of hearts, then we say tada and the position number.
And here, you lost the card.
Okay, so the dough is how far off?
Right. Okay, got it.
>> [sighs] >> All right.
So, So, um first things first is this this cut, uh which is not quite the same as a regular cut.
So, Okay.
Um Yeah, let's make that its own lambda.
Uh so, do SH cut.
Uh edit lambda.
So, I want to sort by So, let's just see. If I do sequence 52 minus this value here, and then I do sign of that, that will give me a bunch of minus ones, where I'm less than, a zero where I'm equal to, and a one where I'm greater than.
Is that the right order to then shuffle?
So, one then zero then minus one. Yes, I think so. So, let's just test.
We say sort by sequence 52 by this.
Uh and I have my minus that. All right, so we'll flip the sign of that.
Uh so, let's make it this minus that.
So, we get 34 to 52, then 33, then 1 to 32. Is that what it's supposed to be?
Where are we? 34 to 52, 33, 1 to 32.
Yes. Okay, fine.
So then I think we are good to proceed.
>> [clears throat] >> So, then I want to uh sort by T card by Oops, where's that gone? Sign of that.
That's my starting point for the deck.
>> [snorts] >> Then, oops.
I want to reduce that by all of these.
Uh sorry, just those with shuffle.
And then the question is where have things ended up?
Uh and the things I'm interested in are is it always the same card they choose?
Oh, no, sorry. It's the 33rd card, of course.
Uh so then I want to X match Where's my ace of hearts?
Yeah.
I want to X match this against that.
And I want to X match index T card by 33 against that.
Okay. And if I find that that this is one greater than that, then I do one thing, and otherwise I do the other thing.
And I guess the question is are they ever not in the right order? We'll soon find out. So, uh let uh new order be that. Um then call it AH lock can be X match ace of hearts against new order.
And trick lock can be X match index T card by Uh Then by 33 against new word.
And then we want to say if Well, no. For now, let's just say H stack cuz I want to do some visual inspection here. My concern is is it ever the case that like the ace of hearts ends up in position 52 and this one ends up in position one. Do I need to think about mod or is it just Do I just not need to? Not sure. We'll soon find out. Uh 48 and 49. Yes, that makes sense.
29 31. So, I guess the question is is this one always greater than this one?
And the answer is no. So, let's take a quick look.
All right. So, 33 17 just breaks.
Although, yeah, now here there's a That's a reasonable question. How many cards are in between? Are we taking from 17 to 33 or from 33 all the way wrap around?
Hm.
Let's see how it's worded.
Uh if you If you lose that card, return dough and how many cards between cards not counting either of the cards.
Just return the number between them whichever order they appear in. Okay, that is totally clear.
So, we're going to say uh if trug lock equals ax lock plus one, then return ta-da and ta-da dash and trug lock.
Otherwise, return dough.
Uh uh dash and absolute value of um h lock minus trug lock minus one.
And I guess I might need brackets around that.
And close the if and close the let.
I think that's good.
Let's see.
Ah! One more Ah, 50. Right. Okay.
So, I guess this is probably one where it's going from.
It's wrapping around. So, let's just go back to my numbers where I had them all spelled out. I can't Ah, right. Because I used the macros. Stupid. Never mind.
>> [snorts] >> Uh okay.
Just Uh let's grab this over here and just do H stack, H lock, and new or Sorry, and trug lock.
Uh ba ba ba ba ba And let's Yeah, 52 and one. Okay, fine.
So, hello.
Why isn't that Hm.
Oh, right. Okay. So, we do need to do Fine. Okay. So, the test is what's wrong then.
So, I guess it should be um H lock minus trug lock uh give me mod 52.
If that's equal to one, then that.
No.
Uh sorry. Other way around. Trug lock's the bigger one.
Or should be the bigger one.
There we go.
Did that break the rest? No. Good. All right.
Missed the edge case, but I'll take it.
Level nine.
We're on to the riffle shuffle now.
These are shown by the code R num.
We start as with the cut. We take the first num cards and hold these in our left hand. We hold the rest of the deck in our right hand.
You then alternate the cards starting with the bottom of the cards in your left hand. If you have cards left over, they fall on top while keeping their order.
After the series of riffle shuffles shown below, what card is in the given position? Okay, so R 34. 1 to 34, 35 52.
So, it's 34 then 52 then 33 then 51.
Um 34 first. Okay.
So, let's do this. We do sequence of 52.
So, I want 34 to be one, let's say.
I want 52 to be two.
33 to be three. This to be four.
>> [snorts] >> So, I guess in general the pattern I want is if sequence 52 is less than or equal to uh one times text after uh this R then actually Yeah, let's just grab this text somewhere. I'm going to use it more than once.
So, let um cut num be that.
Uh then we'll say if sequence 52 is less than or equal to cut num then I want I want two times cut num minus sequence 52 plus one.
So, at 34 that would give me one then three. Yes, that's good. And then otherwise, I want 53 minus sequence 52.
So, that That doesn't look right at all.
Ah, actually that's okay. Yeah.
Cuz after 18, I stop caring. So, the equivalent So, this has Oh, sorry. That needs to be doubled.
That needs to be doubled. Um So, that's two times that times that.
So, okay. Now, I have cards up to 36, which means that here it goes up to 35 in 18 cards. Yeah, and then it doesn't matter that these numbers get bigger than 52. So, that's fine. Yes.
Okay.
Uh so, then uh let's just take SH cut.
Edit lambda.
And we'll screw around with this lambda.
Um do do do do do do do do do do do do do.
So, we got sort by. Yes, that's good.
So, we're just going to add let cut num be one for now and then sort by and close the let.
Uh and then cut num is this.
Uh uncut.
Uh cool. And then here is my new and more complex sequence to sort on.
Oh.
So, then we'll save lambda as and this will be SH R for the riffle shuffle.
Uh and then uh I can take my general SH lambda.
Edit.
And if we're starting with an R then we can do Yeah.
SHR.
So, save that. And I'm just cleaning all that up.
And so, finally, uh we are interested in index of reduce of um T card through call of all of this three uh with >> [snorts] >> We just go straight to SH, I guess.
Uh and index by this position and it should be the two of diamonds.
It's not. Bother.
Uh okay.
Hm.
Oh, wait. Hang on. Hang on. Hang on.
Hang on. Hang on.
On. Bother. Uh if you have cards left over, they fall on top while keeping their order.
So, Oh, the first card down is 34. That's what I did. Okay. Um shoot.
Uh >> [sighs] >> So, let's do SHR.
So, do I just need to sort by the negative of that whole mad sequence?
Uh I don't know. Let's see what happens if I do.
Two of diamonds. What do you know? Okay.
Uh so, let's just do one test with the SHR of sequence 52.
Uh and on this riffle.
Okay. Just put it over.
Okay. So, I got 1 to 16 on top then 35 17.
Oh, wait. Oh, no. Sorry. Here.
1 to 16.
Then 35 17.
Okay. I think that's working.
A little uncomfortable that we just fudged it based on the example, but I think it's working.
So, put that in and carry on.
Yes. Okay. Level 10. I'm a shuffle channel. We're going to calculate the Shannon entropy of a shuffled deck.
Ah, the Shannon entropy is a standard measure of randomness in a data set.
First, we perform the shuffles shown.
Next, we find the difference between each card and the next card. If the difference is negative, add 52. Be sure to include the difference between the last card and the first card. You should have 52 values each between 1 and 52.
Count how many times each difference appears, the frequency. Take each frequency and divide it by 52 to find the probability. For each probability, multiply it by its own natural log.
Yes, probability times log of probability is the measure of entropy.
To get the Shannon entropy, you take the sum of all the probability times log of probability values. What is the Shannon entropy after the following shuffles?
Multiply by 100 and round to the nearest integer as your answer. Okay.
So, these are doing here, but never mind.
Uh So, so, so, so, so, let's do um reduce T card through to call of this three SH.
That'll give us some stuff.
Um and then let I guess ord be that.
And then the index will be xmatch.
Don't x Yeah, I want I think I want that. Yeah, let's just see. Uh perfect riffle shuffle.
Cards 27 128 2 Uh let's just xmatch this against T card.
Ooh, wait, 27 1 Is that what I said?
Uh 27 128 2. Yes, good.
The differences 128 are that.
Therefore, 26 lots of 26, 25 lots of 25, and one lot of 51.
Got it.
Okay.
So, in that case, I don't think I even want to start with T card. I want to start with sequence 52.
Okay.
Uh and then >> [snorts] >> I'll say let ord be that and uh I guess shifted ord can be sort by ord.
That's what I want to do. I want to Yeah, move the first one to the end. So, we'll say sort by sequence 52 equals one.
And let's just show me shifted order.
And that should bump everything along by 1 128 229. Yes, that makes sense. So, it's the bottom. Good. Uh so, then I want uh ord minus SH ord.
SH O, that's not the most helpful naming.
Uh and then I think I want that mod 52.
Should serve to do that. Yes, good.
Um then uh what do I want? Well, just call that diffs.
Uh and then I want to group by diffs diffs.
Uh rows 0 0 and then 0 minus 2, so and then we're not interested in this part. We're just interested in this, I think.
So, we'll drop the first column.
Um wait a minute.
Sorry. Here, drop the first column.
Uh and divide by 52. That's our probabilities.
So, then our entropy is sum of probs times ln of probs.
And we want to round 100 times entropy to zero decimal places.
Okay.
Uh I suppose we're changing the sign at some point here as well.
Didn't actually say that, but I do think you mean it.
Oh, sorry. No, no. We've got uh we forgot All right. Well, anyway, there's definitely a minus sign comes in here somewhere. I know that.
Uh so, I think it comes into the entropy calculation itself. So, we'll put it there. All right.
Cool. All right. Level 11. Can I stop now, please? No, honestly, like it's longer, but I wouldn't say any of this has felt uh you know, brutal in the way that some of [ __ ] for instance, felt brutal.
But anyway, okay. Let's arbitrarily say that anything above a Shannon entropy of 300 three before multiplication is well shuffled.
Uh okay.
Solid.
Starting from the new deck order, perform the shuffles below until the deck is well shuffled, then stop. If the deck is still not well shuffled after 10 shuffles, then keep repeating the 10th shuffle until the deck is well shuffled.
Find the Shannon entropy of the well shuffled deck and ensure your Shannon entropy isn't rounded or multiplied by 100 to get a whole number, then multiply this number by the number of shuffles it took to get there. What's the result?
Okay.
So, [snorts] All right. I have some ideas. First, I should probably just lambdafy this Shannon thingy thing thing thing.
Um So, >> [snorts] >> yeah.
Um All right.
So, everything downstream of here is calculated as that. Yes, it's fine.
So, let's say lambda of ord.
Let SH ord be that, diffs be that, probs be that, entropy be that, and let's just return entropy.
I think.
Um Okay.
So, we'll save lambda.
We'll call that entropy.
Ent for entropy.
Keep it tight.
Uh okay.
So, then I want to reduce sequence 52.
Um and I don't know. We'll need to figure out what the biggest number of shuffles we might need will be, but for now, let's say sequence 20, and we can make it bigger if we need to.
Um lambda A V.
Okay. So, I want to apply the shuffle. Well, I want to calculate the entropy.
I want to apply the shuffle.
Sorry. I'm going to calculate the entropy.
If the entropy is low, then stop and return the entropy times the step number.
Which really means the first thing needs to be if.
So, an input at a step here is either going to be uh a column of 52 numbers, 1 to 52 in some shuffled order, or it's going to be a single value, which is entropy times step number or whatever it is.
Uh and are we Okay, so we are rounding by Okay, fine.
So, we're going to say if row I'm going to Stop. Stop being noisy. If rows of A uh equals one, then just keep A.
Otherwise, uh we're going to say let NXT be um SH of A and index this by the minimum of V and 10.
So, that just means if V goes beyond 10, we just keep doing the 10th shuffle.
Uh okay. So, shuffle A by that. Uh and then we'll say if ent of A is greater than three 300 I can't remember what exactly I included in ent. Let's pause and check.
Um Yeah, so if we're going to Let me just double check quickly.
Rounded and multiplied by 100 to get a whole number. All right, let me just quickly check if there's anything up here for which I would require the unrounded entropy. Otherwise, we can just go on.
This is at level eight. Using two decks of cards uh each of which is in NDO and one on top of the other. Is the card on top of Yeah, fine.
On a single NDO, if you perform R26 10 times or this 100 times or this serves the highest resulting Shannon entropy.
Okay.
>> [laughter] >> Uh cool. Fine.
So, then the answer is I don't need Shannon entropy uh to be rounded. So, we'll say round of 100 times ent to zero decimal places, and then that'll just simplify things.
Save lambda.
Okay. So, then here uh what are we saying? We're saying Yeah, if the above 300 is well shuffled, define.
So, we'll say if ent A is greater than 300, then return ent of A times V, I think. Times the position number.
Shuffle five with Shannon Okay.
Otherwise, return NXT.
I have a bunch of closing brackets, I think.
Uh it turns out it's 1824.
It's not what I wanted.
It's probably [snorts] something times six.
Ah, wait.
So, that should be shuffle So, I did one two Right. Yes, yes, yes, yes, yes, because No, it says right.
So, [snorts] it seems like it wants me to say V minus one, but I'm not satisfied as why I would be saying V minus one.
Um Let's just output some debugging stuff that I can look at here. If I H stack it, then it'll still only have one row, and it'll still terminate the calculation. So, let's do index of uh this by V.
So, that says C23, which is the sixth shuffle.
So, 1 2 3 4 5 6.
Huh.
Oh, sorry. Sorry. Sorry. I see it. I see it. I see it. I'm doing ent of A, but I should be doing ent of NXT.
There we go. Uh okay, so now we're not multiplying by Ooh, wait. What?
That's not good.
Oh, sorry. Because again, it needs to be end of NXT.
Okay, there we go.
Um shouldn't really be calculating that entropy twice, so let's not.
Uh call it NXT int.
So, NXT int can be that.
Uh if that, then then just return that cuz we don't need to check anymore.
Uh oops, sorry. Uh times V.
Cool.
Okay, and then that should just work unless we need to up the number of turns it's going through some of the time.
Uh so, if any of these returns are split Oh.
Okay.
Well, I was going to say if any of these returns are split, I'll crank up the number, but none of them did, so it's fine. Okay. Um All right, you want to make the magic trick from level eight work more often.
For each of the games, limit the number of shuffles you do with 10 shuffles, you should average success 40% of the time.
Uh Oh, got it. Got it. Got it. You should average success 40% of the time. Is that right? Um do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do do That's yes, eight out of 20. Cool. Um Limit the number of shuffles you do with 10 shuffles, you should average success rate.
After how many shuffles should you stop to make sure you astound your audience at least two-thirds of the time across the 20 games?
That means you need 14 successes. Um Is there a smart way to do this, I find myself wondering?
>> [snorts] >> Um Hm.
Um I think I'm just going to do what happens after each of the 10 steps.
There might be a smarter way to do it, but I'm not seeing it right now. Uh so, we do sequence comma 10.
Uh and we'll take most of this.
But, I just want to say one, otherwise zero.
Actually, we can just therefore make it one big minus minus.
Uh and now, this should become take from here by this many columns.
Okay.
So, you sometimes lose even on the very first one. Okay.
Uh ooh, you didn't like that. Uh probably cuz I didn't lock some stuff.
Let's lock some stuff. Uh so, yes, that be locked. This should be locked. This should be locked.
Uh that's locked the way it should be.
That should be locked.
Cool.
Okay.
Uh so, then I need average of these.
And so, it looks like wow, you can only shuffle twice. That's pretty bad.
Uh but okay.
So, what was the question?
Uh for each of the games, limit the number of shuffles that you do.
After how many shuffles should you stop?
Really, only two? Yes, okay.
All right, using two decks of cards, each of which is in India, one on top of the other, what is the result after performing consecutive riffles of R50?
Okay, so I think I need to change SHR to not use a constant 52. So, we'll do rows of cards.
Um Ah.
Hm.
Okay, yeah.
Uh so, let's Is this if I do rows of cards, it'll break when cards is omitted, which is some of the use case stuff set up. So, let's do cards use will be this.
Uh and then we'll do rows of cards use.
Um Uh there and there.
And oh, this should be uh rows of card use plus one.
Anything else to change? No, I think that's good.
Uh I guess I'll just save it differently just to be safe. Uh so, we'll do SHR flex.
So, then uh equals reduce equals reduce uh V stack T card with T card.
Um Do do do do do do do do do do do do do do if sequence five R50 Yes, R50.
Um Uh SHR flex.
Uh and then I want the top card, which I assume is just index one.
Now, ah crap.
Um >> [snorts] >> Okay, well, let's check the basics, I guess.
Hm hm hm hm hm hm hm hm hm hm hm hm hm hm hm hm hm hm hm hm hm hm hm Uh so, I start with one.
Uh Let's do What am I trying to do here? Um Can't tell a thing from looking at that.
Uh so, let's do sequence.
Let's just do the whole thing as sequence 104.
That's not great.
What?
So, when I flex, these are the cards.
The cut is R50.
Not doing anything. That's not good.
I also broken it.
Uh if I guess Yes.
>> [snorts] >> Cards use, yes.
What the heck am I doing wrong? I don't know. Oh, hang on. Rows of rows of cards use. No, what? Ah, right, yeah. I remember now. I was copying and pasting rows of card use instead of card use.
Okay, so that would totally break that, and that maybe makes sense.
52 53 54 55 51 51 52 52 Yeah.
Okay. All right, so save lambda and save that rescues it. Uh sorry, no. What?
Save lambda, not save lambda as There we go.
Okay.
So, that certainly changes the answer.
There we go. Phew. Okay.
Just a silly mistake. Okay, on a single Indio, if you perform R26 10 times or S263 100 times or C26 1,000 times, what is the highest resulting Shannon entropy multiplied by 100 and round to the nearest whole number? Okay, I'm not going to take the bait of doing C26 1,000 times, because if you do C26 twice, you're back to where you started.
So, C26 1,000 times is definitely back to where you started. Although, just out of curiosity, let's see if we can handle doing it 1,000 times uh the dumb way.
Uh so, we say if sequence 1,000 uh then C26 uh and I want to shuffle I guess we'll allow myself to use SH cut.
All right, well, that was actually pretty much instantaneous, so no complaints. Anyway, okay, so uh what's the highest resulting Shannon entropy?
So, we'll do max of three things, which is going to be reduced T card.
Uh sorry. Uh entropy.
Uh I guess we want to just do it on sequence 52.
So, we're going to reduce that uh through Okay, R26 10 times. So, we say if sequence 10 then R26 uh and we'll do SHR.
And that's the reduce. That's the entropy.
And then here, we're going to say uh 100 times of S263.
And here, we're going to say 1,000 times, given that we know the answer, but I think we don't. Uh sorry.
Just make all of these SH.
Uh okay.
Go.
Boom. Perfect score. Very happy with that. Uh that was that was pretty smooth sailing uh for for a Karim director's cut, I was expecting uh it to be more traumatizing. Uh but, lovely case. Uh love the idea, like the you know, kind of where do you go with uh with shuffling, you think about all the different shuffles you could do for tricks, and then you think about how random are you actually getting it through the shuffling. Uh awesome idea for a case. Really enjoyed it. Uh even if it wasn't or because it wasn't, I don't know.
Because despite uh adjacent to it not being as hard as the last one, uh super fun case. Thanks, Karim, for that. And that's all I got for today. Thanks for watching. See you next time.
And in.
Related Videos
VALORANT's Latest 'Exclusive' Tier Bundle is Rough...
KangaValorant
17K views•2026-05-28
Flight Attendant Mocks Poor Looking Black Woman — Mid Air Announcement Exposes Her Real Power
SkyboundStories-b4r
184 views•2026-05-28
I FIXED My Friend’s Blown Turbo RX-8… Then Sold It
Cameron-RX8
134 views•2026-05-28
NewsWatch 12 at 5: Top Stories
NewsWatch12
1K views•2026-05-28
Simon Jordan & Danny Murphy deliver PREDICTIONS for Arsenal's Champions League FINAL with PSG
talkSPORTArsenal
6K views•2026-05-28
Botting is OUT OF CONTROL in Classic WoW (Again)...
SolheimGaming
108 views•2026-05-28
The "AI Job Apocalypse" is CANCELLED!
WesRoth
9K views•2026-05-28
STREET FIGHTER 6 - INGRID Story Walkthrough @ 4K 60ᶠᵖˢ ✔
RajmanGamingHD
12K views•2026-05-28











