public class ChutesAndLaddersSolver
{
	final int GOAL = 100;
	final double GAMMA = 1.0, THETA = 1e-9;
	int[] goesTo = new int[GOAL + 1]; // chute & ladder transitions
	double[] V = new double[GOAL + 1];

	public ChutesAndLaddersSolver()
	{
		initialize();
		valueIterate();
	}

	private void initialize() 
	{
		// Initialize chute/ladder transitions
		for (int i = 0; i < goesTo.length; i++)
			goesTo[i] = i;
		int[] from = {1, 4, 9, 16, 21, 28, 36, 48, 49, 51, 56, 62, 64, 71, 80, 87, 93, 95, 98};
		int[] to = {38, 14, 31, 6, 42, 84, 44, 26, 11, 67, 53, 19, 60, 91, 100, 24, 73, 75, 78};
		for (int i = 0; i < from.length; i++)
			goesTo[from[i]] = to[i];
	}

	public void valueIterate() 
	{
		// Value iterate the Chutes & Ladders game to compute the expected turns to go from any given state.
	}

	public String toString() 
	{
		StringBuffer sb = new StringBuffer();
		sb.append(String.format("Expected turns per game: %5.2f\n", Math.abs(V[0])));
		sb.append("Expected turns remaining by position:\n");
		for (int row = 9; row >= 0; row--) {
			for (int col = 0; col < 10; col++) {
				int boardPos = (row % 2 == 0) ? 10 * row + col + 1 : 10 * row + 10 - col; 
				sb.append(String.format("%3d: %5.2f ", boardPos, Math.abs(V[boardPos])));
			}
			sb.append("\n");
		}
		return sb.toString();
	}

	public static void main(String[] args) 
	{
		System.out.println(new ChutesAndLaddersSolver());
	}

}
