Skip to content

Instantly share code, notes, and snippets.

@calda
Last active October 11, 2016 19:16
Show Gist options
  • Save calda/4957973 to your computer and use it in GitHub Desktop.
Save calda/4957973 to your computer and use it in GitHub Desktop.
Statistical analysis of Bulgarian Solitaire
//scroll down for statistical analysis
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
public class BulgarianSolitairePlayer{
static List<Integer> moves = new ArrayList<Integer>();
static HashMap<Integer, List<Integer>> movesDouble = new HashMap<Integer, List<Integer>>();
public static void main(String[] args){
for(int i = 0; i <= 1000000; i++){
BulgarianSolitaire deck = new BulgarianSolitaire();
ArrayList<Integer> start = deck.setupRandomly();
deck.play();
moves.add(deck.getNumberOfMoves());
List<Integer> xTimes;
if(movesDouble.containsKey(start.size())){
xTimes = movesDouble.get(start.size());
}else xTimes = new ArrayList<Integer>();
xTimes.add(deck.getNumberOfMoves());
movesDouble.put(start.size(), xTimes);
if(i % 100000 == 0 && i != 0){
System.out.println(getMeanOfList(moves) + " moves per game at game " + i + " \t\tGame " + i + " took " + deck.getNumberOfMoves() + " moves, starting at " + start);
}
}HashMap<Integer, Integer> movesMean = new HashMap<Integer, Integer>();
HashMap<Integer, Integer> movesCount = new HashMap<Integer, Integer>();
Iterator<Entry<Integer, List<Integer>>> i = movesDouble.entrySet().iterator();
while(i.hasNext()){
Entry<Integer, List<Integer>> e = i.next();
movesMean.put(e.getKey(), getMeanOfList(e.getValue()));
movesCount.put(e.getKey(), e.getValue().size());
}Iterator<Entry<Integer, Integer>> i2 = movesMean.entrySet().iterator();
Iterator<Entry<Integer, Integer>> i3 = movesCount.entrySet().iterator();
System.out.println();
while(i2.hasNext()){
Entry<Integer, Integer> e = i2.next();
Entry<Integer, Integer> e2 = i3.next();
int timesMean = e.getValue();
int owner = e.getKey();
System.out.println("Initial Stack: " + owner + " \tAverage moves: " + timesMean + " \tTimes made: " + e2.getValue() + " \t% of Time made: " + ((int)((((float)e2.getValue()) / 1000000) * 100)));
}
}
public static int getMeanOfList(List<Integer> moves){
int sum = 0;
int amount = 0;
for(int im : moves){
sum += im;
amount += 1;
}return (sum / amount);
}
}
//OUTPUT
54 moves per game at game 100000 Game 100000 took 67 moves, starting at [10, 11, 13, 8, 3]
54 moves per game at game 200000 Game 200000 took 51 moves, starting at [42, 3]
54 moves per game at game 300000 Game 300000 took 26 moves, starting at [27, 3, 1, 12, 2]
54 moves per game at game 400000 Game 400000 took 69 moves, starting at [5, 21, 15, 4]
54 moves per game at game 500000 Game 500000 took 66 moves, starting at [28, 12, 1, 4]
54 moves per game at game 600000 Game 600000 took 38 moves, starting at [39, 6]
54 moves per game at game 700000 Game 700000 took 44 moves, starting at [45]
54 moves per game at game 800000 Game 800000 took 72 moves, starting at [3, 6, 24, 10, 1, 1]
54 moves per game at game 900000 Game 900000 took 66 moves, starting at [29, 5, 11]
54 moves per game at game 1000000 Game 1000000 took 40 moves, starting at [41, 4]
Initial Stack: 1 Average moves: 44 Times made: 21363 % of Time made: 2
Initial Stack: 2 Average moves: 46 Times made: 115858 % of Time made: 11
Initial Stack: 3 Average moves: 49 Times made: 186386 % of Time made: 18
Initial Stack: 4 Average moves: 53 Times made: 232499 % of Time made: 23
Initial Stack: 5 Average moves: 56 Times made: 195040 % of Time made: 19
Initial Stack: 6 Average moves: 59 Times made: 130892 % of Time made: 13
Initial Stack: 7 Average moves: 61 Times made: 70311 % of Time made: 7
Initial Stack: 8 Average moves: 63 Times made: 31545 % of Time made: 3
Initial Stack: 9 Average moves: 65 Times made: 11260 % of Time made: 1
Initial Stack: 10 Average moves: 66 Times made: 3552 % of Time made: 0
Initial Stack: 11 Average moves: 68 Times made: 990 % of Time made: 0
Initial Stack: 12 Average moves: 69 Times made: 243 % of Time made: 0
Initial Stack: 13 Average moves: 68 Times made: 50 % of Time made: 0
Initial Stack: 14 Average moves: 73 Times made: 10 % of Time made: 0
Initial Stack: 15 Average moves: 79 Times made: 2 % of Time made: 0
//FINDINGS
*It takes an average of 54 moves per game
*The more stacks created at the beggining, the longer it will take (1 stack takes 44, 15 takes 79)
*4 initial stacks is the most common at 23% occuranc
*15 stacks is the least common at (2/1000000)% occurance
YAY STATISTICS!
-Cal Stephens
@hugabor
Copy link

hugabor commented Oct 11, 2016

omg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment