## Class Shuffle

```java.lang.Object
Shuffle
```

`public class Shuffleextends java.lang.Object`

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

### Shuffle

`public Shuffle()`
Method Detail

### main

`public static void main(java.lang.String[] args)`
Calls printShufflePeriods with lo = 2, hi = 100. Essentially used for testing

### printShufflePeriods

```public 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

Parameters:
`lo` - the smallest array size to check the shuffle period of
`hi` - the greatest array size to check the shuffle period of
Precondition:
lo and hi should both be even, with lo <= hi

### shufflePeriod

`public static int shufflePeriod(int L)`
Counts the number of perfect shuffles required to go from the identity array back to the identity array

Parameters:
`L` - the length of the deck to be shuffled
Returns:

### perfectShuffle

`public static int[] perfectShuffle(int[] A)`
Performs a perfect shuffle, alternating cards from the first and second halves of the deck

Parameters:
`A` - the array to be shuffled
Returns:
the shuffled array

### identity

`public static int[] identity(int L)`
Creates an identity array of the given size

Parameters:
`L` - the length of the identity array to be created
Returns:
an identity array of length L

### isIdentity

`public static boolean isIdentity(int[] A)`
Tests whether a given array is the identity array

Parameters:
`A` - the array to be compared to the identity array
Returns:
true if the array is the identity array, false otherwise

### intArrayToString

`public static java.lang.String intArrayToString(int[] a)`
Method for debugging: converts int array into string

Parameters:
`a` - the array to be converted
Returns:
a comma delimited string within brackets with each element of the int array