Problem Statement
A company is developing a 3-dimensional computer monitor. The monitor has a resolution of 1024 by 1024 by 1024 pixels. The monitor is a cube, with a grid of lasers on three sides of the cube, all of which share an edge (that is, no grid is on the face directly opposite another grid). As a result, one of these grids is in the XY-plane of the monitor, another is in the YZ-plane, and the third is in the XZ-plane. To "light up" a pixel, the laser on each grid which corresponds to the pixel's coordinate needs to be on, and the intersection of these three lasers is what creates the point of light.
Create a class FullMonitor containing a method numLasers which takes as an argument a
For example, if we wish to light the point (4,4,3), the XY-plane would have to light up the laser at (4,4), the YZ-plane would have to light up the laser at (4,3), and the XZ-plane would have to light up the laser at (4,3). In total, 3 lasers would have to be activated. If we were to then light the point (4,3,3), the following lasers would have to be activated: XY-plane (4,3), YZ-plane (3,3), XZ-plane (4,3). Since the XZ-plane's (4,3) laser is already activated, a total of 5 lasers would have to be activated.
Each element of pixels is formatted as (quotes added for clarity) "X,Y,Z" where X, Y, and Z are the respective coordinates of the pixel. Each coordinate is an integer between 0 and 1023 inclusive (with no extra leading zeroes).
Definition
- Class:
- FullMonitor
- Method:
- numLasers
- Parameters:
- String[]
- Returns:
- int
- Method signature:
- int numLasers(String[] pixels)
- (be sure your method is public)
Notes
- Each laser grid has 1024*1024=1048576 lasers, for a total of 3145728 possible activated lasers. However, this situation requires more lit pixels than can be represented using the input.
Constraints
- pixels will contain between 0 and 50 elements, inclusive.
- each element of pixels will be formatted as (quotes added for clarity) "X,Y,Z" where X, Y, and Z are integers between 0 and 1023, inclusive, with no extra leading zeroes
- each element of pixels will be unique.
Examples
{"25,25,25"}
Returns: 3
Only one pixel is lit, and it requires 3 lasers to be displayed.
{"25,25,25","25,25,26"}
Returns: 5
2 pixels are lit, but share the same XY laser at point (25,25), so only 5 lasers are lit.
{"25,25,25","25,25,26","25,26,26"}
Returns: 7
{"25,25,25","25,25,26","25,26,26","25,26,25"}
Returns: 8
{"1000,1005,20","20,50,20","30,90,10","1005,30,90", "90,1000,1005","30,90,20","1000,90,10","40,90,10", "1000,1000,1000"}
Returns: -1
{"1,1,3","1,3,1","3,1,1"}
Returns: -1
These three pixels cannot be lit without lighting the pixel (1,1,1), so return -1.
{"1,1,3","1,3,1","3,1,1","1,1,1"}
Returns: 9
The previous example, with (1,1,1) activated to make it possible.
{"938,134,626","1015,310,957","427,741,13","388,513,56", "914,169,526","716,540,478","796,461,500","506,886,866", "44,185,744","474,104,631","557,402,744","992,132,804", "440,499,122","895,845,612","711,576,984","281,846,475", "781,620,301","305,632,954","874,659,36","17,978,393", "765,481,372","612,316,8","902,281,515","272,125,1012", "413,513,987","595,940,1014","858,1019,100","899,554,613", "226,995,592","793,939,286","386,41,212","111,899,737", "339,199,117","1014,710,638","413,187,56","301,691,368", "387,285,286","546,356,739","366,356,660","877,461,737", "538,301,629","707,116,7","701,730,70"}
Returns: -1
{"552,691,899","114,377,200","721,33,596","30,463,316","78,837,693","376,612,754","373,801,857","824,776,704","329,433,789","583,357,7","852,793,270","968,382,844","282,501,938","11,934,863","946,859,953","467,149,573","178,464,174","448,440,201","329,433,842","230,815,571","675,197,196","847,928,994","157,123,719","803,925,670","397,108,871","518,564,42","297,885,489","126,484,240","255,745,948","129,422,859","13,670,830","524,127,110","688,168,815","779,543,833","309,137,874","445,971,447","570,951,393","173,727,571","741,740,846","339,189,341","89,517,234","971,762,304","946,414,753","937,350,803","206,247,332","22,262,846","922,592,823","420,968,550","662,825,432","542,442,858"}
Returns: 149
{"1002,153,730","335,475,535","201,599,818","250,696,676","34,758,172","368,496,938","868,152,947","934,84,942","214,597,347","868,677,947","778,339,151","625,60,380","406,864,859","790,542,1022","228,220,222","893,893,654","98,981,135","312,331,822","19,637,224","416,215,96","976,629,29","732,163,649","664,803,161","106,422,370","207,700,170","536,819,709","9,217,685","197,735,652","390,830,349","182,26,744","191,246,573","515,473,764","607,894,366","841,498,142","214,789,602","629,758,610","308,397,32","188,502,770","19,773,426","866,853,356","984,402,207","926,469,977"}
Returns: 125
{"895,218,784","327,68,973","109,984,734","12,901,109","482,457,730","33,751,54","640,817,910","202,501,881","363,771,1011","1017,571,138","1018,322,1023","574,813,952","767,127,739","276,92,268","605,762,535","482,799,730","30,933,952","111,313,673"}
Returns: 53
{"664,522,80","651,978,528","714,266,653","27,267,945","687,73,643","113,322,291","377,376,131","547,509,541","842,747,21","465,298,606","898,785,800","296,275,150","596,26,187","403,42,102","101,849,977","478,513,606","638,559,862","47,941,902","6,842,741","259,186,1008","44,42,287","439,892,943","687,934,643","523,84,25","645,162,969","29,584,944","365,745,447","711,54,437","665,558,562","616,457,648","586,143,729","443,531,868","515,635,470","475,525,678","618,638,601","93,799,18","185,438,650","543,375,1000","788,261,576"}
Returns: 116
{"734,545,593","375,21,805","667,579,952","808,919,658","525,214,360","795,754,840","531,335,744","233,807,450","839,283,662","292,562,225","612,897,605","324,925,447","440,343,804","18,172,308","787,457,500","972,218,715","219,564,916","491,346,167","711,154,653","956,90,113","222,750,127","424,390,306","18,741,308","74,340,636","799,32,957","1007,315,250","588,362,263","250,1004,206"}
Returns: 83
{"286,596,559","502,325,84","303,56,960","28,678,821", "542,57,303","233,418,91","13,520,124","645,129,889", "438,433,951","835,953,56","921,531,943","416,159,446", "513,426,1018","778,486,254","132,380,822","828,351,787", "659,531,866","893,140,419","603,721,110","888,144,689", "861,869,515","632,912,973","435,828,676","526,365,850", "162,860,173","637,910,701","169,21,311","431,722,798", "674,663,1012","451,343,584","132,380,1000","184,720,1011"}
Returns: 95
{"507,497,504","10,961,544","792,223,293","158,416,745","476,477,53","860,774,622","558,40,901","267,965,806","807,278,595","922,129,736","712,272,23","167,525,827","226,77,352","296,553,661","822,505,323","294,236,834","810,116,361","80,390,657","406,673,353","733,207,643","741,451,378","733,283,502","88,272,803","749,105,345","317,524,269","285,953,349","96,856,1023","947,249,920","206,704,972","524,596,997","327,683,208","118,939,682","303,398,44","598,643,754","158,482,270","760,41,446","91,23,772","712,272,659","829,6,234","642,810,636","1021,906,413","85,329,196","937,702,640"}
Returns: 128
{"853,650,487","517,937,0","812,411,705","843,446,170","635,574,46","27,553,10","63,901,340","520,897,174","145,572,263","681,721,335","129,907,208","513,907,472","769,219,2","841,180,92","509,473,322","985,336,471","427,523,356","68,609,890","751,993,450","259,284,250","126,796,940","125,261,957","248,439,806","686,473,1006","44,581,567","256,778,456","839,343,647","584,123,713","481,795,456","45,542,12","254,556,967","203,229,825","513,907,818","116,176,832","633,16,943","423,778,739","328,267,233","696,400,670","527,381,962","875,688,619","370,973,393","556,517,16","1004,307,775","974,225,150","942,419,929","332,840,276","119,1008,855","433,879,5","701,12,541","304,926,905"}
Returns: 149
{"370,625,130","541,84,667","56,253,310","321,643,138","870,227,723","533,571,35","270,928,188","115,535,370","1015,245,617","959,953,795","466,850,124","5,488,335","91,878,286","466,850,913","531,919,323","146,578,983"}
Returns: 47
{"7,6,8","14,13,12","11,13,10","0,12,3","6,12,2","7,18,5","7,13,18","10,19,11","1,5,11","13,18,7","5,14,9","8,12,18","18,10,3","5,18,16","16,3,13","10,17,3","5,19,11"}
Returns: 50
{"8,5,17","7,11,15","17,1,0","17,2,7","14,4,11","2,10,11","13,3,8","18,1,10","15,9,10","19,16,13","1,14,13","8,0,0","17,7,17","13,16,16","8,4,0","8,6,6","14,15,12","7,8,7","11,17,14","10,11,15"}
Returns: 58
{"4,12,6","4,13,12","18,9,3","10,13,11","5,3,18","5,17,19","15,8,11","19,12,9","11,9,14","7,14,10","3,4,17","13,7,16","3,7,16","3,11,19","5,5,5","14,1,6","6,7,8","13,1,19","10,9,8","3,8,1","8,17,4","11,18,5","6,19,8"}
Returns: 67
{"10,14,7","9,9,0","17,14,9","0,17,1","13,10,16","14,12,1","8,17,16","17,3,12","11,18,17","11,17,17","0,1,3","1,4,4","14,1,8","5,4,15","19,0,2","18,17,6","16,1,5","5,18,5","6,16,6","13,6,18","19,10,14","8,14,16","8,14,7","18,17,16","10,6,2","2,5,4","13,4,10","11,10,14","6,8,15","19,14,4","8,18,18","12,2,7","15,19,9","9,1,16"}
Returns: 95
{"12,16,19","18,0,7","12,9,3","17,17,17","18,4,12","15,19,6","11,1,12","4,13,15","15,14,15","10,19,5","19,13,5","5,2,4","9,11,5","19,4,4","7,17,9","10,3,9","5,0,17","17,5,7","5,0,14","17,10,10","2,11,12","5,9,16","12,18,18","5,8,19","15,14,6","15,10,2","10,5,7","5,1,14","15,19,13","12,16,9","10,2,5"}
Returns: 85
{"5,8,17","13,16,4","10,2,18","15,0,2","16,5,13","14,5,13","19,15,7","14,12,9","7,19,9","12,14,1","9,15,12","16,18,9","7,16,4","9,0,3","1,16,8","2,19,17","6,13,6","9,19,10","15,0,18","15,17,18","19,18,9","7,9,18","11,1,8","18,8,10","5,8,8","10,2,0","5,2,7","4,6,11","9,2,16","18,10,5","10,16,6","3,14,4","14,5,16"}
Returns: 91
{"11,10,17","9,7,18","3,4,6","6,9,8","0,1,10","14,17,17","1,1,4","9,13,16","11,6,15","1,16,4","7,9,15","6,16,1","4,16,1","8,19,3","13,17,3","6,16,19","13,7,1","9,12,3","0,3,0","13,4,19","5,3,0","13,4,1","4,14,17","10,15,1","14,7,7","8,16,4"}
Returns: 71
{"0,11,15","9,5,19","17,0,1","12,12,9","16,18,0","7,14,15","18,17,8","9,14,3","6,0,4","7,18,13","16,0,11","14,3,18","11,5,19","12,4,11","0,17,8","12,15,10","16,0,12","10,14,4","3,14,3","3,14,9","9,8,18","2,18,0","16,3,12","8,7,14","4,10,13","6,1,7","15,7,2","5,5,0","1,10,5","10,1,5","17,0,11","1,3,9","11,0,1"}
Returns: 89
{"7,8,8","2,7,0","4,9,8","6,5,9","9,3,4","7,2,6","1,1,4","4,5,9","0,4,8","3,1,6","8,7,2","3,2,6","3,3,7","2,7,4","8,9,2","5,6,9","2,4,5","9,4,3","6,0,9","6,2,9","7,9,8","3,6,2","9,3,7","3,9,2","1,0,1","1,9,8"}
Returns: 64
{"3,0,1","2,9,8","6,4,1","7,5,5","7,5,9","9,5,9","7,5,8","7,3,6","2,4,0","7,8,6","0,3,6","5,0,5","3,1,6","2,0,2","8,2,3","0,2,9","3,0,7","3,5,7","8,1,3","4,9,6","5,2,5","2,9,9","2,0,8","2,9,0"}
Returns: 58
{"4,9,3","5,4,8","3,6,3","4,9,2","8,6,5","3,7,3","6,5,9","7,1,8","6,3,3","6,5,3","2,7,5","8,1,5","5,7,8","4,4,1","8,5,9","9,0,5","9,2,6","3,7,8","8,5,5","2,7,8","7,1,4","0,6,0","5,6,0","6,0,0"}
Returns: 57
{"6,5,0","5,9,4","3,4,1","5,2,0","0,3,3","7,1,1","6,6,9","1,9,4","0,7,3","3,8,2","3,9,7","2,8,6","3,9,8","3,9,4","4,4,1","4,8,2","6,4,0","5,2,4","7,3,3","8,7,1","6,7,5","4,4,0","3,5,8","2,2,1","1,8,9"}
Returns: 61
{"1,0,0","4,1,2","0,2,0","0,0,0","4,4,3","2,3,2","0,4,3", "4,2,3","4,4,1","2,2,0","4,1,1","4,0,1","1,0,2","1,3,2", "0,2,3","4,0,2","2,2,3"}
Returns: 31