Statistics

Problem Statement for "FloorIndicator"

Problem Statement

Imagine a skyscraper with 10^N floors, numbered 0 to 10^N-1. The floor indicator in the elevator shows the floor number using exactly N digits, padding it with leading zeroes if necessary. Each digit is shown as a 5x3 field of small lamps, some of which are lit and some of which are unlit. Here is a representation of all the digits from 0 to 9 ('#' represents lit lamps and '.' represents unlit lamps) :

###...#.###.###.#.#.###.###.###.###.###
#.#...#...#...#.#.#.#...#.....#.#.#.#.#
#.#...#.###.###.###.###.###...#.###.###
#.#...#.#.....#...#...#.#.#...#.#.#...#
###...#.###.###...#.###.###...#.###.###


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 String[] where each element represents a row of lamps, and rows are given from top to bottom. Return the average that you calculate, or -1 if no valid floor number could possibly be represented by the indicator.

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. 1

    {"###", "#.#", "#.#", "#.#", "###"}

    Returns: 4.0

  2. 2

    {"###.###", "#.#.#.#", "#.#.#.#", "#.#.#.#", "###.###"}

    Returns: 44.0

  3. 1

    { "...", "...", "...", "...", "..." }

    Returns: 4.5

  4. 1

    { "###", "..#", "..#", "..#", "..#" }

    Returns: 5.4

  5. 1

    {"###", "#.#", "#.#", "..#", "###"}

    Returns: 5.666666666666667

  6. 1

    {"###",".#.","...","...","..."}

    Returns: -1.0

  7. 1

    {"###", "#.#", "###", "#.#", "###"}

    Returns: 8.0

    This digit is clearly "8", so it is the only possible floor.

  8. 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.

  9. 2

    {".......", ".......", ".......", ".......", "......."}

    Returns: 49.5

    This indicator is completely broken, so any floor number between 0 and 99 is possible.

  10. 1

    {"...", ".#.", "...", "...", "..."}

    Returns: -1.0

    No digit fits here.

  11. 1

    {"###","..#","..#","..#","..#"}

    Returns: 5.4

  12. 1

    {"###","...","#.#","...","..#"}

    Returns: 4.714285714285714

  13. 9

    {"...................................","...................................","...................................","...................................","..................................."}

    Returns: 4.999999995E8

  14. 1

    {"###","###","###","###","###"}

    Returns: -1.0

  15. 2

    {"###....","#.#....","###....","#.#....","#.#...#"}

    Returns: 84.5

  16. 3

    {"...........","...........","...........",".........#.","..........."}

    Returns: -1.0

  17. 1

    {"###","#.#","###","#.#","###"}

    Returns: 8.0

  18. 1

    {".##","..#",".##","..#",".#."}

    Returns: 6.666666666666667

  19. 1

    {"...","...","...","...","..."}

    Returns: 4.5

  20. 1

    {".#.",".#.","#.#","#.#","..."}

    Returns: -1.0

  21. 2

    {".......",".......",".....#.",".......","..#...#"}

    Returns: 50.285714285714285

  22. 2

    {"..#...#","#.....#","..#..#.",".......","..#..##"}

    Returns: 58.83333333333333

  23. 2

    {".#.....","#.#....",".#..##.","#......",".##...#"}

    Returns: 85.28571428571429

  24. 2

    {"###.##.","#...#.#",".##...#","#.#...#","##..###"}

    Returns: 75.66666666666667

  25. 2

    {"###.###","#.#.#.#","###.###","#.#.#.#","###.###"}

    Returns: 88.0

  26. 2

    {"###.###","#.#.#.#","###.###","###.#.#","###.###"}

    Returns: -1.0

  27. 3

    {"...........","...........","....#...#..","#.#........","..........."}

    Returns: 517.5416666666667

  28. 3

    {"...........","...........","...........","...........","..........."}

    Returns: 499.5

  29. 3

    {"...........","...........","...........",".........#.","..........."}

    Returns: -1.0

  30. 3

    {"###.###.###","#.....#...#","###..#..###","....#.#.#.#","###...#.#.."}

    Returns: 788.0

  31. 4

    {"....###...#..##","....#...#...#..","###..#..##...#.","#.....#...#.#.#","#.......##..#.."}

    Returns: 6110.333333333333

  32. 4

    {".##.#.#.###..##","#.#.#.#.#...#..","###..##.#.#.#.#","#.#.#.#.#.#...#",".##.###.###.##."}

    Returns: 8852.266666666666

  33. 4

    {"............#..","#...........#..","#.#..#...##....","#.#.#.........#","..#.#.......#.#"}

    Returns: 5258.4571428571435

  34. 5

    {"...................","...................","...................","...................","..................."}

    Returns: 49999.5

  35. 5

    {"#.#.###.##..###..##","..#.#.#.#...#.#.#..","###..#..##..###..##","#.....#...#.#.#...#","###.###.###.###.###"}

    Returns: 59287.0

  36. 5

    {"........#.....#...#","#...#.#............","........#....#.....","..............#.#..",".#..##..#...#.....#"}

    Returns: 62204.09523809524

  37. 6

    {".#..##..##....#.#.#.#..","#.#..##.#...#..........","###.#.#...#.#.#.##..#.#","#.......#.#.#.....#.#.#","###......#...#..#...#.."}

    Returns: -1.0

  38. 6

    {"###.###.###.###.###.###","..#.#.#.#.#.#.#.#.#.#..",".##.###.###.###.##..###","#.#.#.#.#.#.#.#.#.#.#.#","##..###.###.###.#.#.#.#"}

    Returns: 888887.0

  39. 6

    {"......#..#.............","................#...#..","..............#.......#","......................#",".....................#."}

    Returns: 500508.93333333335

  40. 7

    {".#...#....#.#...#.#.....##.","....#...#...#.#.#.#.#.#....","#.#.##.......##...#.##..##.","#.......#.#.#.......#.#...#","#....#...#..#....#..###...."}

    Returns: 4755319.533333333

  41. 7

    {"##..##..###..#...##.#....##","..#...#.#.#.#.....#.#.#.#.#","#.#...#.##.......##..##.###","#...#...#.#...#...#.#...#.#","#...###...#.#.#.##...##.#.#"}

    Returns: 3753021.3333333335

  42. 7

    {"###.###.###.#.#.###.###.###","#.#.#.#.#.#.#.#.#.#.#.#.#.#","#.#.#....##.###.###.#.#.###","#.#.#.#.#.#.#.#.#.#.#.#.#.#",".##.###..##.###.###.###.###"}

    Returns: 4488848.0

  43. 8

    {"...............................",".................#.............","...............................","...............................","..............................."}

    Returns: -1.0

  44. 8

    {"###.###.###.###.###.###.###.###","#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#","###.###.###.###.###.###.###.###","#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#","###.###.###.###.###.###.###.###"}

    Returns: 8.8888888E7

  45. 8

    {"...............................","......#.#...#...#.......#...#..","....#...#.....#..........#.....","#.....................#.#...#..","##...#....#......#....#..#....#"}

    Returns: 4.499281911111111E7

  46. 8

    {".##.###.##..#.#...#...#..#..##.","..#.#...#.#...#...#.#...#...#..","#.#.###...#...#.#.#.##..##...#.","..#.#.#.#.#.#.......#...#.#...#","#...#.#.##...##.##..#.#.##....#"}

    Returns: 5.7438510333333336E7

  47. 9

    {"........#...#.....#......#...#.....","...................................",".#....#..#...#..........#........#.","........#.......#...........#......",".........................##........"}

    Returns: 5.79478350047619E8

  48. 9

    {".........#..............##.........","........#.......#...........#.#.#..","##......#.............#.#.#...#.#.#","............#...............#......","................................#.."}

    Returns: 5.796297789333333E8

  49. 9

    {"....#...###.#....##..#........#.#..","#.......#...#......................",".#..#........#..#....##..##.#...#..","....#...#.#.......#...#...#.#.#...#",".#...#....#..#..#...#...#...#.#.#.."}

    Returns: 7.454252051666666E8

  50. 9

    {"#.......###..#..#...#.#.#.#...#.#.#","....#.#...#...#...#.#...#.#...#....","##..#.#.##......##..#....#..#.....#","....#.......#.............#...#.#.#","#.#.###..#..#.....#.....#....#...##"}

    Returns: 5.958915713333334E8

  51. 9

    {"#.#.##..###.##....#.....#...##...##","#.#.#.....#.#.#.......#.......#...#","###..##.#.........#.##...#..##.....","..#...........#.#.............#.#..","#.#..#....#...#..#.......#...##.#.."}

    Returns: 9.250124866666666E8

  52. 9

    {"#.#.###..#...##.###.#.....#.#.#.#.#","....#...#...#.#.......#...#..##.#.#","###.###..#..##....#.###.#.#.#.....#","#...#.#.#.#.#.#.....#.#.#.#.#.#...#","#.#.....###..##.###.#....##...#.#.."}

    Returns: -1.0

  53. 9

    {"....###.#...###.##..###..##.###.###","....#...#.#.....#.#.#.#.#.#.#...#..","..#.###.###.......#..##...#...#.###","#.#.#.#.#.#...#...#.#.#.#...#.#....","##..##..###..#..##...#..###.###.###"}

    Returns: 5.452484536666667E8

  54. 9

    {"###.###.#.#.###.##..#.#.#.#.#....#.","#.#.#.#.....#.#...#.#.#.#.#.#.#.#.#","###.###.##..###.##...#..###.#.#..##","#.#.#...#.#.#.#.#...#.#.#.#.#.#...#","##..#.#.###.##..#.#.##..##..###..##"}

    Returns: 8.878588485E8

  55. 9

    {".##..#..#.#.##..###.##....#.###.###","..#.....#.......#.#.#.#.#.#...#.#.#","###.#.#.###.###.###.###.#.#.##..###","#.#.#.#.#.#.#.#.#.#.#.#.#...#.#.#.#","###..##.###.###.###..##.##...##.###"}

    Returns: 8.544551546666666E8

  56. 9

    {"##..###..##..##.###.#.#.###.##..###","#.#.#.#...#.#.#.#.#.#.#.#.#.#.#...#","###.###.#.#.###.###.###.###..##.###","#.#.#.#.....#.#.#.#.#.#.#.#.#.#...#","###.#.#.###..##.###.#.#..##.###.##."}

    Returns: 8.852888866666666E8

  57. 9

    {"###.###.###.###.###.###.###.###.###","#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#","###.###.###.###.###.###.###.###.###","#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#","###.###.###.###.###.###.###.###.###"}

    Returns: 8.88888888E8

  58. 2

    {".......", ".......", ".......", ".......", "......." }

    Returns: 49.5

  59. 2

    {"###.###", "#.#.#.#", "#.#.###", "#.#...#", "###.###" }

    Returns: 48.5

  60. 9

    {"....#..............................", "...................................", "...................................", "...................................", "..................................." }

    Returns: 5.038888883888889E8

  61. 1

    {"...", ".#.", "...", "...", "..." }

    Returns: -1.0

  62. 9

    {"...................................", "...................................", "...................................", "...................................", "..................................." }

    Returns: 4.999999995E8

  63. 9

    {"...................................", "...................................", "..#...#...#...#...#...#...#...#...#", "...................................", "..................................." }

    Returns: 4.999999995E8

  64. 9

    {"....###.###.###....................", "....#.#...#.................#......", "....#.#.###.........###............", "....#.#...#.............#..........", "....###.###.....###................" }

    Returns: 4.972195530714286E8

  65. 9

    {".#.................................", "...................................", "...................................", "...................................", "..................................." }

    Returns: 5.499999995E8


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: