|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.ObjectShuffle
public class Shuffle
Shuffle.java
Solution for CS 201 HW 1 problem 3
Program to calculate the number of perfect shuffles that it takes to return an array to its starting position
| Constructor Summary | |
|---|---|
Shuffle()
|
|
| Method Summary | |
|---|---|
static int[] |
identity(int L)
Creates an identity array of the given size |
static java.lang.String |
intArrayToString(int[] a)
Method for debugging: converts int array into string |
static boolean |
isIdentity(int[] A)
Tests whether a given array is the identity array |
static void |
main(java.lang.String[] args)
Calls printShufflePeriods with lo = 2, hi = 100. |
static int[] |
perfectShuffle(int[] A)
Performs a perfect shuffle, alternating cards from the first and second halves of the deck |
static void |
printShufflePeriods(int lo,
int hi)
Prints the shuffle periods for all even integers between lo and hi (inclusive) Uses the form shufflePeriod(k)=P |
static int |
shufflePeriod(int L)
Counts the number of perfect shuffles required to go from the identity array back to the identity array |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Shuffle()
| Method Detail |
|---|
public static void main(java.lang.String[] args)
public static void printShufflePeriods(int lo,
int hi)
lo - the smallest array size to check the shuffle period ofhi - the greatest array size to check the shuffle period ofpublic static int shufflePeriod(int L)
L - the length of the deck to be shuffled
public static int[] perfectShuffle(int[] A)
A - the array to be shuffled
public static int[] identity(int L)
L - the length of the identity array to be created
public static boolean isIdentity(int[] A)
A - the array to be compared to the identity array
public static java.lang.String intArrayToString(int[] a)
a - the array to be converted
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||