I got the idea for this from a conversation I had during lunch today: talking about how many shuffles it would take to get a deck of cards to it's original state. So I made a program to simulate that.
I added some human error, so if you can imagine that you've got half of the deck in each hand, your thumbs holding back the cards, about to shuffle: a random number of cards (0 to 4 I think) is chosen to be taken from each half each time (ie, 2 from the left half, 1 from the right half, 3 from the left, etc.).
I ran this to 100 million shuffles, and it took 22 minutes, so if anyone has a blazing fast computer and wants to run the program until the deck gets back in order, please do.
If anyone doesn't understand how it works, or what a certain part does, feel free to ask.
public class Shenanigans
{
private int [] deck = new int[52];
private int count = 0;
private void fill()
{
for(int i = 0; i < deck.length; i++){
deck = (i + 1);
}
}
private int[] separate(int startIndex)
{
int [] half = new int[26];
int j = 0;
for(int i = startIndex; i < startIndex + 26; i++){
half[j] = deck;
j++;
}
return half;
}
private boolean more()
{
boolean more = false;
for(int i = 0; i <deck> 26){
rand = (int) (Math.random() * 4);
}
return rand;
}
private void shuffle(int [] first, int [] second)
{
int card = 0;
int i = 0;
int j = 0;
while(card < 52){
int rand = getRand(i) + i;
while(i < rand){
deck[card] = first;
card++;
i++;
}
rand = getRand(j) + j;
while(j < rand){
deck[card] = second[j];
card++;
j++;
}
}
count++;
}
private void print(long time)
{
System.out.println(count + " shuffles, in " + time + " seconds.");
}
private long time()
{
return System.currentTimeMillis();
}
public void RUN()
{
long startTime = time();
fill();
shuffle(separate(0), separate(26));
while(more()){
shuffle(separate(0), separate(26));
}
long endTime = time();
print((endTime - startTime) / 1000);
}
}
Neat little Java program I wrote
Neat little Java program I wrote
Matt Kemmer