Problem Statement
###...#.###.###.#.#.###.###.###.###.###
#.#...#...#...#.#.#.#...#.....#.#.#.#.#
#.#...#.###.###.###.###.###...#.###.###
#.#...#.#.....#...#...#.#.#...#.#.#...#
###...#.###.###...#.###.###...#.###.###
Here, as in the actual floor indicator, consecutive digits are separated by a single column of unlit lamps. Some of the lamps in the floor indicator are malfunctioning and always remain unlit. Imagine that you are stuck in this elevator and you want to know the current floor number. You decide to calculate it as the average value of all floor numbers that could possibly be represented by the current state of the indicator, assuming that any number of the unlit lamps might be malfunctioning. You are given the state of the indicator as a
Definition
- Class:
- FloorIndicator
- Method:
- averageFloor
- Parameters:
- int, String[]
- Returns:
- double
- Method signature:
- double averageFloor(int N, String[] indicator)
- (be sure your method is public)
Notes
- The returned value must be accurate to within a relative or absolute value of 1E-9.
Constraints
- N will be between 1 and 9, inclusive.
- indicator will contain exactly 5 elements.
- Each element of indicator will contain exactly 4*N - 1 characters.
- Each element of indicator will be either '#' or '.' (dot).
- All characters corresponding to lamps in separating columns will be '.' (dots).
Examples
1
{"###", "#.#", "#.#", "#.#", "###"}
Returns: 4.0
2
{"###.###", "#.#.#.#", "#.#.#.#", "#.#.#.#", "###.###"}
Returns: 44.0
1
{ "...", "...", "...", "...", "..." }
Returns: 4.5
1
{ "###", "..#", "..#", "..#", "..#" }
Returns: 5.4
1
{"###", "#.#", "#.#", "..#", "###"}
Returns: 5.666666666666667
1
{"###",".#.","...","...","..."}
Returns: -1.0
1
{"###", "#.#", "###", "#.#", "###"}
Returns: 8.0
This digit is clearly "8", so it is the only possible floor.
2
{"###.###", "#.#.#.#", "#.#.###", "#.#...#", "###.###"}
Returns: 48.5
Although the indicator shows "09", both digits can also be partially lit "8", so the possible floor numbers are: 08,09,88,89. This results in average floor number (8+9+88+89)/4 = 48.5.
2
{".......", ".......", ".......", ".......", "......."}
Returns: 49.5
This indicator is completely broken, so any floor number between 0 and 99 is possible.
1
{"...", ".#.", "...", "...", "..."}
Returns: -1.0
No digit fits here.
1
{"###","..#","..#","..#","..#"}
Returns: 5.4
1
{"###","...","#.#","...","..#"}
Returns: 4.714285714285714
9
{"...................................","...................................","...................................","...................................","..................................."}
Returns: 4.999999995E8
1
{"###","###","###","###","###"}
Returns: -1.0
2
{"###....","#.#....","###....","#.#....","#.#...#"}
Returns: 84.5
3
{"...........","...........","...........",".........#.","..........."}
Returns: -1.0
1
{"###","#.#","###","#.#","###"}
Returns: 8.0
1
{".##","..#",".##","..#",".#."}
Returns: 6.666666666666667
1
{"...","...","...","...","..."}
Returns: 4.5
1
{".#.",".#.","#.#","#.#","..."}
Returns: -1.0
2
{".......",".......",".....#.",".......","..#...#"}
Returns: 50.285714285714285
2
{"..#...#","#.....#","..#..#.",".......","..#..##"}
Returns: 58.83333333333333
2
{".#.....","#.#....",".#..##.","#......",".##...#"}
Returns: 85.28571428571429
2
{"###.##.","#...#.#",".##...#","#.#...#","##..###"}
Returns: 75.66666666666667
2
{"###.###","#.#.#.#","###.###","#.#.#.#","###.###"}
Returns: 88.0
2
{"###.###","#.#.#.#","###.###","###.#.#","###.###"}
Returns: -1.0
3
{"...........","...........","....#...#..","#.#........","..........."}
Returns: 517.5416666666667
3
{"...........","...........","...........","...........","..........."}
Returns: 499.5
3
{"...........","...........","...........",".........#.","..........."}
Returns: -1.0
3
{"###.###.###","#.....#...#","###..#..###","....#.#.#.#","###...#.#.."}
Returns: 788.0
4
{"....###...#..##","....#...#...#..","###..#..##...#.","#.....#...#.#.#","#.......##..#.."}
Returns: 6110.333333333333
4
{".##.#.#.###..##","#.#.#.#.#...#..","###..##.#.#.#.#","#.#.#.#.#.#...#",".##.###.###.##."}
Returns: 8852.266666666666
4
{"............#..","#...........#..","#.#..#...##....","#.#.#.........#","..#.#.......#.#"}
Returns: 5258.4571428571435
5
{"...................","...................","...................","...................","..................."}
Returns: 49999.5
5
{"#.#.###.##..###..##","..#.#.#.#...#.#.#..","###..#..##..###..##","#.....#...#.#.#...#","###.###.###.###.###"}
Returns: 59287.0
5
{"........#.....#...#","#...#.#............","........#....#.....","..............#.#..",".#..##..#...#.....#"}
Returns: 62204.09523809524
6
{".#..##..##....#.#.#.#..","#.#..##.#...#..........","###.#.#...#.#.#.##..#.#","#.......#.#.#.....#.#.#","###......#...#..#...#.."}
Returns: -1.0
6
{"###.###.###.###.###.###","..#.#.#.#.#.#.#.#.#.#..",".##.###.###.###.##..###","#.#.#.#.#.#.#.#.#.#.#.#","##..###.###.###.#.#.#.#"}
Returns: 888887.0
6
{"......#..#.............","................#...#..","..............#.......#","......................#",".....................#."}
Returns: 500508.93333333335
7
{".#...#....#.#...#.#.....##.","....#...#...#.#.#.#.#.#....","#.#.##.......##...#.##..##.","#.......#.#.#.......#.#...#","#....#...#..#....#..###...."}
Returns: 4755319.533333333
7
{"##..##..###..#...##.#....##","..#...#.#.#.#.....#.#.#.#.#","#.#...#.##.......##..##.###","#...#...#.#...#...#.#...#.#","#...###...#.#.#.##...##.#.#"}
Returns: 3753021.3333333335
7
{"###.###.###.#.#.###.###.###","#.#.#.#.#.#.#.#.#.#.#.#.#.#","#.#.#....##.###.###.#.#.###","#.#.#.#.#.#.#.#.#.#.#.#.#.#",".##.###..##.###.###.###.###"}
Returns: 4488848.0
8
{"...............................",".................#.............","...............................","...............................","..............................."}
Returns: -1.0
8
{"###.###.###.###.###.###.###.###","#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#","###.###.###.###.###.###.###.###","#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#","###.###.###.###.###.###.###.###"}
Returns: 8.8888888E7
8
{"...............................","......#.#...#...#.......#...#..","....#...#.....#..........#.....","#.....................#.#...#..","##...#....#......#....#..#....#"}
Returns: 4.499281911111111E7
8
{".##.###.##..#.#...#...#..#..##.","..#.#...#.#...#...#.#...#...#..","#.#.###...#...#.#.#.##..##...#.","..#.#.#.#.#.#.......#...#.#...#","#...#.#.##...##.##..#.#.##....#"}
Returns: 5.7438510333333336E7
9
{"........#...#.....#......#...#.....","...................................",".#....#..#...#..........#........#.","........#.......#...........#......",".........................##........"}
Returns: 5.79478350047619E8
9
{".........#..............##.........","........#.......#...........#.#.#..","##......#.............#.#.#...#.#.#","............#...............#......","................................#.."}
Returns: 5.796297789333333E8
9
{"....#...###.#....##..#........#.#..","#.......#...#......................",".#..#........#..#....##..##.#...#..","....#...#.#.......#...#...#.#.#...#",".#...#....#..#..#...#...#...#.#.#.."}
Returns: 7.454252051666666E8
9
{"#.......###..#..#...#.#.#.#...#.#.#","....#.#...#...#...#.#...#.#...#....","##..#.#.##......##..#....#..#.....#","....#.......#.............#...#.#.#","#.#.###..#..#.....#.....#....#...##"}
Returns: 5.958915713333334E8
9
{"#.#.##..###.##....#.....#...##...##","#.#.#.....#.#.#.......#.......#...#","###..##.#.........#.##...#..##.....","..#...........#.#.............#.#..","#.#..#....#...#..#.......#...##.#.."}
Returns: 9.250124866666666E8
9
{"#.#.###..#...##.###.#.....#.#.#.#.#","....#...#...#.#.......#...#..##.#.#","###.###..#..##....#.###.#.#.#.....#","#...#.#.#.#.#.#.....#.#.#.#.#.#...#","#.#.....###..##.###.#....##...#.#.."}
Returns: -1.0
9
{"....###.#...###.##..###..##.###.###","....#...#.#.....#.#.#.#.#.#.#...#..","..#.###.###.......#..##...#...#.###","#.#.#.#.#.#...#...#.#.#.#...#.#....","##..##..###..#..##...#..###.###.###"}
Returns: 5.452484536666667E8
9
{"###.###.#.#.###.##..#.#.#.#.#....#.","#.#.#.#.....#.#...#.#.#.#.#.#.#.#.#","###.###.##..###.##...#..###.#.#..##","#.#.#...#.#.#.#.#...#.#.#.#.#.#...#","##..#.#.###.##..#.#.##..##..###..##"}
Returns: 8.878588485E8
9
{".##..#..#.#.##..###.##....#.###.###","..#.....#.......#.#.#.#.#.#...#.#.#","###.#.#.###.###.###.###.#.#.##..###","#.#.#.#.#.#.#.#.#.#.#.#.#...#.#.#.#","###..##.###.###.###..##.##...##.###"}
Returns: 8.544551546666666E8
9
{"##..###..##..##.###.#.#.###.##..###","#.#.#.#...#.#.#.#.#.#.#.#.#.#.#...#","###.###.#.#.###.###.###.###..##.###","#.#.#.#.....#.#.#.#.#.#.#.#.#.#...#","###.#.#.###..##.###.#.#..##.###.##."}
Returns: 8.852888866666666E8
9
{"###.###.###.###.###.###.###.###.###","#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#","###.###.###.###.###.###.###.###.###","#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#","###.###.###.###.###.###.###.###.###"}
Returns: 8.88888888E8
2
{".......", ".......", ".......", ".......", "......." }
Returns: 49.5
2
{"###.###", "#.#.#.#", "#.#.###", "#.#...#", "###.###" }
Returns: 48.5
9
{"....#..............................", "...................................", "...................................", "...................................", "..................................." }
Returns: 5.038888883888889E8
1
{"...", ".#.", "...", "...", "..." }
Returns: -1.0
9
{"...................................", "...................................", "...................................", "...................................", "..................................." }
Returns: 4.999999995E8
9
{"...................................", "...................................", "..#...#...#...#...#...#...#...#...#", "...................................", "..................................." }
Returns: 4.999999995E8
9
{"....###.###.###....................", "....#.#...#.................#......", "....#.#.###.........###............", "....#.#...#.............#..........", "....###.###.....###................" }
Returns: 4.972195530714286E8
9
{".#.................................", "...................................", "...................................", "...................................", "..................................." }
Returns: 5.499999995E8